Completed
Branch ENH/stop-messages-extra-meta (061f89)
by
unknown
09:49 queued 07:41
created
core/db_classes/EE_Message.class.php 1 patch
Indentation   +869 added lines, -869 removed lines patch added patch discarded remove patch
@@ -9,877 +9,877 @@
 block discarded – undo
9 9
  */
10 10
 class EE_Message extends EE_Base_Class implements EEI_Admin_Links
11 11
 {
12
-    /**
13
-     * @deprecated 4.9.0  Added for backward compat with add-on's
14
-     * @type null
15
-     */
16
-    public $template_pack;
17
-
18
-    /**
19
-     * @deprecated 4.9.0 Added for backward compat with add-on's
20
-     * @type null
21
-     */
22
-    public $template_variation;
23
-
24
-    /**
25
-     * @deprecated 4.9.0 Added for backward compat with add-on's
26
-     * @type string
27
-     */
28
-    public $content = '';
29
-
30
-
31
-    /**
32
-     * @type EE_messenger $_messenger
33
-     */
34
-    protected $_messenger = null;
35
-
36
-    /**
37
-     * @type EE_message_type $_message_type
38
-     */
39
-    protected $_message_type = null;
40
-
41
-
42
-    /**
43
-     * @param array  $props_n_values
44
-     * @param string $timezone
45
-     * @param array  $date_formats incoming date formats in an array.  First value is the date_format, second is time
46
-     *                             format.
47
-     * @return EE_Message
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__);
52
-        // if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
53
-        if (! $has_object) {
54
-            EE_Registry::instance()->load_helper('URL');
55
-            $props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
56
-        }
57
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
58
-    }
59
-
60
-
61
-    /**
62
-     * @param array  $props_n_values
63
-     * @param string $timezone
64
-     * @return EE_Message
65
-     */
66
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
67
-    {
68
-        return new self($props_n_values, true, $timezone);
69
-    }
70
-
71
-
72
-    /**
73
-     * Gets MSG_token
74
-     *
75
-     * @return int
76
-     */
77
-    public function MSG_token()
78
-    {
79
-        return $this->get('MSG_token');
80
-    }
81
-
82
-
83
-    /**
84
-     * Sets MSG_token
85
-     *
86
-     * @param int $MSG_token
87
-     */
88
-    public function set_MSG_token($MSG_token)
89
-    {
90
-        $this->set('MSG_token', $MSG_token);
91
-    }
92
-
93
-
94
-    /**
95
-     * Gets GRP_ID
96
-     *
97
-     * @return int
98
-     */
99
-    public function GRP_ID()
100
-    {
101
-        return $this->get('GRP_ID');
102
-    }
103
-
104
-
105
-    /**
106
-     * Sets GRP_ID
107
-     *
108
-     * @param int $GRP_ID
109
-     */
110
-    public function set_GRP_ID($GRP_ID)
111
-    {
112
-        $this->set('GRP_ID', $GRP_ID);
113
-    }
114
-
115
-
116
-    /**
117
-     * Gets TXN_ID
118
-     *
119
-     * @return int
120
-     */
121
-    public function TXN_ID()
122
-    {
123
-        return $this->get('TXN_ID');
124
-    }
125
-
126
-
127
-    /**
128
-     * Sets TXN_ID
129
-     *
130
-     * @param int $TXN_ID
131
-     */
132
-    public function set_TXN_ID($TXN_ID)
133
-    {
134
-        $this->set('TXN_ID', $TXN_ID);
135
-    }
136
-
137
-
138
-    /**
139
-     * Gets messenger
140
-     *
141
-     * @return string
142
-     */
143
-    public function messenger()
144
-    {
145
-        return $this->get('MSG_messenger');
146
-    }
147
-
148
-
149
-    /**
150
-     * Sets messenger
151
-     *
152
-     * @param string $messenger
153
-     */
154
-    public function set_messenger($messenger)
155
-    {
156
-        $this->set('MSG_messenger', $messenger);
157
-    }
158
-
159
-
160
-    /**
161
-     * Returns corresponding messenger object for the set messenger on this message
162
-     *
163
-     * @return EE_messenger | null
164
-     */
165
-    public function messenger_object()
166
-    {
167
-        return $this->_messenger;
168
-    }
169
-
170
-
171
-    /**
172
-     * Sets messenger
173
-     *
174
-     * @param EE_messenger $messenger
175
-     */
176
-    public function set_messenger_object(EE_messenger $messenger)
177
-    {
178
-        $this->_messenger = $messenger;
179
-    }
180
-
181
-
182
-    /**
183
-     * validates messenger
184
-     *
185
-     * @param bool $throw_exceptions
186
-     * @return bool
187
-     * @throws \EE_Error
188
-     */
189
-    public function valid_messenger($throw_exceptions = false)
190
-    {
191
-        if ($this->_messenger instanceof EE_messenger) {
192
-            return true;
193
-        }
194
-        if ($throw_exceptions) {
195
-            throw new EE_Error(
196
-                sprintf(
197
-                    esc_html__(
198
-                        'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
199
-                        'event_espresso'
200
-                    ),
201
-                    $this->messenger()
202
-                )
203
-            );
204
-        }
205
-        return false;
206
-    }
207
-
208
-
209
-    /**
210
-     * This returns the set localized label for the messenger on this message.
211
-     * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved
212
-     * with this message.
213
-     *
214
-     * @param   bool $plural whether to return the plural label or not.
215
-     * @return string
216
-     */
217
-    public function messenger_label($plural = false)
218
-    {
219
-        $label_type = $plural ? 'plural' : 'singular';
220
-        $messenger = $this->messenger_object();
221
-        return $messenger instanceof EE_messenger ? $messenger->label[ $label_type ] : $this->messenger();
222
-    }
223
-
224
-
225
-    /**
226
-     * Gets message_type
227
-     *
228
-     * @return string
229
-     */
230
-    public function message_type()
231
-    {
232
-        return $this->get('MSG_message_type');
233
-    }
234
-
235
-
236
-    /**
237
-     * Sets message_type
238
-     *
239
-     * @param string $message_type
240
-     */
241
-    public function set_message_type($message_type)
242
-    {
243
-        $this->set('MSG_message_type', $message_type);
244
-    }
245
-
246
-
247
-    /**
248
-     * Returns the message type object for the set message type on this message
249
-     *
250
-     * @return EE_message_type | null
251
-     */
252
-    public function message_type_object()
253
-    {
254
-        return $this->_message_type;
255
-    }
256
-
257
-
258
-    /**
259
-     * Sets message_type
260
-     *
261
-     * @param EE_message_type $message_type
262
-     * @param bool            $set_priority   This indicates whether to set the priority to whatever the priority is on
263
-     *                                        the message type or not.
264
-     */
265
-    public function set_message_type_object(EE_message_type $message_type, $set_priority = false)
266
-    {
267
-        $this->_message_type = $message_type;
268
-        if ($set_priority) {
269
-            $this->set_priority($this->_message_type->get_priority());
270
-        }
271
-    }
272
-
273
-
274
-    /**
275
-     * validates message_type
276
-     *
277
-     * @param bool $throw_exceptions
278
-     * @return bool
279
-     * @throws \EE_Error
280
-     */
281
-    public function valid_message_type($throw_exceptions = false)
282
-    {
283
-        if ($this->_message_type instanceof EE_message_type) {
284
-            return true;
285
-        }
286
-        if ($throw_exceptions) {
287
-            throw new EE_Error(
288
-                sprintf(
289
-                    esc_html__(
290
-                        'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
291
-                        'event_espresso'
292
-                    ),
293
-                    $this->message_type()
294
-                )
295
-            );
296
-        }
297
-        return false;
298
-    }
299
-
300
-
301
-    /**
302
-     * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects).
303
-     *
304
-     * @param bool $throw_exceptions
305
-     * @return bool
306
-     * @throws \EE_Error
307
-     */
308
-    public function is_valid($throw_exceptions = false)
309
-    {
310
-        if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) {
311
-            return true;
312
-        }
313
-        return false;
314
-    }
315
-
316
-
317
-    /**
318
-     * This validates whether the internal messenger and message type objects are valid for sending.
319
-     * Three checks are done:
320
-     * 1. There is a valid messenger object.
321
-     * 2. There is a valid message type object.
322
-     * 3. The message type object is active for the messenger.
323
-     *
324
-     * @throws EE_Error  But only if $throw_exceptions is set to true.
325
-     * @param bool $throw_exceptions
326
-     * @return bool
327
-     */
328
-    public function is_valid_for_sending_or_generation($throw_exceptions = false)
329
-    {
330
-        $valid = false;
331
-        if ($this->is_valid($throw_exceptions)) {
332
-            /** @var EE_Message_Resource_Manager $message_resource_manager */
333
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
334
-            $valid = $message_resource_manager->is_message_type_active_for_messenger(
335
-                $this->messenger(),
336
-                $this->message_type()
337
-            );
338
-            if (! $valid && $throw_exceptions) {
339
-                throw new EE_Error(
340
-                    sprintf(
341
-                        esc_html__(
342
-                            'The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.',
343
-                            'event_espresso'
344
-                        ),
345
-                        $this->message_type(),
346
-                        $this->messenger()
347
-                    )
348
-                );
349
-            }
350
-        }
351
-        return $valid;
352
-    }
353
-
354
-
355
-    /**
356
-     * This returns the set localized label for the message type on this message.
357
-     * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved
358
-     * with this message.
359
-     *
360
-     * @param   bool $plural whether to return the plural label or not.
361
-     * @return string
362
-     */
363
-    public function message_type_label($plural = false)
364
-    {
365
-        $label_type = $plural ? 'plural' : 'singular';
366
-        $message_type = $this->message_type_object();
367
-        return $message_type instanceof EE_message_type
368
-            ? $message_type->label[ $label_type ]
369
-            : str_replace(
370
-                '_',
371
-                ' ',
372
-                $this->message_type()
373
-            );
374
-    }
375
-
376
-
377
-    /**
378
-     * Gets context
379
-     *
380
-     * @return string
381
-     */
382
-    public function context()
383
-    {
384
-        return $this->get('MSG_context');
385
-    }
386
-
387
-
388
-    /**
389
-     * This returns the corresponding localized label for the given context slug, if possible from installed message
390
-     * types. Otherwise, this will just return the set context slug on this object.
391
-     *
392
-     * @return string
393
-     */
394
-    public function context_label()
395
-    {
396
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
397
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
398
-        $contexts = $message_resource_manager->get_all_contexts();
399
-        return isset($contexts[ $this->context() ]) ? $contexts[ $this->context() ] : $this->context();
400
-    }
401
-
402
-
403
-    /**
404
-     * Sets context
405
-     *
406
-     * @param string $context
407
-     */
408
-    public function set_context($context)
409
-    {
410
-        $this->set('MSG_context', $context);
411
-    }
412
-
413
-
414
-    /**
415
-     * Gets recipient_ID
416
-     *
417
-     * @return int
418
-     */
419
-    public function recipient_ID()
420
-    {
421
-        return $this->get('MSG_recipient_ID');
422
-    }
423
-
424
-
425
-    /**
426
-     * Sets recipient_ID
427
-     *
428
-     * @param string $recipient_ID
429
-     */
430
-    public function set_recipient_ID($recipient_ID)
431
-    {
432
-        $this->set('MSG_recipient_ID', $recipient_ID);
433
-    }
434
-
435
-
436
-    /**
437
-     * Gets recipient_type
438
-     *
439
-     * @return string
440
-     */
441
-    public function recipient_type()
442
-    {
443
-        return $this->get('MSG_recipient_type');
444
-    }
445
-
446
-
447
-    /**
448
-     * Return the related object matching the recipient type and ID.
449
-     *
450
-     * @return EE_Base_Class | null
451
-     */
452
-    public function recipient_object()
453
-    {
454
-        if (! $this->recipient_type() || ! $this->recipient_ID()) {
455
-            return null;
456
-        }
457
-
458
-        return $this->get_first_related($this->recipient_type());
459
-    }
460
-
461
-
462
-    /**
463
-     * Sets recipient_type
464
-     *
465
-     * @param string $recipient_type
466
-     */
467
-    public function set_recipient_type($recipient_type)
468
-    {
469
-        $this->set('MSG_recipient_type', $recipient_type);
470
-    }
471
-
472
-
473
-    /**
474
-     * Gets content
475
-     *
476
-     * @return string
477
-     */
478
-    public function content()
479
-    {
480
-        return $this->get('MSG_content');
481
-    }
482
-
483
-
484
-    /**
485
-     * Sets content
486
-     *
487
-     * @param string $content
488
-     */
489
-    public function set_content($content)
490
-    {
491
-        $this->set('MSG_content', $content);
492
-    }
493
-
494
-
495
-    /**
496
-     * Gets subject
497
-     *
498
-     * @return string
499
-     */
500
-    public function subject()
501
-    {
502
-        return $this->get('MSG_subject');
503
-    }
504
-
505
-
506
-    /**
507
-     * Sets subject
508
-     *
509
-     * @param string $subject
510
-     */
511
-    public function set_subject($subject)
512
-    {
513
-        $this->set('MSG_subject', $subject);
514
-    }
515
-
516
-
517
-    /**
518
-     * Gets to
519
-     *
520
-     * @return string
521
-     */
522
-    public function to()
523
-    {
524
-        $to = $this->get('MSG_to');
525
-        return empty($to) ? esc_html__('No recipient', 'event_espresso') : $to;
526
-    }
527
-
528
-
529
-    /**
530
-     * Sets to
531
-     *
532
-     * @param string $to
533
-     */
534
-    public function set_to($to)
535
-    {
536
-        $this->set('MSG_to', $to);
537
-    }
538
-
539
-
540
-    /**
541
-     * Gets from
542
-     *
543
-     * @return string
544
-     */
545
-    public function from()
546
-    {
547
-        return $this->get('MSG_from');
548
-    }
549
-
550
-
551
-    /**
552
-     * Sets from
553
-     *
554
-     * @param string $from
555
-     */
556
-    public function set_from($from)
557
-    {
558
-        $this->set('MSG_from', $from);
559
-    }
560
-
561
-
562
-    /**
563
-     * Gets priority
564
-     *
565
-     * @return int
566
-     */
567
-    public function priority()
568
-    {
569
-        return $this->get('MSG_priority');
570
-    }
571
-
572
-
573
-    /**
574
-     * Sets priority
575
-     * Note.  Send Now Messengers always override any priority that may be set on a Message.  So
576
-     * this method calls the send_now method to verify that.
577
-     *
578
-     * @param int $priority
579
-     */
580
-    public function set_priority($priority)
581
-    {
582
-        $priority = $this->send_now() ? EEM_Message::priority_high : $priority;
583
-        parent::set('MSG_priority', $priority);
584
-    }
585
-
586
-
587
-    /**
588
-     * Overrides parent::set method so we can capture any sets for priority.
589
-     *
590
-     * @see parent::set() for phpdocs
591
-     * @param string $field_name
592
-     * @param mixed  $field_value
593
-     * @param bool   $use_default
594
-     * @throws EE_Error
595
-     */
596
-    public function set($field_name, $field_value, $use_default = false)
597
-    {
598
-        if ($field_name === 'MSG_priority') {
599
-            $this->set_priority($field_value);
600
-        }
601
-        parent::set($field_name, $field_value, $use_default);
602
-    }
603
-
604
-
605
-    /**
606
-     * @return bool
607
-     * @throws \EE_Error
608
-     */
609
-    public function send_now()
610
-    {
611
-        $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high
612
-            : $this->priority();
613
-        return $send_now === EEM_Message::priority_high ? true : false;
614
-    }
615
-
616
-
617
-    /**
618
-     * Gets STS_ID
619
-     *
620
-     * @return string
621
-     */
622
-    public function STS_ID()
623
-    {
624
-        return $this->get('STS_ID');
625
-    }
626
-
627
-
628
-    /**
629
-     * Sets STS_ID
630
-     *
631
-     * @param string $STS_ID
632
-     */
633
-    public function set_STS_ID($STS_ID)
634
-    {
635
-        $this->set('STS_ID', $STS_ID);
636
-    }
637
-
638
-
639
-    /**
640
-     * Gets created
641
-     *
642
-     * @return string
643
-     */
644
-    public function created()
645
-    {
646
-        return $this->get('MSG_created');
647
-    }
648
-
649
-
650
-    /**
651
-     * Sets created
652
-     *
653
-     * @param string $created
654
-     */
655
-    public function set_created($created)
656
-    {
657
-        $this->set('MSG_created', $created);
658
-    }
659
-
660
-
661
-    /**
662
-     * Gets modified
663
-     *
664
-     * @return string
665
-     */
666
-    public function modified()
667
-    {
668
-        return $this->get('MSG_modified');
669
-    }
670
-
671
-
672
-    /**
673
-     * Sets modified
674
-     *
675
-     * @param string $modified
676
-     */
677
-    public function set_modified($modified)
678
-    {
679
-        $this->set('MSG_modified', $modified);
680
-    }
681
-
682
-
683
-    /**
684
-     * Sets generation data for this message.
685
-     *
686
-     * @param mixed $data
687
-     */
688
-    public function set_generation_data($data)
689
-    {
690
-        $this->set_field_or_extra_meta('MSG_generation_data', $data);
691
-    }
692
-
693
-
694
-    /**
695
-     * Returns any set generation data for this message.
696
-     *
697
-     * @return mixed|null
698
-     */
699
-    public function get_generation_data()
700
-    {
701
-        return $this->get_field_or_extra_meta('MSG_generation_data');
702
-    }
703
-
704
-
705
-    /**
706
-     * Gets any error message.
707
-     *
708
-     * @return mixed|null
709
-     */
710
-    public function error_message()
711
-    {
712
-        return $this->get_field_or_extra_meta('MSG_error');
713
-    }
714
-
715
-
716
-    /**
717
-     * Sets an error message.
718
-     *
719
-     * @param $message
720
-     * @return bool|int
721
-     */
722
-    public function set_error_message($message)
723
-    {
724
-        return $this->set_field_or_extra_meta('MSG_error', $message);
725
-    }
726
-
727
-
728
-    /**
729
-     * This retrieves the associated template pack with this message.
730
-     *
731
-     * @return EE_Messages_Template_Pack | null
732
-     */
733
-    public function get_template_pack()
734
-    {
735
-        /**
736
-         * This is deprecated functionality that will be removed eventually but included here now for backward compat.
737
-         */
738
-        if (! empty($this->template_pack)) {
739
-            return $this->template_pack;
740
-        }
741
-        /** @type EE_Message_Template_Group $grp */
742
-        $grp = $this->get_first_related('Message_Template_Group');
743
-        // if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
744
-        if (! $grp instanceof EE_Message_Template_Group) {
745
-            $grp = EEM_Message_Template_Group::instance()->get_one(
746
-                array(
747
-                    array(
748
-                        'MTP_messenger'    => $this->messenger(),
749
-                        'MTP_message_type' => $this->message_type(),
750
-                        'MTP_is_global'    => true,
751
-                    ),
752
-                )
753
-            );
754
-        }
755
-
756
-        return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null;
757
-    }
758
-
759
-
760
-    /**
761
-     * Retrieves the variation used for generating this message.
762
-     *
763
-     * @return string
764
-     */
765
-    public function get_template_pack_variation()
766
-    {
767
-        /**
768
-         * This is deprecated functionality that will be removed eventually but included here now for backward compat.
769
-         */
770
-        if (! empty($this->template_variation)) {
771
-            return $this->template_variation;
772
-        }
773
-
774
-        /** @type EE_Message_Template_Group $grp */
775
-        $grp = $this->get_first_related('Message_Template_Group');
776
-
777
-        // if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
778
-        if (! $grp instanceof EE_Message_Template_Group) {
779
-            $grp = EEM_Message_Template_Group::instance()->get_one(
780
-                array(
781
-                    array(
782
-                        'MTP_messenger'    => $this->messenger(),
783
-                        'MTP_message_type' => $this->message_type(),
784
-                        'MTP_is_global'    => true,
785
-                    ),
786
-                )
787
-            );
788
-        }
789
-
790
-        return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : '';
791
-    }
792
-
793
-    /**
794
-     * Return the link to the admin details for the object.
795
-     *
796
-     * @return string
797
-     */
798
-    public function get_admin_details_link()
799
-    {
800
-        EE_Registry::instance()->load_helper('URL');
801
-        EE_Registry::instance()->load_helper('MSG_Template');
802
-        switch ($this->STS_ID()) {
803
-            case EEM_Message::status_failed:
804
-            case EEM_Message::status_debug_only:
805
-                return EEH_MSG_Template::generate_error_display_trigger($this);
806
-                break;
807
-
808
-            case EEM_Message::status_sent:
809
-                return EEH_MSG_Template::generate_browser_trigger($this);
810
-                break;
811
-
812
-            default:
813
-                return '';
814
-        }
815
-    }
816
-
817
-    /**
818
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
819
-     *
820
-     * @return string
821
-     */
822
-    public function get_admin_edit_link()
823
-    {
824
-        return $this->get_admin_details_link();
825
-    }
826
-
827
-    /**
828
-     * Returns the link to a settings page for the object.
829
-     *
830
-     * @return string
831
-     */
832
-    public function get_admin_settings_link()
833
-    {
834
-        EE_Registry::instance()->load_helper('URL');
835
-        return EEH_URL::add_query_args_and_nonce(
836
-            array(
837
-                'page'   => 'espresso_messages',
838
-                'action' => 'settings',
839
-            ),
840
-            admin_url('admin.php')
841
-        );
842
-    }
843
-
844
-    /**
845
-     * Returns the link to the "overview" for the object (typically the "list table" view).
846
-     *
847
-     * @return string
848
-     */
849
-    public function get_admin_overview_link()
850
-    {
851
-        EE_Registry::instance()->load_helper('URL');
852
-        return EEH_URL::add_query_args_and_nonce(
853
-            array(
854
-                'page'   => 'espresso_messages',
855
-                'action' => 'default',
856
-            ),
857
-            admin_url('admin.php')
858
-        );
859
-    }
860
-
861
-
862
-    /**
863
-     * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for
864
-     * it.
865
-     * Note this also SAVES the current message object to the db because it adds an error message to accompany the
866
-     * status.
867
-     *
868
-     */
869
-    public function set_messenger_is_executing()
870
-    {
871
-        $this->set_STS_ID(EEM_Message::status_messenger_executing);
872
-        if (EEM_Message::debug()) {
873
-            $this->set_error_message(
874
-                esc_html__(
875
-                    'A message with this status indicates that there was a problem that occurred while the message was being
12
+	/**
13
+	 * @deprecated 4.9.0  Added for backward compat with add-on's
14
+	 * @type null
15
+	 */
16
+	public $template_pack;
17
+
18
+	/**
19
+	 * @deprecated 4.9.0 Added for backward compat with add-on's
20
+	 * @type null
21
+	 */
22
+	public $template_variation;
23
+
24
+	/**
25
+	 * @deprecated 4.9.0 Added for backward compat with add-on's
26
+	 * @type string
27
+	 */
28
+	public $content = '';
29
+
30
+
31
+	/**
32
+	 * @type EE_messenger $_messenger
33
+	 */
34
+	protected $_messenger = null;
35
+
36
+	/**
37
+	 * @type EE_message_type $_message_type
38
+	 */
39
+	protected $_message_type = null;
40
+
41
+
42
+	/**
43
+	 * @param array  $props_n_values
44
+	 * @param string $timezone
45
+	 * @param array  $date_formats incoming date formats in an array.  First value is the date_format, second is time
46
+	 *                             format.
47
+	 * @return EE_Message
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__);
52
+		// if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
53
+		if (! $has_object) {
54
+			EE_Registry::instance()->load_helper('URL');
55
+			$props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
56
+		}
57
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
58
+	}
59
+
60
+
61
+	/**
62
+	 * @param array  $props_n_values
63
+	 * @param string $timezone
64
+	 * @return EE_Message
65
+	 */
66
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
67
+	{
68
+		return new self($props_n_values, true, $timezone);
69
+	}
70
+
71
+
72
+	/**
73
+	 * Gets MSG_token
74
+	 *
75
+	 * @return int
76
+	 */
77
+	public function MSG_token()
78
+	{
79
+		return $this->get('MSG_token');
80
+	}
81
+
82
+
83
+	/**
84
+	 * Sets MSG_token
85
+	 *
86
+	 * @param int $MSG_token
87
+	 */
88
+	public function set_MSG_token($MSG_token)
89
+	{
90
+		$this->set('MSG_token', $MSG_token);
91
+	}
92
+
93
+
94
+	/**
95
+	 * Gets GRP_ID
96
+	 *
97
+	 * @return int
98
+	 */
99
+	public function GRP_ID()
100
+	{
101
+		return $this->get('GRP_ID');
102
+	}
103
+
104
+
105
+	/**
106
+	 * Sets GRP_ID
107
+	 *
108
+	 * @param int $GRP_ID
109
+	 */
110
+	public function set_GRP_ID($GRP_ID)
111
+	{
112
+		$this->set('GRP_ID', $GRP_ID);
113
+	}
114
+
115
+
116
+	/**
117
+	 * Gets TXN_ID
118
+	 *
119
+	 * @return int
120
+	 */
121
+	public function TXN_ID()
122
+	{
123
+		return $this->get('TXN_ID');
124
+	}
125
+
126
+
127
+	/**
128
+	 * Sets TXN_ID
129
+	 *
130
+	 * @param int $TXN_ID
131
+	 */
132
+	public function set_TXN_ID($TXN_ID)
133
+	{
134
+		$this->set('TXN_ID', $TXN_ID);
135
+	}
136
+
137
+
138
+	/**
139
+	 * Gets messenger
140
+	 *
141
+	 * @return string
142
+	 */
143
+	public function messenger()
144
+	{
145
+		return $this->get('MSG_messenger');
146
+	}
147
+
148
+
149
+	/**
150
+	 * Sets messenger
151
+	 *
152
+	 * @param string $messenger
153
+	 */
154
+	public function set_messenger($messenger)
155
+	{
156
+		$this->set('MSG_messenger', $messenger);
157
+	}
158
+
159
+
160
+	/**
161
+	 * Returns corresponding messenger object for the set messenger on this message
162
+	 *
163
+	 * @return EE_messenger | null
164
+	 */
165
+	public function messenger_object()
166
+	{
167
+		return $this->_messenger;
168
+	}
169
+
170
+
171
+	/**
172
+	 * Sets messenger
173
+	 *
174
+	 * @param EE_messenger $messenger
175
+	 */
176
+	public function set_messenger_object(EE_messenger $messenger)
177
+	{
178
+		$this->_messenger = $messenger;
179
+	}
180
+
181
+
182
+	/**
183
+	 * validates messenger
184
+	 *
185
+	 * @param bool $throw_exceptions
186
+	 * @return bool
187
+	 * @throws \EE_Error
188
+	 */
189
+	public function valid_messenger($throw_exceptions = false)
190
+	{
191
+		if ($this->_messenger instanceof EE_messenger) {
192
+			return true;
193
+		}
194
+		if ($throw_exceptions) {
195
+			throw new EE_Error(
196
+				sprintf(
197
+					esc_html__(
198
+						'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
199
+						'event_espresso'
200
+					),
201
+					$this->messenger()
202
+				)
203
+			);
204
+		}
205
+		return false;
206
+	}
207
+
208
+
209
+	/**
210
+	 * This returns the set localized label for the messenger on this message.
211
+	 * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved
212
+	 * with this message.
213
+	 *
214
+	 * @param   bool $plural whether to return the plural label or not.
215
+	 * @return string
216
+	 */
217
+	public function messenger_label($plural = false)
218
+	{
219
+		$label_type = $plural ? 'plural' : 'singular';
220
+		$messenger = $this->messenger_object();
221
+		return $messenger instanceof EE_messenger ? $messenger->label[ $label_type ] : $this->messenger();
222
+	}
223
+
224
+
225
+	/**
226
+	 * Gets message_type
227
+	 *
228
+	 * @return string
229
+	 */
230
+	public function message_type()
231
+	{
232
+		return $this->get('MSG_message_type');
233
+	}
234
+
235
+
236
+	/**
237
+	 * Sets message_type
238
+	 *
239
+	 * @param string $message_type
240
+	 */
241
+	public function set_message_type($message_type)
242
+	{
243
+		$this->set('MSG_message_type', $message_type);
244
+	}
245
+
246
+
247
+	/**
248
+	 * Returns the message type object for the set message type on this message
249
+	 *
250
+	 * @return EE_message_type | null
251
+	 */
252
+	public function message_type_object()
253
+	{
254
+		return $this->_message_type;
255
+	}
256
+
257
+
258
+	/**
259
+	 * Sets message_type
260
+	 *
261
+	 * @param EE_message_type $message_type
262
+	 * @param bool            $set_priority   This indicates whether to set the priority to whatever the priority is on
263
+	 *                                        the message type or not.
264
+	 */
265
+	public function set_message_type_object(EE_message_type $message_type, $set_priority = false)
266
+	{
267
+		$this->_message_type = $message_type;
268
+		if ($set_priority) {
269
+			$this->set_priority($this->_message_type->get_priority());
270
+		}
271
+	}
272
+
273
+
274
+	/**
275
+	 * validates message_type
276
+	 *
277
+	 * @param bool $throw_exceptions
278
+	 * @return bool
279
+	 * @throws \EE_Error
280
+	 */
281
+	public function valid_message_type($throw_exceptions = false)
282
+	{
283
+		if ($this->_message_type instanceof EE_message_type) {
284
+			return true;
285
+		}
286
+		if ($throw_exceptions) {
287
+			throw new EE_Error(
288
+				sprintf(
289
+					esc_html__(
290
+						'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
291
+						'event_espresso'
292
+					),
293
+					$this->message_type()
294
+				)
295
+			);
296
+		}
297
+		return false;
298
+	}
299
+
300
+
301
+	/**
302
+	 * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects).
303
+	 *
304
+	 * @param bool $throw_exceptions
305
+	 * @return bool
306
+	 * @throws \EE_Error
307
+	 */
308
+	public function is_valid($throw_exceptions = false)
309
+	{
310
+		if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) {
311
+			return true;
312
+		}
313
+		return false;
314
+	}
315
+
316
+
317
+	/**
318
+	 * This validates whether the internal messenger and message type objects are valid for sending.
319
+	 * Three checks are done:
320
+	 * 1. There is a valid messenger object.
321
+	 * 2. There is a valid message type object.
322
+	 * 3. The message type object is active for the messenger.
323
+	 *
324
+	 * @throws EE_Error  But only if $throw_exceptions is set to true.
325
+	 * @param bool $throw_exceptions
326
+	 * @return bool
327
+	 */
328
+	public function is_valid_for_sending_or_generation($throw_exceptions = false)
329
+	{
330
+		$valid = false;
331
+		if ($this->is_valid($throw_exceptions)) {
332
+			/** @var EE_Message_Resource_Manager $message_resource_manager */
333
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
334
+			$valid = $message_resource_manager->is_message_type_active_for_messenger(
335
+				$this->messenger(),
336
+				$this->message_type()
337
+			);
338
+			if (! $valid && $throw_exceptions) {
339
+				throw new EE_Error(
340
+					sprintf(
341
+						esc_html__(
342
+							'The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.',
343
+							'event_espresso'
344
+						),
345
+						$this->message_type(),
346
+						$this->messenger()
347
+					)
348
+				);
349
+			}
350
+		}
351
+		return $valid;
352
+	}
353
+
354
+
355
+	/**
356
+	 * This returns the set localized label for the message type on this message.
357
+	 * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved
358
+	 * with this message.
359
+	 *
360
+	 * @param   bool $plural whether to return the plural label or not.
361
+	 * @return string
362
+	 */
363
+	public function message_type_label($plural = false)
364
+	{
365
+		$label_type = $plural ? 'plural' : 'singular';
366
+		$message_type = $this->message_type_object();
367
+		return $message_type instanceof EE_message_type
368
+			? $message_type->label[ $label_type ]
369
+			: str_replace(
370
+				'_',
371
+				' ',
372
+				$this->message_type()
373
+			);
374
+	}
375
+
376
+
377
+	/**
378
+	 * Gets context
379
+	 *
380
+	 * @return string
381
+	 */
382
+	public function context()
383
+	{
384
+		return $this->get('MSG_context');
385
+	}
386
+
387
+
388
+	/**
389
+	 * This returns the corresponding localized label for the given context slug, if possible from installed message
390
+	 * types. Otherwise, this will just return the set context slug on this object.
391
+	 *
392
+	 * @return string
393
+	 */
394
+	public function context_label()
395
+	{
396
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
397
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
398
+		$contexts = $message_resource_manager->get_all_contexts();
399
+		return isset($contexts[ $this->context() ]) ? $contexts[ $this->context() ] : $this->context();
400
+	}
401
+
402
+
403
+	/**
404
+	 * Sets context
405
+	 *
406
+	 * @param string $context
407
+	 */
408
+	public function set_context($context)
409
+	{
410
+		$this->set('MSG_context', $context);
411
+	}
412
+
413
+
414
+	/**
415
+	 * Gets recipient_ID
416
+	 *
417
+	 * @return int
418
+	 */
419
+	public function recipient_ID()
420
+	{
421
+		return $this->get('MSG_recipient_ID');
422
+	}
423
+
424
+
425
+	/**
426
+	 * Sets recipient_ID
427
+	 *
428
+	 * @param string $recipient_ID
429
+	 */
430
+	public function set_recipient_ID($recipient_ID)
431
+	{
432
+		$this->set('MSG_recipient_ID', $recipient_ID);
433
+	}
434
+
435
+
436
+	/**
437
+	 * Gets recipient_type
438
+	 *
439
+	 * @return string
440
+	 */
441
+	public function recipient_type()
442
+	{
443
+		return $this->get('MSG_recipient_type');
444
+	}
445
+
446
+
447
+	/**
448
+	 * Return the related object matching the recipient type and ID.
449
+	 *
450
+	 * @return EE_Base_Class | null
451
+	 */
452
+	public function recipient_object()
453
+	{
454
+		if (! $this->recipient_type() || ! $this->recipient_ID()) {
455
+			return null;
456
+		}
457
+
458
+		return $this->get_first_related($this->recipient_type());
459
+	}
460
+
461
+
462
+	/**
463
+	 * Sets recipient_type
464
+	 *
465
+	 * @param string $recipient_type
466
+	 */
467
+	public function set_recipient_type($recipient_type)
468
+	{
469
+		$this->set('MSG_recipient_type', $recipient_type);
470
+	}
471
+
472
+
473
+	/**
474
+	 * Gets content
475
+	 *
476
+	 * @return string
477
+	 */
478
+	public function content()
479
+	{
480
+		return $this->get('MSG_content');
481
+	}
482
+
483
+
484
+	/**
485
+	 * Sets content
486
+	 *
487
+	 * @param string $content
488
+	 */
489
+	public function set_content($content)
490
+	{
491
+		$this->set('MSG_content', $content);
492
+	}
493
+
494
+
495
+	/**
496
+	 * Gets subject
497
+	 *
498
+	 * @return string
499
+	 */
500
+	public function subject()
501
+	{
502
+		return $this->get('MSG_subject');
503
+	}
504
+
505
+
506
+	/**
507
+	 * Sets subject
508
+	 *
509
+	 * @param string $subject
510
+	 */
511
+	public function set_subject($subject)
512
+	{
513
+		$this->set('MSG_subject', $subject);
514
+	}
515
+
516
+
517
+	/**
518
+	 * Gets to
519
+	 *
520
+	 * @return string
521
+	 */
522
+	public function to()
523
+	{
524
+		$to = $this->get('MSG_to');
525
+		return empty($to) ? esc_html__('No recipient', 'event_espresso') : $to;
526
+	}
527
+
528
+
529
+	/**
530
+	 * Sets to
531
+	 *
532
+	 * @param string $to
533
+	 */
534
+	public function set_to($to)
535
+	{
536
+		$this->set('MSG_to', $to);
537
+	}
538
+
539
+
540
+	/**
541
+	 * Gets from
542
+	 *
543
+	 * @return string
544
+	 */
545
+	public function from()
546
+	{
547
+		return $this->get('MSG_from');
548
+	}
549
+
550
+
551
+	/**
552
+	 * Sets from
553
+	 *
554
+	 * @param string $from
555
+	 */
556
+	public function set_from($from)
557
+	{
558
+		$this->set('MSG_from', $from);
559
+	}
560
+
561
+
562
+	/**
563
+	 * Gets priority
564
+	 *
565
+	 * @return int
566
+	 */
567
+	public function priority()
568
+	{
569
+		return $this->get('MSG_priority');
570
+	}
571
+
572
+
573
+	/**
574
+	 * Sets priority
575
+	 * Note.  Send Now Messengers always override any priority that may be set on a Message.  So
576
+	 * this method calls the send_now method to verify that.
577
+	 *
578
+	 * @param int $priority
579
+	 */
580
+	public function set_priority($priority)
581
+	{
582
+		$priority = $this->send_now() ? EEM_Message::priority_high : $priority;
583
+		parent::set('MSG_priority', $priority);
584
+	}
585
+
586
+
587
+	/**
588
+	 * Overrides parent::set method so we can capture any sets for priority.
589
+	 *
590
+	 * @see parent::set() for phpdocs
591
+	 * @param string $field_name
592
+	 * @param mixed  $field_value
593
+	 * @param bool   $use_default
594
+	 * @throws EE_Error
595
+	 */
596
+	public function set($field_name, $field_value, $use_default = false)
597
+	{
598
+		if ($field_name === 'MSG_priority') {
599
+			$this->set_priority($field_value);
600
+		}
601
+		parent::set($field_name, $field_value, $use_default);
602
+	}
603
+
604
+
605
+	/**
606
+	 * @return bool
607
+	 * @throws \EE_Error
608
+	 */
609
+	public function send_now()
610
+	{
611
+		$send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high
612
+			: $this->priority();
613
+		return $send_now === EEM_Message::priority_high ? true : false;
614
+	}
615
+
616
+
617
+	/**
618
+	 * Gets STS_ID
619
+	 *
620
+	 * @return string
621
+	 */
622
+	public function STS_ID()
623
+	{
624
+		return $this->get('STS_ID');
625
+	}
626
+
627
+
628
+	/**
629
+	 * Sets STS_ID
630
+	 *
631
+	 * @param string $STS_ID
632
+	 */
633
+	public function set_STS_ID($STS_ID)
634
+	{
635
+		$this->set('STS_ID', $STS_ID);
636
+	}
637
+
638
+
639
+	/**
640
+	 * Gets created
641
+	 *
642
+	 * @return string
643
+	 */
644
+	public function created()
645
+	{
646
+		return $this->get('MSG_created');
647
+	}
648
+
649
+
650
+	/**
651
+	 * Sets created
652
+	 *
653
+	 * @param string $created
654
+	 */
655
+	public function set_created($created)
656
+	{
657
+		$this->set('MSG_created', $created);
658
+	}
659
+
660
+
661
+	/**
662
+	 * Gets modified
663
+	 *
664
+	 * @return string
665
+	 */
666
+	public function modified()
667
+	{
668
+		return $this->get('MSG_modified');
669
+	}
670
+
671
+
672
+	/**
673
+	 * Sets modified
674
+	 *
675
+	 * @param string $modified
676
+	 */
677
+	public function set_modified($modified)
678
+	{
679
+		$this->set('MSG_modified', $modified);
680
+	}
681
+
682
+
683
+	/**
684
+	 * Sets generation data for this message.
685
+	 *
686
+	 * @param mixed $data
687
+	 */
688
+	public function set_generation_data($data)
689
+	{
690
+		$this->set_field_or_extra_meta('MSG_generation_data', $data);
691
+	}
692
+
693
+
694
+	/**
695
+	 * Returns any set generation data for this message.
696
+	 *
697
+	 * @return mixed|null
698
+	 */
699
+	public function get_generation_data()
700
+	{
701
+		return $this->get_field_or_extra_meta('MSG_generation_data');
702
+	}
703
+
704
+
705
+	/**
706
+	 * Gets any error message.
707
+	 *
708
+	 * @return mixed|null
709
+	 */
710
+	public function error_message()
711
+	{
712
+		return $this->get_field_or_extra_meta('MSG_error');
713
+	}
714
+
715
+
716
+	/**
717
+	 * Sets an error message.
718
+	 *
719
+	 * @param $message
720
+	 * @return bool|int
721
+	 */
722
+	public function set_error_message($message)
723
+	{
724
+		return $this->set_field_or_extra_meta('MSG_error', $message);
725
+	}
726
+
727
+
728
+	/**
729
+	 * This retrieves the associated template pack with this message.
730
+	 *
731
+	 * @return EE_Messages_Template_Pack | null
732
+	 */
733
+	public function get_template_pack()
734
+	{
735
+		/**
736
+		 * This is deprecated functionality that will be removed eventually but included here now for backward compat.
737
+		 */
738
+		if (! empty($this->template_pack)) {
739
+			return $this->template_pack;
740
+		}
741
+		/** @type EE_Message_Template_Group $grp */
742
+		$grp = $this->get_first_related('Message_Template_Group');
743
+		// if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
744
+		if (! $grp instanceof EE_Message_Template_Group) {
745
+			$grp = EEM_Message_Template_Group::instance()->get_one(
746
+				array(
747
+					array(
748
+						'MTP_messenger'    => $this->messenger(),
749
+						'MTP_message_type' => $this->message_type(),
750
+						'MTP_is_global'    => true,
751
+					),
752
+				)
753
+			);
754
+		}
755
+
756
+		return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null;
757
+	}
758
+
759
+
760
+	/**
761
+	 * Retrieves the variation used for generating this message.
762
+	 *
763
+	 * @return string
764
+	 */
765
+	public function get_template_pack_variation()
766
+	{
767
+		/**
768
+		 * This is deprecated functionality that will be removed eventually but included here now for backward compat.
769
+		 */
770
+		if (! empty($this->template_variation)) {
771
+			return $this->template_variation;
772
+		}
773
+
774
+		/** @type EE_Message_Template_Group $grp */
775
+		$grp = $this->get_first_related('Message_Template_Group');
776
+
777
+		// if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
778
+		if (! $grp instanceof EE_Message_Template_Group) {
779
+			$grp = EEM_Message_Template_Group::instance()->get_one(
780
+				array(
781
+					array(
782
+						'MTP_messenger'    => $this->messenger(),
783
+						'MTP_message_type' => $this->message_type(),
784
+						'MTP_is_global'    => true,
785
+					),
786
+				)
787
+			);
788
+		}
789
+
790
+		return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : '';
791
+	}
792
+
793
+	/**
794
+	 * Return the link to the admin details for the object.
795
+	 *
796
+	 * @return string
797
+	 */
798
+	public function get_admin_details_link()
799
+	{
800
+		EE_Registry::instance()->load_helper('URL');
801
+		EE_Registry::instance()->load_helper('MSG_Template');
802
+		switch ($this->STS_ID()) {
803
+			case EEM_Message::status_failed:
804
+			case EEM_Message::status_debug_only:
805
+				return EEH_MSG_Template::generate_error_display_trigger($this);
806
+				break;
807
+
808
+			case EEM_Message::status_sent:
809
+				return EEH_MSG_Template::generate_browser_trigger($this);
810
+				break;
811
+
812
+			default:
813
+				return '';
814
+		}
815
+	}
816
+
817
+	/**
818
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
819
+	 *
820
+	 * @return string
821
+	 */
822
+	public function get_admin_edit_link()
823
+	{
824
+		return $this->get_admin_details_link();
825
+	}
826
+
827
+	/**
828
+	 * Returns the link to a settings page for the object.
829
+	 *
830
+	 * @return string
831
+	 */
832
+	public function get_admin_settings_link()
833
+	{
834
+		EE_Registry::instance()->load_helper('URL');
835
+		return EEH_URL::add_query_args_and_nonce(
836
+			array(
837
+				'page'   => 'espresso_messages',
838
+				'action' => 'settings',
839
+			),
840
+			admin_url('admin.php')
841
+		);
842
+	}
843
+
844
+	/**
845
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
846
+	 *
847
+	 * @return string
848
+	 */
849
+	public function get_admin_overview_link()
850
+	{
851
+		EE_Registry::instance()->load_helper('URL');
852
+		return EEH_URL::add_query_args_and_nonce(
853
+			array(
854
+				'page'   => 'espresso_messages',
855
+				'action' => 'default',
856
+			),
857
+			admin_url('admin.php')
858
+		);
859
+	}
860
+
861
+
862
+	/**
863
+	 * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for
864
+	 * it.
865
+	 * Note this also SAVES the current message object to the db because it adds an error message to accompany the
866
+	 * status.
867
+	 *
868
+	 */
869
+	public function set_messenger_is_executing()
870
+	{
871
+		$this->set_STS_ID(EEM_Message::status_messenger_executing);
872
+		if (EEM_Message::debug()) {
873
+			$this->set_error_message(
874
+				esc_html__(
875
+					'A message with this status indicates that there was a problem that occurred while the message was being
876 876
                     processed by the messenger.  It is still possible that the message was sent successfully, but at some
877 877
                     point during the processing there was a failure.  This usually is indicative of a timeout issue with PHP 
878 878
                     or memory limits being reached.  If you see this repeatedly you may want to consider upgrading the memory 
879 879
                     available to PHP on your server.',
880
-                    'event_espresso'
881
-                )
882
-            );
883
-        }
884
-    }
880
+					'event_espresso'
881
+				)
882
+			);
883
+		}
884
+	}
885 885
 }
Please login to merge, or discard this patch.
modules/single_page_checkout/inc/EE_SPCO_JSON_Response.php 1 patch
Indentation   +397 added lines, -397 removed lines patch added patch discarded remove patch
@@ -14,401 +14,401 @@
 block discarded – undo
14 14
  */
15 15
 class EE_SPCO_JSON_Response
16 16
 {
17
-    /**
18
-     * @var string
19
-     */
20
-    protected $_errors = '';
21
-
22
-    /**
23
-     * @var string
24
-     */
25
-    protected $_unexpected_errors = '';
26
-
27
-    /**
28
-     * @var string
29
-     */
30
-    protected $_attention = '';
31
-
32
-    /**
33
-     * @var string
34
-     */
35
-    protected $_success = '';
36
-
37
-    /**
38
-     * @var string
39
-     */
40
-    protected $_plz_select_method_of_payment = '';
41
-
42
-    /**
43
-     * @var string
44
-     */
45
-    protected $_redirect_url = '';
46
-
47
-    /**
48
-     * @var string
49
-     */
50
-    protected $_registration_time_limit = '';
51
-
52
-    /**
53
-     * @var string
54
-     */
55
-    protected $_redirect_form = '';
56
-
57
-    /**
58
-     * @var string
59
-     */
60
-    protected $_reg_step_html = '';
61
-
62
-    /**
63
-     * @var string
64
-     */
65
-    protected $_method_of_payment = '';
66
-
67
-    /**
68
-     * @var float
69
-     */
70
-    protected $_payment_amount;
71
-
72
-    /**
73
-     * @var array
74
-     */
75
-    protected $_return_data = array();
76
-
77
-
78
-    /**
79
-     * @var array
80
-     */
81
-    protected $_validation_rules = array();
82
-
83
-
84
-    /**
85
-     *    class constructor
86
-     */
87
-    public function __construct()
88
-    {
89
-    }
90
-
91
-
92
-    /**
93
-     *    __toString
94
-     *
95
-     *        allows you to simply echo or print an EE_SPCO_JSON_Response object to produce a  JSON encoded string
96
-     *
97
-     * @access    public
98
-     * @return    string
99
-     */
100
-    public function __toString()
101
-    {
102
-        $JSON_response = array();
103
-        // grab notices
104
-        $notices = EE_Error::get_notices(false);
105
-        $this->set_attention(isset($notices['attention']) ? $notices['attention'] : '');
106
-        $this->set_errors(isset($notices['errors']) ? $notices['errors'] : '');
107
-        $this->set_success(isset($notices['success']) ? $notices['success'] : '');
108
-        // add notices to JSON response, but only if they exist
109
-        if ($this->attention()) {
110
-            $JSON_response['attention'] = $this->attention();
111
-        }
112
-        if ($this->errors()) {
113
-            $JSON_response['errors'] = $this->errors();
114
-        }
115
-        if ($this->unexpected_errors()) {
116
-            $JSON_response['unexpected_errors'] = $this->unexpected_errors();
117
-        }
118
-        if ($this->success()) {
119
-            $JSON_response['success'] = $this->success();
120
-        }
121
-        // but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked
122
-        if (! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) {
123
-            $JSON_response['success'] = null;
124
-        }
125
-        // set redirect_url, IF it exists
126
-        if ($this->redirect_url()) {
127
-            $JSON_response['redirect_url'] = $this->redirect_url();
128
-        }
129
-        // set registration_time_limit, IF it exists
130
-        if ($this->registration_time_limit()) {
131
-            $JSON_response['registration_time_limit'] = $this->registration_time_limit();
132
-        }
133
-        // set payment_amount, IF it exists
134
-        if ($this->payment_amount() !== null) {
135
-            $JSON_response['payment_amount'] = $this->payment_amount();
136
-        }
137
-        // grab generic return data
138
-        $return_data = $this->return_data();
139
-        // add billing form validation rules
140
-        if ($this->validation_rules()) {
141
-            $return_data['validation_rules'] = $this->validation_rules();
142
-        }
143
-        // set reg_step_html, IF it exists
144
-        if ($this->reg_step_html()) {
145
-            $return_data['reg_step_html'] = $this->reg_step_html();
146
-        }
147
-        // set method of payment, IF it exists
148
-        if ($this->method_of_payment()) {
149
-            $return_data['method_of_payment'] = $this->method_of_payment();
150
-        }
151
-        // set "plz_select_method_of_payment" message, IF it exists
152
-        if ($this->plz_select_method_of_payment()) {
153
-            $return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment();
154
-        }
155
-        // set redirect_form, IF it exists
156
-        if ($this->redirect_form()) {
157
-            $return_data['redirect_form'] = $this->redirect_form();
158
-        }
159
-        // and finally, add return_data array to main JSON response array, IF it contains anything
160
-        // why did we add some of the above properties to the return data array?
161
-        // because it is easier and cleaner in the Javascript to deal with this way
162
-        if (! empty($return_data)) {
163
-            $JSON_response['return_data'] = $return_data;
164
-        }
165
-        // filter final array
166
-        $JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response);
167
-        // return encoded array
168
-        return (string) wp_json_encode($JSON_response);
169
-    }
170
-
171
-
172
-    /**
173
-     * @param string $attention
174
-     */
175
-    public function set_attention($attention)
176
-    {
177
-        $this->_attention = $attention;
178
-    }
179
-
180
-
181
-    /**
182
-     * @return string
183
-     */
184
-    public function attention()
185
-    {
186
-        return $this->_attention;
187
-    }
188
-
189
-
190
-    /**
191
-     * @param string $errors
192
-     */
193
-    public function set_errors($errors)
194
-    {
195
-        $this->_errors = $errors;
196
-    }
197
-
198
-
199
-    /**
200
-     * @return string
201
-     */
202
-    public function errors()
203
-    {
204
-        return $this->_errors;
205
-    }
206
-
207
-
208
-    /**
209
-     * @return string
210
-     */
211
-    public function unexpected_errors()
212
-    {
213
-        return $this->_unexpected_errors;
214
-    }
215
-
216
-
217
-    /**
218
-     * @param string $unexpected_errors
219
-     */
220
-    public function set_unexpected_errors($unexpected_errors)
221
-    {
222
-        $this->_unexpected_errors = $unexpected_errors;
223
-    }
224
-
225
-
226
-    /**
227
-     * @param string $success
228
-     */
229
-    public function set_success($success)
230
-    {
231
-        $this->_success = $success;
232
-    }
233
-
234
-
235
-    /**
236
-     * @return string
237
-     */
238
-    public function success()
239
-    {
240
-        return $this->_success;
241
-    }
242
-
243
-
244
-    /**
245
-     * @param string $method_of_payment
246
-     */
247
-    public function set_method_of_payment($method_of_payment)
248
-    {
249
-        $this->_method_of_payment = $method_of_payment;
250
-    }
251
-
252
-
253
-    /**
254
-     * @return string
255
-     */
256
-    public function method_of_payment()
257
-    {
258
-        return $this->_method_of_payment;
259
-    }
260
-
261
-
262
-    /**
263
-     * @return float
264
-     */
265
-    public function payment_amount()
266
-    {
267
-        return $this->_payment_amount;
268
-    }
269
-
270
-
271
-    /**
272
-     * @param float $payment_amount
273
-     * @throws EE_Error
274
-     */
275
-    public function set_payment_amount($payment_amount)
276
-    {
277
-        $this->_payment_amount = (float) $payment_amount;
278
-    }
279
-
280
-
281
-    /**
282
-     * @param string $next_step_html
283
-     */
284
-    public function set_reg_step_html($next_step_html)
285
-    {
286
-        $this->_reg_step_html = $next_step_html;
287
-    }
288
-
289
-
290
-    /**
291
-     * @return string
292
-     */
293
-    public function reg_step_html()
294
-    {
295
-        return $this->_reg_step_html;
296
-    }
297
-
298
-
299
-    /**
300
-     * @param string $redirect_form
301
-     */
302
-    public function set_redirect_form($redirect_form)
303
-    {
304
-        $this->_redirect_form = $redirect_form;
305
-    }
306
-
307
-
308
-    /**
309
-     * @return string
310
-     */
311
-    public function redirect_form()
312
-    {
313
-        return ! empty($this->_redirect_form) ? $this->_redirect_form : false;
314
-    }
315
-
316
-
317
-    /**
318
-     * @param string $plz_select_method_of_payment
319
-     */
320
-    public function set_plz_select_method_of_payment($plz_select_method_of_payment)
321
-    {
322
-        $this->_plz_select_method_of_payment = $plz_select_method_of_payment;
323
-    }
324
-
325
-
326
-    /**
327
-     * @return string
328
-     */
329
-    public function plz_select_method_of_payment()
330
-    {
331
-        return $this->_plz_select_method_of_payment;
332
-    }
333
-
334
-
335
-    /**
336
-     * @param string $redirect_url
337
-     */
338
-    public function set_redirect_url($redirect_url)
339
-    {
340
-        $this->_redirect_url = $redirect_url;
341
-    }
342
-
343
-
344
-    /**
345
-     * @return string
346
-     */
347
-    public function redirect_url()
348
-    {
349
-        return $this->_redirect_url;
350
-    }
351
-
352
-
353
-    /**
354
-     * @return string
355
-     */
356
-    public function registration_time_limit()
357
-    {
358
-        return $this->_registration_time_limit;
359
-    }
360
-
361
-
362
-    /**
363
-     * @param string $registration_time_limit
364
-     */
365
-    public function set_registration_time_limit($registration_time_limit)
366
-    {
367
-        $this->_registration_time_limit = $registration_time_limit;
368
-    }
369
-
370
-
371
-    /**
372
-     * @param array $return_data
373
-     */
374
-    public function set_return_data($return_data)
375
-    {
376
-        $this->_return_data = array_merge($this->_return_data, $return_data);
377
-    }
378
-
379
-
380
-    /**
381
-     * @return array
382
-     */
383
-    public function return_data()
384
-    {
385
-        return $this->_return_data;
386
-    }
387
-
388
-
389
-    /**
390
-     * @param array $validation_rules
391
-     */
392
-    public function add_validation_rules(array $validation_rules = array())
393
-    {
394
-        if (is_array($validation_rules) && ! empty($validation_rules)) {
395
-            $this->_validation_rules = array_merge($this->_validation_rules, $validation_rules);
396
-        }
397
-    }
398
-
399
-
400
-    /**
401
-     * @return array | bool
402
-     */
403
-    public function validation_rules()
404
-    {
405
-        return ! empty($this->_validation_rules) ? $this->_validation_rules : false;
406
-    }
407
-
408
-
409
-    public function echoAndExit()
410
-    {
411
-        echo ($this);
412
-        exit();
413
-    }
17
+	/**
18
+	 * @var string
19
+	 */
20
+	protected $_errors = '';
21
+
22
+	/**
23
+	 * @var string
24
+	 */
25
+	protected $_unexpected_errors = '';
26
+
27
+	/**
28
+	 * @var string
29
+	 */
30
+	protected $_attention = '';
31
+
32
+	/**
33
+	 * @var string
34
+	 */
35
+	protected $_success = '';
36
+
37
+	/**
38
+	 * @var string
39
+	 */
40
+	protected $_plz_select_method_of_payment = '';
41
+
42
+	/**
43
+	 * @var string
44
+	 */
45
+	protected $_redirect_url = '';
46
+
47
+	/**
48
+	 * @var string
49
+	 */
50
+	protected $_registration_time_limit = '';
51
+
52
+	/**
53
+	 * @var string
54
+	 */
55
+	protected $_redirect_form = '';
56
+
57
+	/**
58
+	 * @var string
59
+	 */
60
+	protected $_reg_step_html = '';
61
+
62
+	/**
63
+	 * @var string
64
+	 */
65
+	protected $_method_of_payment = '';
66
+
67
+	/**
68
+	 * @var float
69
+	 */
70
+	protected $_payment_amount;
71
+
72
+	/**
73
+	 * @var array
74
+	 */
75
+	protected $_return_data = array();
76
+
77
+
78
+	/**
79
+	 * @var array
80
+	 */
81
+	protected $_validation_rules = array();
82
+
83
+
84
+	/**
85
+	 *    class constructor
86
+	 */
87
+	public function __construct()
88
+	{
89
+	}
90
+
91
+
92
+	/**
93
+	 *    __toString
94
+	 *
95
+	 *        allows you to simply echo or print an EE_SPCO_JSON_Response object to produce a  JSON encoded string
96
+	 *
97
+	 * @access    public
98
+	 * @return    string
99
+	 */
100
+	public function __toString()
101
+	{
102
+		$JSON_response = array();
103
+		// grab notices
104
+		$notices = EE_Error::get_notices(false);
105
+		$this->set_attention(isset($notices['attention']) ? $notices['attention'] : '');
106
+		$this->set_errors(isset($notices['errors']) ? $notices['errors'] : '');
107
+		$this->set_success(isset($notices['success']) ? $notices['success'] : '');
108
+		// add notices to JSON response, but only if they exist
109
+		if ($this->attention()) {
110
+			$JSON_response['attention'] = $this->attention();
111
+		}
112
+		if ($this->errors()) {
113
+			$JSON_response['errors'] = $this->errors();
114
+		}
115
+		if ($this->unexpected_errors()) {
116
+			$JSON_response['unexpected_errors'] = $this->unexpected_errors();
117
+		}
118
+		if ($this->success()) {
119
+			$JSON_response['success'] = $this->success();
120
+		}
121
+		// but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked
122
+		if (! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) {
123
+			$JSON_response['success'] = null;
124
+		}
125
+		// set redirect_url, IF it exists
126
+		if ($this->redirect_url()) {
127
+			$JSON_response['redirect_url'] = $this->redirect_url();
128
+		}
129
+		// set registration_time_limit, IF it exists
130
+		if ($this->registration_time_limit()) {
131
+			$JSON_response['registration_time_limit'] = $this->registration_time_limit();
132
+		}
133
+		// set payment_amount, IF it exists
134
+		if ($this->payment_amount() !== null) {
135
+			$JSON_response['payment_amount'] = $this->payment_amount();
136
+		}
137
+		// grab generic return data
138
+		$return_data = $this->return_data();
139
+		// add billing form validation rules
140
+		if ($this->validation_rules()) {
141
+			$return_data['validation_rules'] = $this->validation_rules();
142
+		}
143
+		// set reg_step_html, IF it exists
144
+		if ($this->reg_step_html()) {
145
+			$return_data['reg_step_html'] = $this->reg_step_html();
146
+		}
147
+		// set method of payment, IF it exists
148
+		if ($this->method_of_payment()) {
149
+			$return_data['method_of_payment'] = $this->method_of_payment();
150
+		}
151
+		// set "plz_select_method_of_payment" message, IF it exists
152
+		if ($this->plz_select_method_of_payment()) {
153
+			$return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment();
154
+		}
155
+		// set redirect_form, IF it exists
156
+		if ($this->redirect_form()) {
157
+			$return_data['redirect_form'] = $this->redirect_form();
158
+		}
159
+		// and finally, add return_data array to main JSON response array, IF it contains anything
160
+		// why did we add some of the above properties to the return data array?
161
+		// because it is easier and cleaner in the Javascript to deal with this way
162
+		if (! empty($return_data)) {
163
+			$JSON_response['return_data'] = $return_data;
164
+		}
165
+		// filter final array
166
+		$JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response);
167
+		// return encoded array
168
+		return (string) wp_json_encode($JSON_response);
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param string $attention
174
+	 */
175
+	public function set_attention($attention)
176
+	{
177
+		$this->_attention = $attention;
178
+	}
179
+
180
+
181
+	/**
182
+	 * @return string
183
+	 */
184
+	public function attention()
185
+	{
186
+		return $this->_attention;
187
+	}
188
+
189
+
190
+	/**
191
+	 * @param string $errors
192
+	 */
193
+	public function set_errors($errors)
194
+	{
195
+		$this->_errors = $errors;
196
+	}
197
+
198
+
199
+	/**
200
+	 * @return string
201
+	 */
202
+	public function errors()
203
+	{
204
+		return $this->_errors;
205
+	}
206
+
207
+
208
+	/**
209
+	 * @return string
210
+	 */
211
+	public function unexpected_errors()
212
+	{
213
+		return $this->_unexpected_errors;
214
+	}
215
+
216
+
217
+	/**
218
+	 * @param string $unexpected_errors
219
+	 */
220
+	public function set_unexpected_errors($unexpected_errors)
221
+	{
222
+		$this->_unexpected_errors = $unexpected_errors;
223
+	}
224
+
225
+
226
+	/**
227
+	 * @param string $success
228
+	 */
229
+	public function set_success($success)
230
+	{
231
+		$this->_success = $success;
232
+	}
233
+
234
+
235
+	/**
236
+	 * @return string
237
+	 */
238
+	public function success()
239
+	{
240
+		return $this->_success;
241
+	}
242
+
243
+
244
+	/**
245
+	 * @param string $method_of_payment
246
+	 */
247
+	public function set_method_of_payment($method_of_payment)
248
+	{
249
+		$this->_method_of_payment = $method_of_payment;
250
+	}
251
+
252
+
253
+	/**
254
+	 * @return string
255
+	 */
256
+	public function method_of_payment()
257
+	{
258
+		return $this->_method_of_payment;
259
+	}
260
+
261
+
262
+	/**
263
+	 * @return float
264
+	 */
265
+	public function payment_amount()
266
+	{
267
+		return $this->_payment_amount;
268
+	}
269
+
270
+
271
+	/**
272
+	 * @param float $payment_amount
273
+	 * @throws EE_Error
274
+	 */
275
+	public function set_payment_amount($payment_amount)
276
+	{
277
+		$this->_payment_amount = (float) $payment_amount;
278
+	}
279
+
280
+
281
+	/**
282
+	 * @param string $next_step_html
283
+	 */
284
+	public function set_reg_step_html($next_step_html)
285
+	{
286
+		$this->_reg_step_html = $next_step_html;
287
+	}
288
+
289
+
290
+	/**
291
+	 * @return string
292
+	 */
293
+	public function reg_step_html()
294
+	{
295
+		return $this->_reg_step_html;
296
+	}
297
+
298
+
299
+	/**
300
+	 * @param string $redirect_form
301
+	 */
302
+	public function set_redirect_form($redirect_form)
303
+	{
304
+		$this->_redirect_form = $redirect_form;
305
+	}
306
+
307
+
308
+	/**
309
+	 * @return string
310
+	 */
311
+	public function redirect_form()
312
+	{
313
+		return ! empty($this->_redirect_form) ? $this->_redirect_form : false;
314
+	}
315
+
316
+
317
+	/**
318
+	 * @param string $plz_select_method_of_payment
319
+	 */
320
+	public function set_plz_select_method_of_payment($plz_select_method_of_payment)
321
+	{
322
+		$this->_plz_select_method_of_payment = $plz_select_method_of_payment;
323
+	}
324
+
325
+
326
+	/**
327
+	 * @return string
328
+	 */
329
+	public function plz_select_method_of_payment()
330
+	{
331
+		return $this->_plz_select_method_of_payment;
332
+	}
333
+
334
+
335
+	/**
336
+	 * @param string $redirect_url
337
+	 */
338
+	public function set_redirect_url($redirect_url)
339
+	{
340
+		$this->_redirect_url = $redirect_url;
341
+	}
342
+
343
+
344
+	/**
345
+	 * @return string
346
+	 */
347
+	public function redirect_url()
348
+	{
349
+		return $this->_redirect_url;
350
+	}
351
+
352
+
353
+	/**
354
+	 * @return string
355
+	 */
356
+	public function registration_time_limit()
357
+	{
358
+		return $this->_registration_time_limit;
359
+	}
360
+
361
+
362
+	/**
363
+	 * @param string $registration_time_limit
364
+	 */
365
+	public function set_registration_time_limit($registration_time_limit)
366
+	{
367
+		$this->_registration_time_limit = $registration_time_limit;
368
+	}
369
+
370
+
371
+	/**
372
+	 * @param array $return_data
373
+	 */
374
+	public function set_return_data($return_data)
375
+	{
376
+		$this->_return_data = array_merge($this->_return_data, $return_data);
377
+	}
378
+
379
+
380
+	/**
381
+	 * @return array
382
+	 */
383
+	public function return_data()
384
+	{
385
+		return $this->_return_data;
386
+	}
387
+
388
+
389
+	/**
390
+	 * @param array $validation_rules
391
+	 */
392
+	public function add_validation_rules(array $validation_rules = array())
393
+	{
394
+		if (is_array($validation_rules) && ! empty($validation_rules)) {
395
+			$this->_validation_rules = array_merge($this->_validation_rules, $validation_rules);
396
+		}
397
+	}
398
+
399
+
400
+	/**
401
+	 * @return array | bool
402
+	 */
403
+	public function validation_rules()
404
+	{
405
+		return ! empty($this->_validation_rules) ? $this->_validation_rules : false;
406
+	}
407
+
408
+
409
+	public function echoAndExit()
410
+	{
411
+		echo ($this);
412
+		exit();
413
+	}
414 414
 }
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Html_messenger.class.php 1 patch
Indentation   +545 added lines, -545 removed lines patch added patch discarded remove patch
@@ -12,549 +12,549 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Html_messenger extends EE_messenger
14 14
 {
15
-    /**
16
-     * The following are the properties that this messenger requires for displaying the html
17
-     */
18
-    /**
19
-     * This is the html body generated by the template via the message type.
20
-     *
21
-     * @var string
22
-     */
23
-    protected $_content = '';
24
-
25
-    /**
26
-     * This is for the page title that gets displayed.  (Why use "subject"?  Because the "title" tag in html is
27
-     * equivalent to the "subject" of the page.
28
-     *
29
-     * @var string
30
-     */
31
-    protected $_subject = '';
32
-
33
-
34
-    /**
35
-     * EE_Html_messenger constructor.
36
-     */
37
-    public function __construct()
38
-    {
39
-        // set properties
40
-        $this->name                = 'html';
41
-        $this->description         = esc_html__(
42
-            'This messenger outputs a message to a browser for display.',
43
-            'event_espresso'
44
-        );
45
-        $this->label               = [
46
-            'singular' => esc_html__('html', 'event_espresso'),
47
-            'plural'   => esc_html__('html', 'event_espresso'),
48
-        ];
49
-        $this->activate_on_install = true;
50
-        // add the "powered by EE" credit link to the HTML receipt and invoice
51
-        add_filter(
52
-            'FHEE__EE_Html_messenger___send_message__main_body',
53
-            [$this, 'add_powered_by_credit_link_to_receipt_and_invoice'],
54
-            10,
55
-            3
56
-        );
57
-        parent::__construct();
58
-    }
59
-
60
-
61
-    /**
62
-     * HTML Messenger desires execution immediately.
63
-     *
64
-     * @return bool
65
-     * @since  4.9.0
66
-     * @see    parent::send_now() for documentation.
67
-     */
68
-    public function send_now(): bool
69
-    {
70
-        return true;
71
-    }
72
-
73
-
74
-    /**
75
-     * HTML Messenger allows an empty to field.
76
-     *
77
-     * @return bool
78
-     * @since  4.9.0
79
-     * @see    parent::allow_empty_to_field() for documentation
80
-     */
81
-    public function allow_empty_to_field(): bool
82
-    {
83
-        return true;
84
-    }
85
-
86
-
87
-    /**
88
-     * @see abstract declaration in EE_messenger for details.
89
-     */
90
-    protected function _set_admin_pages()
91
-    {
92
-        $this->admin_registered_pages = ['events_edit' => true];
93
-    }
94
-
95
-
96
-    /**
97
-     * @see abstract declaration in EE_messenger for details.
98
-     */
99
-    protected function _set_valid_shortcodes()
100
-    {
101
-        $this->_valid_shortcodes = [];
102
-    }
103
-
104
-
105
-    /**
106
-     * @see abstract declaration in EE_messenger for details.
107
-     */
108
-    protected function _set_validator_config()
109
-    {
110
-        $this->_validator_config = [
111
-            'subject'                       => [
112
-                'shortcodes' => ['organization', 'primary_registration_details', 'email', 'transaction'],
113
-            ],
114
-            'content'                       => [
115
-                'shortcodes' => [
116
-                    'organization',
117
-                    'primary_registration_list',
118
-                    'primary_registration_details',
119
-                    'email',
120
-                    'transaction',
121
-                    'event_list',
122
-                    'payment_list',
123
-                    'venue',
124
-                    'line_item_list',
125
-                    'messenger',
126
-                    'ticket_list',
127
-                ],
128
-            ],
129
-            'event_list'                    => [
130
-                'shortcodes' => [
131
-                    'event',
132
-                    'ticket_list',
133
-                    'venue',
134
-                    'primary_registration_details',
135
-                    'primary_registration_list',
136
-                    'event_author',
137
-                ],
138
-                'required'   => ['[EVENT_LIST]'],
139
-            ],
140
-            'ticket_list'                   => [
141
-                'shortcodes' => [
142
-                    'attendee_list',
143
-                    'ticket',
144
-                    'datetime_list',
145
-                    'primary_registration_details',
146
-                    'line_item_list',
147
-                    'venue',
148
-                ],
149
-                'required'   => ['[TICKET_LIST]'],
150
-            ],
151
-            'ticket_line_item_no_pms'       => [
152
-                'shortcodes' => ['line_item', 'ticket'],
153
-                'required'   => ['[TICKET_LINE_ITEM_LIST]'],
154
-            ],
155
-            'ticket_line_item_pms'          => [
156
-                'shortcodes' => ['line_item', 'ticket', 'line_item_list'],
157
-                'required'   => ['[TICKET_LINE_ITEM_LIST]'],
158
-            ],
159
-            'price_modifier_line_item_list' => [
160
-                'shortcodes' => ['line_item'],
161
-                'required'   => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'],
162
-            ],
163
-            'datetime_list'                 => [
164
-                'shortcodes' => ['datetime'],
165
-                'required'   => ['[DATETIME_LIST]'],
166
-            ],
167
-            'attendee_list'                 => [
168
-                'shortcodes' => ['attendee'],
169
-                'required'   => ['[ATTENDEE_LIST]'],
170
-            ],
171
-            'tax_line_item_list'            => [
172
-                'shortcodes' => ['line_item'],
173
-                'required'   => ['[TAX_LINE_ITEM_LIST]'],
174
-            ],
175
-            'additional_line_item_list'     => [
176
-                'shortcodes' => ['line_item'],
177
-                'required'   => ['[ADDITIONAL_LINE_ITEM_LIST]'],
178
-            ],
179
-            'payment_list'                  => [
180
-                'shortcodes' => ['payment'],
181
-                'required'   => ['[PAYMENT_LIST_*]'],
182
-            ],
183
-        ];
184
-    }
185
-
186
-
187
-    /**
188
-     * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger
189
-     * is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary
190
-     * (i.e. swap out css files or something else).
191
-     *
192
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
193
-     * @return void
194
-     * @since 4.5.0
195
-     */
196
-    public function do_secondary_messenger_hooks($sending_messenger_name)
197
-    {
198
-        if ($sending_messenger_name === 'pdf') {
199
-            add_filter('EE_messenger__get_variation__variation', [$this, 'add_html_css'], 10, 8);
200
-        }
201
-    }
202
-
203
-
204
-    /**
205
-     * @param                            $variation_path
206
-     * @param EE_Messages_Template_Pack  $template_pack
207
-     * @param                            $messenger_name
208
-     * @param                            $message_type_name
209
-     * @param                            $url
210
-     * @param                            $type
211
-     * @param                            $variation
212
-     * @param                            $skip_filters
213
-     * @return string
214
-     */
215
-    public function add_html_css(
216
-        $variation_path,
217
-        EE_Messages_Template_Pack $template_pack,
218
-        $messenger_name,
219
-        $message_type_name,
220
-        $url,
221
-        $type,
222
-        $variation,
223
-        $skip_filters
224
-    ): string {
225
-        return $template_pack->get_variation(
226
-            $this->name,
227
-            $message_type_name,
228
-            $type,
229
-            $variation,
230
-            $url,
231
-            '.css',
232
-            $skip_filters
233
-        );
234
-    }
235
-
236
-
237
-    /**
238
-     * Takes care of enqueuing any necessary scripts or styles for the page.  A do_action() so message types using this
239
-     * messenger can add their own js.
240
-     *
241
-     * @return void.
242
-     */
243
-    public function enqueue_scripts_styles()
244
-    {
245
-        parent::enqueue_scripts_styles();
246
-        do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles');
247
-    }
248
-
249
-
250
-    /**
251
-     * _set_template_fields
252
-     * This sets up the fields that a messenger requires for the message to go out.
253
-     *
254
-     * @access  protected
255
-     * @return void
256
-     */
257
-    protected function _set_template_fields()
258
-    {
259
-        // any extra template fields that are NOT used by the messenger
260
-        // but will get used by a messenger field for shortcode replacement
261
-        // get added to the 'extra' key in an associated array
262
-        // indexed by the messenger field they relate to.
263
-        // This is important for the Messages_admin to know what fields to display to the user.
264
-        // Also, notice that the "values" are equal to the field type
265
-        // that messages admin will use to know what kind of field to display.
266
-        // The values ALSO have one index labeled "shortcode".
267
-        // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE])
268
-        // is required in order for this extra field to be displayed.
269
-        //  If the required shortcode isn't part of the shortcodes array
270
-        // then the field is not needed and will not be displayed/parsed.
271
-        $this->_template_fields = [
272
-            'subject' => [
273
-                'input'      => 'text',
274
-                'label'      => esc_html__('Page Title', 'event_espresso'),
275
-                'type'       => 'string',
276
-                'required'   => true,
277
-                'validation' => true,
278
-                'css_class'  => 'large-text',
279
-                'format'     => '%s',
280
-            ],
281
-            'content' => '',
282
-            // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
283
-            'extra'   => [
284
-                'content' => [
285
-                    'main'                          => [
286
-                        'input'      => 'wp_editor',
287
-                        'label'      => esc_html__('Main Content', 'event_espresso'),
288
-                        'type'       => 'string',
289
-                        'required'   => true,
290
-                        'validation' => true,
291
-                        'format'     => '%s',
292
-                        'rows'       => '15',
293
-                    ],
294
-                    'event_list'                    => [
295
-                        'input'               => 'wp_editor',
296
-                        'label'               => '[EVENT_LIST]',
297
-                        'type'                => 'string',
298
-                        'required'            => true,
299
-                        'validation'          => true,
300
-                        'format'              => '%s',
301
-                        'rows'                => '15',
302
-                        'shortcodes_required' => ['[EVENT_LIST]'],
303
-                    ],
304
-                    'ticket_list'                   => [
305
-                        'input'               => 'textarea',
306
-                        'label'               => '[TICKET_LIST]',
307
-                        'type'                => 'string',
308
-                        'required'            => true,
309
-                        'validation'          => true,
310
-                        'format'              => '%s',
311
-                        'css_class'           => 'large-text',
312
-                        'rows'                => '10',
313
-                        'shortcodes_required' => ['[TICKET_LIST]'],
314
-                    ],
315
-                    'ticket_line_item_no_pms'       => [
316
-                        'input'               => 'textarea',
317
-                        'label'               => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__(
318
-                            'Ticket Line Item List with no Price Modifiers',
319
-                            'event_espresso'
320
-                        ),
321
-                        'type'                => 'string',
322
-                        'required'            => false,
323
-                        'validation'          => true,
324
-                        'format'              => '%s',
325
-                        'css_class'           => 'large-text',
326
-                        'rows'                => '5',
327
-                        'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'],
328
-                    ],
329
-                    'ticket_line_item_pms'          => [
330
-                        'input'               => 'textarea',
331
-                        'label'               => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__(
332
-                            'Ticket Line Item List with Price Modifiers',
333
-                            'event_espresso'
334
-                        ),
335
-                        'type'                => 'string',
336
-                        'required'            => false,
337
-                        'validation'          => true,
338
-                        'format'              => '%s',
339
-                        'css_class'           => 'large-text',
340
-                        'rows'                => '5',
341
-                        'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'],
342
-                    ],
343
-                    'price_modifier_line_item_list' => [
344
-                        'input'               => 'textarea',
345
-                        'label'               => '[PRICE_MODIFIER_LINE_ITEM_LIST]',
346
-                        'type'                => 'string',
347
-                        'required'            => false,
348
-                        'validation'          => true,
349
-                        'format'              => '%s',
350
-                        'css_class'           => 'large-text',
351
-                        'rows'                => '5',
352
-                        'shortcodes_required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'],
353
-                    ],
354
-                    'datetime_list'                 => [
355
-                        'input'               => 'textarea',
356
-                        'label'               => '[DATETIME_LIST]',
357
-                        'type'                => 'string',
358
-                        'required'            => true,
359
-                        'validation'          => true,
360
-                        'format'              => '%s',
361
-                        'css_class'           => 'large-text',
362
-                        'rows'                => '5',
363
-                        'shortcodes_required' => ['[DATETIME_LIST]'],
364
-                    ],
365
-                    'attendee_list'                 => [
366
-                        'input'               => 'textarea',
367
-                        'label'               => '[ATTENDEE_LIST]',
368
-                        'type'                => 'string',
369
-                        'required'            => true,
370
-                        'validation'          => true,
371
-                        'format'              => '%s',
372
-                        'css_class'           => 'large-text',
373
-                        'rows'                => '5',
374
-                        'shortcodes_required' => ['[ATTENDEE_LIST]'],
375
-                    ],
376
-                    'tax_line_item_list'            => [
377
-                        'input'               => 'textarea',
378
-                        'label'               => '[TAX_LINE_ITEM_LIST]',
379
-                        'type'                => 'string',
380
-                        'required'            => false,
381
-                        'validation'          => true,
382
-                        'format'              => '%s',
383
-                        'css_class'           => 'large-text',
384
-                        'rows'                => '5',
385
-                        'shortcodes_required' => ['[TAX_LINE_ITEM_LIST]'],
386
-                    ],
387
-                    'additional_line_item_list'     => [
388
-                        'input'               => 'textarea',
389
-                        'label'               => '[ADDITIONAL_LINE_ITEM_LIST]',
390
-                        'type'                => 'string',
391
-                        'required'            => false,
392
-                        'validation'          => true,
393
-                        'format'              => '%s',
394
-                        'css_class'           => 'large-text',
395
-                        'rows'                => '5',
396
-                        'shortcodes_required' => ['[ADDITIONAL_LINE_ITEM_LIST]'],
397
-                    ],
398
-                    'payment_list'                  => [
399
-                        'input'               => 'textarea',
400
-                        'label'               => '[PAYMENT_LIST]',
401
-                        'type'                => 'string',
402
-                        'required'            => true,
403
-                        'validation'          => true,
404
-                        'format'              => '%s',
405
-                        'css_class'           => 'large-text',
406
-                        'rows'                => '5',
407
-                        'shortcodes_required' => ['[PAYMENT_LIST_*]'],
408
-                    ],
409
-                ],
410
-            ],
411
-        ];
412
-    }
413
-
414
-
415
-    /**
416
-     * @see   definition of this method in parent
417
-     * @since 4.5.0
418
-     */
419
-    protected function _set_default_message_types()
420
-    {
421
-        $this->_default_message_types = ['receipt', 'invoice'];
422
-    }
423
-
424
-
425
-    /**
426
-     * @see   definition of this method in parent
427
-     * @since 4.5.0
428
-     */
429
-    protected function _set_valid_message_types()
430
-    {
431
-        $this->_valid_message_types = ['receipt', 'invoice'];
432
-    }
433
-
434
-
435
-    /**
436
-     * Displays the message in the browser.
437
-     *
438
-     * @return void.
439
-     * @since 4.5.0
440
-     */
441
-    protected function _send_message()
442
-    {
443
-        $this->_template_args = [
444
-            'page_title' => $this->_subject,
445
-            'base_css'   => $this->get_variation(
446
-                $this->_tmp_pack,
447
-                $this->_incoming_message_type->name,
448
-                true,
449
-                'base',
450
-                $this->_variation
451
-            ),
452
-            'print_css'  => $this->get_variation(
453
-                $this->_tmp_pack,
454
-                $this->_incoming_message_type->name,
455
-                true,
456
-                'print',
457
-                $this->_variation
458
-            ),
459
-            'main_css'   => $this->get_variation(
460
-                $this->_tmp_pack,
461
-                $this->_incoming_message_type->name,
462
-                true,
463
-                'main',
464
-                $this->_variation
465
-            ),
466
-            'main_body'  => wpautop(
467
-                apply_filters(
468
-                    'FHEE__EE_Html_messenger___send_message__main_body',
469
-                    $this->_content,
470
-                    $this->_content,
471
-                    $this->_incoming_message_type
472
-                )
473
-            ),
474
-        ];
475
-        $this->_deregister_wp_hooks();
476
-        add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']);
477
-        echo ($this->_get_main_template());
478
-        exit();
479
-    }
480
-
481
-
482
-    /**
483
-     * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't
484
-     * interfere with our templates.  If users want to add any custom styles or scripts they must use the
485
-     * AHEE__EE_Html_messenger__enqueue_scripts_styles hook.
486
-     *
487
-     * @return void
488
-     * @since 4.5.0
489
-     */
490
-    protected function _deregister_wp_hooks()
491
-    {
492
-        remove_all_actions('wp_head');
493
-        remove_all_actions('wp_footer');
494
-        remove_all_actions('wp_print_footer_scripts');
495
-        remove_all_actions('wp_enqueue_scripts');
496
-        global $wp_scripts, $wp_styles;
497
-        $wp_scripts = $wp_styles = [];
498
-        // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
499
-        add_action('wp_footer', 'wp_print_footer_scripts');
500
-        add_action('wp_print_footer_scripts', '_wp_footer_scripts');
501
-        add_action('wp_head', 'wp_enqueue_scripts');
502
-    }
503
-
504
-
505
-    /**
506
-     * Overwrite parent _get_main_template for display_html purposes.
507
-     *
508
-     * @param bool $preview
509
-     * @return string
510
-     * @since  4.5.0
511
-     */
512
-    protected function _get_main_template($preview = false): string
513
-    {
514
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name);
515
-        // include message type as a template arg
516
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
517
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
518
-    }
519
-
520
-
521
-    /**
522
-     * @return void
523
-     */
524
-    protected function _preview()
525
-    {
526
-        $this->_send_message();
527
-    }
528
-
529
-
530
-    protected function _set_admin_settings_fields()
531
-    {
532
-    }
533
-
534
-
535
-    /**
536
-     * add the "powered by EE" credit link to the HTML receipt and invoice
537
-     *
538
-     * @param string          $content
539
-     * @param string          $content_again
540
-     * @param EE_message_type $incoming_message_type
541
-     * @return string
542
-     */
543
-    public function add_powered_by_credit_link_to_receipt_and_invoice(
544
-        string $content,
545
-        string $content_again,
546
-        EE_message_type $incoming_message_type
547
-    ): string {
548
-        if (
549
-            ($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt')
550
-            && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true)
551
-        ) {
552
-            $content .= EEH_Template::powered_by_event_espresso(
553
-                'aln-cntr',
554
-                '',
555
-                ['utm_content' => 'messages_system']
556
-            ) . EEH_HTML::div(EEH_HTML::p('&nbsp;'));
557
-        }
558
-        return $content;
559
-    }
15
+	/**
16
+	 * The following are the properties that this messenger requires for displaying the html
17
+	 */
18
+	/**
19
+	 * This is the html body generated by the template via the message type.
20
+	 *
21
+	 * @var string
22
+	 */
23
+	protected $_content = '';
24
+
25
+	/**
26
+	 * This is for the page title that gets displayed.  (Why use "subject"?  Because the "title" tag in html is
27
+	 * equivalent to the "subject" of the page.
28
+	 *
29
+	 * @var string
30
+	 */
31
+	protected $_subject = '';
32
+
33
+
34
+	/**
35
+	 * EE_Html_messenger constructor.
36
+	 */
37
+	public function __construct()
38
+	{
39
+		// set properties
40
+		$this->name                = 'html';
41
+		$this->description         = esc_html__(
42
+			'This messenger outputs a message to a browser for display.',
43
+			'event_espresso'
44
+		);
45
+		$this->label               = [
46
+			'singular' => esc_html__('html', 'event_espresso'),
47
+			'plural'   => esc_html__('html', 'event_espresso'),
48
+		];
49
+		$this->activate_on_install = true;
50
+		// add the "powered by EE" credit link to the HTML receipt and invoice
51
+		add_filter(
52
+			'FHEE__EE_Html_messenger___send_message__main_body',
53
+			[$this, 'add_powered_by_credit_link_to_receipt_and_invoice'],
54
+			10,
55
+			3
56
+		);
57
+		parent::__construct();
58
+	}
59
+
60
+
61
+	/**
62
+	 * HTML Messenger desires execution immediately.
63
+	 *
64
+	 * @return bool
65
+	 * @since  4.9.0
66
+	 * @see    parent::send_now() for documentation.
67
+	 */
68
+	public function send_now(): bool
69
+	{
70
+		return true;
71
+	}
72
+
73
+
74
+	/**
75
+	 * HTML Messenger allows an empty to field.
76
+	 *
77
+	 * @return bool
78
+	 * @since  4.9.0
79
+	 * @see    parent::allow_empty_to_field() for documentation
80
+	 */
81
+	public function allow_empty_to_field(): bool
82
+	{
83
+		return true;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @see abstract declaration in EE_messenger for details.
89
+	 */
90
+	protected function _set_admin_pages()
91
+	{
92
+		$this->admin_registered_pages = ['events_edit' => true];
93
+	}
94
+
95
+
96
+	/**
97
+	 * @see abstract declaration in EE_messenger for details.
98
+	 */
99
+	protected function _set_valid_shortcodes()
100
+	{
101
+		$this->_valid_shortcodes = [];
102
+	}
103
+
104
+
105
+	/**
106
+	 * @see abstract declaration in EE_messenger for details.
107
+	 */
108
+	protected function _set_validator_config()
109
+	{
110
+		$this->_validator_config = [
111
+			'subject'                       => [
112
+				'shortcodes' => ['organization', 'primary_registration_details', 'email', 'transaction'],
113
+			],
114
+			'content'                       => [
115
+				'shortcodes' => [
116
+					'organization',
117
+					'primary_registration_list',
118
+					'primary_registration_details',
119
+					'email',
120
+					'transaction',
121
+					'event_list',
122
+					'payment_list',
123
+					'venue',
124
+					'line_item_list',
125
+					'messenger',
126
+					'ticket_list',
127
+				],
128
+			],
129
+			'event_list'                    => [
130
+				'shortcodes' => [
131
+					'event',
132
+					'ticket_list',
133
+					'venue',
134
+					'primary_registration_details',
135
+					'primary_registration_list',
136
+					'event_author',
137
+				],
138
+				'required'   => ['[EVENT_LIST]'],
139
+			],
140
+			'ticket_list'                   => [
141
+				'shortcodes' => [
142
+					'attendee_list',
143
+					'ticket',
144
+					'datetime_list',
145
+					'primary_registration_details',
146
+					'line_item_list',
147
+					'venue',
148
+				],
149
+				'required'   => ['[TICKET_LIST]'],
150
+			],
151
+			'ticket_line_item_no_pms'       => [
152
+				'shortcodes' => ['line_item', 'ticket'],
153
+				'required'   => ['[TICKET_LINE_ITEM_LIST]'],
154
+			],
155
+			'ticket_line_item_pms'          => [
156
+				'shortcodes' => ['line_item', 'ticket', 'line_item_list'],
157
+				'required'   => ['[TICKET_LINE_ITEM_LIST]'],
158
+			],
159
+			'price_modifier_line_item_list' => [
160
+				'shortcodes' => ['line_item'],
161
+				'required'   => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'],
162
+			],
163
+			'datetime_list'                 => [
164
+				'shortcodes' => ['datetime'],
165
+				'required'   => ['[DATETIME_LIST]'],
166
+			],
167
+			'attendee_list'                 => [
168
+				'shortcodes' => ['attendee'],
169
+				'required'   => ['[ATTENDEE_LIST]'],
170
+			],
171
+			'tax_line_item_list'            => [
172
+				'shortcodes' => ['line_item'],
173
+				'required'   => ['[TAX_LINE_ITEM_LIST]'],
174
+			],
175
+			'additional_line_item_list'     => [
176
+				'shortcodes' => ['line_item'],
177
+				'required'   => ['[ADDITIONAL_LINE_ITEM_LIST]'],
178
+			],
179
+			'payment_list'                  => [
180
+				'shortcodes' => ['payment'],
181
+				'required'   => ['[PAYMENT_LIST_*]'],
182
+			],
183
+		];
184
+	}
185
+
186
+
187
+	/**
188
+	 * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger
189
+	 * is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary
190
+	 * (i.e. swap out css files or something else).
191
+	 *
192
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
193
+	 * @return void
194
+	 * @since 4.5.0
195
+	 */
196
+	public function do_secondary_messenger_hooks($sending_messenger_name)
197
+	{
198
+		if ($sending_messenger_name === 'pdf') {
199
+			add_filter('EE_messenger__get_variation__variation', [$this, 'add_html_css'], 10, 8);
200
+		}
201
+	}
202
+
203
+
204
+	/**
205
+	 * @param                            $variation_path
206
+	 * @param EE_Messages_Template_Pack  $template_pack
207
+	 * @param                            $messenger_name
208
+	 * @param                            $message_type_name
209
+	 * @param                            $url
210
+	 * @param                            $type
211
+	 * @param                            $variation
212
+	 * @param                            $skip_filters
213
+	 * @return string
214
+	 */
215
+	public function add_html_css(
216
+		$variation_path,
217
+		EE_Messages_Template_Pack $template_pack,
218
+		$messenger_name,
219
+		$message_type_name,
220
+		$url,
221
+		$type,
222
+		$variation,
223
+		$skip_filters
224
+	): string {
225
+		return $template_pack->get_variation(
226
+			$this->name,
227
+			$message_type_name,
228
+			$type,
229
+			$variation,
230
+			$url,
231
+			'.css',
232
+			$skip_filters
233
+		);
234
+	}
235
+
236
+
237
+	/**
238
+	 * Takes care of enqueuing any necessary scripts or styles for the page.  A do_action() so message types using this
239
+	 * messenger can add their own js.
240
+	 *
241
+	 * @return void.
242
+	 */
243
+	public function enqueue_scripts_styles()
244
+	{
245
+		parent::enqueue_scripts_styles();
246
+		do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles');
247
+	}
248
+
249
+
250
+	/**
251
+	 * _set_template_fields
252
+	 * This sets up the fields that a messenger requires for the message to go out.
253
+	 *
254
+	 * @access  protected
255
+	 * @return void
256
+	 */
257
+	protected function _set_template_fields()
258
+	{
259
+		// any extra template fields that are NOT used by the messenger
260
+		// but will get used by a messenger field for shortcode replacement
261
+		// get added to the 'extra' key in an associated array
262
+		// indexed by the messenger field they relate to.
263
+		// This is important for the Messages_admin to know what fields to display to the user.
264
+		// Also, notice that the "values" are equal to the field type
265
+		// that messages admin will use to know what kind of field to display.
266
+		// The values ALSO have one index labeled "shortcode".
267
+		// The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE])
268
+		// is required in order for this extra field to be displayed.
269
+		//  If the required shortcode isn't part of the shortcodes array
270
+		// then the field is not needed and will not be displayed/parsed.
271
+		$this->_template_fields = [
272
+			'subject' => [
273
+				'input'      => 'text',
274
+				'label'      => esc_html__('Page Title', 'event_espresso'),
275
+				'type'       => 'string',
276
+				'required'   => true,
277
+				'validation' => true,
278
+				'css_class'  => 'large-text',
279
+				'format'     => '%s',
280
+			],
281
+			'content' => '',
282
+			// left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
283
+			'extra'   => [
284
+				'content' => [
285
+					'main'                          => [
286
+						'input'      => 'wp_editor',
287
+						'label'      => esc_html__('Main Content', 'event_espresso'),
288
+						'type'       => 'string',
289
+						'required'   => true,
290
+						'validation' => true,
291
+						'format'     => '%s',
292
+						'rows'       => '15',
293
+					],
294
+					'event_list'                    => [
295
+						'input'               => 'wp_editor',
296
+						'label'               => '[EVENT_LIST]',
297
+						'type'                => 'string',
298
+						'required'            => true,
299
+						'validation'          => true,
300
+						'format'              => '%s',
301
+						'rows'                => '15',
302
+						'shortcodes_required' => ['[EVENT_LIST]'],
303
+					],
304
+					'ticket_list'                   => [
305
+						'input'               => 'textarea',
306
+						'label'               => '[TICKET_LIST]',
307
+						'type'                => 'string',
308
+						'required'            => true,
309
+						'validation'          => true,
310
+						'format'              => '%s',
311
+						'css_class'           => 'large-text',
312
+						'rows'                => '10',
313
+						'shortcodes_required' => ['[TICKET_LIST]'],
314
+					],
315
+					'ticket_line_item_no_pms'       => [
316
+						'input'               => 'textarea',
317
+						'label'               => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__(
318
+							'Ticket Line Item List with no Price Modifiers',
319
+							'event_espresso'
320
+						),
321
+						'type'                => 'string',
322
+						'required'            => false,
323
+						'validation'          => true,
324
+						'format'              => '%s',
325
+						'css_class'           => 'large-text',
326
+						'rows'                => '5',
327
+						'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'],
328
+					],
329
+					'ticket_line_item_pms'          => [
330
+						'input'               => 'textarea',
331
+						'label'               => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__(
332
+							'Ticket Line Item List with Price Modifiers',
333
+							'event_espresso'
334
+						),
335
+						'type'                => 'string',
336
+						'required'            => false,
337
+						'validation'          => true,
338
+						'format'              => '%s',
339
+						'css_class'           => 'large-text',
340
+						'rows'                => '5',
341
+						'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'],
342
+					],
343
+					'price_modifier_line_item_list' => [
344
+						'input'               => 'textarea',
345
+						'label'               => '[PRICE_MODIFIER_LINE_ITEM_LIST]',
346
+						'type'                => 'string',
347
+						'required'            => false,
348
+						'validation'          => true,
349
+						'format'              => '%s',
350
+						'css_class'           => 'large-text',
351
+						'rows'                => '5',
352
+						'shortcodes_required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'],
353
+					],
354
+					'datetime_list'                 => [
355
+						'input'               => 'textarea',
356
+						'label'               => '[DATETIME_LIST]',
357
+						'type'                => 'string',
358
+						'required'            => true,
359
+						'validation'          => true,
360
+						'format'              => '%s',
361
+						'css_class'           => 'large-text',
362
+						'rows'                => '5',
363
+						'shortcodes_required' => ['[DATETIME_LIST]'],
364
+					],
365
+					'attendee_list'                 => [
366
+						'input'               => 'textarea',
367
+						'label'               => '[ATTENDEE_LIST]',
368
+						'type'                => 'string',
369
+						'required'            => true,
370
+						'validation'          => true,
371
+						'format'              => '%s',
372
+						'css_class'           => 'large-text',
373
+						'rows'                => '5',
374
+						'shortcodes_required' => ['[ATTENDEE_LIST]'],
375
+					],
376
+					'tax_line_item_list'            => [
377
+						'input'               => 'textarea',
378
+						'label'               => '[TAX_LINE_ITEM_LIST]',
379
+						'type'                => 'string',
380
+						'required'            => false,
381
+						'validation'          => true,
382
+						'format'              => '%s',
383
+						'css_class'           => 'large-text',
384
+						'rows'                => '5',
385
+						'shortcodes_required' => ['[TAX_LINE_ITEM_LIST]'],
386
+					],
387
+					'additional_line_item_list'     => [
388
+						'input'               => 'textarea',
389
+						'label'               => '[ADDITIONAL_LINE_ITEM_LIST]',
390
+						'type'                => 'string',
391
+						'required'            => false,
392
+						'validation'          => true,
393
+						'format'              => '%s',
394
+						'css_class'           => 'large-text',
395
+						'rows'                => '5',
396
+						'shortcodes_required' => ['[ADDITIONAL_LINE_ITEM_LIST]'],
397
+					],
398
+					'payment_list'                  => [
399
+						'input'               => 'textarea',
400
+						'label'               => '[PAYMENT_LIST]',
401
+						'type'                => 'string',
402
+						'required'            => true,
403
+						'validation'          => true,
404
+						'format'              => '%s',
405
+						'css_class'           => 'large-text',
406
+						'rows'                => '5',
407
+						'shortcodes_required' => ['[PAYMENT_LIST_*]'],
408
+					],
409
+				],
410
+			],
411
+		];
412
+	}
413
+
414
+
415
+	/**
416
+	 * @see   definition of this method in parent
417
+	 * @since 4.5.0
418
+	 */
419
+	protected function _set_default_message_types()
420
+	{
421
+		$this->_default_message_types = ['receipt', 'invoice'];
422
+	}
423
+
424
+
425
+	/**
426
+	 * @see   definition of this method in parent
427
+	 * @since 4.5.0
428
+	 */
429
+	protected function _set_valid_message_types()
430
+	{
431
+		$this->_valid_message_types = ['receipt', 'invoice'];
432
+	}
433
+
434
+
435
+	/**
436
+	 * Displays the message in the browser.
437
+	 *
438
+	 * @return void.
439
+	 * @since 4.5.0
440
+	 */
441
+	protected function _send_message()
442
+	{
443
+		$this->_template_args = [
444
+			'page_title' => $this->_subject,
445
+			'base_css'   => $this->get_variation(
446
+				$this->_tmp_pack,
447
+				$this->_incoming_message_type->name,
448
+				true,
449
+				'base',
450
+				$this->_variation
451
+			),
452
+			'print_css'  => $this->get_variation(
453
+				$this->_tmp_pack,
454
+				$this->_incoming_message_type->name,
455
+				true,
456
+				'print',
457
+				$this->_variation
458
+			),
459
+			'main_css'   => $this->get_variation(
460
+				$this->_tmp_pack,
461
+				$this->_incoming_message_type->name,
462
+				true,
463
+				'main',
464
+				$this->_variation
465
+			),
466
+			'main_body'  => wpautop(
467
+				apply_filters(
468
+					'FHEE__EE_Html_messenger___send_message__main_body',
469
+					$this->_content,
470
+					$this->_content,
471
+					$this->_incoming_message_type
472
+				)
473
+			),
474
+		];
475
+		$this->_deregister_wp_hooks();
476
+		add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']);
477
+		echo ($this->_get_main_template());
478
+		exit();
479
+	}
480
+
481
+
482
+	/**
483
+	 * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't
484
+	 * interfere with our templates.  If users want to add any custom styles or scripts they must use the
485
+	 * AHEE__EE_Html_messenger__enqueue_scripts_styles hook.
486
+	 *
487
+	 * @return void
488
+	 * @since 4.5.0
489
+	 */
490
+	protected function _deregister_wp_hooks()
491
+	{
492
+		remove_all_actions('wp_head');
493
+		remove_all_actions('wp_footer');
494
+		remove_all_actions('wp_print_footer_scripts');
495
+		remove_all_actions('wp_enqueue_scripts');
496
+		global $wp_scripts, $wp_styles;
497
+		$wp_scripts = $wp_styles = [];
498
+		// just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
499
+		add_action('wp_footer', 'wp_print_footer_scripts');
500
+		add_action('wp_print_footer_scripts', '_wp_footer_scripts');
501
+		add_action('wp_head', 'wp_enqueue_scripts');
502
+	}
503
+
504
+
505
+	/**
506
+	 * Overwrite parent _get_main_template for display_html purposes.
507
+	 *
508
+	 * @param bool $preview
509
+	 * @return string
510
+	 * @since  4.5.0
511
+	 */
512
+	protected function _get_main_template($preview = false): string
513
+	{
514
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name);
515
+		// include message type as a template arg
516
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
517
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
518
+	}
519
+
520
+
521
+	/**
522
+	 * @return void
523
+	 */
524
+	protected function _preview()
525
+	{
526
+		$this->_send_message();
527
+	}
528
+
529
+
530
+	protected function _set_admin_settings_fields()
531
+	{
532
+	}
533
+
534
+
535
+	/**
536
+	 * add the "powered by EE" credit link to the HTML receipt and invoice
537
+	 *
538
+	 * @param string          $content
539
+	 * @param string          $content_again
540
+	 * @param EE_message_type $incoming_message_type
541
+	 * @return string
542
+	 */
543
+	public function add_powered_by_credit_link_to_receipt_and_invoice(
544
+		string $content,
545
+		string $content_again,
546
+		EE_message_type $incoming_message_type
547
+	): string {
548
+		if (
549
+			($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt')
550
+			&& apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true)
551
+		) {
552
+			$content .= EEH_Template::powered_by_event_espresso(
553
+				'aln-cntr',
554
+				'',
555
+				['utm_content' => 'messages_system']
556
+			) . EEH_HTML::div(EEH_HTML::p('&nbsp;'));
557
+		}
558
+		return $content;
559
+	}
560 560
 }
Please login to merge, or discard this patch.
core/libraries/iframe_display/Iframe.php 1 patch
Indentation   +334 added lines, -334 removed lines patch added patch discarded remove patch
@@ -18,373 +18,373 @@
 block discarded – undo
18 18
  */
19 19
 class Iframe
20 20
 {
21
-    /*
21
+	/*
22 22
     * HTML for notices and ajax gif
23 23
     * @var string $title
24 24
     */
25
-    protected $title = '';
25
+	protected $title = '';
26 26
 
27
-    /*
27
+	/*
28 28
     * HTML for the content being displayed
29 29
     * @var string $content
30 30
     */
31
-    protected $content = '';
31
+	protected $content = '';
32 32
 
33
-    /*
33
+	/*
34 34
     * whether or not to call wp_head() and wp_footer()
35 35
     * @var boolean $enqueue_wp_assets
36 36
     */
37
-    protected $enqueue_wp_assets = false;
37
+	protected $enqueue_wp_assets = false;
38 38
 
39
-    /*
39
+	/*
40 40
     * an array of CSS URLs
41 41
     * @var array $css
42 42
     */
43
-    protected $css = array();
43
+	protected $css = array();
44 44
 
45
-    /*
45
+	/*
46 46
     * an array of JS URLs to be set in the HTML header.
47 47
     * @var array $header_js
48 48
     */
49
-    protected $header_js = array();
49
+	protected $header_js = array();
50 50
 
51
-    /*
51
+	/*
52 52
     * an array of additional attributes to be added to <script> tags for header JS
53 53
     * @var array $footer_js
54 54
     */
55
-    protected $header_js_attributes = array();
55
+	protected $header_js_attributes = array();
56 56
 
57
-    /*
57
+	/*
58 58
     * an array of JS URLs to be displayed before the HTML </body> tag
59 59
     * @var array $footer_js
60 60
     */
61
-    protected $footer_js = array();
61
+	protected $footer_js = array();
62 62
 
63
-    /*
63
+	/*
64 64
     * an array of additional attributes to be added to <script> tags for footer JS
65 65
     * @var array $footer_js_attributes
66 66
     */
67
-    protected $footer_js_attributes = array();
67
+	protected $footer_js_attributes = array();
68 68
 
69
-    /*
69
+	/*
70 70
     * an array of JSON vars to be set in the HTML header.
71 71
     * @var array $localized_vars
72 72
     */
73
-    protected $localized_vars = array();
74
-
75
-
76
-    /**
77
-     * Iframe constructor
78
-     *
79
-     * @param string $title
80
-     * @param string $content
81
-     * @throws DomainException
82
-     */
83
-    public function __construct($title, $content)
84
-    {
85
-        global $wp_version;
86
-        if (! defined('EE_IFRAME_DIR_URL')) {
87
-            define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__));
88
-        }
89
-        $this->setContent($content);
90
-        $this->setTitle($title);
91
-        $this->addStylesheets(
92
-            apply_filters(
93
-                'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css',
94
-                array(
95
-                    'site_theme'       => get_stylesheet_directory_uri()
96
-                                          . '/style.css?ver=' . EVENT_ESPRESSO_VERSION,
97
-                    'dashicons'        => includes_url('css/dashicons.min.css?ver=' . $wp_version),
98
-                    'espresso_default' => EE_GLOBAL_ASSETS_URL
99
-                                          . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
100
-                ),
101
-                $this
102
-            )
103
-        );
104
-        $this->addScripts(
105
-            apply_filters(
106
-                'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js',
107
-                array(
108
-                    'jquery'        => includes_url('js/jquery/jquery.js?ver=' . $wp_version),
109
-                    'espresso_core' => EE_GLOBAL_ASSETS_URL
110
-                                       . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION,
111
-                ),
112
-                $this
113
-            )
114
-        );
115
-        if (
116
-            apply_filters(
117
-                'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet',
118
-                false
119
-            )
120
-        ) {
121
-            $this->addStylesheets(
122
-                apply_filters(
123
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet',
124
-                    array('default_theme_stylesheet' => get_stylesheet_uri()),
125
-                    $this
126
-                )
127
-            );
128
-        }
129
-    }
130
-
131
-
132
-    /**
133
-     * @param string $title
134
-     * @throws DomainException
135
-     */
136
-    public function setTitle($title)
137
-    {
138
-        if (empty($title)) {
139
-            throw new DomainException(
140
-                esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso')
141
-            );
142
-        }
143
-        $this->title = $title;
144
-    }
145
-
146
-
147
-    /**
148
-     * @param string $content
149
-     * @throws DomainException
150
-     */
151
-    public function setContent($content)
152
-    {
153
-        if (empty($content)) {
154
-            throw new DomainException(
155
-                esc_html__('You must provide content in order to create an iframe.', 'event_espresso')
156
-            );
157
-        }
158
-        $this->content = $content;
159
-    }
160
-
161
-
162
-    /**
163
-     * @param boolean $enqueue_wp_assets
164
-     */
165
-    public function setEnqueueWpAssets($enqueue_wp_assets)
166
-    {
167
-        $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN);
168
-    }
169
-
170
-
171
-    /**
172
-     * @param array $stylesheets
173
-     * @throws DomainException
174
-     */
175
-    public function addStylesheets(array $stylesheets)
176
-    {
177
-        if (empty($stylesheets)) {
178
-            throw new DomainException(
179
-                esc_html__(
180
-                    'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.',
181
-                    'event_espresso'
182
-                )
183
-            );
184
-        }
185
-        foreach ($stylesheets as $handle => $stylesheet) {
186
-            $this->css[ $handle ] = $stylesheet;
187
-        }
188
-    }
189
-
190
-
191
-    /**
192
-     * @param array $scripts
193
-     * @param bool  $add_to_header
194
-     * @throws DomainException
195
-     */
196
-    public function addScripts(array $scripts, $add_to_header = false)
197
-    {
198
-        if (empty($scripts)) {
199
-            throw new DomainException(
200
-                esc_html__(
201
-                    'A non-empty array of URLs, is required to add Javascript to an iframe.',
202
-                    'event_espresso'
203
-                )
204
-            );
205
-        }
206
-        foreach ($scripts as $handle => $script) {
207
-            if ($add_to_header) {
208
-                $this->header_js[ $handle ] = $script;
209
-            } else {
210
-                $this->footer_js[ $handle ] = $script;
211
-            }
212
-        }
213
-    }
214
-
215
-
216
-    /**
217
-     * @param array $script_attributes
218
-     * @param bool  $add_to_header
219
-     * @throws DomainException
220
-     */
221
-    public function addScriptAttributes(array $script_attributes, $add_to_header = false)
222
-    {
223
-        if (empty($script_attributes)) {
224
-            throw new DomainException(
225
-                esc_html__(
226
-                    'A non-empty array of strings, is required to add attributes to iframe Javascript.',
227
-                    'event_espresso'
228
-                )
229
-            );
230
-        }
231
-        foreach ($script_attributes as $handle => $script_attribute) {
232
-            if ($add_to_header) {
233
-                $this->header_js_attributes[ $handle ] = $script_attribute;
234
-            } else {
235
-                $this->footer_js_attributes[ $handle ] = $script_attribute;
236
-            }
237
-        }
238
-    }
239
-
240
-
241
-    /**
242
-     * @param array  $vars
243
-     * @param string $var_name
244
-     * @throws DomainException
245
-     */
246
-    public function addLocalizedVars(array $vars, $var_name = 'eei18n')
247
-    {
248
-        if (empty($vars)) {
249
-            throw new DomainException(
250
-                esc_html__(
251
-                    'A non-empty array of vars, is required to add localized Javascript vars to an iframe.',
252
-                    'event_espresso'
253
-                )
254
-            );
255
-        }
256
-        foreach ($vars as $handle => $var) {
257
-            if ($var_name === 'eei18n') {
258
-                EE_Registry::$i18n_js_strings[ $handle ] = $var;
259
-            } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') {
260
-                $this->localized_vars[ $var_name ] = $var;
261
-            } else {
262
-                if (! isset($this->localized_vars[ $var_name ])) {
263
-                    $this->localized_vars[ $var_name ] = array();
264
-                }
265
-                $this->localized_vars[ $var_name ][ $handle ] = $var;
266
-            }
267
-        }
268
-    }
269
-
270
-
271
-    /**
272
-     * @param string $utm_content
273
-     * @throws DomainException
274
-     */
275
-    public function display($utm_content = '')
276
-    {
277
-        $this->content .= EEH_Template::powered_by_event_espresso(
278
-            '',
279
-            '',
280
-            ! empty($utm_content) ? array('utm_content' => $utm_content) : array()
281
-        );
282
-        EE_System::do_not_cache();
283
-        echo ($this->getTemplate());
284
-        exit;
285
-    }
286
-
287
-
288
-    /**
289
-     * @return string
290
-     * @throws DomainException
291
-     */
292
-    public function getTemplate()
293
-    {
294
-        return EEH_Template::display_template(
295
-            __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php',
296
-            array(
297
-                'title'                => apply_filters(
298
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title',
299
-                    $this->title,
300
-                    $this
301
-                ),
302
-                'content'              => apply_filters(
303
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content',
304
-                    $this->content,
305
-                    $this
306
-                ),
307
-                'enqueue_wp_assets'    => apply_filters(
308
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets',
309
-                    $this->enqueue_wp_assets,
310
-                    $this
311
-                ),
312
-                'css'                  => (array) apply_filters(
313
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls',
314
-                    $this->css,
315
-                    $this
316
-                ),
317
-                'header_js'            => (array) apply_filters(
318
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls',
319
-                    $this->header_js,
320
-                    $this
321
-                ),
322
-                'header_js_attributes' => (array) apply_filters(
323
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes',
324
-                    $this->header_js_attributes,
325
-                    $this
326
-                ),
327
-                'footer_js'            => (array) apply_filters(
328
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls',
329
-                    $this->footer_js,
330
-                    $this
331
-                ),
332
-                'footer_js_attributes' => (array) apply_filters(
333
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes',
334
-                    $this->footer_js_attributes,
335
-                    $this
336
-                ),
337
-                'eei18n'               => apply_filters(
338
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings',
339
-                    EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(),
340
-                    $this
341
-                ),
342
-                'notices'              => EEH_Template::display_template(
343
-                    EE_TEMPLATES . 'espresso-ajax-notices.template.php',
344
-                    array(),
345
-                    true
346
-                ),
347
-            ),
348
-            true,
349
-            true
350
-        );
351
-    }
352
-
353
-
354
-    /**
355
-     * localizeJsonVars
356
-     *
357
-     * @return string
358
-     */
359
-    public function localizeJsonVars()
360
-    {
361
-        $JSON = '';
362
-        foreach ($this->localized_vars as $var_name => $vars) {
363
-            $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars);
364
-            $JSON .= "/* <![CDATA[ */ var {$var_name} = ";
365
-            $JSON .= wp_json_encode($this->localized_vars[ $var_name ]);
366
-            $JSON .= '; /* ]]> */';
367
-        }
368
-        return $JSON;
369
-    }
370
-
371
-
372
-    /**
373
-     * @param bool|int|float|string|array $var
374
-     * @return array|string|null
375
-     */
376
-    public function encodeJsonVars($var)
377
-    {
378
-        if (is_array($var)) {
379
-            $localized_vars = array();
380
-            foreach ((array) $var as $key => $value) {
381
-                $localized_vars[ $key ] = $this->encodeJsonVars($value);
382
-            }
383
-            return $localized_vars;
384
-        }
385
-        if (is_scalar($var)) {
386
-            return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8');
387
-        }
388
-        return null;
389
-    }
73
+	protected $localized_vars = array();
74
+
75
+
76
+	/**
77
+	 * Iframe constructor
78
+	 *
79
+	 * @param string $title
80
+	 * @param string $content
81
+	 * @throws DomainException
82
+	 */
83
+	public function __construct($title, $content)
84
+	{
85
+		global $wp_version;
86
+		if (! defined('EE_IFRAME_DIR_URL')) {
87
+			define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__));
88
+		}
89
+		$this->setContent($content);
90
+		$this->setTitle($title);
91
+		$this->addStylesheets(
92
+			apply_filters(
93
+				'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css',
94
+				array(
95
+					'site_theme'       => get_stylesheet_directory_uri()
96
+										  . '/style.css?ver=' . EVENT_ESPRESSO_VERSION,
97
+					'dashicons'        => includes_url('css/dashicons.min.css?ver=' . $wp_version),
98
+					'espresso_default' => EE_GLOBAL_ASSETS_URL
99
+										  . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
100
+				),
101
+				$this
102
+			)
103
+		);
104
+		$this->addScripts(
105
+			apply_filters(
106
+				'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js',
107
+				array(
108
+					'jquery'        => includes_url('js/jquery/jquery.js?ver=' . $wp_version),
109
+					'espresso_core' => EE_GLOBAL_ASSETS_URL
110
+									   . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION,
111
+				),
112
+				$this
113
+			)
114
+		);
115
+		if (
116
+			apply_filters(
117
+				'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet',
118
+				false
119
+			)
120
+		) {
121
+			$this->addStylesheets(
122
+				apply_filters(
123
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet',
124
+					array('default_theme_stylesheet' => get_stylesheet_uri()),
125
+					$this
126
+				)
127
+			);
128
+		}
129
+	}
130
+
131
+
132
+	/**
133
+	 * @param string $title
134
+	 * @throws DomainException
135
+	 */
136
+	public function setTitle($title)
137
+	{
138
+		if (empty($title)) {
139
+			throw new DomainException(
140
+				esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso')
141
+			);
142
+		}
143
+		$this->title = $title;
144
+	}
145
+
146
+
147
+	/**
148
+	 * @param string $content
149
+	 * @throws DomainException
150
+	 */
151
+	public function setContent($content)
152
+	{
153
+		if (empty($content)) {
154
+			throw new DomainException(
155
+				esc_html__('You must provide content in order to create an iframe.', 'event_espresso')
156
+			);
157
+		}
158
+		$this->content = $content;
159
+	}
160
+
161
+
162
+	/**
163
+	 * @param boolean $enqueue_wp_assets
164
+	 */
165
+	public function setEnqueueWpAssets($enqueue_wp_assets)
166
+	{
167
+		$this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN);
168
+	}
169
+
170
+
171
+	/**
172
+	 * @param array $stylesheets
173
+	 * @throws DomainException
174
+	 */
175
+	public function addStylesheets(array $stylesheets)
176
+	{
177
+		if (empty($stylesheets)) {
178
+			throw new DomainException(
179
+				esc_html__(
180
+					'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.',
181
+					'event_espresso'
182
+				)
183
+			);
184
+		}
185
+		foreach ($stylesheets as $handle => $stylesheet) {
186
+			$this->css[ $handle ] = $stylesheet;
187
+		}
188
+	}
189
+
190
+
191
+	/**
192
+	 * @param array $scripts
193
+	 * @param bool  $add_to_header
194
+	 * @throws DomainException
195
+	 */
196
+	public function addScripts(array $scripts, $add_to_header = false)
197
+	{
198
+		if (empty($scripts)) {
199
+			throw new DomainException(
200
+				esc_html__(
201
+					'A non-empty array of URLs, is required to add Javascript to an iframe.',
202
+					'event_espresso'
203
+				)
204
+			);
205
+		}
206
+		foreach ($scripts as $handle => $script) {
207
+			if ($add_to_header) {
208
+				$this->header_js[ $handle ] = $script;
209
+			} else {
210
+				$this->footer_js[ $handle ] = $script;
211
+			}
212
+		}
213
+	}
214
+
215
+
216
+	/**
217
+	 * @param array $script_attributes
218
+	 * @param bool  $add_to_header
219
+	 * @throws DomainException
220
+	 */
221
+	public function addScriptAttributes(array $script_attributes, $add_to_header = false)
222
+	{
223
+		if (empty($script_attributes)) {
224
+			throw new DomainException(
225
+				esc_html__(
226
+					'A non-empty array of strings, is required to add attributes to iframe Javascript.',
227
+					'event_espresso'
228
+				)
229
+			);
230
+		}
231
+		foreach ($script_attributes as $handle => $script_attribute) {
232
+			if ($add_to_header) {
233
+				$this->header_js_attributes[ $handle ] = $script_attribute;
234
+			} else {
235
+				$this->footer_js_attributes[ $handle ] = $script_attribute;
236
+			}
237
+		}
238
+	}
239
+
240
+
241
+	/**
242
+	 * @param array  $vars
243
+	 * @param string $var_name
244
+	 * @throws DomainException
245
+	 */
246
+	public function addLocalizedVars(array $vars, $var_name = 'eei18n')
247
+	{
248
+		if (empty($vars)) {
249
+			throw new DomainException(
250
+				esc_html__(
251
+					'A non-empty array of vars, is required to add localized Javascript vars to an iframe.',
252
+					'event_espresso'
253
+				)
254
+			);
255
+		}
256
+		foreach ($vars as $handle => $var) {
257
+			if ($var_name === 'eei18n') {
258
+				EE_Registry::$i18n_js_strings[ $handle ] = $var;
259
+			} elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') {
260
+				$this->localized_vars[ $var_name ] = $var;
261
+			} else {
262
+				if (! isset($this->localized_vars[ $var_name ])) {
263
+					$this->localized_vars[ $var_name ] = array();
264
+				}
265
+				$this->localized_vars[ $var_name ][ $handle ] = $var;
266
+			}
267
+		}
268
+	}
269
+
270
+
271
+	/**
272
+	 * @param string $utm_content
273
+	 * @throws DomainException
274
+	 */
275
+	public function display($utm_content = '')
276
+	{
277
+		$this->content .= EEH_Template::powered_by_event_espresso(
278
+			'',
279
+			'',
280
+			! empty($utm_content) ? array('utm_content' => $utm_content) : array()
281
+		);
282
+		EE_System::do_not_cache();
283
+		echo ($this->getTemplate());
284
+		exit;
285
+	}
286
+
287
+
288
+	/**
289
+	 * @return string
290
+	 * @throws DomainException
291
+	 */
292
+	public function getTemplate()
293
+	{
294
+		return EEH_Template::display_template(
295
+			__DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php',
296
+			array(
297
+				'title'                => apply_filters(
298
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title',
299
+					$this->title,
300
+					$this
301
+				),
302
+				'content'              => apply_filters(
303
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content',
304
+					$this->content,
305
+					$this
306
+				),
307
+				'enqueue_wp_assets'    => apply_filters(
308
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets',
309
+					$this->enqueue_wp_assets,
310
+					$this
311
+				),
312
+				'css'                  => (array) apply_filters(
313
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls',
314
+					$this->css,
315
+					$this
316
+				),
317
+				'header_js'            => (array) apply_filters(
318
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls',
319
+					$this->header_js,
320
+					$this
321
+				),
322
+				'header_js_attributes' => (array) apply_filters(
323
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes',
324
+					$this->header_js_attributes,
325
+					$this
326
+				),
327
+				'footer_js'            => (array) apply_filters(
328
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls',
329
+					$this->footer_js,
330
+					$this
331
+				),
332
+				'footer_js_attributes' => (array) apply_filters(
333
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes',
334
+					$this->footer_js_attributes,
335
+					$this
336
+				),
337
+				'eei18n'               => apply_filters(
338
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings',
339
+					EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(),
340
+					$this
341
+				),
342
+				'notices'              => EEH_Template::display_template(
343
+					EE_TEMPLATES . 'espresso-ajax-notices.template.php',
344
+					array(),
345
+					true
346
+				),
347
+			),
348
+			true,
349
+			true
350
+		);
351
+	}
352
+
353
+
354
+	/**
355
+	 * localizeJsonVars
356
+	 *
357
+	 * @return string
358
+	 */
359
+	public function localizeJsonVars()
360
+	{
361
+		$JSON = '';
362
+		foreach ($this->localized_vars as $var_name => $vars) {
363
+			$this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars);
364
+			$JSON .= "/* <![CDATA[ */ var {$var_name} = ";
365
+			$JSON .= wp_json_encode($this->localized_vars[ $var_name ]);
366
+			$JSON .= '; /* ]]> */';
367
+		}
368
+		return $JSON;
369
+	}
370
+
371
+
372
+	/**
373
+	 * @param bool|int|float|string|array $var
374
+	 * @return array|string|null
375
+	 */
376
+	public function encodeJsonVars($var)
377
+	{
378
+		if (is_array($var)) {
379
+			$localized_vars = array();
380
+			foreach ((array) $var as $key => $value) {
381
+				$localized_vars[ $key ] = $this->encodeJsonVars($value);
382
+			}
383
+			return $localized_vars;
384
+		}
385
+		if (is_scalar($var)) {
386
+			return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8');
387
+		}
388
+		return null;
389
+	}
390 390
 }
Please login to merge, or discard this patch.
core/libraries/iframe_display/iframe_wrapper.template.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
                 <?php echo ($eei18n); ?>
37 37
             </script>
38 38
         <?php foreach ($header_js as $key => $url) :?>
39
-            <?php $header_attributes = isset($header_js_attributes[ $key ]) ? $header_js_attributes[ $key ] : ''; ?>
39
+            <?php $header_attributes = isset($header_js_attributes[$key]) ? $header_js_attributes[$key] : ''; ?>
40 40
         <script type="text/javascript" src="<?php echo esc_url_raw($url); ?>" <?php echo AttributesSanitizer::clean($header_attributes, AllowedTags::getAllowedTags(), 'script'); ?>></script>
41 41
         <?php endforeach; ?>
42 42
     <?php endif; ?>
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     <?php echo wp_kses($content, AllowedTags::getWithFullTags()); ?>
48 48
 </div>
49 49
 <?php foreach ($footer_js as $key => $url) : ?>
50
-    <?php $footer_attributes = isset($footer_js_attributes[ $key ]) ? $footer_js_attributes[ $key ] : ''; ?>
50
+    <?php $footer_attributes = isset($footer_js_attributes[$key]) ? $footer_js_attributes[$key] : ''; ?>
51 51
     <script type="text/javascript" src="<?php echo esc_url_raw($url); ?>" <?php echo AttributesSanitizer::clean($footer_attributes, AllowedTags::getAllowedTags(), 'script'); ?>></script>
52 52
 <?php endforeach; ?>
53 53
 <?php if ($enqueue_wp_assets) : ?>
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,9 +28,12 @@
 block discarded – undo
28 28
     <title><?php echo wp_strip_all_tags($title); ?></title>
29 29
     <?php if ($enqueue_wp_assets) : ?>
30 30
         <?php wp_head(); ?>
31
-    <?php else : ?>
31
+    <?php else {
32
+	: ?>
32 33
         <?php foreach ($css as $url) :?>
33
-    <link rel="stylesheet" type="text/css" href="<?php echo esc_url_raw($url); ?>">
34
+    <link rel="stylesheet" type="text/css" href="<?php echo esc_url_raw($url);
35
+}
36
+?>">
34 37
         <?php endforeach; ?>
35 38
             <script type="text/javascript">
36 39
                 <?php echo ($eei18n); ?>
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2799 added lines, -2799 removed lines patch added patch discarded remove patch
@@ -15,2806 +15,2806 @@
 block discarded – undo
15 15
  */
16 16
 class Events_Admin_Page extends EE_Admin_Page_CPT
17 17
 {
18
-    /**
19
-     * This will hold the event object for event_details screen.
18
+	/**
19
+	 * This will hold the event object for event_details screen.
20
+	 *
21
+	 * @var EE_Event $_event
22
+	 */
23
+	protected $_event;
24
+
25
+
26
+	/**
27
+	 * This will hold the category object for category_details screen.
28
+	 *
29
+	 * @var stdClass $_category
30
+	 */
31
+	protected $_category;
32
+
33
+
34
+	/**
35
+	 * This will hold the event model instance
36
+	 *
37
+	 * @var EEM_Event $_event_model
38
+	 */
39
+	protected $_event_model;
40
+
41
+
42
+	/**
43
+	 * @var EE_Event
44
+	 */
45
+	protected $_cpt_model_obj = false;
46
+
47
+
48
+	/**
49
+	 * @var NodeGroupDao
50
+	 */
51
+	protected $model_obj_node_group_persister;
52
+
53
+
54
+	/**
55
+	 * Initialize page props for this admin page group.
56
+	 */
57
+	protected function _init_page_props()
58
+	{
59
+		$this->page_slug        = EVENTS_PG_SLUG;
60
+		$this->page_label       = EVENTS_LABEL;
61
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
62
+		$this->_admin_base_path = EVENTS_ADMIN;
63
+		$this->_cpt_model_names = [
64
+			'create_new' => 'EEM_Event',
65
+			'edit'       => 'EEM_Event',
66
+		];
67
+		$this->_cpt_edit_routes = [
68
+			'espresso_events' => 'edit',
69
+		];
70
+		add_action(
71
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
72
+			[$this, 'verify_event_edit'],
73
+			10,
74
+			2
75
+		);
76
+	}
77
+
78
+
79
+	/**
80
+	 * Sets the ajax hooks used for this admin page group.
81
+	 */
82
+	protected function _ajax_hooks()
83
+	{
84
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
85
+	}
86
+
87
+
88
+	/**
89
+	 * Sets the page properties for this admin page group.
90
+	 */
91
+	protected function _define_page_props()
92
+	{
93
+		$this->_admin_page_title = EVENTS_LABEL;
94
+		$this->_labels           = [
95
+			'buttons'      => [
96
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
97
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
98
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
99
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
100
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
101
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
102
+			],
103
+			'editor_title' => [
104
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
105
+			],
106
+			'publishbox'   => [
107
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
108
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
109
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
110
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
111
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
112
+			],
113
+		];
114
+	}
115
+
116
+
117
+	/**
118
+	 * Sets the page routes property for this admin page group.
119
+	 */
120
+	protected function _set_page_routes()
121
+	{
122
+		// load formatter helper
123
+		// load field generator helper
124
+		// is there a evt_id in the request?
125
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
126
+		$EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
127
+
128
+		$this->_page_routes = [
129
+			'default'                       => [
130
+				'func'       => '_events_overview_list_table',
131
+				'capability' => 'ee_read_events',
132
+			],
133
+			'create_new'                    => [
134
+				'func'       => '_create_new_cpt_item',
135
+				'capability' => 'ee_edit_events',
136
+			],
137
+			'edit'                          => [
138
+				'func'       => '_edit_cpt_item',
139
+				'capability' => 'ee_edit_event',
140
+				'obj_id'     => $EVT_ID,
141
+			],
142
+			'copy_event'                    => [
143
+				'func'       => '_copy_events',
144
+				'capability' => 'ee_edit_event',
145
+				'obj_id'     => $EVT_ID,
146
+				'noheader'   => true,
147
+			],
148
+			'trash_event'                   => [
149
+				'func'       => '_trash_or_restore_event',
150
+				'args'       => ['event_status' => 'trash'],
151
+				'capability' => 'ee_delete_event',
152
+				'obj_id'     => $EVT_ID,
153
+				'noheader'   => true,
154
+			],
155
+			'trash_events'                  => [
156
+				'func'       => '_trash_or_restore_events',
157
+				'args'       => ['event_status' => 'trash'],
158
+				'capability' => 'ee_delete_events',
159
+				'noheader'   => true,
160
+			],
161
+			'restore_event'                 => [
162
+				'func'       => '_trash_or_restore_event',
163
+				'args'       => ['event_status' => 'draft'],
164
+				'capability' => 'ee_delete_event',
165
+				'obj_id'     => $EVT_ID,
166
+				'noheader'   => true,
167
+			],
168
+			'restore_events'                => [
169
+				'func'       => '_trash_or_restore_events',
170
+				'args'       => ['event_status' => 'draft'],
171
+				'capability' => 'ee_delete_events',
172
+				'noheader'   => true,
173
+			],
174
+			'delete_event'                  => [
175
+				'func'       => '_delete_event',
176
+				'capability' => 'ee_delete_event',
177
+				'obj_id'     => $EVT_ID,
178
+				'noheader'   => true,
179
+			],
180
+			'delete_events'                 => [
181
+				'func'       => '_delete_events',
182
+				'capability' => 'ee_delete_events',
183
+				'noheader'   => true,
184
+			],
185
+			'view_report'                   => [
186
+				'func'       => '_view_report',
187
+				'capability' => 'ee_edit_events',
188
+			],
189
+			'default_event_settings'        => [
190
+				'func'       => '_default_event_settings',
191
+				'capability' => 'manage_options',
192
+			],
193
+			'update_default_event_settings' => [
194
+				'func'       => '_update_default_event_settings',
195
+				'capability' => 'manage_options',
196
+				'noheader'   => true,
197
+			],
198
+			'template_settings'             => [
199
+				'func'       => '_template_settings',
200
+				'capability' => 'manage_options',
201
+			],
202
+			// event category tab related
203
+			'add_category'                  => [
204
+				'func'       => '_category_details',
205
+				'capability' => 'ee_edit_event_category',
206
+				'args'       => ['add'],
207
+			],
208
+			'edit_category'                 => [
209
+				'func'       => '_category_details',
210
+				'capability' => 'ee_edit_event_category',
211
+				'args'       => ['edit'],
212
+			],
213
+			'delete_categories'             => [
214
+				'func'       => '_delete_categories',
215
+				'capability' => 'ee_delete_event_category',
216
+				'noheader'   => true,
217
+			],
218
+			'delete_category'               => [
219
+				'func'       => '_delete_categories',
220
+				'capability' => 'ee_delete_event_category',
221
+				'noheader'   => true,
222
+			],
223
+			'insert_category'               => [
224
+				'func'       => '_insert_or_update_category',
225
+				'args'       => ['new_category' => true],
226
+				'capability' => 'ee_edit_event_category',
227
+				'noheader'   => true,
228
+			],
229
+			'update_category'               => [
230
+				'func'       => '_insert_or_update_category',
231
+				'args'       => ['new_category' => false],
232
+				'capability' => 'ee_edit_event_category',
233
+				'noheader'   => true,
234
+			],
235
+			'category_list'                 => [
236
+				'func'       => '_category_list_table',
237
+				'capability' => 'ee_manage_event_categories',
238
+			],
239
+			'preview_deletion'              => [
240
+				'func'       => 'previewDeletion',
241
+				'capability' => 'ee_delete_events',
242
+			],
243
+			'confirm_deletion'              => [
244
+				'func'       => 'confirmDeletion',
245
+				'capability' => 'ee_delete_events',
246
+				'noheader'   => true,
247
+			],
248
+		];
249
+	}
250
+
251
+
252
+	/**
253
+	 * Set the _page_config property for this admin page group.
254
+	 */
255
+	protected function _set_page_config()
256
+	{
257
+		$post_id            = $this->request->getRequestParam('post', 0, 'int');
258
+		$EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
259
+		$this->_page_config = [
260
+			'default'                => [
261
+				'nav'           => [
262
+					'label' => esc_html__('Overview', 'event_espresso'),
263
+					'order' => 10,
264
+				],
265
+				'list_table'    => 'Events_Admin_List_Table',
266
+				'help_tabs'     => [
267
+					'events_overview_help_tab'                       => [
268
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
269
+						'filename' => 'events_overview',
270
+					],
271
+					'events_overview_table_column_headings_help_tab' => [
272
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
273
+						'filename' => 'events_overview_table_column_headings',
274
+					],
275
+					'events_overview_filters_help_tab'               => [
276
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
277
+						'filename' => 'events_overview_filters',
278
+					],
279
+					'events_overview_view_help_tab'                  => [
280
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
281
+						'filename' => 'events_overview_views',
282
+					],
283
+					'events_overview_other_help_tab'                 => [
284
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
285
+						'filename' => 'events_overview_other',
286
+					],
287
+				],
288
+				'qtips'         => [
289
+					'EE_Event_List_Table_Tips',
290
+				],
291
+				'require_nonce' => false,
292
+			],
293
+			'create_new'             => [
294
+				'nav'           => [
295
+					'label'      => esc_html__('Add Event', 'event_espresso'),
296
+					'order'      => 5,
297
+					'persistent' => false,
298
+				],
299
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
300
+				'help_tabs'     => [
301
+					'event_editor_help_tab'                            => [
302
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
303
+						'filename' => 'event_editor',
304
+					],
305
+					'event_editor_title_richtexteditor_help_tab'       => [
306
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
307
+						'filename' => 'event_editor_title_richtexteditor',
308
+					],
309
+					'event_editor_venue_details_help_tab'              => [
310
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
311
+						'filename' => 'event_editor_venue_details',
312
+					],
313
+					'event_editor_event_datetimes_help_tab'            => [
314
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
315
+						'filename' => 'event_editor_event_datetimes',
316
+					],
317
+					'event_editor_event_tickets_help_tab'              => [
318
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
319
+						'filename' => 'event_editor_event_tickets',
320
+					],
321
+					'event_editor_event_registration_options_help_tab' => [
322
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
323
+						'filename' => 'event_editor_event_registration_options',
324
+					],
325
+					'event_editor_tags_categories_help_tab'            => [
326
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
327
+						'filename' => 'event_editor_tags_categories',
328
+					],
329
+					'event_editor_questions_registrants_help_tab'      => [
330
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
331
+						'filename' => 'event_editor_questions_registrants',
332
+					],
333
+					'event_editor_save_new_event_help_tab'             => [
334
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
335
+						'filename' => 'event_editor_save_new_event',
336
+					],
337
+					'event_editor_other_help_tab'                      => [
338
+						'title'    => esc_html__('Event Other', 'event_espresso'),
339
+						'filename' => 'event_editor_other',
340
+					],
341
+				],
342
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
343
+				'require_nonce' => false,
344
+			],
345
+			'edit'                   => [
346
+				'nav'           => [
347
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
348
+					'order'      => 5,
349
+					'persistent' => false,
350
+					'url'        => $post_id
351
+						? EE_Admin_Page::add_query_args_and_nonce(
352
+							['post' => $post_id, 'action' => 'edit'],
353
+							$this->_current_page_view_url
354
+						)
355
+						: $this->_admin_base_url,
356
+				],
357
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
358
+				'help_tabs'     => [
359
+					'event_editor_help_tab'                            => [
360
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
361
+						'filename' => 'event_editor',
362
+					],
363
+					'event_editor_title_richtexteditor_help_tab'       => [
364
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
365
+						'filename' => 'event_editor_title_richtexteditor',
366
+					],
367
+					'event_editor_venue_details_help_tab'              => [
368
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
369
+						'filename' => 'event_editor_venue_details',
370
+					],
371
+					'event_editor_event_datetimes_help_tab'            => [
372
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
373
+						'filename' => 'event_editor_event_datetimes',
374
+					],
375
+					'event_editor_event_tickets_help_tab'              => [
376
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
377
+						'filename' => 'event_editor_event_tickets',
378
+					],
379
+					'event_editor_event_registration_options_help_tab' => [
380
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
381
+						'filename' => 'event_editor_event_registration_options',
382
+					],
383
+					'event_editor_tags_categories_help_tab'            => [
384
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
385
+						'filename' => 'event_editor_tags_categories',
386
+					],
387
+					'event_editor_questions_registrants_help_tab'      => [
388
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
389
+						'filename' => 'event_editor_questions_registrants',
390
+					],
391
+					'event_editor_save_new_event_help_tab'             => [
392
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
393
+						'filename' => 'event_editor_save_new_event',
394
+					],
395
+					'event_editor_other_help_tab'                      => [
396
+						'title'    => esc_html__('Event Other', 'event_espresso'),
397
+						'filename' => 'event_editor_other',
398
+					],
399
+				],
400
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
401
+				'require_nonce' => false,
402
+			],
403
+			'default_event_settings' => [
404
+				'nav'           => [
405
+					'label' => esc_html__('Default Settings', 'event_espresso'),
406
+					'order' => 40,
407
+				],
408
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
409
+				'labels'        => [
410
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
411
+				],
412
+				'help_tabs'     => [
413
+					'default_settings_help_tab'        => [
414
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
415
+						'filename' => 'events_default_settings',
416
+					],
417
+					'default_settings_status_help_tab' => [
418
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
419
+						'filename' => 'events_default_settings_status',
420
+					],
421
+					'default_maximum_tickets_help_tab' => [
422
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
423
+						'filename' => 'events_default_settings_max_tickets',
424
+					],
425
+				],
426
+				'require_nonce' => false,
427
+			],
428
+			// template settings
429
+			'template_settings'      => [
430
+				'nav'           => [
431
+					'label' => esc_html__('Templates', 'event_espresso'),
432
+					'order' => 30,
433
+				],
434
+				'metaboxes'     => $this->_default_espresso_metaboxes,
435
+				'help_tabs'     => [
436
+					'general_settings_templates_help_tab' => [
437
+						'title'    => esc_html__('Templates', 'event_espresso'),
438
+						'filename' => 'general_settings_templates',
439
+					],
440
+				],
441
+				'require_nonce' => false,
442
+			],
443
+			// event category stuff
444
+			'add_category'           => [
445
+				'nav'           => [
446
+					'label'      => esc_html__('Add Category', 'event_espresso'),
447
+					'order'      => 15,
448
+					'persistent' => false,
449
+				],
450
+				'help_tabs'     => [
451
+					'add_category_help_tab' => [
452
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
453
+						'filename' => 'events_add_category',
454
+					],
455
+				],
456
+				'metaboxes'     => ['_publish_post_box'],
457
+				'require_nonce' => false,
458
+			],
459
+			'edit_category'          => [
460
+				'nav'           => [
461
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
462
+					'order'      => 15,
463
+					'persistent' => false,
464
+					'url'        => $EVT_CAT_ID
465
+						? add_query_arg(
466
+							['EVT_CAT_ID' => $EVT_CAT_ID],
467
+							$this->_current_page_view_url
468
+						)
469
+						: $this->_admin_base_url,
470
+				],
471
+				'help_tabs'     => [
472
+					'edit_category_help_tab' => [
473
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
474
+						'filename' => 'events_edit_category',
475
+					],
476
+				],
477
+				'metaboxes'     => ['_publish_post_box'],
478
+				'require_nonce' => false,
479
+			],
480
+			'category_list'          => [
481
+				'nav'           => [
482
+					'label' => esc_html__('Categories', 'event_espresso'),
483
+					'order' => 20,
484
+				],
485
+				'list_table'    => 'Event_Categories_Admin_List_Table',
486
+				'help_tabs'     => [
487
+					'events_categories_help_tab'                       => [
488
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
489
+						'filename' => 'events_categories',
490
+					],
491
+					'events_categories_table_column_headings_help_tab' => [
492
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
493
+						'filename' => 'events_categories_table_column_headings',
494
+					],
495
+					'events_categories_view_help_tab'                  => [
496
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
497
+						'filename' => 'events_categories_views',
498
+					],
499
+					'events_categories_other_help_tab'                 => [
500
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
501
+						'filename' => 'events_categories_other',
502
+					],
503
+				],
504
+				'metaboxes'     => $this->_default_espresso_metaboxes,
505
+				'require_nonce' => false,
506
+			],
507
+			'preview_deletion'       => [
508
+				'nav'           => [
509
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
510
+					'order'      => 15,
511
+					'persistent' => false,
512
+					'url'        => '',
513
+				],
514
+				'require_nonce' => false,
515
+			],
516
+		];
517
+	}
518
+
519
+
520
+	/**
521
+	 * Used to register any global screen options if necessary for every route in this admin page group.
522
+	 */
523
+	protected function _add_screen_options()
524
+	{
525
+	}
526
+
527
+
528
+	/**
529
+	 * Implementing the screen options for the 'default' route.
530
+	 */
531
+	protected function _add_screen_options_default()
532
+	{
533
+		$this->_per_page_screen_option();
534
+	}
535
+
536
+
537
+	/**
538
+	 * Implementing screen options for the category list route.
539
+	 */
540
+	protected function _add_screen_options_category_list()
541
+	{
542
+		$page_title              = $this->_admin_page_title;
543
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
544
+		$this->_per_page_screen_option();
545
+		$this->_admin_page_title = $page_title;
546
+	}
547
+
548
+
549
+	/**
550
+	 * Used to register any global feature pointers for the admin page group.
551
+	 */
552
+	protected function _add_feature_pointers()
553
+	{
554
+	}
555
+
556
+
557
+	/**
558
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
559
+	 */
560
+	public function load_scripts_styles()
561
+	{
562
+		wp_register_style(
563
+			'events-admin-css',
564
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
565
+			[],
566
+			EVENT_ESPRESSO_VERSION
567
+		);
568
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
569
+		wp_enqueue_style('events-admin-css');
570
+		wp_enqueue_style('ee-cat-admin');
571
+		// todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
572
+		// registers for all views
573
+		// scripts
574
+		wp_register_script(
575
+			'event_editor_js',
576
+			EVENTS_ASSETS_URL . 'event_editor.js',
577
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
578
+			EVENT_ESPRESSO_VERSION,
579
+			true
580
+		);
581
+	}
582
+
583
+
584
+	/**
585
+	 * Enqueuing scripts and styles specific to this view
586
+	 */
587
+	public function load_scripts_styles_create_new()
588
+	{
589
+		$this->load_scripts_styles_edit();
590
+	}
591
+
592
+
593
+	/**
594
+	 * Enqueuing scripts and styles specific to this view
595
+	 */
596
+	public function load_scripts_styles_edit()
597
+	{
598
+		// styles
599
+		wp_enqueue_style('espresso-ui-theme');
600
+		wp_register_style(
601
+			'event-editor-css',
602
+			EVENTS_ASSETS_URL . 'event-editor.css',
603
+			['ee-admin-css'],
604
+			EVENT_ESPRESSO_VERSION
605
+		);
606
+		wp_enqueue_style('event-editor-css');
607
+		// scripts
608
+		wp_register_script(
609
+			'event-datetime-metabox',
610
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
611
+			['event_editor_js', 'ee-datepicker'],
612
+			EVENT_ESPRESSO_VERSION
613
+		);
614
+		wp_enqueue_script('event-datetime-metabox');
615
+	}
616
+
617
+
618
+	/**
619
+	 * Populating the _views property for the category list table view.
620
+	 */
621
+	protected function _set_list_table_views_category_list()
622
+	{
623
+		$this->_views = [
624
+			'all' => [
625
+				'slug'        => 'all',
626
+				'label'       => esc_html__('All', 'event_espresso'),
627
+				'count'       => 0,
628
+				'bulk_action' => [
629
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
630
+				],
631
+			],
632
+		];
633
+	}
634
+
635
+
636
+	/**
637
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
638
+	 */
639
+	public function admin_init()
640
+	{
641
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
642
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
643
+			'event_espresso'
644
+		);
645
+	}
646
+
647
+
648
+	/**
649
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
650
+	 * group.
651
+	 */
652
+	public function admin_notices()
653
+	{
654
+	}
655
+
656
+
657
+	/**
658
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
659
+	 * this admin page group.
660
+	 */
661
+	public function admin_footer_scripts()
662
+	{
663
+	}
664
+
665
+
666
+	/**
667
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
668
+	 * warning (via EE_Error::add_error());
669
+	 *
670
+	 * @param EE_Event $event Event object
671
+	 * @param string   $req_type
672
+	 * @return void
673
+	 * @throws EE_Error
674
+	 * @throws ReflectionException
675
+	 */
676
+	public function verify_event_edit($event = null, $req_type = '')
677
+	{
678
+		// don't need to do this when processing
679
+		if (! empty($req_type)) {
680
+			return;
681
+		}
682
+		// no event?
683
+		if (empty($event)) {
684
+			// set event
685
+			$event = $this->_cpt_model_obj;
686
+		}
687
+		// STILL no event?
688
+		if (! $event instanceof EE_Event) {
689
+			return;
690
+		}
691
+		$orig_status = $event->status();
692
+		// first check if event is active.
693
+		if (
694
+			$orig_status === EEM_Event::cancelled
695
+			|| $orig_status === EEM_Event::postponed
696
+			|| $event->is_expired()
697
+			|| $event->is_inactive()
698
+		) {
699
+			return;
700
+		}
701
+		// made it here so it IS active... next check that any of the tickets are sold.
702
+		if ($event->is_sold_out(true)) {
703
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
704
+				EE_Error::add_attention(
705
+					sprintf(
706
+						esc_html__(
707
+							'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.',
708
+							'event_espresso'
709
+						),
710
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
711
+					)
712
+				);
713
+			}
714
+			return;
715
+		} elseif ($orig_status === EEM_Event::sold_out) {
716
+			EE_Error::add_attention(
717
+				sprintf(
718
+					esc_html__(
719
+						'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.',
720
+						'event_espresso'
721
+					),
722
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
723
+				)
724
+			);
725
+		}
726
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
727
+		if (! $event->tickets_on_sale()) {
728
+			return;
729
+		}
730
+		// made it here so show warning
731
+		$this->_edit_event_warning();
732
+	}
733
+
734
+
735
+	/**
736
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
737
+	 * When needed, hook this into a EE_Error::add_error() notice.
738
+	 *
739
+	 * @access protected
740
+	 * @return void
741
+	 */
742
+	protected function _edit_event_warning()
743
+	{
744
+		// we don't want to add warnings during these requests
745
+		if ($this->request->getRequestParam('action') === 'editpost') {
746
+			return;
747
+		}
748
+		EE_Error::add_attention(
749
+			sprintf(
750
+				esc_html__(
751
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
752
+					'event_espresso'
753
+				),
754
+				'<a class="espresso-help-tab-lnk">',
755
+				'</a>'
756
+			)
757
+		);
758
+	}
759
+
760
+
761
+	/**
762
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
763
+	 * Otherwise, do the normal logic
764
+	 *
765
+	 * @return void
766
+	 * @throws EE_Error
767
+	 */
768
+	protected function _create_new_cpt_item()
769
+	{
770
+		$has_timezone_string = get_option('timezone_string');
771
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
772
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
773
+			EE_Error::add_attention(
774
+				sprintf(
775
+					esc_html__(
776
+						'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',
777
+						'event_espresso'
778
+					),
779
+					'<br>',
780
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
781
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
782
+					. '</select>',
783
+					'<button class="button button-secondary timezone-submit">',
784
+					'</button><span class="spinner"></span>'
785
+				),
786
+				__FILE__,
787
+				__FUNCTION__,
788
+				__LINE__
789
+			);
790
+		}
791
+		parent::_create_new_cpt_item();
792
+	}
793
+
794
+
795
+	/**
796
+	 * Sets the _views property for the default route in this admin page group.
797
+	 */
798
+	protected function _set_list_table_views_default()
799
+	{
800
+		$this->_views = [
801
+			'all'   => [
802
+				'slug'        => 'all',
803
+				'label'       => esc_html__('View All Events', 'event_espresso'),
804
+				'count'       => 0,
805
+				'bulk_action' => [
806
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
807
+				],
808
+			],
809
+			'draft' => [
810
+				'slug'        => 'draft',
811
+				'label'       => esc_html__('Draft', 'event_espresso'),
812
+				'count'       => 0,
813
+				'bulk_action' => [
814
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
815
+				],
816
+			],
817
+		];
818
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
819
+			$this->_views['trash'] = [
820
+				'slug'        => 'trash',
821
+				'label'       => esc_html__('Trash', 'event_espresso'),
822
+				'count'       => 0,
823
+				'bulk_action' => [
824
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
825
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
826
+				],
827
+			];
828
+		}
829
+	}
830
+
831
+
832
+	/**
833
+	 * Provides the legend item array for the default list table view.
834
+	 *
835
+	 * @return array
836
+	 * @throws EE_Error
837
+	 * @throws EE_Error
838
+	 */
839
+	protected function _event_legend_items()
840
+	{
841
+		$items    = [
842
+			'view_details'   => [
843
+				'class' => 'dashicons dashicons-search',
844
+				'desc'  => esc_html__('View Event', 'event_espresso'),
845
+			],
846
+			'edit_event'     => [
847
+				'class' => 'ee-icon ee-icon-calendar-edit',
848
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
849
+			],
850
+			'view_attendees' => [
851
+				'class' => 'dashicons dashicons-groups',
852
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
853
+			],
854
+		];
855
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
856
+		$statuses = [
857
+			'sold_out_status'  => [
858
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
859
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
860
+			],
861
+			'active_status'    => [
862
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
863
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
864
+			],
865
+			'upcoming_status'  => [
866
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
867
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
868
+			],
869
+			'postponed_status' => [
870
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
871
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
872
+			],
873
+			'cancelled_status' => [
874
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
875
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
876
+			],
877
+			'expired_status'   => [
878
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
879
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
880
+			],
881
+			'inactive_status'  => [
882
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
883
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
884
+			],
885
+		];
886
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
887
+		return array_merge($items, $statuses);
888
+	}
889
+
890
+
891
+	/**
892
+	 * @return EEM_Event
893
+	 * @throws EE_Error
894
+	 * @throws ReflectionException
895
+	 */
896
+	private function _event_model()
897
+	{
898
+		if (! $this->_event_model instanceof EEM_Event) {
899
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
900
+		}
901
+		return $this->_event_model;
902
+	}
903
+
904
+
905
+	/**
906
+	 * Adds extra buttons to the WP CPT permalink field row.
907
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
908
+	 *
909
+	 * @param string $return    the current html
910
+	 * @param int    $id        the post id for the page
911
+	 * @param string $new_title What the title is
912
+	 * @param string $new_slug  what the slug is
913
+	 * @return string            The new html string for the permalink area
914
+	 */
915
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
916
+	{
917
+		// make sure this is only when editing
918
+		if (! empty($id)) {
919
+			$post   = get_post($id);
920
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
921
+					   . esc_html__('Shortcode', 'event_espresso')
922
+					   . '</a> ';
923
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
924
+					   . $post->ID
925
+					   . ']">';
926
+		}
927
+		return $return;
928
+	}
929
+
930
+
931
+	/**
932
+	 * _events_overview_list_table
933
+	 * This contains the logic for showing the events_overview list
934
+	 *
935
+	 * @access protected
936
+	 * @return void
937
+	 * @throws EE_Error
938
+	 */
939
+	protected function _events_overview_list_table()
940
+	{
941
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
942
+		$this->_template_args['after_list_table']                           =
943
+			! empty($this->_template_args['after_list_table'])
944
+				? (array) $this->_template_args['after_list_table']
945
+				: [];
946
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
947
+			. EEH_Template::get_button_or_link(
948
+				get_post_type_archive_link('espresso_events'),
949
+				esc_html__("View Event Archive Page", "event_espresso"),
950
+				'button'
951
+			);
952
+		$this->_template_args['after_list_table']['legend']                 = $this->_display_legend(
953
+			$this->_event_legend_items()
954
+		);
955
+		$this->_admin_page_title                                            .= ' ' . $this->get_action_link_or_button(
956
+			'create_new',
957
+			'add',
958
+			[],
959
+			'add-new-h2'
960
+		);
961
+		$this->display_admin_list_table_page_with_no_sidebar();
962
+	}
963
+
964
+
965
+	/**
966
+	 * this allows for extra misc actions in the default WP publish box
967
+	 *
968
+	 * @return void
969
+	 * @throws EE_Error
970
+	 * @throws ReflectionException
971
+	 */
972
+	public function extra_misc_actions_publish_box()
973
+	{
974
+		$this->_generate_publish_box_extra_content();
975
+	}
976
+
977
+
978
+	/**
979
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
980
+	 * saved.
981
+	 * Typically you would use this to save any additional data.
982
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
983
+	 * ALSO very important.  When a post transitions from scheduled to published,
984
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
985
+	 * other meta saves. So MAKE sure that you handle this accordingly.
986
+	 *
987
+	 * @access protected
988
+	 * @abstract
989
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
990
+	 * @param WP_Post $post    The post object of the cpt that was saved.
991
+	 * @return void
992
+	 * @throws EE_Error
993
+	 * @throws ReflectionException
994
+	 */
995
+	protected function _insert_update_cpt_item($post_id, $post)
996
+	{
997
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
998
+			// get out we're not processing an event save.
999
+			return;
1000
+		}
1001
+
1002
+		$event_values = [
1003
+			'EVT_display_desc'                => $this->request->getRequestParam('display_desc', false, 'bool'),
1004
+			'EVT_display_ticket_selector'     => $this->request->getRequestParam(
1005
+				'display_ticket_selector',
1006
+				false,
1007
+				'bool'
1008
+			),
1009
+			'EVT_additional_limit'            => min(
1010
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1011
+				$this->request->getRequestParam('additional_limit', null, 'int')
1012
+			),
1013
+			'EVT_default_registration_status' => $this->request->getRequestParam(
1014
+				'EVT_default_registration_status',
1015
+				EE_Registry::instance()->CFG->registration->default_STS_ID
1016
+			),
1017
+
1018
+			'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1019
+			'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1020
+			'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1021
+			'EVT_external_URL'    => $this->request->getRequestParam('externalURL'),
1022
+			'EVT_phone'           => $this->request->getRequestParam('event_phone'),
1023
+		];
1024
+		// update event
1025
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1026
+		// get event_object for other metaboxes...
1027
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1028
+		// i have to setup where conditions to override the filters in the model
1029
+		// that filter out autodraft and inherit statuses so we GET the inherit id!
1030
+		$event = $this->_event_model()->get_one(
1031
+			[
1032
+				[
1033
+					$this->_event_model()->primary_key_name() => $post_id,
1034
+					'OR'                                      => [
1035
+						'status'   => $post->post_status,
1036
+						// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1037
+						// but the returned object here has a status of "publish", so use the original post status as well
1038
+						'status*1' => $this->request->getRequestParam('original_post_status'),
1039
+					],
1040
+				],
1041
+			]
1042
+		);
1043
+		// the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1044
+		$event_update_callbacks = apply_filters(
1045
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1046
+			[
1047
+				[$this, '_default_venue_update'],
1048
+				[$this, '_default_tickets_update'],
1049
+			]
1050
+		);
1051
+		$att_success            = true;
1052
+		foreach ($event_update_callbacks as $e_callback) {
1053
+			$_success = is_callable($e_callback)
1054
+				? call_user_func($e_callback, $event, $this->request->requestParams())
1055
+				: false;
1056
+			// if ANY of these updates fail then we want the appropriate global error message
1057
+			$att_success = ! $att_success ? $att_success : $_success;
1058
+		}
1059
+		// any errors?
1060
+		if ($success && false === $att_success) {
1061
+			EE_Error::add_error(
1062
+				esc_html__(
1063
+					'Event Details saved successfully but something went wrong with saving attachments.',
1064
+					'event_espresso'
1065
+				),
1066
+				__FILE__,
1067
+				__FUNCTION__,
1068
+				__LINE__
1069
+			);
1070
+		} elseif ($success === false) {
1071
+			EE_Error::add_error(
1072
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1073
+				__FILE__,
1074
+				__FUNCTION__,
1075
+				__LINE__
1076
+			);
1077
+		}
1078
+	}
1079
+
1080
+
1081
+	/**
1082
+	 * @param int $post_id
1083
+	 * @param int $revision_id
1084
+	 * @throws EE_Error
1085
+	 * @throws EE_Error
1086
+	 * @throws ReflectionException
1087
+	 * @see parent::restore_item()
1088
+	 */
1089
+	protected function _restore_cpt_item($post_id, $revision_id)
1090
+	{
1091
+		// copy existing event meta to new post
1092
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1093
+		if ($post_evt instanceof EE_Event) {
1094
+			// meta revision restore
1095
+			$post_evt->restore_revision($revision_id);
1096
+			// related objs restore
1097
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1098
+		}
1099
+	}
1100
+
1101
+
1102
+	/**
1103
+	 * Attach the venue to the Event
1104
+	 *
1105
+	 * @param EE_Event $event Event Object to add the venue to
1106
+	 * @param array    $data  The request data from the form
1107
+	 * @return bool           Success or fail.
1108
+	 * @throws EE_Error
1109
+	 * @throws ReflectionException
1110
+	 */
1111
+	protected function _default_venue_update(EE_Event $event, $data)
1112
+	{
1113
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1114
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1115
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1116
+		// very important.  If we don't have a venue name...
1117
+		// then we'll get out because not necessary to create empty venue
1118
+		if (empty($data['venue_title'])) {
1119
+			return false;
1120
+		}
1121
+		$venue_array = [
1122
+			'VNU_wp_user'         => $event->get('EVT_wp_user'),
1123
+			'VNU_name'            => $data['venue_title'],
1124
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1125
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1126
+			'VNU_short_desc'      => ! empty($data['venue_short_description'])
1127
+				? $data['venue_short_description']
1128
+				: null,
1129
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1130
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1131
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1132
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1133
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1134
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1135
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1136
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1137
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1138
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1139
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1140
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1141
+			'status'              => 'publish',
1142
+		];
1143
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1144
+		if (! empty($venue_id)) {
1145
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1146
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1147
+			// we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1148
+			$event->_add_relation_to($venue_id, 'Venue');
1149
+			return $rows_affected > 0;
1150
+		}
1151
+		// we insert the venue
1152
+		$venue_id = $venue_model->insert($venue_array);
1153
+		$event->_add_relation_to($venue_id, 'Venue');
1154
+		return ! empty($venue_id);
1155
+		// when we have the ancestor come in it's already been handled by the revision save.
1156
+	}
1157
+
1158
+
1159
+	/**
1160
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1161
+	 *
1162
+	 * @param EE_Event $event The Event object we're attaching data to
1163
+	 * @param array    $data  The request data from the form
1164
+	 * @return array
1165
+	 * @throws EE_Error
1166
+	 * @throws ReflectionException
1167
+	 * @throws Exception
1168
+	 */
1169
+	protected function _default_tickets_update(EE_Event $event, $data)
1170
+	{
1171
+		$datetime       = null;
1172
+		$saved_tickets  = [];
1173
+		$event_timezone = $event->get_timezone();
1174
+		$date_formats   = ['Y-m-d', 'h:i a'];
1175
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1176
+			// trim all values to ensure any excess whitespace is removed.
1177
+			$datetime_data                = array_map('trim', $datetime_data);
1178
+			$datetime_data['DTT_EVT_end'] =
1179
+				isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1180
+					? $datetime_data['DTT_EVT_end']
1181
+					: $datetime_data['DTT_EVT_start'];
1182
+			$datetime_values              = [
1183
+				'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1184
+				'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1185
+				'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1186
+				'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1187
+				'DTT_order'     => $row,
1188
+			];
1189
+			// if we have an id then let's get existing object first and then set the new values.
1190
+			//  Otherwise we instantiate a new object for save.
1191
+			if (! empty($datetime_data['DTT_ID'])) {
1192
+				$datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1193
+				if (! $datetime instanceof EE_Datetime) {
1194
+					throw new RuntimeException(
1195
+						sprintf(
1196
+							esc_html__(
1197
+								'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1198
+								'event_espresso'
1199
+							),
1200
+							$datetime_data['DTT_ID']
1201
+						)
1202
+					);
1203
+				}
1204
+				$datetime->set_date_format($date_formats[0]);
1205
+				$datetime->set_time_format($date_formats[1]);
1206
+				foreach ($datetime_values as $field => $value) {
1207
+					$datetime->set($field, $value);
1208
+				}
1209
+			} else {
1210
+				$datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1211
+			}
1212
+			if (! $datetime instanceof EE_Datetime) {
1213
+				throw new RuntimeException(
1214
+					sprintf(
1215
+						esc_html__(
1216
+							'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1217
+							'event_espresso'
1218
+						),
1219
+						print_r($datetime_values, true)
1220
+					)
1221
+				);
1222
+			}
1223
+			// before going any further make sure our dates are setup correctly
1224
+			// so that the end date is always equal or greater than the start date.
1225
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1226
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1227
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1228
+			}
1229
+			$datetime->save();
1230
+			$event->_add_relation_to($datetime, 'Datetime');
1231
+		}
1232
+		// no datetimes get deleted so we don't do any of that logic here.
1233
+		// update tickets next
1234
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1235
+
1236
+		// set up some default start and end dates in case those are not present in the incoming data
1237
+		$default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1238
+		$default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1239
+		// use the start date of the first datetime for the end date
1240
+		$first_datetime   = $event->first_datetime();
1241
+		$default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1242
+
1243
+		// now process the incoming data
1244
+		foreach ($data['edit_tickets'] as $row => $ticket_data) {
1245
+			$update_prices = false;
1246
+			$ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1247
+				? $data['edit_prices'][ $row ][1]['PRC_amount']
1248
+				: 0;
1249
+			// trim inputs to ensure any excess whitespace is removed.
1250
+			$ticket_data   = array_map('trim', $ticket_data);
1251
+			$ticket_values = [
1252
+				'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1253
+				'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1254
+				'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1255
+				'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1256
+				'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1257
+					? $ticket_data['TKT_start_date']
1258
+					: $default_start_date,
1259
+				'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1260
+					? $ticket_data['TKT_end_date']
1261
+					: $default_end_date,
1262
+				'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1263
+									 || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1264
+					? $ticket_data['TKT_qty']
1265
+					: EE_INF,
1266
+				'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1267
+									 || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1268
+					? $ticket_data['TKT_uses']
1269
+					: EE_INF,
1270
+				'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1271
+				'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1272
+				'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1273
+				'TKT_price'       => $ticket_price,
1274
+				'TKT_row'         => $row,
1275
+			];
1276
+			// if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1277
+			// which means in turn that the prices will become new prices as well.
1278
+			if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1279
+				$ticket_values['TKT_ID']         = 0;
1280
+				$ticket_values['TKT_is_default'] = 0;
1281
+				$update_prices                   = true;
1282
+			}
1283
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1284
+			// we actually do our saves ahead of adding any relations because its entirely possible that this
1285
+			// ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1286
+			// keep in mind that if the ticket has been sold (and we have changed pricing information),
1287
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1288
+			if (! empty($ticket_data['TKT_ID'])) {
1289
+				$existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1290
+				if (! $existing_ticket instanceof EE_Ticket) {
1291
+					throw new RuntimeException(
1292
+						sprintf(
1293
+							esc_html__(
1294
+								'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1295
+								'event_espresso'
1296
+							),
1297
+							$ticket_data['TKT_ID']
1298
+						)
1299
+					);
1300
+				}
1301
+				$ticket_sold = $existing_ticket->count_related(
1302
+					'Registration',
1303
+					[
1304
+						[
1305
+							'STS_ID' => [
1306
+								'NOT IN',
1307
+								[EEM_Registration::status_id_incomplete],
1308
+							],
1309
+						],
1310
+					]
1311
+				) > 0;
1312
+				// let's just check the total price for the existing ticket and determine if it matches the new total price.
1313
+				// if they are different then we create a new ticket (if $ticket_sold)
1314
+				// if they aren't different then we go ahead and modify existing ticket.
1315
+				$create_new_ticket = $ticket_sold
1316
+									 && $ticket_price !== $existing_ticket->price()
1317
+									 && ! $existing_ticket->deleted();
1318
+				$existing_ticket->set_date_format($date_formats[0]);
1319
+				$existing_ticket->set_time_format($date_formats[1]);
1320
+				// set new values
1321
+				foreach ($ticket_values as $field => $value) {
1322
+					if ($field == 'TKT_qty') {
1323
+						$existing_ticket->set_qty($value);
1324
+					} elseif ($field == 'TKT_price') {
1325
+						$existing_ticket->set('TKT_price', $ticket_price);
1326
+					} else {
1327
+						$existing_ticket->set($field, $value);
1328
+					}
1329
+				}
1330
+				$ticket = $existing_ticket;
1331
+				// if $create_new_ticket is false then we can safely update the existing ticket.
1332
+				//  Otherwise we have to create a new ticket.
1333
+				if ($create_new_ticket) {
1334
+					// archive the old ticket first
1335
+					$existing_ticket->set('TKT_deleted', 1);
1336
+					$existing_ticket->save();
1337
+					// make sure this ticket is still recorded in our $saved_tickets
1338
+					// so we don't run it through the regular trash routine.
1339
+					$saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1340
+					// create new ticket that's a copy of the existing except,
1341
+					// (a new id of course and not archived) AND has the new TKT_price associated with it.
1342
+					$new_ticket = clone $existing_ticket;
1343
+					$new_ticket->set('TKT_ID', 0);
1344
+					$new_ticket->set('TKT_deleted', 0);
1345
+					$new_ticket->set('TKT_sold', 0);
1346
+					// now we need to make sure that $new prices are created as well and attached to new ticket.
1347
+					$update_prices = true;
1348
+					$ticket        = $new_ticket;
1349
+				}
1350
+			} else {
1351
+				// no TKT_id so a new ticket
1352
+				$ticket_values['TKT_price'] = $ticket_price;
1353
+				$ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1354
+				$update_prices              = true;
1355
+			}
1356
+			if (! $ticket instanceof EE_Ticket) {
1357
+				throw new RuntimeException(
1358
+					sprintf(
1359
+						esc_html__(
1360
+							'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1361
+							'event_espresso'
1362
+						),
1363
+						print_r($ticket_values, true)
1364
+					)
1365
+				);
1366
+			}
1367
+			// cap ticket qty by datetime reg limits
1368
+			$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1369
+			// update ticket.
1370
+			$ticket->save();
1371
+			// before going any further make sure our dates are setup correctly
1372
+			// so that the end date is always equal or greater than the start date.
1373
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1374
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1375
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1376
+				$ticket->save();
1377
+			}
1378
+			// initially let's add the ticket to the datetime
1379
+			$datetime->_add_relation_to($ticket, 'Ticket');
1380
+			$saved_tickets[ $ticket->ID() ] = $ticket;
1381
+			// add prices to ticket
1382
+			$prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1383
+				? $data['edit_prices'][ $row ]
1384
+				: [];
1385
+			$this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1386
+		}
1387
+		// however now we need to handle permanently deleting tickets via the ui.
1388
+		// Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1389
+		// However, it does allow for deleting tickets that have no tickets sold,
1390
+		// in which case we want to get rid of permanently because there is no need to save in db.
1391
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? [] : $old_tickets;
1392
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1393
+		foreach ($tickets_removed as $id) {
1394
+			$id = absint($id);
1395
+			// get the ticket for this id
1396
+			$ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1397
+			if (! $ticket_to_remove instanceof EE_Ticket) {
1398
+				continue;
1399
+			}
1400
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1401
+			// (remember this process can ONLY kick off if there are NO tickets sold)
1402
+			$related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1403
+			foreach ($related_datetimes as $related_datetime) {
1404
+				$ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1405
+			}
1406
+			// need to do the same for prices (except these prices can also be deleted because again,
1407
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1408
+			$ticket_to_remove->delete_related_permanently('Price');
1409
+			// finally let's delete this ticket
1410
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1411
+			$ticket_to_remove->delete_permanently();
1412
+		}
1413
+		return [$datetime, $saved_tickets];
1414
+	}
1415
+
1416
+
1417
+	/**
1418
+	 * This attaches a list of given prices to a ticket.
1419
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1420
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1421
+	 * price info and prices are automatically "archived" via the ticket.
1422
+	 *
1423
+	 * @access  private
1424
+	 * @param array     $prices_data Array of prices from the form.
1425
+	 * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1426
+	 * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1427
+	 * @return  void
1428
+	 * @throws EE_Error
1429
+	 * @throws ReflectionException
1430
+	 */
1431
+	private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1432
+	{
1433
+		$timezone = $ticket->get_timezone();
1434
+		foreach ($prices_data as $row => $price_data) {
1435
+			$price_values = [
1436
+				'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1437
+				'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1438
+				'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1439
+				'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1440
+				'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1441
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1442
+				'PRC_order'      => $row,
1443
+			];
1444
+			if ($new_prices || empty($price_values['PRC_ID'])) {
1445
+				$price_values['PRC_ID'] = 0;
1446
+				$price                  = EE_Price::new_instance($price_values, $timezone);
1447
+			} else {
1448
+				$price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1449
+				// update this price with new values
1450
+				foreach ($price_values as $field => $new_price) {
1451
+					$price->set($field, $new_price);
1452
+				}
1453
+			}
1454
+			if (! $price instanceof EE_Price) {
1455
+				throw new RuntimeException(
1456
+					sprintf(
1457
+						esc_html__(
1458
+							'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1459
+							'event_espresso'
1460
+						),
1461
+						print_r($price_values, true)
1462
+					)
1463
+				);
1464
+			}
1465
+			$price->save();
1466
+			$ticket->_add_relation_to($price, 'Price');
1467
+		}
1468
+	}
1469
+
1470
+
1471
+	/**
1472
+	 * Add in our autosave ajax handlers
1473
+	 *
1474
+	 */
1475
+	protected function _ee_autosave_create_new()
1476
+	{
1477
+	}
1478
+
1479
+
1480
+	/**
1481
+	 * More autosave handlers.
1482
+	 */
1483
+	protected function _ee_autosave_edit()
1484
+	{
1485
+		// TEMPORARILY EXITING CAUSE THIS IS A TODO
1486
+	}
1487
+
1488
+
1489
+	/**
1490
+	 * @throws EE_Error
1491
+	 * @throws ReflectionException
1492
+	 */
1493
+	private function _generate_publish_box_extra_content()
1494
+	{
1495
+		// load formatter helper
1496
+		// args for getting related registrations
1497
+		$approved_query_args        = [
1498
+			[
1499
+				'REG_deleted' => 0,
1500
+				'STS_ID'      => EEM_Registration::status_id_approved,
1501
+			],
1502
+		];
1503
+		$not_approved_query_args    = [
1504
+			[
1505
+				'REG_deleted' => 0,
1506
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1507
+			],
1508
+		];
1509
+		$pending_payment_query_args = [
1510
+			[
1511
+				'REG_deleted' => 0,
1512
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1513
+			],
1514
+		];
1515
+		// publish box
1516
+		$publish_box_extra_args = [
1517
+			'view_approved_reg_url'        => add_query_arg(
1518
+				[
1519
+					'action'      => 'default',
1520
+					'event_id'    => $this->_cpt_model_obj->ID(),
1521
+					'_reg_status' => EEM_Registration::status_id_approved,
1522
+					'use_filters' => true,
1523
+				],
1524
+				REG_ADMIN_URL
1525
+			),
1526
+			'view_not_approved_reg_url'    => add_query_arg(
1527
+				[
1528
+					'action'      => 'default',
1529
+					'event_id'    => $this->_cpt_model_obj->ID(),
1530
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1531
+					'use_filters' => true,
1532
+				],
1533
+				REG_ADMIN_URL
1534
+			),
1535
+			'view_pending_payment_reg_url' => add_query_arg(
1536
+				[
1537
+					'action'      => 'default',
1538
+					'event_id'    => $this->_cpt_model_obj->ID(),
1539
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1540
+					'use_filters' => true,
1541
+				],
1542
+				REG_ADMIN_URL
1543
+			),
1544
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1545
+				'Registration',
1546
+				$approved_query_args
1547
+			),
1548
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1549
+				'Registration',
1550
+				$not_approved_query_args
1551
+			),
1552
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1553
+				'Registration',
1554
+				$pending_payment_query_args
1555
+			),
1556
+			'misc_pub_section_class'       => apply_filters(
1557
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1558
+				'misc-pub-section'
1559
+			),
1560
+		];
1561
+		ob_start();
1562
+		do_action(
1563
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1564
+			$this->_cpt_model_obj
1565
+		);
1566
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1567
+		// load template
1568
+		EEH_Template::display_template(
1569
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1570
+			$publish_box_extra_args
1571
+		);
1572
+	}
1573
+
1574
+
1575
+	/**
1576
+	 * @return EE_Event
1577
+	 */
1578
+	public function get_event_object()
1579
+	{
1580
+		return $this->_cpt_model_obj;
1581
+	}
1582
+
1583
+
1584
+
1585
+
1586
+	/** METABOXES * */
1587
+	/**
1588
+	 * _register_event_editor_meta_boxes
1589
+	 * add all metaboxes related to the event_editor
1590
+	 *
1591
+	 * @return void
1592
+	 * @throws EE_Error
1593
+	 * @throws ReflectionException
1594
+	 */
1595
+	protected function _register_event_editor_meta_boxes()
1596
+	{
1597
+		$this->verify_cpt_object();
1598
+		add_meta_box(
1599
+			'espresso_event_editor_tickets',
1600
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1601
+			[$this, 'ticket_metabox'],
1602
+			$this->page_slug,
1603
+			'normal',
1604
+			'high'
1605
+		);
1606
+		add_meta_box(
1607
+			'espresso_event_editor_event_options',
1608
+			esc_html__('Event Registration Options', 'event_espresso'),
1609
+			[$this, 'registration_options_meta_box'],
1610
+			$this->page_slug,
1611
+			'side'
1612
+		);
1613
+		// NOTE: if you're looking for other metaboxes in here,
1614
+		// where a metabox has a related management page in the admin
1615
+		// you will find it setup in the related management page's "_Hooks" file.
1616
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1617
+	}
1618
+
1619
+
1620
+	/**
1621
+	 * @throws DomainException
1622
+	 * @throws EE_Error
1623
+	 * @throws ReflectionException
1624
+	 */
1625
+	public function ticket_metabox()
1626
+	{
1627
+		$existing_datetime_ids = $existing_ticket_ids = [];
1628
+		// defaults for template args
1629
+		$template_args = [
1630
+			'existing_datetime_ids'    => '',
1631
+			'event_datetime_help_link' => '',
1632
+			'ticket_options_help_link' => '',
1633
+			'time'                     => null,
1634
+			'ticket_rows'              => '',
1635
+			'existing_ticket_ids'      => '',
1636
+			'total_ticket_rows'        => 1,
1637
+			'ticket_js_structure'      => '',
1638
+			'trash_icon'               => 'ee-lock-icon',
1639
+			'disabled'                 => '',
1640
+		];
1641
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1642
+		/**
1643
+		 * 1. Start with retrieving Datetimes
1644
+		 * 2. Fore each datetime get related tickets
1645
+		 * 3. For each ticket get related prices
1646
+		 */
1647
+		$times          = EEM_Datetime::instance()->get_all_event_dates($event_id);
1648
+		$first_datetime = reset($times);
1649
+		// do we get related tickets?
1650
+		if (
1651
+			$first_datetime instanceof EE_Datetime
1652
+			&& $first_datetime->ID() !== 0
1653
+		) {
1654
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1655
+			$template_args['time']   = $first_datetime;
1656
+			$related_tickets         = $first_datetime->tickets(
1657
+				[
1658
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1659
+					'default_where_conditions' => 'none',
1660
+				]
1661
+			);
1662
+			if (! empty($related_tickets)) {
1663
+				$template_args['total_ticket_rows'] = count($related_tickets);
1664
+				$row                                = 0;
1665
+				foreach ($related_tickets as $ticket) {
1666
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1667
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1668
+					$row++;
1669
+				}
1670
+			} else {
1671
+				$template_args['total_ticket_rows'] = 1;
1672
+				/** @type EE_Ticket $ticket */
1673
+				$ticket                       = EEM_Ticket::instance()->create_default_object();
1674
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1675
+			}
1676
+		} else {
1677
+			$template_args['time']        = $times[0];
1678
+			$tickets                      = EEM_Ticket::instance()->get_all_default_tickets();
1679
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1680
+			// NOTE: we're just sending the first default row
1681
+			// (decaf can't manage default tickets so this should be sufficient);
1682
+		}
1683
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1684
+			'event_editor_event_datetimes_help_tab'
1685
+		);
1686
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1687
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1688
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1689
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1690
+			EEM_Ticket::instance()->create_default_object(),
1691
+			true
1692
+		);
1693
+		$template                                  = apply_filters(
1694
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1695
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1696
+		);
1697
+		EEH_Template::display_template($template, $template_args);
1698
+	}
1699
+
1700
+
1701
+	/**
1702
+	 * Setup an individual ticket form for the decaf event editor page
1703
+	 *
1704
+	 * @access private
1705
+	 * @param EE_Ticket $ticket   the ticket object
1706
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1707
+	 * @param int       $row
1708
+	 * @return string generated html for the ticket row.
1709
+	 * @throws EE_Error
1710
+	 * @throws ReflectionException
1711
+	 */
1712
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1713
+	{
1714
+		$template_args = [
1715
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1716
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1717
+				: '',
1718
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1719
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1720
+			'TKT_name'            => $ticket->get('TKT_name'),
1721
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1722
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1723
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1724
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1725
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1726
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1727
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1728
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1729
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1730
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1731
+				: ' disabled=disabled',
1732
+		];
1733
+		$price         = $ticket->ID() !== 0
1734
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1735
+			: null;
1736
+		$price         = $price instanceof EE_Price
1737
+			? $price
1738
+			: EEM_Price::instance()->create_default_object();
1739
+		$price_args    = [
1740
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1741
+			'PRC_amount'            => $price->get('PRC_amount'),
1742
+			'PRT_ID'                => $price->get('PRT_ID'),
1743
+			'PRC_ID'                => $price->get('PRC_ID'),
1744
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1745
+		];
1746
+		// make sure we have default start and end dates if skeleton
1747
+		// handle rows that should NOT be empty
1748
+		if (empty($template_args['TKT_start_date'])) {
1749
+			// if empty then the start date will be now.
1750
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1751
+		}
1752
+		if (empty($template_args['TKT_end_date'])) {
1753
+			// get the earliest datetime (if present);
1754
+			$earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1755
+				? $this->_cpt_model_obj->get_first_related(
1756
+					'Datetime',
1757
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1758
+				)
1759
+				: null;
1760
+			$template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1761
+				? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1762
+				: date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1763
+		}
1764
+		$template_args = array_merge($template_args, $price_args);
1765
+		$template      = apply_filters(
1766
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1767
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1768
+			$ticket
1769
+		);
1770
+		return EEH_Template::display_template($template, $template_args, true);
1771
+	}
1772
+
1773
+
1774
+	/**
1775
+	 * @throws EE_Error
1776
+	 * @throws ReflectionException
1777
+	 */
1778
+	public function registration_options_meta_box()
1779
+	{
1780
+		$yes_no_values             = [
1781
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1782
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1783
+		];
1784
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1785
+			[
1786
+				EEM_Registration::status_id_cancelled,
1787
+				EEM_Registration::status_id_declined,
1788
+				EEM_Registration::status_id_incomplete,
1789
+			],
1790
+			true
1791
+		);
1792
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1793
+		$template_args['_event']                          = $this->_cpt_model_obj;
1794
+		$template_args['event']                           = $this->_cpt_model_obj;
1795
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1796
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1797
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1798
+			'default_reg_status',
1799
+			$default_reg_status_values,
1800
+			$this->_cpt_model_obj->default_registration_status()
1801
+		);
1802
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1803
+			'display_desc',
1804
+			$yes_no_values,
1805
+			$this->_cpt_model_obj->display_description()
1806
+		);
1807
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1808
+			'display_ticket_selector',
1809
+			$yes_no_values,
1810
+			$this->_cpt_model_obj->display_ticket_selector(),
1811
+			'',
1812
+			'',
1813
+			false
1814
+		);
1815
+		$template_args['additional_registration_options'] = apply_filters(
1816
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1817
+			'',
1818
+			$template_args,
1819
+			$yes_no_values,
1820
+			$default_reg_status_values
1821
+		);
1822
+		EEH_Template::display_template(
1823
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1824
+			$template_args
1825
+		);
1826
+	}
1827
+
1828
+
1829
+	/**
1830
+	 * _get_events()
1831
+	 * This method simply returns all the events (for the given _view and paging)
1832
+	 *
1833
+	 * @access public
1834
+	 * @param int  $per_page     count of items per page (20 default);
1835
+	 * @param int  $current_page what is the current page being viewed.
1836
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1837
+	 *                           If FALSE then we return an array of event objects
1838
+	 *                           that match the given _view and paging parameters.
1839
+	 * @return array|int         an array of event objects or a count of them.
1840
+	 * @throws Exception
1841
+	 */
1842
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1843
+	{
1844
+		$EEM_Event   = $this->_event_model();
1845
+		$offset      = ($current_page - 1) * $per_page;
1846
+		$limit       = $count ? null : $offset . ',' . $per_page;
1847
+		$orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1848
+		$order       = $this->request->getRequestParam('order', 'DESC');
1849
+		$month_range = $this->request->getRequestParam('month_range');
1850
+		if ($month_range) {
1851
+			$pieces = explode(' ', $month_range, 3);
1852
+			// simulate the FIRST day of the month, that fixes issues for months like February
1853
+			// where PHP doesn't know what to assume for date.
1854
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1855
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1856
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1857
+		}
1858
+		$where  = [];
1859
+		$status = $this->request->getRequestParam('status');
1860
+		// determine what post_status our condition will have for the query.
1861
+		switch ($status) {
1862
+			case 'month':
1863
+			case 'today':
1864
+			case null:
1865
+			case 'all':
1866
+				break;
1867
+			case 'draft':
1868
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1869
+				break;
1870
+			default:
1871
+				$where['status'] = $status;
1872
+		}
1873
+		// categories? The default for all categories is -1
1874
+		$category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1875
+		if ($category !== -1) {
1876
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1877
+			$where['Term_Taxonomy.term_id']  = $category;
1878
+		}
1879
+		// date where conditions
1880
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1881
+		if ($month_range) {
1882
+			$DateTime = new DateTime(
1883
+				$year_r . '-' . $month_r . '-01 00:00:00',
1884
+				new DateTimeZone('UTC')
1885
+			);
1886
+			$start    = $DateTime->getTimestamp();
1887
+			// set the datetime to be the end of the month
1888
+			$DateTime->setDate(
1889
+				$year_r,
1890
+				$month_r,
1891
+				$DateTime->format('t')
1892
+			)->setTime(23, 59, 59);
1893
+			$end                             = $DateTime->getTimestamp();
1894
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1895
+		} elseif ($status === 'today') {
1896
+			$DateTime                        =
1897
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1898
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1899
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1900
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1901
+		} elseif ($status === 'month') {
1902
+			$now                             = date('Y-m-01');
1903
+			$DateTime                        =
1904
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1905
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1906
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1907
+														->setTime(23, 59, 59)
1908
+														->format(implode(' ', $start_formats));
1909
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1910
+		}
1911
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1912
+			$where['EVT_wp_user'] = get_current_user_id();
1913
+		} else {
1914
+			if (! isset($where['status'])) {
1915
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1916
+					$where['OR'] = [
1917
+						'status*restrict_private' => ['!=', 'private'],
1918
+						'AND'                     => [
1919
+							'status*inclusive' => ['=', 'private'],
1920
+							'EVT_wp_user'      => get_current_user_id(),
1921
+						],
1922
+					];
1923
+				}
1924
+			}
1925
+		}
1926
+		$wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1927
+		if (
1928
+			$wp_user
1929
+			&& $wp_user !== get_current_user_id()
1930
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1931
+		) {
1932
+			$where['EVT_wp_user'] = $wp_user;
1933
+		}
1934
+		// search query handling
1935
+		$search_term = $this->request->getRequestParam('s');
1936
+		if ($search_term) {
1937
+			$search_term = '%' . $search_term . '%';
1938
+			$where['OR'] = [
1939
+				'EVT_name'       => ['LIKE', $search_term],
1940
+				'EVT_desc'       => ['LIKE', $search_term],
1941
+				'EVT_short_desc' => ['LIKE', $search_term],
1942
+			];
1943
+		}
1944
+		// filter events by venue.
1945
+		$venue = $this->request->getRequestParam('venue', 0, 'int');
1946
+		if ($venue) {
1947
+			$where['Venue.VNU_ID'] = $venue;
1948
+		}
1949
+		$request_params = $this->request->requestParams();
1950
+		$where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
1951
+		$query_params   = apply_filters(
1952
+			'FHEE__Events_Admin_Page__get_events__query_params',
1953
+			[
1954
+				$where,
1955
+				'limit'    => $limit,
1956
+				'order_by' => $orderby,
1957
+				'order'    => $order,
1958
+				'group_by' => 'EVT_ID',
1959
+			],
1960
+			$request_params
1961
+		);
1962
+
1963
+		// let's first check if we have special requests coming in.
1964
+		$active_status = $this->request->getRequestParam('active_status');
1965
+		if ($active_status) {
1966
+			switch ($active_status) {
1967
+				case 'upcoming':
1968
+					return $EEM_Event->get_upcoming_events($query_params, $count);
1969
+				case 'expired':
1970
+					return $EEM_Event->get_expired_events($query_params, $count);
1971
+				case 'active':
1972
+					return $EEM_Event->get_active_events($query_params, $count);
1973
+				case 'inactive':
1974
+					return $EEM_Event->get_inactive_events($query_params, $count);
1975
+			}
1976
+		}
1977
+
1978
+		return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
1979
+	}
1980
+
1981
+
1982
+	/**
1983
+	 * handling for WordPress CPT actions (trash, restore, delete)
1984
+	 *
1985
+	 * @param string $post_id
1986
+	 * @throws EE_Error
1987
+	 * @throws ReflectionException
1988
+	 */
1989
+	public function trash_cpt_item($post_id)
1990
+	{
1991
+		$this->request->setRequestParam('EVT_ID', $post_id);
1992
+		$this->_trash_or_restore_event('trash', false);
1993
+	}
1994
+
1995
+
1996
+	/**
1997
+	 * @param string $post_id
1998
+	 * @throws EE_Error
1999
+	 * @throws ReflectionException
2000
+	 */
2001
+	public function restore_cpt_item($post_id)
2002
+	{
2003
+		$this->request->setRequestParam('EVT_ID', $post_id);
2004
+		$this->_trash_or_restore_event('draft', false);
2005
+	}
2006
+
2007
+
2008
+	/**
2009
+	 * @param string $post_id
2010
+	 * @throws EE_Error
2011
+	 * @throws EE_Error
2012
+	 */
2013
+	public function delete_cpt_item($post_id)
2014
+	{
2015
+		throw new EE_Error(
2016
+			esc_html__(
2017
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2018
+				'event_espresso'
2019
+			)
2020
+		);
2021
+		// $this->request->setRequestParam('EVT_ID', $post_id);
2022
+		// $this->_delete_event();
2023
+	}
2024
+
2025
+
2026
+	/**
2027
+	 * _trash_or_restore_event
2028
+	 *
2029
+	 * @access protected
2030
+	 * @param string $event_status
2031
+	 * @param bool   $redirect_after
2032
+	 * @throws EE_Error
2033
+	 * @throws EE_Error
2034
+	 * @throws ReflectionException
2035
+	 */
2036
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2037
+	{
2038
+		// determine the event id and set to array.
2039
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2040
+		// loop thru events
2041
+		if ($EVT_ID) {
2042
+			// clean status
2043
+			$event_status = sanitize_key($event_status);
2044
+			// grab status
2045
+			if (! empty($event_status)) {
2046
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2047
+			} else {
2048
+				$success = false;
2049
+				$msg     = esc_html__(
2050
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2051
+					'event_espresso'
2052
+				);
2053
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2054
+			}
2055
+		} else {
2056
+			$success = false;
2057
+			$msg     = esc_html__(
2058
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2059
+				'event_espresso'
2060
+			);
2061
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2062
+		}
2063
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2064
+		if ($redirect_after) {
2065
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2066
+		}
2067
+	}
2068
+
2069
+
2070
+	/**
2071
+	 * _trash_or_restore_events
2072
+	 *
2073
+	 * @access protected
2074
+	 * @param string $event_status
2075
+	 * @return void
2076
+	 * @throws EE_Error
2077
+	 * @throws EE_Error
2078
+	 * @throws ReflectionException
2079
+	 */
2080
+	protected function _trash_or_restore_events($event_status = 'trash')
2081
+	{
2082
+		// clean status
2083
+		$event_status = sanitize_key($event_status);
2084
+		// grab status
2085
+		if (! empty($event_status)) {
2086
+			$success = true;
2087
+			// determine the event id and set to array.
2088
+			$EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2089
+			// loop thru events
2090
+			foreach ($EVT_IDs as $EVT_ID) {
2091
+				if ($EVT_ID = absint($EVT_ID)) {
2092
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2093
+					$success = $results !== false ? $success : false;
2094
+				} else {
2095
+					$msg = sprintf(
2096
+						esc_html__(
2097
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2098
+							'event_espresso'
2099
+						),
2100
+						$EVT_ID
2101
+					);
2102
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2103
+					$success = false;
2104
+				}
2105
+			}
2106
+		} else {
2107
+			$success = false;
2108
+			$msg     = esc_html__(
2109
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2110
+				'event_espresso'
2111
+			);
2112
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2113
+		}
2114
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2115
+		$success = $success ? 2 : false;
2116
+		$action  = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2117
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2118
+	}
2119
+
2120
+
2121
+	/**
2122
+	 * @param int    $EVT_ID
2123
+	 * @param string $event_status
2124
+	 * @return bool
2125
+	 * @throws EE_Error
2126
+	 * @throws ReflectionException
2127
+	 */
2128
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2129
+	{
2130
+		// grab event id
2131
+		if (! $EVT_ID) {
2132
+			$msg = esc_html__(
2133
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2134
+				'event_espresso'
2135
+			);
2136
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2137
+			return false;
2138
+		}
2139
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2140
+		// clean status
2141
+		$event_status = sanitize_key($event_status);
2142
+		// grab status
2143
+		if (empty($event_status)) {
2144
+			$msg = esc_html__(
2145
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2146
+				'event_espresso'
2147
+			);
2148
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2149
+			return false;
2150
+		}
2151
+		// was event trashed or restored ?
2152
+		switch ($event_status) {
2153
+			case 'draft':
2154
+				$action = 'restored from the trash';
2155
+				$hook   = 'AHEE_event_restored_from_trash';
2156
+				break;
2157
+			case 'trash':
2158
+				$action = 'moved to the trash';
2159
+				$hook   = 'AHEE_event_moved_to_trash';
2160
+				break;
2161
+			default:
2162
+				$action = 'updated';
2163
+				$hook   = false;
2164
+		}
2165
+		// use class to change status
2166
+		$this->_cpt_model_obj->set_status($event_status);
2167
+		$success = $this->_cpt_model_obj->save();
2168
+		if (! $success) {
2169
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2170
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2171
+			return false;
2172
+		}
2173
+		if ($hook) {
2174
+			do_action($hook);
2175
+		}
2176
+		return true;
2177
+	}
2178
+
2179
+
2180
+	/**
2181
+	 * @param array $event_ids
2182
+	 * @return array
2183
+	 * @since   4.10.23.p
2184
+	 */
2185
+	private function cleanEventIds(array $event_ids)
2186
+	{
2187
+		return array_map('absint', $event_ids);
2188
+	}
2189
+
2190
+
2191
+	/**
2192
+	 * @return array
2193
+	 * @since   4.10.23.p
2194
+	 */
2195
+	private function getEventIdsFromRequest()
2196
+	{
2197
+		if ($this->request->requestParamIsSet('EVT_IDs')) {
2198
+			return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2199
+		} else {
2200
+			return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2201
+		}
2202
+	}
2203
+
2204
+
2205
+	/**
2206
+	 * @param bool $preview_delete
2207
+	 * @throws EE_Error
2208
+	 */
2209
+	protected function _delete_event($preview_delete = true)
2210
+	{
2211
+		$this->_delete_events($preview_delete);
2212
+	}
2213
+
2214
+
2215
+	/**
2216
+	 * Gets the tree traversal batch persister.
2217
+	 *
2218
+	 * @return NodeGroupDao
2219
+	 * @throws InvalidArgumentException
2220
+	 * @throws InvalidDataTypeException
2221
+	 * @throws InvalidInterfaceException
2222
+	 * @since 4.10.12.p
2223
+	 */
2224
+	protected function getModelObjNodeGroupPersister()
2225
+	{
2226
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2227
+			$this->model_obj_node_group_persister =
2228
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2229
+		}
2230
+		return $this->model_obj_node_group_persister;
2231
+	}
2232
+
2233
+
2234
+	/**
2235
+	 * @param bool $preview_delete
2236
+	 * @return void
2237
+	 * @throws EE_Error
2238
+	 */
2239
+	protected function _delete_events($preview_delete = true)
2240
+	{
2241
+		$event_ids = $this->getEventIdsFromRequest();
2242
+		if ($preview_delete) {
2243
+			$this->generateDeletionPreview($event_ids);
2244
+		} else {
2245
+			EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2246
+		}
2247
+	}
2248
+
2249
+
2250
+	/**
2251
+	 * @param array $event_ids
2252
+	 */
2253
+	protected function generateDeletionPreview(array $event_ids)
2254
+	{
2255
+		$event_ids = $this->cleanEventIds($event_ids);
2256
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2257
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2258
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2259
+			[
2260
+				'action'            => 'preview_deletion',
2261
+				'deletion_job_code' => $deletion_job_code,
2262
+			],
2263
+			$this->_admin_base_url
2264
+		);
2265
+		EEH_URL::safeRedirectAndExit(
2266
+			EE_Admin_Page::add_query_args_and_nonce(
2267
+				[
2268
+					'page'              => 'espresso_batch',
2269
+					'batch'             => EED_Batch::batch_job,
2270
+					'EVT_IDs'           => $event_ids,
2271
+					'deletion_job_code' => $deletion_job_code,
2272
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2273
+					'return_url'        => urlencode($return_url),
2274
+				],
2275
+				admin_url()
2276
+			)
2277
+		);
2278
+	}
2279
+
2280
+
2281
+	/**
2282
+	 * Checks for a POST submission
2283
+	 *
2284
+	 * @since 4.10.12.p
2285
+	 */
2286
+	protected function confirmDeletion()
2287
+	{
2288
+		$deletion_redirect_logic =
2289
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2290
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2291
+	}
2292
+
2293
+
2294
+	/**
2295
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2296
+	 *
2297
+	 * @throws EE_Error
2298
+	 * @since 4.10.12.p
2299
+	 */
2300
+	protected function previewDeletion()
2301
+	{
2302
+		$preview_deletion_logic =
2303
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2304
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2305
+		$this->display_admin_page_with_no_sidebar();
2306
+	}
2307
+
2308
+
2309
+	/**
2310
+	 * get total number of events
2311
+	 *
2312
+	 * @access public
2313
+	 * @return int
2314
+	 * @throws EE_Error
2315
+	 * @throws EE_Error
2316
+	 */
2317
+	public function total_events()
2318
+	{
2319
+		return EEM_Event::instance()->count(
2320
+			['caps' => 'read_admin'],
2321
+			'EVT_ID',
2322
+			true
2323
+		);
2324
+	}
2325
+
2326
+
2327
+	/**
2328
+	 * get total number of draft events
2329
+	 *
2330
+	 * @access public
2331
+	 * @return int
2332
+	 * @throws EE_Error
2333
+	 * @throws EE_Error
2334
+	 */
2335
+	public function total_events_draft()
2336
+	{
2337
+		return EEM_Event::instance()->count(
2338
+			[
2339
+				['status' => ['IN', ['draft', 'auto-draft']]],
2340
+				'caps' => 'read_admin',
2341
+			],
2342
+			'EVT_ID',
2343
+			true
2344
+		);
2345
+	}
2346
+
2347
+
2348
+	/**
2349
+	 * get total number of trashed events
2350
+	 *
2351
+	 * @access public
2352
+	 * @return int
2353
+	 * @throws EE_Error
2354
+	 * @throws EE_Error
2355
+	 */
2356
+	public function total_trashed_events()
2357
+	{
2358
+		return EEM_Event::instance()->count(
2359
+			[
2360
+				['status' => 'trash'],
2361
+				'caps' => 'read_admin',
2362
+			],
2363
+			'EVT_ID',
2364
+			true
2365
+		);
2366
+	}
2367
+
2368
+
2369
+	/**
2370
+	 *    _default_event_settings
2371
+	 *    This generates the Default Settings Tab
2372
+	 *
2373
+	 * @return void
2374
+	 * @throws EE_Error
2375
+	 */
2376
+	protected function _default_event_settings()
2377
+	{
2378
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2379
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2380
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2381
+		$this->display_admin_page_with_sidebar();
2382
+	}
2383
+
2384
+
2385
+	/**
2386
+	 * Return the form for event settings.
2387
+	 *
2388
+	 * @return EE_Form_Section_Proper
2389
+	 * @throws EE_Error
2390
+	 */
2391
+	protected function _default_event_settings_form()
2392
+	{
2393
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2394
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2395
+		// exclude
2396
+			[
2397
+				EEM_Registration::status_id_cancelled,
2398
+				EEM_Registration::status_id_declined,
2399
+				EEM_Registration::status_id_incomplete,
2400
+				EEM_Registration::status_id_wait_list,
2401
+			],
2402
+			true
2403
+		);
2404
+		return new EE_Form_Section_Proper(
2405
+			[
2406
+				'name'            => 'update_default_event_settings',
2407
+				'html_id'         => 'update_default_event_settings',
2408
+				'html_class'      => 'form-table',
2409
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2410
+				'subsections'     => apply_filters(
2411
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2412
+					[
2413
+						'default_reg_status'  => new EE_Select_Input(
2414
+							$registration_stati_for_selection,
2415
+							[
2416
+								'default'         => isset($registration_config->default_STS_ID)
2417
+													 && array_key_exists(
2418
+														 $registration_config->default_STS_ID,
2419
+														 $registration_stati_for_selection
2420
+													 )
2421
+									? sanitize_text_field($registration_config->default_STS_ID)
2422
+									: EEM_Registration::status_id_pending_payment,
2423
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2424
+													 . EEH_Template::get_help_tab_link(
2425
+														 'default_settings_status_help_tab'
2426
+													 ),
2427
+								'html_help_text'  => esc_html__(
2428
+									'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.',
2429
+									'event_espresso'
2430
+								),
2431
+							]
2432
+						),
2433
+						'default_max_tickets' => new EE_Integer_Input(
2434
+							[
2435
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2436
+									? $registration_config->default_maximum_number_of_tickets
2437
+									: EEM_Event::get_default_additional_limit(),
2438
+								'html_label_text' => esc_html__(
2439
+									'Default Maximum Tickets Allowed Per Order:',
2440
+									'event_espresso'
2441
+								)
2442
+								. EEH_Template::get_help_tab_link(
2443
+									'default_maximum_tickets_help_tab"'
2444
+								),
2445
+								'html_help_text'  => esc_html__(
2446
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2447
+									'event_espresso'
2448
+								),
2449
+							]
2450
+						),
2451
+					]
2452
+				),
2453
+			]
2454
+		);
2455
+	}
2456
+
2457
+
2458
+	/**
2459
+	 * _update_default_event_settings
2460
+	 *
2461
+	 * @access protected
2462
+	 * @return void
2463
+	 * @throws EE_Error
2464
+	 */
2465
+	protected function _update_default_event_settings()
2466
+	{
2467
+		$registration_config = EE_Registry::instance()->CFG->registration;
2468
+		$form                = $this->_default_event_settings_form();
2469
+		if ($form->was_submitted()) {
2470
+			$form->receive_form_submission();
2471
+			if ($form->is_valid()) {
2472
+				$valid_data = $form->valid_data();
2473
+				if (isset($valid_data['default_reg_status'])) {
2474
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2475
+				}
2476
+				if (isset($valid_data['default_max_tickets'])) {
2477
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2478
+				}
2479
+				// update because data was valid!
2480
+				EE_Registry::instance()->CFG->update_espresso_config();
2481
+				EE_Error::overwrite_success();
2482
+				EE_Error::add_success(
2483
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2484
+				);
2485
+			}
2486
+		}
2487
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2488
+	}
2489
+
2490
+
2491
+	/*************        Templates        *************
20 2492
      *
21
-     * @var EE_Event $_event
22
-     */
23
-    protected $_event;
24
-
25
-
26
-    /**
27
-     * This will hold the category object for category_details screen.
28
-     *
29
-     * @var stdClass $_category
30
-     */
31
-    protected $_category;
32
-
33
-
34
-    /**
35
-     * This will hold the event model instance
36
-     *
37
-     * @var EEM_Event $_event_model
38
-     */
39
-    protected $_event_model;
40
-
41
-
42
-    /**
43
-     * @var EE_Event
44
-     */
45
-    protected $_cpt_model_obj = false;
46
-
47
-
48
-    /**
49
-     * @var NodeGroupDao
50
-     */
51
-    protected $model_obj_node_group_persister;
52
-
53
-
54
-    /**
55
-     * Initialize page props for this admin page group.
56
-     */
57
-    protected function _init_page_props()
58
-    {
59
-        $this->page_slug        = EVENTS_PG_SLUG;
60
-        $this->page_label       = EVENTS_LABEL;
61
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
62
-        $this->_admin_base_path = EVENTS_ADMIN;
63
-        $this->_cpt_model_names = [
64
-            'create_new' => 'EEM_Event',
65
-            'edit'       => 'EEM_Event',
66
-        ];
67
-        $this->_cpt_edit_routes = [
68
-            'espresso_events' => 'edit',
69
-        ];
70
-        add_action(
71
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
72
-            [$this, 'verify_event_edit'],
73
-            10,
74
-            2
75
-        );
76
-    }
77
-
78
-
79
-    /**
80
-     * Sets the ajax hooks used for this admin page group.
81
-     */
82
-    protected function _ajax_hooks()
83
-    {
84
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
85
-    }
86
-
87
-
88
-    /**
89
-     * Sets the page properties for this admin page group.
90
-     */
91
-    protected function _define_page_props()
92
-    {
93
-        $this->_admin_page_title = EVENTS_LABEL;
94
-        $this->_labels           = [
95
-            'buttons'      => [
96
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
97
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
98
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
99
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
100
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
101
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
102
-            ],
103
-            'editor_title' => [
104
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
105
-            ],
106
-            'publishbox'   => [
107
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
108
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
109
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
110
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
111
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
112
-            ],
113
-        ];
114
-    }
115
-
116
-
117
-    /**
118
-     * Sets the page routes property for this admin page group.
119
-     */
120
-    protected function _set_page_routes()
121
-    {
122
-        // load formatter helper
123
-        // load field generator helper
124
-        // is there a evt_id in the request?
125
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
126
-        $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
127
-
128
-        $this->_page_routes = [
129
-            'default'                       => [
130
-                'func'       => '_events_overview_list_table',
131
-                'capability' => 'ee_read_events',
132
-            ],
133
-            'create_new'                    => [
134
-                'func'       => '_create_new_cpt_item',
135
-                'capability' => 'ee_edit_events',
136
-            ],
137
-            'edit'                          => [
138
-                'func'       => '_edit_cpt_item',
139
-                'capability' => 'ee_edit_event',
140
-                'obj_id'     => $EVT_ID,
141
-            ],
142
-            'copy_event'                    => [
143
-                'func'       => '_copy_events',
144
-                'capability' => 'ee_edit_event',
145
-                'obj_id'     => $EVT_ID,
146
-                'noheader'   => true,
147
-            ],
148
-            'trash_event'                   => [
149
-                'func'       => '_trash_or_restore_event',
150
-                'args'       => ['event_status' => 'trash'],
151
-                'capability' => 'ee_delete_event',
152
-                'obj_id'     => $EVT_ID,
153
-                'noheader'   => true,
154
-            ],
155
-            'trash_events'                  => [
156
-                'func'       => '_trash_or_restore_events',
157
-                'args'       => ['event_status' => 'trash'],
158
-                'capability' => 'ee_delete_events',
159
-                'noheader'   => true,
160
-            ],
161
-            'restore_event'                 => [
162
-                'func'       => '_trash_or_restore_event',
163
-                'args'       => ['event_status' => 'draft'],
164
-                'capability' => 'ee_delete_event',
165
-                'obj_id'     => $EVT_ID,
166
-                'noheader'   => true,
167
-            ],
168
-            'restore_events'                => [
169
-                'func'       => '_trash_or_restore_events',
170
-                'args'       => ['event_status' => 'draft'],
171
-                'capability' => 'ee_delete_events',
172
-                'noheader'   => true,
173
-            ],
174
-            'delete_event'                  => [
175
-                'func'       => '_delete_event',
176
-                'capability' => 'ee_delete_event',
177
-                'obj_id'     => $EVT_ID,
178
-                'noheader'   => true,
179
-            ],
180
-            'delete_events'                 => [
181
-                'func'       => '_delete_events',
182
-                'capability' => 'ee_delete_events',
183
-                'noheader'   => true,
184
-            ],
185
-            'view_report'                   => [
186
-                'func'       => '_view_report',
187
-                'capability' => 'ee_edit_events',
188
-            ],
189
-            'default_event_settings'        => [
190
-                'func'       => '_default_event_settings',
191
-                'capability' => 'manage_options',
192
-            ],
193
-            'update_default_event_settings' => [
194
-                'func'       => '_update_default_event_settings',
195
-                'capability' => 'manage_options',
196
-                'noheader'   => true,
197
-            ],
198
-            'template_settings'             => [
199
-                'func'       => '_template_settings',
200
-                'capability' => 'manage_options',
201
-            ],
202
-            // event category tab related
203
-            'add_category'                  => [
204
-                'func'       => '_category_details',
205
-                'capability' => 'ee_edit_event_category',
206
-                'args'       => ['add'],
207
-            ],
208
-            'edit_category'                 => [
209
-                'func'       => '_category_details',
210
-                'capability' => 'ee_edit_event_category',
211
-                'args'       => ['edit'],
212
-            ],
213
-            'delete_categories'             => [
214
-                'func'       => '_delete_categories',
215
-                'capability' => 'ee_delete_event_category',
216
-                'noheader'   => true,
217
-            ],
218
-            'delete_category'               => [
219
-                'func'       => '_delete_categories',
220
-                'capability' => 'ee_delete_event_category',
221
-                'noheader'   => true,
222
-            ],
223
-            'insert_category'               => [
224
-                'func'       => '_insert_or_update_category',
225
-                'args'       => ['new_category' => true],
226
-                'capability' => 'ee_edit_event_category',
227
-                'noheader'   => true,
228
-            ],
229
-            'update_category'               => [
230
-                'func'       => '_insert_or_update_category',
231
-                'args'       => ['new_category' => false],
232
-                'capability' => 'ee_edit_event_category',
233
-                'noheader'   => true,
234
-            ],
235
-            'category_list'                 => [
236
-                'func'       => '_category_list_table',
237
-                'capability' => 'ee_manage_event_categories',
238
-            ],
239
-            'preview_deletion'              => [
240
-                'func'       => 'previewDeletion',
241
-                'capability' => 'ee_delete_events',
242
-            ],
243
-            'confirm_deletion'              => [
244
-                'func'       => 'confirmDeletion',
245
-                'capability' => 'ee_delete_events',
246
-                'noheader'   => true,
247
-            ],
248
-        ];
249
-    }
250
-
251
-
252
-    /**
253
-     * Set the _page_config property for this admin page group.
254
-     */
255
-    protected function _set_page_config()
256
-    {
257
-        $post_id            = $this->request->getRequestParam('post', 0, 'int');
258
-        $EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
259
-        $this->_page_config = [
260
-            'default'                => [
261
-                'nav'           => [
262
-                    'label' => esc_html__('Overview', 'event_espresso'),
263
-                    'order' => 10,
264
-                ],
265
-                'list_table'    => 'Events_Admin_List_Table',
266
-                'help_tabs'     => [
267
-                    'events_overview_help_tab'                       => [
268
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
269
-                        'filename' => 'events_overview',
270
-                    ],
271
-                    'events_overview_table_column_headings_help_tab' => [
272
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
273
-                        'filename' => 'events_overview_table_column_headings',
274
-                    ],
275
-                    'events_overview_filters_help_tab'               => [
276
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
277
-                        'filename' => 'events_overview_filters',
278
-                    ],
279
-                    'events_overview_view_help_tab'                  => [
280
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
281
-                        'filename' => 'events_overview_views',
282
-                    ],
283
-                    'events_overview_other_help_tab'                 => [
284
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
285
-                        'filename' => 'events_overview_other',
286
-                    ],
287
-                ],
288
-                'qtips'         => [
289
-                    'EE_Event_List_Table_Tips',
290
-                ],
291
-                'require_nonce' => false,
292
-            ],
293
-            'create_new'             => [
294
-                'nav'           => [
295
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
296
-                    'order'      => 5,
297
-                    'persistent' => false,
298
-                ],
299
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
300
-                'help_tabs'     => [
301
-                    'event_editor_help_tab'                            => [
302
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
303
-                        'filename' => 'event_editor',
304
-                    ],
305
-                    'event_editor_title_richtexteditor_help_tab'       => [
306
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
307
-                        'filename' => 'event_editor_title_richtexteditor',
308
-                    ],
309
-                    'event_editor_venue_details_help_tab'              => [
310
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
311
-                        'filename' => 'event_editor_venue_details',
312
-                    ],
313
-                    'event_editor_event_datetimes_help_tab'            => [
314
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
315
-                        'filename' => 'event_editor_event_datetimes',
316
-                    ],
317
-                    'event_editor_event_tickets_help_tab'              => [
318
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
319
-                        'filename' => 'event_editor_event_tickets',
320
-                    ],
321
-                    'event_editor_event_registration_options_help_tab' => [
322
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
323
-                        'filename' => 'event_editor_event_registration_options',
324
-                    ],
325
-                    'event_editor_tags_categories_help_tab'            => [
326
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
327
-                        'filename' => 'event_editor_tags_categories',
328
-                    ],
329
-                    'event_editor_questions_registrants_help_tab'      => [
330
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
331
-                        'filename' => 'event_editor_questions_registrants',
332
-                    ],
333
-                    'event_editor_save_new_event_help_tab'             => [
334
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
335
-                        'filename' => 'event_editor_save_new_event',
336
-                    ],
337
-                    'event_editor_other_help_tab'                      => [
338
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
339
-                        'filename' => 'event_editor_other',
340
-                    ],
341
-                ],
342
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
343
-                'require_nonce' => false,
344
-            ],
345
-            'edit'                   => [
346
-                'nav'           => [
347
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
348
-                    'order'      => 5,
349
-                    'persistent' => false,
350
-                    'url'        => $post_id
351
-                        ? EE_Admin_Page::add_query_args_and_nonce(
352
-                            ['post' => $post_id, 'action' => 'edit'],
353
-                            $this->_current_page_view_url
354
-                        )
355
-                        : $this->_admin_base_url,
356
-                ],
357
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
358
-                'help_tabs'     => [
359
-                    'event_editor_help_tab'                            => [
360
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
361
-                        'filename' => 'event_editor',
362
-                    ],
363
-                    'event_editor_title_richtexteditor_help_tab'       => [
364
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
365
-                        'filename' => 'event_editor_title_richtexteditor',
366
-                    ],
367
-                    'event_editor_venue_details_help_tab'              => [
368
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
369
-                        'filename' => 'event_editor_venue_details',
370
-                    ],
371
-                    'event_editor_event_datetimes_help_tab'            => [
372
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
373
-                        'filename' => 'event_editor_event_datetimes',
374
-                    ],
375
-                    'event_editor_event_tickets_help_tab'              => [
376
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
377
-                        'filename' => 'event_editor_event_tickets',
378
-                    ],
379
-                    'event_editor_event_registration_options_help_tab' => [
380
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
381
-                        'filename' => 'event_editor_event_registration_options',
382
-                    ],
383
-                    'event_editor_tags_categories_help_tab'            => [
384
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
385
-                        'filename' => 'event_editor_tags_categories',
386
-                    ],
387
-                    'event_editor_questions_registrants_help_tab'      => [
388
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
389
-                        'filename' => 'event_editor_questions_registrants',
390
-                    ],
391
-                    'event_editor_save_new_event_help_tab'             => [
392
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
393
-                        'filename' => 'event_editor_save_new_event',
394
-                    ],
395
-                    'event_editor_other_help_tab'                      => [
396
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
397
-                        'filename' => 'event_editor_other',
398
-                    ],
399
-                ],
400
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
401
-                'require_nonce' => false,
402
-            ],
403
-            'default_event_settings' => [
404
-                'nav'           => [
405
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
406
-                    'order' => 40,
407
-                ],
408
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
409
-                'labels'        => [
410
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
411
-                ],
412
-                'help_tabs'     => [
413
-                    'default_settings_help_tab'        => [
414
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
415
-                        'filename' => 'events_default_settings',
416
-                    ],
417
-                    'default_settings_status_help_tab' => [
418
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
419
-                        'filename' => 'events_default_settings_status',
420
-                    ],
421
-                    'default_maximum_tickets_help_tab' => [
422
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
423
-                        'filename' => 'events_default_settings_max_tickets',
424
-                    ],
425
-                ],
426
-                'require_nonce' => false,
427
-            ],
428
-            // template settings
429
-            'template_settings'      => [
430
-                'nav'           => [
431
-                    'label' => esc_html__('Templates', 'event_espresso'),
432
-                    'order' => 30,
433
-                ],
434
-                'metaboxes'     => $this->_default_espresso_metaboxes,
435
-                'help_tabs'     => [
436
-                    'general_settings_templates_help_tab' => [
437
-                        'title'    => esc_html__('Templates', 'event_espresso'),
438
-                        'filename' => 'general_settings_templates',
439
-                    ],
440
-                ],
441
-                'require_nonce' => false,
442
-            ],
443
-            // event category stuff
444
-            'add_category'           => [
445
-                'nav'           => [
446
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
447
-                    'order'      => 15,
448
-                    'persistent' => false,
449
-                ],
450
-                'help_tabs'     => [
451
-                    'add_category_help_tab' => [
452
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
453
-                        'filename' => 'events_add_category',
454
-                    ],
455
-                ],
456
-                'metaboxes'     => ['_publish_post_box'],
457
-                'require_nonce' => false,
458
-            ],
459
-            'edit_category'          => [
460
-                'nav'           => [
461
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
462
-                    'order'      => 15,
463
-                    'persistent' => false,
464
-                    'url'        => $EVT_CAT_ID
465
-                        ? add_query_arg(
466
-                            ['EVT_CAT_ID' => $EVT_CAT_ID],
467
-                            $this->_current_page_view_url
468
-                        )
469
-                        : $this->_admin_base_url,
470
-                ],
471
-                'help_tabs'     => [
472
-                    'edit_category_help_tab' => [
473
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
474
-                        'filename' => 'events_edit_category',
475
-                    ],
476
-                ],
477
-                'metaboxes'     => ['_publish_post_box'],
478
-                'require_nonce' => false,
479
-            ],
480
-            'category_list'          => [
481
-                'nav'           => [
482
-                    'label' => esc_html__('Categories', 'event_espresso'),
483
-                    'order' => 20,
484
-                ],
485
-                'list_table'    => 'Event_Categories_Admin_List_Table',
486
-                'help_tabs'     => [
487
-                    'events_categories_help_tab'                       => [
488
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
489
-                        'filename' => 'events_categories',
490
-                    ],
491
-                    'events_categories_table_column_headings_help_tab' => [
492
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
493
-                        'filename' => 'events_categories_table_column_headings',
494
-                    ],
495
-                    'events_categories_view_help_tab'                  => [
496
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
497
-                        'filename' => 'events_categories_views',
498
-                    ],
499
-                    'events_categories_other_help_tab'                 => [
500
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
501
-                        'filename' => 'events_categories_other',
502
-                    ],
503
-                ],
504
-                'metaboxes'     => $this->_default_espresso_metaboxes,
505
-                'require_nonce' => false,
506
-            ],
507
-            'preview_deletion'       => [
508
-                'nav'           => [
509
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
510
-                    'order'      => 15,
511
-                    'persistent' => false,
512
-                    'url'        => '',
513
-                ],
514
-                'require_nonce' => false,
515
-            ],
516
-        ];
517
-    }
518
-
519
-
520
-    /**
521
-     * Used to register any global screen options if necessary for every route in this admin page group.
522
-     */
523
-    protected function _add_screen_options()
524
-    {
525
-    }
526
-
527
-
528
-    /**
529
-     * Implementing the screen options for the 'default' route.
530
-     */
531
-    protected function _add_screen_options_default()
532
-    {
533
-        $this->_per_page_screen_option();
534
-    }
535
-
536
-
537
-    /**
538
-     * Implementing screen options for the category list route.
539
-     */
540
-    protected function _add_screen_options_category_list()
541
-    {
542
-        $page_title              = $this->_admin_page_title;
543
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
544
-        $this->_per_page_screen_option();
545
-        $this->_admin_page_title = $page_title;
546
-    }
547
-
548
-
549
-    /**
550
-     * Used to register any global feature pointers for the admin page group.
551
-     */
552
-    protected function _add_feature_pointers()
553
-    {
554
-    }
555
-
556
-
557
-    /**
558
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
559
-     */
560
-    public function load_scripts_styles()
561
-    {
562
-        wp_register_style(
563
-            'events-admin-css',
564
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
565
-            [],
566
-            EVENT_ESPRESSO_VERSION
567
-        );
568
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
569
-        wp_enqueue_style('events-admin-css');
570
-        wp_enqueue_style('ee-cat-admin');
571
-        // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
572
-        // registers for all views
573
-        // scripts
574
-        wp_register_script(
575
-            'event_editor_js',
576
-            EVENTS_ASSETS_URL . 'event_editor.js',
577
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
578
-            EVENT_ESPRESSO_VERSION,
579
-            true
580
-        );
581
-    }
582
-
583
-
584
-    /**
585
-     * Enqueuing scripts and styles specific to this view
586
-     */
587
-    public function load_scripts_styles_create_new()
588
-    {
589
-        $this->load_scripts_styles_edit();
590
-    }
591
-
592
-
593
-    /**
594
-     * Enqueuing scripts and styles specific to this view
595
-     */
596
-    public function load_scripts_styles_edit()
597
-    {
598
-        // styles
599
-        wp_enqueue_style('espresso-ui-theme');
600
-        wp_register_style(
601
-            'event-editor-css',
602
-            EVENTS_ASSETS_URL . 'event-editor.css',
603
-            ['ee-admin-css'],
604
-            EVENT_ESPRESSO_VERSION
605
-        );
606
-        wp_enqueue_style('event-editor-css');
607
-        // scripts
608
-        wp_register_script(
609
-            'event-datetime-metabox',
610
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
611
-            ['event_editor_js', 'ee-datepicker'],
612
-            EVENT_ESPRESSO_VERSION
613
-        );
614
-        wp_enqueue_script('event-datetime-metabox');
615
-    }
616
-
617
-
618
-    /**
619
-     * Populating the _views property for the category list table view.
620
-     */
621
-    protected function _set_list_table_views_category_list()
622
-    {
623
-        $this->_views = [
624
-            'all' => [
625
-                'slug'        => 'all',
626
-                'label'       => esc_html__('All', 'event_espresso'),
627
-                'count'       => 0,
628
-                'bulk_action' => [
629
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
630
-                ],
631
-            ],
632
-        ];
633
-    }
634
-
635
-
636
-    /**
637
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
638
-     */
639
-    public function admin_init()
640
-    {
641
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
642
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
643
-            'event_espresso'
644
-        );
645
-    }
646
-
647
-
648
-    /**
649
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
650
-     * group.
651
-     */
652
-    public function admin_notices()
653
-    {
654
-    }
655
-
656
-
657
-    /**
658
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
659
-     * this admin page group.
660
-     */
661
-    public function admin_footer_scripts()
662
-    {
663
-    }
664
-
665
-
666
-    /**
667
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
668
-     * warning (via EE_Error::add_error());
669
-     *
670
-     * @param EE_Event $event Event object
671
-     * @param string   $req_type
672
-     * @return void
673
-     * @throws EE_Error
674
-     * @throws ReflectionException
675
-     */
676
-    public function verify_event_edit($event = null, $req_type = '')
677
-    {
678
-        // don't need to do this when processing
679
-        if (! empty($req_type)) {
680
-            return;
681
-        }
682
-        // no event?
683
-        if (empty($event)) {
684
-            // set event
685
-            $event = $this->_cpt_model_obj;
686
-        }
687
-        // STILL no event?
688
-        if (! $event instanceof EE_Event) {
689
-            return;
690
-        }
691
-        $orig_status = $event->status();
692
-        // first check if event is active.
693
-        if (
694
-            $orig_status === EEM_Event::cancelled
695
-            || $orig_status === EEM_Event::postponed
696
-            || $event->is_expired()
697
-            || $event->is_inactive()
698
-        ) {
699
-            return;
700
-        }
701
-        // made it here so it IS active... next check that any of the tickets are sold.
702
-        if ($event->is_sold_out(true)) {
703
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
704
-                EE_Error::add_attention(
705
-                    sprintf(
706
-                        esc_html__(
707
-                            '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.',
708
-                            'event_espresso'
709
-                        ),
710
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
711
-                    )
712
-                );
713
-            }
714
-            return;
715
-        } elseif ($orig_status === EEM_Event::sold_out) {
716
-            EE_Error::add_attention(
717
-                sprintf(
718
-                    esc_html__(
719
-                        '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.',
720
-                        'event_espresso'
721
-                    ),
722
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
723
-                )
724
-            );
725
-        }
726
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
727
-        if (! $event->tickets_on_sale()) {
728
-            return;
729
-        }
730
-        // made it here so show warning
731
-        $this->_edit_event_warning();
732
-    }
733
-
734
-
735
-    /**
736
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
737
-     * When needed, hook this into a EE_Error::add_error() notice.
738
-     *
739
-     * @access protected
740
-     * @return void
741
-     */
742
-    protected function _edit_event_warning()
743
-    {
744
-        // we don't want to add warnings during these requests
745
-        if ($this->request->getRequestParam('action') === 'editpost') {
746
-            return;
747
-        }
748
-        EE_Error::add_attention(
749
-            sprintf(
750
-                esc_html__(
751
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
752
-                    'event_espresso'
753
-                ),
754
-                '<a class="espresso-help-tab-lnk">',
755
-                '</a>'
756
-            )
757
-        );
758
-    }
759
-
760
-
761
-    /**
762
-     * When a user is creating a new event, notify them if they haven't set their timezone.
763
-     * Otherwise, do the normal logic
764
-     *
765
-     * @return void
766
-     * @throws EE_Error
767
-     */
768
-    protected function _create_new_cpt_item()
769
-    {
770
-        $has_timezone_string = get_option('timezone_string');
771
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
772
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
773
-            EE_Error::add_attention(
774
-                sprintf(
775
-                    esc_html__(
776
-                        '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',
777
-                        'event_espresso'
778
-                    ),
779
-                    '<br>',
780
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
781
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
782
-                    . '</select>',
783
-                    '<button class="button button-secondary timezone-submit">',
784
-                    '</button><span class="spinner"></span>'
785
-                ),
786
-                __FILE__,
787
-                __FUNCTION__,
788
-                __LINE__
789
-            );
790
-        }
791
-        parent::_create_new_cpt_item();
792
-    }
793
-
794
-
795
-    /**
796
-     * Sets the _views property for the default route in this admin page group.
797
-     */
798
-    protected function _set_list_table_views_default()
799
-    {
800
-        $this->_views = [
801
-            'all'   => [
802
-                'slug'        => 'all',
803
-                'label'       => esc_html__('View All Events', 'event_espresso'),
804
-                'count'       => 0,
805
-                'bulk_action' => [
806
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
807
-                ],
808
-            ],
809
-            'draft' => [
810
-                'slug'        => 'draft',
811
-                'label'       => esc_html__('Draft', 'event_espresso'),
812
-                'count'       => 0,
813
-                'bulk_action' => [
814
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
815
-                ],
816
-            ],
817
-        ];
818
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
819
-            $this->_views['trash'] = [
820
-                'slug'        => 'trash',
821
-                'label'       => esc_html__('Trash', 'event_espresso'),
822
-                'count'       => 0,
823
-                'bulk_action' => [
824
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
825
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
826
-                ],
827
-            ];
828
-        }
829
-    }
830
-
831
-
832
-    /**
833
-     * Provides the legend item array for the default list table view.
834
-     *
835
-     * @return array
836
-     * @throws EE_Error
837
-     * @throws EE_Error
838
-     */
839
-    protected function _event_legend_items()
840
-    {
841
-        $items    = [
842
-            'view_details'   => [
843
-                'class' => 'dashicons dashicons-search',
844
-                'desc'  => esc_html__('View Event', 'event_espresso'),
845
-            ],
846
-            'edit_event'     => [
847
-                'class' => 'ee-icon ee-icon-calendar-edit',
848
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
849
-            ],
850
-            'view_attendees' => [
851
-                'class' => 'dashicons dashicons-groups',
852
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
853
-            ],
854
-        ];
855
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
856
-        $statuses = [
857
-            'sold_out_status'  => [
858
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
859
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
860
-            ],
861
-            'active_status'    => [
862
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
863
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
864
-            ],
865
-            'upcoming_status'  => [
866
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
867
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
868
-            ],
869
-            'postponed_status' => [
870
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
871
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
872
-            ],
873
-            'cancelled_status' => [
874
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
875
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
876
-            ],
877
-            'expired_status'   => [
878
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
879
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
880
-            ],
881
-            'inactive_status'  => [
882
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
883
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
884
-            ],
885
-        ];
886
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
887
-        return array_merge($items, $statuses);
888
-    }
889
-
890
-
891
-    /**
892
-     * @return EEM_Event
893
-     * @throws EE_Error
894
-     * @throws ReflectionException
895
-     */
896
-    private function _event_model()
897
-    {
898
-        if (! $this->_event_model instanceof EEM_Event) {
899
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
900
-        }
901
-        return $this->_event_model;
902
-    }
903
-
904
-
905
-    /**
906
-     * Adds extra buttons to the WP CPT permalink field row.
907
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
908
-     *
909
-     * @param string $return    the current html
910
-     * @param int    $id        the post id for the page
911
-     * @param string $new_title What the title is
912
-     * @param string $new_slug  what the slug is
913
-     * @return string            The new html string for the permalink area
914
-     */
915
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
916
-    {
917
-        // make sure this is only when editing
918
-        if (! empty($id)) {
919
-            $post   = get_post($id);
920
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
921
-                       . esc_html__('Shortcode', 'event_espresso')
922
-                       . '</a> ';
923
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
924
-                       . $post->ID
925
-                       . ']">';
926
-        }
927
-        return $return;
928
-    }
929
-
930
-
931
-    /**
932
-     * _events_overview_list_table
933
-     * This contains the logic for showing the events_overview list
934
-     *
935
-     * @access protected
936
-     * @return void
937
-     * @throws EE_Error
938
-     */
939
-    protected function _events_overview_list_table()
940
-    {
941
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
942
-        $this->_template_args['after_list_table']                           =
943
-            ! empty($this->_template_args['after_list_table'])
944
-                ? (array) $this->_template_args['after_list_table']
945
-                : [];
946
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
947
-            . EEH_Template::get_button_or_link(
948
-                get_post_type_archive_link('espresso_events'),
949
-                esc_html__("View Event Archive Page", "event_espresso"),
950
-                'button'
951
-            );
952
-        $this->_template_args['after_list_table']['legend']                 = $this->_display_legend(
953
-            $this->_event_legend_items()
954
-        );
955
-        $this->_admin_page_title                                            .= ' ' . $this->get_action_link_or_button(
956
-            'create_new',
957
-            'add',
958
-            [],
959
-            'add-new-h2'
960
-        );
961
-        $this->display_admin_list_table_page_with_no_sidebar();
962
-    }
963
-
964
-
965
-    /**
966
-     * this allows for extra misc actions in the default WP publish box
967
-     *
968
-     * @return void
969
-     * @throws EE_Error
970
-     * @throws ReflectionException
971
-     */
972
-    public function extra_misc_actions_publish_box()
973
-    {
974
-        $this->_generate_publish_box_extra_content();
975
-    }
976
-
977
-
978
-    /**
979
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
980
-     * saved.
981
-     * Typically you would use this to save any additional data.
982
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
983
-     * ALSO very important.  When a post transitions from scheduled to published,
984
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
985
-     * other meta saves. So MAKE sure that you handle this accordingly.
986
-     *
987
-     * @access protected
988
-     * @abstract
989
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
990
-     * @param WP_Post $post    The post object of the cpt that was saved.
991
-     * @return void
992
-     * @throws EE_Error
993
-     * @throws ReflectionException
994
-     */
995
-    protected function _insert_update_cpt_item($post_id, $post)
996
-    {
997
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
998
-            // get out we're not processing an event save.
999
-            return;
1000
-        }
1001
-
1002
-        $event_values = [
1003
-            'EVT_display_desc'                => $this->request->getRequestParam('display_desc', false, 'bool'),
1004
-            'EVT_display_ticket_selector'     => $this->request->getRequestParam(
1005
-                'display_ticket_selector',
1006
-                false,
1007
-                'bool'
1008
-            ),
1009
-            'EVT_additional_limit'            => min(
1010
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1011
-                $this->request->getRequestParam('additional_limit', null, 'int')
1012
-            ),
1013
-            'EVT_default_registration_status' => $this->request->getRequestParam(
1014
-                'EVT_default_registration_status',
1015
-                EE_Registry::instance()->CFG->registration->default_STS_ID
1016
-            ),
1017
-
1018
-            'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1019
-            'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1020
-            'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1021
-            'EVT_external_URL'    => $this->request->getRequestParam('externalURL'),
1022
-            'EVT_phone'           => $this->request->getRequestParam('event_phone'),
1023
-        ];
1024
-        // update event
1025
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1026
-        // get event_object for other metaboxes...
1027
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1028
-        // i have to setup where conditions to override the filters in the model
1029
-        // that filter out autodraft and inherit statuses so we GET the inherit id!
1030
-        $event = $this->_event_model()->get_one(
1031
-            [
1032
-                [
1033
-                    $this->_event_model()->primary_key_name() => $post_id,
1034
-                    'OR'                                      => [
1035
-                        'status'   => $post->post_status,
1036
-                        // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1037
-                        // but the returned object here has a status of "publish", so use the original post status as well
1038
-                        'status*1' => $this->request->getRequestParam('original_post_status'),
1039
-                    ],
1040
-                ],
1041
-            ]
1042
-        );
1043
-        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1044
-        $event_update_callbacks = apply_filters(
1045
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1046
-            [
1047
-                [$this, '_default_venue_update'],
1048
-                [$this, '_default_tickets_update'],
1049
-            ]
1050
-        );
1051
-        $att_success            = true;
1052
-        foreach ($event_update_callbacks as $e_callback) {
1053
-            $_success = is_callable($e_callback)
1054
-                ? call_user_func($e_callback, $event, $this->request->requestParams())
1055
-                : false;
1056
-            // if ANY of these updates fail then we want the appropriate global error message
1057
-            $att_success = ! $att_success ? $att_success : $_success;
1058
-        }
1059
-        // any errors?
1060
-        if ($success && false === $att_success) {
1061
-            EE_Error::add_error(
1062
-                esc_html__(
1063
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1064
-                    'event_espresso'
1065
-                ),
1066
-                __FILE__,
1067
-                __FUNCTION__,
1068
-                __LINE__
1069
-            );
1070
-        } elseif ($success === false) {
1071
-            EE_Error::add_error(
1072
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1073
-                __FILE__,
1074
-                __FUNCTION__,
1075
-                __LINE__
1076
-            );
1077
-        }
1078
-    }
1079
-
1080
-
1081
-    /**
1082
-     * @param int $post_id
1083
-     * @param int $revision_id
1084
-     * @throws EE_Error
1085
-     * @throws EE_Error
1086
-     * @throws ReflectionException
1087
-     * @see parent::restore_item()
1088
-     */
1089
-    protected function _restore_cpt_item($post_id, $revision_id)
1090
-    {
1091
-        // copy existing event meta to new post
1092
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1093
-        if ($post_evt instanceof EE_Event) {
1094
-            // meta revision restore
1095
-            $post_evt->restore_revision($revision_id);
1096
-            // related objs restore
1097
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1098
-        }
1099
-    }
1100
-
1101
-
1102
-    /**
1103
-     * Attach the venue to the Event
1104
-     *
1105
-     * @param EE_Event $event Event Object to add the venue to
1106
-     * @param array    $data  The request data from the form
1107
-     * @return bool           Success or fail.
1108
-     * @throws EE_Error
1109
-     * @throws ReflectionException
1110
-     */
1111
-    protected function _default_venue_update(EE_Event $event, $data)
1112
-    {
1113
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1114
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1115
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1116
-        // very important.  If we don't have a venue name...
1117
-        // then we'll get out because not necessary to create empty venue
1118
-        if (empty($data['venue_title'])) {
1119
-            return false;
1120
-        }
1121
-        $venue_array = [
1122
-            'VNU_wp_user'         => $event->get('EVT_wp_user'),
1123
-            'VNU_name'            => $data['venue_title'],
1124
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1125
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1126
-            'VNU_short_desc'      => ! empty($data['venue_short_description'])
1127
-                ? $data['venue_short_description']
1128
-                : null,
1129
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1130
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1131
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1132
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1133
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1134
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1135
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1136
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1137
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1138
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1139
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1140
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1141
-            'status'              => 'publish',
1142
-        ];
1143
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1144
-        if (! empty($venue_id)) {
1145
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1146
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1147
-            // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1148
-            $event->_add_relation_to($venue_id, 'Venue');
1149
-            return $rows_affected > 0;
1150
-        }
1151
-        // we insert the venue
1152
-        $venue_id = $venue_model->insert($venue_array);
1153
-        $event->_add_relation_to($venue_id, 'Venue');
1154
-        return ! empty($venue_id);
1155
-        // when we have the ancestor come in it's already been handled by the revision save.
1156
-    }
1157
-
1158
-
1159
-    /**
1160
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1161
-     *
1162
-     * @param EE_Event $event The Event object we're attaching data to
1163
-     * @param array    $data  The request data from the form
1164
-     * @return array
1165
-     * @throws EE_Error
1166
-     * @throws ReflectionException
1167
-     * @throws Exception
1168
-     */
1169
-    protected function _default_tickets_update(EE_Event $event, $data)
1170
-    {
1171
-        $datetime       = null;
1172
-        $saved_tickets  = [];
1173
-        $event_timezone = $event->get_timezone();
1174
-        $date_formats   = ['Y-m-d', 'h:i a'];
1175
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1176
-            // trim all values to ensure any excess whitespace is removed.
1177
-            $datetime_data                = array_map('trim', $datetime_data);
1178
-            $datetime_data['DTT_EVT_end'] =
1179
-                isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1180
-                    ? $datetime_data['DTT_EVT_end']
1181
-                    : $datetime_data['DTT_EVT_start'];
1182
-            $datetime_values              = [
1183
-                'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1184
-                'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1185
-                'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1186
-                'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1187
-                'DTT_order'     => $row,
1188
-            ];
1189
-            // if we have an id then let's get existing object first and then set the new values.
1190
-            //  Otherwise we instantiate a new object for save.
1191
-            if (! empty($datetime_data['DTT_ID'])) {
1192
-                $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1193
-                if (! $datetime instanceof EE_Datetime) {
1194
-                    throw new RuntimeException(
1195
-                        sprintf(
1196
-                            esc_html__(
1197
-                                'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1198
-                                'event_espresso'
1199
-                            ),
1200
-                            $datetime_data['DTT_ID']
1201
-                        )
1202
-                    );
1203
-                }
1204
-                $datetime->set_date_format($date_formats[0]);
1205
-                $datetime->set_time_format($date_formats[1]);
1206
-                foreach ($datetime_values as $field => $value) {
1207
-                    $datetime->set($field, $value);
1208
-                }
1209
-            } else {
1210
-                $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1211
-            }
1212
-            if (! $datetime instanceof EE_Datetime) {
1213
-                throw new RuntimeException(
1214
-                    sprintf(
1215
-                        esc_html__(
1216
-                            'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1217
-                            'event_espresso'
1218
-                        ),
1219
-                        print_r($datetime_values, true)
1220
-                    )
1221
-                );
1222
-            }
1223
-            // before going any further make sure our dates are setup correctly
1224
-            // so that the end date is always equal or greater than the start date.
1225
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1226
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1227
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1228
-            }
1229
-            $datetime->save();
1230
-            $event->_add_relation_to($datetime, 'Datetime');
1231
-        }
1232
-        // no datetimes get deleted so we don't do any of that logic here.
1233
-        // update tickets next
1234
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1235
-
1236
-        // set up some default start and end dates in case those are not present in the incoming data
1237
-        $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1238
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1239
-        // use the start date of the first datetime for the end date
1240
-        $first_datetime   = $event->first_datetime();
1241
-        $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1242
-
1243
-        // now process the incoming data
1244
-        foreach ($data['edit_tickets'] as $row => $ticket_data) {
1245
-            $update_prices = false;
1246
-            $ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1247
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1248
-                : 0;
1249
-            // trim inputs to ensure any excess whitespace is removed.
1250
-            $ticket_data   = array_map('trim', $ticket_data);
1251
-            $ticket_values = [
1252
-                'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1253
-                'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1254
-                'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1255
-                'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1256
-                'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1257
-                    ? $ticket_data['TKT_start_date']
1258
-                    : $default_start_date,
1259
-                'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1260
-                    ? $ticket_data['TKT_end_date']
1261
-                    : $default_end_date,
1262
-                'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1263
-                                     || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1264
-                    ? $ticket_data['TKT_qty']
1265
-                    : EE_INF,
1266
-                'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1267
-                                     || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1268
-                    ? $ticket_data['TKT_uses']
1269
-                    : EE_INF,
1270
-                'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1271
-                'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1272
-                'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1273
-                'TKT_price'       => $ticket_price,
1274
-                'TKT_row'         => $row,
1275
-            ];
1276
-            // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1277
-            // which means in turn that the prices will become new prices as well.
1278
-            if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1279
-                $ticket_values['TKT_ID']         = 0;
1280
-                $ticket_values['TKT_is_default'] = 0;
1281
-                $update_prices                   = true;
1282
-            }
1283
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1284
-            // we actually do our saves ahead of adding any relations because its entirely possible that this
1285
-            // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1286
-            // keep in mind that if the ticket has been sold (and we have changed pricing information),
1287
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1288
-            if (! empty($ticket_data['TKT_ID'])) {
1289
-                $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1290
-                if (! $existing_ticket instanceof EE_Ticket) {
1291
-                    throw new RuntimeException(
1292
-                        sprintf(
1293
-                            esc_html__(
1294
-                                'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1295
-                                'event_espresso'
1296
-                            ),
1297
-                            $ticket_data['TKT_ID']
1298
-                        )
1299
-                    );
1300
-                }
1301
-                $ticket_sold = $existing_ticket->count_related(
1302
-                    'Registration',
1303
-                    [
1304
-                        [
1305
-                            'STS_ID' => [
1306
-                                'NOT IN',
1307
-                                [EEM_Registration::status_id_incomplete],
1308
-                            ],
1309
-                        ],
1310
-                    ]
1311
-                ) > 0;
1312
-                // let's just check the total price for the existing ticket and determine if it matches the new total price.
1313
-                // if they are different then we create a new ticket (if $ticket_sold)
1314
-                // if they aren't different then we go ahead and modify existing ticket.
1315
-                $create_new_ticket = $ticket_sold
1316
-                                     && $ticket_price !== $existing_ticket->price()
1317
-                                     && ! $existing_ticket->deleted();
1318
-                $existing_ticket->set_date_format($date_formats[0]);
1319
-                $existing_ticket->set_time_format($date_formats[1]);
1320
-                // set new values
1321
-                foreach ($ticket_values as $field => $value) {
1322
-                    if ($field == 'TKT_qty') {
1323
-                        $existing_ticket->set_qty($value);
1324
-                    } elseif ($field == 'TKT_price') {
1325
-                        $existing_ticket->set('TKT_price', $ticket_price);
1326
-                    } else {
1327
-                        $existing_ticket->set($field, $value);
1328
-                    }
1329
-                }
1330
-                $ticket = $existing_ticket;
1331
-                // if $create_new_ticket is false then we can safely update the existing ticket.
1332
-                //  Otherwise we have to create a new ticket.
1333
-                if ($create_new_ticket) {
1334
-                    // archive the old ticket first
1335
-                    $existing_ticket->set('TKT_deleted', 1);
1336
-                    $existing_ticket->save();
1337
-                    // make sure this ticket is still recorded in our $saved_tickets
1338
-                    // so we don't run it through the regular trash routine.
1339
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1340
-                    // create new ticket that's a copy of the existing except,
1341
-                    // (a new id of course and not archived) AND has the new TKT_price associated with it.
1342
-                    $new_ticket = clone $existing_ticket;
1343
-                    $new_ticket->set('TKT_ID', 0);
1344
-                    $new_ticket->set('TKT_deleted', 0);
1345
-                    $new_ticket->set('TKT_sold', 0);
1346
-                    // now we need to make sure that $new prices are created as well and attached to new ticket.
1347
-                    $update_prices = true;
1348
-                    $ticket        = $new_ticket;
1349
-                }
1350
-            } else {
1351
-                // no TKT_id so a new ticket
1352
-                $ticket_values['TKT_price'] = $ticket_price;
1353
-                $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1354
-                $update_prices              = true;
1355
-            }
1356
-            if (! $ticket instanceof EE_Ticket) {
1357
-                throw new RuntimeException(
1358
-                    sprintf(
1359
-                        esc_html__(
1360
-                            'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1361
-                            'event_espresso'
1362
-                        ),
1363
-                        print_r($ticket_values, true)
1364
-                    )
1365
-                );
1366
-            }
1367
-            // cap ticket qty by datetime reg limits
1368
-            $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1369
-            // update ticket.
1370
-            $ticket->save();
1371
-            // before going any further make sure our dates are setup correctly
1372
-            // so that the end date is always equal or greater than the start date.
1373
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1374
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1375
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1376
-                $ticket->save();
1377
-            }
1378
-            // initially let's add the ticket to the datetime
1379
-            $datetime->_add_relation_to($ticket, 'Ticket');
1380
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1381
-            // add prices to ticket
1382
-            $prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1383
-                ? $data['edit_prices'][ $row ]
1384
-                : [];
1385
-            $this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1386
-        }
1387
-        // however now we need to handle permanently deleting tickets via the ui.
1388
-        // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1389
-        // However, it does allow for deleting tickets that have no tickets sold,
1390
-        // in which case we want to get rid of permanently because there is no need to save in db.
1391
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? [] : $old_tickets;
1392
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1393
-        foreach ($tickets_removed as $id) {
1394
-            $id = absint($id);
1395
-            // get the ticket for this id
1396
-            $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1397
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1398
-                continue;
1399
-            }
1400
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1401
-            // (remember this process can ONLY kick off if there are NO tickets sold)
1402
-            $related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1403
-            foreach ($related_datetimes as $related_datetime) {
1404
-                $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1405
-            }
1406
-            // need to do the same for prices (except these prices can also be deleted because again,
1407
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1408
-            $ticket_to_remove->delete_related_permanently('Price');
1409
-            // finally let's delete this ticket
1410
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1411
-            $ticket_to_remove->delete_permanently();
1412
-        }
1413
-        return [$datetime, $saved_tickets];
1414
-    }
1415
-
1416
-
1417
-    /**
1418
-     * This attaches a list of given prices to a ticket.
1419
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1420
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1421
-     * price info and prices are automatically "archived" via the ticket.
1422
-     *
1423
-     * @access  private
1424
-     * @param array     $prices_data Array of prices from the form.
1425
-     * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1426
-     * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1427
-     * @return  void
1428
-     * @throws EE_Error
1429
-     * @throws ReflectionException
1430
-     */
1431
-    private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1432
-    {
1433
-        $timezone = $ticket->get_timezone();
1434
-        foreach ($prices_data as $row => $price_data) {
1435
-            $price_values = [
1436
-                'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1437
-                'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1438
-                'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1439
-                'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1440
-                'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1441
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1442
-                'PRC_order'      => $row,
1443
-            ];
1444
-            if ($new_prices || empty($price_values['PRC_ID'])) {
1445
-                $price_values['PRC_ID'] = 0;
1446
-                $price                  = EE_Price::new_instance($price_values, $timezone);
1447
-            } else {
1448
-                $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1449
-                // update this price with new values
1450
-                foreach ($price_values as $field => $new_price) {
1451
-                    $price->set($field, $new_price);
1452
-                }
1453
-            }
1454
-            if (! $price instanceof EE_Price) {
1455
-                throw new RuntimeException(
1456
-                    sprintf(
1457
-                        esc_html__(
1458
-                            'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1459
-                            'event_espresso'
1460
-                        ),
1461
-                        print_r($price_values, true)
1462
-                    )
1463
-                );
1464
-            }
1465
-            $price->save();
1466
-            $ticket->_add_relation_to($price, 'Price');
1467
-        }
1468
-    }
1469
-
1470
-
1471
-    /**
1472
-     * Add in our autosave ajax handlers
1473
-     *
1474
-     */
1475
-    protected function _ee_autosave_create_new()
1476
-    {
1477
-    }
1478
-
1479
-
1480
-    /**
1481
-     * More autosave handlers.
1482
-     */
1483
-    protected function _ee_autosave_edit()
1484
-    {
1485
-        // TEMPORARILY EXITING CAUSE THIS IS A TODO
1486
-    }
1487
-
1488
-
1489
-    /**
1490
-     * @throws EE_Error
1491
-     * @throws ReflectionException
1492
-     */
1493
-    private function _generate_publish_box_extra_content()
1494
-    {
1495
-        // load formatter helper
1496
-        // args for getting related registrations
1497
-        $approved_query_args        = [
1498
-            [
1499
-                'REG_deleted' => 0,
1500
-                'STS_ID'      => EEM_Registration::status_id_approved,
1501
-            ],
1502
-        ];
1503
-        $not_approved_query_args    = [
1504
-            [
1505
-                'REG_deleted' => 0,
1506
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1507
-            ],
1508
-        ];
1509
-        $pending_payment_query_args = [
1510
-            [
1511
-                'REG_deleted' => 0,
1512
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1513
-            ],
1514
-        ];
1515
-        // publish box
1516
-        $publish_box_extra_args = [
1517
-            'view_approved_reg_url'        => add_query_arg(
1518
-                [
1519
-                    'action'      => 'default',
1520
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1521
-                    '_reg_status' => EEM_Registration::status_id_approved,
1522
-                    'use_filters' => true,
1523
-                ],
1524
-                REG_ADMIN_URL
1525
-            ),
1526
-            'view_not_approved_reg_url'    => add_query_arg(
1527
-                [
1528
-                    'action'      => 'default',
1529
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1530
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1531
-                    'use_filters' => true,
1532
-                ],
1533
-                REG_ADMIN_URL
1534
-            ),
1535
-            'view_pending_payment_reg_url' => add_query_arg(
1536
-                [
1537
-                    'action'      => 'default',
1538
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1539
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1540
-                    'use_filters' => true,
1541
-                ],
1542
-                REG_ADMIN_URL
1543
-            ),
1544
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1545
-                'Registration',
1546
-                $approved_query_args
1547
-            ),
1548
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1549
-                'Registration',
1550
-                $not_approved_query_args
1551
-            ),
1552
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1553
-                'Registration',
1554
-                $pending_payment_query_args
1555
-            ),
1556
-            'misc_pub_section_class'       => apply_filters(
1557
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1558
-                'misc-pub-section'
1559
-            ),
1560
-        ];
1561
-        ob_start();
1562
-        do_action(
1563
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1564
-            $this->_cpt_model_obj
1565
-        );
1566
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1567
-        // load template
1568
-        EEH_Template::display_template(
1569
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1570
-            $publish_box_extra_args
1571
-        );
1572
-    }
1573
-
1574
-
1575
-    /**
1576
-     * @return EE_Event
1577
-     */
1578
-    public function get_event_object()
1579
-    {
1580
-        return $this->_cpt_model_obj;
1581
-    }
1582
-
1583
-
1584
-
1585
-
1586
-    /** METABOXES * */
1587
-    /**
1588
-     * _register_event_editor_meta_boxes
1589
-     * add all metaboxes related to the event_editor
1590
-     *
1591
-     * @return void
1592
-     * @throws EE_Error
1593
-     * @throws ReflectionException
1594
-     */
1595
-    protected function _register_event_editor_meta_boxes()
1596
-    {
1597
-        $this->verify_cpt_object();
1598
-        add_meta_box(
1599
-            'espresso_event_editor_tickets',
1600
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1601
-            [$this, 'ticket_metabox'],
1602
-            $this->page_slug,
1603
-            'normal',
1604
-            'high'
1605
-        );
1606
-        add_meta_box(
1607
-            'espresso_event_editor_event_options',
1608
-            esc_html__('Event Registration Options', 'event_espresso'),
1609
-            [$this, 'registration_options_meta_box'],
1610
-            $this->page_slug,
1611
-            'side'
1612
-        );
1613
-        // NOTE: if you're looking for other metaboxes in here,
1614
-        // where a metabox has a related management page in the admin
1615
-        // you will find it setup in the related management page's "_Hooks" file.
1616
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1617
-    }
1618
-
1619
-
1620
-    /**
1621
-     * @throws DomainException
1622
-     * @throws EE_Error
1623
-     * @throws ReflectionException
1624
-     */
1625
-    public function ticket_metabox()
1626
-    {
1627
-        $existing_datetime_ids = $existing_ticket_ids = [];
1628
-        // defaults for template args
1629
-        $template_args = [
1630
-            'existing_datetime_ids'    => '',
1631
-            'event_datetime_help_link' => '',
1632
-            'ticket_options_help_link' => '',
1633
-            'time'                     => null,
1634
-            'ticket_rows'              => '',
1635
-            'existing_ticket_ids'      => '',
1636
-            'total_ticket_rows'        => 1,
1637
-            'ticket_js_structure'      => '',
1638
-            'trash_icon'               => 'ee-lock-icon',
1639
-            'disabled'                 => '',
1640
-        ];
1641
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1642
-        /**
1643
-         * 1. Start with retrieving Datetimes
1644
-         * 2. Fore each datetime get related tickets
1645
-         * 3. For each ticket get related prices
1646
-         */
1647
-        $times          = EEM_Datetime::instance()->get_all_event_dates($event_id);
1648
-        $first_datetime = reset($times);
1649
-        // do we get related tickets?
1650
-        if (
1651
-            $first_datetime instanceof EE_Datetime
1652
-            && $first_datetime->ID() !== 0
1653
-        ) {
1654
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1655
-            $template_args['time']   = $first_datetime;
1656
-            $related_tickets         = $first_datetime->tickets(
1657
-                [
1658
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1659
-                    'default_where_conditions' => 'none',
1660
-                ]
1661
-            );
1662
-            if (! empty($related_tickets)) {
1663
-                $template_args['total_ticket_rows'] = count($related_tickets);
1664
-                $row                                = 0;
1665
-                foreach ($related_tickets as $ticket) {
1666
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1667
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1668
-                    $row++;
1669
-                }
1670
-            } else {
1671
-                $template_args['total_ticket_rows'] = 1;
1672
-                /** @type EE_Ticket $ticket */
1673
-                $ticket                       = EEM_Ticket::instance()->create_default_object();
1674
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1675
-            }
1676
-        } else {
1677
-            $template_args['time']        = $times[0];
1678
-            $tickets                      = EEM_Ticket::instance()->get_all_default_tickets();
1679
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1680
-            // NOTE: we're just sending the first default row
1681
-            // (decaf can't manage default tickets so this should be sufficient);
1682
-        }
1683
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1684
-            'event_editor_event_datetimes_help_tab'
1685
-        );
1686
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1687
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1688
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1689
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1690
-            EEM_Ticket::instance()->create_default_object(),
1691
-            true
1692
-        );
1693
-        $template                                  = apply_filters(
1694
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1695
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1696
-        );
1697
-        EEH_Template::display_template($template, $template_args);
1698
-    }
1699
-
1700
-
1701
-    /**
1702
-     * Setup an individual ticket form for the decaf event editor page
1703
-     *
1704
-     * @access private
1705
-     * @param EE_Ticket $ticket   the ticket object
1706
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1707
-     * @param int       $row
1708
-     * @return string generated html for the ticket row.
1709
-     * @throws EE_Error
1710
-     * @throws ReflectionException
1711
-     */
1712
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1713
-    {
1714
-        $template_args = [
1715
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1716
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1717
-                : '',
1718
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1719
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1720
-            'TKT_name'            => $ticket->get('TKT_name'),
1721
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1722
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1723
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1724
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1725
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1726
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1727
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1728
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1729
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1730
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1731
-                : ' disabled=disabled',
1732
-        ];
1733
-        $price         = $ticket->ID() !== 0
1734
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1735
-            : null;
1736
-        $price         = $price instanceof EE_Price
1737
-            ? $price
1738
-            : EEM_Price::instance()->create_default_object();
1739
-        $price_args    = [
1740
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1741
-            'PRC_amount'            => $price->get('PRC_amount'),
1742
-            'PRT_ID'                => $price->get('PRT_ID'),
1743
-            'PRC_ID'                => $price->get('PRC_ID'),
1744
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1745
-        ];
1746
-        // make sure we have default start and end dates if skeleton
1747
-        // handle rows that should NOT be empty
1748
-        if (empty($template_args['TKT_start_date'])) {
1749
-            // if empty then the start date will be now.
1750
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1751
-        }
1752
-        if (empty($template_args['TKT_end_date'])) {
1753
-            // get the earliest datetime (if present);
1754
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1755
-                ? $this->_cpt_model_obj->get_first_related(
1756
-                    'Datetime',
1757
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1758
-                )
1759
-                : null;
1760
-            $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1761
-                ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1762
-                : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1763
-        }
1764
-        $template_args = array_merge($template_args, $price_args);
1765
-        $template      = apply_filters(
1766
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1767
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1768
-            $ticket
1769
-        );
1770
-        return EEH_Template::display_template($template, $template_args, true);
1771
-    }
1772
-
1773
-
1774
-    /**
1775
-     * @throws EE_Error
1776
-     * @throws ReflectionException
1777
-     */
1778
-    public function registration_options_meta_box()
1779
-    {
1780
-        $yes_no_values             = [
1781
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1782
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1783
-        ];
1784
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1785
-            [
1786
-                EEM_Registration::status_id_cancelled,
1787
-                EEM_Registration::status_id_declined,
1788
-                EEM_Registration::status_id_incomplete,
1789
-            ],
1790
-            true
1791
-        );
1792
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1793
-        $template_args['_event']                          = $this->_cpt_model_obj;
1794
-        $template_args['event']                           = $this->_cpt_model_obj;
1795
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1796
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1797
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1798
-            'default_reg_status',
1799
-            $default_reg_status_values,
1800
-            $this->_cpt_model_obj->default_registration_status()
1801
-        );
1802
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1803
-            'display_desc',
1804
-            $yes_no_values,
1805
-            $this->_cpt_model_obj->display_description()
1806
-        );
1807
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1808
-            'display_ticket_selector',
1809
-            $yes_no_values,
1810
-            $this->_cpt_model_obj->display_ticket_selector(),
1811
-            '',
1812
-            '',
1813
-            false
1814
-        );
1815
-        $template_args['additional_registration_options'] = apply_filters(
1816
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1817
-            '',
1818
-            $template_args,
1819
-            $yes_no_values,
1820
-            $default_reg_status_values
1821
-        );
1822
-        EEH_Template::display_template(
1823
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1824
-            $template_args
1825
-        );
1826
-    }
1827
-
1828
-
1829
-    /**
1830
-     * _get_events()
1831
-     * This method simply returns all the events (for the given _view and paging)
1832
-     *
1833
-     * @access public
1834
-     * @param int  $per_page     count of items per page (20 default);
1835
-     * @param int  $current_page what is the current page being viewed.
1836
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1837
-     *                           If FALSE then we return an array of event objects
1838
-     *                           that match the given _view and paging parameters.
1839
-     * @return array|int         an array of event objects or a count of them.
1840
-     * @throws Exception
1841
-     */
1842
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1843
-    {
1844
-        $EEM_Event   = $this->_event_model();
1845
-        $offset      = ($current_page - 1) * $per_page;
1846
-        $limit       = $count ? null : $offset . ',' . $per_page;
1847
-        $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1848
-        $order       = $this->request->getRequestParam('order', 'DESC');
1849
-        $month_range = $this->request->getRequestParam('month_range');
1850
-        if ($month_range) {
1851
-            $pieces = explode(' ', $month_range, 3);
1852
-            // simulate the FIRST day of the month, that fixes issues for months like February
1853
-            // where PHP doesn't know what to assume for date.
1854
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1855
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1856
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1857
-        }
1858
-        $where  = [];
1859
-        $status = $this->request->getRequestParam('status');
1860
-        // determine what post_status our condition will have for the query.
1861
-        switch ($status) {
1862
-            case 'month':
1863
-            case 'today':
1864
-            case null:
1865
-            case 'all':
1866
-                break;
1867
-            case 'draft':
1868
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1869
-                break;
1870
-            default:
1871
-                $where['status'] = $status;
1872
-        }
1873
-        // categories? The default for all categories is -1
1874
-        $category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1875
-        if ($category !== -1) {
1876
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1877
-            $where['Term_Taxonomy.term_id']  = $category;
1878
-        }
1879
-        // date where conditions
1880
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1881
-        if ($month_range) {
1882
-            $DateTime = new DateTime(
1883
-                $year_r . '-' . $month_r . '-01 00:00:00',
1884
-                new DateTimeZone('UTC')
1885
-            );
1886
-            $start    = $DateTime->getTimestamp();
1887
-            // set the datetime to be the end of the month
1888
-            $DateTime->setDate(
1889
-                $year_r,
1890
-                $month_r,
1891
-                $DateTime->format('t')
1892
-            )->setTime(23, 59, 59);
1893
-            $end                             = $DateTime->getTimestamp();
1894
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1895
-        } elseif ($status === 'today') {
1896
-            $DateTime                        =
1897
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1898
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1899
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1900
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1901
-        } elseif ($status === 'month') {
1902
-            $now                             = date('Y-m-01');
1903
-            $DateTime                        =
1904
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1905
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1906
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1907
-                                                        ->setTime(23, 59, 59)
1908
-                                                        ->format(implode(' ', $start_formats));
1909
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1910
-        }
1911
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1912
-            $where['EVT_wp_user'] = get_current_user_id();
1913
-        } else {
1914
-            if (! isset($where['status'])) {
1915
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1916
-                    $where['OR'] = [
1917
-                        'status*restrict_private' => ['!=', 'private'],
1918
-                        'AND'                     => [
1919
-                            'status*inclusive' => ['=', 'private'],
1920
-                            'EVT_wp_user'      => get_current_user_id(),
1921
-                        ],
1922
-                    ];
1923
-                }
1924
-            }
1925
-        }
1926
-        $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1927
-        if (
1928
-            $wp_user
1929
-            && $wp_user !== get_current_user_id()
1930
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1931
-        ) {
1932
-            $where['EVT_wp_user'] = $wp_user;
1933
-        }
1934
-        // search query handling
1935
-        $search_term = $this->request->getRequestParam('s');
1936
-        if ($search_term) {
1937
-            $search_term = '%' . $search_term . '%';
1938
-            $where['OR'] = [
1939
-                'EVT_name'       => ['LIKE', $search_term],
1940
-                'EVT_desc'       => ['LIKE', $search_term],
1941
-                'EVT_short_desc' => ['LIKE', $search_term],
1942
-            ];
1943
-        }
1944
-        // filter events by venue.
1945
-        $venue = $this->request->getRequestParam('venue', 0, 'int');
1946
-        if ($venue) {
1947
-            $where['Venue.VNU_ID'] = $venue;
1948
-        }
1949
-        $request_params = $this->request->requestParams();
1950
-        $where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
1951
-        $query_params   = apply_filters(
1952
-            'FHEE__Events_Admin_Page__get_events__query_params',
1953
-            [
1954
-                $where,
1955
-                'limit'    => $limit,
1956
-                'order_by' => $orderby,
1957
-                'order'    => $order,
1958
-                'group_by' => 'EVT_ID',
1959
-            ],
1960
-            $request_params
1961
-        );
1962
-
1963
-        // let's first check if we have special requests coming in.
1964
-        $active_status = $this->request->getRequestParam('active_status');
1965
-        if ($active_status) {
1966
-            switch ($active_status) {
1967
-                case 'upcoming':
1968
-                    return $EEM_Event->get_upcoming_events($query_params, $count);
1969
-                case 'expired':
1970
-                    return $EEM_Event->get_expired_events($query_params, $count);
1971
-                case 'active':
1972
-                    return $EEM_Event->get_active_events($query_params, $count);
1973
-                case 'inactive':
1974
-                    return $EEM_Event->get_inactive_events($query_params, $count);
1975
-            }
1976
-        }
1977
-
1978
-        return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
1979
-    }
1980
-
1981
-
1982
-    /**
1983
-     * handling for WordPress CPT actions (trash, restore, delete)
1984
-     *
1985
-     * @param string $post_id
1986
-     * @throws EE_Error
1987
-     * @throws ReflectionException
1988
-     */
1989
-    public function trash_cpt_item($post_id)
1990
-    {
1991
-        $this->request->setRequestParam('EVT_ID', $post_id);
1992
-        $this->_trash_or_restore_event('trash', false);
1993
-    }
1994
-
1995
-
1996
-    /**
1997
-     * @param string $post_id
1998
-     * @throws EE_Error
1999
-     * @throws ReflectionException
2000
-     */
2001
-    public function restore_cpt_item($post_id)
2002
-    {
2003
-        $this->request->setRequestParam('EVT_ID', $post_id);
2004
-        $this->_trash_or_restore_event('draft', false);
2005
-    }
2006
-
2007
-
2008
-    /**
2009
-     * @param string $post_id
2010
-     * @throws EE_Error
2011
-     * @throws EE_Error
2012
-     */
2013
-    public function delete_cpt_item($post_id)
2014
-    {
2015
-        throw new EE_Error(
2016
-            esc_html__(
2017
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2018
-                'event_espresso'
2019
-            )
2020
-        );
2021
-        // $this->request->setRequestParam('EVT_ID', $post_id);
2022
-        // $this->_delete_event();
2023
-    }
2024
-
2025
-
2026
-    /**
2027
-     * _trash_or_restore_event
2028
-     *
2029
-     * @access protected
2030
-     * @param string $event_status
2031
-     * @param bool   $redirect_after
2032
-     * @throws EE_Error
2033
-     * @throws EE_Error
2034
-     * @throws ReflectionException
2035
-     */
2036
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2037
-    {
2038
-        // determine the event id and set to array.
2039
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2040
-        // loop thru events
2041
-        if ($EVT_ID) {
2042
-            // clean status
2043
-            $event_status = sanitize_key($event_status);
2044
-            // grab status
2045
-            if (! empty($event_status)) {
2046
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2047
-            } else {
2048
-                $success = false;
2049
-                $msg     = esc_html__(
2050
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2051
-                    'event_espresso'
2052
-                );
2053
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2054
-            }
2055
-        } else {
2056
-            $success = false;
2057
-            $msg     = esc_html__(
2058
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2059
-                'event_espresso'
2060
-            );
2061
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2062
-        }
2063
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2064
-        if ($redirect_after) {
2065
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2066
-        }
2067
-    }
2068
-
2069
-
2070
-    /**
2071
-     * _trash_or_restore_events
2072
-     *
2073
-     * @access protected
2074
-     * @param string $event_status
2075
-     * @return void
2076
-     * @throws EE_Error
2077
-     * @throws EE_Error
2078
-     * @throws ReflectionException
2079
-     */
2080
-    protected function _trash_or_restore_events($event_status = 'trash')
2081
-    {
2082
-        // clean status
2083
-        $event_status = sanitize_key($event_status);
2084
-        // grab status
2085
-        if (! empty($event_status)) {
2086
-            $success = true;
2087
-            // determine the event id and set to array.
2088
-            $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2089
-            // loop thru events
2090
-            foreach ($EVT_IDs as $EVT_ID) {
2091
-                if ($EVT_ID = absint($EVT_ID)) {
2092
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2093
-                    $success = $results !== false ? $success : false;
2094
-                } else {
2095
-                    $msg = sprintf(
2096
-                        esc_html__(
2097
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2098
-                            'event_espresso'
2099
-                        ),
2100
-                        $EVT_ID
2101
-                    );
2102
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2103
-                    $success = false;
2104
-                }
2105
-            }
2106
-        } else {
2107
-            $success = false;
2108
-            $msg     = esc_html__(
2109
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2110
-                'event_espresso'
2111
-            );
2112
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2113
-        }
2114
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2115
-        $success = $success ? 2 : false;
2116
-        $action  = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2117
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2118
-    }
2119
-
2120
-
2121
-    /**
2122
-     * @param int    $EVT_ID
2123
-     * @param string $event_status
2124
-     * @return bool
2125
-     * @throws EE_Error
2126
-     * @throws ReflectionException
2127
-     */
2128
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2129
-    {
2130
-        // grab event id
2131
-        if (! $EVT_ID) {
2132
-            $msg = esc_html__(
2133
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2134
-                'event_espresso'
2135
-            );
2136
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2137
-            return false;
2138
-        }
2139
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2140
-        // clean status
2141
-        $event_status = sanitize_key($event_status);
2142
-        // grab status
2143
-        if (empty($event_status)) {
2144
-            $msg = esc_html__(
2145
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2146
-                'event_espresso'
2147
-            );
2148
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2149
-            return false;
2150
-        }
2151
-        // was event trashed or restored ?
2152
-        switch ($event_status) {
2153
-            case 'draft':
2154
-                $action = 'restored from the trash';
2155
-                $hook   = 'AHEE_event_restored_from_trash';
2156
-                break;
2157
-            case 'trash':
2158
-                $action = 'moved to the trash';
2159
-                $hook   = 'AHEE_event_moved_to_trash';
2160
-                break;
2161
-            default:
2162
-                $action = 'updated';
2163
-                $hook   = false;
2164
-        }
2165
-        // use class to change status
2166
-        $this->_cpt_model_obj->set_status($event_status);
2167
-        $success = $this->_cpt_model_obj->save();
2168
-        if (! $success) {
2169
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2170
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2171
-            return false;
2172
-        }
2173
-        if ($hook) {
2174
-            do_action($hook);
2175
-        }
2176
-        return true;
2177
-    }
2178
-
2179
-
2180
-    /**
2181
-     * @param array $event_ids
2182
-     * @return array
2183
-     * @since   4.10.23.p
2184
-     */
2185
-    private function cleanEventIds(array $event_ids)
2186
-    {
2187
-        return array_map('absint', $event_ids);
2188
-    }
2189
-
2190
-
2191
-    /**
2192
-     * @return array
2193
-     * @since   4.10.23.p
2194
-     */
2195
-    private function getEventIdsFromRequest()
2196
-    {
2197
-        if ($this->request->requestParamIsSet('EVT_IDs')) {
2198
-            return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2199
-        } else {
2200
-            return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2201
-        }
2202
-    }
2203
-
2204
-
2205
-    /**
2206
-     * @param bool $preview_delete
2207
-     * @throws EE_Error
2208
-     */
2209
-    protected function _delete_event($preview_delete = true)
2210
-    {
2211
-        $this->_delete_events($preview_delete);
2212
-    }
2213
-
2214
-
2215
-    /**
2216
-     * Gets the tree traversal batch persister.
2217
-     *
2218
-     * @return NodeGroupDao
2219
-     * @throws InvalidArgumentException
2220
-     * @throws InvalidDataTypeException
2221
-     * @throws InvalidInterfaceException
2222
-     * @since 4.10.12.p
2223
-     */
2224
-    protected function getModelObjNodeGroupPersister()
2225
-    {
2226
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2227
-            $this->model_obj_node_group_persister =
2228
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2229
-        }
2230
-        return $this->model_obj_node_group_persister;
2231
-    }
2232
-
2233
-
2234
-    /**
2235
-     * @param bool $preview_delete
2236
-     * @return void
2237
-     * @throws EE_Error
2238
-     */
2239
-    protected function _delete_events($preview_delete = true)
2240
-    {
2241
-        $event_ids = $this->getEventIdsFromRequest();
2242
-        if ($preview_delete) {
2243
-            $this->generateDeletionPreview($event_ids);
2244
-        } else {
2245
-            EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2246
-        }
2247
-    }
2248
-
2249
-
2250
-    /**
2251
-     * @param array $event_ids
2252
-     */
2253
-    protected function generateDeletionPreview(array $event_ids)
2254
-    {
2255
-        $event_ids = $this->cleanEventIds($event_ids);
2256
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2257
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2258
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2259
-            [
2260
-                'action'            => 'preview_deletion',
2261
-                'deletion_job_code' => $deletion_job_code,
2262
-            ],
2263
-            $this->_admin_base_url
2264
-        );
2265
-        EEH_URL::safeRedirectAndExit(
2266
-            EE_Admin_Page::add_query_args_and_nonce(
2267
-                [
2268
-                    'page'              => 'espresso_batch',
2269
-                    'batch'             => EED_Batch::batch_job,
2270
-                    'EVT_IDs'           => $event_ids,
2271
-                    'deletion_job_code' => $deletion_job_code,
2272
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2273
-                    'return_url'        => urlencode($return_url),
2274
-                ],
2275
-                admin_url()
2276
-            )
2277
-        );
2278
-    }
2279
-
2280
-
2281
-    /**
2282
-     * Checks for a POST submission
2283
-     *
2284
-     * @since 4.10.12.p
2285
-     */
2286
-    protected function confirmDeletion()
2287
-    {
2288
-        $deletion_redirect_logic =
2289
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2290
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2291
-    }
2292
-
2293
-
2294
-    /**
2295
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2296
-     *
2297
-     * @throws EE_Error
2298
-     * @since 4.10.12.p
2299
-     */
2300
-    protected function previewDeletion()
2301
-    {
2302
-        $preview_deletion_logic =
2303
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2304
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2305
-        $this->display_admin_page_with_no_sidebar();
2306
-    }
2307
-
2308
-
2309
-    /**
2310
-     * get total number of events
2311
-     *
2312
-     * @access public
2313
-     * @return int
2314
-     * @throws EE_Error
2315
-     * @throws EE_Error
2316
-     */
2317
-    public function total_events()
2318
-    {
2319
-        return EEM_Event::instance()->count(
2320
-            ['caps' => 'read_admin'],
2321
-            'EVT_ID',
2322
-            true
2323
-        );
2324
-    }
2325
-
2326
-
2327
-    /**
2328
-     * get total number of draft events
2329
-     *
2330
-     * @access public
2331
-     * @return int
2332
-     * @throws EE_Error
2333
-     * @throws EE_Error
2334
-     */
2335
-    public function total_events_draft()
2336
-    {
2337
-        return EEM_Event::instance()->count(
2338
-            [
2339
-                ['status' => ['IN', ['draft', 'auto-draft']]],
2340
-                'caps' => 'read_admin',
2341
-            ],
2342
-            'EVT_ID',
2343
-            true
2344
-        );
2345
-    }
2346
-
2347
-
2348
-    /**
2349
-     * get total number of trashed events
2350
-     *
2351
-     * @access public
2352
-     * @return int
2353
-     * @throws EE_Error
2354
-     * @throws EE_Error
2355
-     */
2356
-    public function total_trashed_events()
2357
-    {
2358
-        return EEM_Event::instance()->count(
2359
-            [
2360
-                ['status' => 'trash'],
2361
-                'caps' => 'read_admin',
2362
-            ],
2363
-            'EVT_ID',
2364
-            true
2365
-        );
2366
-    }
2367
-
2368
-
2369
-    /**
2370
-     *    _default_event_settings
2371
-     *    This generates the Default Settings Tab
2372
-     *
2373
-     * @return void
2374
-     * @throws EE_Error
2375
-     */
2376
-    protected function _default_event_settings()
2377
-    {
2378
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2379
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2380
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2381
-        $this->display_admin_page_with_sidebar();
2382
-    }
2383
-
2384
-
2385
-    /**
2386
-     * Return the form for event settings.
2387
-     *
2388
-     * @return EE_Form_Section_Proper
2389
-     * @throws EE_Error
2390
-     */
2391
-    protected function _default_event_settings_form()
2392
-    {
2393
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2394
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2395
-        // exclude
2396
-            [
2397
-                EEM_Registration::status_id_cancelled,
2398
-                EEM_Registration::status_id_declined,
2399
-                EEM_Registration::status_id_incomplete,
2400
-                EEM_Registration::status_id_wait_list,
2401
-            ],
2402
-            true
2403
-        );
2404
-        return new EE_Form_Section_Proper(
2405
-            [
2406
-                'name'            => 'update_default_event_settings',
2407
-                'html_id'         => 'update_default_event_settings',
2408
-                'html_class'      => 'form-table',
2409
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2410
-                'subsections'     => apply_filters(
2411
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2412
-                    [
2413
-                        'default_reg_status'  => new EE_Select_Input(
2414
-                            $registration_stati_for_selection,
2415
-                            [
2416
-                                'default'         => isset($registration_config->default_STS_ID)
2417
-                                                     && array_key_exists(
2418
-                                                         $registration_config->default_STS_ID,
2419
-                                                         $registration_stati_for_selection
2420
-                                                     )
2421
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2422
-                                    : EEM_Registration::status_id_pending_payment,
2423
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2424
-                                                     . EEH_Template::get_help_tab_link(
2425
-                                                         'default_settings_status_help_tab'
2426
-                                                     ),
2427
-                                'html_help_text'  => esc_html__(
2428
-                                    '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.',
2429
-                                    'event_espresso'
2430
-                                ),
2431
-                            ]
2432
-                        ),
2433
-                        'default_max_tickets' => new EE_Integer_Input(
2434
-                            [
2435
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2436
-                                    ? $registration_config->default_maximum_number_of_tickets
2437
-                                    : EEM_Event::get_default_additional_limit(),
2438
-                                'html_label_text' => esc_html__(
2439
-                                    'Default Maximum Tickets Allowed Per Order:',
2440
-                                    'event_espresso'
2441
-                                )
2442
-                                . EEH_Template::get_help_tab_link(
2443
-                                    'default_maximum_tickets_help_tab"'
2444
-                                ),
2445
-                                'html_help_text'  => esc_html__(
2446
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2447
-                                    'event_espresso'
2448
-                                ),
2449
-                            ]
2450
-                        ),
2451
-                    ]
2452
-                ),
2453
-            ]
2454
-        );
2455
-    }
2456
-
2457
-
2458
-    /**
2459
-     * _update_default_event_settings
2460
-     *
2461
-     * @access protected
2462
-     * @return void
2463
-     * @throws EE_Error
2464
-     */
2465
-    protected function _update_default_event_settings()
2466
-    {
2467
-        $registration_config = EE_Registry::instance()->CFG->registration;
2468
-        $form                = $this->_default_event_settings_form();
2469
-        if ($form->was_submitted()) {
2470
-            $form->receive_form_submission();
2471
-            if ($form->is_valid()) {
2472
-                $valid_data = $form->valid_data();
2473
-                if (isset($valid_data['default_reg_status'])) {
2474
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2475
-                }
2476
-                if (isset($valid_data['default_max_tickets'])) {
2477
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2478
-                }
2479
-                // update because data was valid!
2480
-                EE_Registry::instance()->CFG->update_espresso_config();
2481
-                EE_Error::overwrite_success();
2482
-                EE_Error::add_success(
2483
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2484
-                );
2485
-            }
2486
-        }
2487
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2488
-    }
2489
-
2490
-
2491
-    /*************        Templates        *************
2492
-     *
2493
-     * @throws EE_Error
2494
-     */
2495
-    protected function _template_settings()
2496
-    {
2497
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2498
-        $this->_template_args['preview_img']  = '<img src="'
2499
-                                                . EVENTS_ASSETS_URL
2500
-                                                . '/images/'
2501
-                                                . 'caffeinated_template_features.jpg" alt="'
2502
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2503
-                                                . '" />';
2504
-        $this->_template_args['preview_text'] = '<strong>'
2505
-                                                . esc_html__(
2506
-                                                    '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.',
2507
-                                                    'event_espresso'
2508
-                                                ) . '</strong>';
2509
-        $this->display_admin_caf_preview_page('template_settings_tab');
2510
-    }
2511
-
2512
-
2513
-    /** Event Category Stuff **/
2514
-    /**
2515
-     * set the _category property with the category object for the loaded page.
2516
-     *
2517
-     * @access private
2518
-     * @return void
2519
-     */
2520
-    private function _set_category_object()
2521
-    {
2522
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2523
-            return;
2524
-        } //already have the category object so get out.
2525
-        // set default category object
2526
-        $this->_set_empty_category_object();
2527
-        // only set if we've got an id
2528
-        $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2529
-        if (! $category_ID) {
2530
-            return;
2531
-        }
2532
-        $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2533
-        if (! empty($term)) {
2534
-            $this->_category->category_name       = $term->name;
2535
-            $this->_category->category_identifier = $term->slug;
2536
-            $this->_category->category_desc       = $term->description;
2537
-            $this->_category->id                  = $term->term_id;
2538
-            $this->_category->parent              = $term->parent;
2539
-        }
2540
-    }
2541
-
2542
-
2543
-    /**
2544
-     * Clears out category properties.
2545
-     */
2546
-    private function _set_empty_category_object()
2547
-    {
2548
-        $this->_category                = new stdClass();
2549
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2550
-        $this->_category->id            = $this->_category->parent = 0;
2551
-    }
2552
-
2553
-
2554
-    /**
2555
-     * @throws EE_Error
2556
-     */
2557
-    protected function _category_list_table()
2558
-    {
2559
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2560
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2561
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2562
-            'add_category',
2563
-            'add_category',
2564
-            [],
2565
-            'add-new-h2'
2566
-        );
2567
-        $this->display_admin_list_table_page_with_sidebar();
2568
-    }
2569
-
2570
-
2571
-    /**
2572
-     * Output category details view.
2573
-     *
2574
-     * @throws EE_Error
2575
-     * @throws EE_Error
2576
-     */
2577
-    protected function _category_details($view)
2578
-    {
2579
-        // load formatter helper
2580
-        // load field generator helper
2581
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2582
-        $this->_set_add_edit_form_tags($route);
2583
-        $this->_set_category_object();
2584
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2585
-        $delete_action = 'delete_category';
2586
-        // custom redirect
2587
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2588
-            ['action' => 'category_list'],
2589
-            $this->_admin_base_url
2590
-        );
2591
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2592
-        // take care of contents
2593
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2594
-        $this->display_admin_page_with_sidebar();
2595
-    }
2596
-
2597
-
2598
-    /**
2599
-     * Output category details content.
2600
-     */
2601
-    protected function _category_details_content()
2602
-    {
2603
-        $editor_args['category_desc'] = [
2604
-            'type'          => 'wp_editor',
2605
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2606
-            'class'         => 'my_editor_custom',
2607
-            'wpeditor_args' => ['media_buttons' => false],
2608
-        ];
2609
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2610
-        $all_terms                    = get_terms(
2611
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2612
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2613
-        );
2614
-        // setup category select for term parents.
2615
-        $category_select_values[] = [
2616
-            'text' => esc_html__('No Parent', 'event_espresso'),
2617
-            'id'   => 0,
2618
-        ];
2619
-        foreach ($all_terms as $term) {
2620
-            $category_select_values[] = [
2621
-                'text' => $term->name,
2622
-                'id'   => $term->term_id,
2623
-            ];
2624
-        }
2625
-        $category_select = EEH_Form_Fields::select_input(
2626
-            'category_parent',
2627
-            $category_select_values,
2628
-            $this->_category->parent
2629
-        );
2630
-        $template_args   = [
2631
-            'category'                 => $this->_category,
2632
-            'category_select'          => $category_select,
2633
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2634
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2635
-            'disable'                  => '',
2636
-            'disabled_message'         => false,
2637
-        ];
2638
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2639
-        return EEH_Template::display_template($template, $template_args, true);
2640
-    }
2641
-
2642
-
2643
-    /**
2644
-     * Handles deleting categories.
2645
-     *
2646
-     * @throws EE_Error
2647
-     */
2648
-    protected function _delete_categories()
2649
-    {
2650
-        $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2651
-        foreach ($category_IDs as $category_ID) {
2652
-            $this->_delete_category($category_ID);
2653
-        }
2654
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2655
-        $query_args = [
2656
-            'action' => 'category_list',
2657
-        ];
2658
-        $this->_redirect_after_action(0, '', '', $query_args);
2659
-    }
2660
-
2661
-
2662
-    /**
2663
-     * Handles deleting specific category.
2664
-     *
2665
-     * @param int $cat_id
2666
-     */
2667
-    protected function _delete_category($cat_id)
2668
-    {
2669
-        $cat_id = absint($cat_id);
2670
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2671
-    }
2672
-
2673
-
2674
-    /**
2675
-     * Handles triggering the update or insertion of a new category.
2676
-     *
2677
-     * @param bool $new_category true means we're triggering the insert of a new category.
2678
-     * @throws EE_Error
2679
-     * @throws EE_Error
2680
-     */
2681
-    protected function _insert_or_update_category($new_category)
2682
-    {
2683
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2684
-        $success = 0; // we already have a success message so lets not send another.
2685
-        if ($cat_id) {
2686
-            $query_args = [
2687
-                'action'     => 'edit_category',
2688
-                'EVT_CAT_ID' => $cat_id,
2689
-            ];
2690
-        } else {
2691
-            $query_args = ['action' => 'add_category'];
2692
-        }
2693
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2694
-    }
2695
-
2696
-
2697
-    /**
2698
-     * Inserts or updates category
2699
-     *
2700
-     * @param bool $update (true indicates we're updating a category).
2701
-     * @return bool|mixed|string
2702
-     */
2703
-    private function _insert_category($update = false)
2704
-    {
2705
-        $category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2706
-        $category_name       = $this->request->getRequestParam('category_name', '');
2707
-        $category_desc       = $this->request->getRequestParam('category_desc', '');
2708
-        $category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2709
-        $category_identifier = $this->request->getRequestParam('category_identifier', '');
2710
-
2711
-        if (empty($category_name)) {
2712
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2713
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2714
-            return false;
2715
-        }
2716
-        $term_args = [
2717
-            'name'        => $category_name,
2718
-            'description' => $category_desc,
2719
-            'parent'      => $category_parent,
2720
-        ];
2721
-        // was the category_identifier input disabled?
2722
-        if ($category_identifier) {
2723
-            $term_args['slug'] = $category_identifier;
2724
-        }
2725
-        $insert_ids = $update
2726
-            ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2727
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2728
-        if (! is_array($insert_ids)) {
2729
-            $msg = esc_html__(
2730
-                'An error occurred and the category has not been saved to the database.',
2731
-                'event_espresso'
2732
-            );
2733
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2734
-        } else {
2735
-            $category_ID = $insert_ids['term_id'];
2736
-            $msg         =
2737
-                sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2738
-            EE_Error::add_success($msg);
2739
-        }
2740
-        return $category_ID;
2741
-    }
2742
-
2743
-
2744
-    /**
2745
-     * Gets categories or count of categories matching the arguments in the request.
2746
-     *
2747
-     * @param int  $per_page
2748
-     * @param int  $current_page
2749
-     * @param bool $count
2750
-     * @return EE_Term_Taxonomy[]|int
2751
-     * @throws EE_Error
2752
-     * @throws EE_Error
2753
-     */
2754
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2755
-    {
2756
-        // testing term stuff
2757
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2758
-        $order       = $this->request->getRequestParam('order', 'DESC');
2759
-        $limit       = ($current_page - 1) * $per_page;
2760
-        $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2761
-        $search_term = $this->request->getRequestParam('s');
2762
-        if ($search_term) {
2763
-            $search_term = '%' . $search_term . '%';
2764
-            $where['OR'] = [
2765
-                'Term.name'   => ['LIKE', $search_term],
2766
-                'description' => ['LIKE', $search_term],
2767
-            ];
2768
-        }
2769
-        $query_params = [
2770
-            $where,
2771
-            'order_by'   => [$orderby => $order],
2772
-            'limit'      => $limit . ',' . $per_page,
2773
-            'force_join' => ['Term'],
2774
-        ];
2775
-        return $count
2776
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2777
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2778
-    }
2779
-
2780
-    /* end category stuff */
2781
-    /**************/
2782
-
2783
-
2784
-    /**
2785
-     * Callback for the `ee_save_timezone_setting` ajax action.
2786
-     *
2787
-     * @throws EE_Error
2788
-     */
2789
-    public function saveTimezoneString()
2790
-    {
2791
-        $timezone_string = $this->request->getRequestParam('timezone_selected');
2792
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2793
-            EE_Error::add_error(
2794
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2795
-                __FILE__,
2796
-                __FUNCTION__,
2797
-                __LINE__
2798
-            );
2799
-            $this->_template_args['error'] = true;
2800
-            $this->_return_json();
2801
-        }
2802
-
2803
-        update_option('timezone_string', $timezone_string);
2804
-        EE_Error::add_success(
2805
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2806
-        );
2807
-        $this->_template_args['success'] = true;
2808
-        $this->_return_json(true, ['action' => 'create_new']);
2809
-    }
2810
-
2811
-
2812
-    /**
2813 2493
      * @throws EE_Error
2814
-     * @deprecated 4.10.25.p
2815 2494
      */
2816
-    public function save_timezonestring_setting()
2817
-    {
2818
-        $this->saveTimezoneString();
2819
-    }
2495
+	protected function _template_settings()
2496
+	{
2497
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2498
+		$this->_template_args['preview_img']  = '<img src="'
2499
+												. EVENTS_ASSETS_URL
2500
+												. '/images/'
2501
+												. 'caffeinated_template_features.jpg" alt="'
2502
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2503
+												. '" />';
2504
+		$this->_template_args['preview_text'] = '<strong>'
2505
+												. esc_html__(
2506
+													'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.',
2507
+													'event_espresso'
2508
+												) . '</strong>';
2509
+		$this->display_admin_caf_preview_page('template_settings_tab');
2510
+	}
2511
+
2512
+
2513
+	/** Event Category Stuff **/
2514
+	/**
2515
+	 * set the _category property with the category object for the loaded page.
2516
+	 *
2517
+	 * @access private
2518
+	 * @return void
2519
+	 */
2520
+	private function _set_category_object()
2521
+	{
2522
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2523
+			return;
2524
+		} //already have the category object so get out.
2525
+		// set default category object
2526
+		$this->_set_empty_category_object();
2527
+		// only set if we've got an id
2528
+		$category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2529
+		if (! $category_ID) {
2530
+			return;
2531
+		}
2532
+		$term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2533
+		if (! empty($term)) {
2534
+			$this->_category->category_name       = $term->name;
2535
+			$this->_category->category_identifier = $term->slug;
2536
+			$this->_category->category_desc       = $term->description;
2537
+			$this->_category->id                  = $term->term_id;
2538
+			$this->_category->parent              = $term->parent;
2539
+		}
2540
+	}
2541
+
2542
+
2543
+	/**
2544
+	 * Clears out category properties.
2545
+	 */
2546
+	private function _set_empty_category_object()
2547
+	{
2548
+		$this->_category                = new stdClass();
2549
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2550
+		$this->_category->id            = $this->_category->parent = 0;
2551
+	}
2552
+
2553
+
2554
+	/**
2555
+	 * @throws EE_Error
2556
+	 */
2557
+	protected function _category_list_table()
2558
+	{
2559
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2560
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2561
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2562
+			'add_category',
2563
+			'add_category',
2564
+			[],
2565
+			'add-new-h2'
2566
+		);
2567
+		$this->display_admin_list_table_page_with_sidebar();
2568
+	}
2569
+
2570
+
2571
+	/**
2572
+	 * Output category details view.
2573
+	 *
2574
+	 * @throws EE_Error
2575
+	 * @throws EE_Error
2576
+	 */
2577
+	protected function _category_details($view)
2578
+	{
2579
+		// load formatter helper
2580
+		// load field generator helper
2581
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2582
+		$this->_set_add_edit_form_tags($route);
2583
+		$this->_set_category_object();
2584
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2585
+		$delete_action = 'delete_category';
2586
+		// custom redirect
2587
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2588
+			['action' => 'category_list'],
2589
+			$this->_admin_base_url
2590
+		);
2591
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2592
+		// take care of contents
2593
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2594
+		$this->display_admin_page_with_sidebar();
2595
+	}
2596
+
2597
+
2598
+	/**
2599
+	 * Output category details content.
2600
+	 */
2601
+	protected function _category_details_content()
2602
+	{
2603
+		$editor_args['category_desc'] = [
2604
+			'type'          => 'wp_editor',
2605
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2606
+			'class'         => 'my_editor_custom',
2607
+			'wpeditor_args' => ['media_buttons' => false],
2608
+		];
2609
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2610
+		$all_terms                    = get_terms(
2611
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2612
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2613
+		);
2614
+		// setup category select for term parents.
2615
+		$category_select_values[] = [
2616
+			'text' => esc_html__('No Parent', 'event_espresso'),
2617
+			'id'   => 0,
2618
+		];
2619
+		foreach ($all_terms as $term) {
2620
+			$category_select_values[] = [
2621
+				'text' => $term->name,
2622
+				'id'   => $term->term_id,
2623
+			];
2624
+		}
2625
+		$category_select = EEH_Form_Fields::select_input(
2626
+			'category_parent',
2627
+			$category_select_values,
2628
+			$this->_category->parent
2629
+		);
2630
+		$template_args   = [
2631
+			'category'                 => $this->_category,
2632
+			'category_select'          => $category_select,
2633
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2634
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2635
+			'disable'                  => '',
2636
+			'disabled_message'         => false,
2637
+		];
2638
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2639
+		return EEH_Template::display_template($template, $template_args, true);
2640
+	}
2641
+
2642
+
2643
+	/**
2644
+	 * Handles deleting categories.
2645
+	 *
2646
+	 * @throws EE_Error
2647
+	 */
2648
+	protected function _delete_categories()
2649
+	{
2650
+		$category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2651
+		foreach ($category_IDs as $category_ID) {
2652
+			$this->_delete_category($category_ID);
2653
+		}
2654
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2655
+		$query_args = [
2656
+			'action' => 'category_list',
2657
+		];
2658
+		$this->_redirect_after_action(0, '', '', $query_args);
2659
+	}
2660
+
2661
+
2662
+	/**
2663
+	 * Handles deleting specific category.
2664
+	 *
2665
+	 * @param int $cat_id
2666
+	 */
2667
+	protected function _delete_category($cat_id)
2668
+	{
2669
+		$cat_id = absint($cat_id);
2670
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2671
+	}
2672
+
2673
+
2674
+	/**
2675
+	 * Handles triggering the update or insertion of a new category.
2676
+	 *
2677
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2678
+	 * @throws EE_Error
2679
+	 * @throws EE_Error
2680
+	 */
2681
+	protected function _insert_or_update_category($new_category)
2682
+	{
2683
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2684
+		$success = 0; // we already have a success message so lets not send another.
2685
+		if ($cat_id) {
2686
+			$query_args = [
2687
+				'action'     => 'edit_category',
2688
+				'EVT_CAT_ID' => $cat_id,
2689
+			];
2690
+		} else {
2691
+			$query_args = ['action' => 'add_category'];
2692
+		}
2693
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2694
+	}
2695
+
2696
+
2697
+	/**
2698
+	 * Inserts or updates category
2699
+	 *
2700
+	 * @param bool $update (true indicates we're updating a category).
2701
+	 * @return bool|mixed|string
2702
+	 */
2703
+	private function _insert_category($update = false)
2704
+	{
2705
+		$category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2706
+		$category_name       = $this->request->getRequestParam('category_name', '');
2707
+		$category_desc       = $this->request->getRequestParam('category_desc', '');
2708
+		$category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2709
+		$category_identifier = $this->request->getRequestParam('category_identifier', '');
2710
+
2711
+		if (empty($category_name)) {
2712
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2713
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2714
+			return false;
2715
+		}
2716
+		$term_args = [
2717
+			'name'        => $category_name,
2718
+			'description' => $category_desc,
2719
+			'parent'      => $category_parent,
2720
+		];
2721
+		// was the category_identifier input disabled?
2722
+		if ($category_identifier) {
2723
+			$term_args['slug'] = $category_identifier;
2724
+		}
2725
+		$insert_ids = $update
2726
+			? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2727
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2728
+		if (! is_array($insert_ids)) {
2729
+			$msg = esc_html__(
2730
+				'An error occurred and the category has not been saved to the database.',
2731
+				'event_espresso'
2732
+			);
2733
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2734
+		} else {
2735
+			$category_ID = $insert_ids['term_id'];
2736
+			$msg         =
2737
+				sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2738
+			EE_Error::add_success($msg);
2739
+		}
2740
+		return $category_ID;
2741
+	}
2742
+
2743
+
2744
+	/**
2745
+	 * Gets categories or count of categories matching the arguments in the request.
2746
+	 *
2747
+	 * @param int  $per_page
2748
+	 * @param int  $current_page
2749
+	 * @param bool $count
2750
+	 * @return EE_Term_Taxonomy[]|int
2751
+	 * @throws EE_Error
2752
+	 * @throws EE_Error
2753
+	 */
2754
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2755
+	{
2756
+		// testing term stuff
2757
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2758
+		$order       = $this->request->getRequestParam('order', 'DESC');
2759
+		$limit       = ($current_page - 1) * $per_page;
2760
+		$where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2761
+		$search_term = $this->request->getRequestParam('s');
2762
+		if ($search_term) {
2763
+			$search_term = '%' . $search_term . '%';
2764
+			$where['OR'] = [
2765
+				'Term.name'   => ['LIKE', $search_term],
2766
+				'description' => ['LIKE', $search_term],
2767
+			];
2768
+		}
2769
+		$query_params = [
2770
+			$where,
2771
+			'order_by'   => [$orderby => $order],
2772
+			'limit'      => $limit . ',' . $per_page,
2773
+			'force_join' => ['Term'],
2774
+		];
2775
+		return $count
2776
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2777
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2778
+	}
2779
+
2780
+	/* end category stuff */
2781
+	/**************/
2782
+
2783
+
2784
+	/**
2785
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2786
+	 *
2787
+	 * @throws EE_Error
2788
+	 */
2789
+	public function saveTimezoneString()
2790
+	{
2791
+		$timezone_string = $this->request->getRequestParam('timezone_selected');
2792
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2793
+			EE_Error::add_error(
2794
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2795
+				__FILE__,
2796
+				__FUNCTION__,
2797
+				__LINE__
2798
+			);
2799
+			$this->_template_args['error'] = true;
2800
+			$this->_return_json();
2801
+		}
2802
+
2803
+		update_option('timezone_string', $timezone_string);
2804
+		EE_Error::add_success(
2805
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2806
+		);
2807
+		$this->_template_args['success'] = true;
2808
+		$this->_return_json(true, ['action' => 'create_new']);
2809
+	}
2810
+
2811
+
2812
+	/**
2813
+	 * @throws EE_Error
2814
+	 * @deprecated 4.10.25.p
2815
+	 */
2816
+	public function save_timezonestring_setting()
2817
+	{
2818
+		$this->saveTimezoneString();
2819
+	}
2820 2820
 }
Please login to merge, or discard this patch.
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 1 patch
Indentation   +1788 added lines, -1788 removed lines patch added patch discarded remove patch
@@ -19,1792 +19,1792 @@
 block discarded – undo
19 19
  */
20 20
 class EED_Single_Page_Checkout extends EED_Module
21 21
 {
22
-    /**
23
-     * $_initialized - has the SPCO controller already been initialized ?
24
-     *
25
-     * @var bool $_initialized
26
-     */
27
-    private static $_initialized = false;
28
-
29
-
30
-    /**
31
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
32
-     *
33
-     * @var bool $_valid_checkout
34
-     */
35
-    private static $_checkout_verified = true;
36
-
37
-    /**
38
-     *    $_reg_steps_array - holds initial array of reg steps
39
-     *
40
-     * @var array $_reg_steps_array
41
-     */
42
-    private static $_reg_steps_array = array();
43
-
44
-    /**
45
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
46
-     *
47
-     * @var EE_Checkout $checkout
48
-     */
49
-    public $checkout;
50
-
51
-    /**
52
-     * @var RequestInterface $request
53
-     */
54
-    protected $request;
55
-
56
-
57
-    /**
58
-     * @return EED_Single_Page_Checkout|EED_Module
59
-     * @throws EE_Error
60
-     * @throws ReflectionException
61
-     */
62
-    public static function instance()
63
-    {
64
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
65
-        return parent::get_instance(__CLASS__);
66
-    }
67
-
68
-
69
-    /**
70
-     * @return EE_CART
71
-     */
72
-    public function cart()
73
-    {
74
-        return $this->checkout->cart;
75
-    }
76
-
77
-
78
-    /**
79
-     * @return RequestInterface
80
-     * @since   4.10.14.p
81
-     */
82
-    public static function getRequest()
83
-    {
84
-        return LoaderFactory::getLoader()->getShared(RequestInterface::class);
85
-    }
86
-
87
-
88
-    /**
89
-     * @return EE_Transaction
90
-     */
91
-    public function transaction()
92
-    {
93
-        return $this->checkout->transaction;
94
-    }
95
-
96
-
97
-    /**
98
-     *    set_hooks - for hooking into EE Core, other modules, etc
99
-     *
100
-     * @return    void
101
-     * @throws EE_Error
102
-     */
103
-    public static function set_hooks()
104
-    {
105
-        EED_Single_Page_Checkout::set_definitions();
106
-    }
107
-
108
-
109
-    /**
110
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
111
-     *
112
-     * @return    void
113
-     * @throws EE_Error
114
-     */
115
-    public static function set_hooks_admin()
116
-    {
117
-        EED_Single_Page_Checkout::set_definitions();
118
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
119
-            return;
120
-        }
121
-        // going to start an output buffer in case anything gets accidentally output
122
-        // that might disrupt our JSON response
123
-        ob_start();
124
-        EED_Single_Page_Checkout::load_reg_steps();
125
-        // set ajax hooks
126
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
127
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
128
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
129
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
130
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
131
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
132
-    }
133
-
134
-
135
-    /**
136
-     *    process ajax request
137
-     *
138
-     * @param string $ajax_action
139
-     * @throws EE_Error
140
-     * @throws ReflectionException
141
-     */
142
-    public static function process_ajax_request($ajax_action)
143
-    {
144
-        $request = EED_Single_Page_Checkout::getRequest();
145
-        $request->setRequestParam('action', $ajax_action);
146
-        EED_Single_Page_Checkout::instance()->_initialize();
147
-    }
148
-
149
-
150
-    /**
151
-     * ajax display registration step
152
-     *
153
-     * @throws EE_Error
154
-     * @throws ReflectionException
155
-     */
156
-    public static function display_reg_step()
157
-    {
158
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
159
-    }
160
-
161
-
162
-    /**
163
-     * ajax process registration step
164
-     *
165
-     * @throws EE_Error
166
-     * @throws ReflectionException
167
-     */
168
-    public static function process_reg_step()
169
-    {
170
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
171
-    }
172
-
173
-
174
-    /**
175
-     * ajax process registration step
176
-     *
177
-     * @throws EE_Error
178
-     * @throws ReflectionException
179
-     */
180
-    public static function update_reg_step()
181
-    {
182
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
183
-    }
184
-
185
-
186
-    /**
187
-     * update_checkout
188
-     *
189
-     * @return void
190
-     * @throws ReflectionException
191
-     * @throws EE_Error
192
-     */
193
-    public static function update_checkout()
194
-    {
195
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
196
-    }
197
-
198
-
199
-    /**
200
-     * @return void
201
-     * @deprecated 4.10.14.p
202
-     */
203
-    public static function load_request_handler()
204
-    {
205
-    }
206
-
207
-
208
-    /**
209
-     *    set_definitions
210
-     *
211
-     * @return    void
212
-     * @throws EE_Error
213
-     */
214
-    public static function set_definitions()
215
-    {
216
-        if (defined('SPCO_BASE_PATH')) {
217
-            return;
218
-        }
219
-        define(
220
-            'SPCO_BASE_PATH',
221
-            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
222
-        );
223
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css/');
224
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img/');
225
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js/');
226
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc/');
227
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps/');
228
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates/');
229
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
230
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
231
-        );
232
-    }
233
-
234
-
235
-    /**
236
-     * load_reg_steps
237
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
238
-     *
239
-     * @throws EE_Error
240
-     */
241
-    public static function load_reg_steps()
242
-    {
243
-        static $reg_steps_loaded = false;
244
-        if ($reg_steps_loaded) {
245
-            return;
246
-        }
247
-        // filter list of reg_steps
248
-        $reg_steps_to_load = (array) apply_filters(
249
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
250
-            EED_Single_Page_Checkout::get_reg_steps()
251
-        );
252
-        // sort by key (order)
253
-        ksort($reg_steps_to_load);
254
-        // loop through folders
255
-        foreach ($reg_steps_to_load as $order => $reg_step) {
256
-            // we need a
257
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
258
-                // copy over to the reg_steps_array
259
-                EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
260
-                // register custom key route for each reg step
261
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
262
-                EE_Config::register_route(
263
-                    $reg_step['slug'],
264
-                    'EED_Single_Page_Checkout',
265
-                    'run',
266
-                    'step'
267
-                );
268
-                // add AJAX or other hooks
269
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
270
-                    // setup autoloaders if necessary
271
-                    if (! class_exists($reg_step['class_name'])) {
272
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
273
-                            $reg_step['file_path'],
274
-                            true
275
-                        );
276
-                    }
277
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
278
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
279
-                    }
280
-                }
281
-            }
282
-        }
283
-        $reg_steps_loaded = true;
284
-    }
285
-
286
-
287
-    /**
288
-     *    get_reg_steps
289
-     *
290
-     * @return    array
291
-     */
292
-    public static function get_reg_steps()
293
-    {
294
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
295
-        if (empty($reg_steps)) {
296
-            $reg_steps = array(
297
-                10  => array(
298
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
299
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
300
-                    'slug'       => 'attendee_information',
301
-                    'has_hooks'  => false,
302
-                ),
303
-                30  => array(
304
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
305
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
306
-                    'slug'       => 'payment_options',
307
-                    'has_hooks'  => true,
308
-                ),
309
-                999 => array(
310
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
311
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
312
-                    'slug'       => 'finalize_registration',
313
-                    'has_hooks'  => false,
314
-                ),
315
-            );
316
-        }
317
-        return $reg_steps;
318
-    }
319
-
320
-
321
-    /**
322
-     *    registration_checkout_for_admin
323
-     *
324
-     * @return    string
325
-     * @throws EE_Error
326
-     * @throws ReflectionException
327
-     */
328
-    public static function registration_checkout_for_admin()
329
-    {
330
-        $request = EED_Single_Page_Checkout::getRequest();
331
-        $request->setRequestParam('step', 'attendee_information');
332
-        $request->setRequestParam('action', 'display_spco_reg_step');
333
-        $request->setRequestParam('process_form_submission', false);
334
-        EED_Single_Page_Checkout::instance()->_initialize();
335
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
336
-        return EED_Single_Page_Checkout::getResponse()->getOutput();
337
-    }
338
-
339
-
340
-    /**
341
-     * process_registration_from_admin
342
-     *
343
-     * @return EE_Transaction
344
-     * @throws EE_Error
345
-     * @throws ReflectionException
346
-     */
347
-    public static function process_registration_from_admin()
348
-    {
349
-        $request = EED_Single_Page_Checkout::getRequest();
350
-        $request->setRequestParam('step', 'attendee_information');
351
-        $request->setRequestParam('action', 'process_reg_step');
352
-        $request->setRequestParam('process_form_submission', true);
353
-        EED_Single_Page_Checkout::instance()->_initialize();
354
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
355
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
356
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
357
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
358
-                if ($final_reg_step->process_reg_step()) {
359
-                    $final_reg_step->set_completed();
360
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
361
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
362
-                }
363
-            }
364
-        }
365
-        return null;
366
-    }
367
-
368
-
369
-    /**
370
-     *    run
371
-     *
372
-     * @param WP_Query $WP
373
-     * @return    void
374
-     */
375
-    public function run($WP)
376
-    {
377
-        if (
378
-            $WP instanceof WP_Query
379
-            && $WP->is_main_query()
380
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
381
-            && $this->_is_reg_checkout()
382
-        ) {
383
-            $this->_initialize();
384
-        }
385
-    }
386
-
387
-
388
-    /**
389
-     * determines whether current url matches reg page url
390
-     *
391
-     * @return bool
392
-     */
393
-    protected function _is_reg_checkout()
394
-    {
395
-        // get current permalink for reg page without any extra query args
396
-        $reg_page_url = get_permalink(EE_Config::instance()->core->reg_page_id);
397
-        // get request URI for current request, but without the scheme or host
398
-        $current_request_uri = EEH_URL::filter_input_server_url();
399
-        $current_request_uri = html_entity_decode($current_request_uri);
400
-        // get array of query args from the current request URI
401
-        $query_args = EEH_URL::get_query_string($current_request_uri);
402
-        // grab page id if it is set
403
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
404
-        // and remove the page id from the query args (we will re-add it later)
405
-        unset($query_args['page_id']);
406
-        // now strip all query args from current request URI
407
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
408
-        // and re-add the page id if it was set
409
-        if ($page_id) {
410
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
411
-        }
412
-        // remove slashes and ?
413
-        $current_request_uri = trim($current_request_uri, '?/');
414
-        // is current request URI part of the known full reg page URL ?
415
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
416
-    }
417
-
418
-
419
-    /**
420
-     * @param WP_Query $wp_query
421
-     * @return    void
422
-     * @throws EE_Error
423
-     * @throws ReflectionException
424
-     */
425
-    public static function init($wp_query)
426
-    {
427
-        EED_Single_Page_Checkout::instance()->run($wp_query);
428
-    }
429
-
430
-
431
-    /**
432
-     *    _initialize - initial module setup
433
-     *
434
-     * @return    void
435
-     */
436
-    private function _initialize()
437
-    {
438
-        // ensure SPCO doesn't run twice
439
-        if (EED_Single_Page_Checkout::$_initialized) {
440
-            return;
441
-        }
442
-        try {
443
-            $this->request = EED_Single_Page_Checkout::getRequest();
444
-            EED_Single_Page_Checkout::load_reg_steps();
445
-            $this->_verify_session();
446
-            // setup the EE_Checkout object
447
-            $this->checkout = $this->_initialize_checkout();
448
-            // filter checkout
449
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
450
-            // get the $_GET
451
-            $this->_get_request_vars();
452
-            if ($this->_block_bots()) {
453
-                return;
454
-            }
455
-            // filter continue_reg
456
-            $this->checkout->continue_reg = apply_filters(
457
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
458
-                true,
459
-                $this->checkout
460
-            );
461
-            // load the reg steps array
462
-            if (! $this->_load_and_instantiate_reg_steps()) {
463
-                EED_Single_Page_Checkout::$_initialized = true;
464
-                return;
465
-            }
466
-            // set the current step
467
-            $this->checkout->set_current_step($this->checkout->step);
468
-            // and the next step
469
-            $this->checkout->set_next_step();
470
-            // verify that everything has been setup correctly
471
-            if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
472
-                EED_Single_Page_Checkout::$_initialized = true;
473
-                return;
474
-            }
475
-            // lock the transaction
476
-            $this->checkout->transaction->lock();
477
-            // make sure all of our cached objects are added to their respective model entity mappers
478
-            $this->checkout->refresh_all_entities();
479
-            // set amount owing
480
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
481
-            // initialize each reg step, which gives them the chance to potentially alter the process
482
-            $this->_initialize_reg_steps();
483
-            // DEBUG LOG
484
-            // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
485
-            // get reg form
486
-            if (! $this->_check_form_submission()) {
487
-                EED_Single_Page_Checkout::$_initialized = true;
488
-                return;
489
-            }
490
-            // checkout the action!!!
491
-            $this->_process_form_action();
492
-            // add some style and make it dance
493
-            $this->add_styles_and_scripts($this);
494
-            // kk... SPCO has successfully run
495
-            EED_Single_Page_Checkout::$_initialized = true;
496
-            // set no cache headers and constants
497
-            EE_System::do_not_cache();
498
-            // add anchor
499
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
500
-            // remove transaction lock
501
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
502
-        } catch (Exception $e) {
503
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
504
-        }
505
-    }
506
-
507
-
508
-    /**
509
-     *    _verify_session
510
-     * checks that the session is valid and not expired
511
-     *
512
-     * @throws EE_Error
513
-     * @throws ReflectionException
514
-     */
515
-    private function _verify_session()
516
-    {
517
-        if (! EE_Registry::instance()->SSN instanceof EE_Session) {
518
-            throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso'));
519
-        }
520
-        $clear_session_requested = $this->request->getRequestParam('clear_session', false, 'bool');
521
-        // is session still valid ?
522
-        if (
523
-            $clear_session_requested
524
-            || (
525
-                EE_Registry::instance()->SSN->expired()
526
-                && $this->request->getRequestParam('e_reg_url_link') === ''
527
-            )
528
-        ) {
529
-            $this->checkout = new EE_Checkout();
530
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
531
-            // EE_Registry::instance()->SSN->reset_cart();
532
-            // EE_Registry::instance()->SSN->reset_checkout();
533
-            // EE_Registry::instance()->SSN->reset_transaction();
534
-            if (! $clear_session_requested) {
535
-                EE_Error::add_attention(
536
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
537
-                    __FILE__,
538
-                    __FUNCTION__,
539
-                    __LINE__
540
-                );
541
-            }
542
-            // EE_Registry::instance()->SSN->reset_expired();
543
-        }
544
-    }
545
-
546
-
547
-    /**
548
-     *    _initialize_checkout
549
-     * loads and instantiates EE_Checkout
550
-     *
551
-     * @return EE_Checkout
552
-     * @throws EE_Error
553
-     * @throws ReflectionException
554
-     */
555
-    private function _initialize_checkout()
556
-    {
557
-        // look in session for existing checkout
558
-        /** @type EE_Checkout $checkout */
559
-        $checkout = EE_Registry::instance()->SSN->checkout();
560
-        // verify
561
-        if (! $checkout instanceof EE_Checkout) {
562
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
563
-            $checkout = EE_Registry::instance()->load_file(
564
-                SPCO_INC_PATH,
565
-                'EE_Checkout',
566
-                'class',
567
-                array(),
568
-                false
569
-            );
570
-        } else {
571
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
572
-                $this->unlock_transaction();
573
-                wp_safe_redirect($checkout->redirect_url);
574
-                exit();
575
-            }
576
-        }
577
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
578
-        // verify again
579
-        if (! $checkout instanceof EE_Checkout) {
580
-            throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso'));
581
-        }
582
-        // reset anything that needs a clean slate for each request
583
-        $checkout->reset_for_current_request();
584
-        return $checkout;
585
-    }
586
-
587
-
588
-    /**
589
-     *    _get_request_vars
590
-     *
591
-     * @return    void
592
-     */
593
-    private function _get_request_vars()
594
-    {
595
-        // make sure this request is marked as belonging to EE
596
-        /** @var CurrentPage $current_page */
597
-        $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
598
-        $current_page->setEspressoPage(true);
599
-        // which step is being requested ?
600
-        $this->checkout->step = $this->request->getRequestParam('step', $this->_get_first_step());
601
-        // which step is being edited ?
602
-        $this->checkout->edit_step = $this->request->getRequestParam('edit_step');
603
-        // and what we're doing on the current step
604
-        $this->checkout->action = $this->request->getRequestParam('action', 'display_spco_reg_step');
605
-        // timestamp
606
-        $this->checkout->uts = $this->request->getRequestParam('uts', 0, 'int');
607
-        // returning to edit ?
608
-        $this->checkout->reg_url_link = $this->request->getRequestParam('e_reg_url_link');
609
-        // add reg url link to registration query params
610
-        if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
611
-            $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
612
-        }
613
-        // or some other kind of revisit ?
614
-        $this->checkout->revisit = $this->request->getRequestParam('revisit', false, 'bool');
615
-        // and whether or not to generate a reg form for this request
616
-        $this->checkout->generate_reg_form = $this->request->getRequestParam('generate_reg_form', true, 'bool');
617
-        // and whether or not to process a reg form submission for this request
618
-        $this->checkout->process_form_submission = $this->request->getRequestParam(
619
-            'process_form_submission',
620
-            $this->checkout->action === 'process_reg_step',
621
-            'bool'
622
-        );
623
-        $this->checkout->process_form_submission = filter_var(
624
-            $this->checkout->action !== 'display_spco_reg_step'
625
-                ? $this->checkout->process_form_submission
626
-                : false,
627
-            FILTER_VALIDATE_BOOLEAN
628
-        );
629
-        // $this->_display_request_vars();
630
-    }
631
-
632
-
633
-    /**
634
-     *  _display_request_vars
635
-     *
636
-     * @return    void
637
-     */
638
-    protected function _display_request_vars()
639
-    {
640
-        if (! WP_DEBUG) {
641
-            return;
642
-        }
643
-        EEH_Debug_Tools::printr($this->request->requestParams(), 'requestParams', __FILE__, __LINE__);
644
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
645
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
646
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
647
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
648
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
649
-        EEH_Debug_Tools::printr(
650
-            $this->checkout->generate_reg_form,
651
-            '$this->checkout->generate_reg_form',
652
-            __FILE__,
653
-            __LINE__
654
-        );
655
-        EEH_Debug_Tools::printr(
656
-            $this->checkout->process_form_submission,
657
-            '$this->checkout->process_form_submission',
658
-            __FILE__,
659
-            __LINE__
660
-        );
661
-    }
662
-
663
-
664
-    /**
665
-     * _block_bots
666
-     * checks that the incoming request has either of the following set:
667
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
668
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
669
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
670
-     * then where you coming from man?
671
-     *
672
-     * @return boolean
673
-     */
674
-    private function _block_bots()
675
-    {
676
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
677
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
678
-            return true;
679
-        }
680
-        return false;
681
-    }
682
-
683
-
684
-    /**
685
-     *    _get_first_step
686
-     *  gets slug for first step in $_reg_steps_array
687
-     *
688
-     * @return    string
689
-     */
690
-    private function _get_first_step()
691
-    {
692
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
693
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
694
-    }
695
-
696
-
697
-    /**
698
-     * instantiates each reg step based on the loaded reg_steps array
699
-     *
700
-     * @return    bool
701
-     * @throws EE_Error
702
-     * @throws InvalidArgumentException
703
-     * @throws InvalidDataTypeException
704
-     * @throws InvalidInterfaceException
705
-     * @throws ReflectionException
706
-     */
707
-    private function _load_and_instantiate_reg_steps()
708
-    {
709
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
710
-        // have reg_steps already been instantiated ?
711
-        if (
712
-            empty($this->checkout->reg_steps)
713
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
714
-        ) {
715
-            // if not, then loop through raw reg steps array
716
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
717
-                if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
718
-                    return false;
719
-                }
720
-            }
721
-            if (isset($this->checkout->reg_steps['registration_confirmation'])) {
722
-                // skip the registration_confirmation page ?
723
-                if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
724
-                    // just remove it from the reg steps array
725
-                    $this->checkout->remove_reg_step('registration_confirmation', false);
726
-                } elseif (
727
-                    EE_Registry::instance()->CFG->registration->reg_confirmation_last
728
-                ) {
729
-                    // set the order to something big like 100
730
-                    $this->checkout->set_reg_step_order('registration_confirmation');
731
-                }
732
-            }
733
-            // filter the array for good luck
734
-            $this->checkout->reg_steps = apply_filters(
735
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
736
-                $this->checkout->reg_steps
737
-            );
738
-            // finally re-sort based on the reg step class order properties
739
-            $this->checkout->sort_reg_steps();
740
-        } else {
741
-            foreach ($this->checkout->reg_steps as $reg_step) {
742
-                // set all current step stati to FALSE
743
-                $reg_step->set_is_current_step(false);
744
-            }
745
-        }
746
-        if (empty($this->checkout->reg_steps)) {
747
-            EE_Error::add_error(
748
-                esc_html__('No Reg Steps were loaded..', 'event_espresso'),
749
-                __FILE__,
750
-                __FUNCTION__,
751
-                __LINE__
752
-            );
753
-            return false;
754
-        }
755
-        // make reg step details available to JS
756
-        $this->checkout->set_reg_step_JSON_info();
757
-        return true;
758
-    }
759
-
760
-
761
-    /**
762
-     *     _load_and_instantiate_reg_step
763
-     *
764
-     * @param array $reg_step
765
-     * @param int   $order
766
-     * @return bool
767
-     * @throws EE_Error
768
-     * @throws ReflectionException
769
-     */
770
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
771
-    {
772
-        // we need a file_path, class_name, and slug to add a reg step
773
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
774
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
775
-            if (
776
-                $this->checkout->reg_url_link
777
-                && $this->checkout->step !== $reg_step['slug']
778
-                && $reg_step['slug'] !== 'finalize_registration'
779
-                // normally at this point we would NOT load the reg step, but this filter can change that
780
-                && apply_filters(
781
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
782
-                    true,
783
-                    $reg_step,
784
-                    $this->checkout
785
-                )
786
-            ) {
787
-                return true;
788
-            }
789
-
790
-            // instantiate step class using file path and class name
791
-            $reg_step_obj = EE_Registry::instance()->load_file(
792
-                $reg_step['file_path'],
793
-                $reg_step['class_name'],
794
-                'class',
795
-                [$this->checkout],
796
-                false
797
-            );
798
-            // did we gets the goods ?
799
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
800
-                // set reg step order based on config
801
-                $reg_step_obj->set_order($order);
802
-                // add instantiated reg step object to the master reg steps array
803
-                $this->checkout->add_reg_step($reg_step_obj);
804
-            } else {
805
-                EE_Error::add_error(
806
-                    esc_html__('The current step could not be set.', 'event_espresso'),
807
-                    __FILE__,
808
-                    __FUNCTION__,
809
-                    __LINE__
810
-                );
811
-                return false;
812
-            }
813
-        } else {
814
-            if (WP_DEBUG) {
815
-                EE_Error::add_error(
816
-                    sprintf(
817
-                        esc_html__(
818
-                            'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
819
-                            'event_espresso'
820
-                        ),
821
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
822
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
823
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
824
-                        '<ul>',
825
-                        '<li>',
826
-                        '</li>',
827
-                        '</ul>'
828
-                    ),
829
-                    __FILE__,
830
-                    __FUNCTION__,
831
-                    __LINE__
832
-                );
833
-            }
834
-            return false;
835
-        }
836
-        return true;
837
-    }
838
-
839
-
840
-    /**
841
-     * _verify_transaction_and_get_registrations
842
-     *
843
-     * @return bool
844
-     * @throws EE_Error
845
-     * @throws ReflectionException
846
-     */
847
-    private function _verify_transaction_and_get_registrations()
848
-    {
849
-        // was there already a valid transaction in the checkout from the session ?
850
-        if (! $this->checkout->transaction instanceof EE_Transaction) {
851
-            // get transaction from db or session
852
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
853
-                ? $this->_get_transaction_and_cart_for_previous_visit()
854
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
855
-            if (! $this->checkout->transaction instanceof EE_Transaction) {
856
-                EE_Error::add_error(
857
-                    esc_html__(
858
-                        'Your Registration and Transaction information could not be retrieved from the db.',
859
-                        'event_espresso'
860
-                    ),
861
-                    __FILE__,
862
-                    __FUNCTION__,
863
-                    __LINE__
864
-                );
865
-                $this->checkout->transaction = EE_Transaction::new_instance();
866
-                // add some style and make it dance
867
-                $this->add_styles_and_scripts($this);
868
-                EED_Single_Page_Checkout::$_initialized = true;
869
-                return false;
870
-            }
871
-            // and the registrations for the transaction
872
-            $this->_get_registrations($this->checkout->transaction);
873
-        }
874
-        return true;
875
-    }
876
-
877
-
878
-    /**
879
-     * _get_transaction_and_cart_for_previous_visit
880
-     *
881
-     * @return EE_Transaction|null
882
-     * @throws EE_Error
883
-     * @throws ReflectionException
884
-     */
885
-    private function _get_transaction_and_cart_for_previous_visit()
886
-    {
887
-        /** @var $TXN_model EEM_Transaction */
888
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
889
-        // because the reg_url_link is present in the request,
890
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
891
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
892
-        // verify transaction
893
-        if ($transaction instanceof EE_Transaction) {
894
-            // and get the cart that was used for that transaction
895
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
896
-            return $transaction;
897
-        }
898
-        EE_Error::add_error(
899
-            esc_html__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
900
-            __FILE__,
901
-            __FUNCTION__,
902
-            __LINE__
903
-        );
904
-        return null;
905
-    }
906
-
907
-
908
-    /**
909
-     * _get_cart_for_transaction
910
-     *
911
-     * @param EE_Transaction $transaction
912
-     * @return EE_Cart
913
-     */
914
-    private function _get_cart_for_transaction($transaction)
915
-    {
916
-        return $this->checkout->get_cart_for_transaction($transaction);
917
-    }
918
-
919
-
920
-    /**
921
-     * get_cart_for_transaction
922
-     *
923
-     * @param EE_Transaction $transaction
924
-     * @return EE_Cart
925
-     */
926
-    public function get_cart_for_transaction(EE_Transaction $transaction)
927
-    {
928
-        return $this->checkout->get_cart_for_transaction($transaction);
929
-    }
930
-
931
-
932
-    /**
933
-     * _get_transaction_and_cart_for_current_session
934
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
935
-     *
936
-     * @return EE_Transaction
937
-     * @throws EE_Error
938
-     * @throws ReflectionException
939
-     */
940
-    private function _get_cart_for_current_session_and_setup_new_transaction()
941
-    {
942
-        //  if there's no transaction, then this is the FIRST visit to SPCO
943
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
944
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
945
-        // and then create a new transaction
946
-        $transaction = $this->_initialize_transaction();
947
-        // verify transaction
948
-        if ($transaction instanceof EE_Transaction) {
949
-            // save it so that we have an ID for other objects to use
950
-            $transaction->save();
951
-            // and save TXN data to the cart
952
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
953
-        } else {
954
-            EE_Error::add_error(
955
-                esc_html__('A Valid Transaction could not be initialized.', 'event_espresso'),
956
-                __FILE__,
957
-                __FUNCTION__,
958
-                __LINE__
959
-            );
960
-        }
961
-        return $transaction;
962
-    }
963
-
964
-
965
-    /**
966
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
967
-     *
968
-     * @return EE_Transaction|null
969
-     */
970
-    private function _initialize_transaction()
971
-    {
972
-        try {
973
-            // ensure cart totals have been calculated
974
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
975
-            // grab the cart grand total
976
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
977
-            // create new TXN
978
-            $transaction = EE_Transaction::new_instance(
979
-                array(
980
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
981
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
982
-                    'TXN_paid'      => 0,
983
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
984
-                )
985
-            );
986
-            // save it so that we have an ID for other objects to use
987
-            $transaction->save();
988
-            // set cron job for following up on TXNs after their session has expired
989
-            EE_Cron_Tasks::schedule_expired_transaction_check(
990
-                EE_Registry::instance()->SSN->expiration() + 1,
991
-                $transaction->ID()
992
-            );
993
-            return $transaction;
994
-        } catch (Exception $e) {
995
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
996
-        }
997
-        return null;
998
-    }
999
-
1000
-
1001
-    /**
1002
-     * _get_registrations
1003
-     *
1004
-     * @param EE_Transaction $transaction
1005
-     * @return void
1006
-     * @throws EE_Error
1007
-     * @throws ReflectionException
1008
-     */
1009
-    private function _get_registrations(EE_Transaction $transaction)
1010
-    {
1011
-        // first step: grab the registrants  { : o
1012
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params);
1013
-        $this->checkout->total_ticket_count = count($registrations);
1014
-        // verify registrations have been set
1015
-        if (empty($registrations)) {
1016
-            // if no cached registrations, then check the db
1017
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params);
1018
-            // still nothing ? well as long as this isn't a revisit
1019
-            if (empty($registrations) && ! $this->checkout->revisit) {
1020
-                // generate new registrations from scratch
1021
-                $registrations = $this->_initialize_registrations($transaction);
1022
-            }
1023
-        }
1024
-        // sort by their original registration order
1025
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1026
-        // then loop thru the array
1027
-        foreach ($registrations as $registration) {
1028
-            // verify each registration
1029
-            if ($registration instanceof EE_Registration) {
1030
-                // we display all attendee info for the primary registrant
1031
-                if (
1032
-                    $this->checkout->reg_url_link === $registration->reg_url_link()
1033
-                    && $registration->is_primary_registrant()
1034
-                ) {
1035
-                    $this->checkout->primary_revisit = true;
1036
-                    break;
1037
-                }
1038
-                if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1039
-                    // but hide info if it doesn't belong to you
1040
-                    $transaction->clear_cache('Registration', $registration->ID());
1041
-                    $this->checkout->total_ticket_count--;
1042
-                }
1043
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1044
-            }
1045
-        }
1046
-    }
1047
-
1048
-
1049
-    /**
1050
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1051
-     *
1052
-     * @param EE_Transaction $transaction
1053
-     * @return    array
1054
-     * @throws EE_Error
1055
-     * @throws ReflectionException
1056
-     */
1057
-    private function _initialize_registrations(EE_Transaction $transaction)
1058
-    {
1059
-        $att_nmbr = 0;
1060
-        $registrations = array();
1061
-        if ($transaction instanceof EE_Transaction) {
1062
-            /** @type EE_Registration_Processor $registration_processor */
1063
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1064
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1065
-            // now let's add the cart items to the $transaction
1066
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1067
-                // do the following for each ticket of this type they selected
1068
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1069
-                    $att_nmbr++;
1070
-                    /** @var CreateRegistrationCommand $CreateRegistrationCommand */
1071
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1072
-                        CreateRegistrationCommand::class,
1073
-                        [
1074
-                            $transaction,
1075
-                            $line_item,
1076
-                            $att_nmbr,
1077
-                            $this->checkout->total_ticket_count,
1078
-                        ]
1079
-                    );
1080
-                    // override capabilities for frontend registrations
1081
-                    if ($this->request->isFrontend()) {
1082
-                        $CreateRegistrationCommand->setCapCheck(
1083
-                            new PublicCapabilities('', 'create_new_registration')
1084
-                        );
1085
-                    }
1086
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1087
-                    if (! $registration instanceof EE_Registration) {
1088
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1089
-                    }
1090
-                    $registrations[ $registration->ID() ] = $registration;
1091
-                }
1092
-            }
1093
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1094
-        }
1095
-        return $registrations;
1096
-    }
1097
-
1098
-
1099
-    /**
1100
-     * sorts registrations by REG_count
1101
-     *
1102
-     * @param EE_Registration $reg_A
1103
-     * @param EE_Registration $reg_B
1104
-     * @return int
1105
-     */
1106
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1107
-    {
1108
-        // this shouldn't ever happen within the same TXN, but oh well
1109
-        if ($reg_A->count() === $reg_B->count()) {
1110
-            return 0;
1111
-        }
1112
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1113
-    }
1114
-
1115
-
1116
-    /**
1117
-     *    _final_verifications
1118
-     * just makes sure that everything is set up correctly before proceeding
1119
-     *
1120
-     * @return    bool
1121
-     * @throws EE_Error
1122
-     * @throws ReflectionException
1123
-     */
1124
-    private function _final_verifications()
1125
-    {
1126
-        // filter checkout
1127
-        $this->checkout = apply_filters(
1128
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1129
-            $this->checkout
1130
-        );
1131
-        // verify that current step is still set correctly
1132
-        if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1133
-            EE_Error::add_error(
1134
-                esc_html__(
1135
-                    'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.',
1136
-                    'event_espresso'
1137
-                ),
1138
-                __FILE__,
1139
-                __FUNCTION__,
1140
-                __LINE__
1141
-            );
1142
-            return false;
1143
-        }
1144
-        // if returning to SPCO, then verify that primary registrant is set
1145
-        if (! empty($this->checkout->reg_url_link)) {
1146
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1147
-            if (! $valid_registrant instanceof EE_Registration) {
1148
-                EE_Error::add_error(
1149
-                    esc_html__(
1150
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.',
1151
-                        'event_espresso'
1152
-                    ),
1153
-                    __FILE__,
1154
-                    __FUNCTION__,
1155
-                    __LINE__
1156
-                );
1157
-                return false;
1158
-            }
1159
-            $valid_registrant = null;
1160
-            foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1161
-                if (
1162
-                    $registration instanceof EE_Registration
1163
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1164
-                ) {
1165
-                    $valid_registrant = $registration;
1166
-                }
1167
-            }
1168
-            if (! $valid_registrant instanceof EE_Registration) {
1169
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1170
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1171
-                    // clear the session, mark the checkout as unverified, and try again
1172
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1173
-                    EED_Single_Page_Checkout::$_initialized = false;
1174
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1175
-                    $this->_initialize();
1176
-                    EE_Error::reset_notices();
1177
-                    return false;
1178
-                }
1179
-                EE_Error::add_error(
1180
-                    esc_html__(
1181
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1182
-                        'event_espresso'
1183
-                    ),
1184
-                    __FILE__,
1185
-                    __FUNCTION__,
1186
-                    __LINE__
1187
-                );
1188
-                return false;
1189
-            }
1190
-        }
1191
-        // now that things have been kinda sufficiently verified,
1192
-        // let's add the checkout to the session so that it's available to other systems
1193
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1194
-        return true;
1195
-    }
1196
-
1197
-
1198
-    /**
1199
-     *    _initialize_reg_steps
1200
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1201
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1202
-     *
1203
-     * @param bool $reinitializing
1204
-     * @throws EE_Error
1205
-     */
1206
-    private function _initialize_reg_steps($reinitializing = false)
1207
-    {
1208
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1209
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1210
-        foreach ($this->checkout->reg_steps as $reg_step) {
1211
-            if (! $reg_step->initialize_reg_step()) {
1212
-                // if not initialized then maybe this step is being removed...
1213
-                if (! $reinitializing && $reg_step->is_current_step()) {
1214
-                    // if it was the current step, then we need to start over here
1215
-                    $this->_initialize_reg_steps(true);
1216
-                    return;
1217
-                }
1218
-                continue;
1219
-            }
1220
-            // add css and JS for current step
1221
-            $this->add_styles_and_scripts($reg_step);
1222
-            if ($reg_step->is_current_step()) {
1223
-                // the text that appears on the reg step form submit button
1224
-                $reg_step->set_submit_button_text();
1225
-            }
1226
-        }
1227
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1228
-        do_action(
1229
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1230
-            $this->checkout->current_step
1231
-        );
1232
-    }
1233
-
1234
-
1235
-    /**
1236
-     * _check_form_submission
1237
-     *
1238
-     * @return boolean
1239
-     * @throws EE_Error
1240
-     * @throws ReflectionException
1241
-     */
1242
-    private function _check_form_submission()
1243
-    {
1244
-        // does this request require the reg form to be generated ?
1245
-        if ($this->checkout->generate_reg_form) {
1246
-            // ever heard that song by Blue Rodeo ?
1247
-            try {
1248
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1249
-                // if not displaying a form, then check for form submission
1250
-                if (
1251
-                    $this->checkout->process_form_submission
1252
-                    && $this->checkout->current_step->reg_form->was_submitted()
1253
-                ) {
1254
-                    // clear out any old data in case this step is being run again
1255
-                    $this->checkout->current_step->set_valid_data(array());
1256
-                    // capture submitted form data
1257
-                    $request_data = $this->request->requestParams();
1258
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1259
-                        (array) apply_filters(
1260
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1261
-                            $request_data,
1262
-                            $this->checkout
1263
-                        )
1264
-                    );
1265
-                    // validate submitted form data
1266
-                    if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1267
-                        // thou shall not pass !!!
1268
-                        $this->checkout->continue_reg = false;
1269
-                        // any form validation errors?
1270
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1271
-                            EE_Error::add_error(
1272
-                                $this->checkout->current_step->reg_form->submission_error_message(),
1273
-                                __FILE__,
1274
-                                __FUNCTION__,
1275
-                                __LINE__
1276
-                            );
1277
-                        }
1278
-                        // well not really... what will happen is
1279
-                        // we'll just get redirected back to redo the current step
1280
-                        $this->go_to_next_step();
1281
-                        return false;
1282
-                    }
1283
-                }
1284
-            } catch (EE_Error $e) {
1285
-                $e->get_error();
1286
-            }
1287
-        }
1288
-        return true;
1289
-    }
1290
-
1291
-
1292
-    /**
1293
-     * _process_action
1294
-     *
1295
-     * @return void
1296
-     * @throws EE_Error
1297
-     * @throws ReflectionException
1298
-     */
1299
-    private function _process_form_action()
1300
-    {
1301
-        // what cha wanna do?
1302
-        switch ($this->checkout->action) {
1303
-            // AJAX next step reg form
1304
-            case 'display_spco_reg_step':
1305
-                $this->checkout->redirect = false;
1306
-                if ($this->request->isAjax()) {
1307
-                    $this->checkout->json_response->set_reg_step_html(
1308
-                        $this->checkout->current_step->display_reg_form()
1309
-                    );
1310
-                }
1311
-                break;
1312
-            default:
1313
-                // meh... do one of those other steps first
1314
-                if (
1315
-                    ! empty($this->checkout->action)
1316
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1317
-                ) {
1318
-                    // dynamically creates hook point like:
1319
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1320
-                    do_action(
1321
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1322
-                        $this->checkout->current_step
1323
-                    );
1324
-                    $process_reg_step = apply_filters(
1325
-                        "AHEE__Single_Page_Checkout__process_reg_step__{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1326
-                        true,
1327
-                        $this->checkout->current_step,
1328
-                        $this
1329
-                    );
1330
-                    // call action on current step
1331
-                    if ($process_reg_step && call_user_func([$this->checkout->current_step, $this->checkout->action])) {
1332
-                        // good registrant, you get to proceed
1333
-                        if (
1334
-                            $this->checkout->current_step->success_message() !== ''
1335
-                            && apply_filters(
1336
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1337
-                                false
1338
-                            )
1339
-                        ) {
1340
-                            EE_Error::add_success(
1341
-                                $this->checkout->current_step->success_message()
1342
-                                . '<br />' . $this->checkout->next_step->_instructions()
1343
-                            );
1344
-                        }
1345
-                        // pack it up, pack it in...
1346
-                        $this->_setup_redirect();
1347
-                    }
1348
-                    // dynamically creates hook point like:
1349
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1350
-                    do_action(
1351
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1352
-                        $this->checkout->current_step
1353
-                    );
1354
-                } else {
1355
-                    EE_Error::add_error(
1356
-                        sprintf(
1357
-                            esc_html__(
1358
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1359
-                                'event_espresso'
1360
-                            ),
1361
-                            $this->checkout->action,
1362
-                            $this->checkout->current_step->name()
1363
-                        ),
1364
-                        __FILE__,
1365
-                        __FUNCTION__,
1366
-                        __LINE__
1367
-                    );
1368
-                }
1369
-            // end default
1370
-        }
1371
-        // store our progress so far
1372
-        $this->checkout->stash_transaction_and_checkout();
1373
-        // advance to the next step! If you pass GO, collect $200
1374
-        $this->go_to_next_step();
1375
-    }
1376
-
1377
-
1378
-    /**
1379
-     * @param EED_Single_Page_Checkout|EE_SPCO_Reg_Step $target an object with the method `translate_js_strings` and
1380
-     *                                                          `enqueue_styles_and_scripts`.
1381
-     * @return        void
1382
-     */
1383
-    public function add_styles_and_scripts($target)
1384
-    {
1385
-        // i18n
1386
-        $target->translate_js_strings();
1387
-        if ($this->checkout->admin_request) {
1388
-            add_action('admin_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1389
-        } else {
1390
-            add_action('wp_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1391
-        }
1392
-    }
1393
-
1394
-    /**
1395
-     *        translate_js_strings
1396
-     *
1397
-     * @return        void
1398
-     */
1399
-    public function translate_js_strings()
1400
-    {
1401
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1402
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1403
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
1404
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1405
-            'event_espresso'
1406
-        );
1407
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = esc_html__(
1408
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1409
-            'event_espresso'
1410
-        );
1411
-        EE_Registry::$i18n_js_strings['validation_error'] = esc_html__(
1412
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1413
-            'event_espresso'
1414
-        );
1415
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
1416
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1417
-            'event_espresso'
1418
-        );
1419
-        EE_Registry::$i18n_js_strings['reg_step_error'] = esc_html__(
1420
-            'This registration step could not be completed. Please refresh the page and try again.',
1421
-            'event_espresso'
1422
-        );
1423
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = esc_html__(
1424
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1425
-            'event_espresso'
1426
-        );
1427
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1428
-            esc_html__(
1429
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1430
-                'event_espresso'
1431
-            ),
1432
-            '<br/>',
1433
-            '<br/>'
1434
-        );
1435
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1436
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1437
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1438
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1439
-        EE_Registry::$i18n_js_strings['timer_years'] = esc_html__('years', 'event_espresso');
1440
-        EE_Registry::$i18n_js_strings['timer_months'] = esc_html__('months', 'event_espresso');
1441
-        EE_Registry::$i18n_js_strings['timer_weeks'] = esc_html__('weeks', 'event_espresso');
1442
-        EE_Registry::$i18n_js_strings['timer_days'] = esc_html__('days', 'event_espresso');
1443
-        EE_Registry::$i18n_js_strings['timer_hours'] = esc_html__('hours', 'event_espresso');
1444
-        EE_Registry::$i18n_js_strings['timer_minutes'] = esc_html__('minutes', 'event_espresso');
1445
-        EE_Registry::$i18n_js_strings['timer_seconds'] = esc_html__('seconds', 'event_espresso');
1446
-        EE_Registry::$i18n_js_strings['timer_year'] = esc_html__('year', 'event_espresso');
1447
-        EE_Registry::$i18n_js_strings['timer_month'] = esc_html__('month', 'event_espresso');
1448
-        EE_Registry::$i18n_js_strings['timer_week'] = esc_html__('week', 'event_espresso');
1449
-        EE_Registry::$i18n_js_strings['timer_day'] = esc_html__('day', 'event_espresso');
1450
-        EE_Registry::$i18n_js_strings['timer_hour'] = esc_html__('hour', 'event_espresso');
1451
-        EE_Registry::$i18n_js_strings['timer_minute'] = esc_html__('minute', 'event_espresso');
1452
-        EE_Registry::$i18n_js_strings['timer_second'] = esc_html__('second', 'event_espresso');
1453
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
1454
-        );
1455
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1456
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1457
-            true
1458
-        );
1459
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1460
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1461
-        );
1462
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1463
-            'M d, Y H:i:s',
1464
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1465
-        );
1466
-    }
1467
-
1468
-
1469
-    /**
1470
-     *    enqueue_styles_and_scripts
1471
-     *
1472
-     * @return        void
1473
-     * @throws EE_Error
1474
-     */
1475
-    public function enqueue_styles_and_scripts()
1476
-    {
1477
-        // load css
1478
-        wp_register_style(
1479
-            'single_page_checkout',
1480
-            SPCO_CSS_URL . 'single_page_checkout.css',
1481
-            array('espresso_default'),
1482
-            EVENT_ESPRESSO_VERSION
1483
-        );
1484
-        wp_enqueue_style('single_page_checkout');
1485
-        // load JS
1486
-        wp_register_script(
1487
-            'jquery_plugin',
1488
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1489
-            array('jquery'),
1490
-            '1.0.1',
1491
-            true
1492
-        );
1493
-        wp_register_script(
1494
-            'jquery_countdown',
1495
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1496
-            array('jquery_plugin'),
1497
-            '2.1.0',
1498
-            true
1499
-        );
1500
-        wp_register_script(
1501
-            'single_page_checkout',
1502
-            SPCO_JS_URL . 'single_page_checkout.js',
1503
-            array('espresso_core', 'underscore', 'ee_form_section_validation'),
1504
-            EVENT_ESPRESSO_VERSION,
1505
-            true
1506
-        );
1507
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1508
-            $this->checkout->registration_form->enqueue_js();
1509
-        }
1510
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1511
-            $this->checkout->current_step->reg_form->enqueue_js();
1512
-        }
1513
-        wp_enqueue_script('single_page_checkout');
1514
-        if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) {
1515
-            wp_enqueue_script('jquery_countdown');
1516
-        }
1517
-        /**
1518
-         * global action hook for enqueueing styles and scripts with
1519
-         * spco calls.
1520
-         */
1521
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1522
-        /**
1523
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1524
-         * The hook will end up being something like:
1525
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1526
-         */
1527
-        do_action(
1528
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1529
-            $this
1530
-        );
1531
-    }
1532
-
1533
-
1534
-    /**
1535
-     *    display the Registration Single Page Checkout Form
1536
-     *
1537
-     * @return    void
1538
-     * @throws EE_Error
1539
-     * @throws ReflectionException
1540
-     */
1541
-    private function _display_spco_reg_form()
1542
-    {
1543
-        // if registering via the admin, just display the reg form for the current step
1544
-        if ($this->checkout->admin_request) {
1545
-            EED_Single_Page_Checkout::getResponse()->addOutput($this->checkout->current_step->display_reg_form());
1546
-        } else {
1547
-            // add powered by EE msg
1548
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1549
-            $empty_cart = count(
1550
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1551
-            ) < 1;
1552
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1553
-            $cookies_not_set_msg = '';
1554
-            if ($empty_cart) {
1555
-                $cookies_not_set_msg = apply_filters(
1556
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1557
-                    sprintf(
1558
-                        esc_html__(
1559
-                            '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1560
-                            'event_espresso'
1561
-                        ),
1562
-                        '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1563
-                        '</div>',
1564
-                        '<h6 class="important-notice">',
1565
-                        '</h6>',
1566
-                        '<p>',
1567
-                        '</p>',
1568
-                        '<br />',
1569
-                        '<a href="https://www.whatismybrowser.com/guides/how-to-enable-cookies/" target="_blank" rel="noopener noreferrer">',
1570
-                        '</a>'
1571
-                    )
1572
-                );
1573
-            }
1574
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1575
-                array(
1576
-                    'name'            => 'single-page-checkout',
1577
-                    'html_id'         => 'ee-single-page-checkout-dv',
1578
-                    'layout_strategy' =>
1579
-                        new EE_Template_Layout(
1580
-                            array(
1581
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1582
-                                'template_args'        => array(
1583
-                                    'empty_cart'              => $empty_cart,
1584
-                                    'revisit'                 => $this->checkout->revisit,
1585
-                                    'reg_steps'               => $this->checkout->reg_steps,
1586
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1587
-                                        ? $this->checkout->next_step->slug()
1588
-                                        : '',
1589
-                                    'empty_msg'               => apply_filters(
1590
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1591
-                                        sprintf(
1592
-                                            esc_html__(
1593
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1594
-                                                'event_espresso'
1595
-                                            ),
1596
-                                            '<a href="'
1597
-                                            . get_post_type_archive_link('espresso_events')
1598
-                                            . '" title="',
1599
-                                            '">',
1600
-                                            '</a>'
1601
-                                        )
1602
-                                    ),
1603
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1604
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1605
-                                    'session_expiration'      => gmdate(
1606
-                                        'M d, Y H:i:s',
1607
-                                        EE_Registry::instance()->SSN->expiration()
1608
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1609
-                                    ),
1610
-                                ),
1611
-                            )
1612
-                        ),
1613
-                )
1614
-            );
1615
-            // load template and add to output sent that gets filtered into the_content()
1616
-            EED_Single_Page_Checkout::getResponse()->addOutput($this->checkout->registration_form->get_html());
1617
-        }
1618
-    }
1619
-
1620
-
1621
-    /**
1622
-     *    add_extra_finalize_registration_inputs
1623
-     *
1624
-     * @param $next_step
1625
-     * @internal  param string $label
1626
-     * @return void
1627
-     */
1628
-    public function add_extra_finalize_registration_inputs($next_step)
1629
-    {
1630
-        if ($next_step === 'finalize_registration') {
1631
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1632
-        }
1633
-    }
1634
-
1635
-
1636
-    /**
1637
-     *    display_registration_footer
1638
-     *
1639
-     * @return    string
1640
-     */
1641
-    public static function display_registration_footer()
1642
-    {
1643
-        if (
1644
-            apply_filters(
1645
-                'FHEE__EE_Front__Controller__show_reg_footer',
1646
-                EE_Registry::instance()->CFG->admin->show_reg_footer
1647
-            )
1648
-        ) {
1649
-            add_filter(
1650
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1651
-                function ($url) {
1652
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1653
-                }
1654
-            );
1655
-            echo apply_filters(
1656
-                'FHEE__EE_Front_Controller__display_registration_footer',
1657
-                EEH_Template::powered_by_event_espresso(
1658
-                    '',
1659
-                    'espresso-registration-footer-dv',
1660
-                    array('utm_content' => 'registration_checkout')
1661
-                )
1662
-            );
1663
-        }
1664
-        return '';
1665
-    }
1666
-
1667
-
1668
-    /**
1669
-     *    unlock_transaction
1670
-     *
1671
-     * @return    void
1672
-     * @throws EE_Error
1673
-     * @throws ReflectionException
1674
-     */
1675
-    public function unlock_transaction()
1676
-    {
1677
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1678
-            $this->checkout->transaction->unlock();
1679
-        }
1680
-    }
1681
-
1682
-
1683
-    /**
1684
-     *        _setup_redirect
1685
-     *
1686
-     * @return void
1687
-     */
1688
-    private function _setup_redirect()
1689
-    {
1690
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1691
-            $this->checkout->redirect = true;
1692
-            if (empty($this->checkout->redirect_url)) {
1693
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1694
-            }
1695
-            $this->checkout->redirect_url = apply_filters(
1696
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1697
-                $this->checkout->redirect_url,
1698
-                $this->checkout
1699
-            );
1700
-        }
1701
-    }
1702
-
1703
-
1704
-    /**
1705
-     *   handle ajax message responses and redirects
1706
-     *
1707
-     * @return void
1708
-     * @throws EE_Error
1709
-     * @throws ReflectionException
1710
-     */
1711
-    public function go_to_next_step()
1712
-    {
1713
-        if ($this->request->isAjax()) {
1714
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1715
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1716
-        }
1717
-        $this->unlock_transaction();
1718
-        // just return for these conditions
1719
-        if (
1720
-            $this->checkout->admin_request
1721
-            || $this->checkout->action === 'redirect_form'
1722
-            || $this->checkout->action === 'update_checkout'
1723
-        ) {
1724
-            return;
1725
-        }
1726
-        // AJAX response
1727
-        $this->_handle_json_response();
1728
-        // redirect to next step or the Thank You page
1729
-        $this->_handle_html_redirects();
1730
-        // hmmm... must be something wrong, so let's just display the form again !
1731
-        $this->_display_spco_reg_form();
1732
-    }
1733
-
1734
-
1735
-    /**
1736
-     *   _handle_json_response
1737
-     *
1738
-     * @return void
1739
-     * @throws EE_Error
1740
-     */
1741
-    protected function _handle_json_response()
1742
-    {
1743
-        // if this is an ajax request
1744
-        if ($this->request->isAjax()) {
1745
-            $this->checkout->json_response->set_registration_time_limit(
1746
-                $this->checkout->get_registration_time_limit()
1747
-            );
1748
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1749
-            // just send the ajax (
1750
-            $json_response = apply_filters(
1751
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1752
-                $this->checkout->json_response
1753
-            );
1754
-            echo ($json_response);
1755
-            exit();
1756
-        }
1757
-    }
1758
-
1759
-
1760
-    /**
1761
-     *   _handle_redirects
1762
-     *
1763
-     * @return void
1764
-     */
1765
-    protected function _handle_html_redirects()
1766
-    {
1767
-        // going somewhere ?
1768
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1769
-            // store notices in a transient
1770
-            EE_Error::get_notices(false, true);
1771
-            wp_safe_redirect($this->checkout->redirect_url);
1772
-            exit();
1773
-        }
1774
-    }
1775
-
1776
-
1777
-    /**
1778
-     *   set_checkout_anchor
1779
-     *
1780
-     * @return void
1781
-     */
1782
-    public function set_checkout_anchor()
1783
-    {
1784
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1785
-    }
1786
-
1787
-    /**
1788
-     *    getRegistrationExpirationNotice
1789
-     *
1790
-     * @since     4.9.59.p
1791
-     * @return    string
1792
-     */
1793
-    public static function getRegistrationExpirationNotice()
1794
-    {
1795
-        return sprintf(
1796
-            esc_html__(
1797
-                '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1798
-                'event_espresso'
1799
-            ),
1800
-            '<h4 class="important-notice">',
1801
-            '</h4>',
1802
-            '<br />',
1803
-            '<p>',
1804
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1805
-            '">',
1806
-            '</a>',
1807
-            '</p>'
1808
-        );
1809
-    }
22
+	/**
23
+	 * $_initialized - has the SPCO controller already been initialized ?
24
+	 *
25
+	 * @var bool $_initialized
26
+	 */
27
+	private static $_initialized = false;
28
+
29
+
30
+	/**
31
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
32
+	 *
33
+	 * @var bool $_valid_checkout
34
+	 */
35
+	private static $_checkout_verified = true;
36
+
37
+	/**
38
+	 *    $_reg_steps_array - holds initial array of reg steps
39
+	 *
40
+	 * @var array $_reg_steps_array
41
+	 */
42
+	private static $_reg_steps_array = array();
43
+
44
+	/**
45
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
46
+	 *
47
+	 * @var EE_Checkout $checkout
48
+	 */
49
+	public $checkout;
50
+
51
+	/**
52
+	 * @var RequestInterface $request
53
+	 */
54
+	protected $request;
55
+
56
+
57
+	/**
58
+	 * @return EED_Single_Page_Checkout|EED_Module
59
+	 * @throws EE_Error
60
+	 * @throws ReflectionException
61
+	 */
62
+	public static function instance()
63
+	{
64
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
65
+		return parent::get_instance(__CLASS__);
66
+	}
67
+
68
+
69
+	/**
70
+	 * @return EE_CART
71
+	 */
72
+	public function cart()
73
+	{
74
+		return $this->checkout->cart;
75
+	}
76
+
77
+
78
+	/**
79
+	 * @return RequestInterface
80
+	 * @since   4.10.14.p
81
+	 */
82
+	public static function getRequest()
83
+	{
84
+		return LoaderFactory::getLoader()->getShared(RequestInterface::class);
85
+	}
86
+
87
+
88
+	/**
89
+	 * @return EE_Transaction
90
+	 */
91
+	public function transaction()
92
+	{
93
+		return $this->checkout->transaction;
94
+	}
95
+
96
+
97
+	/**
98
+	 *    set_hooks - for hooking into EE Core, other modules, etc
99
+	 *
100
+	 * @return    void
101
+	 * @throws EE_Error
102
+	 */
103
+	public static function set_hooks()
104
+	{
105
+		EED_Single_Page_Checkout::set_definitions();
106
+	}
107
+
108
+
109
+	/**
110
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
111
+	 *
112
+	 * @return    void
113
+	 * @throws EE_Error
114
+	 */
115
+	public static function set_hooks_admin()
116
+	{
117
+		EED_Single_Page_Checkout::set_definitions();
118
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
119
+			return;
120
+		}
121
+		// going to start an output buffer in case anything gets accidentally output
122
+		// that might disrupt our JSON response
123
+		ob_start();
124
+		EED_Single_Page_Checkout::load_reg_steps();
125
+		// set ajax hooks
126
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
127
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
128
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
129
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
130
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
131
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
132
+	}
133
+
134
+
135
+	/**
136
+	 *    process ajax request
137
+	 *
138
+	 * @param string $ajax_action
139
+	 * @throws EE_Error
140
+	 * @throws ReflectionException
141
+	 */
142
+	public static function process_ajax_request($ajax_action)
143
+	{
144
+		$request = EED_Single_Page_Checkout::getRequest();
145
+		$request->setRequestParam('action', $ajax_action);
146
+		EED_Single_Page_Checkout::instance()->_initialize();
147
+	}
148
+
149
+
150
+	/**
151
+	 * ajax display registration step
152
+	 *
153
+	 * @throws EE_Error
154
+	 * @throws ReflectionException
155
+	 */
156
+	public static function display_reg_step()
157
+	{
158
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
159
+	}
160
+
161
+
162
+	/**
163
+	 * ajax process registration step
164
+	 *
165
+	 * @throws EE_Error
166
+	 * @throws ReflectionException
167
+	 */
168
+	public static function process_reg_step()
169
+	{
170
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
171
+	}
172
+
173
+
174
+	/**
175
+	 * ajax process registration step
176
+	 *
177
+	 * @throws EE_Error
178
+	 * @throws ReflectionException
179
+	 */
180
+	public static function update_reg_step()
181
+	{
182
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
183
+	}
184
+
185
+
186
+	/**
187
+	 * update_checkout
188
+	 *
189
+	 * @return void
190
+	 * @throws ReflectionException
191
+	 * @throws EE_Error
192
+	 */
193
+	public static function update_checkout()
194
+	{
195
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
196
+	}
197
+
198
+
199
+	/**
200
+	 * @return void
201
+	 * @deprecated 4.10.14.p
202
+	 */
203
+	public static function load_request_handler()
204
+	{
205
+	}
206
+
207
+
208
+	/**
209
+	 *    set_definitions
210
+	 *
211
+	 * @return    void
212
+	 * @throws EE_Error
213
+	 */
214
+	public static function set_definitions()
215
+	{
216
+		if (defined('SPCO_BASE_PATH')) {
217
+			return;
218
+		}
219
+		define(
220
+			'SPCO_BASE_PATH',
221
+			rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
222
+		);
223
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css/');
224
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img/');
225
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js/');
226
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc/');
227
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps/');
228
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates/');
229
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
230
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
231
+		);
232
+	}
233
+
234
+
235
+	/**
236
+	 * load_reg_steps
237
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
238
+	 *
239
+	 * @throws EE_Error
240
+	 */
241
+	public static function load_reg_steps()
242
+	{
243
+		static $reg_steps_loaded = false;
244
+		if ($reg_steps_loaded) {
245
+			return;
246
+		}
247
+		// filter list of reg_steps
248
+		$reg_steps_to_load = (array) apply_filters(
249
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
250
+			EED_Single_Page_Checkout::get_reg_steps()
251
+		);
252
+		// sort by key (order)
253
+		ksort($reg_steps_to_load);
254
+		// loop through folders
255
+		foreach ($reg_steps_to_load as $order => $reg_step) {
256
+			// we need a
257
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
258
+				// copy over to the reg_steps_array
259
+				EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
260
+				// register custom key route for each reg step
261
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
262
+				EE_Config::register_route(
263
+					$reg_step['slug'],
264
+					'EED_Single_Page_Checkout',
265
+					'run',
266
+					'step'
267
+				);
268
+				// add AJAX or other hooks
269
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
270
+					// setup autoloaders if necessary
271
+					if (! class_exists($reg_step['class_name'])) {
272
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
273
+							$reg_step['file_path'],
274
+							true
275
+						);
276
+					}
277
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
278
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
279
+					}
280
+				}
281
+			}
282
+		}
283
+		$reg_steps_loaded = true;
284
+	}
285
+
286
+
287
+	/**
288
+	 *    get_reg_steps
289
+	 *
290
+	 * @return    array
291
+	 */
292
+	public static function get_reg_steps()
293
+	{
294
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
295
+		if (empty($reg_steps)) {
296
+			$reg_steps = array(
297
+				10  => array(
298
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
299
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
300
+					'slug'       => 'attendee_information',
301
+					'has_hooks'  => false,
302
+				),
303
+				30  => array(
304
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
305
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
306
+					'slug'       => 'payment_options',
307
+					'has_hooks'  => true,
308
+				),
309
+				999 => array(
310
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
311
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
312
+					'slug'       => 'finalize_registration',
313
+					'has_hooks'  => false,
314
+				),
315
+			);
316
+		}
317
+		return $reg_steps;
318
+	}
319
+
320
+
321
+	/**
322
+	 *    registration_checkout_for_admin
323
+	 *
324
+	 * @return    string
325
+	 * @throws EE_Error
326
+	 * @throws ReflectionException
327
+	 */
328
+	public static function registration_checkout_for_admin()
329
+	{
330
+		$request = EED_Single_Page_Checkout::getRequest();
331
+		$request->setRequestParam('step', 'attendee_information');
332
+		$request->setRequestParam('action', 'display_spco_reg_step');
333
+		$request->setRequestParam('process_form_submission', false);
334
+		EED_Single_Page_Checkout::instance()->_initialize();
335
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
336
+		return EED_Single_Page_Checkout::getResponse()->getOutput();
337
+	}
338
+
339
+
340
+	/**
341
+	 * process_registration_from_admin
342
+	 *
343
+	 * @return EE_Transaction
344
+	 * @throws EE_Error
345
+	 * @throws ReflectionException
346
+	 */
347
+	public static function process_registration_from_admin()
348
+	{
349
+		$request = EED_Single_Page_Checkout::getRequest();
350
+		$request->setRequestParam('step', 'attendee_information');
351
+		$request->setRequestParam('action', 'process_reg_step');
352
+		$request->setRequestParam('process_form_submission', true);
353
+		EED_Single_Page_Checkout::instance()->_initialize();
354
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
355
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
356
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
357
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
358
+				if ($final_reg_step->process_reg_step()) {
359
+					$final_reg_step->set_completed();
360
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
361
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
362
+				}
363
+			}
364
+		}
365
+		return null;
366
+	}
367
+
368
+
369
+	/**
370
+	 *    run
371
+	 *
372
+	 * @param WP_Query $WP
373
+	 * @return    void
374
+	 */
375
+	public function run($WP)
376
+	{
377
+		if (
378
+			$WP instanceof WP_Query
379
+			&& $WP->is_main_query()
380
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
381
+			&& $this->_is_reg_checkout()
382
+		) {
383
+			$this->_initialize();
384
+		}
385
+	}
386
+
387
+
388
+	/**
389
+	 * determines whether current url matches reg page url
390
+	 *
391
+	 * @return bool
392
+	 */
393
+	protected function _is_reg_checkout()
394
+	{
395
+		// get current permalink for reg page without any extra query args
396
+		$reg_page_url = get_permalink(EE_Config::instance()->core->reg_page_id);
397
+		// get request URI for current request, but without the scheme or host
398
+		$current_request_uri = EEH_URL::filter_input_server_url();
399
+		$current_request_uri = html_entity_decode($current_request_uri);
400
+		// get array of query args from the current request URI
401
+		$query_args = EEH_URL::get_query_string($current_request_uri);
402
+		// grab page id if it is set
403
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
404
+		// and remove the page id from the query args (we will re-add it later)
405
+		unset($query_args['page_id']);
406
+		// now strip all query args from current request URI
407
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
408
+		// and re-add the page id if it was set
409
+		if ($page_id) {
410
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
411
+		}
412
+		// remove slashes and ?
413
+		$current_request_uri = trim($current_request_uri, '?/');
414
+		// is current request URI part of the known full reg page URL ?
415
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
416
+	}
417
+
418
+
419
+	/**
420
+	 * @param WP_Query $wp_query
421
+	 * @return    void
422
+	 * @throws EE_Error
423
+	 * @throws ReflectionException
424
+	 */
425
+	public static function init($wp_query)
426
+	{
427
+		EED_Single_Page_Checkout::instance()->run($wp_query);
428
+	}
429
+
430
+
431
+	/**
432
+	 *    _initialize - initial module setup
433
+	 *
434
+	 * @return    void
435
+	 */
436
+	private function _initialize()
437
+	{
438
+		// ensure SPCO doesn't run twice
439
+		if (EED_Single_Page_Checkout::$_initialized) {
440
+			return;
441
+		}
442
+		try {
443
+			$this->request = EED_Single_Page_Checkout::getRequest();
444
+			EED_Single_Page_Checkout::load_reg_steps();
445
+			$this->_verify_session();
446
+			// setup the EE_Checkout object
447
+			$this->checkout = $this->_initialize_checkout();
448
+			// filter checkout
449
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
450
+			// get the $_GET
451
+			$this->_get_request_vars();
452
+			if ($this->_block_bots()) {
453
+				return;
454
+			}
455
+			// filter continue_reg
456
+			$this->checkout->continue_reg = apply_filters(
457
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
458
+				true,
459
+				$this->checkout
460
+			);
461
+			// load the reg steps array
462
+			if (! $this->_load_and_instantiate_reg_steps()) {
463
+				EED_Single_Page_Checkout::$_initialized = true;
464
+				return;
465
+			}
466
+			// set the current step
467
+			$this->checkout->set_current_step($this->checkout->step);
468
+			// and the next step
469
+			$this->checkout->set_next_step();
470
+			// verify that everything has been setup correctly
471
+			if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
472
+				EED_Single_Page_Checkout::$_initialized = true;
473
+				return;
474
+			}
475
+			// lock the transaction
476
+			$this->checkout->transaction->lock();
477
+			// make sure all of our cached objects are added to their respective model entity mappers
478
+			$this->checkout->refresh_all_entities();
479
+			// set amount owing
480
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
481
+			// initialize each reg step, which gives them the chance to potentially alter the process
482
+			$this->_initialize_reg_steps();
483
+			// DEBUG LOG
484
+			// $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
485
+			// get reg form
486
+			if (! $this->_check_form_submission()) {
487
+				EED_Single_Page_Checkout::$_initialized = true;
488
+				return;
489
+			}
490
+			// checkout the action!!!
491
+			$this->_process_form_action();
492
+			// add some style and make it dance
493
+			$this->add_styles_and_scripts($this);
494
+			// kk... SPCO has successfully run
495
+			EED_Single_Page_Checkout::$_initialized = true;
496
+			// set no cache headers and constants
497
+			EE_System::do_not_cache();
498
+			// add anchor
499
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
500
+			// remove transaction lock
501
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
502
+		} catch (Exception $e) {
503
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
504
+		}
505
+	}
506
+
507
+
508
+	/**
509
+	 *    _verify_session
510
+	 * checks that the session is valid and not expired
511
+	 *
512
+	 * @throws EE_Error
513
+	 * @throws ReflectionException
514
+	 */
515
+	private function _verify_session()
516
+	{
517
+		if (! EE_Registry::instance()->SSN instanceof EE_Session) {
518
+			throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso'));
519
+		}
520
+		$clear_session_requested = $this->request->getRequestParam('clear_session', false, 'bool');
521
+		// is session still valid ?
522
+		if (
523
+			$clear_session_requested
524
+			|| (
525
+				EE_Registry::instance()->SSN->expired()
526
+				&& $this->request->getRequestParam('e_reg_url_link') === ''
527
+			)
528
+		) {
529
+			$this->checkout = new EE_Checkout();
530
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
531
+			// EE_Registry::instance()->SSN->reset_cart();
532
+			// EE_Registry::instance()->SSN->reset_checkout();
533
+			// EE_Registry::instance()->SSN->reset_transaction();
534
+			if (! $clear_session_requested) {
535
+				EE_Error::add_attention(
536
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
537
+					__FILE__,
538
+					__FUNCTION__,
539
+					__LINE__
540
+				);
541
+			}
542
+			// EE_Registry::instance()->SSN->reset_expired();
543
+		}
544
+	}
545
+
546
+
547
+	/**
548
+	 *    _initialize_checkout
549
+	 * loads and instantiates EE_Checkout
550
+	 *
551
+	 * @return EE_Checkout
552
+	 * @throws EE_Error
553
+	 * @throws ReflectionException
554
+	 */
555
+	private function _initialize_checkout()
556
+	{
557
+		// look in session for existing checkout
558
+		/** @type EE_Checkout $checkout */
559
+		$checkout = EE_Registry::instance()->SSN->checkout();
560
+		// verify
561
+		if (! $checkout instanceof EE_Checkout) {
562
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
563
+			$checkout = EE_Registry::instance()->load_file(
564
+				SPCO_INC_PATH,
565
+				'EE_Checkout',
566
+				'class',
567
+				array(),
568
+				false
569
+			);
570
+		} else {
571
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
572
+				$this->unlock_transaction();
573
+				wp_safe_redirect($checkout->redirect_url);
574
+				exit();
575
+			}
576
+		}
577
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
578
+		// verify again
579
+		if (! $checkout instanceof EE_Checkout) {
580
+			throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso'));
581
+		}
582
+		// reset anything that needs a clean slate for each request
583
+		$checkout->reset_for_current_request();
584
+		return $checkout;
585
+	}
586
+
587
+
588
+	/**
589
+	 *    _get_request_vars
590
+	 *
591
+	 * @return    void
592
+	 */
593
+	private function _get_request_vars()
594
+	{
595
+		// make sure this request is marked as belonging to EE
596
+		/** @var CurrentPage $current_page */
597
+		$current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
598
+		$current_page->setEspressoPage(true);
599
+		// which step is being requested ?
600
+		$this->checkout->step = $this->request->getRequestParam('step', $this->_get_first_step());
601
+		// which step is being edited ?
602
+		$this->checkout->edit_step = $this->request->getRequestParam('edit_step');
603
+		// and what we're doing on the current step
604
+		$this->checkout->action = $this->request->getRequestParam('action', 'display_spco_reg_step');
605
+		// timestamp
606
+		$this->checkout->uts = $this->request->getRequestParam('uts', 0, 'int');
607
+		// returning to edit ?
608
+		$this->checkout->reg_url_link = $this->request->getRequestParam('e_reg_url_link');
609
+		// add reg url link to registration query params
610
+		if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
611
+			$this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
612
+		}
613
+		// or some other kind of revisit ?
614
+		$this->checkout->revisit = $this->request->getRequestParam('revisit', false, 'bool');
615
+		// and whether or not to generate a reg form for this request
616
+		$this->checkout->generate_reg_form = $this->request->getRequestParam('generate_reg_form', true, 'bool');
617
+		// and whether or not to process a reg form submission for this request
618
+		$this->checkout->process_form_submission = $this->request->getRequestParam(
619
+			'process_form_submission',
620
+			$this->checkout->action === 'process_reg_step',
621
+			'bool'
622
+		);
623
+		$this->checkout->process_form_submission = filter_var(
624
+			$this->checkout->action !== 'display_spco_reg_step'
625
+				? $this->checkout->process_form_submission
626
+				: false,
627
+			FILTER_VALIDATE_BOOLEAN
628
+		);
629
+		// $this->_display_request_vars();
630
+	}
631
+
632
+
633
+	/**
634
+	 *  _display_request_vars
635
+	 *
636
+	 * @return    void
637
+	 */
638
+	protected function _display_request_vars()
639
+	{
640
+		if (! WP_DEBUG) {
641
+			return;
642
+		}
643
+		EEH_Debug_Tools::printr($this->request->requestParams(), 'requestParams', __FILE__, __LINE__);
644
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
645
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
646
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
647
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
648
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
649
+		EEH_Debug_Tools::printr(
650
+			$this->checkout->generate_reg_form,
651
+			'$this->checkout->generate_reg_form',
652
+			__FILE__,
653
+			__LINE__
654
+		);
655
+		EEH_Debug_Tools::printr(
656
+			$this->checkout->process_form_submission,
657
+			'$this->checkout->process_form_submission',
658
+			__FILE__,
659
+			__LINE__
660
+		);
661
+	}
662
+
663
+
664
+	/**
665
+	 * _block_bots
666
+	 * checks that the incoming request has either of the following set:
667
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
668
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
669
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
670
+	 * then where you coming from man?
671
+	 *
672
+	 * @return boolean
673
+	 */
674
+	private function _block_bots()
675
+	{
676
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
677
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
678
+			return true;
679
+		}
680
+		return false;
681
+	}
682
+
683
+
684
+	/**
685
+	 *    _get_first_step
686
+	 *  gets slug for first step in $_reg_steps_array
687
+	 *
688
+	 * @return    string
689
+	 */
690
+	private function _get_first_step()
691
+	{
692
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
693
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
694
+	}
695
+
696
+
697
+	/**
698
+	 * instantiates each reg step based on the loaded reg_steps array
699
+	 *
700
+	 * @return    bool
701
+	 * @throws EE_Error
702
+	 * @throws InvalidArgumentException
703
+	 * @throws InvalidDataTypeException
704
+	 * @throws InvalidInterfaceException
705
+	 * @throws ReflectionException
706
+	 */
707
+	private function _load_and_instantiate_reg_steps()
708
+	{
709
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
710
+		// have reg_steps already been instantiated ?
711
+		if (
712
+			empty($this->checkout->reg_steps)
713
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
714
+		) {
715
+			// if not, then loop through raw reg steps array
716
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
717
+				if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
718
+					return false;
719
+				}
720
+			}
721
+			if (isset($this->checkout->reg_steps['registration_confirmation'])) {
722
+				// skip the registration_confirmation page ?
723
+				if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
724
+					// just remove it from the reg steps array
725
+					$this->checkout->remove_reg_step('registration_confirmation', false);
726
+				} elseif (
727
+					EE_Registry::instance()->CFG->registration->reg_confirmation_last
728
+				) {
729
+					// set the order to something big like 100
730
+					$this->checkout->set_reg_step_order('registration_confirmation');
731
+				}
732
+			}
733
+			// filter the array for good luck
734
+			$this->checkout->reg_steps = apply_filters(
735
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
736
+				$this->checkout->reg_steps
737
+			);
738
+			// finally re-sort based on the reg step class order properties
739
+			$this->checkout->sort_reg_steps();
740
+		} else {
741
+			foreach ($this->checkout->reg_steps as $reg_step) {
742
+				// set all current step stati to FALSE
743
+				$reg_step->set_is_current_step(false);
744
+			}
745
+		}
746
+		if (empty($this->checkout->reg_steps)) {
747
+			EE_Error::add_error(
748
+				esc_html__('No Reg Steps were loaded..', 'event_espresso'),
749
+				__FILE__,
750
+				__FUNCTION__,
751
+				__LINE__
752
+			);
753
+			return false;
754
+		}
755
+		// make reg step details available to JS
756
+		$this->checkout->set_reg_step_JSON_info();
757
+		return true;
758
+	}
759
+
760
+
761
+	/**
762
+	 *     _load_and_instantiate_reg_step
763
+	 *
764
+	 * @param array $reg_step
765
+	 * @param int   $order
766
+	 * @return bool
767
+	 * @throws EE_Error
768
+	 * @throws ReflectionException
769
+	 */
770
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
771
+	{
772
+		// we need a file_path, class_name, and slug to add a reg step
773
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
774
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
775
+			if (
776
+				$this->checkout->reg_url_link
777
+				&& $this->checkout->step !== $reg_step['slug']
778
+				&& $reg_step['slug'] !== 'finalize_registration'
779
+				// normally at this point we would NOT load the reg step, but this filter can change that
780
+				&& apply_filters(
781
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
782
+					true,
783
+					$reg_step,
784
+					$this->checkout
785
+				)
786
+			) {
787
+				return true;
788
+			}
789
+
790
+			// instantiate step class using file path and class name
791
+			$reg_step_obj = EE_Registry::instance()->load_file(
792
+				$reg_step['file_path'],
793
+				$reg_step['class_name'],
794
+				'class',
795
+				[$this->checkout],
796
+				false
797
+			);
798
+			// did we gets the goods ?
799
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
800
+				// set reg step order based on config
801
+				$reg_step_obj->set_order($order);
802
+				// add instantiated reg step object to the master reg steps array
803
+				$this->checkout->add_reg_step($reg_step_obj);
804
+			} else {
805
+				EE_Error::add_error(
806
+					esc_html__('The current step could not be set.', 'event_espresso'),
807
+					__FILE__,
808
+					__FUNCTION__,
809
+					__LINE__
810
+				);
811
+				return false;
812
+			}
813
+		} else {
814
+			if (WP_DEBUG) {
815
+				EE_Error::add_error(
816
+					sprintf(
817
+						esc_html__(
818
+							'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
819
+							'event_espresso'
820
+						),
821
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
822
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
823
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
824
+						'<ul>',
825
+						'<li>',
826
+						'</li>',
827
+						'</ul>'
828
+					),
829
+					__FILE__,
830
+					__FUNCTION__,
831
+					__LINE__
832
+				);
833
+			}
834
+			return false;
835
+		}
836
+		return true;
837
+	}
838
+
839
+
840
+	/**
841
+	 * _verify_transaction_and_get_registrations
842
+	 *
843
+	 * @return bool
844
+	 * @throws EE_Error
845
+	 * @throws ReflectionException
846
+	 */
847
+	private function _verify_transaction_and_get_registrations()
848
+	{
849
+		// was there already a valid transaction in the checkout from the session ?
850
+		if (! $this->checkout->transaction instanceof EE_Transaction) {
851
+			// get transaction from db or session
852
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
853
+				? $this->_get_transaction_and_cart_for_previous_visit()
854
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
855
+			if (! $this->checkout->transaction instanceof EE_Transaction) {
856
+				EE_Error::add_error(
857
+					esc_html__(
858
+						'Your Registration and Transaction information could not be retrieved from the db.',
859
+						'event_espresso'
860
+					),
861
+					__FILE__,
862
+					__FUNCTION__,
863
+					__LINE__
864
+				);
865
+				$this->checkout->transaction = EE_Transaction::new_instance();
866
+				// add some style and make it dance
867
+				$this->add_styles_and_scripts($this);
868
+				EED_Single_Page_Checkout::$_initialized = true;
869
+				return false;
870
+			}
871
+			// and the registrations for the transaction
872
+			$this->_get_registrations($this->checkout->transaction);
873
+		}
874
+		return true;
875
+	}
876
+
877
+
878
+	/**
879
+	 * _get_transaction_and_cart_for_previous_visit
880
+	 *
881
+	 * @return EE_Transaction|null
882
+	 * @throws EE_Error
883
+	 * @throws ReflectionException
884
+	 */
885
+	private function _get_transaction_and_cart_for_previous_visit()
886
+	{
887
+		/** @var $TXN_model EEM_Transaction */
888
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
889
+		// because the reg_url_link is present in the request,
890
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
891
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
892
+		// verify transaction
893
+		if ($transaction instanceof EE_Transaction) {
894
+			// and get the cart that was used for that transaction
895
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
896
+			return $transaction;
897
+		}
898
+		EE_Error::add_error(
899
+			esc_html__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
900
+			__FILE__,
901
+			__FUNCTION__,
902
+			__LINE__
903
+		);
904
+		return null;
905
+	}
906
+
907
+
908
+	/**
909
+	 * _get_cart_for_transaction
910
+	 *
911
+	 * @param EE_Transaction $transaction
912
+	 * @return EE_Cart
913
+	 */
914
+	private function _get_cart_for_transaction($transaction)
915
+	{
916
+		return $this->checkout->get_cart_for_transaction($transaction);
917
+	}
918
+
919
+
920
+	/**
921
+	 * get_cart_for_transaction
922
+	 *
923
+	 * @param EE_Transaction $transaction
924
+	 * @return EE_Cart
925
+	 */
926
+	public function get_cart_for_transaction(EE_Transaction $transaction)
927
+	{
928
+		return $this->checkout->get_cart_for_transaction($transaction);
929
+	}
930
+
931
+
932
+	/**
933
+	 * _get_transaction_and_cart_for_current_session
934
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
935
+	 *
936
+	 * @return EE_Transaction
937
+	 * @throws EE_Error
938
+	 * @throws ReflectionException
939
+	 */
940
+	private function _get_cart_for_current_session_and_setup_new_transaction()
941
+	{
942
+		//  if there's no transaction, then this is the FIRST visit to SPCO
943
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
944
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
945
+		// and then create a new transaction
946
+		$transaction = $this->_initialize_transaction();
947
+		// verify transaction
948
+		if ($transaction instanceof EE_Transaction) {
949
+			// save it so that we have an ID for other objects to use
950
+			$transaction->save();
951
+			// and save TXN data to the cart
952
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
953
+		} else {
954
+			EE_Error::add_error(
955
+				esc_html__('A Valid Transaction could not be initialized.', 'event_espresso'),
956
+				__FILE__,
957
+				__FUNCTION__,
958
+				__LINE__
959
+			);
960
+		}
961
+		return $transaction;
962
+	}
963
+
964
+
965
+	/**
966
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
967
+	 *
968
+	 * @return EE_Transaction|null
969
+	 */
970
+	private function _initialize_transaction()
971
+	{
972
+		try {
973
+			// ensure cart totals have been calculated
974
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
975
+			// grab the cart grand total
976
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
977
+			// create new TXN
978
+			$transaction = EE_Transaction::new_instance(
979
+				array(
980
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
981
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
982
+					'TXN_paid'      => 0,
983
+					'STS_ID'        => EEM_Transaction::failed_status_code,
984
+				)
985
+			);
986
+			// save it so that we have an ID for other objects to use
987
+			$transaction->save();
988
+			// set cron job for following up on TXNs after their session has expired
989
+			EE_Cron_Tasks::schedule_expired_transaction_check(
990
+				EE_Registry::instance()->SSN->expiration() + 1,
991
+				$transaction->ID()
992
+			);
993
+			return $transaction;
994
+		} catch (Exception $e) {
995
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
996
+		}
997
+		return null;
998
+	}
999
+
1000
+
1001
+	/**
1002
+	 * _get_registrations
1003
+	 *
1004
+	 * @param EE_Transaction $transaction
1005
+	 * @return void
1006
+	 * @throws EE_Error
1007
+	 * @throws ReflectionException
1008
+	 */
1009
+	private function _get_registrations(EE_Transaction $transaction)
1010
+	{
1011
+		// first step: grab the registrants  { : o
1012
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params);
1013
+		$this->checkout->total_ticket_count = count($registrations);
1014
+		// verify registrations have been set
1015
+		if (empty($registrations)) {
1016
+			// if no cached registrations, then check the db
1017
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params);
1018
+			// still nothing ? well as long as this isn't a revisit
1019
+			if (empty($registrations) && ! $this->checkout->revisit) {
1020
+				// generate new registrations from scratch
1021
+				$registrations = $this->_initialize_registrations($transaction);
1022
+			}
1023
+		}
1024
+		// sort by their original registration order
1025
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1026
+		// then loop thru the array
1027
+		foreach ($registrations as $registration) {
1028
+			// verify each registration
1029
+			if ($registration instanceof EE_Registration) {
1030
+				// we display all attendee info for the primary registrant
1031
+				if (
1032
+					$this->checkout->reg_url_link === $registration->reg_url_link()
1033
+					&& $registration->is_primary_registrant()
1034
+				) {
1035
+					$this->checkout->primary_revisit = true;
1036
+					break;
1037
+				}
1038
+				if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1039
+					// but hide info if it doesn't belong to you
1040
+					$transaction->clear_cache('Registration', $registration->ID());
1041
+					$this->checkout->total_ticket_count--;
1042
+				}
1043
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1044
+			}
1045
+		}
1046
+	}
1047
+
1048
+
1049
+	/**
1050
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1051
+	 *
1052
+	 * @param EE_Transaction $transaction
1053
+	 * @return    array
1054
+	 * @throws EE_Error
1055
+	 * @throws ReflectionException
1056
+	 */
1057
+	private function _initialize_registrations(EE_Transaction $transaction)
1058
+	{
1059
+		$att_nmbr = 0;
1060
+		$registrations = array();
1061
+		if ($transaction instanceof EE_Transaction) {
1062
+			/** @type EE_Registration_Processor $registration_processor */
1063
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1064
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1065
+			// now let's add the cart items to the $transaction
1066
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1067
+				// do the following for each ticket of this type they selected
1068
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1069
+					$att_nmbr++;
1070
+					/** @var CreateRegistrationCommand $CreateRegistrationCommand */
1071
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1072
+						CreateRegistrationCommand::class,
1073
+						[
1074
+							$transaction,
1075
+							$line_item,
1076
+							$att_nmbr,
1077
+							$this->checkout->total_ticket_count,
1078
+						]
1079
+					);
1080
+					// override capabilities for frontend registrations
1081
+					if ($this->request->isFrontend()) {
1082
+						$CreateRegistrationCommand->setCapCheck(
1083
+							new PublicCapabilities('', 'create_new_registration')
1084
+						);
1085
+					}
1086
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1087
+					if (! $registration instanceof EE_Registration) {
1088
+						throw new InvalidEntityException($registration, 'EE_Registration');
1089
+					}
1090
+					$registrations[ $registration->ID() ] = $registration;
1091
+				}
1092
+			}
1093
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1094
+		}
1095
+		return $registrations;
1096
+	}
1097
+
1098
+
1099
+	/**
1100
+	 * sorts registrations by REG_count
1101
+	 *
1102
+	 * @param EE_Registration $reg_A
1103
+	 * @param EE_Registration $reg_B
1104
+	 * @return int
1105
+	 */
1106
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1107
+	{
1108
+		// this shouldn't ever happen within the same TXN, but oh well
1109
+		if ($reg_A->count() === $reg_B->count()) {
1110
+			return 0;
1111
+		}
1112
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1113
+	}
1114
+
1115
+
1116
+	/**
1117
+	 *    _final_verifications
1118
+	 * just makes sure that everything is set up correctly before proceeding
1119
+	 *
1120
+	 * @return    bool
1121
+	 * @throws EE_Error
1122
+	 * @throws ReflectionException
1123
+	 */
1124
+	private function _final_verifications()
1125
+	{
1126
+		// filter checkout
1127
+		$this->checkout = apply_filters(
1128
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1129
+			$this->checkout
1130
+		);
1131
+		// verify that current step is still set correctly
1132
+		if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1133
+			EE_Error::add_error(
1134
+				esc_html__(
1135
+					'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.',
1136
+					'event_espresso'
1137
+				),
1138
+				__FILE__,
1139
+				__FUNCTION__,
1140
+				__LINE__
1141
+			);
1142
+			return false;
1143
+		}
1144
+		// if returning to SPCO, then verify that primary registrant is set
1145
+		if (! empty($this->checkout->reg_url_link)) {
1146
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1147
+			if (! $valid_registrant instanceof EE_Registration) {
1148
+				EE_Error::add_error(
1149
+					esc_html__(
1150
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.',
1151
+						'event_espresso'
1152
+					),
1153
+					__FILE__,
1154
+					__FUNCTION__,
1155
+					__LINE__
1156
+				);
1157
+				return false;
1158
+			}
1159
+			$valid_registrant = null;
1160
+			foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1161
+				if (
1162
+					$registration instanceof EE_Registration
1163
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1164
+				) {
1165
+					$valid_registrant = $registration;
1166
+				}
1167
+			}
1168
+			if (! $valid_registrant instanceof EE_Registration) {
1169
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1170
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1171
+					// clear the session, mark the checkout as unverified, and try again
1172
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1173
+					EED_Single_Page_Checkout::$_initialized = false;
1174
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1175
+					$this->_initialize();
1176
+					EE_Error::reset_notices();
1177
+					return false;
1178
+				}
1179
+				EE_Error::add_error(
1180
+					esc_html__(
1181
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1182
+						'event_espresso'
1183
+					),
1184
+					__FILE__,
1185
+					__FUNCTION__,
1186
+					__LINE__
1187
+				);
1188
+				return false;
1189
+			}
1190
+		}
1191
+		// now that things have been kinda sufficiently verified,
1192
+		// let's add the checkout to the session so that it's available to other systems
1193
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1194
+		return true;
1195
+	}
1196
+
1197
+
1198
+	/**
1199
+	 *    _initialize_reg_steps
1200
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1201
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1202
+	 *
1203
+	 * @param bool $reinitializing
1204
+	 * @throws EE_Error
1205
+	 */
1206
+	private function _initialize_reg_steps($reinitializing = false)
1207
+	{
1208
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1209
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1210
+		foreach ($this->checkout->reg_steps as $reg_step) {
1211
+			if (! $reg_step->initialize_reg_step()) {
1212
+				// if not initialized then maybe this step is being removed...
1213
+				if (! $reinitializing && $reg_step->is_current_step()) {
1214
+					// if it was the current step, then we need to start over here
1215
+					$this->_initialize_reg_steps(true);
1216
+					return;
1217
+				}
1218
+				continue;
1219
+			}
1220
+			// add css and JS for current step
1221
+			$this->add_styles_and_scripts($reg_step);
1222
+			if ($reg_step->is_current_step()) {
1223
+				// the text that appears on the reg step form submit button
1224
+				$reg_step->set_submit_button_text();
1225
+			}
1226
+		}
1227
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1228
+		do_action(
1229
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1230
+			$this->checkout->current_step
1231
+		);
1232
+	}
1233
+
1234
+
1235
+	/**
1236
+	 * _check_form_submission
1237
+	 *
1238
+	 * @return boolean
1239
+	 * @throws EE_Error
1240
+	 * @throws ReflectionException
1241
+	 */
1242
+	private function _check_form_submission()
1243
+	{
1244
+		// does this request require the reg form to be generated ?
1245
+		if ($this->checkout->generate_reg_form) {
1246
+			// ever heard that song by Blue Rodeo ?
1247
+			try {
1248
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1249
+				// if not displaying a form, then check for form submission
1250
+				if (
1251
+					$this->checkout->process_form_submission
1252
+					&& $this->checkout->current_step->reg_form->was_submitted()
1253
+				) {
1254
+					// clear out any old data in case this step is being run again
1255
+					$this->checkout->current_step->set_valid_data(array());
1256
+					// capture submitted form data
1257
+					$request_data = $this->request->requestParams();
1258
+					$this->checkout->current_step->reg_form->receive_form_submission(
1259
+						(array) apply_filters(
1260
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1261
+							$request_data,
1262
+							$this->checkout
1263
+						)
1264
+					);
1265
+					// validate submitted form data
1266
+					if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1267
+						// thou shall not pass !!!
1268
+						$this->checkout->continue_reg = false;
1269
+						// any form validation errors?
1270
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1271
+							EE_Error::add_error(
1272
+								$this->checkout->current_step->reg_form->submission_error_message(),
1273
+								__FILE__,
1274
+								__FUNCTION__,
1275
+								__LINE__
1276
+							);
1277
+						}
1278
+						// well not really... what will happen is
1279
+						// we'll just get redirected back to redo the current step
1280
+						$this->go_to_next_step();
1281
+						return false;
1282
+					}
1283
+				}
1284
+			} catch (EE_Error $e) {
1285
+				$e->get_error();
1286
+			}
1287
+		}
1288
+		return true;
1289
+	}
1290
+
1291
+
1292
+	/**
1293
+	 * _process_action
1294
+	 *
1295
+	 * @return void
1296
+	 * @throws EE_Error
1297
+	 * @throws ReflectionException
1298
+	 */
1299
+	private function _process_form_action()
1300
+	{
1301
+		// what cha wanna do?
1302
+		switch ($this->checkout->action) {
1303
+			// AJAX next step reg form
1304
+			case 'display_spco_reg_step':
1305
+				$this->checkout->redirect = false;
1306
+				if ($this->request->isAjax()) {
1307
+					$this->checkout->json_response->set_reg_step_html(
1308
+						$this->checkout->current_step->display_reg_form()
1309
+					);
1310
+				}
1311
+				break;
1312
+			default:
1313
+				// meh... do one of those other steps first
1314
+				if (
1315
+					! empty($this->checkout->action)
1316
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1317
+				) {
1318
+					// dynamically creates hook point like:
1319
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1320
+					do_action(
1321
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1322
+						$this->checkout->current_step
1323
+					);
1324
+					$process_reg_step = apply_filters(
1325
+						"AHEE__Single_Page_Checkout__process_reg_step__{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1326
+						true,
1327
+						$this->checkout->current_step,
1328
+						$this
1329
+					);
1330
+					// call action on current step
1331
+					if ($process_reg_step && call_user_func([$this->checkout->current_step, $this->checkout->action])) {
1332
+						// good registrant, you get to proceed
1333
+						if (
1334
+							$this->checkout->current_step->success_message() !== ''
1335
+							&& apply_filters(
1336
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1337
+								false
1338
+							)
1339
+						) {
1340
+							EE_Error::add_success(
1341
+								$this->checkout->current_step->success_message()
1342
+								. '<br />' . $this->checkout->next_step->_instructions()
1343
+							);
1344
+						}
1345
+						// pack it up, pack it in...
1346
+						$this->_setup_redirect();
1347
+					}
1348
+					// dynamically creates hook point like:
1349
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1350
+					do_action(
1351
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1352
+						$this->checkout->current_step
1353
+					);
1354
+				} else {
1355
+					EE_Error::add_error(
1356
+						sprintf(
1357
+							esc_html__(
1358
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1359
+								'event_espresso'
1360
+							),
1361
+							$this->checkout->action,
1362
+							$this->checkout->current_step->name()
1363
+						),
1364
+						__FILE__,
1365
+						__FUNCTION__,
1366
+						__LINE__
1367
+					);
1368
+				}
1369
+			// end default
1370
+		}
1371
+		// store our progress so far
1372
+		$this->checkout->stash_transaction_and_checkout();
1373
+		// advance to the next step! If you pass GO, collect $200
1374
+		$this->go_to_next_step();
1375
+	}
1376
+
1377
+
1378
+	/**
1379
+	 * @param EED_Single_Page_Checkout|EE_SPCO_Reg_Step $target an object with the method `translate_js_strings` and
1380
+	 *                                                          `enqueue_styles_and_scripts`.
1381
+	 * @return        void
1382
+	 */
1383
+	public function add_styles_and_scripts($target)
1384
+	{
1385
+		// i18n
1386
+		$target->translate_js_strings();
1387
+		if ($this->checkout->admin_request) {
1388
+			add_action('admin_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1389
+		} else {
1390
+			add_action('wp_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1391
+		}
1392
+	}
1393
+
1394
+	/**
1395
+	 *        translate_js_strings
1396
+	 *
1397
+	 * @return        void
1398
+	 */
1399
+	public function translate_js_strings()
1400
+	{
1401
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1402
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1403
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
1404
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1405
+			'event_espresso'
1406
+		);
1407
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = esc_html__(
1408
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1409
+			'event_espresso'
1410
+		);
1411
+		EE_Registry::$i18n_js_strings['validation_error'] = esc_html__(
1412
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1413
+			'event_espresso'
1414
+		);
1415
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
1416
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1417
+			'event_espresso'
1418
+		);
1419
+		EE_Registry::$i18n_js_strings['reg_step_error'] = esc_html__(
1420
+			'This registration step could not be completed. Please refresh the page and try again.',
1421
+			'event_espresso'
1422
+		);
1423
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = esc_html__(
1424
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1425
+			'event_espresso'
1426
+		);
1427
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1428
+			esc_html__(
1429
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1430
+				'event_espresso'
1431
+			),
1432
+			'<br/>',
1433
+			'<br/>'
1434
+		);
1435
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1436
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1437
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1438
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1439
+		EE_Registry::$i18n_js_strings['timer_years'] = esc_html__('years', 'event_espresso');
1440
+		EE_Registry::$i18n_js_strings['timer_months'] = esc_html__('months', 'event_espresso');
1441
+		EE_Registry::$i18n_js_strings['timer_weeks'] = esc_html__('weeks', 'event_espresso');
1442
+		EE_Registry::$i18n_js_strings['timer_days'] = esc_html__('days', 'event_espresso');
1443
+		EE_Registry::$i18n_js_strings['timer_hours'] = esc_html__('hours', 'event_espresso');
1444
+		EE_Registry::$i18n_js_strings['timer_minutes'] = esc_html__('minutes', 'event_espresso');
1445
+		EE_Registry::$i18n_js_strings['timer_seconds'] = esc_html__('seconds', 'event_espresso');
1446
+		EE_Registry::$i18n_js_strings['timer_year'] = esc_html__('year', 'event_espresso');
1447
+		EE_Registry::$i18n_js_strings['timer_month'] = esc_html__('month', 'event_espresso');
1448
+		EE_Registry::$i18n_js_strings['timer_week'] = esc_html__('week', 'event_espresso');
1449
+		EE_Registry::$i18n_js_strings['timer_day'] = esc_html__('day', 'event_espresso');
1450
+		EE_Registry::$i18n_js_strings['timer_hour'] = esc_html__('hour', 'event_espresso');
1451
+		EE_Registry::$i18n_js_strings['timer_minute'] = esc_html__('minute', 'event_espresso');
1452
+		EE_Registry::$i18n_js_strings['timer_second'] = esc_html__('second', 'event_espresso');
1453
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
1454
+		);
1455
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1456
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1457
+			true
1458
+		);
1459
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1460
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1461
+		);
1462
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1463
+			'M d, Y H:i:s',
1464
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1465
+		);
1466
+	}
1467
+
1468
+
1469
+	/**
1470
+	 *    enqueue_styles_and_scripts
1471
+	 *
1472
+	 * @return        void
1473
+	 * @throws EE_Error
1474
+	 */
1475
+	public function enqueue_styles_and_scripts()
1476
+	{
1477
+		// load css
1478
+		wp_register_style(
1479
+			'single_page_checkout',
1480
+			SPCO_CSS_URL . 'single_page_checkout.css',
1481
+			array('espresso_default'),
1482
+			EVENT_ESPRESSO_VERSION
1483
+		);
1484
+		wp_enqueue_style('single_page_checkout');
1485
+		// load JS
1486
+		wp_register_script(
1487
+			'jquery_plugin',
1488
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1489
+			array('jquery'),
1490
+			'1.0.1',
1491
+			true
1492
+		);
1493
+		wp_register_script(
1494
+			'jquery_countdown',
1495
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1496
+			array('jquery_plugin'),
1497
+			'2.1.0',
1498
+			true
1499
+		);
1500
+		wp_register_script(
1501
+			'single_page_checkout',
1502
+			SPCO_JS_URL . 'single_page_checkout.js',
1503
+			array('espresso_core', 'underscore', 'ee_form_section_validation'),
1504
+			EVENT_ESPRESSO_VERSION,
1505
+			true
1506
+		);
1507
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1508
+			$this->checkout->registration_form->enqueue_js();
1509
+		}
1510
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1511
+			$this->checkout->current_step->reg_form->enqueue_js();
1512
+		}
1513
+		wp_enqueue_script('single_page_checkout');
1514
+		if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) {
1515
+			wp_enqueue_script('jquery_countdown');
1516
+		}
1517
+		/**
1518
+		 * global action hook for enqueueing styles and scripts with
1519
+		 * spco calls.
1520
+		 */
1521
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1522
+		/**
1523
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1524
+		 * The hook will end up being something like:
1525
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1526
+		 */
1527
+		do_action(
1528
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1529
+			$this
1530
+		);
1531
+	}
1532
+
1533
+
1534
+	/**
1535
+	 *    display the Registration Single Page Checkout Form
1536
+	 *
1537
+	 * @return    void
1538
+	 * @throws EE_Error
1539
+	 * @throws ReflectionException
1540
+	 */
1541
+	private function _display_spco_reg_form()
1542
+	{
1543
+		// if registering via the admin, just display the reg form for the current step
1544
+		if ($this->checkout->admin_request) {
1545
+			EED_Single_Page_Checkout::getResponse()->addOutput($this->checkout->current_step->display_reg_form());
1546
+		} else {
1547
+			// add powered by EE msg
1548
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1549
+			$empty_cart = count(
1550
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1551
+			) < 1;
1552
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1553
+			$cookies_not_set_msg = '';
1554
+			if ($empty_cart) {
1555
+				$cookies_not_set_msg = apply_filters(
1556
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1557
+					sprintf(
1558
+						esc_html__(
1559
+							'%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1560
+							'event_espresso'
1561
+						),
1562
+						'<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1563
+						'</div>',
1564
+						'<h6 class="important-notice">',
1565
+						'</h6>',
1566
+						'<p>',
1567
+						'</p>',
1568
+						'<br />',
1569
+						'<a href="https://www.whatismybrowser.com/guides/how-to-enable-cookies/" target="_blank" rel="noopener noreferrer">',
1570
+						'</a>'
1571
+					)
1572
+				);
1573
+			}
1574
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1575
+				array(
1576
+					'name'            => 'single-page-checkout',
1577
+					'html_id'         => 'ee-single-page-checkout-dv',
1578
+					'layout_strategy' =>
1579
+						new EE_Template_Layout(
1580
+							array(
1581
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1582
+								'template_args'        => array(
1583
+									'empty_cart'              => $empty_cart,
1584
+									'revisit'                 => $this->checkout->revisit,
1585
+									'reg_steps'               => $this->checkout->reg_steps,
1586
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1587
+										? $this->checkout->next_step->slug()
1588
+										: '',
1589
+									'empty_msg'               => apply_filters(
1590
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1591
+										sprintf(
1592
+											esc_html__(
1593
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1594
+												'event_espresso'
1595
+											),
1596
+											'<a href="'
1597
+											. get_post_type_archive_link('espresso_events')
1598
+											. '" title="',
1599
+											'">',
1600
+											'</a>'
1601
+										)
1602
+									),
1603
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1604
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1605
+									'session_expiration'      => gmdate(
1606
+										'M d, Y H:i:s',
1607
+										EE_Registry::instance()->SSN->expiration()
1608
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1609
+									),
1610
+								),
1611
+							)
1612
+						),
1613
+				)
1614
+			);
1615
+			// load template and add to output sent that gets filtered into the_content()
1616
+			EED_Single_Page_Checkout::getResponse()->addOutput($this->checkout->registration_form->get_html());
1617
+		}
1618
+	}
1619
+
1620
+
1621
+	/**
1622
+	 *    add_extra_finalize_registration_inputs
1623
+	 *
1624
+	 * @param $next_step
1625
+	 * @internal  param string $label
1626
+	 * @return void
1627
+	 */
1628
+	public function add_extra_finalize_registration_inputs($next_step)
1629
+	{
1630
+		if ($next_step === 'finalize_registration') {
1631
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1632
+		}
1633
+	}
1634
+
1635
+
1636
+	/**
1637
+	 *    display_registration_footer
1638
+	 *
1639
+	 * @return    string
1640
+	 */
1641
+	public static function display_registration_footer()
1642
+	{
1643
+		if (
1644
+			apply_filters(
1645
+				'FHEE__EE_Front__Controller__show_reg_footer',
1646
+				EE_Registry::instance()->CFG->admin->show_reg_footer
1647
+			)
1648
+		) {
1649
+			add_filter(
1650
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1651
+				function ($url) {
1652
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1653
+				}
1654
+			);
1655
+			echo apply_filters(
1656
+				'FHEE__EE_Front_Controller__display_registration_footer',
1657
+				EEH_Template::powered_by_event_espresso(
1658
+					'',
1659
+					'espresso-registration-footer-dv',
1660
+					array('utm_content' => 'registration_checkout')
1661
+				)
1662
+			);
1663
+		}
1664
+		return '';
1665
+	}
1666
+
1667
+
1668
+	/**
1669
+	 *    unlock_transaction
1670
+	 *
1671
+	 * @return    void
1672
+	 * @throws EE_Error
1673
+	 * @throws ReflectionException
1674
+	 */
1675
+	public function unlock_transaction()
1676
+	{
1677
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1678
+			$this->checkout->transaction->unlock();
1679
+		}
1680
+	}
1681
+
1682
+
1683
+	/**
1684
+	 *        _setup_redirect
1685
+	 *
1686
+	 * @return void
1687
+	 */
1688
+	private function _setup_redirect()
1689
+	{
1690
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1691
+			$this->checkout->redirect = true;
1692
+			if (empty($this->checkout->redirect_url)) {
1693
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1694
+			}
1695
+			$this->checkout->redirect_url = apply_filters(
1696
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1697
+				$this->checkout->redirect_url,
1698
+				$this->checkout
1699
+			);
1700
+		}
1701
+	}
1702
+
1703
+
1704
+	/**
1705
+	 *   handle ajax message responses and redirects
1706
+	 *
1707
+	 * @return void
1708
+	 * @throws EE_Error
1709
+	 * @throws ReflectionException
1710
+	 */
1711
+	public function go_to_next_step()
1712
+	{
1713
+		if ($this->request->isAjax()) {
1714
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1715
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1716
+		}
1717
+		$this->unlock_transaction();
1718
+		// just return for these conditions
1719
+		if (
1720
+			$this->checkout->admin_request
1721
+			|| $this->checkout->action === 'redirect_form'
1722
+			|| $this->checkout->action === 'update_checkout'
1723
+		) {
1724
+			return;
1725
+		}
1726
+		// AJAX response
1727
+		$this->_handle_json_response();
1728
+		// redirect to next step or the Thank You page
1729
+		$this->_handle_html_redirects();
1730
+		// hmmm... must be something wrong, so let's just display the form again !
1731
+		$this->_display_spco_reg_form();
1732
+	}
1733
+
1734
+
1735
+	/**
1736
+	 *   _handle_json_response
1737
+	 *
1738
+	 * @return void
1739
+	 * @throws EE_Error
1740
+	 */
1741
+	protected function _handle_json_response()
1742
+	{
1743
+		// if this is an ajax request
1744
+		if ($this->request->isAjax()) {
1745
+			$this->checkout->json_response->set_registration_time_limit(
1746
+				$this->checkout->get_registration_time_limit()
1747
+			);
1748
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1749
+			// just send the ajax (
1750
+			$json_response = apply_filters(
1751
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1752
+				$this->checkout->json_response
1753
+			);
1754
+			echo ($json_response);
1755
+			exit();
1756
+		}
1757
+	}
1758
+
1759
+
1760
+	/**
1761
+	 *   _handle_redirects
1762
+	 *
1763
+	 * @return void
1764
+	 */
1765
+	protected function _handle_html_redirects()
1766
+	{
1767
+		// going somewhere ?
1768
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1769
+			// store notices in a transient
1770
+			EE_Error::get_notices(false, true);
1771
+			wp_safe_redirect($this->checkout->redirect_url);
1772
+			exit();
1773
+		}
1774
+	}
1775
+
1776
+
1777
+	/**
1778
+	 *   set_checkout_anchor
1779
+	 *
1780
+	 * @return void
1781
+	 */
1782
+	public function set_checkout_anchor()
1783
+	{
1784
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1785
+	}
1786
+
1787
+	/**
1788
+	 *    getRegistrationExpirationNotice
1789
+	 *
1790
+	 * @since     4.9.59.p
1791
+	 * @return    string
1792
+	 */
1793
+	public static function getRegistrationExpirationNotice()
1794
+	{
1795
+		return sprintf(
1796
+			esc_html__(
1797
+				'%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1798
+				'event_espresso'
1799
+			),
1800
+			'<h4 class="important-notice">',
1801
+			'</h4>',
1802
+			'<br />',
1803
+			'<p>',
1804
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1805
+			'">',
1806
+			'</a>',
1807
+			'</p>'
1808
+		);
1809
+	}
1810 1810
 }
Please login to merge, or discard this patch.
widgets/upcoming_events/EEW_Upcoming_Events.widget.php 2 patches
Indentation   +594 added lines, -594 removed lines patch added patch discarded remove patch
@@ -12,109 +12,109 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class EEW_Upcoming_Events extends EspressoWidget
14 14
 {
15
-    /**
16
-     * @var string
17
-     */
18
-    private $title;
19
-    /**
20
-     * @var string
21
-     */
22
-    private $events_category;
23
-
24
-    /**
25
-     * @var bool
26
-     */
27
-    private $show_expired;
28
-
29
-    /**
30
-     * @var string
31
-     */
32
-    private $image_size;
33
-
34
-    /**
35
-     * @var bool
36
-     */
37
-    private $show_desc;
38
-
39
-    /**
40
-     * @var bool
41
-     */
42
-    private $show_dates;
43
-
44
-    /**
45
-     * @var string
46
-     */
47
-    private $date_limit;
48
-
49
-    /**
50
-     * @var string
51
-     */
52
-    private $date_range;
53
-
54
-    /**
55
-     * @var string
56
-     */
57
-    private $limit;
58
-
59
-    /**
60
-     * @var string
61
-     */
62
-    private $order;
63
-
64
-
65
-    /**
66
-     * Register widget with WordPress.
67
-     */
68
-    public function __construct()
69
-    {
70
-        parent::__construct(
71
-            esc_html__('Event Espresso Upcoming Events', 'event_espresso'),
72
-            ['description' => esc_html__('A widget to display your upcoming events.', 'event_espresso')]
73
-        );
74
-    }
75
-
76
-
77
-    /**
78
-     * Back-end widget form.
79
-     *
80
-     * @param array $instance Previously saved values from database.
81
-     * @return void
82
-     * @throws EE_Error
83
-     * @throws ReflectionException
84
-     * @see WP_Widget::form()
85
-     */
86
-    public function form($instance)
87
-    {
88
-
89
-        EE_Registry::instance()->load_class('Question_Option', [], false, false, true);
90
-        // Set up some default widget settings.
91
-        $defaults = [
92
-            'title'           => esc_html__('Upcoming Events', 'event_espresso'),
93
-            'category_name'   => '',
94
-            'show_expired'    => 0,
95
-            'show_desc'       => true,
96
-            'show_dates'      => true,
97
-            'show_everywhere' => false,
98
-            'date_limit'      => 2,
99
-            'limit'           => 10,
100
-            'sort'            => 'ASC',
101
-            'date_range'      => false,
102
-            'image_size'      => 'medium',
103
-        ];
104
-
105
-        $instance = wp_parse_args((array) $instance, $defaults);
106
-        // don't add HTML labels for EE_Form_Fields generated inputs
107
-        add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string');
108
-        $yes_no_values = [
109
-            EE_Question_Option::new_instance(['QSO_value' => false, 'QSO_desc' => esc_html__('No', 'event_espresso')]),
110
-            EE_Question_Option::new_instance(['QSO_value' => true, 'QSO_desc' => esc_html__('Yes', 'event_espresso')]),
111
-        ];
112
-        $sort_values   = [
113
-            EE_Question_Option::new_instance(['QSO_value' => 'ASC', 'QSO_desc' => esc_html__('ASC', 'event_espresso')]),
114
-            EE_Question_Option::new_instance(['QSO_value' => 'DESC', 'QSO_desc' => esc_html__('DESC', 'event_espresso')]),
115
-        ];
116
-
117
-        ?>
15
+	/**
16
+	 * @var string
17
+	 */
18
+	private $title;
19
+	/**
20
+	 * @var string
21
+	 */
22
+	private $events_category;
23
+
24
+	/**
25
+	 * @var bool
26
+	 */
27
+	private $show_expired;
28
+
29
+	/**
30
+	 * @var string
31
+	 */
32
+	private $image_size;
33
+
34
+	/**
35
+	 * @var bool
36
+	 */
37
+	private $show_desc;
38
+
39
+	/**
40
+	 * @var bool
41
+	 */
42
+	private $show_dates;
43
+
44
+	/**
45
+	 * @var string
46
+	 */
47
+	private $date_limit;
48
+
49
+	/**
50
+	 * @var string
51
+	 */
52
+	private $date_range;
53
+
54
+	/**
55
+	 * @var string
56
+	 */
57
+	private $limit;
58
+
59
+	/**
60
+	 * @var string
61
+	 */
62
+	private $order;
63
+
64
+
65
+	/**
66
+	 * Register widget with WordPress.
67
+	 */
68
+	public function __construct()
69
+	{
70
+		parent::__construct(
71
+			esc_html__('Event Espresso Upcoming Events', 'event_espresso'),
72
+			['description' => esc_html__('A widget to display your upcoming events.', 'event_espresso')]
73
+		);
74
+	}
75
+
76
+
77
+	/**
78
+	 * Back-end widget form.
79
+	 *
80
+	 * @param array $instance Previously saved values from database.
81
+	 * @return void
82
+	 * @throws EE_Error
83
+	 * @throws ReflectionException
84
+	 * @see WP_Widget::form()
85
+	 */
86
+	public function form($instance)
87
+	{
88
+
89
+		EE_Registry::instance()->load_class('Question_Option', [], false, false, true);
90
+		// Set up some default widget settings.
91
+		$defaults = [
92
+			'title'           => esc_html__('Upcoming Events', 'event_espresso'),
93
+			'category_name'   => '',
94
+			'show_expired'    => 0,
95
+			'show_desc'       => true,
96
+			'show_dates'      => true,
97
+			'show_everywhere' => false,
98
+			'date_limit'      => 2,
99
+			'limit'           => 10,
100
+			'sort'            => 'ASC',
101
+			'date_range'      => false,
102
+			'image_size'      => 'medium',
103
+		];
104
+
105
+		$instance = wp_parse_args((array) $instance, $defaults);
106
+		// don't add HTML labels for EE_Form_Fields generated inputs
107
+		add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string');
108
+		$yes_no_values = [
109
+			EE_Question_Option::new_instance(['QSO_value' => false, 'QSO_desc' => esc_html__('No', 'event_espresso')]),
110
+			EE_Question_Option::new_instance(['QSO_value' => true, 'QSO_desc' => esc_html__('Yes', 'event_espresso')]),
111
+		];
112
+		$sort_values   = [
113
+			EE_Question_Option::new_instance(['QSO_value' => 'ASC', 'QSO_desc' => esc_html__('ASC', 'event_espresso')]),
114
+			EE_Question_Option::new_instance(['QSO_value' => 'DESC', 'QSO_desc' => esc_html__('DESC', 'event_espresso')]),
115
+		];
116
+
117
+		?>
118 118
 
119 119
         <!-- Widget Title: Text Input -->
120 120
 
@@ -151,32 +151,32 @@  discard block
 block discarded – undo
151 151
                 <?php esc_html_e('Show Expired Events:', 'event_espresso'); ?>
152 152
             </label>
153 153
             <?php
154
-            $show_expired_options   = $yes_no_values;
155
-            $show_expired_options[] = EE_Question_Option::new_instance(
156
-                ['QSO_value' => 2, 'QSO_desc' => esc_html__('Show Only Expired', 'event_espresso')]
157
-            );
158
-            echo EEH_Form_Fields::select(
159
-                esc_html__('Show Expired Events:', 'event_espresso'),
160
-                $instance['show_expired'],
161
-                $show_expired_options,
162
-                $this->fieldName('show_expired'),
163
-                $this->fieldID('show_expired')
164
-            );
165
-            ?>
154
+			$show_expired_options   = $yes_no_values;
155
+			$show_expired_options[] = EE_Question_Option::new_instance(
156
+				['QSO_value' => 2, 'QSO_desc' => esc_html__('Show Only Expired', 'event_espresso')]
157
+			);
158
+			echo EEH_Form_Fields::select(
159
+				esc_html__('Show Expired Events:', 'event_espresso'),
160
+				$instance['show_expired'],
161
+				$show_expired_options,
162
+				$this->fieldName('show_expired'),
163
+				$this->fieldID('show_expired')
164
+			);
165
+			?>
166 166
         </p>
167 167
         <p>
168 168
             <label for="<?php echo esc_attr($this->fieldID('sort')); ?>">
169 169
                 <?php esc_html_e('Sort Events:', 'event_espresso'); ?>
170 170
             </label>
171 171
             <?php
172
-            echo EEH_Form_Fields::select(
173
-                esc_html__('Sort Events:', 'event_espresso'),
174
-                $instance['sort'],
175
-                $sort_values,
176
-                $this->fieldName('sort'),
177
-                $this->fieldID('sort')
178
-            );
179
-            ?>
172
+			echo EEH_Form_Fields::select(
173
+				esc_html__('Sort Events:', 'event_espresso'),
174
+				$instance['sort'],
175
+				$sort_values,
176
+				$this->fieldName('sort'),
177
+				$this->fieldID('sort')
178
+			);
179
+			?>
180 180
         </p>
181 181
         <p>
182 182
             <label for="<?php echo esc_attr($this->fieldID('image_size')); ?>">
@@ -190,42 +190,42 @@  discard block
 block discarded – undo
190 190
                 <?php esc_html_e('Show Description:', 'event_espresso'); ?>
191 191
             </label>
192 192
             <?php
193
-            echo EEH_Form_Fields::select(
194
-                esc_html__('Show Description:', 'event_espresso'),
195
-                $instance['show_desc'],
196
-                $yes_no_values,
197
-                $this->fieldName('show_desc'),
198
-                $this->fieldID('show_desc')
199
-            );
200
-            ?>
193
+			echo EEH_Form_Fields::select(
194
+				esc_html__('Show Description:', 'event_espresso'),
195
+				$instance['show_desc'],
196
+				$yes_no_values,
197
+				$this->fieldName('show_desc'),
198
+				$this->fieldID('show_desc')
199
+			);
200
+			?>
201 201
         </p>
202 202
         <p>
203 203
             <label for="<?php echo esc_attr($this->fieldID('show_dates')); ?>">
204 204
                 <?php esc_html_e('Show Dates:', 'event_espresso'); ?>
205 205
             </label>
206 206
             <?php
207
-            echo EEH_Form_Fields::select(
208
-                esc_html__('Show Dates:', 'event_espresso'),
209
-                $instance['show_dates'],
210
-                $yes_no_values,
211
-                $this->fieldName('show_dates'),
212
-                $this->fieldID('show_dates')
213
-            );
214
-            ?>
207
+			echo EEH_Form_Fields::select(
208
+				esc_html__('Show Dates:', 'event_espresso'),
209
+				$instance['show_dates'],
210
+				$yes_no_values,
211
+				$this->fieldName('show_dates'),
212
+				$this->fieldID('show_dates')
213
+			);
214
+			?>
215 215
         </p>
216 216
         <p>
217 217
             <label for="<?php echo esc_attr($this->fieldID('show_everywhere')); ?>">
218 218
                 <?php esc_html_e('Show on all Pages:', 'event_espresso'); ?>
219 219
             </label>
220 220
             <?php
221
-            echo EEH_Form_Fields::select(
222
-                esc_html__('Show on all Pages:', 'event_espresso'),
223
-                $instance['show_everywhere'],
224
-                $yes_no_values,
225
-                $this->fieldName('show_everywhere'),
226
-                $this->fieldID('show_everywhere')
227
-            );
228
-            ?>
221
+			echo EEH_Form_Fields::select(
222
+				esc_html__('Show on all Pages:', 'event_espresso'),
223
+				$instance['show_everywhere'],
224
+				$yes_no_values,
225
+				$this->fieldName('show_everywhere'),
226
+				$this->fieldID('show_everywhere')
227
+			);
228
+			?>
229 229
         </p>
230 230
         <p>
231 231
             <label for="<?php echo esc_attr($this->fieldID('date_limit')); ?>">
@@ -243,278 +243,278 @@  discard block
 block discarded – undo
243 243
                 <?php esc_html_e('Show Date Range:', 'event_espresso'); ?>
244 244
             </label>
245 245
             <?php
246
-            echo EEH_Form_Fields::select(
247
-                esc_html__('Show Date Range:', 'event_espresso'),
248
-                $instance['date_range'],
249
-                $yes_no_values,
250
-                $this->fieldName('date_range'),
251
-                $this->fieldID('date_range')
252
-            );
253
-            ?>
246
+			echo EEH_Form_Fields::select(
247
+				esc_html__('Show Date Range:', 'event_espresso'),
248
+				$instance['date_range'],
249
+				$yes_no_values,
250
+				$this->fieldName('date_range'),
251
+				$this->fieldID('date_range')
252
+			);
253
+			?>
254 254
             <span class="description">
255 255
                 <br />
256 256
                 <?php esc_html_e(
257
-                    'This setting will replace the list of dates in the widget.',
258
-                    'event_espresso'
259
-                ); ?>
257
+					'This setting will replace the list of dates in the widget.',
258
+					'event_espresso'
259
+				); ?>
260 260
             </span>
261 261
         </p>
262 262
 
263 263
         <?php
264
-    }
265
-
266
-
267
-    /**
268
-     * Sanitize widget form values as they are saved.
269
-     *
270
-     * @param array $new_instance Values just sent to be saved.
271
-     * @param array $old_instance Previously saved values from database.
272
-     *
273
-     * @return array Updated safe values to be saved.
274
-     * @see WP_Widget::update()
275
-     *
276
-     */
277
-    public function update($new_instance, $old_instance)
278
-    {
279
-        $instance                    = $old_instance;
280
-        $instance['title']           = ! empty($new_instance['title']) ? strip_tags((string) $new_instance['title']) : '';
281
-        $instance['category_name']   = $new_instance['category_name'];
282
-        $instance['show_expired']    = $new_instance['show_expired'];
283
-        $instance['limit']           = $new_instance['limit'];
284
-        $instance['sort']            = $new_instance['sort'];
285
-        $instance['image_size']      = $new_instance['image_size'];
286
-        $instance['show_desc']       = $new_instance['show_desc'];
287
-        $instance['show_dates']      = $new_instance['show_dates'];
288
-        $instance['show_everywhere'] = $new_instance['show_everywhere'];
289
-        $instance['date_limit']      = $new_instance['date_limit'];
290
-        $instance['date_range']      = $new_instance['date_range'];
291
-        return $instance;
292
-    }
293
-
294
-
295
-    /**
296
-     * Front-end display of widget.
297
-     *
298
-     * @param array $args     Widget arguments.
299
-     * @param array $instance Saved values from database.
300
-     * @throws EE_Error
301
-     * @throws ReflectionException
302
-     * @see WP_Widget::widget()
303
-     *
304
-     */
305
-    public function widget($args, $instance)
306
-    {
307
-
308
-        global $post;
309
-        // make sure there is some kinda post object
310
-        if ($post instanceof WP_Post) {
311
-            $before_widget = '';
312
-            $before_title  = '';
313
-            $after_title   = '';
314
-            $after_widget  = '';
315
-            // but NOT an events archives page, cuz that would be like two event lists on the same page
316
-            $show_everywhere = ! isset($instance['show_everywhere']) || absint($instance['show_everywhere']);
317
-            if ($show_everywhere || ! ($post->post_type == 'espresso_events' && is_archive())) {
318
-                // let's use some of the event helper functions'
319
-                // make separate vars out of attributes
320
-                extract($args);
321
-
322
-                // grab widget settings
323
-                $this->parseWidgetSettings($instance);
324
-                $title = $this->widgetTitle();
325
-
326
-                // Before widget (defined by themes).
327
-                echo wp_kses($before_widget, AllowedTags::getAllowedTags());
328
-                // Display the widget title if one was input (before and after defined by themes).
329
-                if (! empty($title)) {
330
-                    echo wp_kses($before_title . $title . $after_title, AllowedTags::getAllowedTags());
331
-                }
332
-                echo wp_kses($this->widgetContent($post), AllowedTags::getWithFormTags());
333
-                // After widget (defined by themes).
334
-                echo wp_kses($after_widget, AllowedTags::getAllowedTags());
335
-            }
336
-        }
337
-    }
338
-
339
-
340
-    /**
341
-     * make_the_title_a_link
342
-     * callback for widget_title filter
343
-     *
344
-     * @param $title
345
-     * @return string
346
-     */
347
-    public function make_the_title_a_link($title)
348
-    {
349
-        return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>';
350
-    }
351
-
352
-
353
-    /**
354
-     * @param string $field_name
355
-     * @return string
356
-     * @since   4.10.14.p
357
-     */
358
-    public function fieldID($field_name)
359
-    {
360
-        return parent::get_field_id($field_name);
361
-    }
362
-
363
-
364
-    /**
365
-     * @param string $field_name
366
-     * @return string
367
-     * @since   4.10.14.p
368
-     */
369
-    public function fieldName($field_name)
370
-    {
371
-        return parent::get_field_name($field_name);
372
-    }
373
-
374
-
375
-    /**
376
-     * @param array $instance
377
-     * @throws EE_Error
378
-     * @throws ReflectionException
379
-     * @since   4.10.14.p
380
-     */
381
-    private function eventCategoriesSelector(array $instance)
382
-    {
383
-        $event_categories = [];
384
-        $categories       = EEM_Term::instance()->get_all_ee_categories(true);
385
-        if ($categories) {
386
-            foreach ($categories as $category) {
387
-                if ($category instanceof EE_Term) {
388
-                    $event_categories[] =
389
-                        EE_Question_Option::new_instance(
390
-                            [
391
-                                'QSO_value' => $category->get('slug'),
392
-                                'QSO_desc'  => $category->get('name'),
393
-                            ]
394
-                        );
395
-                }
396
-            }
397
-        }
398
-        array_unshift(
399
-            $event_categories,
400
-            EE_Question_Option::new_instance(
401
-                [
402
-                    'QSO_value' => '',
403
-                    'QSO_desc'  => esc_html__(' - display all - ', 'event_espresso'),
404
-                ]
405
-            )
406
-        );
407
-        echo EEH_Form_Fields::select(
408
-            esc_html__('Event Category:', 'event_espresso'),
409
-            $instance['category_name'],
410
-            $event_categories,
411
-            $this->fieldName('category_name'),
412
-            $this->fieldID('category_name')
413
-        );
414
-    }
415
-
416
-
417
-    /**
418
-     * @param array $instance
419
-     * @since   4.10.14.p
420
-     */
421
-    private function imageSizeSelector(array $instance)
422
-    {
423
-        $image_sizes = [];
424
-        $sizes       = get_intermediate_image_sizes();
425
-        if ($sizes) {
426
-            // loop thru images and create option objects out of them
427
-            foreach ($sizes as $image_size) {
428
-                $image_size = trim($image_size);
429
-                // no big images plz
430
-                if (! in_array($image_size, ['large', 'post-thumbnail'])) {
431
-                    $image_sizes[] =
432
-                        EE_Question_Option::new_instance(['QSO_value' => $image_size, 'QSO_desc' => $image_size]);
433
-                }
434
-            }
435
-            $image_sizes[] =
436
-                EE_Question_Option::new_instance(
437
-                    ['QSO_value' => 'none', 'QSO_desc' => esc_html__('don\'t show images', 'event_espresso')]
438
-                );
439
-        }
440
-        echo EEH_Form_Fields::select(
441
-            esc_html__('Image Size:', 'event_espresso'),
442
-            $instance['image_size'],
443
-            $image_sizes,
444
-            $this->fieldName('image_size'),
445
-            $this->fieldID('image_size')
446
-        );
447
-    }
448
-
449
-
450
-    /**
451
-     * @param array $instance
452
-     * @since   4.10.14.p
453
-     */
454
-    private function parseWidgetSettings(array $instance)
455
-    {
456
-        $this->title = isset($instance['title']) && ! empty($instance['title']) ? $instance['title'] : '';
457
-        $this->events_category     = isset($instance['category_name']) && ! empty($instance['category_name'])
458
-            ? $instance['category_name']
459
-            : false;
460
-        $this->show_expired = isset($instance['show_expired'])
461
-            ? filter_var($instance['show_expired'], FILTER_VALIDATE_BOOLEAN)
462
-            : 0;
463
-        $this->image_size   = isset($instance['image_size']) && ! empty($instance['image_size'])
464
-            ? $instance['image_size']
465
-            : 'medium';
466
-        $this->show_desc    = ! isset($instance['show_desc'])
467
-                              || filter_var($instance['show_desc'], FILTER_VALIDATE_BOOLEAN);
468
-        $this->show_dates   = ! isset($instance['show_dates'])
469
-                              || filter_var($instance['show_dates'], FILTER_VALIDATE_BOOLEAN);
470
-        $this->date_limit   = isset($instance['date_limit']) && ! empty($instance['date_limit'])
471
-            ? $instance['date_limit']
472
-            : null;
473
-        $this->date_range   = isset($instance['date_range']) && ! empty($instance['date_range'])
474
-            ? $instance['date_range']
475
-            : false;
476
-        $this->limit        = isset($instance['limit']) ? absint($instance['limit']) : 10;
477
-        $this->order        = isset($instance['sort']) && $instance['sort'] === 'DESC'
478
-            ? 'DESC'
479
-            : 'ASC';
480
-    }
481
-
482
-
483
-    /**
484
-     * @return mixed|void
485
-     * @since   4.10.14.p
486
-     */
487
-    private function widgetTitle()
488
-    {
489
-        // add function to make the title a link
490
-        add_filter('widget_title', [$this, 'make_the_title_a_link'], 15);
491
-        // filter the title
492
-        $title = apply_filters('widget_title', $this->title);
493
-        // remove the function from the filter, so it does not affect other widgets
494
-        remove_filter('widget_title', [$this, 'make_the_title_a_link'], 15);
495
-        return $title;
496
-    }
497
-
498
-
499
-    /**
500
-     * @param WP_Post $post
501
-     * @return string
502
-     * @throws EE_Error
503
-     * @throws ReflectionException
504
-     * @since   4.10.14.p
505
-     */
506
-    private function widgetContent(WP_Post $post)
507
-    {
508
-        // run the query
509
-        $events = $this->getUpcomingEvents();
510
-        if (empty($events)) {
511
-            return '';
512
-        }
513
-        $list_items = '';
514
-        foreach ($events as $event) {
515
-            if ($event instanceof EE_Event && (! is_single() || $post->ID != $event->ID())) {
516
-                $event_url = $this->eventUrl($event);
517
-                $list_items .= '
264
+	}
265
+
266
+
267
+	/**
268
+	 * Sanitize widget form values as they are saved.
269
+	 *
270
+	 * @param array $new_instance Values just sent to be saved.
271
+	 * @param array $old_instance Previously saved values from database.
272
+	 *
273
+	 * @return array Updated safe values to be saved.
274
+	 * @see WP_Widget::update()
275
+	 *
276
+	 */
277
+	public function update($new_instance, $old_instance)
278
+	{
279
+		$instance                    = $old_instance;
280
+		$instance['title']           = ! empty($new_instance['title']) ? strip_tags((string) $new_instance['title']) : '';
281
+		$instance['category_name']   = $new_instance['category_name'];
282
+		$instance['show_expired']    = $new_instance['show_expired'];
283
+		$instance['limit']           = $new_instance['limit'];
284
+		$instance['sort']            = $new_instance['sort'];
285
+		$instance['image_size']      = $new_instance['image_size'];
286
+		$instance['show_desc']       = $new_instance['show_desc'];
287
+		$instance['show_dates']      = $new_instance['show_dates'];
288
+		$instance['show_everywhere'] = $new_instance['show_everywhere'];
289
+		$instance['date_limit']      = $new_instance['date_limit'];
290
+		$instance['date_range']      = $new_instance['date_range'];
291
+		return $instance;
292
+	}
293
+
294
+
295
+	/**
296
+	 * Front-end display of widget.
297
+	 *
298
+	 * @param array $args     Widget arguments.
299
+	 * @param array $instance Saved values from database.
300
+	 * @throws EE_Error
301
+	 * @throws ReflectionException
302
+	 * @see WP_Widget::widget()
303
+	 *
304
+	 */
305
+	public function widget($args, $instance)
306
+	{
307
+
308
+		global $post;
309
+		// make sure there is some kinda post object
310
+		if ($post instanceof WP_Post) {
311
+			$before_widget = '';
312
+			$before_title  = '';
313
+			$after_title   = '';
314
+			$after_widget  = '';
315
+			// but NOT an events archives page, cuz that would be like two event lists on the same page
316
+			$show_everywhere = ! isset($instance['show_everywhere']) || absint($instance['show_everywhere']);
317
+			if ($show_everywhere || ! ($post->post_type == 'espresso_events' && is_archive())) {
318
+				// let's use some of the event helper functions'
319
+				// make separate vars out of attributes
320
+				extract($args);
321
+
322
+				// grab widget settings
323
+				$this->parseWidgetSettings($instance);
324
+				$title = $this->widgetTitle();
325
+
326
+				// Before widget (defined by themes).
327
+				echo wp_kses($before_widget, AllowedTags::getAllowedTags());
328
+				// Display the widget title if one was input (before and after defined by themes).
329
+				if (! empty($title)) {
330
+					echo wp_kses($before_title . $title . $after_title, AllowedTags::getAllowedTags());
331
+				}
332
+				echo wp_kses($this->widgetContent($post), AllowedTags::getWithFormTags());
333
+				// After widget (defined by themes).
334
+				echo wp_kses($after_widget, AllowedTags::getAllowedTags());
335
+			}
336
+		}
337
+	}
338
+
339
+
340
+	/**
341
+	 * make_the_title_a_link
342
+	 * callback for widget_title filter
343
+	 *
344
+	 * @param $title
345
+	 * @return string
346
+	 */
347
+	public function make_the_title_a_link($title)
348
+	{
349
+		return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>';
350
+	}
351
+
352
+
353
+	/**
354
+	 * @param string $field_name
355
+	 * @return string
356
+	 * @since   4.10.14.p
357
+	 */
358
+	public function fieldID($field_name)
359
+	{
360
+		return parent::get_field_id($field_name);
361
+	}
362
+
363
+
364
+	/**
365
+	 * @param string $field_name
366
+	 * @return string
367
+	 * @since   4.10.14.p
368
+	 */
369
+	public function fieldName($field_name)
370
+	{
371
+		return parent::get_field_name($field_name);
372
+	}
373
+
374
+
375
+	/**
376
+	 * @param array $instance
377
+	 * @throws EE_Error
378
+	 * @throws ReflectionException
379
+	 * @since   4.10.14.p
380
+	 */
381
+	private function eventCategoriesSelector(array $instance)
382
+	{
383
+		$event_categories = [];
384
+		$categories       = EEM_Term::instance()->get_all_ee_categories(true);
385
+		if ($categories) {
386
+			foreach ($categories as $category) {
387
+				if ($category instanceof EE_Term) {
388
+					$event_categories[] =
389
+						EE_Question_Option::new_instance(
390
+							[
391
+								'QSO_value' => $category->get('slug'),
392
+								'QSO_desc'  => $category->get('name'),
393
+							]
394
+						);
395
+				}
396
+			}
397
+		}
398
+		array_unshift(
399
+			$event_categories,
400
+			EE_Question_Option::new_instance(
401
+				[
402
+					'QSO_value' => '',
403
+					'QSO_desc'  => esc_html__(' - display all - ', 'event_espresso'),
404
+				]
405
+			)
406
+		);
407
+		echo EEH_Form_Fields::select(
408
+			esc_html__('Event Category:', 'event_espresso'),
409
+			$instance['category_name'],
410
+			$event_categories,
411
+			$this->fieldName('category_name'),
412
+			$this->fieldID('category_name')
413
+		);
414
+	}
415
+
416
+
417
+	/**
418
+	 * @param array $instance
419
+	 * @since   4.10.14.p
420
+	 */
421
+	private function imageSizeSelector(array $instance)
422
+	{
423
+		$image_sizes = [];
424
+		$sizes       = get_intermediate_image_sizes();
425
+		if ($sizes) {
426
+			// loop thru images and create option objects out of them
427
+			foreach ($sizes as $image_size) {
428
+				$image_size = trim($image_size);
429
+				// no big images plz
430
+				if (! in_array($image_size, ['large', 'post-thumbnail'])) {
431
+					$image_sizes[] =
432
+						EE_Question_Option::new_instance(['QSO_value' => $image_size, 'QSO_desc' => $image_size]);
433
+				}
434
+			}
435
+			$image_sizes[] =
436
+				EE_Question_Option::new_instance(
437
+					['QSO_value' => 'none', 'QSO_desc' => esc_html__('don\'t show images', 'event_espresso')]
438
+				);
439
+		}
440
+		echo EEH_Form_Fields::select(
441
+			esc_html__('Image Size:', 'event_espresso'),
442
+			$instance['image_size'],
443
+			$image_sizes,
444
+			$this->fieldName('image_size'),
445
+			$this->fieldID('image_size')
446
+		);
447
+	}
448
+
449
+
450
+	/**
451
+	 * @param array $instance
452
+	 * @since   4.10.14.p
453
+	 */
454
+	private function parseWidgetSettings(array $instance)
455
+	{
456
+		$this->title = isset($instance['title']) && ! empty($instance['title']) ? $instance['title'] : '';
457
+		$this->events_category     = isset($instance['category_name']) && ! empty($instance['category_name'])
458
+			? $instance['category_name']
459
+			: false;
460
+		$this->show_expired = isset($instance['show_expired'])
461
+			? filter_var($instance['show_expired'], FILTER_VALIDATE_BOOLEAN)
462
+			: 0;
463
+		$this->image_size   = isset($instance['image_size']) && ! empty($instance['image_size'])
464
+			? $instance['image_size']
465
+			: 'medium';
466
+		$this->show_desc    = ! isset($instance['show_desc'])
467
+							  || filter_var($instance['show_desc'], FILTER_VALIDATE_BOOLEAN);
468
+		$this->show_dates   = ! isset($instance['show_dates'])
469
+							  || filter_var($instance['show_dates'], FILTER_VALIDATE_BOOLEAN);
470
+		$this->date_limit   = isset($instance['date_limit']) && ! empty($instance['date_limit'])
471
+			? $instance['date_limit']
472
+			: null;
473
+		$this->date_range   = isset($instance['date_range']) && ! empty($instance['date_range'])
474
+			? $instance['date_range']
475
+			: false;
476
+		$this->limit        = isset($instance['limit']) ? absint($instance['limit']) : 10;
477
+		$this->order        = isset($instance['sort']) && $instance['sort'] === 'DESC'
478
+			? 'DESC'
479
+			: 'ASC';
480
+	}
481
+
482
+
483
+	/**
484
+	 * @return mixed|void
485
+	 * @since   4.10.14.p
486
+	 */
487
+	private function widgetTitle()
488
+	{
489
+		// add function to make the title a link
490
+		add_filter('widget_title', [$this, 'make_the_title_a_link'], 15);
491
+		// filter the title
492
+		$title = apply_filters('widget_title', $this->title);
493
+		// remove the function from the filter, so it does not affect other widgets
494
+		remove_filter('widget_title', [$this, 'make_the_title_a_link'], 15);
495
+		return $title;
496
+	}
497
+
498
+
499
+	/**
500
+	 * @param WP_Post $post
501
+	 * @return string
502
+	 * @throws EE_Error
503
+	 * @throws ReflectionException
504
+	 * @since   4.10.14.p
505
+	 */
506
+	private function widgetContent(WP_Post $post)
507
+	{
508
+		// run the query
509
+		$events = $this->getUpcomingEvents();
510
+		if (empty($events)) {
511
+			return '';
512
+		}
513
+		$list_items = '';
514
+		foreach ($events as $event) {
515
+			if ($event instanceof EE_Event && (! is_single() || $post->ID != $event->ID())) {
516
+				$event_url = $this->eventUrl($event);
517
+				$list_items .= '
518 518
                 <li id="ee-upcoming-events-widget-li-' . absint($event->ID()) . '" 
519 519
                     class="ee-upcoming-events-widget-li"
520 520
                 >
@@ -525,194 +525,194 @@  discard block
 block discarded – undo
525 525
                     </h5>
526 526
                     ' . $this->eventWidgetContent($event, $event_url) . '
527 527
                 </li>';
528
-            }
529
-        }
530
-        return '
528
+			}
529
+		}
530
+		return '
531 531
             <ul class="ee-upcoming-events-widget-ul">
532 532
                 ' . $list_items . '
533 533
             </ul>';
534
-    }
535
-
536
-
537
-    /**
538
-     * @param EE_Event $event
539
-     * @return string|null
540
-     * @throws EE_Error
541
-     * @since   4.10.14.p
542
-     */
543
-    private function eventUrl(EE_Event $event)
544
-    {
545
-        return esc_url_raw(
546
-            apply_filters(
547
-                'FHEE_EEW_Upcoming_Events__widget__event_url',
548
-                $event->get_permalink(),
549
-                $event
550
-            )
551
-        );
552
-    }
553
-
554
-
555
-    /**
556
-     * @return EE_Base_Class[]
557
-     * @throws EE_Error
558
-     */
559
-    private function getUpcomingEvents()
560
-    {
561
-        return EEM_Event::instance()->get_all(
562
-            [
563
-                $this->queryWhereParams(),
564
-                'limit'    => '0,' . $this->limit,
565
-                'order_by' => 'Datetime.DTT_EVT_start',
566
-                'order'    => $this->order,
567
-                'group_by' => 'EVT_ID',
568
-            ]
569
-        );
570
-    }
571
-
572
-
573
-    /**
574
-     * @return mixed|void
575
-     * @throws EE_Error
576
-     * @since   4.10.14.p
577
-     */
578
-    private function queryWhereParams()
579
-    {
580
-        // start to build our where clause
581
-        $where = [
582
-            'status' => ['IN', ['publish', 'sold_out']],
583
-        ];
584
-        // add category
585
-        if ($this->events_category) {
586
-            $where['Term_Taxonomy.taxonomy']  = 'espresso_event_categories';
587
-            $where['Term_Taxonomy.Term.slug'] = $this->events_category;
588
-        }
589
-        // if NOT expired then we want events that start today or in the future
590
-        // if NOT show expired then we want events that start today or in the future
591
-        if ($this->show_expired == 0) {
592
-            $where['Datetime.DTT_EVT_end'] = [
593
-                '>=',
594
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
595
-            ];
596
-        }
597
-        // if show ONLY expired we want events that ended prior to today
598
-        if ($this->show_expired == 2) {
599
-            $where['Datetime.DTT_EVT_end'] = [
600
-                '<=',
601
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
602
-            ];
603
-        }
604
-        // allow $where to be filtered
605
-        return apply_filters('FHEE__EEW_Upcoming_Events__widget__where', $where, $this->events_category, $this->show_expired);
606
-    }
607
-
608
-
609
-    /**
610
-     * @param EE_Event $event
611
-     * @return string
612
-     * @throws EE_Error
613
-     * @throws ReflectionException
614
-     * @since   4.10.14.p
615
-     */
616
-    private function linkClass(EE_Event $event)
617
-    {
618
-        // how big is the event name ?
619
-        $name_length = strlen($event->name());
620
-        switch ($name_length) {
621
-            case $name_length > 70:
622
-                return ' three-line';
623
-            case $name_length > 35:
624
-                return ' two-line';
625
-        }
626
-        return ' one-line';
627
-    }
628
-
629
-
630
-    /**
631
-     * @param EE_Event $event
632
-     * @param string   $event_url
633
-     * @return mixed|string|void
634
-     * @throws EE_Error
635
-     * @throws ReflectionException
636
-     * @since   4.10.14.p
637
-     */
638
-    private function eventWidgetContent(EE_Event $event, $event_url = '')
639
-    {
640
-        if (post_password_required($event->ID())) {
641
-            return apply_filters(
642
-                'FHEE_EEW_Upcoming_Events__widget__password_form',
643
-                get_the_password_form($event->ID()),
644
-                $event
645
-            );
646
-        }
647
-
648
-        $content = '';
649
-        if (has_post_thumbnail($event->ID()) && $this->image_size != 'none') {
650
-            $content .= '
534
+	}
535
+
536
+
537
+	/**
538
+	 * @param EE_Event $event
539
+	 * @return string|null
540
+	 * @throws EE_Error
541
+	 * @since   4.10.14.p
542
+	 */
543
+	private function eventUrl(EE_Event $event)
544
+	{
545
+		return esc_url_raw(
546
+			apply_filters(
547
+				'FHEE_EEW_Upcoming_Events__widget__event_url',
548
+				$event->get_permalink(),
549
+				$event
550
+			)
551
+		);
552
+	}
553
+
554
+
555
+	/**
556
+	 * @return EE_Base_Class[]
557
+	 * @throws EE_Error
558
+	 */
559
+	private function getUpcomingEvents()
560
+	{
561
+		return EEM_Event::instance()->get_all(
562
+			[
563
+				$this->queryWhereParams(),
564
+				'limit'    => '0,' . $this->limit,
565
+				'order_by' => 'Datetime.DTT_EVT_start',
566
+				'order'    => $this->order,
567
+				'group_by' => 'EVT_ID',
568
+			]
569
+		);
570
+	}
571
+
572
+
573
+	/**
574
+	 * @return mixed|void
575
+	 * @throws EE_Error
576
+	 * @since   4.10.14.p
577
+	 */
578
+	private function queryWhereParams()
579
+	{
580
+		// start to build our where clause
581
+		$where = [
582
+			'status' => ['IN', ['publish', 'sold_out']],
583
+		];
584
+		// add category
585
+		if ($this->events_category) {
586
+			$where['Term_Taxonomy.taxonomy']  = 'espresso_event_categories';
587
+			$where['Term_Taxonomy.Term.slug'] = $this->events_category;
588
+		}
589
+		// if NOT expired then we want events that start today or in the future
590
+		// if NOT show expired then we want events that start today or in the future
591
+		if ($this->show_expired == 0) {
592
+			$where['Datetime.DTT_EVT_end'] = [
593
+				'>=',
594
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
595
+			];
596
+		}
597
+		// if show ONLY expired we want events that ended prior to today
598
+		if ($this->show_expired == 2) {
599
+			$where['Datetime.DTT_EVT_end'] = [
600
+				'<=',
601
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
602
+			];
603
+		}
604
+		// allow $where to be filtered
605
+		return apply_filters('FHEE__EEW_Upcoming_Events__widget__where', $where, $this->events_category, $this->show_expired);
606
+	}
607
+
608
+
609
+	/**
610
+	 * @param EE_Event $event
611
+	 * @return string
612
+	 * @throws EE_Error
613
+	 * @throws ReflectionException
614
+	 * @since   4.10.14.p
615
+	 */
616
+	private function linkClass(EE_Event $event)
617
+	{
618
+		// how big is the event name ?
619
+		$name_length = strlen($event->name());
620
+		switch ($name_length) {
621
+			case $name_length > 70:
622
+				return ' three-line';
623
+			case $name_length > 35:
624
+				return ' two-line';
625
+		}
626
+		return ' one-line';
627
+	}
628
+
629
+
630
+	/**
631
+	 * @param EE_Event $event
632
+	 * @param string   $event_url
633
+	 * @return mixed|string|void
634
+	 * @throws EE_Error
635
+	 * @throws ReflectionException
636
+	 * @since   4.10.14.p
637
+	 */
638
+	private function eventWidgetContent(EE_Event $event, $event_url = '')
639
+	{
640
+		if (post_password_required($event->ID())) {
641
+			return apply_filters(
642
+				'FHEE_EEW_Upcoming_Events__widget__password_form',
643
+				get_the_password_form($event->ID()),
644
+				$event
645
+			);
646
+		}
647
+
648
+		$content = '';
649
+		if (has_post_thumbnail($event->ID()) && $this->image_size != 'none') {
650
+			$content .= '
651 651
                 <div class="ee-upcoming-events-widget-img-dv">
652 652
                     <a class="ee-upcoming-events-widget-img" href="' . $event_url . '">
653 653
                         ' . get_the_post_thumbnail($event->ID(), $this->image_size) . '
654 654
                     </a>
655 655
                 </div>';
656
-        }
657
-
658
-        if ($this->show_dates) {
659
-            $content .= $this->eventDates($event);
660
-        }
661
-
662
-        if ($this->show_desc) {
663
-            $allowedtags = AllowedTags::getAllowedTags();
664
-            $desc    = $event->short_description(25);
665
-            $content .= $desc ? '<p style="margin-top: .5em">' . wp_kses($desc, $allowedtags) . '</p>' : '';
666
-        }
667
-
668
-        return $content;
669
-    }
670
-
671
-
672
-    /**
673
-     * @param EE_Event $event
674
-     * @return string
675
-     * @throws EE_Error
676
-     * @throws ReflectionException
677
-     * @since   4.10.14.p
678
-     */
679
-    private function eventDates(EE_Event $event)
680
-    {
681
-        $date_format        = apply_filters(
682
-            'FHEE__espresso_event_date_range__date_format',
683
-            get_option('date_format')
684
-        );
685
-        $time_format        = apply_filters(
686
-            'FHEE__espresso_event_date_range__time_format',
687
-            get_option('time_format')
688
-        );
689
-        $single_date_format = apply_filters(
690
-            'FHEE__espresso_event_date_range__single_date_format',
691
-            get_option('date_format')
692
-        );
693
-        $single_time_format = apply_filters(
694
-            'FHEE__espresso_event_date_range__single_time_format',
695
-            get_option('time_format')
696
-        );
697
-        if ($this->date_range == true) {
698
-            return espresso_event_date_range(
699
-                $date_format,
700
-                $time_format,
701
-                $single_date_format,
702
-                $single_time_format,
703
-                $event->ID(),
704
-                false
705
-            );
706
-        }
707
-        return espresso_list_of_event_dates(
708
-            $event->ID(),
709
-            $date_format,
710
-            $time_format,
711
-            false,
712
-            null,
713
-            true,
714
-            true,
715
-            $this->date_limit
716
-        );
717
-    }
656
+		}
657
+
658
+		if ($this->show_dates) {
659
+			$content .= $this->eventDates($event);
660
+		}
661
+
662
+		if ($this->show_desc) {
663
+			$allowedtags = AllowedTags::getAllowedTags();
664
+			$desc    = $event->short_description(25);
665
+			$content .= $desc ? '<p style="margin-top: .5em">' . wp_kses($desc, $allowedtags) . '</p>' : '';
666
+		}
667
+
668
+		return $content;
669
+	}
670
+
671
+
672
+	/**
673
+	 * @param EE_Event $event
674
+	 * @return string
675
+	 * @throws EE_Error
676
+	 * @throws ReflectionException
677
+	 * @since   4.10.14.p
678
+	 */
679
+	private function eventDates(EE_Event $event)
680
+	{
681
+		$date_format        = apply_filters(
682
+			'FHEE__espresso_event_date_range__date_format',
683
+			get_option('date_format')
684
+		);
685
+		$time_format        = apply_filters(
686
+			'FHEE__espresso_event_date_range__time_format',
687
+			get_option('time_format')
688
+		);
689
+		$single_date_format = apply_filters(
690
+			'FHEE__espresso_event_date_range__single_date_format',
691
+			get_option('date_format')
692
+		);
693
+		$single_time_format = apply_filters(
694
+			'FHEE__espresso_event_date_range__single_time_format',
695
+			get_option('time_format')
696
+		);
697
+		if ($this->date_range == true) {
698
+			return espresso_event_date_range(
699
+				$date_format,
700
+				$time_format,
701
+				$single_date_format,
702
+				$single_time_format,
703
+				$event->ID(),
704
+				false
705
+			);
706
+		}
707
+		return espresso_list_of_event_dates(
708
+			$event->ID(),
709
+			$date_format,
710
+			$time_format,
711
+			false,
712
+			null,
713
+			true,
714
+			true,
715
+			$this->date_limit
716
+		);
717
+	}
718 718
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
             EE_Question_Option::new_instance(['QSO_value' => false, 'QSO_desc' => esc_html__('No', 'event_espresso')]),
110 110
             EE_Question_Option::new_instance(['QSO_value' => true, 'QSO_desc' => esc_html__('Yes', 'event_espresso')]),
111 111
         ];
112
-        $sort_values   = [
112
+        $sort_values = [
113 113
             EE_Question_Option::new_instance(['QSO_value' => 'ASC', 'QSO_desc' => esc_html__('ASC', 'event_espresso')]),
114 114
             EE_Question_Option::new_instance(['QSO_value' => 'DESC', 'QSO_desc' => esc_html__('DESC', 'event_espresso')]),
115 115
         ];
@@ -326,8 +326,8 @@  discard block
 block discarded – undo
326 326
                 // Before widget (defined by themes).
327 327
                 echo wp_kses($before_widget, AllowedTags::getAllowedTags());
328 328
                 // Display the widget title if one was input (before and after defined by themes).
329
-                if (! empty($title)) {
330
-                    echo wp_kses($before_title . $title . $after_title, AllowedTags::getAllowedTags());
329
+                if ( ! empty($title)) {
330
+                    echo wp_kses($before_title.$title.$after_title, AllowedTags::getAllowedTags());
331 331
                 }
332 332
                 echo wp_kses($this->widgetContent($post), AllowedTags::getWithFormTags());
333 333
                 // After widget (defined by themes).
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
      */
347 347
     public function make_the_title_a_link($title)
348 348
     {
349
-        return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>';
349
+        return '<a href="'.EEH_Event_View::event_archive_url().'">'.$title.'</a>';
350 350
     }
351 351
 
352 352
 
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
             foreach ($sizes as $image_size) {
428 428
                 $image_size = trim($image_size);
429 429
                 // no big images plz
430
-                if (! in_array($image_size, ['large', 'post-thumbnail'])) {
430
+                if ( ! in_array($image_size, ['large', 'post-thumbnail'])) {
431 431
                     $image_sizes[] =
432 432
                         EE_Question_Option::new_instance(['QSO_value' => $image_size, 'QSO_desc' => $image_size]);
433 433
                 }
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
     private function parseWidgetSettings(array $instance)
455 455
     {
456 456
         $this->title = isset($instance['title']) && ! empty($instance['title']) ? $instance['title'] : '';
457
-        $this->events_category     = isset($instance['category_name']) && ! empty($instance['category_name'])
457
+        $this->events_category = isset($instance['category_name']) && ! empty($instance['category_name'])
458 458
             ? $instance['category_name']
459 459
             : false;
460 460
         $this->show_expired = isset($instance['show_expired'])
@@ -512,24 +512,24 @@  discard block
 block discarded – undo
512 512
         }
513 513
         $list_items = '';
514 514
         foreach ($events as $event) {
515
-            if ($event instanceof EE_Event && (! is_single() || $post->ID != $event->ID())) {
515
+            if ($event instanceof EE_Event && ( ! is_single() || $post->ID != $event->ID())) {
516 516
                 $event_url = $this->eventUrl($event);
517 517
                 $list_items .= '
518
-                <li id="ee-upcoming-events-widget-li-' . absint($event->ID()) . '" 
518
+                <li id="ee-upcoming-events-widget-li-' . absint($event->ID()).'" 
519 519
                     class="ee-upcoming-events-widget-li"
520 520
                 >
521 521
                     <h5 class="ee-upcoming-events-widget-title-h5">
522
-                        <a class="ee-widget-event-name-a' . $this->linkClass($event) . '" href="' . $event_url . '">
523
-                            ' . esc_html($event->name()) . '
522
+                        <a class="ee-widget-event-name-a' . $this->linkClass($event).'" href="'.$event_url.'">
523
+                            ' . esc_html($event->name()).'
524 524
                         </a>
525 525
                     </h5>
526
-                    ' . $this->eventWidgetContent($event, $event_url) . '
526
+                    ' . $this->eventWidgetContent($event, $event_url).'
527 527
                 </li>';
528 528
             }
529 529
         }
530 530
         return '
531 531
             <ul class="ee-upcoming-events-widget-ul">
532
-                ' . $list_items . '
532
+                ' . $list_items.'
533 533
             </ul>';
534 534
     }
535 535
 
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
         return EEM_Event::instance()->get_all(
562 562
             [
563 563
                 $this->queryWhereParams(),
564
-                'limit'    => '0,' . $this->limit,
564
+                'limit'    => '0,'.$this->limit,
565 565
                 'order_by' => 'Datetime.DTT_EVT_start',
566 566
                 'order'    => $this->order,
567 567
                 'group_by' => 'EVT_ID',
@@ -649,8 +649,8 @@  discard block
 block discarded – undo
649 649
         if (has_post_thumbnail($event->ID()) && $this->image_size != 'none') {
650 650
             $content .= '
651 651
                 <div class="ee-upcoming-events-widget-img-dv">
652
-                    <a class="ee-upcoming-events-widget-img" href="' . $event_url . '">
653
-                        ' . get_the_post_thumbnail($event->ID(), $this->image_size) . '
652
+                    <a class="ee-upcoming-events-widget-img" href="' . $event_url.'">
653
+                        ' . get_the_post_thumbnail($event->ID(), $this->image_size).'
654 654
                     </a>
655 655
                 </div>';
656 656
         }
@@ -661,8 +661,8 @@  discard block
 block discarded – undo
661 661
 
662 662
         if ($this->show_desc) {
663 663
             $allowedtags = AllowedTags::getAllowedTags();
664
-            $desc    = $event->short_description(25);
665
-            $content .= $desc ? '<p style="margin-top: .5em">' . wp_kses($desc, $allowedtags) . '</p>' : '';
664
+            $desc = $event->short_description(25);
665
+            $content .= $desc ? '<p style="margin-top: .5em">'.wp_kses($desc, $allowedtags).'</p>' : '';
666 666
         }
667 667
 
668 668
         return $content;
@@ -678,11 +678,11 @@  discard block
 block discarded – undo
678 678
      */
679 679
     private function eventDates(EE_Event $event)
680 680
     {
681
-        $date_format        = apply_filters(
681
+        $date_format = apply_filters(
682 682
             'FHEE__espresso_event_date_range__date_format',
683 683
             get_option('date_format')
684 684
         );
685
-        $time_format        = apply_filters(
685
+        $time_format = apply_filters(
686 686
             'FHEE__espresso_event_date_range__time_format',
687 687
             get_option('time_format')
688 688
         );
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.36.rc.003');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.36.rc.003');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.