Completed
Branch BUG/11268/session-ticket-relea... (f9aa59)
by
unknown
13:30 queued 24s
created
core/libraries/form_sections/base/EE_Form_Section_Proper.form.php 3 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
      *                                                      with construction finalize being called later
460 460
      *                                                      (realizing that the subsections' html names
461 461
      *                                                      might not be set yet, etc.)
462
-     * @return EE_Form_Section_Base
462
+     * @return EE_Form_Section_Validatable|null
463 463
      * @throws EE_Error
464 464
      */
465 465
     public function get_subsection($name, $require_construction_to_be_finalized = true)
@@ -1289,7 +1289,6 @@  discard block
 block discarded – undo
1289 1289
     /**
1290 1290
      * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1291 1291
      * @param string                           $form_submission_error_message
1292
-     * @param EE_Form_Section_Validatable $form_section unused
1293 1292
      * @throws EE_Error
1294 1293
      */
1295 1294
     public function set_submission_error_message(
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
             //AND we are going to make sure they're in that specified order
112 112
             $reordered_subsections = array();
113 113
             foreach ($options_array['include'] as $input_name) {
114
-                if (isset($this->_subsections[ $input_name ])) {
115
-                    $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
114
+                if (isset($this->_subsections[$input_name])) {
115
+                    $reordered_subsections[$input_name] = $this->_subsections[$input_name];
116 116
                 }
117 117
             }
118 118
             $this->_subsections = $reordered_subsections;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
         if (isset($options_array['layout_strategy'])) {
125 125
             $this->_layout_strategy = $options_array['layout_strategy'];
126 126
         }
127
-        if (! $this->_layout_strategy) {
127
+        if ( ! $this->_layout_strategy) {
128 128
             $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129 129
         }
130 130
         $this->_layout_strategy->_construct_finalize($this);
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
                 $req_data,
278 278
                 $this
279 279
             );
280
-            $this->cached_request_data = (array)$req_data;
280
+            $this->cached_request_data = (array) $req_data;
281 281
         }
282 282
         return $this->cached_request_data;
283 283
     }
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
         if ($validate) {
314 314
             $this->_validate();
315 315
             //if it's invalid, we're going to want to re-display so remember what they submitted
316
-            if (! $this->is_valid()) {
316
+            if ( ! $this->is_valid()) {
317 317
                 $this->store_submitted_form_data_in_session();
318 318
             }
319 319
         }
@@ -426,11 +426,11 @@  discard block
 block discarded – undo
426 426
     public function populate_defaults($default_data)
427 427
     {
428 428
         foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
-            if (isset($default_data[ $subsection_name ])) {
429
+            if (isset($default_data[$subsection_name])) {
430 430
                 if ($subsection instanceof EE_Form_Input_Base) {
431
-                    $subsection->set_default($default_data[ $subsection_name ]);
431
+                    $subsection->set_default($default_data[$subsection_name]);
432 432
                 } elseif ($subsection instanceof EE_Form_Section_Proper) {
433
-                    $subsection->populate_defaults($default_data[ $subsection_name ]);
433
+                    $subsection->populate_defaults($default_data[$subsection_name]);
434 434
                 }
435 435
             }
436 436
         }
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
      */
446 446
     public function subsection_exists($name)
447 447
     {
448
-        return isset($this->_subsections[ $name ]) ? true : false;
448
+        return isset($this->_subsections[$name]) ? true : false;
449 449
     }
450 450
 
451 451
 
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
         if ($require_construction_to_be_finalized) {
468 468
             $this->ensure_construct_finalized_called();
469 469
         }
470
-        return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
470
+        return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
471 471
     }
472 472
 
473 473
 
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
         $validatable_subsections = array();
483 483
         foreach ($this->subsections() as $name => $obj) {
484 484
             if ($obj instanceof EE_Form_Section_Validatable) {
485
-                $validatable_subsections[ $name ] = $obj;
485
+                $validatable_subsections[$name] = $obj;
486 486
             }
487 487
         }
488 488
         return $validatable_subsections;
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
             $name,
510 510
             $require_construction_to_be_finalized
511 511
         );
512
-        if (! $subsection instanceof EE_Form_Input_Base) {
512
+        if ( ! $subsection instanceof EE_Form_Input_Base) {
513 513
             throw new EE_Error(
514 514
                 sprintf(
515 515
                     esc_html__(
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
             $name,
547 547
             $require_construction_to_be_finalized
548 548
         );
549
-        if (! $subsection instanceof EE_Form_Section_Proper) {
549
+        if ( ! $subsection instanceof EE_Form_Section_Proper) {
550 550
             throw new EE_Error(
551 551
                 sprintf(
552 552
                     esc_html__(
@@ -585,8 +585,8 @@  discard block
 block discarded – undo
585 585
      */
586 586
     public function is_valid()
587 587
     {
588
-        if($this->is_valid === null) {
589
-            if (! $this->has_received_submission()) {
588
+        if ($this->is_valid === null) {
589
+            if ( ! $this->has_received_submission()) {
590 590
                 throw new EE_Error(
591 591
                     sprintf(
592 592
                         esc_html__(
@@ -596,14 +596,14 @@  discard block
 block discarded – undo
596 596
                     )
597 597
                 );
598 598
             }
599
-            if (! parent::is_valid()) {
599
+            if ( ! parent::is_valid()) {
600 600
                 $this->is_valid = false;
601 601
             } else {
602 602
                 // ok so no general errors to this entire form section.
603 603
                 // so let's check the subsections, but only set errors if that hasn't been done yet
604 604
                 $this->is_valid = true;
605 605
                 foreach ($this->get_validatable_subsections() as $subsection) {
606
-                    if (! $subsection->is_valid()) {
606
+                    if ( ! $subsection->is_valid()) {
607 607
                         $this->is_valid = false;
608 608
                     }
609 609
                 }
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
      */
621 621
     protected function _set_default_name_if_empty()
622 622
     {
623
-        if (! $this->_name) {
623
+        if ( ! $this->_name) {
624 624
             $classname    = get_class($this);
625 625
             $default_name = str_replace('EE_', '', $classname);
626 626
             $this->_name  = $default_name;
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
     {
711 711
         wp_register_script(
712 712
             'ee_form_section_validation',
713
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
713
+            EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js',
714 714
             array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715 715
             EVENT_ESPRESSO_VERSION,
716 716
             true
@@ -754,13 +754,13 @@  discard block
 block discarded – undo
754 754
         // we only want to localize vars ONCE for the entire form,
755 755
         // so if the form section doesn't have a parent, then it must be the top dog
756 756
         if ($return_for_subsection || ! $this->parent_section()) {
757
-            EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
757
+            EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
758 758
                 'form_section_id'  => $this->html_id(true),
759 759
                 'validation_rules' => $this->get_jquery_validation_rules(),
760 760
                 'other_data'       => $this->get_other_js_data(),
761 761
                 'errors'           => $this->subsection_validation_errors_by_html_name(),
762 762
             );
763
-            EE_Form_Section_Proper::$_scripts_localized                                = true;
763
+            EE_Form_Section_Proper::$_scripts_localized = true;
764 764
         }
765 765
     }
766 766
 
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
         $inputs = array();
796 796
         foreach ($this->subsections() as $subsection) {
797 797
             if ($subsection instanceof EE_Form_Input_Base) {
798
-                $inputs[ $subsection->html_name() ] = $subsection;
798
+                $inputs[$subsection->html_name()] = $subsection;
799 799
             } elseif ($subsection instanceof EE_Form_Section_Proper) {
800 800
                 $inputs += $subsection->inputs_in_subsections();
801 801
             }
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
         $errors = array();
819 819
         foreach ($inputs as $form_input) {
820 820
             if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
-                $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
821
+                $errors[$form_input->html_name()] = $form_input->get_validation_error_string();
822 822
             }
823 823
         }
824 824
         return $errors;
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
         $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842 842
             ? EE_Registry::instance()->CFG->registration->email_validation_level
843 843
             : 'wp_default';
844
-        EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
844
+        EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
845 845
         wp_enqueue_script('ee_form_section_validation');
846 846
         wp_localize_script(
847 847
             'ee_form_section_validation',
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
      */
859 859
     public function ensure_scripts_localized()
860 860
     {
861
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
861
+        if ( ! EE_Form_Section_Proper::$_scripts_localized) {
862 862
             $this->_enqueue_and_localize_form_js();
863 863
         }
864 864
     }
@@ -954,8 +954,8 @@  discard block
 block discarded – undo
954 954
         //reset the cache of whether this form is valid or not- we're re-validating it now
955 955
         $this->is_valid = null;
956 956
         foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
-            if (method_exists($this, '_validate_' . $subsection_name)) {
958
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
957
+            if (method_exists($this, '_validate_'.$subsection_name)) {
958
+                call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection));
959 959
             }
960 960
             $subsection->_validate();
961 961
         }
@@ -973,9 +973,9 @@  discard block
 block discarded – undo
973 973
         $inputs = array();
974 974
         foreach ($this->subsections() as $subsection_name => $subsection) {
975 975
             if ($subsection instanceof EE_Form_Section_Proper) {
976
-                $inputs[ $subsection_name ] = $subsection->valid_data();
976
+                $inputs[$subsection_name] = $subsection->valid_data();
977 977
             } elseif ($subsection instanceof EE_Form_Input_Base) {
978
-                $inputs[ $subsection_name ] = $subsection->normalized_value();
978
+                $inputs[$subsection_name] = $subsection->normalized_value();
979 979
             }
980 980
         }
981 981
         return $inputs;
@@ -993,7 +993,7 @@  discard block
 block discarded – undo
993 993
         $inputs = array();
994 994
         foreach ($this->subsections() as $subsection_name => $subsection) {
995 995
             if ($subsection instanceof EE_Form_Input_Base) {
996
-                $inputs[ $subsection_name ] = $subsection;
996
+                $inputs[$subsection_name] = $subsection;
997 997
             }
998 998
         }
999 999
         return $inputs;
@@ -1011,7 +1011,7 @@  discard block
 block discarded – undo
1011 1011
         $form_sections = array();
1012 1012
         foreach ($this->subsections() as $name => $obj) {
1013 1013
             if ($obj instanceof EE_Form_Section_Proper) {
1014
-                $form_sections[ $name ] = $obj;
1014
+                $form_sections[$name] = $obj;
1015 1015
             }
1016 1016
         }
1017 1017
         return $form_sections;
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
         $input_values = array();
1119 1119
         foreach ($this->subsections() as $subsection_name => $subsection) {
1120 1120
             if ($subsection instanceof EE_Form_Input_Base) {
1121
-                $input_values[ $subsection_name ] = $pretty
1121
+                $input_values[$subsection_name] = $pretty
1122 1122
                     ? $subsection->pretty_value()
1123 1123
                     : $subsection->normalized_value();
1124 1124
             } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
@@ -1130,7 +1130,7 @@  discard block
 block discarded – undo
1130 1130
                 if ($flatten) {
1131 1131
                     $input_values = array_merge($input_values, $subform_input_values);
1132 1132
                 } else {
1133
-                    $input_values[ $subsection_name ] = $subform_input_values;
1133
+                    $input_values[$subsection_name] = $subform_input_values;
1134 1134
                 }
1135 1135
             }
1136 1136
         }
@@ -1158,7 +1158,7 @@  discard block
 block discarded – undo
1158 1158
             if ($subsection instanceof EE_Form_Input_Base) {
1159 1159
                 // is this input part of an array of inputs?
1160 1160
                 if (strpos($subsection->html_name(), '[') !== false) {
1161
-                    $full_input_name  = EEH_Array::convert_array_values_to_keys(
1161
+                    $full_input_name = EEH_Array::convert_array_values_to_keys(
1162 1162
                         explode(
1163 1163
                             '[',
1164 1164
                             str_replace(']', '', $subsection->html_name())
@@ -1167,7 +1167,7 @@  discard block
 block discarded – undo
1167 1167
                     );
1168 1168
                     $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169 1169
                 } else {
1170
-                    $submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1170
+                    $submitted_values[$subsection->html_name()] = $subsection->raw_value();
1171 1171
                 }
1172 1172
             } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173 1173
                 $subform_input_values = $subsection->submitted_values($include_subforms);
@@ -1202,7 +1202,7 @@  discard block
 block discarded – undo
1202 1202
     public function exclude(array $inputs_to_exclude = array())
1203 1203
     {
1204 1204
         foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
-            unset($this->_subsections[ $input_to_exclude_name ]);
1205
+            unset($this->_subsections[$input_to_exclude_name]);
1206 1206
         }
1207 1207
     }
1208 1208
 
@@ -1244,7 +1244,7 @@  discard block
 block discarded – undo
1244 1244
     public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1245 1245
     {
1246 1246
         foreach ($new_subsections as $subsection_name => $subsection) {
1247
-            if (! $subsection instanceof EE_Form_Section_Base) {
1247
+            if ( ! $subsection instanceof EE_Form_Section_Base) {
1248 1248
                 EE_Error::add_error(
1249 1249
                     sprintf(
1250 1250
                         esc_html__(
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
                         $this->name()
1257 1257
                     )
1258 1258
                 );
1259
-                unset($new_subsections[ $subsection_name ]);
1259
+                unset($new_subsections[$subsection_name]);
1260 1260
             }
1261 1261
         }
1262 1262
         $this->_subsections = EEH_Array::insert_into_array(
@@ -1348,7 +1348,7 @@  discard block
 block discarded – undo
1348 1348
     public function html_name_prefix()
1349 1349
     {
1350 1350
         if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1351
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1351
+            return $this->parent_section()->html_name_prefix().'['.$this->name().']';
1352 1352
         }
1353 1353
         return $this->name();
1354 1354
     }
@@ -1388,7 +1388,7 @@  discard block
 block discarded – undo
1388 1388
      */
1389 1389
     public function ensure_construct_finalized_called()
1390 1390
     {
1391
-        if (! $this->_construction_finalized) {
1391
+        if ( ! $this->_construction_finalized) {
1392 1392
             $this->_construct_finalize($this->_parent_section, $this->_name);
1393 1393
         }
1394 1394
     }
@@ -1460,7 +1460,7 @@  discard block
 block discarded – undo
1460 1460
                 $form_section = $validation_error->get_form_section();
1461 1461
                 if ($form_section instanceof EE_Form_Input_Base) {
1462 1462
                    $label = $validation_error->get_form_section()->html_label_text();
1463
-                } elseif($form_section instanceof EE_Form_Section_Validatable) {
1463
+                } elseif ($form_section instanceof EE_Form_Section_Validatable) {
1464 1464
                     $label = $validation_error->get_form_section()->name();
1465 1465
                 } else {
1466 1466
                     $label = esc_html__('Unknown', 'event_espresso');
Please login to merge, or discard this patch.
Indentation   +1500 added lines, -1500 removed lines patch added patch discarded remove patch
@@ -14,1505 +14,1505 @@
 block discarded – undo
14 14
 class EE_Form_Section_Proper extends EE_Form_Section_Validatable
15 15
 {
16 16
 
17
-    const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
-
19
-    /**
20
-     * Subsections
21
-     *
22
-     * @var EE_Form_Section_Validatable[]
23
-     */
24
-    protected $_subsections = array();
25
-
26
-    /**
27
-     * Strategy for laying out the form
28
-     *
29
-     * @var EE_Form_Section_Layout_Base
30
-     */
31
-    protected $_layout_strategy;
32
-
33
-    /**
34
-     * Whether or not this form has received and validated a form submission yet
35
-     *
36
-     * @var boolean
37
-     */
38
-    protected $_received_submission = false;
39
-
40
-    /**
41
-     * message displayed to users upon successful form submission
42
-     *
43
-     * @var string
44
-     */
45
-    protected $_form_submission_success_message = '';
46
-
47
-    /**
48
-     * message displayed to users upon unsuccessful form submission
49
-     *
50
-     * @var string
51
-     */
52
-    protected $_form_submission_error_message = '';
53
-
54
-    /**
55
-     * @var array like $_REQUEST
56
-     */
57
-    protected $cached_request_data;
58
-
59
-    /**
60
-     * Stores whether this form (and its sub-sections) were found to be valid or not.
61
-     * Starts off as null, but once the form is validated, it set to either true or false
62
-     * @var boolean|null
63
-     */
64
-    protected $is_valid;
65
-
66
-    /**
67
-     * Stores all the data that will localized for form validation
68
-     *
69
-     * @var array
70
-     */
71
-    static protected $_js_localization = array();
72
-
73
-    /**
74
-     * whether or not the form's localized validation JS vars have been set
75
-     *
76
-     * @type boolean
77
-     */
78
-    static protected $_scripts_localized = false;
79
-
80
-
81
-    /**
82
-     * when constructing a proper form section, calls _construct_finalize on children
83
-     * so that they know who their parent is, and what name they've been given.
84
-     *
85
-     * @param array[] $options_array   {
86
-     * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
-     * @type          $include         string[] numerically-indexed where values are section names to be included,
88
-     *                                 and in that order. This is handy if you want
89
-     *                                 the subsections to be ordered differently than the default, and if you override
90
-     *                                 which fields are shown
91
-     * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
-     *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
-     *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
-     *                                 items from that list of inclusions)
95
-     * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
-     *                                 } @see EE_Form_Section_Validatable::__construct()
97
-     * @throws EE_Error
98
-     */
99
-    public function __construct($options_array = array())
100
-    {
101
-        $options_array = (array) apply_filters(
102
-            'FHEE__EE_Form_Section_Proper___construct__options_array',
103
-            $options_array,
104
-            $this
105
-        );
106
-        //call parent first, as it may be setting the name
107
-        parent::__construct($options_array);
108
-        //if they've included subsections in the constructor, add them now
109
-        if (isset($options_array['include'])) {
110
-            //we are going to make sure we ONLY have those subsections to include
111
-            //AND we are going to make sure they're in that specified order
112
-            $reordered_subsections = array();
113
-            foreach ($options_array['include'] as $input_name) {
114
-                if (isset($this->_subsections[ $input_name ])) {
115
-                    $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
-                }
117
-            }
118
-            $this->_subsections = $reordered_subsections;
119
-        }
120
-        if (isset($options_array['exclude'])) {
121
-            $exclude            = $options_array['exclude'];
122
-            $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
-        }
124
-        if (isset($options_array['layout_strategy'])) {
125
-            $this->_layout_strategy = $options_array['layout_strategy'];
126
-        }
127
-        if (! $this->_layout_strategy) {
128
-            $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
-        }
130
-        $this->_layout_strategy->_construct_finalize($this);
131
-        //ok so we are definitely going to want the forms JS,
132
-        //so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
-            //ok so they've constructed this object after when they should have.
135
-            //just enqueue the generic form scripts and initialize the form immediately in the JS
136
-            EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
-        } else {
138
-            add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
-            add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
-        }
141
-        add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
-        /**
143
-         * Gives other plugins a chance to hook in before construct finalize is called.
144
-         * The form probably doesn't yet have a parent form section.
145
-         * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
-         * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
-         * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
-         *
149
-         * @since 4.9.32
150
-         * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
-         *                                              except maybe calling _construct_finalize has been done
152
-         * @param array                  $options_array options passed into the constructor
153
-         */
154
-        do_action(
155
-            'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
-            $this,
157
-            $options_array
158
-        );
159
-        if (isset($options_array['name'])) {
160
-            $this->_construct_finalize(null, $options_array['name']);
161
-        }
162
-    }
163
-
164
-
165
-    /**
166
-     * Finishes construction given the parent form section and this form section's name
167
-     *
168
-     * @param EE_Form_Section_Proper $parent_form_section
169
-     * @param string                 $name
170
-     * @throws EE_Error
171
-     */
172
-    public function _construct_finalize($parent_form_section, $name)
173
-    {
174
-        parent::_construct_finalize($parent_form_section, $name);
175
-        $this->_set_default_name_if_empty();
176
-        $this->_set_default_html_id_if_empty();
177
-        foreach ($this->_subsections as $subsection_name => $subsection) {
178
-            if ($subsection instanceof EE_Form_Section_Base) {
179
-                $subsection->_construct_finalize($this, $subsection_name);
180
-            } else {
181
-                throw new EE_Error(
182
-                    sprintf(
183
-                        esc_html__(
184
-                            'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
-                            'event_espresso'
186
-                        ),
187
-                        $subsection_name,
188
-                        get_class($this),
189
-                        $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
-                    )
191
-                );
192
-            }
193
-        }
194
-        /**
195
-         * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
-         * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
-         * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
-         * This might only happen just before displaying the form, or just before it receives form submission data.
199
-         * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
-         * ensured it has a name, HTML IDs, etc
201
-         *
202
-         * @param EE_Form_Section_Proper      $this
203
-         * @param EE_Form_Section_Proper|null $parent_form_section
204
-         * @param string                      $name
205
-         */
206
-        do_action(
207
-            'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
-            $this,
209
-            $parent_form_section,
210
-            $name
211
-        );
212
-    }
213
-
214
-
215
-    /**
216
-     * Gets the layout strategy for this form section
217
-     *
218
-     * @return EE_Form_Section_Layout_Base
219
-     */
220
-    public function get_layout_strategy()
221
-    {
222
-        return $this->_layout_strategy;
223
-    }
224
-
225
-
226
-    /**
227
-     * Gets the HTML for a single input for this form section according
228
-     * to the layout strategy
229
-     *
230
-     * @param EE_Form_Input_Base $input
231
-     * @return string
232
-     */
233
-    public function get_html_for_input($input)
234
-    {
235
-        return $this->_layout_strategy->layout_input($input);
236
-    }
237
-
238
-
239
-    /**
240
-     * was_submitted - checks if form inputs are present in request data
241
-     * Basically an alias for form_data_present_in() (which is used by both
242
-     * proper form sections and form inputs)
243
-     *
244
-     * @param null $form_data
245
-     * @return boolean
246
-     * @throws EE_Error
247
-     */
248
-    public function was_submitted($form_data = null)
249
-    {
250
-        return $this->form_data_present_in($form_data);
251
-    }
252
-
253
-    /**
254
-     * Gets the cached request data; but if there is none, or $req_data was set with
255
-     * something different, refresh the cache, and then return it
256
-     * @param null $req_data
257
-     * @return array
258
-     */
259
-    protected function getCachedRequest($req_data = null)
260
-    {
261
-        if ($this->cached_request_data === null
262
-            || (
263
-                $req_data !== null &&
264
-                $req_data !== $this->cached_request_data
265
-            )
266
-        ) {
267
-            $req_data = apply_filters(
268
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
269
-                $req_data,
270
-                $this
271
-            );
272
-            if ($req_data === null) {
273
-                $req_data = array_merge($_GET, $_POST);
274
-            }
275
-            $req_data = apply_filters(
276
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
277
-                $req_data,
278
-                $this
279
-            );
280
-            $this->cached_request_data = (array)$req_data;
281
-        }
282
-        return $this->cached_request_data;
283
-    }
284
-
285
-
286
-    /**
287
-     * After the form section is initially created, call this to sanitize the data in the submission
288
-     * which relates to this form section, validate it, and set it as properties on the form.
289
-     *
290
-     * @param array|null $req_data should usually be $_POST (the default).
291
-     *                             However, you CAN supply a different array.
292
-     *                             Consider using set_defaults() instead however.
293
-     *                             (If you rendered the form in the page using echo $form_x->get_html()
294
-     *                             the inputs will have the correct name in the request data for this function
295
-     *                             to find them and populate the form with them.
296
-     *                             If you have a flat form (with only input subsections),
297
-     *                             you can supply a flat array where keys
298
-     *                             are the form input names and values are their values)
299
-     * @param boolean    $validate whether or not to perform validation on this data. Default is,
300
-     *                             of course, to validate that data, and set errors on the invalid values.
301
-     *                             But if the data has already been validated
302
-     *                             (eg you validated the data then stored it in the DB)
303
-     *                             you may want to skip this step.
304
-     * @throws InvalidArgumentException
305
-     * @throws InvalidInterfaceException
306
-     * @throws InvalidDataTypeException
307
-     * @throws EE_Error
308
-     */
309
-    public function receive_form_submission($req_data = null, $validate = true)
310
-    {
311
-        $req_data = $this->getCachedRequest($req_data);
312
-        $this->_normalize($req_data);
313
-        if ($validate) {
314
-            $this->_validate();
315
-            //if it's invalid, we're going to want to re-display so remember what they submitted
316
-            if (! $this->is_valid()) {
317
-                $this->store_submitted_form_data_in_session();
318
-            }
319
-        }
320
-        if ($this->submission_error_message() === '' && ! $this->is_valid()) {
321
-            $this->set_submission_error_message();
322
-        }
323
-        do_action(
324
-            'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
325
-            $req_data,
326
-            $this,
327
-            $validate
328
-        );
329
-    }
330
-
331
-
332
-    /**
333
-     * caches the originally submitted input values in the session
334
-     * so that they can be used to repopulate the form if it failed validation
335
-     *
336
-     * @return boolean whether or not the data was successfully stored in the session
337
-     * @throws InvalidArgumentException
338
-     * @throws InvalidInterfaceException
339
-     * @throws InvalidDataTypeException
340
-     * @throws EE_Error
341
-     */
342
-    protected function store_submitted_form_data_in_session()
343
-    {
344
-        return EE_Registry::instance()->SSN->set_session_data(
345
-            array(
346
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
347
-            )
348
-        );
349
-    }
350
-
351
-
352
-    /**
353
-     * retrieves the originally submitted input values in the session
354
-     * so that they can be used to repopulate the form if it failed validation
355
-     *
356
-     * @return array
357
-     * @throws InvalidArgumentException
358
-     * @throws InvalidInterfaceException
359
-     * @throws InvalidDataTypeException
360
-     */
361
-    protected function get_submitted_form_data_from_session()
362
-    {
363
-        $session = EE_Registry::instance()->SSN;
364
-        if ($session instanceof EE_Session) {
365
-            return $session->get_session_data(
366
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
367
-            );
368
-        }
369
-        return array();
370
-    }
371
-
372
-
373
-    /**
374
-     * flushed the originally submitted input values from the session
375
-     *
376
-     * @return boolean whether or not the data was successfully removed from the session
377
-     * @throws InvalidArgumentException
378
-     * @throws InvalidInterfaceException
379
-     * @throws InvalidDataTypeException
380
-     */
381
-    protected function flush_submitted_form_data_from_session()
382
-    {
383
-        return EE_Registry::instance()->SSN->reset_data(
384
-            array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
385
-        );
386
-    }
387
-
388
-
389
-    /**
390
-     * Populates this form and its subsections with data from the session.
391
-     * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
392
-     * validation errors when displaying too)
393
-     * Returns true if the form was populated from the session, false otherwise
394
-     *
395
-     * @return boolean
396
-     * @throws InvalidArgumentException
397
-     * @throws InvalidInterfaceException
398
-     * @throws InvalidDataTypeException
399
-     * @throws EE_Error
400
-     */
401
-    public function populate_from_session()
402
-    {
403
-        $form_data_in_session = $this->get_submitted_form_data_from_session();
404
-        if (empty($form_data_in_session)) {
405
-            return false;
406
-        }
407
-        $this->receive_form_submission($form_data_in_session);
408
-        $this->flush_submitted_form_data_from_session();
409
-        if ($this->form_data_present_in($form_data_in_session)) {
410
-            return true;
411
-        }
412
-        return false;
413
-    }
414
-
415
-
416
-    /**
417
-     * Populates the default data for the form, given an array where keys are
418
-     * the input names, and values are their values (preferably normalized to be their
419
-     * proper PHP types, not all strings... although that should be ok too).
420
-     * Proper subsections are sub-arrays, the key being the subsection's name, and
421
-     * the value being an array formatted in teh same way
422
-     *
423
-     * @param array $default_data
424
-     * @throws EE_Error
425
-     */
426
-    public function populate_defaults($default_data)
427
-    {
428
-        foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
-            if (isset($default_data[ $subsection_name ])) {
430
-                if ($subsection instanceof EE_Form_Input_Base) {
431
-                    $subsection->set_default($default_data[ $subsection_name ]);
432
-                } elseif ($subsection instanceof EE_Form_Section_Proper) {
433
-                    $subsection->populate_defaults($default_data[ $subsection_name ]);
434
-                }
435
-            }
436
-        }
437
-    }
438
-
439
-
440
-    /**
441
-     * returns true if subsection exists
442
-     *
443
-     * @param string $name
444
-     * @return boolean
445
-     */
446
-    public function subsection_exists($name)
447
-    {
448
-        return isset($this->_subsections[ $name ]) ? true : false;
449
-    }
450
-
451
-
452
-    /**
453
-     * Gets the subsection specified by its name
454
-     *
455
-     * @param string  $name
456
-     * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
457
-     *                                                      so that the inputs will be properly configured.
458
-     *                                                      However, some client code may be ok
459
-     *                                                      with construction finalize being called later
460
-     *                                                      (realizing that the subsections' html names
461
-     *                                                      might not be set yet, etc.)
462
-     * @return EE_Form_Section_Base
463
-     * @throws EE_Error
464
-     */
465
-    public function get_subsection($name, $require_construction_to_be_finalized = true)
466
-    {
467
-        if ($require_construction_to_be_finalized) {
468
-            $this->ensure_construct_finalized_called();
469
-        }
470
-        return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
471
-    }
472
-
473
-
474
-    /**
475
-     * Gets all the validatable subsections of this form section
476
-     *
477
-     * @return EE_Form_Section_Validatable[]
478
-     * @throws EE_Error
479
-     */
480
-    public function get_validatable_subsections()
481
-    {
482
-        $validatable_subsections = array();
483
-        foreach ($this->subsections() as $name => $obj) {
484
-            if ($obj instanceof EE_Form_Section_Validatable) {
485
-                $validatable_subsections[ $name ] = $obj;
486
-            }
487
-        }
488
-        return $validatable_subsections;
489
-    }
490
-
491
-
492
-    /**
493
-     * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
494
-     * throw an EE_Error.
495
-     *
496
-     * @param string  $name
497
-     * @param boolean $require_construction_to_be_finalized most client code should
498
-     *                                                      leave this as TRUE so that the inputs will be properly
499
-     *                                                      configured. However, some client code may be ok with
500
-     *                                                      construction finalize being called later
501
-     *                                                      (realizing that the subsections' html names might not be
502
-     *                                                      set yet, etc.)
503
-     * @return EE_Form_Input_Base
504
-     * @throws EE_Error
505
-     */
506
-    public function get_input($name, $require_construction_to_be_finalized = true)
507
-    {
508
-        $subsection = $this->get_subsection(
509
-            $name,
510
-            $require_construction_to_be_finalized
511
-        );
512
-        if (! $subsection instanceof EE_Form_Input_Base) {
513
-            throw new EE_Error(
514
-                sprintf(
515
-                    esc_html__(
516
-                        "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
517
-                        'event_espresso'
518
-                    ),
519
-                    $name,
520
-                    get_class($this),
521
-                    $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
522
-                )
523
-            );
524
-        }
525
-        return $subsection;
526
-    }
527
-
528
-
529
-    /**
530
-     * Like get_input(), gets the proper subsection of the form given the name,
531
-     * otherwise throws an EE_Error
532
-     *
533
-     * @param string  $name
534
-     * @param boolean $require_construction_to_be_finalized most client code should
535
-     *                                                      leave this as TRUE so that the inputs will be properly
536
-     *                                                      configured. However, some client code may be ok with
537
-     *                                                      construction finalize being called later
538
-     *                                                      (realizing that the subsections' html names might not be
539
-     *                                                      set yet, etc.)
540
-     * @return EE_Form_Section_Proper
541
-     * @throws EE_Error
542
-     */
543
-    public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
544
-    {
545
-        $subsection = $this->get_subsection(
546
-            $name,
547
-            $require_construction_to_be_finalized
548
-        );
549
-        if (! $subsection instanceof EE_Form_Section_Proper) {
550
-            throw new EE_Error(
551
-                sprintf(
552
-                    esc_html__(
553
-                        "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
554
-                        'event_espresso'
555
-                    ),
556
-                    $name,
557
-                    get_class($this)
558
-                )
559
-            );
560
-        }
561
-        return $subsection;
562
-    }
563
-
564
-
565
-    /**
566
-     * Gets the value of the specified input. Should be called after receive_form_submission()
567
-     * or populate_defaults() on the form, where the normalized value on the input is set.
568
-     *
569
-     * @param string $name
570
-     * @return mixed depending on the input's type and its normalization strategy
571
-     * @throws EE_Error
572
-     */
573
-    public function get_input_value($name)
574
-    {
575
-        $input = $this->get_input($name);
576
-        return $input->normalized_value();
577
-    }
578
-
579
-
580
-    /**
581
-     * Checks if this form section itself is valid, and then checks its subsections
582
-     *
583
-     * @throws EE_Error
584
-     * @return boolean
585
-     */
586
-    public function is_valid()
587
-    {
588
-        if($this->is_valid === null) {
589
-            if (! $this->has_received_submission()) {
590
-                throw new EE_Error(
591
-                    sprintf(
592
-                        esc_html__(
593
-                            'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
594
-                            'event_espresso'
595
-                        )
596
-                    )
597
-                );
598
-            }
599
-            if (! parent::is_valid()) {
600
-                $this->is_valid = false;
601
-            } else {
602
-                // ok so no general errors to this entire form section.
603
-                // so let's check the subsections, but only set errors if that hasn't been done yet
604
-                $this->is_valid = true;
605
-                foreach ($this->get_validatable_subsections() as $subsection) {
606
-                    if (! $subsection->is_valid()) {
607
-                        $this->is_valid = false;
608
-                    }
609
-                }
610
-            }
611
-        }
612
-        return $this->is_valid;
613
-    }
614
-
615
-
616
-    /**
617
-     * gets the default name of this form section if none is specified
618
-     *
619
-     * @return void
620
-     */
621
-    protected function _set_default_name_if_empty()
622
-    {
623
-        if (! $this->_name) {
624
-            $classname    = get_class($this);
625
-            $default_name = str_replace('EE_', '', $classname);
626
-            $this->_name  = $default_name;
627
-        }
628
-    }
629
-
630
-
631
-    /**
632
-     * Returns the HTML for the form, except for the form opening and closing tags
633
-     * (as the form section doesn't know where you necessarily want to send the information to),
634
-     * and except for a submit button. Enqueues JS and CSS; if called early enough we will
635
-     * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
636
-     * Not doing_it_wrong because theoretically this CAN be used properly,
637
-     * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
638
-     * any CSS.
639
-     *
640
-     * @throws InvalidArgumentException
641
-     * @throws InvalidInterfaceException
642
-     * @throws InvalidDataTypeException
643
-     * @throws EE_Error
644
-     */
645
-    public function get_html_and_js()
646
-    {
647
-        $this->enqueue_js();
648
-        return $this->get_html();
649
-    }
650
-
651
-
652
-    /**
653
-     * returns HTML for displaying this form section. recursively calls display_section() on all subsections
654
-     *
655
-     * @param bool $display_previously_submitted_data
656
-     * @return string
657
-     * @throws InvalidArgumentException
658
-     * @throws InvalidInterfaceException
659
-     * @throws InvalidDataTypeException
660
-     * @throws EE_Error
661
-     * @throws EE_Error
662
-     * @throws EE_Error
663
-     */
664
-    public function get_html($display_previously_submitted_data = true)
665
-    {
666
-        $this->ensure_construct_finalized_called();
667
-        if ($display_previously_submitted_data) {
668
-            $this->populate_from_session();
669
-        }
670
-        return $this->_form_html_filter
671
-            ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
672
-            : $this->_layout_strategy->layout_form();
673
-    }
674
-
675
-
676
-    /**
677
-     * enqueues JS and CSS for the form.
678
-     * It is preferred to call this before wp_enqueue_scripts so the
679
-     * scripts and styles can be put in the header, but if called later
680
-     * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
681
-     * only be in the header; but in HTML5 its ok in the body.
682
-     * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
683
-     * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
684
-     *
685
-     * @return void
686
-     * @throws EE_Error
687
-     */
688
-    public function enqueue_js()
689
-    {
690
-        $this->_enqueue_and_localize_form_js();
691
-        foreach ($this->subsections() as $subsection) {
692
-            $subsection->enqueue_js();
693
-        }
694
-    }
695
-
696
-
697
-    /**
698
-     * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
699
-     * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
700
-     * the wp_enqueue_scripts hook.
701
-     * However, registering the form js and localizing it can happen when we
702
-     * actually output the form (which is preferred, seeing how teh form's fields
703
-     * could change until it's actually outputted)
704
-     *
705
-     * @param boolean $init_form_validation_automatically whether or not we want the form validation
706
-     *                                                    to be triggered automatically or not
707
-     * @return void
708
-     */
709
-    public static function wp_enqueue_scripts($init_form_validation_automatically = true)
710
-    {
711
-        wp_register_script(
712
-            'ee_form_section_validation',
713
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
714
-            array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715
-            EVENT_ESPRESSO_VERSION,
716
-            true
717
-        );
718
-        wp_localize_script(
719
-            'ee_form_section_validation',
720
-            'ee_form_section_validation_init',
721
-            array('init' => $init_form_validation_automatically ? '1' : '0')
722
-        );
723
-    }
724
-
725
-
726
-    /**
727
-     * gets the variables used by form_section_validation.js.
728
-     * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
729
-     * but before the wordpress hook wp_loaded
730
-     *
731
-     * @throws EE_Error
732
-     */
733
-    public function _enqueue_and_localize_form_js()
734
-    {
735
-        $this->ensure_construct_finalized_called();
736
-        //actually, we don't want to localize just yet. There may be other forms on the page.
737
-        //so we need to add our form section data to a static variable accessible by all form sections
738
-        //and localize it just before the footer
739
-        $this->localize_validation_rules();
740
-        add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
741
-        add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
742
-    }
743
-
744
-
745
-    /**
746
-     * add our form section data to a static variable accessible by all form sections
747
-     *
748
-     * @param bool $return_for_subsection
749
-     * @return void
750
-     * @throws EE_Error
751
-     */
752
-    public function localize_validation_rules($return_for_subsection = false)
753
-    {
754
-        // we only want to localize vars ONCE for the entire form,
755
-        // so if the form section doesn't have a parent, then it must be the top dog
756
-        if ($return_for_subsection || ! $this->parent_section()) {
757
-            EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
758
-                'form_section_id'  => $this->html_id(true),
759
-                'validation_rules' => $this->get_jquery_validation_rules(),
760
-                'other_data'       => $this->get_other_js_data(),
761
-                'errors'           => $this->subsection_validation_errors_by_html_name(),
762
-            );
763
-            EE_Form_Section_Proper::$_scripts_localized                                = true;
764
-        }
765
-    }
766
-
767
-
768
-    /**
769
-     * Gets an array of extra data that will be useful for client-side javascript.
770
-     * This is primarily data added by inputs and forms in addition to any
771
-     * scripts they might enqueue
772
-     *
773
-     * @param array $form_other_js_data
774
-     * @return array
775
-     * @throws EE_Error
776
-     */
777
-    public function get_other_js_data($form_other_js_data = array())
778
-    {
779
-        foreach ($this->subsections() as $subsection) {
780
-            $form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
781
-        }
782
-        return $form_other_js_data;
783
-    }
784
-
785
-
786
-    /**
787
-     * Gets a flat array of inputs for this form section and its subsections.
788
-     * Keys are their form names, and values are the inputs themselves
789
-     *
790
-     * @return EE_Form_Input_Base
791
-     * @throws EE_Error
792
-     */
793
-    public function inputs_in_subsections()
794
-    {
795
-        $inputs = array();
796
-        foreach ($this->subsections() as $subsection) {
797
-            if ($subsection instanceof EE_Form_Input_Base) {
798
-                $inputs[ $subsection->html_name() ] = $subsection;
799
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
800
-                $inputs += $subsection->inputs_in_subsections();
801
-            }
802
-        }
803
-        return $inputs;
804
-    }
805
-
806
-
807
-    /**
808
-     * Gets a flat array of all the validation errors.
809
-     * Keys are html names (because those should be unique)
810
-     * and values are a string of all their validation errors
811
-     *
812
-     * @return string[]
813
-     * @throws EE_Error
814
-     */
815
-    public function subsection_validation_errors_by_html_name()
816
-    {
817
-        $inputs = $this->inputs();
818
-        $errors = array();
819
-        foreach ($inputs as $form_input) {
820
-            if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
-                $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
822
-            }
823
-        }
824
-        return $errors;
825
-    }
826
-
827
-
828
-    /**
829
-     * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
830
-     * Should be setup by each form during the _enqueues_and_localize_form_js
831
-     *
832
-     * @throws InvalidArgumentException
833
-     * @throws InvalidInterfaceException
834
-     * @throws InvalidDataTypeException
835
-     */
836
-    public static function localize_script_for_all_forms()
837
-    {
838
-        //allow inputs and stuff to hook in their JS and stuff here
839
-        do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
840
-        EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
841
-        $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
843
-            : 'wp_default';
844
-        EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
845
-        wp_enqueue_script('ee_form_section_validation');
846
-        wp_localize_script(
847
-            'ee_form_section_validation',
848
-            'ee_form_section_vars',
849
-            EE_Form_Section_Proper::$_js_localization
850
-        );
851
-    }
852
-
853
-
854
-    /**
855
-     * ensure_scripts_localized
856
-     *
857
-     * @throws EE_Error
858
-     */
859
-    public function ensure_scripts_localized()
860
-    {
861
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
862
-            $this->_enqueue_and_localize_form_js();
863
-        }
864
-    }
865
-
866
-
867
-    /**
868
-     * Gets the hard-coded validation error messages to be used in the JS. The convention
869
-     * is that the key here should be the same as the custom validation rule put in the JS file
870
-     *
871
-     * @return array keys are custom validation rules, and values are internationalized strings
872
-     */
873
-    private static function _get_localized_error_messages()
874
-    {
875
-        return array(
876
-            'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'),
877
-            'regex'    => esc_html__('Please check your input', 'event_espresso'),
878
-        );
879
-    }
880
-
881
-
882
-    /**
883
-     * @return array
884
-     */
885
-    public static function js_localization()
886
-    {
887
-        return self::$_js_localization;
888
-    }
889
-
890
-
891
-    /**
892
-     * @return void
893
-     */
894
-    public static function reset_js_localization()
895
-    {
896
-        self::$_js_localization = array();
897
-    }
898
-
899
-
900
-    /**
901
-     * Gets the JS to put inside the jquery validation rules for subsection of this form section.
902
-     * See parent function for more...
903
-     *
904
-     * @return array
905
-     * @throws EE_Error
906
-     */
907
-    public function get_jquery_validation_rules()
908
-    {
909
-        $jquery_validation_rules = array();
910
-        foreach ($this->get_validatable_subsections() as $subsection) {
911
-            $jquery_validation_rules = array_merge(
912
-                $jquery_validation_rules,
913
-                $subsection->get_jquery_validation_rules()
914
-            );
915
-        }
916
-        return $jquery_validation_rules;
917
-    }
918
-
919
-
920
-    /**
921
-     * Sanitizes all the data and sets the sanitized value of each field
922
-     *
923
-     * @param array $req_data like $_POST
924
-     * @return void
925
-     * @throws EE_Error
926
-     */
927
-    protected function _normalize($req_data)
928
-    {
929
-        $this->_received_submission = true;
930
-        $this->_validation_errors   = array();
931
-        foreach ($this->get_validatable_subsections() as $subsection) {
932
-            try {
933
-                $subsection->_normalize($req_data);
934
-            } catch (EE_Validation_Error $e) {
935
-                $subsection->add_validation_error($e);
936
-            }
937
-        }
938
-    }
939
-
940
-
941
-    /**
942
-     * Performs validation on this form section and its subsections.
943
-     * For each subsection,
944
-     * calls _validate_{subsection_name} on THIS form (if the function exists)
945
-     * and passes it the subsection, then calls _validate on that subsection.
946
-     * If you need to perform validation on the form as a whole (considering multiple)
947
-     * you would be best to override this _validate method,
948
-     * calling parent::_validate() first.
949
-     *
950
-     * @throws EE_Error
951
-     */
952
-    protected function _validate()
953
-    {
954
-        //reset the cache of whether this form is valid or not- we're re-validating it now
955
-        $this->is_valid = null;
956
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
-            if (method_exists($this, '_validate_' . $subsection_name)) {
958
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
959
-            }
960
-            $subsection->_validate();
961
-        }
962
-    }
963
-
964
-
965
-    /**
966
-     * Gets all the validated inputs for the form section
967
-     *
968
-     * @return array
969
-     * @throws EE_Error
970
-     */
971
-    public function valid_data()
972
-    {
973
-        $inputs = array();
974
-        foreach ($this->subsections() as $subsection_name => $subsection) {
975
-            if ($subsection instanceof EE_Form_Section_Proper) {
976
-                $inputs[ $subsection_name ] = $subsection->valid_data();
977
-            } elseif ($subsection instanceof EE_Form_Input_Base) {
978
-                $inputs[ $subsection_name ] = $subsection->normalized_value();
979
-            }
980
-        }
981
-        return $inputs;
982
-    }
983
-
984
-
985
-    /**
986
-     * Gets all the inputs on this form section
987
-     *
988
-     * @return EE_Form_Input_Base[]
989
-     * @throws EE_Error
990
-     */
991
-    public function inputs()
992
-    {
993
-        $inputs = array();
994
-        foreach ($this->subsections() as $subsection_name => $subsection) {
995
-            if ($subsection instanceof EE_Form_Input_Base) {
996
-                $inputs[ $subsection_name ] = $subsection;
997
-            }
998
-        }
999
-        return $inputs;
1000
-    }
1001
-
1002
-
1003
-    /**
1004
-     * Gets all the subsections which are a proper form
1005
-     *
1006
-     * @return EE_Form_Section_Proper[]
1007
-     * @throws EE_Error
1008
-     */
1009
-    public function subforms()
1010
-    {
1011
-        $form_sections = array();
1012
-        foreach ($this->subsections() as $name => $obj) {
1013
-            if ($obj instanceof EE_Form_Section_Proper) {
1014
-                $form_sections[ $name ] = $obj;
1015
-            }
1016
-        }
1017
-        return $form_sections;
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * Gets all the subsections (inputs, proper subsections, or html-only sections).
1023
-     * Consider using inputs() or subforms()
1024
-     * if you only want form inputs or proper form sections.
1025
-     *
1026
-     * @param boolean $require_construction_to_be_finalized most client code should
1027
-     *                                                      leave this as TRUE so that the inputs will be properly
1028
-     *                                                      configured. However, some client code may be ok with
1029
-     *                                                      construction finalize being called later
1030
-     *                                                      (realizing that the subsections' html names might not be
1031
-     *                                                      set yet, etc.)
1032
-     * @return EE_Form_Section_Proper[]
1033
-     * @throws EE_Error
1034
-     */
1035
-    public function subsections($require_construction_to_be_finalized = true)
1036
-    {
1037
-        if ($require_construction_to_be_finalized) {
1038
-            $this->ensure_construct_finalized_called();
1039
-        }
1040
-        return $this->_subsections;
1041
-    }
1042
-
1043
-
1044
-    /**
1045
-     * Returns whether this form has any subforms or inputs
1046
-     * @return bool
1047
-     */
1048
-    public function hasSubsections()
1049
-    {
1050
-        return ! empty($this->_subsections);
1051
-    }
1052
-
1053
-
1054
-    /**
1055
-     * Returns a simple array where keys are input names, and values are their normalized
1056
-     * values. (Similar to calling get_input_value on inputs)
1057
-     *
1058
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1059
-     *                                        or just this forms' direct children inputs
1060
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1061
-     *                                        or allow multidimensional array
1062
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1063
-     *                                        with array keys being input names
1064
-     *                                        (regardless of whether they are from a subsection or not),
1065
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1066
-     *                                        where keys are always subsection names and values are either
1067
-     *                                        the input's normalized value, or an array like the top-level array
1068
-     * @throws EE_Error
1069
-     */
1070
-    public function input_values($include_subform_inputs = false, $flatten = false)
1071
-    {
1072
-        return $this->_input_values(false, $include_subform_inputs, $flatten);
1073
-    }
1074
-
1075
-
1076
-    /**
1077
-     * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1078
-     * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1079
-     * is not necessarily the value we want to display to users. This creates an array
1080
-     * where keys are the input names, and values are their display values
1081
-     *
1082
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1083
-     *                                        or just this forms' direct children inputs
1084
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1085
-     *                                        or allow multidimensional array
1086
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1087
-     *                                        with array keys being input names
1088
-     *                                        (regardless of whether they are from a subsection or not),
1089
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1090
-     *                                        where keys are always subsection names and values are either
1091
-     *                                        the input's normalized value, or an array like the top-level array
1092
-     * @throws EE_Error
1093
-     */
1094
-    public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1095
-    {
1096
-        return $this->_input_values(true, $include_subform_inputs, $flatten);
1097
-    }
1098
-
1099
-
1100
-    /**
1101
-     * Gets the input values from the form
1102
-     *
1103
-     * @param boolean $pretty                 Whether to retrieve the pretty value,
1104
-     *                                        or just the normalized value
1105
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1106
-     *                                        or just this forms' direct children inputs
1107
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1108
-     *                                        or allow multidimensional array
1109
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1110
-     *                                        input names (regardless of whether they are from a subsection or not),
1111
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1112
-     *                                        where keys are always subsection names and values are either
1113
-     *                                        the input's normalized value, or an array like the top-level array
1114
-     * @throws EE_Error
1115
-     */
1116
-    public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1117
-    {
1118
-        $input_values = array();
1119
-        foreach ($this->subsections() as $subsection_name => $subsection) {
1120
-            if ($subsection instanceof EE_Form_Input_Base) {
1121
-                $input_values[ $subsection_name ] = $pretty
1122
-                    ? $subsection->pretty_value()
1123
-                    : $subsection->normalized_value();
1124
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1125
-                $subform_input_values = $subsection->_input_values(
1126
-                    $pretty,
1127
-                    $include_subform_inputs,
1128
-                    $flatten
1129
-                );
1130
-                if ($flatten) {
1131
-                    $input_values = array_merge($input_values, $subform_input_values);
1132
-                } else {
1133
-                    $input_values[ $subsection_name ] = $subform_input_values;
1134
-                }
1135
-            }
1136
-        }
1137
-        return $input_values;
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * Gets the originally submitted input values from the form
1143
-     *
1144
-     * @param boolean $include_subforms  Whether to include inputs from subforms,
1145
-     *                                   or just this forms' direct children inputs
1146
-     * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1147
-     *                                   with array keys being input names
1148
-     *                                   (regardless of whether they are from a subsection or not),
1149
-     *                                   and if $flatten is FALSE it can be a multidimensional array
1150
-     *                                   where keys are always subsection names and values are either
1151
-     *                                   the input's normalized value, or an array like the top-level array
1152
-     * @throws EE_Error
1153
-     */
1154
-    public function submitted_values($include_subforms = false)
1155
-    {
1156
-        $submitted_values = array();
1157
-        foreach ($this->subsections() as $subsection) {
1158
-            if ($subsection instanceof EE_Form_Input_Base) {
1159
-                // is this input part of an array of inputs?
1160
-                if (strpos($subsection->html_name(), '[') !== false) {
1161
-                    $full_input_name  = EEH_Array::convert_array_values_to_keys(
1162
-                        explode(
1163
-                            '[',
1164
-                            str_replace(']', '', $subsection->html_name())
1165
-                        ),
1166
-                        $subsection->raw_value()
1167
-                    );
1168
-                    $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169
-                } else {
1170
-                    $submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1171
-                }
1172
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173
-                $subform_input_values = $subsection->submitted_values($include_subforms);
1174
-                $submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1175
-            }
1176
-        }
1177
-        return $submitted_values;
1178
-    }
1179
-
1180
-
1181
-    /**
1182
-     * Indicates whether or not this form has received a submission yet
1183
-     * (ie, had receive_form_submission called on it yet)
1184
-     *
1185
-     * @return boolean
1186
-     * @throws EE_Error
1187
-     */
1188
-    public function has_received_submission()
1189
-    {
1190
-        $this->ensure_construct_finalized_called();
1191
-        return $this->_received_submission;
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * Equivalent to passing 'exclude' in the constructor's options array.
1197
-     * Removes the listed inputs from the form
1198
-     *
1199
-     * @param array $inputs_to_exclude values are the input names
1200
-     * @return void
1201
-     */
1202
-    public function exclude(array $inputs_to_exclude = array())
1203
-    {
1204
-        foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
-            unset($this->_subsections[ $input_to_exclude_name ]);
1206
-        }
1207
-    }
1208
-
1209
-
1210
-    /**
1211
-     * @param array $inputs_to_hide
1212
-     * @throws EE_Error
1213
-     */
1214
-    public function hide(array $inputs_to_hide = array())
1215
-    {
1216
-        foreach ($inputs_to_hide as $input_to_hide) {
1217
-            $input = $this->get_input($input_to_hide);
1218
-            $input->set_display_strategy(new EE_Hidden_Display_Strategy());
1219
-        }
1220
-    }
1221
-
1222
-
1223
-    /**
1224
-     * add_subsections
1225
-     * Adds the listed subsections to the form section.
1226
-     * If $subsection_name_to_target is provided,
1227
-     * then new subsections are added before or after that subsection,
1228
-     * otherwise to the start or end of the entire subsections array.
1229
-     *
1230
-     * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1231
-     *                                                          where keys are their names
1232
-     * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1233
-     *                                                          should be added before or after
1234
-     *                                                          IF $subsection_name_to_target is null,
1235
-     *                                                          then $new_subsections will be added to
1236
-     *                                                          the beginning or end of the entire subsections array
1237
-     * @param boolean                $add_before                whether to add $new_subsections, before or after
1238
-     *                                                          $subsection_name_to_target,
1239
-     *                                                          or if $subsection_name_to_target is null,
1240
-     *                                                          before or after entire subsections array
1241
-     * @return void
1242
-     * @throws EE_Error
1243
-     */
1244
-    public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1245
-    {
1246
-        foreach ($new_subsections as $subsection_name => $subsection) {
1247
-            if (! $subsection instanceof EE_Form_Section_Base) {
1248
-                EE_Error::add_error(
1249
-                    sprintf(
1250
-                        esc_html__(
1251
-                            "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1252
-                            'event_espresso'
1253
-                        ),
1254
-                        get_class($subsection),
1255
-                        $subsection_name,
1256
-                        $this->name()
1257
-                    )
1258
-                );
1259
-                unset($new_subsections[ $subsection_name ]);
1260
-            }
1261
-        }
1262
-        $this->_subsections = EEH_Array::insert_into_array(
1263
-            $this->_subsections,
1264
-            $new_subsections,
1265
-            $subsection_name_to_target,
1266
-            $add_before
1267
-        );
1268
-        if ($this->_construction_finalized) {
1269
-            foreach ($this->_subsections as $name => $subsection) {
1270
-                $subsection->_construct_finalize($this, $name);
1271
-            }
1272
-        }
1273
-    }
1274
-
1275
-
1276
-    /**
1277
-     * Just gets all validatable subsections to clean their sensitive data
1278
-     *
1279
-     * @throws EE_Error
1280
-     */
1281
-    public function clean_sensitive_data()
1282
-    {
1283
-        foreach ($this->get_validatable_subsections() as $subsection) {
1284
-            $subsection->clean_sensitive_data();
1285
-        }
1286
-    }
1287
-
1288
-
1289
-    /**
1290
-     * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1291
-     * @param string                           $form_submission_error_message
1292
-     * @param EE_Form_Section_Validatable $form_section unused
1293
-     * @throws EE_Error
1294
-     */
1295
-    public function set_submission_error_message(
1296
-        $form_submission_error_message = ''
1297
-    ) {
1298
-        $this->_form_submission_error_message = ! empty($form_submission_error_message)
1299
-            ? $form_submission_error_message
1300
-            : $this->getAllValidationErrorsString();
1301
-    }
1302
-
1303
-
1304
-    /**
1305
-     * Returns the cached error message. A default value is set for this during _validate(),
1306
-     * (called during receive_form_submission) but it can be explicitly set using
1307
-     * set_submission_error_message
1308
-     *
1309
-     * @return string
1310
-     */
1311
-    public function submission_error_message()
1312
-    {
1313
-        return $this->_form_submission_error_message;
1314
-    }
1315
-
1316
-
1317
-    /**
1318
-     * Sets a message to display if the data submitted to the form was valid.
1319
-     * @param string $form_submission_success_message
1320
-     */
1321
-    public function set_submission_success_message($form_submission_success_message = '')
1322
-    {
1323
-        $this->_form_submission_success_message = ! empty($form_submission_success_message)
1324
-            ? $form_submission_success_message
1325
-            : esc_html__('Form submitted successfully', 'event_espresso');
1326
-    }
1327
-
1328
-
1329
-    /**
1330
-     * Gets a message appropriate for display when the form is correctly submitted
1331
-     * @return string
1332
-     */
1333
-    public function submission_success_message()
1334
-    {
1335
-        return $this->_form_submission_success_message;
1336
-    }
1337
-
1338
-
1339
-    /**
1340
-     * Returns the prefix that should be used on child of this form section for
1341
-     * their html names. If this form section itself has a parent, prepends ITS
1342
-     * prefix onto this form section's prefix. Used primarily by
1343
-     * EE_Form_Input_Base::_set_default_html_name_if_empty
1344
-     *
1345
-     * @return string
1346
-     * @throws EE_Error
1347
-     */
1348
-    public function html_name_prefix()
1349
-    {
1350
-        if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1351
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1352
-        }
1353
-        return $this->name();
1354
-    }
1355
-
1356
-
1357
-    /**
1358
-     * Gets the name, but first checks _construct_finalize has been called. If not,
1359
-     * calls it (assumes there is no parent and that we want the name to be whatever
1360
-     * was set, which is probably nothing, or the classname)
1361
-     *
1362
-     * @return string
1363
-     * @throws EE_Error
1364
-     */
1365
-    public function name()
1366
-    {
1367
-        $this->ensure_construct_finalized_called();
1368
-        return parent::name();
1369
-    }
1370
-
1371
-
1372
-    /**
1373
-     * @return EE_Form_Section_Proper
1374
-     * @throws EE_Error
1375
-     */
1376
-    public function parent_section()
1377
-    {
1378
-        $this->ensure_construct_finalized_called();
1379
-        return parent::parent_section();
1380
-    }
1381
-
1382
-
1383
-    /**
1384
-     * make sure construction finalized was called, otherwise children might not be ready
1385
-     *
1386
-     * @return void
1387
-     * @throws EE_Error
1388
-     */
1389
-    public function ensure_construct_finalized_called()
1390
-    {
1391
-        if (! $this->_construction_finalized) {
1392
-            $this->_construct_finalize($this->_parent_section, $this->_name);
1393
-        }
1394
-    }
1395
-
1396
-
1397
-    /**
1398
-     * Checks if any of this form section's inputs, or any of its children's inputs,
1399
-     * are in teh form data. If any are found, returns true. Else false
1400
-     *
1401
-     * @param array $req_data
1402
-     * @return boolean
1403
-     * @throws EE_Error
1404
-     */
1405
-    public function form_data_present_in($req_data = null)
1406
-    {
1407
-        $req_data = $this->getCachedRequest($req_data);
1408
-        foreach ($this->subsections() as $subsection) {
1409
-            if ($subsection instanceof EE_Form_Input_Base) {
1410
-                if ($subsection->form_data_present_in($req_data)) {
1411
-                    return true;
1412
-                }
1413
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
1414
-                if ($subsection->form_data_present_in($req_data)) {
1415
-                    return true;
1416
-                }
1417
-            }
1418
-        }
1419
-        return false;
1420
-    }
1421
-
1422
-
1423
-    /**
1424
-     * Gets validation errors for this form section and subsections
1425
-     * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1426
-     * gets the validation errors for ALL subsection
1427
-     *
1428
-     * @return EE_Validation_Error[]
1429
-     * @throws EE_Error
1430
-     */
1431
-    public function get_validation_errors_accumulated()
1432
-    {
1433
-        $validation_errors = $this->get_validation_errors();
1434
-        foreach ($this->get_validatable_subsections() as $subsection) {
1435
-            if ($subsection instanceof EE_Form_Section_Proper) {
1436
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1437
-            } else {
1438
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors();
1439
-            }
1440
-            if ($validation_errors_on_this_subsection) {
1441
-                $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1442
-            }
1443
-        }
1444
-        return $validation_errors;
1445
-    }
1446
-
1447
-    /**
1448
-     * Fetch validation errors from children and grandchildren and puts them in a single string.
1449
-     * This traverses the form section tree to generate this, but you probably want to instead use
1450
-     * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1451
-     *
1452
-     * @return string
1453
-     * @since $VID:$
1454
-     */
1455
-    protected function getAllValidationErrorsString()
1456
-    {
1457
-        $submission_error_messages = array();
1458
-        // bad, bad, bad registrant
1459
-        foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1460
-            if ($validation_error instanceof EE_Validation_Error) {
1461
-                $form_section = $validation_error->get_form_section();
1462
-                if ($form_section instanceof EE_Form_Input_Base) {
1463
-                   $label = $validation_error->get_form_section()->html_label_text();
1464
-                } elseif($form_section instanceof EE_Form_Section_Validatable) {
1465
-                    $label = $validation_error->get_form_section()->name();
1466
-                } else {
1467
-                    $label = esc_html__('Unknown', 'event_espresso');
1468
-                }
1469
-                $submission_error_messages[] = sprintf(
1470
-                    __('%s : %s', 'event_espresso'),
1471
-                    $label,
1472
-                    $validation_error->getMessage()
1473
-                );
1474
-            }
1475
-        }
1476
-        return implode('<br', $submission_error_messages);
1477
-    }
1478
-
1479
-
1480
-    /**
1481
-     * This isn't just the name of an input, it's a path pointing to an input. The
1482
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
1483
-     * dot-dot-slash (../) means to ascend into the parent section.
1484
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1485
-     * which will be returned.
1486
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1487
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1488
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1489
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1490
-     * Etc
1491
-     *
1492
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1493
-     * @return EE_Form_Section_Base
1494
-     * @throws EE_Error
1495
-     */
1496
-    public function find_section_from_path($form_section_path)
1497
-    {
1498
-        //check if we can find the input from purely going straight up the tree
1499
-        $input = parent::find_section_from_path($form_section_path);
1500
-        if ($input instanceof EE_Form_Section_Base) {
1501
-            return $input;
1502
-        }
1503
-        $next_slash_pos = strpos($form_section_path, '/');
1504
-        if ($next_slash_pos !== false) {
1505
-            $child_section_name = substr($form_section_path, 0, $next_slash_pos);
1506
-            $subpath            = substr($form_section_path, $next_slash_pos + 1);
1507
-        } else {
1508
-            $child_section_name = $form_section_path;
1509
-            $subpath            = '';
1510
-        }
1511
-        $child_section = $this->get_subsection($child_section_name);
1512
-        if ($child_section instanceof EE_Form_Section_Base) {
1513
-            return $child_section->find_section_from_path($subpath);
1514
-        }
1515
-        return null;
1516
-    }
17
+	const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
+
19
+	/**
20
+	 * Subsections
21
+	 *
22
+	 * @var EE_Form_Section_Validatable[]
23
+	 */
24
+	protected $_subsections = array();
25
+
26
+	/**
27
+	 * Strategy for laying out the form
28
+	 *
29
+	 * @var EE_Form_Section_Layout_Base
30
+	 */
31
+	protected $_layout_strategy;
32
+
33
+	/**
34
+	 * Whether or not this form has received and validated a form submission yet
35
+	 *
36
+	 * @var boolean
37
+	 */
38
+	protected $_received_submission = false;
39
+
40
+	/**
41
+	 * message displayed to users upon successful form submission
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $_form_submission_success_message = '';
46
+
47
+	/**
48
+	 * message displayed to users upon unsuccessful form submission
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $_form_submission_error_message = '';
53
+
54
+	/**
55
+	 * @var array like $_REQUEST
56
+	 */
57
+	protected $cached_request_data;
58
+
59
+	/**
60
+	 * Stores whether this form (and its sub-sections) were found to be valid or not.
61
+	 * Starts off as null, but once the form is validated, it set to either true or false
62
+	 * @var boolean|null
63
+	 */
64
+	protected $is_valid;
65
+
66
+	/**
67
+	 * Stores all the data that will localized for form validation
68
+	 *
69
+	 * @var array
70
+	 */
71
+	static protected $_js_localization = array();
72
+
73
+	/**
74
+	 * whether or not the form's localized validation JS vars have been set
75
+	 *
76
+	 * @type boolean
77
+	 */
78
+	static protected $_scripts_localized = false;
79
+
80
+
81
+	/**
82
+	 * when constructing a proper form section, calls _construct_finalize on children
83
+	 * so that they know who their parent is, and what name they've been given.
84
+	 *
85
+	 * @param array[] $options_array   {
86
+	 * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
+	 * @type          $include         string[] numerically-indexed where values are section names to be included,
88
+	 *                                 and in that order. This is handy if you want
89
+	 *                                 the subsections to be ordered differently than the default, and if you override
90
+	 *                                 which fields are shown
91
+	 * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
+	 *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
+	 *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
+	 *                                 items from that list of inclusions)
95
+	 * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
+	 *                                 } @see EE_Form_Section_Validatable::__construct()
97
+	 * @throws EE_Error
98
+	 */
99
+	public function __construct($options_array = array())
100
+	{
101
+		$options_array = (array) apply_filters(
102
+			'FHEE__EE_Form_Section_Proper___construct__options_array',
103
+			$options_array,
104
+			$this
105
+		);
106
+		//call parent first, as it may be setting the name
107
+		parent::__construct($options_array);
108
+		//if they've included subsections in the constructor, add them now
109
+		if (isset($options_array['include'])) {
110
+			//we are going to make sure we ONLY have those subsections to include
111
+			//AND we are going to make sure they're in that specified order
112
+			$reordered_subsections = array();
113
+			foreach ($options_array['include'] as $input_name) {
114
+				if (isset($this->_subsections[ $input_name ])) {
115
+					$reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
+				}
117
+			}
118
+			$this->_subsections = $reordered_subsections;
119
+		}
120
+		if (isset($options_array['exclude'])) {
121
+			$exclude            = $options_array['exclude'];
122
+			$this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
+		}
124
+		if (isset($options_array['layout_strategy'])) {
125
+			$this->_layout_strategy = $options_array['layout_strategy'];
126
+		}
127
+		if (! $this->_layout_strategy) {
128
+			$this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
+		}
130
+		$this->_layout_strategy->_construct_finalize($this);
131
+		//ok so we are definitely going to want the forms JS,
132
+		//so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
+			//ok so they've constructed this object after when they should have.
135
+			//just enqueue the generic form scripts and initialize the form immediately in the JS
136
+			EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
+		} else {
138
+			add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
+			add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
+		}
141
+		add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
+		/**
143
+		 * Gives other plugins a chance to hook in before construct finalize is called.
144
+		 * The form probably doesn't yet have a parent form section.
145
+		 * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
+		 * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
+		 * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
+		 *
149
+		 * @since 4.9.32
150
+		 * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
+		 *                                              except maybe calling _construct_finalize has been done
152
+		 * @param array                  $options_array options passed into the constructor
153
+		 */
154
+		do_action(
155
+			'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
+			$this,
157
+			$options_array
158
+		);
159
+		if (isset($options_array['name'])) {
160
+			$this->_construct_finalize(null, $options_array['name']);
161
+		}
162
+	}
163
+
164
+
165
+	/**
166
+	 * Finishes construction given the parent form section and this form section's name
167
+	 *
168
+	 * @param EE_Form_Section_Proper $parent_form_section
169
+	 * @param string                 $name
170
+	 * @throws EE_Error
171
+	 */
172
+	public function _construct_finalize($parent_form_section, $name)
173
+	{
174
+		parent::_construct_finalize($parent_form_section, $name);
175
+		$this->_set_default_name_if_empty();
176
+		$this->_set_default_html_id_if_empty();
177
+		foreach ($this->_subsections as $subsection_name => $subsection) {
178
+			if ($subsection instanceof EE_Form_Section_Base) {
179
+				$subsection->_construct_finalize($this, $subsection_name);
180
+			} else {
181
+				throw new EE_Error(
182
+					sprintf(
183
+						esc_html__(
184
+							'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
+							'event_espresso'
186
+						),
187
+						$subsection_name,
188
+						get_class($this),
189
+						$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
+					)
191
+				);
192
+			}
193
+		}
194
+		/**
195
+		 * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
+		 * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
+		 * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
+		 * This might only happen just before displaying the form, or just before it receives form submission data.
199
+		 * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
+		 * ensured it has a name, HTML IDs, etc
201
+		 *
202
+		 * @param EE_Form_Section_Proper      $this
203
+		 * @param EE_Form_Section_Proper|null $parent_form_section
204
+		 * @param string                      $name
205
+		 */
206
+		do_action(
207
+			'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
+			$this,
209
+			$parent_form_section,
210
+			$name
211
+		);
212
+	}
213
+
214
+
215
+	/**
216
+	 * Gets the layout strategy for this form section
217
+	 *
218
+	 * @return EE_Form_Section_Layout_Base
219
+	 */
220
+	public function get_layout_strategy()
221
+	{
222
+		return $this->_layout_strategy;
223
+	}
224
+
225
+
226
+	/**
227
+	 * Gets the HTML for a single input for this form section according
228
+	 * to the layout strategy
229
+	 *
230
+	 * @param EE_Form_Input_Base $input
231
+	 * @return string
232
+	 */
233
+	public function get_html_for_input($input)
234
+	{
235
+		return $this->_layout_strategy->layout_input($input);
236
+	}
237
+
238
+
239
+	/**
240
+	 * was_submitted - checks if form inputs are present in request data
241
+	 * Basically an alias for form_data_present_in() (which is used by both
242
+	 * proper form sections and form inputs)
243
+	 *
244
+	 * @param null $form_data
245
+	 * @return boolean
246
+	 * @throws EE_Error
247
+	 */
248
+	public function was_submitted($form_data = null)
249
+	{
250
+		return $this->form_data_present_in($form_data);
251
+	}
252
+
253
+	/**
254
+	 * Gets the cached request data; but if there is none, or $req_data was set with
255
+	 * something different, refresh the cache, and then return it
256
+	 * @param null $req_data
257
+	 * @return array
258
+	 */
259
+	protected function getCachedRequest($req_data = null)
260
+	{
261
+		if ($this->cached_request_data === null
262
+			|| (
263
+				$req_data !== null &&
264
+				$req_data !== $this->cached_request_data
265
+			)
266
+		) {
267
+			$req_data = apply_filters(
268
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
269
+				$req_data,
270
+				$this
271
+			);
272
+			if ($req_data === null) {
273
+				$req_data = array_merge($_GET, $_POST);
274
+			}
275
+			$req_data = apply_filters(
276
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
277
+				$req_data,
278
+				$this
279
+			);
280
+			$this->cached_request_data = (array)$req_data;
281
+		}
282
+		return $this->cached_request_data;
283
+	}
284
+
285
+
286
+	/**
287
+	 * After the form section is initially created, call this to sanitize the data in the submission
288
+	 * which relates to this form section, validate it, and set it as properties on the form.
289
+	 *
290
+	 * @param array|null $req_data should usually be $_POST (the default).
291
+	 *                             However, you CAN supply a different array.
292
+	 *                             Consider using set_defaults() instead however.
293
+	 *                             (If you rendered the form in the page using echo $form_x->get_html()
294
+	 *                             the inputs will have the correct name in the request data for this function
295
+	 *                             to find them and populate the form with them.
296
+	 *                             If you have a flat form (with only input subsections),
297
+	 *                             you can supply a flat array where keys
298
+	 *                             are the form input names and values are their values)
299
+	 * @param boolean    $validate whether or not to perform validation on this data. Default is,
300
+	 *                             of course, to validate that data, and set errors on the invalid values.
301
+	 *                             But if the data has already been validated
302
+	 *                             (eg you validated the data then stored it in the DB)
303
+	 *                             you may want to skip this step.
304
+	 * @throws InvalidArgumentException
305
+	 * @throws InvalidInterfaceException
306
+	 * @throws InvalidDataTypeException
307
+	 * @throws EE_Error
308
+	 */
309
+	public function receive_form_submission($req_data = null, $validate = true)
310
+	{
311
+		$req_data = $this->getCachedRequest($req_data);
312
+		$this->_normalize($req_data);
313
+		if ($validate) {
314
+			$this->_validate();
315
+			//if it's invalid, we're going to want to re-display so remember what they submitted
316
+			if (! $this->is_valid()) {
317
+				$this->store_submitted_form_data_in_session();
318
+			}
319
+		}
320
+		if ($this->submission_error_message() === '' && ! $this->is_valid()) {
321
+			$this->set_submission_error_message();
322
+		}
323
+		do_action(
324
+			'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
325
+			$req_data,
326
+			$this,
327
+			$validate
328
+		);
329
+	}
330
+
331
+
332
+	/**
333
+	 * caches the originally submitted input values in the session
334
+	 * so that they can be used to repopulate the form if it failed validation
335
+	 *
336
+	 * @return boolean whether or not the data was successfully stored in the session
337
+	 * @throws InvalidArgumentException
338
+	 * @throws InvalidInterfaceException
339
+	 * @throws InvalidDataTypeException
340
+	 * @throws EE_Error
341
+	 */
342
+	protected function store_submitted_form_data_in_session()
343
+	{
344
+		return EE_Registry::instance()->SSN->set_session_data(
345
+			array(
346
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
347
+			)
348
+		);
349
+	}
350
+
351
+
352
+	/**
353
+	 * retrieves the originally submitted input values in the session
354
+	 * so that they can be used to repopulate the form if it failed validation
355
+	 *
356
+	 * @return array
357
+	 * @throws InvalidArgumentException
358
+	 * @throws InvalidInterfaceException
359
+	 * @throws InvalidDataTypeException
360
+	 */
361
+	protected function get_submitted_form_data_from_session()
362
+	{
363
+		$session = EE_Registry::instance()->SSN;
364
+		if ($session instanceof EE_Session) {
365
+			return $session->get_session_data(
366
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
367
+			);
368
+		}
369
+		return array();
370
+	}
371
+
372
+
373
+	/**
374
+	 * flushed the originally submitted input values from the session
375
+	 *
376
+	 * @return boolean whether or not the data was successfully removed from the session
377
+	 * @throws InvalidArgumentException
378
+	 * @throws InvalidInterfaceException
379
+	 * @throws InvalidDataTypeException
380
+	 */
381
+	protected function flush_submitted_form_data_from_session()
382
+	{
383
+		return EE_Registry::instance()->SSN->reset_data(
384
+			array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
385
+		);
386
+	}
387
+
388
+
389
+	/**
390
+	 * Populates this form and its subsections with data from the session.
391
+	 * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
392
+	 * validation errors when displaying too)
393
+	 * Returns true if the form was populated from the session, false otherwise
394
+	 *
395
+	 * @return boolean
396
+	 * @throws InvalidArgumentException
397
+	 * @throws InvalidInterfaceException
398
+	 * @throws InvalidDataTypeException
399
+	 * @throws EE_Error
400
+	 */
401
+	public function populate_from_session()
402
+	{
403
+		$form_data_in_session = $this->get_submitted_form_data_from_session();
404
+		if (empty($form_data_in_session)) {
405
+			return false;
406
+		}
407
+		$this->receive_form_submission($form_data_in_session);
408
+		$this->flush_submitted_form_data_from_session();
409
+		if ($this->form_data_present_in($form_data_in_session)) {
410
+			return true;
411
+		}
412
+		return false;
413
+	}
414
+
415
+
416
+	/**
417
+	 * Populates the default data for the form, given an array where keys are
418
+	 * the input names, and values are their values (preferably normalized to be their
419
+	 * proper PHP types, not all strings... although that should be ok too).
420
+	 * Proper subsections are sub-arrays, the key being the subsection's name, and
421
+	 * the value being an array formatted in teh same way
422
+	 *
423
+	 * @param array $default_data
424
+	 * @throws EE_Error
425
+	 */
426
+	public function populate_defaults($default_data)
427
+	{
428
+		foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
+			if (isset($default_data[ $subsection_name ])) {
430
+				if ($subsection instanceof EE_Form_Input_Base) {
431
+					$subsection->set_default($default_data[ $subsection_name ]);
432
+				} elseif ($subsection instanceof EE_Form_Section_Proper) {
433
+					$subsection->populate_defaults($default_data[ $subsection_name ]);
434
+				}
435
+			}
436
+		}
437
+	}
438
+
439
+
440
+	/**
441
+	 * returns true if subsection exists
442
+	 *
443
+	 * @param string $name
444
+	 * @return boolean
445
+	 */
446
+	public function subsection_exists($name)
447
+	{
448
+		return isset($this->_subsections[ $name ]) ? true : false;
449
+	}
450
+
451
+
452
+	/**
453
+	 * Gets the subsection specified by its name
454
+	 *
455
+	 * @param string  $name
456
+	 * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
457
+	 *                                                      so that the inputs will be properly configured.
458
+	 *                                                      However, some client code may be ok
459
+	 *                                                      with construction finalize being called later
460
+	 *                                                      (realizing that the subsections' html names
461
+	 *                                                      might not be set yet, etc.)
462
+	 * @return EE_Form_Section_Base
463
+	 * @throws EE_Error
464
+	 */
465
+	public function get_subsection($name, $require_construction_to_be_finalized = true)
466
+	{
467
+		if ($require_construction_to_be_finalized) {
468
+			$this->ensure_construct_finalized_called();
469
+		}
470
+		return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
471
+	}
472
+
473
+
474
+	/**
475
+	 * Gets all the validatable subsections of this form section
476
+	 *
477
+	 * @return EE_Form_Section_Validatable[]
478
+	 * @throws EE_Error
479
+	 */
480
+	public function get_validatable_subsections()
481
+	{
482
+		$validatable_subsections = array();
483
+		foreach ($this->subsections() as $name => $obj) {
484
+			if ($obj instanceof EE_Form_Section_Validatable) {
485
+				$validatable_subsections[ $name ] = $obj;
486
+			}
487
+		}
488
+		return $validatable_subsections;
489
+	}
490
+
491
+
492
+	/**
493
+	 * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
494
+	 * throw an EE_Error.
495
+	 *
496
+	 * @param string  $name
497
+	 * @param boolean $require_construction_to_be_finalized most client code should
498
+	 *                                                      leave this as TRUE so that the inputs will be properly
499
+	 *                                                      configured. However, some client code may be ok with
500
+	 *                                                      construction finalize being called later
501
+	 *                                                      (realizing that the subsections' html names might not be
502
+	 *                                                      set yet, etc.)
503
+	 * @return EE_Form_Input_Base
504
+	 * @throws EE_Error
505
+	 */
506
+	public function get_input($name, $require_construction_to_be_finalized = true)
507
+	{
508
+		$subsection = $this->get_subsection(
509
+			$name,
510
+			$require_construction_to_be_finalized
511
+		);
512
+		if (! $subsection instanceof EE_Form_Input_Base) {
513
+			throw new EE_Error(
514
+				sprintf(
515
+					esc_html__(
516
+						"Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
517
+						'event_espresso'
518
+					),
519
+					$name,
520
+					get_class($this),
521
+					$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
522
+				)
523
+			);
524
+		}
525
+		return $subsection;
526
+	}
527
+
528
+
529
+	/**
530
+	 * Like get_input(), gets the proper subsection of the form given the name,
531
+	 * otherwise throws an EE_Error
532
+	 *
533
+	 * @param string  $name
534
+	 * @param boolean $require_construction_to_be_finalized most client code should
535
+	 *                                                      leave this as TRUE so that the inputs will be properly
536
+	 *                                                      configured. However, some client code may be ok with
537
+	 *                                                      construction finalize being called later
538
+	 *                                                      (realizing that the subsections' html names might not be
539
+	 *                                                      set yet, etc.)
540
+	 * @return EE_Form_Section_Proper
541
+	 * @throws EE_Error
542
+	 */
543
+	public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
544
+	{
545
+		$subsection = $this->get_subsection(
546
+			$name,
547
+			$require_construction_to_be_finalized
548
+		);
549
+		if (! $subsection instanceof EE_Form_Section_Proper) {
550
+			throw new EE_Error(
551
+				sprintf(
552
+					esc_html__(
553
+						"Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
554
+						'event_espresso'
555
+					),
556
+					$name,
557
+					get_class($this)
558
+				)
559
+			);
560
+		}
561
+		return $subsection;
562
+	}
563
+
564
+
565
+	/**
566
+	 * Gets the value of the specified input. Should be called after receive_form_submission()
567
+	 * or populate_defaults() on the form, where the normalized value on the input is set.
568
+	 *
569
+	 * @param string $name
570
+	 * @return mixed depending on the input's type and its normalization strategy
571
+	 * @throws EE_Error
572
+	 */
573
+	public function get_input_value($name)
574
+	{
575
+		$input = $this->get_input($name);
576
+		return $input->normalized_value();
577
+	}
578
+
579
+
580
+	/**
581
+	 * Checks if this form section itself is valid, and then checks its subsections
582
+	 *
583
+	 * @throws EE_Error
584
+	 * @return boolean
585
+	 */
586
+	public function is_valid()
587
+	{
588
+		if($this->is_valid === null) {
589
+			if (! $this->has_received_submission()) {
590
+				throw new EE_Error(
591
+					sprintf(
592
+						esc_html__(
593
+							'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
594
+							'event_espresso'
595
+						)
596
+					)
597
+				);
598
+			}
599
+			if (! parent::is_valid()) {
600
+				$this->is_valid = false;
601
+			} else {
602
+				// ok so no general errors to this entire form section.
603
+				// so let's check the subsections, but only set errors if that hasn't been done yet
604
+				$this->is_valid = true;
605
+				foreach ($this->get_validatable_subsections() as $subsection) {
606
+					if (! $subsection->is_valid()) {
607
+						$this->is_valid = false;
608
+					}
609
+				}
610
+			}
611
+		}
612
+		return $this->is_valid;
613
+	}
614
+
615
+
616
+	/**
617
+	 * gets the default name of this form section if none is specified
618
+	 *
619
+	 * @return void
620
+	 */
621
+	protected function _set_default_name_if_empty()
622
+	{
623
+		if (! $this->_name) {
624
+			$classname    = get_class($this);
625
+			$default_name = str_replace('EE_', '', $classname);
626
+			$this->_name  = $default_name;
627
+		}
628
+	}
629
+
630
+
631
+	/**
632
+	 * Returns the HTML for the form, except for the form opening and closing tags
633
+	 * (as the form section doesn't know where you necessarily want to send the information to),
634
+	 * and except for a submit button. Enqueues JS and CSS; if called early enough we will
635
+	 * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
636
+	 * Not doing_it_wrong because theoretically this CAN be used properly,
637
+	 * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
638
+	 * any CSS.
639
+	 *
640
+	 * @throws InvalidArgumentException
641
+	 * @throws InvalidInterfaceException
642
+	 * @throws InvalidDataTypeException
643
+	 * @throws EE_Error
644
+	 */
645
+	public function get_html_and_js()
646
+	{
647
+		$this->enqueue_js();
648
+		return $this->get_html();
649
+	}
650
+
651
+
652
+	/**
653
+	 * returns HTML for displaying this form section. recursively calls display_section() on all subsections
654
+	 *
655
+	 * @param bool $display_previously_submitted_data
656
+	 * @return string
657
+	 * @throws InvalidArgumentException
658
+	 * @throws InvalidInterfaceException
659
+	 * @throws InvalidDataTypeException
660
+	 * @throws EE_Error
661
+	 * @throws EE_Error
662
+	 * @throws EE_Error
663
+	 */
664
+	public function get_html($display_previously_submitted_data = true)
665
+	{
666
+		$this->ensure_construct_finalized_called();
667
+		if ($display_previously_submitted_data) {
668
+			$this->populate_from_session();
669
+		}
670
+		return $this->_form_html_filter
671
+			? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
672
+			: $this->_layout_strategy->layout_form();
673
+	}
674
+
675
+
676
+	/**
677
+	 * enqueues JS and CSS for the form.
678
+	 * It is preferred to call this before wp_enqueue_scripts so the
679
+	 * scripts and styles can be put in the header, but if called later
680
+	 * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
681
+	 * only be in the header; but in HTML5 its ok in the body.
682
+	 * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
683
+	 * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
684
+	 *
685
+	 * @return void
686
+	 * @throws EE_Error
687
+	 */
688
+	public function enqueue_js()
689
+	{
690
+		$this->_enqueue_and_localize_form_js();
691
+		foreach ($this->subsections() as $subsection) {
692
+			$subsection->enqueue_js();
693
+		}
694
+	}
695
+
696
+
697
+	/**
698
+	 * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
699
+	 * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
700
+	 * the wp_enqueue_scripts hook.
701
+	 * However, registering the form js and localizing it can happen when we
702
+	 * actually output the form (which is preferred, seeing how teh form's fields
703
+	 * could change until it's actually outputted)
704
+	 *
705
+	 * @param boolean $init_form_validation_automatically whether or not we want the form validation
706
+	 *                                                    to be triggered automatically or not
707
+	 * @return void
708
+	 */
709
+	public static function wp_enqueue_scripts($init_form_validation_automatically = true)
710
+	{
711
+		wp_register_script(
712
+			'ee_form_section_validation',
713
+			EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
714
+			array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715
+			EVENT_ESPRESSO_VERSION,
716
+			true
717
+		);
718
+		wp_localize_script(
719
+			'ee_form_section_validation',
720
+			'ee_form_section_validation_init',
721
+			array('init' => $init_form_validation_automatically ? '1' : '0')
722
+		);
723
+	}
724
+
725
+
726
+	/**
727
+	 * gets the variables used by form_section_validation.js.
728
+	 * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
729
+	 * but before the wordpress hook wp_loaded
730
+	 *
731
+	 * @throws EE_Error
732
+	 */
733
+	public function _enqueue_and_localize_form_js()
734
+	{
735
+		$this->ensure_construct_finalized_called();
736
+		//actually, we don't want to localize just yet. There may be other forms on the page.
737
+		//so we need to add our form section data to a static variable accessible by all form sections
738
+		//and localize it just before the footer
739
+		$this->localize_validation_rules();
740
+		add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
741
+		add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
742
+	}
743
+
744
+
745
+	/**
746
+	 * add our form section data to a static variable accessible by all form sections
747
+	 *
748
+	 * @param bool $return_for_subsection
749
+	 * @return void
750
+	 * @throws EE_Error
751
+	 */
752
+	public function localize_validation_rules($return_for_subsection = false)
753
+	{
754
+		// we only want to localize vars ONCE for the entire form,
755
+		// so if the form section doesn't have a parent, then it must be the top dog
756
+		if ($return_for_subsection || ! $this->parent_section()) {
757
+			EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
758
+				'form_section_id'  => $this->html_id(true),
759
+				'validation_rules' => $this->get_jquery_validation_rules(),
760
+				'other_data'       => $this->get_other_js_data(),
761
+				'errors'           => $this->subsection_validation_errors_by_html_name(),
762
+			);
763
+			EE_Form_Section_Proper::$_scripts_localized                                = true;
764
+		}
765
+	}
766
+
767
+
768
+	/**
769
+	 * Gets an array of extra data that will be useful for client-side javascript.
770
+	 * This is primarily data added by inputs and forms in addition to any
771
+	 * scripts they might enqueue
772
+	 *
773
+	 * @param array $form_other_js_data
774
+	 * @return array
775
+	 * @throws EE_Error
776
+	 */
777
+	public function get_other_js_data($form_other_js_data = array())
778
+	{
779
+		foreach ($this->subsections() as $subsection) {
780
+			$form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
781
+		}
782
+		return $form_other_js_data;
783
+	}
784
+
785
+
786
+	/**
787
+	 * Gets a flat array of inputs for this form section and its subsections.
788
+	 * Keys are their form names, and values are the inputs themselves
789
+	 *
790
+	 * @return EE_Form_Input_Base
791
+	 * @throws EE_Error
792
+	 */
793
+	public function inputs_in_subsections()
794
+	{
795
+		$inputs = array();
796
+		foreach ($this->subsections() as $subsection) {
797
+			if ($subsection instanceof EE_Form_Input_Base) {
798
+				$inputs[ $subsection->html_name() ] = $subsection;
799
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
800
+				$inputs += $subsection->inputs_in_subsections();
801
+			}
802
+		}
803
+		return $inputs;
804
+	}
805
+
806
+
807
+	/**
808
+	 * Gets a flat array of all the validation errors.
809
+	 * Keys are html names (because those should be unique)
810
+	 * and values are a string of all their validation errors
811
+	 *
812
+	 * @return string[]
813
+	 * @throws EE_Error
814
+	 */
815
+	public function subsection_validation_errors_by_html_name()
816
+	{
817
+		$inputs = $this->inputs();
818
+		$errors = array();
819
+		foreach ($inputs as $form_input) {
820
+			if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
+				$errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
822
+			}
823
+		}
824
+		return $errors;
825
+	}
826
+
827
+
828
+	/**
829
+	 * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
830
+	 * Should be setup by each form during the _enqueues_and_localize_form_js
831
+	 *
832
+	 * @throws InvalidArgumentException
833
+	 * @throws InvalidInterfaceException
834
+	 * @throws InvalidDataTypeException
835
+	 */
836
+	public static function localize_script_for_all_forms()
837
+	{
838
+		//allow inputs and stuff to hook in their JS and stuff here
839
+		do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
840
+		EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
841
+		$email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842
+			? EE_Registry::instance()->CFG->registration->email_validation_level
843
+			: 'wp_default';
844
+		EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
845
+		wp_enqueue_script('ee_form_section_validation');
846
+		wp_localize_script(
847
+			'ee_form_section_validation',
848
+			'ee_form_section_vars',
849
+			EE_Form_Section_Proper::$_js_localization
850
+		);
851
+	}
852
+
853
+
854
+	/**
855
+	 * ensure_scripts_localized
856
+	 *
857
+	 * @throws EE_Error
858
+	 */
859
+	public function ensure_scripts_localized()
860
+	{
861
+		if (! EE_Form_Section_Proper::$_scripts_localized) {
862
+			$this->_enqueue_and_localize_form_js();
863
+		}
864
+	}
865
+
866
+
867
+	/**
868
+	 * Gets the hard-coded validation error messages to be used in the JS. The convention
869
+	 * is that the key here should be the same as the custom validation rule put in the JS file
870
+	 *
871
+	 * @return array keys are custom validation rules, and values are internationalized strings
872
+	 */
873
+	private static function _get_localized_error_messages()
874
+	{
875
+		return array(
876
+			'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'),
877
+			'regex'    => esc_html__('Please check your input', 'event_espresso'),
878
+		);
879
+	}
880
+
881
+
882
+	/**
883
+	 * @return array
884
+	 */
885
+	public static function js_localization()
886
+	{
887
+		return self::$_js_localization;
888
+	}
889
+
890
+
891
+	/**
892
+	 * @return void
893
+	 */
894
+	public static function reset_js_localization()
895
+	{
896
+		self::$_js_localization = array();
897
+	}
898
+
899
+
900
+	/**
901
+	 * Gets the JS to put inside the jquery validation rules for subsection of this form section.
902
+	 * See parent function for more...
903
+	 *
904
+	 * @return array
905
+	 * @throws EE_Error
906
+	 */
907
+	public function get_jquery_validation_rules()
908
+	{
909
+		$jquery_validation_rules = array();
910
+		foreach ($this->get_validatable_subsections() as $subsection) {
911
+			$jquery_validation_rules = array_merge(
912
+				$jquery_validation_rules,
913
+				$subsection->get_jquery_validation_rules()
914
+			);
915
+		}
916
+		return $jquery_validation_rules;
917
+	}
918
+
919
+
920
+	/**
921
+	 * Sanitizes all the data and sets the sanitized value of each field
922
+	 *
923
+	 * @param array $req_data like $_POST
924
+	 * @return void
925
+	 * @throws EE_Error
926
+	 */
927
+	protected function _normalize($req_data)
928
+	{
929
+		$this->_received_submission = true;
930
+		$this->_validation_errors   = array();
931
+		foreach ($this->get_validatable_subsections() as $subsection) {
932
+			try {
933
+				$subsection->_normalize($req_data);
934
+			} catch (EE_Validation_Error $e) {
935
+				$subsection->add_validation_error($e);
936
+			}
937
+		}
938
+	}
939
+
940
+
941
+	/**
942
+	 * Performs validation on this form section and its subsections.
943
+	 * For each subsection,
944
+	 * calls _validate_{subsection_name} on THIS form (if the function exists)
945
+	 * and passes it the subsection, then calls _validate on that subsection.
946
+	 * If you need to perform validation on the form as a whole (considering multiple)
947
+	 * you would be best to override this _validate method,
948
+	 * calling parent::_validate() first.
949
+	 *
950
+	 * @throws EE_Error
951
+	 */
952
+	protected function _validate()
953
+	{
954
+		//reset the cache of whether this form is valid or not- we're re-validating it now
955
+		$this->is_valid = null;
956
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
+			if (method_exists($this, '_validate_' . $subsection_name)) {
958
+				call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
959
+			}
960
+			$subsection->_validate();
961
+		}
962
+	}
963
+
964
+
965
+	/**
966
+	 * Gets all the validated inputs for the form section
967
+	 *
968
+	 * @return array
969
+	 * @throws EE_Error
970
+	 */
971
+	public function valid_data()
972
+	{
973
+		$inputs = array();
974
+		foreach ($this->subsections() as $subsection_name => $subsection) {
975
+			if ($subsection instanceof EE_Form_Section_Proper) {
976
+				$inputs[ $subsection_name ] = $subsection->valid_data();
977
+			} elseif ($subsection instanceof EE_Form_Input_Base) {
978
+				$inputs[ $subsection_name ] = $subsection->normalized_value();
979
+			}
980
+		}
981
+		return $inputs;
982
+	}
983
+
984
+
985
+	/**
986
+	 * Gets all the inputs on this form section
987
+	 *
988
+	 * @return EE_Form_Input_Base[]
989
+	 * @throws EE_Error
990
+	 */
991
+	public function inputs()
992
+	{
993
+		$inputs = array();
994
+		foreach ($this->subsections() as $subsection_name => $subsection) {
995
+			if ($subsection instanceof EE_Form_Input_Base) {
996
+				$inputs[ $subsection_name ] = $subsection;
997
+			}
998
+		}
999
+		return $inputs;
1000
+	}
1001
+
1002
+
1003
+	/**
1004
+	 * Gets all the subsections which are a proper form
1005
+	 *
1006
+	 * @return EE_Form_Section_Proper[]
1007
+	 * @throws EE_Error
1008
+	 */
1009
+	public function subforms()
1010
+	{
1011
+		$form_sections = array();
1012
+		foreach ($this->subsections() as $name => $obj) {
1013
+			if ($obj instanceof EE_Form_Section_Proper) {
1014
+				$form_sections[ $name ] = $obj;
1015
+			}
1016
+		}
1017
+		return $form_sections;
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * Gets all the subsections (inputs, proper subsections, or html-only sections).
1023
+	 * Consider using inputs() or subforms()
1024
+	 * if you only want form inputs or proper form sections.
1025
+	 *
1026
+	 * @param boolean $require_construction_to_be_finalized most client code should
1027
+	 *                                                      leave this as TRUE so that the inputs will be properly
1028
+	 *                                                      configured. However, some client code may be ok with
1029
+	 *                                                      construction finalize being called later
1030
+	 *                                                      (realizing that the subsections' html names might not be
1031
+	 *                                                      set yet, etc.)
1032
+	 * @return EE_Form_Section_Proper[]
1033
+	 * @throws EE_Error
1034
+	 */
1035
+	public function subsections($require_construction_to_be_finalized = true)
1036
+	{
1037
+		if ($require_construction_to_be_finalized) {
1038
+			$this->ensure_construct_finalized_called();
1039
+		}
1040
+		return $this->_subsections;
1041
+	}
1042
+
1043
+
1044
+	/**
1045
+	 * Returns whether this form has any subforms or inputs
1046
+	 * @return bool
1047
+	 */
1048
+	public function hasSubsections()
1049
+	{
1050
+		return ! empty($this->_subsections);
1051
+	}
1052
+
1053
+
1054
+	/**
1055
+	 * Returns a simple array where keys are input names, and values are their normalized
1056
+	 * values. (Similar to calling get_input_value on inputs)
1057
+	 *
1058
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1059
+	 *                                        or just this forms' direct children inputs
1060
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1061
+	 *                                        or allow multidimensional array
1062
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1063
+	 *                                        with array keys being input names
1064
+	 *                                        (regardless of whether they are from a subsection or not),
1065
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1066
+	 *                                        where keys are always subsection names and values are either
1067
+	 *                                        the input's normalized value, or an array like the top-level array
1068
+	 * @throws EE_Error
1069
+	 */
1070
+	public function input_values($include_subform_inputs = false, $flatten = false)
1071
+	{
1072
+		return $this->_input_values(false, $include_subform_inputs, $flatten);
1073
+	}
1074
+
1075
+
1076
+	/**
1077
+	 * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1078
+	 * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1079
+	 * is not necessarily the value we want to display to users. This creates an array
1080
+	 * where keys are the input names, and values are their display values
1081
+	 *
1082
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1083
+	 *                                        or just this forms' direct children inputs
1084
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1085
+	 *                                        or allow multidimensional array
1086
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1087
+	 *                                        with array keys being input names
1088
+	 *                                        (regardless of whether they are from a subsection or not),
1089
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1090
+	 *                                        where keys are always subsection names and values are either
1091
+	 *                                        the input's normalized value, or an array like the top-level array
1092
+	 * @throws EE_Error
1093
+	 */
1094
+	public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1095
+	{
1096
+		return $this->_input_values(true, $include_subform_inputs, $flatten);
1097
+	}
1098
+
1099
+
1100
+	/**
1101
+	 * Gets the input values from the form
1102
+	 *
1103
+	 * @param boolean $pretty                 Whether to retrieve the pretty value,
1104
+	 *                                        or just the normalized value
1105
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1106
+	 *                                        or just this forms' direct children inputs
1107
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1108
+	 *                                        or allow multidimensional array
1109
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1110
+	 *                                        input names (regardless of whether they are from a subsection or not),
1111
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1112
+	 *                                        where keys are always subsection names and values are either
1113
+	 *                                        the input's normalized value, or an array like the top-level array
1114
+	 * @throws EE_Error
1115
+	 */
1116
+	public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1117
+	{
1118
+		$input_values = array();
1119
+		foreach ($this->subsections() as $subsection_name => $subsection) {
1120
+			if ($subsection instanceof EE_Form_Input_Base) {
1121
+				$input_values[ $subsection_name ] = $pretty
1122
+					? $subsection->pretty_value()
1123
+					: $subsection->normalized_value();
1124
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1125
+				$subform_input_values = $subsection->_input_values(
1126
+					$pretty,
1127
+					$include_subform_inputs,
1128
+					$flatten
1129
+				);
1130
+				if ($flatten) {
1131
+					$input_values = array_merge($input_values, $subform_input_values);
1132
+				} else {
1133
+					$input_values[ $subsection_name ] = $subform_input_values;
1134
+				}
1135
+			}
1136
+		}
1137
+		return $input_values;
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * Gets the originally submitted input values from the form
1143
+	 *
1144
+	 * @param boolean $include_subforms  Whether to include inputs from subforms,
1145
+	 *                                   or just this forms' direct children inputs
1146
+	 * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1147
+	 *                                   with array keys being input names
1148
+	 *                                   (regardless of whether they are from a subsection or not),
1149
+	 *                                   and if $flatten is FALSE it can be a multidimensional array
1150
+	 *                                   where keys are always subsection names and values are either
1151
+	 *                                   the input's normalized value, or an array like the top-level array
1152
+	 * @throws EE_Error
1153
+	 */
1154
+	public function submitted_values($include_subforms = false)
1155
+	{
1156
+		$submitted_values = array();
1157
+		foreach ($this->subsections() as $subsection) {
1158
+			if ($subsection instanceof EE_Form_Input_Base) {
1159
+				// is this input part of an array of inputs?
1160
+				if (strpos($subsection->html_name(), '[') !== false) {
1161
+					$full_input_name  = EEH_Array::convert_array_values_to_keys(
1162
+						explode(
1163
+							'[',
1164
+							str_replace(']', '', $subsection->html_name())
1165
+						),
1166
+						$subsection->raw_value()
1167
+					);
1168
+					$submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169
+				} else {
1170
+					$submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1171
+				}
1172
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173
+				$subform_input_values = $subsection->submitted_values($include_subforms);
1174
+				$submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1175
+			}
1176
+		}
1177
+		return $submitted_values;
1178
+	}
1179
+
1180
+
1181
+	/**
1182
+	 * Indicates whether or not this form has received a submission yet
1183
+	 * (ie, had receive_form_submission called on it yet)
1184
+	 *
1185
+	 * @return boolean
1186
+	 * @throws EE_Error
1187
+	 */
1188
+	public function has_received_submission()
1189
+	{
1190
+		$this->ensure_construct_finalized_called();
1191
+		return $this->_received_submission;
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * Equivalent to passing 'exclude' in the constructor's options array.
1197
+	 * Removes the listed inputs from the form
1198
+	 *
1199
+	 * @param array $inputs_to_exclude values are the input names
1200
+	 * @return void
1201
+	 */
1202
+	public function exclude(array $inputs_to_exclude = array())
1203
+	{
1204
+		foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
+			unset($this->_subsections[ $input_to_exclude_name ]);
1206
+		}
1207
+	}
1208
+
1209
+
1210
+	/**
1211
+	 * @param array $inputs_to_hide
1212
+	 * @throws EE_Error
1213
+	 */
1214
+	public function hide(array $inputs_to_hide = array())
1215
+	{
1216
+		foreach ($inputs_to_hide as $input_to_hide) {
1217
+			$input = $this->get_input($input_to_hide);
1218
+			$input->set_display_strategy(new EE_Hidden_Display_Strategy());
1219
+		}
1220
+	}
1221
+
1222
+
1223
+	/**
1224
+	 * add_subsections
1225
+	 * Adds the listed subsections to the form section.
1226
+	 * If $subsection_name_to_target is provided,
1227
+	 * then new subsections are added before or after that subsection,
1228
+	 * otherwise to the start or end of the entire subsections array.
1229
+	 *
1230
+	 * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1231
+	 *                                                          where keys are their names
1232
+	 * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1233
+	 *                                                          should be added before or after
1234
+	 *                                                          IF $subsection_name_to_target is null,
1235
+	 *                                                          then $new_subsections will be added to
1236
+	 *                                                          the beginning or end of the entire subsections array
1237
+	 * @param boolean                $add_before                whether to add $new_subsections, before or after
1238
+	 *                                                          $subsection_name_to_target,
1239
+	 *                                                          or if $subsection_name_to_target is null,
1240
+	 *                                                          before or after entire subsections array
1241
+	 * @return void
1242
+	 * @throws EE_Error
1243
+	 */
1244
+	public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1245
+	{
1246
+		foreach ($new_subsections as $subsection_name => $subsection) {
1247
+			if (! $subsection instanceof EE_Form_Section_Base) {
1248
+				EE_Error::add_error(
1249
+					sprintf(
1250
+						esc_html__(
1251
+							"Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1252
+							'event_espresso'
1253
+						),
1254
+						get_class($subsection),
1255
+						$subsection_name,
1256
+						$this->name()
1257
+					)
1258
+				);
1259
+				unset($new_subsections[ $subsection_name ]);
1260
+			}
1261
+		}
1262
+		$this->_subsections = EEH_Array::insert_into_array(
1263
+			$this->_subsections,
1264
+			$new_subsections,
1265
+			$subsection_name_to_target,
1266
+			$add_before
1267
+		);
1268
+		if ($this->_construction_finalized) {
1269
+			foreach ($this->_subsections as $name => $subsection) {
1270
+				$subsection->_construct_finalize($this, $name);
1271
+			}
1272
+		}
1273
+	}
1274
+
1275
+
1276
+	/**
1277
+	 * Just gets all validatable subsections to clean their sensitive data
1278
+	 *
1279
+	 * @throws EE_Error
1280
+	 */
1281
+	public function clean_sensitive_data()
1282
+	{
1283
+		foreach ($this->get_validatable_subsections() as $subsection) {
1284
+			$subsection->clean_sensitive_data();
1285
+		}
1286
+	}
1287
+
1288
+
1289
+	/**
1290
+	 * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1291
+	 * @param string                           $form_submission_error_message
1292
+	 * @param EE_Form_Section_Validatable $form_section unused
1293
+	 * @throws EE_Error
1294
+	 */
1295
+	public function set_submission_error_message(
1296
+		$form_submission_error_message = ''
1297
+	) {
1298
+		$this->_form_submission_error_message = ! empty($form_submission_error_message)
1299
+			? $form_submission_error_message
1300
+			: $this->getAllValidationErrorsString();
1301
+	}
1302
+
1303
+
1304
+	/**
1305
+	 * Returns the cached error message. A default value is set for this during _validate(),
1306
+	 * (called during receive_form_submission) but it can be explicitly set using
1307
+	 * set_submission_error_message
1308
+	 *
1309
+	 * @return string
1310
+	 */
1311
+	public function submission_error_message()
1312
+	{
1313
+		return $this->_form_submission_error_message;
1314
+	}
1315
+
1316
+
1317
+	/**
1318
+	 * Sets a message to display if the data submitted to the form was valid.
1319
+	 * @param string $form_submission_success_message
1320
+	 */
1321
+	public function set_submission_success_message($form_submission_success_message = '')
1322
+	{
1323
+		$this->_form_submission_success_message = ! empty($form_submission_success_message)
1324
+			? $form_submission_success_message
1325
+			: esc_html__('Form submitted successfully', 'event_espresso');
1326
+	}
1327
+
1328
+
1329
+	/**
1330
+	 * Gets a message appropriate for display when the form is correctly submitted
1331
+	 * @return string
1332
+	 */
1333
+	public function submission_success_message()
1334
+	{
1335
+		return $this->_form_submission_success_message;
1336
+	}
1337
+
1338
+
1339
+	/**
1340
+	 * Returns the prefix that should be used on child of this form section for
1341
+	 * their html names. If this form section itself has a parent, prepends ITS
1342
+	 * prefix onto this form section's prefix. Used primarily by
1343
+	 * EE_Form_Input_Base::_set_default_html_name_if_empty
1344
+	 *
1345
+	 * @return string
1346
+	 * @throws EE_Error
1347
+	 */
1348
+	public function html_name_prefix()
1349
+	{
1350
+		if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1351
+			return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1352
+		}
1353
+		return $this->name();
1354
+	}
1355
+
1356
+
1357
+	/**
1358
+	 * Gets the name, but first checks _construct_finalize has been called. If not,
1359
+	 * calls it (assumes there is no parent and that we want the name to be whatever
1360
+	 * was set, which is probably nothing, or the classname)
1361
+	 *
1362
+	 * @return string
1363
+	 * @throws EE_Error
1364
+	 */
1365
+	public function name()
1366
+	{
1367
+		$this->ensure_construct_finalized_called();
1368
+		return parent::name();
1369
+	}
1370
+
1371
+
1372
+	/**
1373
+	 * @return EE_Form_Section_Proper
1374
+	 * @throws EE_Error
1375
+	 */
1376
+	public function parent_section()
1377
+	{
1378
+		$this->ensure_construct_finalized_called();
1379
+		return parent::parent_section();
1380
+	}
1381
+
1382
+
1383
+	/**
1384
+	 * make sure construction finalized was called, otherwise children might not be ready
1385
+	 *
1386
+	 * @return void
1387
+	 * @throws EE_Error
1388
+	 */
1389
+	public function ensure_construct_finalized_called()
1390
+	{
1391
+		if (! $this->_construction_finalized) {
1392
+			$this->_construct_finalize($this->_parent_section, $this->_name);
1393
+		}
1394
+	}
1395
+
1396
+
1397
+	/**
1398
+	 * Checks if any of this form section's inputs, or any of its children's inputs,
1399
+	 * are in teh form data. If any are found, returns true. Else false
1400
+	 *
1401
+	 * @param array $req_data
1402
+	 * @return boolean
1403
+	 * @throws EE_Error
1404
+	 */
1405
+	public function form_data_present_in($req_data = null)
1406
+	{
1407
+		$req_data = $this->getCachedRequest($req_data);
1408
+		foreach ($this->subsections() as $subsection) {
1409
+			if ($subsection instanceof EE_Form_Input_Base) {
1410
+				if ($subsection->form_data_present_in($req_data)) {
1411
+					return true;
1412
+				}
1413
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
1414
+				if ($subsection->form_data_present_in($req_data)) {
1415
+					return true;
1416
+				}
1417
+			}
1418
+		}
1419
+		return false;
1420
+	}
1421
+
1422
+
1423
+	/**
1424
+	 * Gets validation errors for this form section and subsections
1425
+	 * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1426
+	 * gets the validation errors for ALL subsection
1427
+	 *
1428
+	 * @return EE_Validation_Error[]
1429
+	 * @throws EE_Error
1430
+	 */
1431
+	public function get_validation_errors_accumulated()
1432
+	{
1433
+		$validation_errors = $this->get_validation_errors();
1434
+		foreach ($this->get_validatable_subsections() as $subsection) {
1435
+			if ($subsection instanceof EE_Form_Section_Proper) {
1436
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1437
+			} else {
1438
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors();
1439
+			}
1440
+			if ($validation_errors_on_this_subsection) {
1441
+				$validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1442
+			}
1443
+		}
1444
+		return $validation_errors;
1445
+	}
1446
+
1447
+	/**
1448
+	 * Fetch validation errors from children and grandchildren and puts them in a single string.
1449
+	 * This traverses the form section tree to generate this, but you probably want to instead use
1450
+	 * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1451
+	 *
1452
+	 * @return string
1453
+	 * @since $VID:$
1454
+	 */
1455
+	protected function getAllValidationErrorsString()
1456
+	{
1457
+		$submission_error_messages = array();
1458
+		// bad, bad, bad registrant
1459
+		foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1460
+			if ($validation_error instanceof EE_Validation_Error) {
1461
+				$form_section = $validation_error->get_form_section();
1462
+				if ($form_section instanceof EE_Form_Input_Base) {
1463
+				   $label = $validation_error->get_form_section()->html_label_text();
1464
+				} elseif($form_section instanceof EE_Form_Section_Validatable) {
1465
+					$label = $validation_error->get_form_section()->name();
1466
+				} else {
1467
+					$label = esc_html__('Unknown', 'event_espresso');
1468
+				}
1469
+				$submission_error_messages[] = sprintf(
1470
+					__('%s : %s', 'event_espresso'),
1471
+					$label,
1472
+					$validation_error->getMessage()
1473
+				);
1474
+			}
1475
+		}
1476
+		return implode('<br', $submission_error_messages);
1477
+	}
1478
+
1479
+
1480
+	/**
1481
+	 * This isn't just the name of an input, it's a path pointing to an input. The
1482
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
1483
+	 * dot-dot-slash (../) means to ascend into the parent section.
1484
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1485
+	 * which will be returned.
1486
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1487
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1488
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1489
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1490
+	 * Etc
1491
+	 *
1492
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1493
+	 * @return EE_Form_Section_Base
1494
+	 * @throws EE_Error
1495
+	 */
1496
+	public function find_section_from_path($form_section_path)
1497
+	{
1498
+		//check if we can find the input from purely going straight up the tree
1499
+		$input = parent::find_section_from_path($form_section_path);
1500
+		if ($input instanceof EE_Form_Section_Base) {
1501
+			return $input;
1502
+		}
1503
+		$next_slash_pos = strpos($form_section_path, '/');
1504
+		if ($next_slash_pos !== false) {
1505
+			$child_section_name = substr($form_section_path, 0, $next_slash_pos);
1506
+			$subpath            = substr($form_section_path, $next_slash_pos + 1);
1507
+		} else {
1508
+			$child_section_name = $form_section_path;
1509
+			$subpath            = '';
1510
+		}
1511
+		$child_section = $this->get_subsection($child_section_name);
1512
+		if ($child_section instanceof EE_Form_Section_Base) {
1513
+			return $child_section->find_section_from_path($subpath);
1514
+		}
1515
+		return null;
1516
+	}
1517 1517
 }
1518 1518
 
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Validatable.form.php 1 patch
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -35,150 +35,150 @@  discard block
 block discarded – undo
35 35
 abstract class EE_Form_Section_Validatable extends EE_Form_Section_Base
36 36
 {
37 37
 
38
-    /**
39
-     * Array of validation errors in this section. Does not contain validation errors in subsections, however.
40
-     * Those are stored individually on each subsection.
41
-     *
42
-     * @var EE_Validation_Error[]
43
-     */
44
-    protected $_validation_errors = array();
45
-
46
-
47
-
48
-    /**
49
-     * Errors on this form section. Note: EE_Form_Section_Proper
50
-     * has another function for getting all errors in this form section and subsections
51
-     * called get_validation_errors_accumulated
52
-     *
53
-     * @return EE_Validation_Error[]
54
-     */
55
-    public function get_validation_errors()
56
-    {
57
-        return $this->_validation_errors;
58
-    }
59
-
60
-
61
-
62
-    /**
63
-     * returns a comma-separated list of all the validation errors in it.
64
-     * If we want this to be customizable, we may decide to create a strategy for displaying it
65
-     *
66
-     * @return string
67
-     */
68
-    public function get_validation_error_string()
69
-    {
70
-        $validation_error_messages = array();
71
-        if ($this->get_validation_errors()) {
72
-            foreach ($this->get_validation_errors() as $validation_error) {
73
-                if ($validation_error instanceof EE_Validation_Error) {
74
-                    $validation_error_messages[] = $validation_error->getMessage();
75
-                }
76
-            }
77
-        }
78
-        return implode(", ", $validation_error_messages);
79
-    }
80
-
81
-
82
-
83
-    /**
84
-     * Performs validation on this form section (and subsections). Should be called after _normalize()
85
-     *
86
-     * @return boolean of whether or not the form section is valid
87
-     */
88
-    abstract protected function _validate();
89
-
90
-
91
-
92
-    /**
93
-     * Checks if this field has any validation errors
94
-     *
95
-     * @return boolean
96
-     */
97
-    public function is_valid()
98
-    {
99
-        if (count($this->_validation_errors)) {
100
-            return false;
101
-        } else {
102
-            return true;
103
-        }
104
-    }
105
-
106
-
107
-
108
-    /**
109
-     * Sanitizes input for this form section
110
-     *
111
-     * @param array $req_data is the full request data like $_POST
112
-     * @return boolean of whether a normalization error occurred
113
-     */
114
-    abstract protected function _normalize($req_data);
115
-
116
-
117
-
118
-    /**
119
-     * Creates a validation error from the arguments provided, and adds it to the form section's list.
120
-     * If such an EE_Validation_Error object is passed in as the first arg, simply sets this as its form section, and
121
-     * adds it to the list of validation errors of errors
122
-     *
123
-     * @param mixed     $message_or_object  internationalized string describing the validation error; or it could be a
124
-     *                                      proper EE_Validation_Error object
125
-     * @param string    $error_code         a short key which can be used to uniquely identify the error
126
-     * @param Exception $previous_exception if there was an exception that caused the error, that exception
127
-     * @return void
128
-     */
129
-    public function add_validation_error($message_or_object, $error_code = null, $previous_exception = null)
130
-    {
131
-        if ($message_or_object instanceof EE_Validation_Error) {
132
-            $validation_error = $message_or_object;
133
-            $validation_error->set_form_section($this);
134
-        } else {
135
-            $validation_error = new EE_Validation_Error($message_or_object, $error_code, $this, $previous_exception);
136
-        }
137
-        $this->_validation_errors[] = $validation_error;
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * When generating the JS for the jquery validation rules like<br>
144
-     * <code>$( "#myform" ).validate({
145
-     * rules: {
146
-     * password: "required",
147
-     * password_again: {
148
-     * equalTo: "#password"
149
-     * }
150
-     * }
151
-     * });</code>
152
-     * gets the sections like
153
-     * <br><code>password: "required",
154
-     * password_again: {
155
-     * equalTo: "#password"
156
-     * }</code>
157
-     * except we leave it as a PHP object, and leave wp_localize_script to
158
-     * turn it into a JSON object which can be used by the js
159
-     *
160
-     * @return array
161
-     */
162
-    abstract public function get_jquery_validation_rules();
163
-
164
-
165
-
166
-    /**
167
-     * Checks if this form section's data is present in the req data specified
168
-     *
169
-     * @param array $req_data usually $_POST, if null that's what's used
170
-     * @return boolean
171
-     */
172
-    abstract public function form_data_present_in($req_data = null);
173
-
174
-
175
-
176
-    /**
177
-     * Removes teh sensitive data from this form section (usually done after
178
-     * utilizing the data business function, but before saving it somewhere. Eg,
179
-     * may remove a password from the form after verifying it was correct)
180
-     *
181
-     * @return void
182
-     */
183
-    abstract public function clean_sensitive_data();
38
+	/**
39
+	 * Array of validation errors in this section. Does not contain validation errors in subsections, however.
40
+	 * Those are stored individually on each subsection.
41
+	 *
42
+	 * @var EE_Validation_Error[]
43
+	 */
44
+	protected $_validation_errors = array();
45
+
46
+
47
+
48
+	/**
49
+	 * Errors on this form section. Note: EE_Form_Section_Proper
50
+	 * has another function for getting all errors in this form section and subsections
51
+	 * called get_validation_errors_accumulated
52
+	 *
53
+	 * @return EE_Validation_Error[]
54
+	 */
55
+	public function get_validation_errors()
56
+	{
57
+		return $this->_validation_errors;
58
+	}
59
+
60
+
61
+
62
+	/**
63
+	 * returns a comma-separated list of all the validation errors in it.
64
+	 * If we want this to be customizable, we may decide to create a strategy for displaying it
65
+	 *
66
+	 * @return string
67
+	 */
68
+	public function get_validation_error_string()
69
+	{
70
+		$validation_error_messages = array();
71
+		if ($this->get_validation_errors()) {
72
+			foreach ($this->get_validation_errors() as $validation_error) {
73
+				if ($validation_error instanceof EE_Validation_Error) {
74
+					$validation_error_messages[] = $validation_error->getMessage();
75
+				}
76
+			}
77
+		}
78
+		return implode(", ", $validation_error_messages);
79
+	}
80
+
81
+
82
+
83
+	/**
84
+	 * Performs validation on this form section (and subsections). Should be called after _normalize()
85
+	 *
86
+	 * @return boolean of whether or not the form section is valid
87
+	 */
88
+	abstract protected function _validate();
89
+
90
+
91
+
92
+	/**
93
+	 * Checks if this field has any validation errors
94
+	 *
95
+	 * @return boolean
96
+	 */
97
+	public function is_valid()
98
+	{
99
+		if (count($this->_validation_errors)) {
100
+			return false;
101
+		} else {
102
+			return true;
103
+		}
104
+	}
105
+
106
+
107
+
108
+	/**
109
+	 * Sanitizes input for this form section
110
+	 *
111
+	 * @param array $req_data is the full request data like $_POST
112
+	 * @return boolean of whether a normalization error occurred
113
+	 */
114
+	abstract protected function _normalize($req_data);
115
+
116
+
117
+
118
+	/**
119
+	 * Creates a validation error from the arguments provided, and adds it to the form section's list.
120
+	 * If such an EE_Validation_Error object is passed in as the first arg, simply sets this as its form section, and
121
+	 * adds it to the list of validation errors of errors
122
+	 *
123
+	 * @param mixed     $message_or_object  internationalized string describing the validation error; or it could be a
124
+	 *                                      proper EE_Validation_Error object
125
+	 * @param string    $error_code         a short key which can be used to uniquely identify the error
126
+	 * @param Exception $previous_exception if there was an exception that caused the error, that exception
127
+	 * @return void
128
+	 */
129
+	public function add_validation_error($message_or_object, $error_code = null, $previous_exception = null)
130
+	{
131
+		if ($message_or_object instanceof EE_Validation_Error) {
132
+			$validation_error = $message_or_object;
133
+			$validation_error->set_form_section($this);
134
+		} else {
135
+			$validation_error = new EE_Validation_Error($message_or_object, $error_code, $this, $previous_exception);
136
+		}
137
+		$this->_validation_errors[] = $validation_error;
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * When generating the JS for the jquery validation rules like<br>
144
+	 * <code>$( "#myform" ).validate({
145
+	 * rules: {
146
+	 * password: "required",
147
+	 * password_again: {
148
+	 * equalTo: "#password"
149
+	 * }
150
+	 * }
151
+	 * });</code>
152
+	 * gets the sections like
153
+	 * <br><code>password: "required",
154
+	 * password_again: {
155
+	 * equalTo: "#password"
156
+	 * }</code>
157
+	 * except we leave it as a PHP object, and leave wp_localize_script to
158
+	 * turn it into a JSON object which can be used by the js
159
+	 *
160
+	 * @return array
161
+	 */
162
+	abstract public function get_jquery_validation_rules();
163
+
164
+
165
+
166
+	/**
167
+	 * Checks if this form section's data is present in the req data specified
168
+	 *
169
+	 * @param array $req_data usually $_POST, if null that's what's used
170
+	 * @return boolean
171
+	 */
172
+	abstract public function form_data_present_in($req_data = null);
173
+
174
+
175
+
176
+	/**
177
+	 * Removes teh sensitive data from this form section (usually done after
178
+	 * utilizing the data business function, but before saving it somewhere. Eg,
179
+	 * may remove a password from the form after verifying it was correct)
180
+	 *
181
+	 * @return void
182
+	 */
183
+	abstract public function clean_sensitive_data();
184 184
 }
185 185
\ No newline at end of file
Please login to merge, or discard this patch.
admin/extend/registrations/Extend_EE_Registrations_List_Table.class.php 2 patches
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -15,115 +15,115 @@
 block discarded – undo
15 15
 class Extend_EE_Registrations_List_Table extends EE_Registrations_List_Table
16 16
 {
17 17
 
18
-    /**
19
-     * @param EE_Registration $item
20
-     * @return string
21
-     * @throws EE_Error
22
-     * @throws InvalidArgumentException
23
-     * @throws ReflectionException
24
-     * @throws InvalidDataTypeException
25
-     * @throws InvalidInterfaceException
26
-     */
27
-    function column__REG_date(EE_Registration $item)
28
-    {
29
-        $date_linked = parent::column__REG_date($item);
30
-        $actions = array();
31
-        //Build row actions
32
-        $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array(
33
-            'action'   => 'event_registrations',
34
-            'event_id' => $item->event_ID(),
35
-        ), REG_ADMIN_URL);
36
-        $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can(
37
-            'ee_read_registration',
38
-            'espresso_registrations_registration_checkins',
39
-            $item->ID()
40
-        ) && EE_Registry::instance()->CAP->current_user_can(
41
-            'ee_read_checkins',
42
-            'espresso_registrations_registration_checkins'
43
-        )
44
-            ? '<a href="' . $check_in_url . '"'
45
-              . ' title="' . esc_attr__(
46
-                  'The Check-In List allows you to easily toggle check-in status for this event',
47
-                  'event_espresso'
48
-              )
49
-              . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>'
50
-            : esc_html__('View Check-ins', 'event_espresso');
18
+	/**
19
+	 * @param EE_Registration $item
20
+	 * @return string
21
+	 * @throws EE_Error
22
+	 * @throws InvalidArgumentException
23
+	 * @throws ReflectionException
24
+	 * @throws InvalidDataTypeException
25
+	 * @throws InvalidInterfaceException
26
+	 */
27
+	function column__REG_date(EE_Registration $item)
28
+	{
29
+		$date_linked = parent::column__REG_date($item);
30
+		$actions = array();
31
+		//Build row actions
32
+		$check_in_url = EE_Admin_Page::add_query_args_and_nonce(array(
33
+			'action'   => 'event_registrations',
34
+			'event_id' => $item->event_ID(),
35
+		), REG_ADMIN_URL);
36
+		$actions['check_in'] = EE_Registry::instance()->CAP->current_user_can(
37
+			'ee_read_registration',
38
+			'espresso_registrations_registration_checkins',
39
+			$item->ID()
40
+		) && EE_Registry::instance()->CAP->current_user_can(
41
+			'ee_read_checkins',
42
+			'espresso_registrations_registration_checkins'
43
+		)
44
+			? '<a href="' . $check_in_url . '"'
45
+			  . ' title="' . esc_attr__(
46
+				  'The Check-In List allows you to easily toggle check-in status for this event',
47
+				  'event_espresso'
48
+			  )
49
+			  . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>'
50
+			: esc_html__('View Check-ins', 'event_espresso');
51 51
 
52
-        return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions));
53
-    }
52
+		return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions));
53
+	}
54 54
 
55 55
 
56
-    /**
57
-     *        column_default
58
-     *
59
-     * @param \EE_Registration $item
60
-     * @return string
61
-     * @throws EE_Error
62
-     * @throws InvalidArgumentException
63
-     * @throws InvalidDataTypeException
64
-     * @throws InvalidInterfaceException
65
-     * @throws ReflectionException
66
-     */
67
-    public function column_DTT_EVT_start(EE_Registration $item)
68
-    {
69
-        $remove_defaults = array('default_where_conditions' => 'none');
70
-        $ticket = $item->ticket();
71
-        $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array();
72
-        $EVT_ID = $item->event_ID();
73
-        $datetimes_for_display = array();
74
-        foreach ($datetimes as $datetime) {
75
-            $datetime_string = '';
76
-            if (EE_Registry::instance()->CAP->current_user_can(
77
-                'ee_read_checkin',
78
-                'espresso_registrations_registration_checkins',
79
-                $item->ID()
80
-            )) {
81
-                // open "a" tag and "href"
82
-                $datetime_string .= '<a href="';
83
-                // checkin URL
84
-                $datetime_string .= EE_Admin_Page::add_query_args_and_nonce(
85
-                    array(
86
-                        'action'   => 'event_registrations',
87
-                        'event_id' => $EVT_ID,
88
-                        'DTT_ID'   => $datetime->ID(),
89
-                    ),
90
-                    REG_ADMIN_URL
91
-                );
92
-                // close "href"
93
-                $datetime_string .= '"';
94
-                // open "title" tag
95
-                $datetime_string .= ' title="';
96
-                // link title text
97
-                $datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso');
98
-                // close "title" tag and end of "a" tag opening
99
-                $datetime_string .= '">';
100
-                // link text
101
-                $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start');
102
-                // close "a" tag
103
-                $datetime_string .= '</a>';
104
-            } else {
105
-                $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start');
106
-            }
107
-            // add a "View Registrations" link that filters list by event AND datetime
108
-            $datetime_string .= $this->row_actions(
109
-                array(
110
-                    'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
111
-                        array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()),
112
-                        REG_ADMIN_URL
113
-                    )
114
-                           . '" title="' . sprintf(
115
-                               esc_attr__(
116
-                                   'Filter this list to only show registrations for this datetime %s',
117
-                                   'event_espresso'
118
-                               ),
119
-                               $datetime->name()
120
-                           ) . '">'
121
-                           . esc_html__('View Registrations', 'event_espresso')
122
-                           . '</a>',
123
-                )
124
-            );
125
-            $datetimes_for_display[] = $datetime_string;
126
-        }
127
-        return $this->generateDisplayForDateTimes($datetimes_for_display);
128
-    }
56
+	/**
57
+	 *        column_default
58
+	 *
59
+	 * @param \EE_Registration $item
60
+	 * @return string
61
+	 * @throws EE_Error
62
+	 * @throws InvalidArgumentException
63
+	 * @throws InvalidDataTypeException
64
+	 * @throws InvalidInterfaceException
65
+	 * @throws ReflectionException
66
+	 */
67
+	public function column_DTT_EVT_start(EE_Registration $item)
68
+	{
69
+		$remove_defaults = array('default_where_conditions' => 'none');
70
+		$ticket = $item->ticket();
71
+		$datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array();
72
+		$EVT_ID = $item->event_ID();
73
+		$datetimes_for_display = array();
74
+		foreach ($datetimes as $datetime) {
75
+			$datetime_string = '';
76
+			if (EE_Registry::instance()->CAP->current_user_can(
77
+				'ee_read_checkin',
78
+				'espresso_registrations_registration_checkins',
79
+				$item->ID()
80
+			)) {
81
+				// open "a" tag and "href"
82
+				$datetime_string .= '<a href="';
83
+				// checkin URL
84
+				$datetime_string .= EE_Admin_Page::add_query_args_and_nonce(
85
+					array(
86
+						'action'   => 'event_registrations',
87
+						'event_id' => $EVT_ID,
88
+						'DTT_ID'   => $datetime->ID(),
89
+					),
90
+					REG_ADMIN_URL
91
+				);
92
+				// close "href"
93
+				$datetime_string .= '"';
94
+				// open "title" tag
95
+				$datetime_string .= ' title="';
96
+				// link title text
97
+				$datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso');
98
+				// close "title" tag and end of "a" tag opening
99
+				$datetime_string .= '">';
100
+				// link text
101
+				$datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start');
102
+				// close "a" tag
103
+				$datetime_string .= '</a>';
104
+			} else {
105
+				$datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start');
106
+			}
107
+			// add a "View Registrations" link that filters list by event AND datetime
108
+			$datetime_string .= $this->row_actions(
109
+				array(
110
+					'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
111
+						array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()),
112
+						REG_ADMIN_URL
113
+					)
114
+						   . '" title="' . sprintf(
115
+							   esc_attr__(
116
+								   'Filter this list to only show registrations for this datetime %s',
117
+								   'event_espresso'
118
+							   ),
119
+							   $datetime->name()
120
+						   ) . '">'
121
+						   . esc_html__('View Registrations', 'event_espresso')
122
+						   . '</a>',
123
+				)
124
+			);
125
+			$datetimes_for_display[] = $datetime_string;
126
+		}
127
+		return $this->generateDisplayForDateTimes($datetimes_for_display);
128
+	}
129 129
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -41,12 +41,12 @@  discard block
 block discarded – undo
41 41
             'ee_read_checkins',
42 42
             'espresso_registrations_registration_checkins'
43 43
         )
44
-            ? '<a href="' . $check_in_url . '"'
45
-              . ' title="' . esc_attr__(
44
+            ? '<a href="'.$check_in_url.'"'
45
+              . ' title="'.esc_attr__(
46 46
                   'The Check-In List allows you to easily toggle check-in status for this event',
47 47
                   'event_espresso'
48 48
               )
49
-              . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>'
49
+              . '">'.esc_html__('View Check-ins', 'event_espresso').'</a>'
50 50
             : esc_html__('View Check-ins', 'event_espresso');
51 51
 
52 52
         return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions));
@@ -107,17 +107,17 @@  discard block
 block discarded – undo
107 107
             // add a "View Registrations" link that filters list by event AND datetime
108 108
             $datetime_string .= $this->row_actions(
109 109
                 array(
110
-                    'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
110
+                    'event_datetime_filter' => '<a href="'.EE_Admin_Page::add_query_args_and_nonce(
111 111
                         array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()),
112 112
                         REG_ADMIN_URL
113 113
                     )
114
-                           . '" title="' . sprintf(
114
+                           . '" title="'.sprintf(
115 115
                                esc_attr__(
116 116
                                    'Filter this list to only show registrations for this datetime %s',
117 117
                                    'event_espresso'
118 118
                                ),
119 119
                                $datetime->name()
120
-                           ) . '">'
120
+                           ).'">'
121 121
                            . esc_html__('View Registrations', 'event_espresso')
122 122
                            . '</a>',
123 123
                 )
Please login to merge, or discard this patch.
admin_pages/registrations/EE_Registrations_List_Table.class.php 2 patches
Indentation   +926 added lines, -926 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\exceptions\InvalidInterfaceException;
4 4
 
5 5
 if (! defined('EVENT_ESPRESSO_VERSION')) {
6
-    exit('No direct script access allowed');
6
+	exit('No direct script access allowed');
7 7
 }
8 8
 
9 9
 
@@ -28,1006 +28,1006 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    /**
32
-     * @var array
33
-     */
34
-    private $_status;
31
+	/**
32
+	 * @var array
33
+	 */
34
+	private $_status;
35 35
 
36 36
 
37
-    /**
38
-     * An array of transaction details for the related transaction to the registration being processed.
39
-     * This is set via the _set_related_details method.
40
-     *
41
-     * @var array
42
-     */
43
-    protected $_transaction_details = array();
37
+	/**
38
+	 * An array of transaction details for the related transaction to the registration being processed.
39
+	 * This is set via the _set_related_details method.
40
+	 *
41
+	 * @var array
42
+	 */
43
+	protected $_transaction_details = array();
44 44
 
45 45
 
46
-    /**
47
-     * An array of event details for the related event to the registration being processed.
48
-     * This is set via the _set_related_details method.
49
-     *
50
-     * @var array
51
-     */
52
-    protected $_event_details = array();
46
+	/**
47
+	 * An array of event details for the related event to the registration being processed.
48
+	 * This is set via the _set_related_details method.
49
+	 *
50
+	 * @var array
51
+	 */
52
+	protected $_event_details = array();
53 53
 
54 54
 
55
-    /**
56
-     * @param \Registrations_Admin_Page $admin_page
57
-     */
58
-    public function __construct(Registrations_Admin_Page $admin_page)
59
-    {
60
-        if (! empty($_GET['event_id'])) {
61
-            $extra_query_args = array();
62
-            foreach ($admin_page->get_views() as $key => $view_details) {
63
-                $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']);
64
-            }
65
-            $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
66
-        }
67
-        parent::__construct($admin_page);
68
-        $this->_status = $this->_admin_page->get_registration_status_array();
69
-    }
55
+	/**
56
+	 * @param \Registrations_Admin_Page $admin_page
57
+	 */
58
+	public function __construct(Registrations_Admin_Page $admin_page)
59
+	{
60
+		if (! empty($_GET['event_id'])) {
61
+			$extra_query_args = array();
62
+			foreach ($admin_page->get_views() as $key => $view_details) {
63
+				$extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']);
64
+			}
65
+			$this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
66
+		}
67
+		parent::__construct($admin_page);
68
+		$this->_status = $this->_admin_page->get_registration_status_array();
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     *    _setup_data
74
-     *
75
-     * @access protected
76
-     * @return void
77
-     */
78
-    protected function _setup_data()
79
-    {
80
-        $this->_data = $this->_admin_page->get_registrations($this->_per_page);
81
-        $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false);
82
-    }
72
+	/**
73
+	 *    _setup_data
74
+	 *
75
+	 * @access protected
76
+	 * @return void
77
+	 */
78
+	protected function _setup_data()
79
+	{
80
+		$this->_data = $this->_admin_page->get_registrations($this->_per_page);
81
+		$this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false);
82
+	}
83 83
 
84 84
 
85
-    /**
86
-     *    _set_properties
87
-     *
88
-     * @access protected
89
-     * @return void
90
-     */
91
-    protected function _set_properties()
92
-    {
93
-        $this->_wp_list_args = array(
94
-            'singular' => __('registration', 'event_espresso'),
95
-            'plural'   => __('registrations', 'event_espresso'),
96
-            'ajax'     => true,
97
-            'screen'   => $this->_admin_page->get_current_screen()->id,
98
-        );
99
-        $ID_column_name = __('ID', 'event_espresso');
100
-        $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
101
-        $ID_column_name .= __('Registrant Name', 'event_espresso');
102
-        $ID_column_name .= '</span> ';
103
-        if (isset($_GET['event_id'])) {
104
-            $this->_columns = array(
105
-                'cb'               => '<input type="checkbox" />', //Render a checkbox instead of text
106
-                '_REG_ID'          => $ID_column_name,
107
-                'ATT_fname'        => __('Name', 'event_espresso'),
108
-                'ATT_email'        => __('Email', 'event_espresso'),
109
-                '_REG_date'        => __('Reg Date', 'event_espresso'),
110
-                'PRC_amount'       => __('TKT Price', 'event_espresso'),
111
-                '_REG_final_price' => __('Final Price', 'event_espresso'),
112
-                'TXN_total'        => __('Total Txn', 'event_espresso'),
113
-                'TXN_paid'         => __('Paid', 'event_espresso'),
114
-                'actions'          => __('Actions', 'event_espresso'),
115
-            );
116
-            $this->_bottom_buttons = array(
117
-                'report' => array(
118
-                    'route'         => 'registrations_report',
119
-                    'extra_request' => array(
120
-                        'EVT_ID'     => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
121
-                        'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
122
-                    ),
123
-                ),
124
-            );
125
-        } else {
126
-            $this->_columns = array(
127
-                'cb'               => '<input type="checkbox" />', //Render a checkbox instead of text
128
-                '_REG_ID'          => $ID_column_name,
129
-                'ATT_fname'        => __('Name', 'event_espresso'),
130
-                '_REG_date'        => __('TXN Date', 'event_espresso'),
131
-                'event_name'       => __('Event', 'event_espresso'),
132
-                'DTT_EVT_start'    => __('Event Date', 'event_espresso'),
133
-                '_REG_final_price' => __('Price', 'event_espresso'),
134
-                '_REG_paid'        => __('Paid', 'event_espresso'),
135
-                'actions'          => __('Actions', 'event_espresso'),
136
-            );
137
-            $this->_bottom_buttons = array(
138
-                'report_all' => array(
139
-                    'route'         => 'registrations_report',
140
-                    'extra_request' => array(
141
-                        'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
142
-                    ),
143
-                ),
144
-            );
145
-        }
146
-        $this->_bottom_buttons['report_filtered'] = array(
147
-            'route'         => 'registrations_report',
148
-            'extra_request' => array(
149
-                'use_filters' => true,
150
-                'filters'     => array_diff_key($this->_req_data, array_flip(array(
151
-                    'page',
152
-                    'action',
153
-                    'default_nonce',
154
-                ))),
155
-                'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
156
-            ),
157
-        );
158
-        $this->_primary_column = '_REG_ID';
159
-        $this->_sortable_columns = array(
160
-            '_REG_date'     => array('_REG_date' => true),   //true means its already sorted
161
-            /**
162
-             * Allows users to change the default sort if they wish.
163
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
164
-             * name.
165
-             */
166
-            'ATT_fname'     => array(
167
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
168
-                true,
169
-                $this,
170
-            )
171
-                ? array('ATT_lname' => false)
172
-                : array('ATT_fname' => false),
173
-            'event_name'    => array('event_name' => false),
174
-            'DTT_EVT_start' => array('DTT_EVT_start' => false),
175
-            '_REG_ID'       => array('_REG_ID' => false),
176
-        );
177
-        $this->_hidden_columns = array();
178
-    }
85
+	/**
86
+	 *    _set_properties
87
+	 *
88
+	 * @access protected
89
+	 * @return void
90
+	 */
91
+	protected function _set_properties()
92
+	{
93
+		$this->_wp_list_args = array(
94
+			'singular' => __('registration', 'event_espresso'),
95
+			'plural'   => __('registrations', 'event_espresso'),
96
+			'ajax'     => true,
97
+			'screen'   => $this->_admin_page->get_current_screen()->id,
98
+		);
99
+		$ID_column_name = __('ID', 'event_espresso');
100
+		$ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
101
+		$ID_column_name .= __('Registrant Name', 'event_espresso');
102
+		$ID_column_name .= '</span> ';
103
+		if (isset($_GET['event_id'])) {
104
+			$this->_columns = array(
105
+				'cb'               => '<input type="checkbox" />', //Render a checkbox instead of text
106
+				'_REG_ID'          => $ID_column_name,
107
+				'ATT_fname'        => __('Name', 'event_espresso'),
108
+				'ATT_email'        => __('Email', 'event_espresso'),
109
+				'_REG_date'        => __('Reg Date', 'event_espresso'),
110
+				'PRC_amount'       => __('TKT Price', 'event_espresso'),
111
+				'_REG_final_price' => __('Final Price', 'event_espresso'),
112
+				'TXN_total'        => __('Total Txn', 'event_espresso'),
113
+				'TXN_paid'         => __('Paid', 'event_espresso'),
114
+				'actions'          => __('Actions', 'event_espresso'),
115
+			);
116
+			$this->_bottom_buttons = array(
117
+				'report' => array(
118
+					'route'         => 'registrations_report',
119
+					'extra_request' => array(
120
+						'EVT_ID'     => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
121
+						'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
122
+					),
123
+				),
124
+			);
125
+		} else {
126
+			$this->_columns = array(
127
+				'cb'               => '<input type="checkbox" />', //Render a checkbox instead of text
128
+				'_REG_ID'          => $ID_column_name,
129
+				'ATT_fname'        => __('Name', 'event_espresso'),
130
+				'_REG_date'        => __('TXN Date', 'event_espresso'),
131
+				'event_name'       => __('Event', 'event_espresso'),
132
+				'DTT_EVT_start'    => __('Event Date', 'event_espresso'),
133
+				'_REG_final_price' => __('Price', 'event_espresso'),
134
+				'_REG_paid'        => __('Paid', 'event_espresso'),
135
+				'actions'          => __('Actions', 'event_espresso'),
136
+			);
137
+			$this->_bottom_buttons = array(
138
+				'report_all' => array(
139
+					'route'         => 'registrations_report',
140
+					'extra_request' => array(
141
+						'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
142
+					),
143
+				),
144
+			);
145
+		}
146
+		$this->_bottom_buttons['report_filtered'] = array(
147
+			'route'         => 'registrations_report',
148
+			'extra_request' => array(
149
+				'use_filters' => true,
150
+				'filters'     => array_diff_key($this->_req_data, array_flip(array(
151
+					'page',
152
+					'action',
153
+					'default_nonce',
154
+				))),
155
+				'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
156
+			),
157
+		);
158
+		$this->_primary_column = '_REG_ID';
159
+		$this->_sortable_columns = array(
160
+			'_REG_date'     => array('_REG_date' => true),   //true means its already sorted
161
+			/**
162
+			 * Allows users to change the default sort if they wish.
163
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
164
+			 * name.
165
+			 */
166
+			'ATT_fname'     => array(
167
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
168
+				true,
169
+				$this,
170
+			)
171
+				? array('ATT_lname' => false)
172
+				: array('ATT_fname' => false),
173
+			'event_name'    => array('event_name' => false),
174
+			'DTT_EVT_start' => array('DTT_EVT_start' => false),
175
+			'_REG_ID'       => array('_REG_ID' => false),
176
+		);
177
+		$this->_hidden_columns = array();
178
+	}
179 179
 
180 180
 
181
-    /**
182
-     * This simply sets up the row class for the table rows.
183
-     * Allows for easier overriding of child methods for setting up sorting.
184
-     *
185
-     * @param  EE_Registration $item the current item
186
-     * @return string
187
-     */
188
-    protected function _get_row_class($item)
189
-    {
190
-        $class = parent::_get_row_class($item);
191
-        //add status class
192
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
193
-        if ($this->_has_checkbox_column) {
194
-            $class .= ' has-checkbox-column';
195
-        }
196
-        return $class;
197
-    }
181
+	/**
182
+	 * This simply sets up the row class for the table rows.
183
+	 * Allows for easier overriding of child methods for setting up sorting.
184
+	 *
185
+	 * @param  EE_Registration $item the current item
186
+	 * @return string
187
+	 */
188
+	protected function _get_row_class($item)
189
+	{
190
+		$class = parent::_get_row_class($item);
191
+		//add status class
192
+		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
193
+		if ($this->_has_checkbox_column) {
194
+			$class .= ' has-checkbox-column';
195
+		}
196
+		return $class;
197
+	}
198 198
 
199 199
 
200
-    /**
201
-     * Set the $_transaction_details property if not set yet.
202
-     *
203
-     * @param EE_Registration $registration
204
-     * @throws EE_Error
205
-     * @throws InvalidArgumentException
206
-     * @throws ReflectionException
207
-     * @throws InvalidDataTypeException
208
-     * @throws InvalidInterfaceException
209
-     */
210
-    protected function _set_related_details(EE_Registration $registration)
211
-    {
212
-        $transaction = $registration->get_first_related('Transaction');
213
-        $status = $transaction instanceof EE_Transaction ? $transaction->status_ID()
214
-            : EEM_Transaction::failed_status_code;
215
-        $this->_transaction_details = array(
216
-            'transaction' => $transaction,
217
-            'status'      => $status,
218
-            'id'          => $transaction instanceof EE_Transaction ? $transaction->ID() : 0,
219
-            'title_attr'  => sprintf(
220
-                __('View Transaction Details (%s)', 'event_espresso'),
221
-                EEH_Template::pretty_status($status, false, 'sentence')
222
-            ),
223
-        );
224
-        try {
225
-            $event = $registration->event();
226
-        } catch (EntityNotFoundException $e) {
227
-            $event = null;
228
-        }
229
-        $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive;
230
-        $this->_event_details = array(
231
-            'event'      => $event,
232
-            'status'     => $status,
233
-            'id'         => $event instanceof EE_Event ? $event->ID() : 0,
234
-            'title_attr' => sprintf(
235
-                __('Edit Event (%s)', 'event_espresso'),
236
-                EEH_Template::pretty_status($status, false, 'sentence')
237
-            ),
238
-        );
239
-    }
200
+	/**
201
+	 * Set the $_transaction_details property if not set yet.
202
+	 *
203
+	 * @param EE_Registration $registration
204
+	 * @throws EE_Error
205
+	 * @throws InvalidArgumentException
206
+	 * @throws ReflectionException
207
+	 * @throws InvalidDataTypeException
208
+	 * @throws InvalidInterfaceException
209
+	 */
210
+	protected function _set_related_details(EE_Registration $registration)
211
+	{
212
+		$transaction = $registration->get_first_related('Transaction');
213
+		$status = $transaction instanceof EE_Transaction ? $transaction->status_ID()
214
+			: EEM_Transaction::failed_status_code;
215
+		$this->_transaction_details = array(
216
+			'transaction' => $transaction,
217
+			'status'      => $status,
218
+			'id'          => $transaction instanceof EE_Transaction ? $transaction->ID() : 0,
219
+			'title_attr'  => sprintf(
220
+				__('View Transaction Details (%s)', 'event_espresso'),
221
+				EEH_Template::pretty_status($status, false, 'sentence')
222
+			),
223
+		);
224
+		try {
225
+			$event = $registration->event();
226
+		} catch (EntityNotFoundException $e) {
227
+			$event = null;
228
+		}
229
+		$status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive;
230
+		$this->_event_details = array(
231
+			'event'      => $event,
232
+			'status'     => $status,
233
+			'id'         => $event instanceof EE_Event ? $event->ID() : 0,
234
+			'title_attr' => sprintf(
235
+				__('Edit Event (%s)', 'event_espresso'),
236
+				EEH_Template::pretty_status($status, false, 'sentence')
237
+			),
238
+		);
239
+	}
240 240
 
241 241
 
242
-    /**
243
-     *    _get_table_filters
244
-     *
245
-     * @access protected
246
-     * @return array
247
-     */
248
-    protected function _get_table_filters()
249
-    {
250
-        $filters = array();
251
-        //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
252
-        // methods.
253
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
254
-        $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
255
-        $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : '';
256
-        $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
257
-        $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
258
-        $status = array();
259
-        $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso'));
260
-        foreach ($this->_status as $key => $value) {
261
-            $status[] = array('id' => $key, 'text' => $value);
262
-        }
263
-        if ($this->_view !== 'incomplete') {
264
-            $filters[] = EEH_Form_Fields::select_input(
265
-                '_reg_status',
266
-                $status,
267
-                isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
268
-                    : ''
269
-            );
270
-        }
271
-        if (isset($this->_req_data['event_id'])) {
272
-            $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
273
-        }
274
-        return $filters;
275
-    }
242
+	/**
243
+	 *    _get_table_filters
244
+	 *
245
+	 * @access protected
246
+	 * @return array
247
+	 */
248
+	protected function _get_table_filters()
249
+	{
250
+		$filters = array();
251
+		//todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
252
+		// methods.
253
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
254
+		$cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
255
+		$reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : '';
256
+		$filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
257
+		$filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
258
+		$status = array();
259
+		$status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso'));
260
+		foreach ($this->_status as $key => $value) {
261
+			$status[] = array('id' => $key, 'text' => $value);
262
+		}
263
+		if ($this->_view !== 'incomplete') {
264
+			$filters[] = EEH_Form_Fields::select_input(
265
+				'_reg_status',
266
+				$status,
267
+				isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
268
+					: ''
269
+			);
270
+		}
271
+		if (isset($this->_req_data['event_id'])) {
272
+			$filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
273
+		}
274
+		return $filters;
275
+	}
276 276
 
277 277
 
278
-    /**
279
-     *    _add_view_counts
280
-     *
281
-     * @access protected
282
-     * @return void
283
-     * @throws EE_Error
284
-     * @throws InvalidArgumentException
285
-     * @throws InvalidDataTypeException
286
-     * @throws InvalidInterfaceException
287
-     */
288
-    protected function _add_view_counts()
289
-    {
290
-        $this->_views['all']['count'] = $this->_total_registrations();
291
-        $this->_views['month']['count'] = $this->_total_registrations_this_month();
292
-        $this->_views['today']['count'] = $this->_total_registrations_today();
293
-        if (EE_Registry::instance()->CAP->current_user_can(
294
-            'ee_delete_registrations',
295
-            'espresso_registrations_trash_registrations'
296
-        )) {
297
-            $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
298
-            $this->_views['trash']['count'] = $this->_total_registrations('trash');
299
-        }
300
-    }
278
+	/**
279
+	 *    _add_view_counts
280
+	 *
281
+	 * @access protected
282
+	 * @return void
283
+	 * @throws EE_Error
284
+	 * @throws InvalidArgumentException
285
+	 * @throws InvalidDataTypeException
286
+	 * @throws InvalidInterfaceException
287
+	 */
288
+	protected function _add_view_counts()
289
+	{
290
+		$this->_views['all']['count'] = $this->_total_registrations();
291
+		$this->_views['month']['count'] = $this->_total_registrations_this_month();
292
+		$this->_views['today']['count'] = $this->_total_registrations_today();
293
+		if (EE_Registry::instance()->CAP->current_user_can(
294
+			'ee_delete_registrations',
295
+			'espresso_registrations_trash_registrations'
296
+		)) {
297
+			$this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
298
+			$this->_views['trash']['count'] = $this->_total_registrations('trash');
299
+		}
300
+	}
301 301
 
302 302
 
303
-    /**
304
-     * _total_registrations
305
-     *
306
-     * @access protected
307
-     * @param string $view
308
-     * @return int
309
-     * @throws EE_Error
310
-     * @throws InvalidArgumentException
311
-     * @throws InvalidDataTypeException
312
-     * @throws InvalidInterfaceException
313
-     */
314
-    protected function _total_registrations($view = '')
315
-    {
316
-        $_where = array();
317
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
318
-        if ($EVT_ID) {
319
-            $_where['EVT_ID'] = $EVT_ID;
320
-        }
321
-        switch ($view) {
322
-            case 'trash':
323
-                return EEM_Registration::instance()->count_deleted(array($_where));
324
-                break;
325
-            case 'incomplete':
326
-                $_where['STS_ID'] = EEM_Registration::status_id_incomplete;
327
-                break;
328
-            default:
329
-                $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
330
-        }
331
-        return EEM_Registration::instance()->count(array($_where));
332
-    }
303
+	/**
304
+	 * _total_registrations
305
+	 *
306
+	 * @access protected
307
+	 * @param string $view
308
+	 * @return int
309
+	 * @throws EE_Error
310
+	 * @throws InvalidArgumentException
311
+	 * @throws InvalidDataTypeException
312
+	 * @throws InvalidInterfaceException
313
+	 */
314
+	protected function _total_registrations($view = '')
315
+	{
316
+		$_where = array();
317
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
318
+		if ($EVT_ID) {
319
+			$_where['EVT_ID'] = $EVT_ID;
320
+		}
321
+		switch ($view) {
322
+			case 'trash':
323
+				return EEM_Registration::instance()->count_deleted(array($_where));
324
+				break;
325
+			case 'incomplete':
326
+				$_where['STS_ID'] = EEM_Registration::status_id_incomplete;
327
+				break;
328
+			default:
329
+				$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
330
+		}
331
+		return EEM_Registration::instance()->count(array($_where));
332
+	}
333 333
 
334 334
 
335
-    /**
336
-     * _total_registrations_this_month
337
-     *
338
-     * @access protected
339
-     * @return int
340
-     * @throws EE_Error
341
-     * @throws InvalidArgumentException
342
-     * @throws InvalidDataTypeException
343
-     * @throws InvalidInterfaceException
344
-     */
345
-    protected function _total_registrations_this_month()
346
-    {
347
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
348
-        $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
349
-        $this_year_r = date('Y', current_time('timestamp'));
350
-        $time_start = ' 00:00:00';
351
-        $time_end = ' 23:59:59';
352
-        $this_month_r = date('m', current_time('timestamp'));
353
-        $days_this_month = date('t', current_time('timestamp'));
354
-        //setup date query.
355
-        $beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
356
-            'REG_date',
357
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
358
-            'Y-m-d H:i:s'
359
-        );
360
-        $end_string = EEM_Registration::instance()->convert_datetime_for_query(
361
-            'REG_date',
362
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
363
-            'Y-m-d H:i:s'
364
-        );
365
-        $_where['REG_date'] = array(
366
-            'BETWEEN',
367
-            array(
368
-                $beginning_string,
369
-                $end_string,
370
-            ),
371
-        );
372
-        $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
373
-        return EEM_Registration::instance()->count(array($_where));
374
-    }
335
+	/**
336
+	 * _total_registrations_this_month
337
+	 *
338
+	 * @access protected
339
+	 * @return int
340
+	 * @throws EE_Error
341
+	 * @throws InvalidArgumentException
342
+	 * @throws InvalidDataTypeException
343
+	 * @throws InvalidInterfaceException
344
+	 */
345
+	protected function _total_registrations_this_month()
346
+	{
347
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
348
+		$_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
349
+		$this_year_r = date('Y', current_time('timestamp'));
350
+		$time_start = ' 00:00:00';
351
+		$time_end = ' 23:59:59';
352
+		$this_month_r = date('m', current_time('timestamp'));
353
+		$days_this_month = date('t', current_time('timestamp'));
354
+		//setup date query.
355
+		$beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
356
+			'REG_date',
357
+			$this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
358
+			'Y-m-d H:i:s'
359
+		);
360
+		$end_string = EEM_Registration::instance()->convert_datetime_for_query(
361
+			'REG_date',
362
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
363
+			'Y-m-d H:i:s'
364
+		);
365
+		$_where['REG_date'] = array(
366
+			'BETWEEN',
367
+			array(
368
+				$beginning_string,
369
+				$end_string,
370
+			),
371
+		);
372
+		$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
373
+		return EEM_Registration::instance()->count(array($_where));
374
+	}
375 375
 
376 376
 
377
-    /**
378
-     * _total_registrations_today
379
-     *
380
-     * @access protected
381
-     * @return int
382
-     * @throws EE_Error
383
-     * @throws InvalidArgumentException
384
-     * @throws InvalidDataTypeException
385
-     * @throws InvalidInterfaceException
386
-     */
387
-    protected function _total_registrations_today()
388
-    {
389
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
390
-        $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
391
-        $current_date = date('Y-m-d', current_time('timestamp'));
392
-        $time_start = ' 00:00:00';
393
-        $time_end = ' 23:59:59';
394
-        $_where['REG_date'] = array(
395
-            'BETWEEN',
396
-            array(
397
-                EEM_Registration::instance()->convert_datetime_for_query(
398
-                    'REG_date',
399
-                    $current_date . $time_start,
400
-                    'Y-m-d H:i:s'
401
-                ),
402
-                EEM_Registration::instance()->convert_datetime_for_query(
403
-                    'REG_date',
404
-                    $current_date . $time_end,
405
-                    'Y-m-d H:i:s'
406
-                ),
407
-            ),
408
-        );
409
-        $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
410
-        return EEM_Registration::instance()->count(array($_where));
411
-    }
377
+	/**
378
+	 * _total_registrations_today
379
+	 *
380
+	 * @access protected
381
+	 * @return int
382
+	 * @throws EE_Error
383
+	 * @throws InvalidArgumentException
384
+	 * @throws InvalidDataTypeException
385
+	 * @throws InvalidInterfaceException
386
+	 */
387
+	protected function _total_registrations_today()
388
+	{
389
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
390
+		$_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
391
+		$current_date = date('Y-m-d', current_time('timestamp'));
392
+		$time_start = ' 00:00:00';
393
+		$time_end = ' 23:59:59';
394
+		$_where['REG_date'] = array(
395
+			'BETWEEN',
396
+			array(
397
+				EEM_Registration::instance()->convert_datetime_for_query(
398
+					'REG_date',
399
+					$current_date . $time_start,
400
+					'Y-m-d H:i:s'
401
+				),
402
+				EEM_Registration::instance()->convert_datetime_for_query(
403
+					'REG_date',
404
+					$current_date . $time_end,
405
+					'Y-m-d H:i:s'
406
+				),
407
+			),
408
+		);
409
+		$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
410
+		return EEM_Registration::instance()->count(array($_where));
411
+	}
412 412
 
413 413
 
414
-    /**
415
-     * column_cb
416
-     *
417
-     * @access public
418
-     * @param \EE_Registration $item
419
-     * @return string
420
-     * @throws EE_Error
421
-     * @throws InvalidArgumentException
422
-     * @throws InvalidDataTypeException
423
-     * @throws InvalidInterfaceException
424
-     * @throws ReflectionException
425
-     */
426
-    public function column_cb($item)
427
-    {
428
-        /** checkbox/lock **/
429
-        $transaction = $item->get_first_related('Transaction');
430
-        $payment_count = $transaction instanceof EE_Transaction
431
-            ? $transaction->count_related('Payment')
432
-            : 0;
433
-        return $payment_count > 0
434
-               || ! EE_Registry::instance()->CAP->current_user_can(
435
-                   'ee_edit_registration',
436
-                   'registration_list_table_checkbox_input',
437
-                   $item->ID()
438
-               )
439
-            ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID())
440
-              . '<span class="ee-lock-icon"></span>'
441
-            : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID());
442
-    }
414
+	/**
415
+	 * column_cb
416
+	 *
417
+	 * @access public
418
+	 * @param \EE_Registration $item
419
+	 * @return string
420
+	 * @throws EE_Error
421
+	 * @throws InvalidArgumentException
422
+	 * @throws InvalidDataTypeException
423
+	 * @throws InvalidInterfaceException
424
+	 * @throws ReflectionException
425
+	 */
426
+	public function column_cb($item)
427
+	{
428
+		/** checkbox/lock **/
429
+		$transaction = $item->get_first_related('Transaction');
430
+		$payment_count = $transaction instanceof EE_Transaction
431
+			? $transaction->count_related('Payment')
432
+			: 0;
433
+		return $payment_count > 0
434
+			   || ! EE_Registry::instance()->CAP->current_user_can(
435
+				   'ee_edit_registration',
436
+				   'registration_list_table_checkbox_input',
437
+				   $item->ID()
438
+			   )
439
+			? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID())
440
+			  . '<span class="ee-lock-icon"></span>'
441
+			: sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID());
442
+	}
443 443
 
444 444
 
445
-    /**
446
-     * column__REG_ID
447
-     *
448
-     * @access public
449
-     * @param \EE_Registration $item
450
-     * @return string
451
-     * @throws EE_Error
452
-     * @throws InvalidArgumentException
453
-     * @throws InvalidDataTypeException
454
-     * @throws InvalidInterfaceException
455
-     * @throws ReflectionException
456
-     */
457
-    public function column__REG_ID(EE_Registration $item)
458
-    {
459
-        $attendee = $item->attendee();
460
-        $content = $item->ID();
461
-        $content .= '<div class="show-on-mobile-view-only">';
462
-        $content .= '<br>';
463
-        $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
464
-        $content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
465
-        $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
466
-        $content .= '</div>';
467
-        return $content;
468
-    }
445
+	/**
446
+	 * column__REG_ID
447
+	 *
448
+	 * @access public
449
+	 * @param \EE_Registration $item
450
+	 * @return string
451
+	 * @throws EE_Error
452
+	 * @throws InvalidArgumentException
453
+	 * @throws InvalidDataTypeException
454
+	 * @throws InvalidInterfaceException
455
+	 * @throws ReflectionException
456
+	 */
457
+	public function column__REG_ID(EE_Registration $item)
458
+	{
459
+		$attendee = $item->attendee();
460
+		$content = $item->ID();
461
+		$content .= '<div class="show-on-mobile-view-only">';
462
+		$content .= '<br>';
463
+		$content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
464
+		$content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
465
+		$content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
466
+		$content .= '</div>';
467
+		return $content;
468
+	}
469 469
 
470 470
 
471
-    /**
472
-     * column__REG_date
473
-     *
474
-     * @access public
475
-     * @param \EE_Registration $item
476
-     * @return string
477
-     * @throws EE_Error
478
-     * @throws InvalidArgumentException
479
-     * @throws InvalidDataTypeException
480
-     * @throws InvalidInterfaceException
481
-     * @throws ReflectionException
482
-     */
483
-    public function column__REG_date(EE_Registration $item)
484
-    {
485
-        $this->_set_related_details($item);
486
-        //Build row actions
487
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
488
-            'action' => 'view_transaction',
489
-            'TXN_ID' => $this->_transaction_details['id'],
490
-        ), TXN_ADMIN_URL);
491
-        $view_link = EE_Registry::instance()->CAP->current_user_can(
492
-            'ee_read_transaction',
493
-            'espresso_transactions_view_transaction'
494
-        )
495
-            ? '<a class="ee-status-color-'
496
-                . $this->_transaction_details['status']
497
-                . '" href="'
498
-                . $view_lnk_url
499
-                . '" title="'
500
-                . esc_attr($this->_transaction_details['title_attr'])
501
-                . '">'
502
-                . $item->get_i18n_datetime('REG_date')
503
-                . '</a>' : $item->get_i18n_datetime('REG_date');
504
-        $view_link .= '<br><span class="ee-status-text-small">'
505
-                      . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
506
-                      . '</span>';
507
-        return $view_link;
508
-    }
471
+	/**
472
+	 * column__REG_date
473
+	 *
474
+	 * @access public
475
+	 * @param \EE_Registration $item
476
+	 * @return string
477
+	 * @throws EE_Error
478
+	 * @throws InvalidArgumentException
479
+	 * @throws InvalidDataTypeException
480
+	 * @throws InvalidInterfaceException
481
+	 * @throws ReflectionException
482
+	 */
483
+	public function column__REG_date(EE_Registration $item)
484
+	{
485
+		$this->_set_related_details($item);
486
+		//Build row actions
487
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
488
+			'action' => 'view_transaction',
489
+			'TXN_ID' => $this->_transaction_details['id'],
490
+		), TXN_ADMIN_URL);
491
+		$view_link = EE_Registry::instance()->CAP->current_user_can(
492
+			'ee_read_transaction',
493
+			'espresso_transactions_view_transaction'
494
+		)
495
+			? '<a class="ee-status-color-'
496
+				. $this->_transaction_details['status']
497
+				. '" href="'
498
+				. $view_lnk_url
499
+				. '" title="'
500
+				. esc_attr($this->_transaction_details['title_attr'])
501
+				. '">'
502
+				. $item->get_i18n_datetime('REG_date')
503
+				. '</a>' : $item->get_i18n_datetime('REG_date');
504
+		$view_link .= '<br><span class="ee-status-text-small">'
505
+					  . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
506
+					  . '</span>';
507
+		return $view_link;
508
+	}
509 509
 
510 510
 
511
-    /**
512
-     * column_event_name
513
-     *
514
-     * @access public
515
-     * @param \EE_Registration $item
516
-     * @return string
517
-     * @throws EE_Error
518
-     * @throws InvalidArgumentException
519
-     * @throws InvalidDataTypeException
520
-     * @throws InvalidInterfaceException
521
-     * @throws ReflectionException
522
-     */
523
-    public function column_event_name(EE_Registration $item)
524
-    {
525
-        $this->_set_related_details($item);
526
-        // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
527
-        $EVT_ID = $item->event_ID();
528
-        $event_name = $item->event_name();
529
-        $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso');
530
-        $event_name = wp_trim_words($event_name, 30, '...');
531
-        if ($EVT_ID) {
532
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
533
-                array('action' => 'edit', 'post' => $EVT_ID),
534
-                EVENTS_ADMIN_URL
535
-            );
536
-            $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
537
-                ? '<a class="ee-status-color-'
538
-                  . $this->_event_details['status']
539
-                  . '" href="'
540
-                  . $edit_event_url
541
-                  . '" title="'
542
-                  . esc_attr($this->_event_details['title_attr'])
543
-                  . '">'
544
-                  . $event_name
545
-                  . '</a>' : $event_name;
546
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
547
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
548
-            $actions['event_filter'] .= sprintf(
549
-                esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
550
-                $event_name
551
-            );
552
-            $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
553
-        } else {
554
-            $edit_event = $event_name;
555
-            $actions['event_filter'] = '';
556
-        }
557
-        return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
558
-    }
511
+	/**
512
+	 * column_event_name
513
+	 *
514
+	 * @access public
515
+	 * @param \EE_Registration $item
516
+	 * @return string
517
+	 * @throws EE_Error
518
+	 * @throws InvalidArgumentException
519
+	 * @throws InvalidDataTypeException
520
+	 * @throws InvalidInterfaceException
521
+	 * @throws ReflectionException
522
+	 */
523
+	public function column_event_name(EE_Registration $item)
524
+	{
525
+		$this->_set_related_details($item);
526
+		// page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
527
+		$EVT_ID = $item->event_ID();
528
+		$event_name = $item->event_name();
529
+		$event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso');
530
+		$event_name = wp_trim_words($event_name, 30, '...');
531
+		if ($EVT_ID) {
532
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
533
+				array('action' => 'edit', 'post' => $EVT_ID),
534
+				EVENTS_ADMIN_URL
535
+			);
536
+			$edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
537
+				? '<a class="ee-status-color-'
538
+				  . $this->_event_details['status']
539
+				  . '" href="'
540
+				  . $edit_event_url
541
+				  . '" title="'
542
+				  . esc_attr($this->_event_details['title_attr'])
543
+				  . '">'
544
+				  . $event_name
545
+				  . '</a>' : $event_name;
546
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
547
+			$actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
548
+			$actions['event_filter'] .= sprintf(
549
+				esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
550
+				$event_name
551
+			);
552
+			$actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
553
+		} else {
554
+			$edit_event = $event_name;
555
+			$actions['event_filter'] = '';
556
+		}
557
+		return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
558
+	}
559 559
 
560 560
 
561
-    /**
562
-     * column_DTT_EVT_start
563
-     *
564
-     * @access public
565
-     * @param \EE_Registration $item
566
-     * @return string
567
-     * @throws EE_Error
568
-     * @throws InvalidArgumentException
569
-     * @throws InvalidDataTypeException
570
-     * @throws InvalidInterfaceException
571
-     * @throws ReflectionException
572
-     */
573
-    public function column_DTT_EVT_start(EE_Registration $item)
574
-    {
575
-        $datetime_strings = array();
576
-        $ticket = $item->ticket(true);
577
-        if ($ticket instanceof EE_Ticket) {
578
-            $remove_defaults = array('default_where_conditions' => 'none');
579
-            $datetimes = $ticket->datetimes($remove_defaults);
580
-            foreach ($datetimes as $datetime) {
581
-                $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
582
-            }
583
-            return $this->generateDisplayForDatetimes($datetime_strings);
584
-        }
585
-        return __('There is no ticket on this registration', 'event_espresso');
586
-    }
561
+	/**
562
+	 * column_DTT_EVT_start
563
+	 *
564
+	 * @access public
565
+	 * @param \EE_Registration $item
566
+	 * @return string
567
+	 * @throws EE_Error
568
+	 * @throws InvalidArgumentException
569
+	 * @throws InvalidDataTypeException
570
+	 * @throws InvalidInterfaceException
571
+	 * @throws ReflectionException
572
+	 */
573
+	public function column_DTT_EVT_start(EE_Registration $item)
574
+	{
575
+		$datetime_strings = array();
576
+		$ticket = $item->ticket(true);
577
+		if ($ticket instanceof EE_Ticket) {
578
+			$remove_defaults = array('default_where_conditions' => 'none');
579
+			$datetimes = $ticket->datetimes($remove_defaults);
580
+			foreach ($datetimes as $datetime) {
581
+				$datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
582
+			}
583
+			return $this->generateDisplayForDatetimes($datetime_strings);
584
+		}
585
+		return __('There is no ticket on this registration', 'event_espresso');
586
+	}
587 587
 
588 588
 
589
-    /**
590
-     * Receives an array of datetime strings to display and converts them to the html container for the column.
591
-     *
592
-     * @param array $datetime_strings
593
-     * @return string
594
-     */
595
-    public function generateDisplayForDateTimes(array $datetime_strings)
596
-    {
597
-        $content = '<div class="ee-registration-event-datetimes-container">';
598
-        $expand_toggle = count($datetime_strings) > 1
599
-            ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
600
-              . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
601
-            : '';
602
-        //get first item for initial visibility
603
-        $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
604
-        $content .= $expand_toggle;
605
-        if ($datetime_strings) {
606
-            $content .= '<div style="clear:both"></div>';
607
-            $content .= '<div class="ee-registration-event-datetimes-container more-items hidden">';
608
-            $content .= implode("<br />", $datetime_strings);
609
-            $content .= '</div>';
610
-        }
611
-        $content .= '</div>';
612
-        return $content;
613
-    }
589
+	/**
590
+	 * Receives an array of datetime strings to display and converts them to the html container for the column.
591
+	 *
592
+	 * @param array $datetime_strings
593
+	 * @return string
594
+	 */
595
+	public function generateDisplayForDateTimes(array $datetime_strings)
596
+	{
597
+		$content = '<div class="ee-registration-event-datetimes-container">';
598
+		$expand_toggle = count($datetime_strings) > 1
599
+			? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
600
+			  . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
601
+			: '';
602
+		//get first item for initial visibility
603
+		$content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
604
+		$content .= $expand_toggle;
605
+		if ($datetime_strings) {
606
+			$content .= '<div style="clear:both"></div>';
607
+			$content .= '<div class="ee-registration-event-datetimes-container more-items hidden">';
608
+			$content .= implode("<br />", $datetime_strings);
609
+			$content .= '</div>';
610
+		}
611
+		$content .= '</div>';
612
+		return $content;
613
+	}
614 614
 
615 615
 
616
-    /**
617
-     * column_ATT_fname
618
-     *
619
-     * @access public
620
-     * @param \EE_Registration $item
621
-     * @return string
622
-     * @throws EE_Error
623
-     * @throws InvalidArgumentException
624
-     * @throws InvalidDataTypeException
625
-     * @throws InvalidInterfaceException
626
-     * @throws ReflectionException
627
-     */
628
-    public function column_ATT_fname(EE_Registration $item)
629
-    {
630
-        $attendee = $item->attendee();
631
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
632
-            'action'  => 'view_registration',
633
-            '_REG_ID' => $item->ID(),
634
-        ), REG_ADMIN_URL);
635
-        $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
636
-        $link = EE_Registry::instance()->CAP->current_user_can(
637
-            'ee_read_registration',
638
-            'espresso_registrations_view_registration',
639
-            $item->ID()
640
-        )
641
-            ? '<a href="'
642
-               . $edit_lnk_url
643
-               . '" title="'
644
-               . esc_attr__('View Registration Details', 'event_espresso')
645
-               . '">'
646
-               . $attendee_name
647
-               . '</a>' : $attendee_name;
648
-        $link .= $item->count() === 1
649
-            ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : '';
650
-        $t = $item->get_first_related('Transaction');
651
-        $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
652
-        //append group count to name
653
-        $link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
654
-        //append reg_code
655
-        $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
656
-        //reg status text for accessibility
657
-        $link .= '<br><span class="ee-status-text-small">'
658
-                 . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
659
-                 . '</span>';
660
-        //trash/restore/delete actions
661
-        $actions = array();
662
-        if ($this->_view !== 'trash'
663
-            && $payment_count === 0
664
-            && EE_Registry::instance()->CAP->current_user_can(
665
-                'ee_delete_registration',
666
-                'espresso_registrations_trash_registrations',
667
-                $item->ID()
668
-            )) {
669
-            $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
670
-                'action'  => 'trash_registrations',
671
-                '_REG_ID' => $item->ID(),
672
-            ), REG_ADMIN_URL);
673
-            $actions['trash'] = '<a href="'
674
-                                . $trash_lnk_url
675
-                                . '" title="'
676
-                                . esc_attr__('Trash Registration', 'event_espresso')
677
-                                . '">' . __('Trash', 'event_espresso') . '</a>';
678
-        } elseif ($this->_view === 'trash') {
679
-            // restore registration link
680
-            if (EE_Registry::instance()->CAP->current_user_can(
681
-                'ee_delete_registration',
682
-                'espresso_registrations_restore_registrations',
683
-                $item->ID()
684
-            )) {
685
-                $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
686
-                    'action'  => 'restore_registrations',
687
-                    '_REG_ID' => $item->ID(),
688
-                ), REG_ADMIN_URL);
689
-                $actions['restore'] = '<a href="'
690
-                                      . $restore_lnk_url
691
-                                      . '" title="'
692
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
693
-                                      . __('Restore', 'event_espresso') . '</a>';
694
-            }
695
-            if (EE_Registry::instance()->CAP->current_user_can(
696
-                'ee_delete_registration',
697
-                'espresso_registrations_ee_delete_registrations',
698
-                $item->ID()
699
-            )) {
700
-                $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
701
-                    'action'  => 'delete_registrations',
702
-                    '_REG_ID' => $item->ID(),
703
-                ), REG_ADMIN_URL);
704
-                $actions['delete'] = '<a href="'
705
-                                     . $delete_lnk_url
706
-                                     . '" title="'
707
-                                     . esc_attr__('Delete Registration Permanently', 'event_espresso')
708
-                                     . '">'
709
-                                     . __('Delete', 'event_espresso')
710
-                                     . '</a>';
711
-            }
712
-        }
713
-        return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
714
-    }
616
+	/**
617
+	 * column_ATT_fname
618
+	 *
619
+	 * @access public
620
+	 * @param \EE_Registration $item
621
+	 * @return string
622
+	 * @throws EE_Error
623
+	 * @throws InvalidArgumentException
624
+	 * @throws InvalidDataTypeException
625
+	 * @throws InvalidInterfaceException
626
+	 * @throws ReflectionException
627
+	 */
628
+	public function column_ATT_fname(EE_Registration $item)
629
+	{
630
+		$attendee = $item->attendee();
631
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
632
+			'action'  => 'view_registration',
633
+			'_REG_ID' => $item->ID(),
634
+		), REG_ADMIN_URL);
635
+		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
636
+		$link = EE_Registry::instance()->CAP->current_user_can(
637
+			'ee_read_registration',
638
+			'espresso_registrations_view_registration',
639
+			$item->ID()
640
+		)
641
+			? '<a href="'
642
+			   . $edit_lnk_url
643
+			   . '" title="'
644
+			   . esc_attr__('View Registration Details', 'event_espresso')
645
+			   . '">'
646
+			   . $attendee_name
647
+			   . '</a>' : $attendee_name;
648
+		$link .= $item->count() === 1
649
+			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : '';
650
+		$t = $item->get_first_related('Transaction');
651
+		$payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
652
+		//append group count to name
653
+		$link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
654
+		//append reg_code
655
+		$link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
656
+		//reg status text for accessibility
657
+		$link .= '<br><span class="ee-status-text-small">'
658
+				 . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
659
+				 . '</span>';
660
+		//trash/restore/delete actions
661
+		$actions = array();
662
+		if ($this->_view !== 'trash'
663
+			&& $payment_count === 0
664
+			&& EE_Registry::instance()->CAP->current_user_can(
665
+				'ee_delete_registration',
666
+				'espresso_registrations_trash_registrations',
667
+				$item->ID()
668
+			)) {
669
+			$trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
670
+				'action'  => 'trash_registrations',
671
+				'_REG_ID' => $item->ID(),
672
+			), REG_ADMIN_URL);
673
+			$actions['trash'] = '<a href="'
674
+								. $trash_lnk_url
675
+								. '" title="'
676
+								. esc_attr__('Trash Registration', 'event_espresso')
677
+								. '">' . __('Trash', 'event_espresso') . '</a>';
678
+		} elseif ($this->_view === 'trash') {
679
+			// restore registration link
680
+			if (EE_Registry::instance()->CAP->current_user_can(
681
+				'ee_delete_registration',
682
+				'espresso_registrations_restore_registrations',
683
+				$item->ID()
684
+			)) {
685
+				$restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
686
+					'action'  => 'restore_registrations',
687
+					'_REG_ID' => $item->ID(),
688
+				), REG_ADMIN_URL);
689
+				$actions['restore'] = '<a href="'
690
+									  . $restore_lnk_url
691
+									  . '" title="'
692
+									  . esc_attr__('Restore Registration', 'event_espresso') . '">'
693
+									  . __('Restore', 'event_espresso') . '</a>';
694
+			}
695
+			if (EE_Registry::instance()->CAP->current_user_can(
696
+				'ee_delete_registration',
697
+				'espresso_registrations_ee_delete_registrations',
698
+				$item->ID()
699
+			)) {
700
+				$delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
701
+					'action'  => 'delete_registrations',
702
+					'_REG_ID' => $item->ID(),
703
+				), REG_ADMIN_URL);
704
+				$actions['delete'] = '<a href="'
705
+									 . $delete_lnk_url
706
+									 . '" title="'
707
+									 . esc_attr__('Delete Registration Permanently', 'event_espresso')
708
+									 . '">'
709
+									 . __('Delete', 'event_espresso')
710
+									 . '</a>';
711
+			}
712
+		}
713
+		return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
714
+	}
715 715
 
716 716
 
717
-    /**
718
-     * column_ATT_email
719
-     *
720
-     * @access public
721
-     * @param \EE_Registration $item
722
-     * @return string
723
-     * @throws EE_Error
724
-     * @throws InvalidArgumentException
725
-     * @throws InvalidDataTypeException
726
-     * @throws InvalidInterfaceException
727
-     * @throws ReflectionException
728
-     */
729
-    public function column_ATT_email(EE_Registration $item)
730
-    {
731
-        $attendee = $item->get_first_related('Attendee');
732
-        return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso')
733
-            : $attendee->email();
734
-    }
717
+	/**
718
+	 * column_ATT_email
719
+	 *
720
+	 * @access public
721
+	 * @param \EE_Registration $item
722
+	 * @return string
723
+	 * @throws EE_Error
724
+	 * @throws InvalidArgumentException
725
+	 * @throws InvalidDataTypeException
726
+	 * @throws InvalidInterfaceException
727
+	 * @throws ReflectionException
728
+	 */
729
+	public function column_ATT_email(EE_Registration $item)
730
+	{
731
+		$attendee = $item->get_first_related('Attendee');
732
+		return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso')
733
+			: $attendee->email();
734
+	}
735 735
 
736 736
 
737
-    /**
738
-     * column__REG_count
739
-     *
740
-     * @access public
741
-     * @param \EE_Registration $item
742
-     * @return string
743
-     */
744
-    public function column__REG_count(EE_Registration $item)
745
-    {
746
-        return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
747
-    }
737
+	/**
738
+	 * column__REG_count
739
+	 *
740
+	 * @access public
741
+	 * @param \EE_Registration $item
742
+	 * @return string
743
+	 */
744
+	public function column__REG_count(EE_Registration $item)
745
+	{
746
+		return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
747
+	}
748 748
 
749 749
 
750
-    /**
751
-     * column_PRC_amount
752
-     *
753
-     * @access public
754
-     * @param \EE_Registration $item
755
-     * @return string
756
-     * @throws EE_Error
757
-     */
758
-    public function column_PRC_amount(EE_Registration $item)
759
-    {
760
-        $ticket = $item->ticket();
761
-        $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">'
762
-                                                                              . $ticket->name()
763
-                                                                              . '</span><br />' : '';
764
-        if ($item->final_price() > 0) {
765
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
766
-        } else {
767
-            // free event
768
-            $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
769
-                        . __('free', 'event_espresso')
770
-                        . '</span>';
771
-        }
772
-        return $content;
773
-    }
750
+	/**
751
+	 * column_PRC_amount
752
+	 *
753
+	 * @access public
754
+	 * @param \EE_Registration $item
755
+	 * @return string
756
+	 * @throws EE_Error
757
+	 */
758
+	public function column_PRC_amount(EE_Registration $item)
759
+	{
760
+		$ticket = $item->ticket();
761
+		$content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">'
762
+																			  . $ticket->name()
763
+																			  . '</span><br />' : '';
764
+		if ($item->final_price() > 0) {
765
+			$content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
766
+		} else {
767
+			// free event
768
+			$content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
769
+						. __('free', 'event_espresso')
770
+						. '</span>';
771
+		}
772
+		return $content;
773
+	}
774 774
 
775 775
 
776
-    /**
777
-     * column__REG_final_price
778
-     *
779
-     * @access public
780
-     * @param \EE_Registration $item
781
-     * @return string
782
-     * @throws EE_Error
783
-     */
784
-    public function column__REG_final_price(EE_Registration $item)
785
-    {
786
-        $ticket = $item->ticket();
787
-        $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket
788
-            ? ''
789
-            : '<span class="TKT_name">'
790
-              . $ticket->name()
791
-              . '</span><br />';
792
-        $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
793
-        return $content;
794
-    }
776
+	/**
777
+	 * column__REG_final_price
778
+	 *
779
+	 * @access public
780
+	 * @param \EE_Registration $item
781
+	 * @return string
782
+	 * @throws EE_Error
783
+	 */
784
+	public function column__REG_final_price(EE_Registration $item)
785
+	{
786
+		$ticket = $item->ticket();
787
+		$content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket
788
+			? ''
789
+			: '<span class="TKT_name">'
790
+			  . $ticket->name()
791
+			  . '</span><br />';
792
+		$content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
793
+		return $content;
794
+	}
795 795
 
796 796
 
797
-    /**
798
-     * column__REG_paid
799
-     *
800
-     * @access public
801
-     * @param \EE_Registration $item
802
-     * @return string
803
-     * @throws EE_Error
804
-     */
805
-    public function column__REG_paid(EE_Registration $item)
806
-    {
807
-        $payment_method = $item->payment_method();
808
-        $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
809
-            : __('Unknown', 'event_espresso');
810
-        $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
811
-        if ($item->paid() > 0) {
812
-            $content .= '<br><span class="ee-status-text-small">'
813
-                        . sprintf(
814
-                            __('...via %s', 'event_espresso'),
815
-                            $payment_method_name
816
-                        )
817
-                        . '</span>';
818
-        }
819
-        return $content;
820
-    }
797
+	/**
798
+	 * column__REG_paid
799
+	 *
800
+	 * @access public
801
+	 * @param \EE_Registration $item
802
+	 * @return string
803
+	 * @throws EE_Error
804
+	 */
805
+	public function column__REG_paid(EE_Registration $item)
806
+	{
807
+		$payment_method = $item->payment_method();
808
+		$payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
809
+			: __('Unknown', 'event_espresso');
810
+		$content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
811
+		if ($item->paid() > 0) {
812
+			$content .= '<br><span class="ee-status-text-small">'
813
+						. sprintf(
814
+							__('...via %s', 'event_espresso'),
815
+							$payment_method_name
816
+						)
817
+						. '</span>';
818
+		}
819
+		return $content;
820
+	}
821 821
 
822 822
 
823
-    /**
824
-     * column_TXN_total
825
-     *
826
-     * @access public
827
-     * @param \EE_Registration $item
828
-     * @return string
829
-     * @throws EE_Error
830
-     * @throws EntityNotFoundException
831
-     * @throws InvalidArgumentException
832
-     * @throws InvalidDataTypeException
833
-     * @throws InvalidInterfaceException
834
-     */
835
-    public function column_TXN_total(EE_Registration $item)
836
-    {
837
-        if ($item->transaction()) {
838
-            $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
839
-                'action' => 'view_transaction',
840
-                'TXN_ID' => $item->transaction_ID(),
841
-            ), TXN_ADMIN_URL);
842
-            return EE_Registry::instance()->CAP->current_user_can(
843
-                'ee_read_transaction',
844
-                'espresso_transactions_view_transaction',
845
-                $item->transaction_ID()
846
-            )
847
-                ? '<span class="reg-pad-rght"><a class="status-'
848
-                  . $item->transaction()->status_ID()
849
-                  . '" href="'
850
-                  . $view_txn_lnk_url
851
-                  . '"  title="'
852
-                  . esc_attr__('View Transaction', 'event_espresso')
853
-                  . '">'
854
-                  . $item->transaction()->pretty_total()
855
-                  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
856
-        } else {
857
-            return __("None", "event_espresso");
858
-        }
859
-    }
823
+	/**
824
+	 * column_TXN_total
825
+	 *
826
+	 * @access public
827
+	 * @param \EE_Registration $item
828
+	 * @return string
829
+	 * @throws EE_Error
830
+	 * @throws EntityNotFoundException
831
+	 * @throws InvalidArgumentException
832
+	 * @throws InvalidDataTypeException
833
+	 * @throws InvalidInterfaceException
834
+	 */
835
+	public function column_TXN_total(EE_Registration $item)
836
+	{
837
+		if ($item->transaction()) {
838
+			$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
839
+				'action' => 'view_transaction',
840
+				'TXN_ID' => $item->transaction_ID(),
841
+			), TXN_ADMIN_URL);
842
+			return EE_Registry::instance()->CAP->current_user_can(
843
+				'ee_read_transaction',
844
+				'espresso_transactions_view_transaction',
845
+				$item->transaction_ID()
846
+			)
847
+				? '<span class="reg-pad-rght"><a class="status-'
848
+				  . $item->transaction()->status_ID()
849
+				  . '" href="'
850
+				  . $view_txn_lnk_url
851
+				  . '"  title="'
852
+				  . esc_attr__('View Transaction', 'event_espresso')
853
+				  . '">'
854
+				  . $item->transaction()->pretty_total()
855
+				  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
856
+		} else {
857
+			return __("None", "event_espresso");
858
+		}
859
+	}
860 860
 
861 861
 
862
-    /**
863
-     * column_TXN_paid
864
-     *
865
-     * @access public
866
-     * @param \EE_Registration $item
867
-     * @return string
868
-     * @throws EE_Error
869
-     * @throws EntityNotFoundException
870
-     * @throws InvalidArgumentException
871
-     * @throws InvalidDataTypeException
872
-     * @throws InvalidInterfaceException
873
-     */
874
-    public function column_TXN_paid(EE_Registration $item)
875
-    {
876
-        if ($item->count() === 1) {
877
-            $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance();
878
-            if ($transaction->paid() >= $transaction->total()) {
879
-                return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
880
-            } else {
881
-                $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
882
-                    'action' => 'view_transaction',
883
-                    'TXN_ID' => $item->transaction_ID(),
884
-                ), TXN_ADMIN_URL);
885
-                return EE_Registry::instance()->CAP->current_user_can(
886
-                    'ee_read_transaction',
887
-                    'espresso_transactions_view_transaction',
888
-                    $item->transaction_ID()
889
-                )
890
-                    ? '<span class="reg-pad-rght"><a class="status-'
891
-                      . $transaction->status_ID()
892
-                      . '" href="'
893
-                      . $view_txn_lnk_url
894
-                      . '"  title="'
895
-                      . esc_attr__('View Transaction', 'event_espresso')
896
-                      . '">'
897
-                      . $item->transaction()->pretty_paid()
898
-                      . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
899
-            }
900
-        }
901
-        return '&nbsp;';
902
-    }
862
+	/**
863
+	 * column_TXN_paid
864
+	 *
865
+	 * @access public
866
+	 * @param \EE_Registration $item
867
+	 * @return string
868
+	 * @throws EE_Error
869
+	 * @throws EntityNotFoundException
870
+	 * @throws InvalidArgumentException
871
+	 * @throws InvalidDataTypeException
872
+	 * @throws InvalidInterfaceException
873
+	 */
874
+	public function column_TXN_paid(EE_Registration $item)
875
+	{
876
+		if ($item->count() === 1) {
877
+			$transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance();
878
+			if ($transaction->paid() >= $transaction->total()) {
879
+				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
880
+			} else {
881
+				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
882
+					'action' => 'view_transaction',
883
+					'TXN_ID' => $item->transaction_ID(),
884
+				), TXN_ADMIN_URL);
885
+				return EE_Registry::instance()->CAP->current_user_can(
886
+					'ee_read_transaction',
887
+					'espresso_transactions_view_transaction',
888
+					$item->transaction_ID()
889
+				)
890
+					? '<span class="reg-pad-rght"><a class="status-'
891
+					  . $transaction->status_ID()
892
+					  . '" href="'
893
+					  . $view_txn_lnk_url
894
+					  . '"  title="'
895
+					  . esc_attr__('View Transaction', 'event_espresso')
896
+					  . '">'
897
+					  . $item->transaction()->pretty_paid()
898
+					  . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
899
+			}
900
+		}
901
+		return '&nbsp;';
902
+	}
903 903
 
904 904
 
905
-    /**
906
-     * column_actions
907
-     *
908
-     * @access public
909
-     * @param \EE_Registration $item
910
-     * @return string
911
-     * @throws EE_Error
912
-     * @throws InvalidArgumentException
913
-     * @throws InvalidDataTypeException
914
-     * @throws InvalidInterfaceException
915
-     * @throws ReflectionException
916
-     */
917
-    public function column_actions(EE_Registration $item)
918
-    {
919
-        $actions = array();
920
-        $attendee = $item->attendee();
921
-        $this->_set_related_details($item);
922
-        //Build row actions
923
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
924
-            'action'  => 'view_registration',
925
-            '_REG_ID' => $item->ID(),
926
-        ), REG_ADMIN_URL);
927
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
928
-            'action' => 'edit_attendee',
929
-            'post'   => $item->attendee_ID(),
930
-        ), REG_ADMIN_URL);
931
-        // page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
932
-        //$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
933
-        $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
934
-            'action'  => 'resend_registration',
935
-            '_REG_ID' => $item->ID(),
936
-        ), REG_ADMIN_URL, true);
937
-        //Build row actions
938
-        $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can(
939
-            'ee_read_registration',
940
-            'espresso_registrations_view_registration',
941
-            $item->ID()
942
-        ) ? '<li><a href="'
943
-            . $view_lnk_url
944
-            . '" title="'
945
-            . esc_attr__('View Registration Details', 'event_espresso')
946
-            . '" class="tiny-text">
905
+	/**
906
+	 * column_actions
907
+	 *
908
+	 * @access public
909
+	 * @param \EE_Registration $item
910
+	 * @return string
911
+	 * @throws EE_Error
912
+	 * @throws InvalidArgumentException
913
+	 * @throws InvalidDataTypeException
914
+	 * @throws InvalidInterfaceException
915
+	 * @throws ReflectionException
916
+	 */
917
+	public function column_actions(EE_Registration $item)
918
+	{
919
+		$actions = array();
920
+		$attendee = $item->attendee();
921
+		$this->_set_related_details($item);
922
+		//Build row actions
923
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
924
+			'action'  => 'view_registration',
925
+			'_REG_ID' => $item->ID(),
926
+		), REG_ADMIN_URL);
927
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
928
+			'action' => 'edit_attendee',
929
+			'post'   => $item->attendee_ID(),
930
+		), REG_ADMIN_URL);
931
+		// page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
932
+		//$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
933
+		$resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
934
+			'action'  => 'resend_registration',
935
+			'_REG_ID' => $item->ID(),
936
+		), REG_ADMIN_URL, true);
937
+		//Build row actions
938
+		$actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can(
939
+			'ee_read_registration',
940
+			'espresso_registrations_view_registration',
941
+			$item->ID()
942
+		) ? '<li><a href="'
943
+			. $view_lnk_url
944
+			. '" title="'
945
+			. esc_attr__('View Registration Details', 'event_espresso')
946
+			. '" class="tiny-text">
947 947
 				<div class="dashicons dashicons-clipboard"></div>
948 948
 			</a>
949 949
 			</li>'
950
-            : '';
951
-        $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can(
952
-            'ee_edit_contacts',
953
-            'espresso_registrations_edit_attendee'
954
-        )
955
-                               && $attendee instanceof EE_Attendee
956
-            ? '
950
+			: '';
951
+		$actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can(
952
+			'ee_edit_contacts',
953
+			'espresso_registrations_edit_attendee'
954
+		)
955
+							   && $attendee instanceof EE_Attendee
956
+			? '
957 957
 			<li>
958 958
 			<a href="' . $edit_lnk_url . '" title="'
959
-              . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
959
+			  . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
960 960
 				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
961 961
 			</a>
962 962
 			</li>' : '';
963
-        $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee
964
-                                     && EE_Registry::instance()->CAP->current_user_can(
965
-                                         'ee_send_message',
966
-                                         'espresso_registrations_resend_registration',
967
-                                         $item->ID()
968
-        )
969
-            ? '
963
+		$actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee
964
+									 && EE_Registry::instance()->CAP->current_user_can(
965
+										 'ee_send_message',
966
+										 'espresso_registrations_resend_registration',
967
+										 $item->ID()
968
+		)
969
+			? '
970 970
 			<li>
971 971
 			<a href="'
972
-                 . $resend_reg_lnk_url
973
-                 . '" title="'
974
-                 . esc_attr__('Resend Registration Details', 'event_espresso')
975
-                 . '" class="tiny-text">
972
+				 . $resend_reg_lnk_url
973
+				 . '" title="'
974
+				 . esc_attr__('Resend Registration Details', 'event_espresso')
975
+				 . '" class="tiny-text">
976 976
 				<div class="dashicons dashicons-email-alt"></div>
977 977
 			</a>
978 978
 			</li>' : '';
979
-        // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
980
-        $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
981
-            'action' => 'view_transaction',
982
-            'TXN_ID' => $this->_transaction_details['id'],
983
-        ), TXN_ADMIN_URL);
984
-        $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can(
985
-            'ee_read_transaction',
986
-            'espresso_transactions_view_transaction',
987
-            $this->_transaction_details['id']
988
-        )
989
-            ? '
979
+		// page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
980
+		$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
981
+			'action' => 'view_transaction',
982
+			'TXN_ID' => $this->_transaction_details['id'],
983
+		), TXN_ADMIN_URL);
984
+		$actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can(
985
+			'ee_read_transaction',
986
+			'espresso_transactions_view_transaction',
987
+			$this->_transaction_details['id']
988
+		)
989
+			? '
990 990
 			<li>
991 991
 			<a class="ee-status-color-'
992
-               . $this->_transaction_details['status']
993
-               . ' tiny-text" href="'
994
-               . $view_txn_lnk_url
995
-               . '"  title="'
996
-               . $this->_transaction_details['title_attr']
997
-               . '">
992
+			   . $this->_transaction_details['status']
993
+			   . ' tiny-text" href="'
994
+			   . $view_txn_lnk_url
995
+			   . '"  title="'
996
+			   . $this->_transaction_details['title_attr']
997
+			   . '">
998 998
 				<div class="dashicons dashicons-cart"></div>
999 999
 			</a>
1000 1000
 			</li>' : '';
1001
-        //invoice link
1002
-        $actions['dl_invoice_lnk'] = '';
1003
-        $dl_invoice_lnk_url = $item->invoice_url();
1004
-        //only show invoice link if message type is active.
1005
-        if ($attendee instanceof EE_Attendee
1006
-            && $item->is_primary_registrant()
1007
-            && EEH_MSG_Template::is_mt_active('invoice')
1008
-        ) {
1009
-            $actions['dl_invoice_lnk'] = '
1001
+		//invoice link
1002
+		$actions['dl_invoice_lnk'] = '';
1003
+		$dl_invoice_lnk_url = $item->invoice_url();
1004
+		//only show invoice link if message type is active.
1005
+		if ($attendee instanceof EE_Attendee
1006
+			&& $item->is_primary_registrant()
1007
+			&& EEH_MSG_Template::is_mt_active('invoice')
1008
+		) {
1009
+			$actions['dl_invoice_lnk'] = '
1010 1010
 		<li>
1011 1011
 			<a title="'
1012
-                 . esc_attr__('View Transaction Invoice', 'event_espresso')
1013
-                 . '" target="_blank" href="'
1014
-                 . $dl_invoice_lnk_url
1015
-                 . '" class="tiny-text">
1012
+				 . esc_attr__('View Transaction Invoice', 'event_espresso')
1013
+				 . '" target="_blank" href="'
1014
+				 . $dl_invoice_lnk_url
1015
+				 . '" class="tiny-text">
1016 1016
 				<span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
1017 1017
 			</a>
1018 1018
 		</li>';
1019
-        }
1020
-        $actions['filtered_messages_link'] = '';
1021
-        //message list table link (filtered by REG_ID
1022
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
1023
-            $actions['filtered_messages_link'] = '<li>'
1024
-                     . EEH_MSG_Template::get_message_action_link(
1025
-                         'see_notifications_for',
1026
-                         null,
1027
-                         array('_REG_ID' => $item->ID())
1028
-                     ) . '</li>';
1029
-        }
1030
-        $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1031
-        return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
1032
-    }
1019
+		}
1020
+		$actions['filtered_messages_link'] = '';
1021
+		//message list table link (filtered by REG_ID
1022
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
1023
+			$actions['filtered_messages_link'] = '<li>'
1024
+					 . EEH_MSG_Template::get_message_action_link(
1025
+						 'see_notifications_for',
1026
+						 null,
1027
+						 array('_REG_ID' => $item->ID())
1028
+					 ) . '</li>';
1029
+		}
1030
+		$actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1031
+		return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
1032
+	}
1033 1033
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\exceptions\InvalidDataTypeException;
3 3
 use EventEspresso\core\exceptions\InvalidInterfaceException;
4 4
 
5
-if (! defined('EVENT_ESPRESSO_VERSION')) {
5
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
6 6
     exit('No direct script access allowed');
7 7
 }
8 8
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function __construct(Registrations_Admin_Page $admin_page)
59 59
     {
60
-        if (! empty($_GET['event_id'])) {
60
+        if ( ! empty($_GET['event_id'])) {
61 61
             $extra_query_args = array();
62 62
             foreach ($admin_page->get_views() as $key => $view_details) {
63 63
                 $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']);
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
         );
158 158
         $this->_primary_column = '_REG_ID';
159 159
         $this->_sortable_columns = array(
160
-            '_REG_date'     => array('_REG_date' => true),   //true means its already sorted
160
+            '_REG_date'     => array('_REG_date' => true), //true means its already sorted
161 161
             /**
162 162
              * Allows users to change the default sort if they wish.
163 163
              * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
     {
190 190
         $class = parent::_get_row_class($item);
191 191
         //add status class
192
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
192
+        $class .= ' ee-status-strip reg-status-'.$item->status_ID();
193 193
         if ($this->_has_checkbox_column) {
194 194
             $class .= ' has-checkbox-column';
195 195
         }
@@ -354,12 +354,12 @@  discard block
 block discarded – undo
354 354
         //setup date query.
355 355
         $beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
356 356
             'REG_date',
357
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
357
+            $this_year_r.'-'.$this_month_r.'-01'.' '.$time_start,
358 358
             'Y-m-d H:i:s'
359 359
         );
360 360
         $end_string = EEM_Registration::instance()->convert_datetime_for_query(
361 361
             'REG_date',
362
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
362
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' '.$time_end,
363 363
             'Y-m-d H:i:s'
364 364
         );
365 365
         $_where['REG_date'] = array(
@@ -396,12 +396,12 @@  discard block
 block discarded – undo
396 396
             array(
397 397
                 EEM_Registration::instance()->convert_datetime_for_query(
398 398
                     'REG_date',
399
-                    $current_date . $time_start,
399
+                    $current_date.$time_start,
400 400
                     'Y-m-d H:i:s'
401 401
                 ),
402 402
                 EEM_Registration::instance()->convert_datetime_for_query(
403 403
                     'REG_date',
404
-                    $current_date . $time_end,
404
+                    $current_date.$time_end,
405 405
                     'Y-m-d H:i:s'
406 406
                 ),
407 407
             ),
@@ -461,8 +461,8 @@  discard block
 block discarded – undo
461 461
         $content .= '<div class="show-on-mobile-view-only">';
462 462
         $content .= '<br>';
463 463
         $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
464
-        $content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
465
-        $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
464
+        $content .= '&nbsp;'.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
465
+        $content .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
466 466
         $content .= '</div>';
467 467
         return $content;
468 468
     }
@@ -544,12 +544,12 @@  discard block
 block discarded – undo
544 544
                   . $event_name
545 545
                   . '</a>' : $event_name;
546 546
             $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
547
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
547
+            $actions['event_filter'] = '<a href="'.$edit_event_url.'" title="';
548 548
             $actions['event_filter'] .= sprintf(
549 549
                 esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
550 550
                 $event_name
551 551
             );
552
-            $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
552
+            $actions['event_filter'] .= '">'.__('View Registrations', 'event_espresso').'</a>';
553 553
         } else {
554 554
             $edit_event = $event_name;
555 555
             $actions['event_filter'] = '';
@@ -596,11 +596,11 @@  discard block
 block discarded – undo
596 596
     {
597 597
         $content = '<div class="ee-registration-event-datetimes-container">';
598 598
         $expand_toggle = count($datetime_strings) > 1
599
-            ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
599
+            ? ' <span title="'.esc_attr__('Click to view all dates', 'event_espresso')
600 600
               . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
601 601
             : '';
602 602
         //get first item for initial visibility
603
-        $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
603
+        $content .= '<div class="left">'.array_shift($datetime_strings).'</div>';
604 604
         $content .= $expand_toggle;
605 605
         if ($datetime_strings) {
606 606
             $content .= '<div style="clear:both"></div>';
@@ -650,9 +650,9 @@  discard block
 block discarded – undo
650 650
         $t = $item->get_first_related('Transaction');
651 651
         $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
652 652
         //append group count to name
653
-        $link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
653
+        $link .= '&nbsp;'.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
654 654
         //append reg_code
655
-        $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
655
+        $link .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
656 656
         //reg status text for accessibility
657 657
         $link .= '<br><span class="ee-status-text-small">'
658 658
                  . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
                                 . $trash_lnk_url
675 675
                                 . '" title="'
676 676
                                 . esc_attr__('Trash Registration', 'event_espresso')
677
-                                . '">' . __('Trash', 'event_espresso') . '</a>';
677
+                                . '">'.__('Trash', 'event_espresso').'</a>';
678 678
         } elseif ($this->_view === 'trash') {
679 679
             // restore registration link
680 680
             if (EE_Registry::instance()->CAP->current_user_can(
@@ -689,8 +689,8 @@  discard block
 block discarded – undo
689 689
                 $actions['restore'] = '<a href="'
690 690
                                       . $restore_lnk_url
691 691
                                       . '" title="'
692
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
693
-                                      . __('Restore', 'event_espresso') . '</a>';
692
+                                      . esc_attr__('Restore Registration', 'event_espresso').'">'
693
+                                      . __('Restore', 'event_espresso').'</a>';
694 694
             }
695 695
             if (EE_Registry::instance()->CAP->current_user_can(
696 696
                 'ee_delete_registration',
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
                                                                               . $ticket->name()
763 763
                                                                               . '</span><br />' : '';
764 764
         if ($item->final_price() > 0) {
765
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
765
+            $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>';
766 766
         } else {
767 767
             // free event
768 768
             $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
             : '<span class="TKT_name">'
790 790
               . $ticket->name()
791 791
               . '</span><br />';
792
-        $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
792
+        $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>';
793 793
         return $content;
794 794
     }
795 795
 
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
         $payment_method = $item->payment_method();
808 808
         $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
809 809
             : __('Unknown', 'event_espresso');
810
-        $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
810
+        $content = '<span class="reg-pad-rght">'.$item->pretty_paid().'</span>';
811 811
         if ($item->paid() > 0) {
812 812
             $content .= '<br><span class="ee-status-text-small">'
813 813
                         . sprintf(
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
                   . esc_attr__('View Transaction', 'event_espresso')
853 853
                   . '">'
854 854
                   . $item->transaction()->pretty_total()
855
-                  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
855
+                  . '</a></span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_total().'</span>';
856 856
         } else {
857 857
             return __("None", "event_espresso");
858 858
         }
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
                       . esc_attr__('View Transaction', 'event_espresso')
896 896
                       . '">'
897 897
                       . $item->transaction()->pretty_paid()
898
-                      . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
898
+                      . '</a><span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>';
899 899
             }
900 900
         }
901 901
         return '&nbsp;';
@@ -955,8 +955,8 @@  discard block
 block discarded – undo
955 955
                                && $attendee instanceof EE_Attendee
956 956
             ? '
957 957
 			<li>
958
-			<a href="' . $edit_lnk_url . '" title="'
959
-              . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
958
+			<a href="' . $edit_lnk_url.'" title="'
959
+              . esc_attr__('Edit Contact Details', 'event_espresso').'" class="tiny-text">
960 960
 				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
961 961
 			</a>
962 962
 			</li>' : '';
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
                          'see_notifications_for',
1026 1026
                          null,
1027 1027
                          array('_REG_ID' => $item->ID())
1028
-                     ) . '</li>';
1028
+                     ).'</li>';
1029 1029
         }
1030 1030
         $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1031 1031
         return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Email_messenger.class.php 1 patch
Indentation   +640 added lines, -640 removed lines patch added patch discarded remove patch
@@ -8,644 +8,644 @@
 block discarded – undo
8 8
 class EE_Email_messenger extends EE_messenger
9 9
 {
10 10
 
11
-    /**
12
-     * To field for email
13
-     * @var string
14
-     */
15
-    protected $_to = '';
16
-
17
-
18
-    /**
19
-     * CC field for email.
20
-     * @var string
21
-     */
22
-    protected $_cc = '';
23
-
24
-    /**
25
-     * From field for email
26
-     * @var string
27
-     */
28
-    protected $_from = '';
29
-
30
-
31
-    /**
32
-     * Subject field for email
33
-     * @var string
34
-     */
35
-    protected $_subject = '';
36
-
37
-
38
-    /**
39
-     * Content field for email
40
-     * @var string
41
-     */
42
-    protected $_content = '';
43
-
44
-
45
-    /**
46
-     * constructor
47
-     *
48
-     * @access public
49
-     */
50
-    public function __construct()
51
-    {
52
-        //set name and description properties
53
-        $this->name                = 'email';
54
-        $this->description         = sprintf(
55
-            esc_html__(
56
-                'This messenger delivers messages via email using the built-in %s function included with WordPress',
57
-                'event_espresso'
58
-            ),
59
-            '<code>wp_mail</code>'
60
-        );
61
-        $this->label               = array(
62
-            'singular' => esc_html__('email', 'event_espresso'),
63
-            'plural'   => esc_html__('emails', 'event_espresso'),
64
-        );
65
-        $this->activate_on_install = true;
66
-
67
-        //we're using defaults so let's call parent constructor that will take care of setting up all the other
68
-        // properties
69
-        parent::__construct();
70
-    }
71
-
72
-
73
-    /**
74
-     * see abstract declaration in parent class for details.
75
-     */
76
-    protected function _set_admin_pages()
77
-    {
78
-        $this->admin_registered_pages = array(
79
-            'events_edit' => true,
80
-        );
81
-    }
82
-
83
-
84
-    /**
85
-     * see abstract declaration in parent class for details
86
-     */
87
-    protected function _set_valid_shortcodes()
88
-    {
89
-        //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
90
-        // message type.
91
-        $this->_valid_shortcodes = array(
92
-            'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
93
-            'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
94
-            'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
95
-        );
96
-    }
97
-
98
-
99
-    /**
100
-     * see abstract declaration in parent class for details
101
-     *
102
-     * @access protected
103
-     * @return void
104
-     */
105
-    protected function _set_validator_config()
106
-    {
107
-        $valid_shortcodes = $this->get_valid_shortcodes();
108
-
109
-        $this->_validator_config = array(
110
-            'to'            => array(
111
-                'shortcodes' => $valid_shortcodes['to'],
112
-                'type'       => 'email',
113
-            ),
114
-            'cc' => array(
115
-                'shortcodes' => $valid_shortcodes['to'],
116
-                'type' => 'email',
117
-            ),
118
-            'from'          => array(
119
-                'shortcodes' => $valid_shortcodes['from'],
120
-                'type'       => 'email',
121
-            ),
122
-            'subject'       => array(
123
-                'shortcodes' => array(
124
-                    'organization',
125
-                    'primary_registration_details',
126
-                    'event_author',
127
-                    'primary_registration_details',
128
-                    'recipient_details',
129
-                ),
130
-            ),
131
-            'content'       => array(
132
-                'shortcodes' => array(
133
-                    'event_list',
134
-                    'attendee_list',
135
-                    'ticket_list',
136
-                    'organization',
137
-                    'primary_registration_details',
138
-                    'primary_registration_list',
139
-                    'event_author',
140
-                    'recipient_details',
141
-                    'recipient_list',
142
-                    'transaction',
143
-                    'messenger',
144
-                ),
145
-            ),
146
-            'attendee_list' => array(
147
-                'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
148
-                'required'   => array('[ATTENDEE_LIST]'),
149
-            ),
150
-            'event_list'    => array(
151
-                'shortcodes' => array(
152
-                    'event',
153
-                    'attendee_list',
154
-                    'ticket_list',
155
-                    'venue',
156
-                    'datetime_list',
157
-                    'attendee',
158
-                    'primary_registration_details',
159
-                    'primary_registration_list',
160
-                    'event_author',
161
-                    'recipient_details',
162
-                    'recipient_list',
163
-                ),
164
-                'required'   => array('[EVENT_LIST]'),
165
-            ),
166
-            'ticket_list'   => array(
167
-                'shortcodes' => array(
168
-                    'event_list',
169
-                    'attendee_list',
170
-                    'ticket',
171
-                    'datetime_list',
172
-                    'primary_registration_details',
173
-                    'recipient_details',
174
-                ),
175
-                'required'   => array('[TICKET_LIST]'),
176
-            ),
177
-            'datetime_list' => array(
178
-                'shortcodes' => array('datetime'),
179
-                'required'   => array('[DATETIME_LIST]'),
180
-            ),
181
-        );
182
-    }
183
-
184
-
185
-    /**
186
-     * @see   parent EE_messenger class for docs
187
-     * @since 4.5.0
188
-     */
189
-    public function do_secondary_messenger_hooks($sending_messenger_name)
190
-    {
191
-        if ($sending_messenger_name = 'html') {
192
-            add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
193
-        }
194
-    }
195
-
196
-
197
-    public function add_email_css(
198
-        $variation_path,
199
-        $messenger,
200
-        $message_type,
201
-        $type,
202
-        $variation,
203
-        $file_extension,
204
-        $url,
205
-        EE_Messages_Template_Pack $template_pack
206
-    ) {
207
-        //prevent recursion on this callback.
208
-        remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
209
-        $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
210
-
211
-        add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
212
-        return $variation;
213
-    }
214
-
215
-
216
-    /**
217
-     * See parent for details
218
-     *
219
-     * @access protected
220
-     * @return void
221
-     */
222
-    protected function _set_test_settings_fields()
223
-    {
224
-        $this->_test_settings_fields = array(
225
-            'to'      => array(
226
-                'input'      => 'text',
227
-                'label'      => esc_html__('Send a test email to', 'event_espresso'),
228
-                'type'       => 'email',
229
-                'required'   => true,
230
-                'validation' => true,
231
-                'css_class'  => 'large-text',
232
-                'format'     => '%s',
233
-                'default'    => get_bloginfo('admin_email'),
234
-            ),
235
-            'subject' => array(
236
-                'input'      => 'hidden',
237
-                'label'      => '',
238
-                'type'       => 'string',
239
-                'required'   => false,
240
-                'validation' => false,
241
-                'format'     => '%s',
242
-                'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
243
-                'default'    => '',
244
-                'css_class'  => '',
245
-            ),
246
-        );
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 but will get used by a messenger field for
260
-        // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
261
-        // they relate to.  This is important for the Messages_admin to know what fields to display to the user.
262
-        //  Also, notice that the "values" are equal to the field type that messages admin will use to know what
263
-        // kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
264
-        // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
265
-        // displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
266
-        // will not be displayed/parsed.
267
-        $this->_template_fields = array(
268
-            'to'      => array(
269
-                'input'      => 'text',
270
-                'label'      => esc_html_x(
271
-                    'To',
272
-                    'Label for the "To" field for email addresses',
273
-                    'event_espresso'
274
-                ),
275
-                'type'       => 'string',
276
-                'required'   => true,
277
-                'validation' => true,
278
-                'css_class'  => 'large-text',
279
-                'format'     => '%s',
280
-            ),
281
-            'cc'      => array(
282
-                'input'      => 'text',
283
-                'label'      => esc_html_x(
284
-                    'CC',
285
-                    'Label for the "Carbon Copy" field used for additional email addresses',
286
-                    'event_espresso'
287
-                ),
288
-                'type'       => 'string',
289
-                'required'   => false,
290
-                'validation' => true,
291
-                'css_class'  => 'large-text',
292
-                'format'     => '%s',
293
-            ),
294
-            'from'    => array(
295
-                'input'      => 'text',
296
-                'label'      => esc_html_x(
297
-                    'From',
298
-                    'Label for the "From" field for email addresses.',
299
-                    'event_espresso'
300
-                ),
301
-                'type'       => 'string',
302
-                'required'   => true,
303
-                'validation' => true,
304
-                'css_class'  => 'large-text',
305
-                'format'     => '%s',
306
-            ),
307
-            'subject' => array(
308
-                'input'      => 'text',
309
-                'label'      => esc_html_x(
310
-                    'Subject',
311
-                    'Label for the "Subject" field (short description of contents) for emails.',
312
-                    'event_espresso'
313
-                ),
314
-                'type'       => 'string',
315
-                'required'   => true,
316
-                'validation' => true,
317
-                'css_class'  => 'large-text',
318
-                'format'     => '%s',
319
-            ),
320
-            'content' => '',
321
-            //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
322
-            'extra'   => array(
323
-                'content' => array(
324
-                    'main'          => array(
325
-                        'input'      => 'wp_editor',
326
-                        'label'      => esc_html__('Main Content', 'event_espresso'),
327
-                        'type'       => 'string',
328
-                        'required'   => true,
329
-                        'validation' => true,
330
-                        'format'     => '%s',
331
-                        'rows'       => '15',
332
-                    ),
333
-                    'event_list'    => array(
334
-                        'input'               => 'wp_editor',
335
-                        'label'               => '[EVENT_LIST]',
336
-                        'type'                => 'string',
337
-                        'required'            => true,
338
-                        'validation'          => true,
339
-                        'format'              => '%s',
340
-                        'rows'                => '15',
341
-                        'shortcodes_required' => array('[EVENT_LIST]'),
342
-                    ),
343
-                    'attendee_list' => array(
344
-                        'input'               => 'textarea',
345
-                        'label'               => '[ATTENDEE_LIST]',
346
-                        'type'                => 'string',
347
-                        'required'            => true,
348
-                        'validation'          => true,
349
-                        'format'              => '%s',
350
-                        'css_class'           => 'large-text',
351
-                        'rows'                => '5',
352
-                        'shortcodes_required' => array('[ATTENDEE_LIST]'),
353
-                    ),
354
-                    'ticket_list'   => array(
355
-                        'input'               => 'textarea',
356
-                        'label'               => '[TICKET_LIST]',
357
-                        'type'                => 'string',
358
-                        'required'            => true,
359
-                        'validation'          => true,
360
-                        'format'              => '%s',
361
-                        'css_class'           => 'large-text',
362
-                        'rows'                => '10',
363
-                        'shortcodes_required' => array('[TICKET_LIST]'),
364
-                    ),
365
-                    'datetime_list' => array(
366
-                        'input'               => 'textarea',
367
-                        'label'               => '[DATETIME_LIST]',
368
-                        'type'                => 'string',
369
-                        'required'            => true,
370
-                        'validation'          => true,
371
-                        'format'              => '%s',
372
-                        'css_class'           => 'large-text',
373
-                        'rows'                => '10',
374
-                        'shortcodes_required' => array('[DATETIME_LIST]'),
375
-                    ),
376
-                ),
377
-            ),
378
-        );
379
-    }
380
-
381
-
382
-    /**
383
-     * See definition of this class in parent
384
-     */
385
-    protected function _set_default_message_types()
386
-    {
387
-        $this->_default_message_types = array(
388
-            'payment',
389
-            'payment_refund',
390
-            'registration',
391
-            'not_approved_registration',
392
-            'pending_approval',
393
-        );
394
-    }
395
-
396
-
397
-    /**
398
-     * @see   definition of this class in parent
399
-     * @since 4.5.0
400
-     */
401
-    protected function _set_valid_message_types()
402
-    {
403
-        $this->_valid_message_types = array(
404
-            'payment',
405
-            'registration',
406
-            'not_approved_registration',
407
-            'declined_registration',
408
-            'cancelled_registration',
409
-            'pending_approval',
410
-            'registration_summary',
411
-            'payment_reminder',
412
-            'payment_declined',
413
-            'payment_refund',
414
-        );
415
-    }
416
-
417
-
418
-    /**
419
-     * setting up admin_settings_fields for messenger.
420
-     */
421
-    protected function _set_admin_settings_fields()
422
-    {
423
-    }
424
-
425
-    /**
426
-     * We just deliver the messages don't kill us!!
427
-     *
428
-     * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
429
-     *              present.
430
-     * @throws EE_Error
431
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
432
-     */
433
-    protected function _send_message()
434
-    {
435
-        $success = wp_mail(
436
-            $this->_to,
437
-            //some old values for subject may be expecting HTML entities to be decoded in the subject
438
-            //and subjects aren't interpreted as HTML, so there should be no HTML in them
439
-            wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),
440
-            $this->_body(),
441
-            $this->_headers()
442
-        );
443
-        if (! $success) {
444
-            EE_Error::add_error(
445
-                sprintf(
446
-                    esc_html__(
447
-                        'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
448
-                        'event_espresso'
449
-                    ),
450
-                    $this->_to,
451
-                    $this->_from,
452
-                    '<br />'
453
-                ),
454
-                __FILE__,
455
-                __FUNCTION__,
456
-                __LINE__
457
-            );
458
-        }
459
-        return $success;
460
-    }
461
-
462
-
463
-    /**
464
-     * see parent for definition
465
-     *
466
-     * @return string html body of the message content and the related css.
467
-     * @throws EE_Error
468
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
469
-     */
470
-    protected function _preview()
471
-    {
472
-        return $this->_body(true);
473
-    }
474
-
475
-
476
-    /**
477
-     * Setup headers for email
478
-     *
479
-     * @access protected
480
-     * @return string formatted header for email
481
-     */
482
-    protected function _headers()
483
-    {
484
-        $this->_ensure_has_from_email_address();
485
-        $from    = $this->_from;
486
-        $headers = array(
487
-            'From:' . $from,
488
-            'Reply-To:' . $from,
489
-            'Content-Type:text/html; charset=utf-8',
490
-        );
491
-
492
-        if (! empty($this->_cc)) {
493
-            $headers[] = 'cc: ' . $this->_cc;
494
-        }
495
-
496
-        //but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
497
-        // header.
498
-        add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
499
-        add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
500
-        return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
501
-    }
502
-
503
-
504
-    /**
505
-     * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
506
-     * address for the from address to avoid problems with sending emails.
507
-     */
508
-    protected function _ensure_has_from_email_address()
509
-    {
510
-        if (empty($this->_from)) {
511
-            $this->_from = get_bloginfo('admin_email');
512
-        }
513
-    }
514
-
515
-
516
-    /**
517
-     * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
518
-     * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
519
-     * be empty
520
-     *
521
-     * @since 4.3.1
522
-     * @return array
523
-     */
524
-    private function _parse_from()
525
-    {
526
-        if (strpos($this->_from, '<') !== false) {
527
-            $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
528
-            $from_name = str_replace('"', '', $from_name);
529
-            $from_name = trim($from_name);
530
-
531
-            $from_email = substr($this->_from, strpos($this->_from, '<') + 1);
532
-            $from_email = str_replace('>', '', $from_email);
533
-            $from_email = trim($from_email);
534
-        } elseif (trim($this->_from) !== '') {
535
-            $from_name  = '';
536
-            $from_email = trim($this->_from);
537
-        } else {
538
-            $from_name = $from_email = '';
539
-        }
540
-        return array($from_name, $from_email);
541
-    }
542
-
543
-
544
-    /**
545
-     * Callback for the wp_mail_from filter.
546
-     *
547
-     * @since 4.3.1
548
-     * @param string $from_email What the original from_email is.
549
-     * @return string
550
-     */
551
-    public function set_from_address($from_email)
552
-    {
553
-        $parsed_from = $this->_parse_from();
554
-        //includes fallback if the parsing failed.
555
-        $from_email = is_array($parsed_from) && ! empty($parsed_from[1])
556
-            ? $parsed_from[1]
557
-            : get_bloginfo('admin_email');
558
-        return $from_email;
559
-    }
560
-
561
-
562
-    /**
563
-     * Callback fro the wp_mail_from_name filter.
564
-     *
565
-     * @since 4.3.1
566
-     * @param string $from_name The original from_name.
567
-     * @return string
568
-     */
569
-    public function set_from_name($from_name)
570
-    {
571
-        $parsed_from = $this->_parse_from();
572
-        if (is_array($parsed_from) && ! empty($parsed_from[0])) {
573
-            $from_name = $parsed_from[0];
574
-        }
575
-
576
-        //if from name is "WordPress" let's sub in the site name instead (more friendly!)
577
-        //but realize the default name is HTML entity-encoded
578
-        $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;
579
-
580
-        return $from_name;
581
-    }
582
-
583
-
584
-    /**
585
-     * setup body for email
586
-     *
587
-     * @param bool $preview will determine whether this is preview template or not.
588
-     * @return string formatted body for email.
589
-     * @throws EE_Error
590
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
591
-     */
592
-    protected function _body($preview = false)
593
-    {
594
-        //setup template args!
595
-        $this->_template_args = array(
596
-            'subject'   => $this->_subject,
597
-            'from'      => $this->_from,
598
-            'main_body' => wpautop($this->_content),
599
-        );
600
-        $body                 = $this->_get_main_template($preview);
601
-
602
-        /**
603
-         * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
604
-         *
605
-         * @type    bool $preview Indicates whether a preview is being generated or not.
606
-         * @return  bool    true  indicates to use the inliner, false bypasses it.
607
-         */
608
-        if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
609
-            //require CssToInlineStyles library and its dependencies via composer autoloader
610
-            require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
611
-
612
-            //now if this isn't a preview, let's setup the body so it has inline styles
613
-            if (! $preview || ($preview && defined('DOING_AJAX'))) {
614
-                $style = file_get_contents(
615
-                    $this->get_variation(
616
-                        $this->_tmp_pack,
617
-                        $this->_incoming_message_type->name,
618
-                        false,
619
-                        'main',
620
-                        $this->_variation
621
-                    ),
622
-                    true
623
-                );
624
-                $CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
625
-                //for some reason the library has a bracket and new line at the beginning.  This takes care of that.
626
-                $body  = ltrim($CSS->convert(true), ">\n");
627
-                //see https://events.codebasehq.com/projects/event-espresso/tickets/8609
628
-                $body  = ltrim($body, "<?");
629
-            }
630
-
631
-        }
632
-        return $body;
633
-    }
634
-
635
-
636
-    /**
637
-     * This just returns any existing test settings that might be saved in the database
638
-     *
639
-     * @access public
640
-     * @return array
641
-     */
642
-    public function get_existing_test_settings()
643
-    {
644
-        $settings = parent::get_existing_test_settings();
645
-        //override subject if present because we always want it to be fresh.
646
-        if (is_array($settings) && ! empty($settings['subject'])) {
647
-            $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
648
-        }
649
-        return $settings;
650
-    }
11
+	/**
12
+	 * To field for email
13
+	 * @var string
14
+	 */
15
+	protected $_to = '';
16
+
17
+
18
+	/**
19
+	 * CC field for email.
20
+	 * @var string
21
+	 */
22
+	protected $_cc = '';
23
+
24
+	/**
25
+	 * From field for email
26
+	 * @var string
27
+	 */
28
+	protected $_from = '';
29
+
30
+
31
+	/**
32
+	 * Subject field for email
33
+	 * @var string
34
+	 */
35
+	protected $_subject = '';
36
+
37
+
38
+	/**
39
+	 * Content field for email
40
+	 * @var string
41
+	 */
42
+	protected $_content = '';
43
+
44
+
45
+	/**
46
+	 * constructor
47
+	 *
48
+	 * @access public
49
+	 */
50
+	public function __construct()
51
+	{
52
+		//set name and description properties
53
+		$this->name                = 'email';
54
+		$this->description         = sprintf(
55
+			esc_html__(
56
+				'This messenger delivers messages via email using the built-in %s function included with WordPress',
57
+				'event_espresso'
58
+			),
59
+			'<code>wp_mail</code>'
60
+		);
61
+		$this->label               = array(
62
+			'singular' => esc_html__('email', 'event_espresso'),
63
+			'plural'   => esc_html__('emails', 'event_espresso'),
64
+		);
65
+		$this->activate_on_install = true;
66
+
67
+		//we're using defaults so let's call parent constructor that will take care of setting up all the other
68
+		// properties
69
+		parent::__construct();
70
+	}
71
+
72
+
73
+	/**
74
+	 * see abstract declaration in parent class for details.
75
+	 */
76
+	protected function _set_admin_pages()
77
+	{
78
+		$this->admin_registered_pages = array(
79
+			'events_edit' => true,
80
+		);
81
+	}
82
+
83
+
84
+	/**
85
+	 * see abstract declaration in parent class for details
86
+	 */
87
+	protected function _set_valid_shortcodes()
88
+	{
89
+		//remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
90
+		// message type.
91
+		$this->_valid_shortcodes = array(
92
+			'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
93
+			'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
94
+			'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
95
+		);
96
+	}
97
+
98
+
99
+	/**
100
+	 * see abstract declaration in parent class for details
101
+	 *
102
+	 * @access protected
103
+	 * @return void
104
+	 */
105
+	protected function _set_validator_config()
106
+	{
107
+		$valid_shortcodes = $this->get_valid_shortcodes();
108
+
109
+		$this->_validator_config = array(
110
+			'to'            => array(
111
+				'shortcodes' => $valid_shortcodes['to'],
112
+				'type'       => 'email',
113
+			),
114
+			'cc' => array(
115
+				'shortcodes' => $valid_shortcodes['to'],
116
+				'type' => 'email',
117
+			),
118
+			'from'          => array(
119
+				'shortcodes' => $valid_shortcodes['from'],
120
+				'type'       => 'email',
121
+			),
122
+			'subject'       => array(
123
+				'shortcodes' => array(
124
+					'organization',
125
+					'primary_registration_details',
126
+					'event_author',
127
+					'primary_registration_details',
128
+					'recipient_details',
129
+				),
130
+			),
131
+			'content'       => array(
132
+				'shortcodes' => array(
133
+					'event_list',
134
+					'attendee_list',
135
+					'ticket_list',
136
+					'organization',
137
+					'primary_registration_details',
138
+					'primary_registration_list',
139
+					'event_author',
140
+					'recipient_details',
141
+					'recipient_list',
142
+					'transaction',
143
+					'messenger',
144
+				),
145
+			),
146
+			'attendee_list' => array(
147
+				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
148
+				'required'   => array('[ATTENDEE_LIST]'),
149
+			),
150
+			'event_list'    => array(
151
+				'shortcodes' => array(
152
+					'event',
153
+					'attendee_list',
154
+					'ticket_list',
155
+					'venue',
156
+					'datetime_list',
157
+					'attendee',
158
+					'primary_registration_details',
159
+					'primary_registration_list',
160
+					'event_author',
161
+					'recipient_details',
162
+					'recipient_list',
163
+				),
164
+				'required'   => array('[EVENT_LIST]'),
165
+			),
166
+			'ticket_list'   => array(
167
+				'shortcodes' => array(
168
+					'event_list',
169
+					'attendee_list',
170
+					'ticket',
171
+					'datetime_list',
172
+					'primary_registration_details',
173
+					'recipient_details',
174
+				),
175
+				'required'   => array('[TICKET_LIST]'),
176
+			),
177
+			'datetime_list' => array(
178
+				'shortcodes' => array('datetime'),
179
+				'required'   => array('[DATETIME_LIST]'),
180
+			),
181
+		);
182
+	}
183
+
184
+
185
+	/**
186
+	 * @see   parent EE_messenger class for docs
187
+	 * @since 4.5.0
188
+	 */
189
+	public function do_secondary_messenger_hooks($sending_messenger_name)
190
+	{
191
+		if ($sending_messenger_name = 'html') {
192
+			add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
193
+		}
194
+	}
195
+
196
+
197
+	public function add_email_css(
198
+		$variation_path,
199
+		$messenger,
200
+		$message_type,
201
+		$type,
202
+		$variation,
203
+		$file_extension,
204
+		$url,
205
+		EE_Messages_Template_Pack $template_pack
206
+	) {
207
+		//prevent recursion on this callback.
208
+		remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
209
+		$variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
210
+
211
+		add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
212
+		return $variation;
213
+	}
214
+
215
+
216
+	/**
217
+	 * See parent for details
218
+	 *
219
+	 * @access protected
220
+	 * @return void
221
+	 */
222
+	protected function _set_test_settings_fields()
223
+	{
224
+		$this->_test_settings_fields = array(
225
+			'to'      => array(
226
+				'input'      => 'text',
227
+				'label'      => esc_html__('Send a test email to', 'event_espresso'),
228
+				'type'       => 'email',
229
+				'required'   => true,
230
+				'validation' => true,
231
+				'css_class'  => 'large-text',
232
+				'format'     => '%s',
233
+				'default'    => get_bloginfo('admin_email'),
234
+			),
235
+			'subject' => array(
236
+				'input'      => 'hidden',
237
+				'label'      => '',
238
+				'type'       => 'string',
239
+				'required'   => false,
240
+				'validation' => false,
241
+				'format'     => '%s',
242
+				'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
243
+				'default'    => '',
244
+				'css_class'  => '',
245
+			),
246
+		);
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 but will get used by a messenger field for
260
+		// shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
261
+		// they relate to.  This is important for the Messages_admin to know what fields to display to the user.
262
+		//  Also, notice that the "values" are equal to the field type that messages admin will use to know what
263
+		// kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
264
+		// indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
265
+		// displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
266
+		// will not be displayed/parsed.
267
+		$this->_template_fields = array(
268
+			'to'      => array(
269
+				'input'      => 'text',
270
+				'label'      => esc_html_x(
271
+					'To',
272
+					'Label for the "To" field for email addresses',
273
+					'event_espresso'
274
+				),
275
+				'type'       => 'string',
276
+				'required'   => true,
277
+				'validation' => true,
278
+				'css_class'  => 'large-text',
279
+				'format'     => '%s',
280
+			),
281
+			'cc'      => array(
282
+				'input'      => 'text',
283
+				'label'      => esc_html_x(
284
+					'CC',
285
+					'Label for the "Carbon Copy" field used for additional email addresses',
286
+					'event_espresso'
287
+				),
288
+				'type'       => 'string',
289
+				'required'   => false,
290
+				'validation' => true,
291
+				'css_class'  => 'large-text',
292
+				'format'     => '%s',
293
+			),
294
+			'from'    => array(
295
+				'input'      => 'text',
296
+				'label'      => esc_html_x(
297
+					'From',
298
+					'Label for the "From" field for email addresses.',
299
+					'event_espresso'
300
+				),
301
+				'type'       => 'string',
302
+				'required'   => true,
303
+				'validation' => true,
304
+				'css_class'  => 'large-text',
305
+				'format'     => '%s',
306
+			),
307
+			'subject' => array(
308
+				'input'      => 'text',
309
+				'label'      => esc_html_x(
310
+					'Subject',
311
+					'Label for the "Subject" field (short description of contents) for emails.',
312
+					'event_espresso'
313
+				),
314
+				'type'       => 'string',
315
+				'required'   => true,
316
+				'validation' => true,
317
+				'css_class'  => 'large-text',
318
+				'format'     => '%s',
319
+			),
320
+			'content' => '',
321
+			//left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
322
+			'extra'   => array(
323
+				'content' => array(
324
+					'main'          => array(
325
+						'input'      => 'wp_editor',
326
+						'label'      => esc_html__('Main Content', 'event_espresso'),
327
+						'type'       => 'string',
328
+						'required'   => true,
329
+						'validation' => true,
330
+						'format'     => '%s',
331
+						'rows'       => '15',
332
+					),
333
+					'event_list'    => array(
334
+						'input'               => 'wp_editor',
335
+						'label'               => '[EVENT_LIST]',
336
+						'type'                => 'string',
337
+						'required'            => true,
338
+						'validation'          => true,
339
+						'format'              => '%s',
340
+						'rows'                => '15',
341
+						'shortcodes_required' => array('[EVENT_LIST]'),
342
+					),
343
+					'attendee_list' => array(
344
+						'input'               => 'textarea',
345
+						'label'               => '[ATTENDEE_LIST]',
346
+						'type'                => 'string',
347
+						'required'            => true,
348
+						'validation'          => true,
349
+						'format'              => '%s',
350
+						'css_class'           => 'large-text',
351
+						'rows'                => '5',
352
+						'shortcodes_required' => array('[ATTENDEE_LIST]'),
353
+					),
354
+					'ticket_list'   => array(
355
+						'input'               => 'textarea',
356
+						'label'               => '[TICKET_LIST]',
357
+						'type'                => 'string',
358
+						'required'            => true,
359
+						'validation'          => true,
360
+						'format'              => '%s',
361
+						'css_class'           => 'large-text',
362
+						'rows'                => '10',
363
+						'shortcodes_required' => array('[TICKET_LIST]'),
364
+					),
365
+					'datetime_list' => array(
366
+						'input'               => 'textarea',
367
+						'label'               => '[DATETIME_LIST]',
368
+						'type'                => 'string',
369
+						'required'            => true,
370
+						'validation'          => true,
371
+						'format'              => '%s',
372
+						'css_class'           => 'large-text',
373
+						'rows'                => '10',
374
+						'shortcodes_required' => array('[DATETIME_LIST]'),
375
+					),
376
+				),
377
+			),
378
+		);
379
+	}
380
+
381
+
382
+	/**
383
+	 * See definition of this class in parent
384
+	 */
385
+	protected function _set_default_message_types()
386
+	{
387
+		$this->_default_message_types = array(
388
+			'payment',
389
+			'payment_refund',
390
+			'registration',
391
+			'not_approved_registration',
392
+			'pending_approval',
393
+		);
394
+	}
395
+
396
+
397
+	/**
398
+	 * @see   definition of this class in parent
399
+	 * @since 4.5.0
400
+	 */
401
+	protected function _set_valid_message_types()
402
+	{
403
+		$this->_valid_message_types = array(
404
+			'payment',
405
+			'registration',
406
+			'not_approved_registration',
407
+			'declined_registration',
408
+			'cancelled_registration',
409
+			'pending_approval',
410
+			'registration_summary',
411
+			'payment_reminder',
412
+			'payment_declined',
413
+			'payment_refund',
414
+		);
415
+	}
416
+
417
+
418
+	/**
419
+	 * setting up admin_settings_fields for messenger.
420
+	 */
421
+	protected function _set_admin_settings_fields()
422
+	{
423
+	}
424
+
425
+	/**
426
+	 * We just deliver the messages don't kill us!!
427
+	 *
428
+	 * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
429
+	 *              present.
430
+	 * @throws EE_Error
431
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
432
+	 */
433
+	protected function _send_message()
434
+	{
435
+		$success = wp_mail(
436
+			$this->_to,
437
+			//some old values for subject may be expecting HTML entities to be decoded in the subject
438
+			//and subjects aren't interpreted as HTML, so there should be no HTML in them
439
+			wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),
440
+			$this->_body(),
441
+			$this->_headers()
442
+		);
443
+		if (! $success) {
444
+			EE_Error::add_error(
445
+				sprintf(
446
+					esc_html__(
447
+						'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
448
+						'event_espresso'
449
+					),
450
+					$this->_to,
451
+					$this->_from,
452
+					'<br />'
453
+				),
454
+				__FILE__,
455
+				__FUNCTION__,
456
+				__LINE__
457
+			);
458
+		}
459
+		return $success;
460
+	}
461
+
462
+
463
+	/**
464
+	 * see parent for definition
465
+	 *
466
+	 * @return string html body of the message content and the related css.
467
+	 * @throws EE_Error
468
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
469
+	 */
470
+	protected function _preview()
471
+	{
472
+		return $this->_body(true);
473
+	}
474
+
475
+
476
+	/**
477
+	 * Setup headers for email
478
+	 *
479
+	 * @access protected
480
+	 * @return string formatted header for email
481
+	 */
482
+	protected function _headers()
483
+	{
484
+		$this->_ensure_has_from_email_address();
485
+		$from    = $this->_from;
486
+		$headers = array(
487
+			'From:' . $from,
488
+			'Reply-To:' . $from,
489
+			'Content-Type:text/html; charset=utf-8',
490
+		);
491
+
492
+		if (! empty($this->_cc)) {
493
+			$headers[] = 'cc: ' . $this->_cc;
494
+		}
495
+
496
+		//but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
497
+		// header.
498
+		add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
499
+		add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
500
+		return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
501
+	}
502
+
503
+
504
+	/**
505
+	 * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
506
+	 * address for the from address to avoid problems with sending emails.
507
+	 */
508
+	protected function _ensure_has_from_email_address()
509
+	{
510
+		if (empty($this->_from)) {
511
+			$this->_from = get_bloginfo('admin_email');
512
+		}
513
+	}
514
+
515
+
516
+	/**
517
+	 * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
518
+	 * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
519
+	 * be empty
520
+	 *
521
+	 * @since 4.3.1
522
+	 * @return array
523
+	 */
524
+	private function _parse_from()
525
+	{
526
+		if (strpos($this->_from, '<') !== false) {
527
+			$from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
528
+			$from_name = str_replace('"', '', $from_name);
529
+			$from_name = trim($from_name);
530
+
531
+			$from_email = substr($this->_from, strpos($this->_from, '<') + 1);
532
+			$from_email = str_replace('>', '', $from_email);
533
+			$from_email = trim($from_email);
534
+		} elseif (trim($this->_from) !== '') {
535
+			$from_name  = '';
536
+			$from_email = trim($this->_from);
537
+		} else {
538
+			$from_name = $from_email = '';
539
+		}
540
+		return array($from_name, $from_email);
541
+	}
542
+
543
+
544
+	/**
545
+	 * Callback for the wp_mail_from filter.
546
+	 *
547
+	 * @since 4.3.1
548
+	 * @param string $from_email What the original from_email is.
549
+	 * @return string
550
+	 */
551
+	public function set_from_address($from_email)
552
+	{
553
+		$parsed_from = $this->_parse_from();
554
+		//includes fallback if the parsing failed.
555
+		$from_email = is_array($parsed_from) && ! empty($parsed_from[1])
556
+			? $parsed_from[1]
557
+			: get_bloginfo('admin_email');
558
+		return $from_email;
559
+	}
560
+
561
+
562
+	/**
563
+	 * Callback fro the wp_mail_from_name filter.
564
+	 *
565
+	 * @since 4.3.1
566
+	 * @param string $from_name The original from_name.
567
+	 * @return string
568
+	 */
569
+	public function set_from_name($from_name)
570
+	{
571
+		$parsed_from = $this->_parse_from();
572
+		if (is_array($parsed_from) && ! empty($parsed_from[0])) {
573
+			$from_name = $parsed_from[0];
574
+		}
575
+
576
+		//if from name is "WordPress" let's sub in the site name instead (more friendly!)
577
+		//but realize the default name is HTML entity-encoded
578
+		$from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;
579
+
580
+		return $from_name;
581
+	}
582
+
583
+
584
+	/**
585
+	 * setup body for email
586
+	 *
587
+	 * @param bool $preview will determine whether this is preview template or not.
588
+	 * @return string formatted body for email.
589
+	 * @throws EE_Error
590
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
591
+	 */
592
+	protected function _body($preview = false)
593
+	{
594
+		//setup template args!
595
+		$this->_template_args = array(
596
+			'subject'   => $this->_subject,
597
+			'from'      => $this->_from,
598
+			'main_body' => wpautop($this->_content),
599
+		);
600
+		$body                 = $this->_get_main_template($preview);
601
+
602
+		/**
603
+		 * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
604
+		 *
605
+		 * @type    bool $preview Indicates whether a preview is being generated or not.
606
+		 * @return  bool    true  indicates to use the inliner, false bypasses it.
607
+		 */
608
+		if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
609
+			//require CssToInlineStyles library and its dependencies via composer autoloader
610
+			require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
611
+
612
+			//now if this isn't a preview, let's setup the body so it has inline styles
613
+			if (! $preview || ($preview && defined('DOING_AJAX'))) {
614
+				$style = file_get_contents(
615
+					$this->get_variation(
616
+						$this->_tmp_pack,
617
+						$this->_incoming_message_type->name,
618
+						false,
619
+						'main',
620
+						$this->_variation
621
+					),
622
+					true
623
+				);
624
+				$CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
625
+				//for some reason the library has a bracket and new line at the beginning.  This takes care of that.
626
+				$body  = ltrim($CSS->convert(true), ">\n");
627
+				//see https://events.codebasehq.com/projects/event-espresso/tickets/8609
628
+				$body  = ltrim($body, "<?");
629
+			}
630
+
631
+		}
632
+		return $body;
633
+	}
634
+
635
+
636
+	/**
637
+	 * This just returns any existing test settings that might be saved in the database
638
+	 *
639
+	 * @access public
640
+	 * @return array
641
+	 */
642
+	public function get_existing_test_settings()
643
+	{
644
+		$settings = parent::get_existing_test_settings();
645
+		//override subject if present because we always want it to be fresh.
646
+		if (is_array($settings) && ! empty($settings['subject'])) {
647
+			$settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
648
+		}
649
+		return $settings;
650
+	}
651 651
 }
Please login to merge, or discard this patch.
modules/single_page_checkout/inc/EE_SPCO_JSON_Response.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -107,71 +107,71 @@  discard block
 block discarded – undo
107 107
 	public function __toString() {
108 108
 		$JSON_response = array();
109 109
 		// grab notices
110
-		$notices = EE_Error::get_notices( FALSE );
111
-		$this->set_attention( isset( $notices['attention'] ) ? $notices['attention'] : '' );
112
-		$this->set_errors( isset( $notices['errors'] ) ? $notices['errors'] : '' );
113
-		$this->set_success( isset( $notices['success'] ) ? $notices['success'] : '' );
110
+		$notices = EE_Error::get_notices(FALSE);
111
+		$this->set_attention(isset($notices['attention']) ? $notices['attention'] : '');
112
+		$this->set_errors(isset($notices['errors']) ? $notices['errors'] : '');
113
+		$this->set_success(isset($notices['success']) ? $notices['success'] : '');
114 114
 		// add notices to JSON response, but only if they exist
115
-		if ( $this->attention() ) {
115
+		if ($this->attention()) {
116 116
 			$JSON_response['attention'] = $this->attention();
117 117
 		}
118
-		if ( $this->errors() ) {
118
+		if ($this->errors()) {
119 119
 			$JSON_response['errors'] = $this->errors();
120 120
 		}
121
-		if ( $this->unexpected_errors() ) {
121
+		if ($this->unexpected_errors()) {
122 122
 			$JSON_response['unexpected_errors'] = $this->unexpected_errors();
123 123
 		}
124
-		if ( $this->success() ) {
124
+		if ($this->success()) {
125 125
 			$JSON_response['success'] = $this->success();
126 126
 		}
127 127
 		// but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked
128
-		if ( ! isset( $JSON_response[ 'attention' ] ) && ! isset( $JSON_response[ 'errors' ] ) && ! isset( $JSON_response[ 'success' ] ) ) {
128
+		if ( ! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) {
129 129
 			$JSON_response['success'] = null;
130 130
 		}
131 131
 		// set redirect_url, IF it exists
132
-		if ( $this->redirect_url() ) {
132
+		if ($this->redirect_url()) {
133 133
 			$JSON_response['redirect_url'] = $this->redirect_url();
134 134
 		}
135 135
 		// set registration_time_limit, IF it exists
136
-		if ( $this->registration_time_limit() ) {
136
+		if ($this->registration_time_limit()) {
137 137
 			$JSON_response['registration_time_limit'] = $this->registration_time_limit();
138 138
 		}
139 139
 		// set payment_amount, IF it exists
140
-		if ( $this->payment_amount() !== null ) {
141
-			$JSON_response[ 'payment_amount' ] = $this->payment_amount();
140
+		if ($this->payment_amount() !== null) {
141
+			$JSON_response['payment_amount'] = $this->payment_amount();
142 142
 		}
143 143
 		// grab generic return data
144 144
 		$return_data = $this->return_data();
145 145
 		// add billing form validation rules
146
-		if ( $this->validation_rules() ) {
146
+		if ($this->validation_rules()) {
147 147
 			$return_data['validation_rules'] = $this->validation_rules();
148 148
 		}
149 149
 		// set reg_step_html, IF it exists
150
-		if ( $this->reg_step_html() ) {
150
+		if ($this->reg_step_html()) {
151 151
 			$return_data['reg_step_html'] = $this->reg_step_html();
152 152
 		}
153 153
 		// set method of payment, IF it exists
154
-		if ( $this->method_of_payment() ) {
154
+		if ($this->method_of_payment()) {
155 155
 			$return_data['method_of_payment'] = $this->method_of_payment();
156 156
 		}
157 157
 		// set "plz_select_method_of_payment" message, IF it exists
158
-		if ( $this->plz_select_method_of_payment() ) {
158
+		if ($this->plz_select_method_of_payment()) {
159 159
 			$return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment();
160 160
 		}
161 161
 		// set redirect_form, IF it exists
162
-		if ( $this->redirect_form() ) {
162
+		if ($this->redirect_form()) {
163 163
 			$return_data['redirect_form'] = $this->redirect_form();
164 164
 		}
165 165
 		// and finally, add return_data array to main JSON response array, IF it contains anything
166 166
 		// why did we add some of the above properties to the return data array?
167 167
 		// because it is easier and cleaner in the Javascript to deal with this way
168
-		if ( ! empty( $return_data )) {
168
+		if ( ! empty($return_data)) {
169 169
 			$JSON_response['return_data'] = $return_data;
170 170
 		}
171 171
 		// filter final array
172
-		$JSON_response = apply_filters( 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response );
172
+		$JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response);
173 173
 		// return encoded array
174
-		return wp_json_encode( $JSON_response );
174
+		return wp_json_encode($JSON_response);
175 175
 	}
176 176
 
177 177
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	/**
180 180
 	 * @param string $attention
181 181
 	 */
182
-	public function set_attention( $attention ) {
182
+	public function set_attention($attention) {
183 183
 		$this->_attention = $attention;
184 184
 	}
185 185
 
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	/**
198 198
 	 * @param string $errors
199 199
 	 */
200
-	public function set_errors( $errors ) {
200
+	public function set_errors($errors) {
201 201
 		$this->_errors = $errors;
202 202
 	}
203 203
 
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 	/**
225 225
 	 * @param string $unexpected_errors
226 226
 	 */
227
-	public function set_unexpected_errors( $unexpected_errors ) {
227
+	public function set_unexpected_errors($unexpected_errors) {
228 228
 		$this->_unexpected_errors = $unexpected_errors;
229 229
 	}
230 230
 
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 	/**
234 234
 	 * @param string $success
235 235
 	 */
236
-	public function set_success( $success ) {
236
+	public function set_success($success) {
237 237
 		$this->_success = $success;
238 238
 	}
239 239
 
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	/**
252 252
 	 * @param string $method_of_payment
253 253
 	 */
254
-	public function set_method_of_payment( $method_of_payment ) {
254
+	public function set_method_of_payment($method_of_payment) {
255 255
 		$this->_method_of_payment = $method_of_payment;
256 256
 	}
257 257
 
@@ -278,8 +278,8 @@  discard block
 block discarded – undo
278 278
 	/**
279 279
 	 * @param float $payment_amount
280 280
 	 */
281
-	public function set_payment_amount( $payment_amount ) {
282
-		$this->_payment_amount = (float)$payment_amount;
281
+	public function set_payment_amount($payment_amount) {
282
+		$this->_payment_amount = (float) $payment_amount;
283 283
 	}
284 284
 
285 285
 
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 	/**
288 288
 	 * @param string $next_step_html
289 289
 	 */
290
-	public function set_reg_step_html( $next_step_html ) {
290
+	public function set_reg_step_html($next_step_html) {
291 291
 		$this->_reg_step_html = $next_step_html;
292 292
 	}
293 293
 
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 	/**
306 306
 	 * @param string $redirect_form
307 307
 	 */
308
-	public function set_redirect_form( $redirect_form ) {
308
+	public function set_redirect_form($redirect_form) {
309 309
 		$this->_redirect_form = $redirect_form;
310 310
 	}
311 311
 
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	 * @return string
316 316
 	 */
317 317
 	public function redirect_form() {
318
-		return ! empty( $this->_redirect_form ) ? $this->_redirect_form : FALSE;
318
+		return ! empty($this->_redirect_form) ? $this->_redirect_form : FALSE;
319 319
 	}
320 320
 
321 321
 
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 	/**
324 324
 	 * @param string $plz_select_method_of_payment
325 325
 	 */
326
-	public function set_plz_select_method_of_payment( $plz_select_method_of_payment ) {
326
+	public function set_plz_select_method_of_payment($plz_select_method_of_payment) {
327 327
 		$this->_plz_select_method_of_payment = $plz_select_method_of_payment;
328 328
 	}
329 329
 
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 	/**
342 342
 	 * @param string $redirect_url
343 343
 	 */
344
-	public function set_redirect_url( $redirect_url ) {
344
+	public function set_redirect_url($redirect_url) {
345 345
 		$this->_redirect_url = $redirect_url;
346 346
 	}
347 347
 
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 	/**
369 369
 	 * @param string $registration_time_limit
370 370
 	 */
371
-	public function set_registration_time_limit( $registration_time_limit ) {
371
+	public function set_registration_time_limit($registration_time_limit) {
372 372
 		$this->_registration_time_limit = $registration_time_limit;
373 373
 	}
374 374
 
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
 	/**
378 378
 	 * @param array $return_data
379 379
 	 */
380
-	public function set_return_data( $return_data ) {
381
-		$this->_return_data = array_merge( $this->_return_data, $return_data );
380
+	public function set_return_data($return_data) {
381
+		$this->_return_data = array_merge($this->_return_data, $return_data);
382 382
 	}
383 383
 
384 384
 
@@ -395,9 +395,9 @@  discard block
 block discarded – undo
395 395
 	/**
396 396
 	 * @param array $validation_rules
397 397
 	 */
398
-	public function add_validation_rules( $validation_rules = array() ) {
399
-		if ( is_array( $validation_rules ) && ! empty( $validation_rules )) {
400
-			$this->_validation_rules = array_merge( $this->_validation_rules, $validation_rules );
398
+	public function add_validation_rules($validation_rules = array()) {
399
+		if (is_array($validation_rules) && ! empty($validation_rules)) {
400
+			$this->_validation_rules = array_merge($this->_validation_rules, $validation_rules);
401 401
 		}
402 402
 	}
403 403
 
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 	 * @return array | bool
408 408
 	 */
409 409
 	public function validation_rules() {
410
-		return ! empty( $this->_validation_rules ) ? $this->_validation_rules : FALSE;
410
+		return ! empty($this->_validation_rules) ? $this->_validation_rules : FALSE;
411 411
 	}
412 412
 
413 413
 
Please login to merge, or discard this patch.
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 2 patches
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -218,19 +218,19 @@  discard block
 block discarded – undo
218 218
      */
219 219
     public static function set_definitions()
220 220
     {
221
-        if(defined('SPCO_BASE_PATH')) {
221
+        if (defined('SPCO_BASE_PATH')) {
222 222
             return;
223 223
         }
224 224
         define(
225 225
             'SPCO_BASE_PATH',
226
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
226
+            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS
227 227
         );
228
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
228
+        define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS);
229
+        define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS);
230
+        define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS);
231
+        define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS);
232
+        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS);
233
+        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS);
234 234
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235 235
         EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
236 236
     }
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
             return;
252 252
         }
253 253
         // filter list of reg_steps
254
-        $reg_steps_to_load = (array)apply_filters(
254
+        $reg_steps_to_load = (array) apply_filters(
255 255
             'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
256 256
             EED_Single_Page_Checkout::get_reg_steps()
257 257
         );
@@ -303,25 +303,25 @@  discard block
 block discarded – undo
303 303
         if (empty($reg_steps)) {
304 304
             $reg_steps = array(
305 305
                 10  => array(
306
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
306
+                    'file_path'  => SPCO_REG_STEPS_PATH.'attendee_information',
307 307
                     'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
308 308
                     'slug'       => 'attendee_information',
309 309
                     'has_hooks'  => false,
310 310
                 ),
311 311
                 20  => array(
312
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
312
+                    'file_path'  => SPCO_REG_STEPS_PATH.'registration_confirmation',
313 313
                     'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
314 314
                     'slug'       => 'registration_confirmation',
315 315
                     'has_hooks'  => false,
316 316
                 ),
317 317
                 30  => array(
318
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
318
+                    'file_path'  => SPCO_REG_STEPS_PATH.'payment_options',
319 319
                     'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
320 320
                     'slug'       => 'payment_options',
321 321
                     'has_hooks'  => true,
322 322
                 ),
323 323
                 999 => array(
324
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
324
+                    'file_path'  => SPCO_REG_STEPS_PATH.'finalize_registration',
325 325
                     'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
326 326
                     'slug'       => 'finalize_registration',
327 327
                     'has_hooks'  => false,
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
             // DEBUG LOG
506 506
             //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
507 507
             // get reg form
508
-            if( ! $this->_check_form_submission()) {
508
+            if ( ! $this->_check_form_submission()) {
509 509
                 EED_Single_Page_Checkout::$_initialized = true;
510 510
                 return;
511 511
             }
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
         );
547 547
         // is session still valid ?
548 548
         if ($clear_session_requested
549
-            || ( EE_Registry::instance()->SSN->expired()
549
+            || (EE_Registry::instance()->SSN->expired()
550 550
               && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
551 551
             )
552 552
         ) {
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
             // EE_Registry::instance()->SSN->reset_cart();
556 556
             // EE_Registry::instance()->SSN->reset_checkout();
557 557
             // EE_Registry::instance()->SSN->reset_transaction();
558
-            if (! $clear_session_requested) {
558
+            if ( ! $clear_session_requested) {
559 559
                 EE_Error::add_attention(
560 560
                     EE_Registry::$i18n_js_strings['registration_expiration_notice'],
561 561
                     __FILE__, __FUNCTION__, __LINE__
@@ -1114,7 +1114,7 @@  discard block
 block discarded – undo
1114 1114
                     if ( ! $registration instanceof EE_Registration) {
1115 1115
                         throw new InvalidEntityException($registration, 'EE_Registration');
1116 1116
                     }
1117
-                    $registrations[ $registration->ID() ] = $registration;
1117
+                    $registrations[$registration->ID()] = $registration;
1118 1118
                 }
1119 1119
             }
1120 1120
             $registration_processor->fix_reg_final_price_rounding_issue($transaction);
@@ -1375,7 +1375,7 @@  discard block
 block discarded – undo
1375 1375
                         ) {
1376 1376
                             EE_Error::add_success(
1377 1377
                                 $this->checkout->current_step->success_message()
1378
-                                . '<br />' . $this->checkout->next_step->_instructions()
1378
+                                . '<br />'.$this->checkout->next_step->_instructions()
1379 1379
                             );
1380 1380
                         }
1381 1381
                         // pack it up, pack it in...
@@ -1519,7 +1519,7 @@  discard block
 block discarded – undo
1519 1519
         // load css
1520 1520
         wp_register_style(
1521 1521
             'single_page_checkout',
1522
-            SPCO_CSS_URL . 'single_page_checkout.css',
1522
+            SPCO_CSS_URL.'single_page_checkout.css',
1523 1523
             array('espresso_default'),
1524 1524
             EVENT_ESPRESSO_VERSION
1525 1525
         );
@@ -1527,21 +1527,21 @@  discard block
 block discarded – undo
1527 1527
         // load JS
1528 1528
         wp_register_script(
1529 1529
             'jquery_plugin',
1530
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1530
+            EE_THIRD_PARTY_URL.'jquery	.plugin.min.js',
1531 1531
             array('jquery'),
1532 1532
             '1.0.1',
1533 1533
             true
1534 1534
         );
1535 1535
         wp_register_script(
1536 1536
             'jquery_countdown',
1537
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1537
+            EE_THIRD_PARTY_URL.'jquery	.countdown.min.js',
1538 1538
             array('jquery_plugin'),
1539 1539
             '2.0.2',
1540 1540
             true
1541 1541
         );
1542 1542
         wp_register_script(
1543 1543
             'single_page_checkout',
1544
-            SPCO_JS_URL . 'single_page_checkout.js',
1544
+            SPCO_JS_URL.'single_page_checkout.js',
1545 1545
             array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1546 1546
             EVENT_ESPRESSO_VERSION,
1547 1547
             true
@@ -1564,7 +1564,7 @@  discard block
 block discarded – undo
1564 1564
          *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1565 1565
          */
1566 1566
         do_action(
1567
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1567
+            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(),
1568 1568
             $this
1569 1569
         );
1570 1570
     }
@@ -1618,7 +1618,7 @@  discard block
 block discarded – undo
1618 1618
                     'layout_strategy' =>
1619 1619
                         new EE_Template_Layout(
1620 1620
                             array(
1621
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1621
+                                'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php',
1622 1622
                                 'template_args'        => array(
1623 1623
                                     'empty_cart'              => $empty_cart,
1624 1624
                                     'revisit'                 => $this->checkout->revisit,
@@ -1692,7 +1692,7 @@  discard block
 block discarded – undo
1692 1692
         ) {
1693 1693
             add_filter(
1694 1694
                 'FHEE__EEH_Template__powered_by_event_espresso__url',
1695
-                function ($url) {
1695
+                function($url) {
1696 1696
                     return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1697 1697
                 }
1698 1698
             );
@@ -1871,7 +1871,7 @@  discard block
 block discarded – undo
1871 1871
             '</h4>',
1872 1872
             '<br />',
1873 1873
             '<p>',
1874
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1874
+            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1875 1875
             '">',
1876 1876
             '</a>',
1877 1877
             '</p>'
Please login to merge, or discard this patch.
Indentation   +1844 added lines, -1844 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\InvalidEntityException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -20,1849 +20,1849 @@  discard block
 block discarded – undo
20 20
 class EED_Single_Page_Checkout extends EED_Module
21 21
 {
22 22
 
23
-    /**
24
-     * $_initialized - has the SPCO controller already been initialized ?
25
-     *
26
-     * @access private
27
-     * @var bool $_initialized
28
-     */
29
-    private static $_initialized = false;
30
-
31
-
32
-    /**
33
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
-     *
35
-     * @access private
36
-     * @var bool $_valid_checkout
37
-     */
38
-    private static $_checkout_verified = true;
39
-
40
-    /**
41
-     *    $_reg_steps_array - holds initial array of reg steps
42
-     *
43
-     * @access private
44
-     * @var array $_reg_steps_array
45
-     */
46
-    private static $_reg_steps_array = array();
47
-
48
-    /**
49
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
-     *
51
-     * @access public
52
-     * @var EE_Checkout $checkout
53
-     */
54
-    public $checkout;
55
-
56
-
57
-
58
-    /**
59
-     * @return EED_Module|EED_Single_Page_Checkout
60
-     */
61
-    public static function instance()
62
-    {
63
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
-        return parent::get_instance(__CLASS__);
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * @return EE_CART
71
-     */
72
-    public function cart()
73
-    {
74
-        return $this->checkout->cart;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * @return EE_Transaction
81
-     */
82
-    public function transaction()
83
-    {
84
-        return $this->checkout->transaction;
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     *    set_hooks - for hooking into EE Core, other modules, etc
91
-     *
92
-     * @access    public
93
-     * @return    void
94
-     * @throws EE_Error
95
-     */
96
-    public static function set_hooks()
97
-    {
98
-        EED_Single_Page_Checkout::set_definitions();
99
-    }
100
-
101
-
102
-
103
-    /**
104
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
-     *
106
-     * @access    public
107
-     * @return    void
108
-     * @throws EE_Error
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        EED_Single_Page_Checkout::set_definitions();
113
-        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
-            return;
115
-        }
116
-        // going to start an output buffer in case anything gets accidentally output
117
-        // that might disrupt our JSON response
118
-        ob_start();
119
-        EED_Single_Page_Checkout::load_request_handler();
120
-        EED_Single_Page_Checkout::load_reg_steps();
121
-        // set ajax hooks
122
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     *    process ajax request
134
-     *
135
-     * @param string $ajax_action
136
-     * @throws EE_Error
137
-     */
138
-    public static function process_ajax_request($ajax_action)
139
-    {
140
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
141
-        EED_Single_Page_Checkout::instance()->_initialize();
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     *    ajax display registration step
148
-     *
149
-     * @throws EE_Error
150
-     */
151
-    public static function display_reg_step()
152
-    {
153
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     *    ajax process registration step
160
-     *
161
-     * @throws EE_Error
162
-     */
163
-    public static function process_reg_step()
164
-    {
165
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     *    ajax process registration step
172
-     *
173
-     * @throws EE_Error
174
-     */
175
-    public static function update_reg_step()
176
-    {
177
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     *   update_checkout
184
-     *
185
-     * @access public
186
-     * @return void
187
-     * @throws EE_Error
188
-     */
189
-    public static function update_checkout()
190
-    {
191
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
-    }
193
-
194
-
195
-
196
-    /**
197
-     *    load_request_handler
198
-     *
199
-     * @access    public
200
-     * @return    void
201
-     */
202
-    public static function load_request_handler()
203
-    {
204
-        // load core Request_Handler class
205
-        if (EE_Registry::instance()->REQ !== null) {
206
-            EE_Registry::instance()->load_core('Request_Handler');
207
-        }
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     *    set_definitions
214
-     *
215
-     * @access    public
216
-     * @return    void
217
-     * @throws EE_Error
218
-     */
219
-    public static function set_definitions()
220
-    {
221
-        if(defined('SPCO_BASE_PATH')) {
222
-            return;
223
-        }
224
-        define(
225
-            'SPCO_BASE_PATH',
226
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
-        );
228
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     * load_reg_steps
242
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
243
-     *
244
-     * @access    private
245
-     * @throws EE_Error
246
-     */
247
-    public static function load_reg_steps()
248
-    {
249
-        static $reg_steps_loaded = false;
250
-        if ($reg_steps_loaded) {
251
-            return;
252
-        }
253
-        // filter list of reg_steps
254
-        $reg_steps_to_load = (array)apply_filters(
255
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
256
-            EED_Single_Page_Checkout::get_reg_steps()
257
-        );
258
-        // sort by key (order)
259
-        ksort($reg_steps_to_load);
260
-        // loop through folders
261
-        foreach ($reg_steps_to_load as $order => $reg_step) {
262
-            // we need a
263
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
264
-                // copy over to the reg_steps_array
265
-                EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
266
-                // register custom key route for each reg step
267
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
268
-                EE_Config::register_route(
269
-                    $reg_step['slug'],
270
-                    'EED_Single_Page_Checkout',
271
-                    'run',
272
-                    'step'
273
-                );
274
-                // add AJAX or other hooks
275
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
276
-                    // setup autoloaders if necessary
277
-                    if ( ! class_exists($reg_step['class_name'])) {
278
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
279
-                            $reg_step['file_path'],
280
-                            true
281
-                        );
282
-                    }
283
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
284
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
285
-                    }
286
-                }
287
-            }
288
-        }
289
-        $reg_steps_loaded = true;
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     *    get_reg_steps
296
-     *
297
-     * @access    public
298
-     * @return    array
299
-     */
300
-    public static function get_reg_steps()
301
-    {
302
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
303
-        if (empty($reg_steps)) {
304
-            $reg_steps = array(
305
-                10  => array(
306
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
307
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
308
-                    'slug'       => 'attendee_information',
309
-                    'has_hooks'  => false,
310
-                ),
311
-                20  => array(
312
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
313
-                    'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
314
-                    'slug'       => 'registration_confirmation',
315
-                    'has_hooks'  => false,
316
-                ),
317
-                30  => array(
318
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
319
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
320
-                    'slug'       => 'payment_options',
321
-                    'has_hooks'  => true,
322
-                ),
323
-                999 => array(
324
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
325
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
326
-                    'slug'       => 'finalize_registration',
327
-                    'has_hooks'  => false,
328
-                ),
329
-            );
330
-        }
331
-        return $reg_steps;
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     *    registration_checkout_for_admin
338
-     *
339
-     * @access    public
340
-     * @return    string
341
-     * @throws EE_Error
342
-     */
343
-    public static function registration_checkout_for_admin()
344
-    {
345
-        EED_Single_Page_Checkout::load_request_handler();
346
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
347
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
348
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
349
-        EED_Single_Page_Checkout::instance()->_initialize();
350
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
351
-        return EE_Registry::instance()->REQ->get_output();
352
-    }
353
-
354
-
355
-
356
-    /**
357
-     * process_registration_from_admin
358
-     *
359
-     * @access public
360
-     * @return \EE_Transaction
361
-     * @throws EE_Error
362
-     */
363
-    public static function process_registration_from_admin()
364
-    {
365
-        EED_Single_Page_Checkout::load_request_handler();
366
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
367
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
368
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
369
-        EED_Single_Page_Checkout::instance()->_initialize();
370
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
371
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
372
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
373
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
374
-                if ($final_reg_step->process_reg_step()) {
375
-                    $final_reg_step->set_completed();
376
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
377
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
378
-                }
379
-            }
380
-        }
381
-        return null;
382
-    }
383
-
384
-
385
-
386
-    /**
387
-     *    run
388
-     *
389
-     * @access    public
390
-     * @param WP_Query $WP_Query
391
-     * @return    void
392
-     * @throws EE_Error
393
-     */
394
-    public function run($WP_Query)
395
-    {
396
-        if (
397
-            $WP_Query instanceof WP_Query
398
-            && $WP_Query->is_main_query()
399
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
400
-            && $this->_is_reg_checkout()
401
-        ) {
402
-            $this->_initialize();
403
-        }
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * determines whether current url matches reg page url
410
-     *
411
-     * @return bool
412
-     */
413
-    protected function _is_reg_checkout()
414
-    {
415
-        // get current permalink for reg page without any extra query args
416
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
417
-        // get request URI for current request, but without the scheme or host
418
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
419
-        $current_request_uri = html_entity_decode($current_request_uri);
420
-        // get array of query args from the current request URI
421
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
422
-        // grab page id if it is set
423
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
424
-        // and remove the page id from the query args (we will re-add it later)
425
-        unset($query_args['page_id']);
426
-        // now strip all query args from current request URI
427
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
428
-        // and re-add the page id if it was set
429
-        if ($page_id) {
430
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
431
-        }
432
-        // remove slashes and ?
433
-        $current_request_uri = trim($current_request_uri, '?/');
434
-        // is current request URI part of the known full reg page URL ?
435
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
436
-    }
437
-
438
-
439
-
440
-    /**
441
-     * @param WP_Query $wp_query
442
-     * @return    void
443
-     * @throws EE_Error
444
-     */
445
-    public static function init($wp_query)
446
-    {
447
-        EED_Single_Page_Checkout::instance()->run($wp_query);
448
-    }
449
-
450
-
451
-
452
-    /**
453
-     *    _initialize - initial module setup
454
-     *
455
-     * @access    private
456
-     * @throws EE_Error
457
-     * @return    void
458
-     */
459
-    private function _initialize()
460
-    {
461
-        // ensure SPCO doesn't run twice
462
-        if (EED_Single_Page_Checkout::$_initialized) {
463
-            return;
464
-        }
465
-        try {
466
-            EED_Single_Page_Checkout::load_reg_steps();
467
-            $this->_verify_session();
468
-            // setup the EE_Checkout object
469
-            $this->checkout = $this->_initialize_checkout();
470
-            // filter checkout
471
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
472
-            // get the $_GET
473
-            $this->_get_request_vars();
474
-            if ($this->_block_bots()) {
475
-                return;
476
-            }
477
-            // filter continue_reg
478
-            $this->checkout->continue_reg = apply_filters(
479
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
480
-                true,
481
-                $this->checkout
482
-            );
483
-            // load the reg steps array
484
-            if ( ! $this->_load_and_instantiate_reg_steps()) {
485
-                EED_Single_Page_Checkout::$_initialized = true;
486
-                return;
487
-            }
488
-            // set the current step
489
-            $this->checkout->set_current_step($this->checkout->step);
490
-            // and the next step
491
-            $this->checkout->set_next_step();
492
-            // verify that everything has been setup correctly
493
-            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
494
-                EED_Single_Page_Checkout::$_initialized = true;
495
-                return;
496
-            }
497
-            // lock the transaction
498
-            $this->checkout->transaction->lock();
499
-            // make sure all of our cached objects are added to their respective model entity mappers
500
-            $this->checkout->refresh_all_entities();
501
-            // set amount owing
502
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
503
-            // initialize each reg step, which gives them the chance to potentially alter the process
504
-            $this->_initialize_reg_steps();
505
-            // DEBUG LOG
506
-            //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
507
-            // get reg form
508
-            if( ! $this->_check_form_submission()) {
509
-                EED_Single_Page_Checkout::$_initialized = true;
510
-                return;
511
-            }
512
-            // checkout the action!!!
513
-            $this->_process_form_action();
514
-            // add some style and make it dance
515
-            $this->add_styles_and_scripts();
516
-            // kk... SPCO has successfully run
517
-            EED_Single_Page_Checkout::$_initialized = true;
518
-            // set no cache headers and constants
519
-            EE_System::do_not_cache();
520
-            // add anchor
521
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
522
-            // remove transaction lock
523
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
524
-        } catch (Exception $e) {
525
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
526
-        }
527
-    }
528
-
529
-
530
-
531
-    /**
532
-     *    _verify_session
533
-     * checks that the session is valid and not expired
534
-     *
535
-     * @access    private
536
-     * @throws EE_Error
537
-     */
538
-    private function _verify_session()
539
-    {
540
-        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
541
-            throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
542
-        }
543
-        $clear_session_requested = filter_var(
544
-            EE_Registry::instance()->REQ->get('clear_session', false),
545
-            FILTER_VALIDATE_BOOLEAN
546
-        );
547
-        // is session still valid ?
548
-        if ($clear_session_requested
549
-            || ( EE_Registry::instance()->SSN->expired()
550
-              && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
551
-            )
552
-        ) {
553
-            $this->checkout = new EE_Checkout();
554
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
555
-            // EE_Registry::instance()->SSN->reset_cart();
556
-            // EE_Registry::instance()->SSN->reset_checkout();
557
-            // EE_Registry::instance()->SSN->reset_transaction();
558
-            if (! $clear_session_requested) {
559
-                EE_Error::add_attention(
560
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
561
-                    __FILE__, __FUNCTION__, __LINE__
562
-                );
563
-            }
564
-            // EE_Registry::instance()->SSN->reset_expired();
565
-        }
566
-    }
567
-
568
-
569
-
570
-    /**
571
-     *    _initialize_checkout
572
-     * loads and instantiates EE_Checkout
573
-     *
574
-     * @access    private
575
-     * @throws EE_Error
576
-     * @return EE_Checkout
577
-     */
578
-    private function _initialize_checkout()
579
-    {
580
-        // look in session for existing checkout
581
-        /** @type EE_Checkout $checkout */
582
-        $checkout = EE_Registry::instance()->SSN->checkout();
583
-        // verify
584
-        if ( ! $checkout instanceof EE_Checkout) {
585
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
586
-            $checkout = EE_Registry::instance()->load_file(
587
-                SPCO_INC_PATH,
588
-                'EE_Checkout',
589
-                'class', array(),
590
-                false
591
-            );
592
-        } else {
593
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
594
-                $this->unlock_transaction();
595
-                wp_safe_redirect($checkout->redirect_url);
596
-                exit();
597
-            }
598
-        }
599
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
600
-        // verify again
601
-        if ( ! $checkout instanceof EE_Checkout) {
602
-            throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
603
-        }
604
-        // reset anything that needs a clean slate for each request
605
-        $checkout->reset_for_current_request();
606
-        return $checkout;
607
-    }
608
-
609
-
610
-
611
-    /**
612
-     *    _get_request_vars
613
-     *
614
-     * @access    private
615
-     * @return    void
616
-     * @throws EE_Error
617
-     */
618
-    private function _get_request_vars()
619
-    {
620
-        // load classes
621
-        EED_Single_Page_Checkout::load_request_handler();
622
-        //make sure this request is marked as belonging to EE
623
-        EE_Registry::instance()->REQ->set_espresso_page(true);
624
-        // which step is being requested ?
625
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
626
-        // which step is being edited ?
627
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
628
-        // and what we're doing on the current step
629
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
630
-        // timestamp
631
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
632
-        // returning to edit ?
633
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
634
-        // add reg url link to registration query params
635
-        if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
636
-            $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
637
-        }
638
-        // or some other kind of revisit ?
639
-        $this->checkout->revisit = filter_var(
640
-            EE_Registry::instance()->REQ->get('revisit', false),
641
-            FILTER_VALIDATE_BOOLEAN
642
-        );
643
-        // and whether or not to generate a reg form for this request
644
-        $this->checkout->generate_reg_form = filter_var(
645
-            EE_Registry::instance()->REQ->get('generate_reg_form', true),
646
-            FILTER_VALIDATE_BOOLEAN
647
-        );
648
-        // and whether or not to process a reg form submission for this request
649
-        $this->checkout->process_form_submission = filter_var(
650
-            EE_Registry::instance()->REQ->get(
651
-                'process_form_submission',
652
-                $this->checkout->action === 'process_reg_step'
653
-            ),
654
-            FILTER_VALIDATE_BOOLEAN
655
-        );
656
-        $this->checkout->process_form_submission = filter_var(
657
-            $this->checkout->action !== 'display_spco_reg_step'
658
-                ? $this->checkout->process_form_submission
659
-                : false,
660
-            FILTER_VALIDATE_BOOLEAN
661
-        );
662
-        // $this->_display_request_vars();
663
-    }
664
-
665
-
666
-
667
-    /**
668
-     *  _display_request_vars
669
-     *
670
-     * @access    protected
671
-     * @return    void
672
-     */
673
-    protected function _display_request_vars()
674
-    {
675
-        if ( ! WP_DEBUG) {
676
-            return;
677
-        }
678
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
679
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
680
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
681
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
682
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
683
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
684
-        EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
685
-        EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * _block_bots
692
-     * checks that the incoming request has either of the following set:
693
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
694
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
695
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
696
-     * then where you coming from man?
697
-     *
698
-     * @return boolean
699
-     */
700
-    private function _block_bots()
701
-    {
702
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
703
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
704
-            return true;
705
-        }
706
-        return false;
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     *    _get_first_step
713
-     *  gets slug for first step in $_reg_steps_array
714
-     *
715
-     * @access    private
716
-     * @throws EE_Error
717
-     * @return    string
718
-     */
719
-    private function _get_first_step()
720
-    {
721
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
722
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
723
-    }
724
-
725
-
726
-
727
-    /**
728
-     *    _load_and_instantiate_reg_steps
729
-     *  instantiates each reg step based on the loaded reg_steps array
730
-     *
731
-     * @access    private
732
-     * @throws EE_Error
733
-     * @return    bool
734
-     */
735
-    private function _load_and_instantiate_reg_steps()
736
-    {
737
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
738
-        // have reg_steps already been instantiated ?
739
-        if (
740
-            empty($this->checkout->reg_steps)
741
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
742
-        ) {
743
-            // if not, then loop through raw reg steps array
744
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
745
-                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
746
-                    return false;
747
-                }
748
-            }
749
-            EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
750
-            EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
751
-            // skip the registration_confirmation page ?
752
-            if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
753
-                // just remove it from the reg steps array
754
-                $this->checkout->remove_reg_step('registration_confirmation', false);
755
-            } else if (
756
-                isset($this->checkout->reg_steps['registration_confirmation'])
757
-                && EE_Registry::instance()->CFG->registration->reg_confirmation_last
758
-            ) {
759
-                // set the order to something big like 100
760
-                $this->checkout->set_reg_step_order('registration_confirmation', 100);
761
-            }
762
-            // filter the array for good luck
763
-            $this->checkout->reg_steps = apply_filters(
764
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
765
-                $this->checkout->reg_steps
766
-            );
767
-            // finally re-sort based on the reg step class order properties
768
-            $this->checkout->sort_reg_steps();
769
-        } else {
770
-            foreach ($this->checkout->reg_steps as $reg_step) {
771
-                // set all current step stati to FALSE
772
-                $reg_step->set_is_current_step(false);
773
-            }
774
-        }
775
-        if (empty($this->checkout->reg_steps)) {
776
-            EE_Error::add_error(
777
-                __('No Reg Steps were loaded..', 'event_espresso'),
778
-                __FILE__, __FUNCTION__, __LINE__
779
-            );
780
-            return false;
781
-        }
782
-        // make reg step details available to JS
783
-        $this->checkout->set_reg_step_JSON_info();
784
-        return true;
785
-    }
786
-
787
-
788
-
789
-    /**
790
-     *     _load_and_instantiate_reg_step
791
-     *
792
-     * @access    private
793
-     * @param array $reg_step
794
-     * @param int   $order
795
-     * @return bool
796
-     */
797
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
798
-    {
799
-        // we need a file_path, class_name, and slug to add a reg step
800
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
801
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
802
-            if (
803
-                $this->checkout->reg_url_link
804
-                && $this->checkout->step !== $reg_step['slug']
805
-                && $reg_step['slug'] !== 'finalize_registration'
806
-                // normally at this point we would NOT load the reg step, but this filter can change that
807
-                && apply_filters(
808
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
809
-                    true,
810
-                    $reg_step,
811
-                    $this->checkout
812
-                )
813
-            ) {
814
-                return true;
815
-            }
816
-            // instantiate step class using file path and class name
817
-            $reg_step_obj = EE_Registry::instance()->load_file(
818
-                $reg_step['file_path'],
819
-                $reg_step['class_name'],
820
-                'class',
821
-                $this->checkout,
822
-                false
823
-            );
824
-            // did we gets the goods ?
825
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
826
-                // set reg step order based on config
827
-                $reg_step_obj->set_order($order);
828
-                // add instantiated reg step object to the master reg steps array
829
-                $this->checkout->add_reg_step($reg_step_obj);
830
-            } else {
831
-                EE_Error::add_error(
832
-                    __('The current step could not be set.', 'event_espresso'),
833
-                    __FILE__, __FUNCTION__, __LINE__
834
-                );
835
-                return false;
836
-            }
837
-        } else {
838
-            if (WP_DEBUG) {
839
-                EE_Error::add_error(
840
-                    sprintf(
841
-                        __(
842
-                            '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',
843
-                            'event_espresso'
844
-                        ),
845
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
846
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
847
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
848
-                        '<ul>',
849
-                        '<li>',
850
-                        '</li>',
851
-                        '</ul>'
852
-                    ),
853
-                    __FILE__, __FUNCTION__, __LINE__
854
-                );
855
-            }
856
-            return false;
857
-        }
858
-        return true;
859
-    }
860
-
861
-
862
-    /**
863
-     * _verify_transaction_and_get_registrations
864
-     *
865
-     * @access private
866
-     * @return bool
867
-     * @throws InvalidDataTypeException
868
-     * @throws InvalidEntityException
869
-     * @throws EE_Error
870
-     */
871
-    private function _verify_transaction_and_get_registrations()
872
-    {
873
-        // was there already a valid transaction in the checkout from the session ?
874
-        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
875
-            // get transaction from db or session
876
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
877
-                ? $this->_get_transaction_and_cart_for_previous_visit()
878
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
879
-            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
880
-                EE_Error::add_error(
881
-                    __('Your Registration and Transaction information could not be retrieved from the db.',
882
-                        'event_espresso'),
883
-                    __FILE__, __FUNCTION__, __LINE__
884
-                );
885
-                $this->checkout->transaction = EE_Transaction::new_instance();
886
-                // add some style and make it dance
887
-                $this->add_styles_and_scripts();
888
-                EED_Single_Page_Checkout::$_initialized = true;
889
-                return false;
890
-            }
891
-            // and the registrations for the transaction
892
-            $this->_get_registrations($this->checkout->transaction);
893
-        }
894
-        return true;
895
-    }
896
-
897
-
898
-
899
-    /**
900
-     * _get_transaction_and_cart_for_previous_visit
901
-     *
902
-     * @access private
903
-     * @return mixed EE_Transaction|NULL
904
-     */
905
-    private function _get_transaction_and_cart_for_previous_visit()
906
-    {
907
-        /** @var $TXN_model EEM_Transaction */
908
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
909
-        // because the reg_url_link is present in the request,
910
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
911
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
912
-        // verify transaction
913
-        if ($transaction instanceof EE_Transaction) {
914
-            // and get the cart that was used for that transaction
915
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
916
-            return $transaction;
917
-        }
918
-        EE_Error::add_error(
919
-            __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
920
-            __FILE__, __FUNCTION__, __LINE__
921
-        );
922
-        return null;
923
-
924
-    }
925
-
926
-
927
-
928
-    /**
929
-     * _get_cart_for_transaction
930
-     *
931
-     * @access private
932
-     * @param EE_Transaction $transaction
933
-     * @return EE_Cart
934
-     */
935
-    private function _get_cart_for_transaction($transaction)
936
-    {
937
-        return $this->checkout->get_cart_for_transaction($transaction);
938
-    }
939
-
940
-
941
-
942
-    /**
943
-     * get_cart_for_transaction
944
-     *
945
-     * @access public
946
-     * @param EE_Transaction $transaction
947
-     * @return EE_Cart
948
-     */
949
-    public function get_cart_for_transaction(EE_Transaction $transaction)
950
-    {
951
-        return $this->checkout->get_cart_for_transaction($transaction);
952
-    }
953
-
954
-
955
-
956
-    /**
957
-     * _get_transaction_and_cart_for_current_session
958
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
959
-     *
960
-     * @access private
961
-     * @return EE_Transaction
962
-     * @throws EE_Error
963
-     */
964
-    private function _get_cart_for_current_session_and_setup_new_transaction()
965
-    {
966
-        //  if there's no transaction, then this is the FIRST visit to SPCO
967
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
968
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
969
-        // and then create a new transaction
970
-        $transaction = $this->_initialize_transaction();
971
-        // verify transaction
972
-        if ($transaction instanceof EE_Transaction) {
973
-            // save it so that we have an ID for other objects to use
974
-            $transaction->save();
975
-            // and save TXN data to the cart
976
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
977
-        } else {
978
-            EE_Error::add_error(
979
-                __('A Valid Transaction could not be initialized.', 'event_espresso'),
980
-                __FILE__, __FUNCTION__, __LINE__
981
-            );
982
-        }
983
-        return $transaction;
984
-    }
985
-
986
-
987
-
988
-    /**
989
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
990
-     *
991
-     * @access private
992
-     * @return mixed EE_Transaction|NULL
993
-     */
994
-    private function _initialize_transaction()
995
-    {
996
-        try {
997
-            // ensure cart totals have been calculated
998
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
999
-            // grab the cart grand total
1000
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
1001
-            // create new TXN
1002
-            $transaction = EE_Transaction::new_instance(
1003
-                array(
1004
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1005
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1006
-                    'TXN_paid'      => 0,
1007
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
1008
-                )
1009
-            );
1010
-            // save it so that we have an ID for other objects to use
1011
-            $transaction->save();
1012
-            // set cron job for following up on TXNs after their session has expired
1013
-            EE_Cron_Tasks::schedule_expired_transaction_check(
1014
-                EE_Registry::instance()->SSN->expiration() + 1,
1015
-                $transaction->ID()
1016
-            );
1017
-            return $transaction;
1018
-        } catch (Exception $e) {
1019
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1020
-        }
1021
-        return null;
1022
-    }
1023
-
1024
-
1025
-    /**
1026
-     * _get_registrations
1027
-     *
1028
-     * @access private
1029
-     * @param EE_Transaction $transaction
1030
-     * @return void
1031
-     * @throws InvalidDataTypeException
1032
-     * @throws InvalidEntityException
1033
-     * @throws EE_Error
1034
-     */
1035
-    private function _get_registrations(EE_Transaction $transaction)
1036
-    {
1037
-        // first step: grab the registrants  { : o
1038
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1039
-        $this->checkout->total_ticket_count = count($registrations);
1040
-        // verify registrations have been set
1041
-        if (empty($registrations)) {
1042
-            // if no cached registrations, then check the db
1043
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1044
-            // still nothing ? well as long as this isn't a revisit
1045
-            if (empty($registrations) && ! $this->checkout->revisit) {
1046
-                // generate new registrations from scratch
1047
-                $registrations = $this->_initialize_registrations($transaction);
1048
-            }
1049
-        }
1050
-        // sort by their original registration order
1051
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1052
-        // then loop thru the array
1053
-        foreach ($registrations as $registration) {
1054
-            // verify each registration
1055
-            if ($registration instanceof EE_Registration) {
1056
-                // we display all attendee info for the primary registrant
1057
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
1058
-                    && $registration->is_primary_registrant()
1059
-                ) {
1060
-                    $this->checkout->primary_revisit = true;
1061
-                    break;
1062
-                }
1063
-                if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1064
-                    // but hide info if it doesn't belong to you
1065
-                    $transaction->clear_cache('Registration', $registration->ID());
1066
-                    $this->checkout->total_ticket_count--;
1067
-                }
1068
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1069
-            }
1070
-        }
1071
-    }
1072
-
1073
-
1074
-    /**
1075
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1076
-     *
1077
-     * @access private
1078
-     * @param EE_Transaction $transaction
1079
-     * @return    array
1080
-     * @throws InvalidDataTypeException
1081
-     * @throws InvalidEntityException
1082
-     * @throws EE_Error
1083
-     */
1084
-    private function _initialize_registrations(EE_Transaction $transaction)
1085
-    {
1086
-        $att_nmbr = 0;
1087
-        $registrations = array();
1088
-        if ($transaction instanceof EE_Transaction) {
1089
-            /** @type EE_Registration_Processor $registration_processor */
1090
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1091
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1092
-            // now let's add the cart items to the $transaction
1093
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1094
-                //do the following for each ticket of this type they selected
1095
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1096
-                    $att_nmbr++;
1097
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1098
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1099
-                        'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1100
-                        array(
1101
-                            $transaction,
1102
-                            $line_item,
1103
-                            $att_nmbr,
1104
-                            $this->checkout->total_ticket_count,
1105
-                        )
1106
-                    );
1107
-                    // override capabilities for frontend registrations
1108
-                    if ( ! is_admin()) {
1109
-                        $CreateRegistrationCommand->setCapCheck(
1110
-                            new PublicCapabilities('', 'create_new_registration')
1111
-                        );
1112
-                    }
1113
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1114
-                    if ( ! $registration instanceof EE_Registration) {
1115
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1116
-                    }
1117
-                    $registrations[ $registration->ID() ] = $registration;
1118
-                }
1119
-            }
1120
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1121
-        }
1122
-        return $registrations;
1123
-    }
1124
-
1125
-
1126
-
1127
-    /**
1128
-     * sorts registrations by REG_count
1129
-     *
1130
-     * @access public
1131
-     * @param EE_Registration $reg_A
1132
-     * @param EE_Registration $reg_B
1133
-     * @return int
1134
-     */
1135
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1136
-    {
1137
-        // this shouldn't ever happen within the same TXN, but oh well
1138
-        if ($reg_A->count() === $reg_B->count()) {
1139
-            return 0;
1140
-        }
1141
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1142
-    }
1143
-
1144
-
1145
-
1146
-    /**
1147
-     *    _final_verifications
1148
-     * just makes sure that everything is set up correctly before proceeding
1149
-     *
1150
-     * @access    private
1151
-     * @return    bool
1152
-     * @throws EE_Error
1153
-     */
1154
-    private function _final_verifications()
1155
-    {
1156
-        // filter checkout
1157
-        $this->checkout = apply_filters(
1158
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1159
-            $this->checkout
1160
-        );
1161
-        //verify that current step is still set correctly
1162
-        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1163
-            EE_Error::add_error(
1164
-                __('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.', 'event_espresso'),
1165
-                __FILE__,
1166
-                __FUNCTION__,
1167
-                __LINE__
1168
-            );
1169
-            return false;
1170
-        }
1171
-        // if returning to SPCO, then verify that primary registrant is set
1172
-        if ( ! empty($this->checkout->reg_url_link)) {
1173
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1174
-            if ( ! $valid_registrant instanceof EE_Registration) {
1175
-                EE_Error::add_error(
1176
-                    __('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.', 'event_espresso'),
1177
-                    __FILE__,
1178
-                    __FUNCTION__,
1179
-                    __LINE__
1180
-                );
1181
-                return false;
1182
-            }
1183
-            $valid_registrant = null;
1184
-            foreach (
1185
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1186
-            ) {
1187
-                if (
1188
-                    $registration instanceof EE_Registration
1189
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1190
-                ) {
1191
-                    $valid_registrant = $registration;
1192
-                }
1193
-            }
1194
-            if ( ! $valid_registrant instanceof EE_Registration) {
1195
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1196
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1197
-                    // clear the session, mark the checkout as unverified, and try again
1198
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1199
-                    EED_Single_Page_Checkout::$_initialized = false;
1200
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1201
-                    $this->_initialize();
1202
-                    EE_Error::reset_notices();
1203
-                    return false;
1204
-                }
1205
-                EE_Error::add_error(
1206
-                    __(
1207
-                        '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.',
1208
-                        'event_espresso'
1209
-                    ),
1210
-                    __FILE__,
1211
-                    __FUNCTION__,
1212
-                    __LINE__
1213
-                );
1214
-                return false;
1215
-            }
1216
-        }
1217
-        // now that things have been kinda sufficiently verified,
1218
-        // let's add the checkout to the session so that it's available to other systems
1219
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1220
-        return true;
1221
-    }
1222
-
1223
-
1224
-
1225
-    /**
1226
-     *    _initialize_reg_steps
1227
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1228
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1229
-     *
1230
-     * @access    private
1231
-     * @param bool $reinitializing
1232
-     * @throws EE_Error
1233
-     */
1234
-    private function _initialize_reg_steps($reinitializing = false)
1235
-    {
1236
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1237
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1238
-        foreach ($this->checkout->reg_steps as $reg_step) {
1239
-            if ( ! $reg_step->initialize_reg_step()) {
1240
-                // if not initialized then maybe this step is being removed...
1241
-                if ( ! $reinitializing && $reg_step->is_current_step()) {
1242
-                    // if it was the current step, then we need to start over here
1243
-                    $this->_initialize_reg_steps(true);
1244
-                    return;
1245
-                }
1246
-                continue;
1247
-            }
1248
-            // add css and JS for current step
1249
-            $reg_step->enqueue_styles_and_scripts();
1250
-            // i18n
1251
-            $reg_step->translate_js_strings();
1252
-            if ($reg_step->is_current_step()) {
1253
-                // the text that appears on the reg step form submit button
1254
-                $reg_step->set_submit_button_text();
1255
-            }
1256
-        }
1257
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1258
-        do_action(
1259
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1260
-            $this->checkout->current_step
1261
-        );
1262
-    }
1263
-
1264
-
1265
-
1266
-    /**
1267
-     * _check_form_submission
1268
-     *
1269
-     * @access private
1270
-     * @return boolean
1271
-     */
1272
-    private function _check_form_submission()
1273
-    {
1274
-        //does this request require the reg form to be generated ?
1275
-        if ($this->checkout->generate_reg_form) {
1276
-            // ever heard that song by Blue Rodeo ?
1277
-            try {
1278
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1279
-                // if not displaying a form, then check for form submission
1280
-                if (
1281
-                    $this->checkout->process_form_submission
1282
-                    && $this->checkout->current_step->reg_form->was_submitted()
1283
-                ) {
1284
-                    // clear out any old data in case this step is being run again
1285
-                    $this->checkout->current_step->set_valid_data(array());
1286
-                    // capture submitted form data
1287
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1288
-                        apply_filters(
1289
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1290
-                            EE_Registry::instance()->REQ->params(),
1291
-                            $this->checkout
1292
-                        )
1293
-                    );
1294
-                    // validate submitted form data
1295
-                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1296
-                        // thou shall not pass !!!
1297
-                        $this->checkout->continue_reg = false;
1298
-                        // any form validation errors?
1299
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1300
-                            EE_Error::add_error(
1301
-                                $this->checkout->current_step->reg_form->submission_error_message(),
1302
-                                __FILE__, __FUNCTION__, __LINE__
1303
-                            );
1304
-                        }
1305
-                        // well not really... what will happen is
1306
-                        // we'll just get redirected back to redo the current step
1307
-                        $this->go_to_next_step();
1308
-                        return false;
1309
-                    }
1310
-                }
1311
-            } catch (EE_Error $e) {
1312
-                $e->get_error();
1313
-            }
1314
-        }
1315
-        return true;
1316
-    }
1317
-
1318
-
1319
-
1320
-    /**
1321
-     * _process_action
1322
-     *
1323
-     * @access private
1324
-     * @return void
1325
-     * @throws EE_Error
1326
-     */
1327
-    private function _process_form_action()
1328
-    {
1329
-        // what cha wanna do?
1330
-        switch ($this->checkout->action) {
1331
-            // AJAX next step reg form
1332
-            case 'display_spco_reg_step' :
1333
-                $this->checkout->redirect = false;
1334
-                if (EE_Registry::instance()->REQ->ajax) {
1335
-                    $this->checkout->json_response->set_reg_step_html(
1336
-                        $this->checkout->current_step->display_reg_form()
1337
-                    );
1338
-                }
1339
-                break;
1340
-            default :
1341
-                // meh... do one of those other steps first
1342
-                if (
1343
-                    ! empty($this->checkout->action)
1344
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1345
-                ) {
1346
-                    // dynamically creates hook point like:
1347
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1348
-                    do_action(
1349
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1350
-                        $this->checkout->current_step
1351
-                    );
1352
-                    // call action on current step
1353
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1354
-                        // good registrant, you get to proceed
1355
-                        if (
1356
-                            $this->checkout->current_step->success_message() !== ''
1357
-                            && apply_filters(
1358
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1359
-                                false
1360
-                            )
1361
-                        ) {
1362
-                            EE_Error::add_success(
1363
-                                $this->checkout->current_step->success_message()
1364
-                                . '<br />' . $this->checkout->next_step->_instructions()
1365
-                            );
1366
-                        }
1367
-                        // pack it up, pack it in...
1368
-                        $this->_setup_redirect();
1369
-                    }
1370
-                    // dynamically creates hook point like:
1371
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1372
-                    do_action(
1373
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1374
-                        $this->checkout->current_step
1375
-                    );
1376
-                } else {
1377
-                    EE_Error::add_error(
1378
-                        sprintf(
1379
-                            __(
1380
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1381
-                                'event_espresso'
1382
-                            ),
1383
-                            $this->checkout->action,
1384
-                            $this->checkout->current_step->name()
1385
-                        ),
1386
-                        __FILE__,
1387
-                        __FUNCTION__,
1388
-                        __LINE__
1389
-                    );
1390
-                }
1391
-            // end default
1392
-        }
1393
-        // store our progress so far
1394
-        $this->checkout->stash_transaction_and_checkout();
1395
-        // advance to the next step! If you pass GO, collect $200
1396
-        $this->go_to_next_step();
1397
-    }
1398
-
1399
-
1400
-
1401
-    /**
1402
-     *        add_styles_and_scripts
1403
-     *
1404
-     * @access        public
1405
-     * @return        void
1406
-     */
1407
-    public function add_styles_and_scripts()
1408
-    {
1409
-        // i18n
1410
-        $this->translate_js_strings();
1411
-        if ($this->checkout->admin_request) {
1412
-            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1413
-        } else {
1414
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1415
-        }
1416
-    }
1417
-
1418
-
1419
-
1420
-    /**
1421
-     *        translate_js_strings
1422
-     *
1423
-     * @access        public
1424
-     * @return        void
1425
-     */
1426
-    public function translate_js_strings()
1427
-    {
1428
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1429
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1430
-        EE_Registry::$i18n_js_strings['server_error'] = __(
1431
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1432
-            'event_espresso'
1433
-        );
1434
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1435
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1436
-            'event_espresso'
1437
-        );
1438
-        EE_Registry::$i18n_js_strings['validation_error'] = __(
1439
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1440
-            'event_espresso'
1441
-        );
1442
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1443
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1444
-            'event_espresso'
1445
-        );
1446
-        EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1447
-            'This registration step could not be completed. Please refresh the page and try again.',
1448
-            'event_espresso'
1449
-        );
1450
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1451
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1452
-            'event_espresso'
1453
-        );
1454
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1455
-            __(
1456
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1457
-                'event_espresso'
1458
-            ),
1459
-            '<br/>',
1460
-            '<br/>'
1461
-        );
1462
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1463
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1464
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1465
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1466
-        EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1467
-        EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1468
-        EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1469
-        EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1470
-        EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1471
-        EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1472
-        EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1473
-        EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1474
-        EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1475
-        EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1476
-        EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1477
-        EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1478
-        EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1479
-        EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1480
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
1481
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1482
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1483
-            true
1484
-        );
1485
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1486
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1487
-        );
1488
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1489
-            'M d, Y H:i:s',
1490
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1491
-        );
1492
-    }
1493
-
1494
-
1495
-
1496
-    /**
1497
-     *    enqueue_styles_and_scripts
1498
-     *
1499
-     * @access        public
1500
-     * @return        void
1501
-     * @throws EE_Error
1502
-     */
1503
-    public function enqueue_styles_and_scripts()
1504
-    {
1505
-        // load css
1506
-        wp_register_style(
1507
-            'single_page_checkout',
1508
-            SPCO_CSS_URL . 'single_page_checkout.css',
1509
-            array('espresso_default'),
1510
-            EVENT_ESPRESSO_VERSION
1511
-        );
1512
-        wp_enqueue_style('single_page_checkout');
1513
-        // load JS
1514
-        wp_register_script(
1515
-            'jquery_plugin',
1516
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1517
-            array('jquery'),
1518
-            '1.0.1',
1519
-            true
1520
-        );
1521
-        wp_register_script(
1522
-            'jquery_countdown',
1523
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1524
-            array('jquery_plugin'),
1525
-            '2.0.2',
1526
-            true
1527
-        );
1528
-        wp_register_script(
1529
-            'single_page_checkout',
1530
-            SPCO_JS_URL . 'single_page_checkout.js',
1531
-            array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1532
-            EVENT_ESPRESSO_VERSION,
1533
-            true
1534
-        );
1535
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1536
-            $this->checkout->registration_form->enqueue_js();
1537
-        }
1538
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1539
-            $this->checkout->current_step->reg_form->enqueue_js();
1540
-        }
1541
-        wp_enqueue_script('single_page_checkout');
1542
-        /**
1543
-         * global action hook for enqueueing styles and scripts with
1544
-         * spco calls.
1545
-         */
1546
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1547
-        /**
1548
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1549
-         * The hook will end up being something like:
1550
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1551
-         */
1552
-        do_action(
1553
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1554
-            $this
1555
-        );
1556
-    }
1557
-
1558
-
1559
-
1560
-    /**
1561
-     *    display the Registration Single Page Checkout Form
1562
-     *
1563
-     * @access    private
1564
-     * @return    void
1565
-     * @throws EE_Error
1566
-     */
1567
-    private function _display_spco_reg_form()
1568
-    {
1569
-        // if registering via the admin, just display the reg form for the current step
1570
-        if ($this->checkout->admin_request) {
1571
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1572
-        } else {
1573
-            // add powered by EE msg
1574
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1575
-            $empty_cart = count(
1576
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1577
-            ) < 1;
1578
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1579
-            $cookies_not_set_msg = '';
1580
-            if ($empty_cart) {
1581
-                $cookies_not_set_msg = apply_filters(
1582
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1583
-                    sprintf(
1584
-                        __(
1585
-                            '%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',
1586
-                            'event_espresso'
1587
-                        ),
1588
-                        '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1589
-                        '</div>',
1590
-                        '<h6 class="important-notice">',
1591
-                        '</h6>',
1592
-                        '<p>',
1593
-                        '</p>',
1594
-                        '<br />',
1595
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1596
-                        '</a>'
1597
-                    )
1598
-                );
1599
-            }
1600
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1601
-                array(
1602
-                    'name'            => 'single-page-checkout',
1603
-                    'html_id'         => 'ee-single-page-checkout-dv',
1604
-                    'layout_strategy' =>
1605
-                        new EE_Template_Layout(
1606
-                            array(
1607
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1608
-                                'template_args'        => array(
1609
-                                    'empty_cart'              => $empty_cart,
1610
-                                    'revisit'                 => $this->checkout->revisit,
1611
-                                    'reg_steps'               => $this->checkout->reg_steps,
1612
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1613
-                                        ? $this->checkout->next_step->slug()
1614
-                                        : '',
1615
-                                    'empty_msg'               => apply_filters(
1616
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1617
-                                        sprintf(
1618
-                                            __(
1619
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1620
-                                                'event_espresso'
1621
-                                            ),
1622
-                                            '<a href="'
1623
-                                            . get_post_type_archive_link('espresso_events')
1624
-                                            . '" title="',
1625
-                                            '">',
1626
-                                            '</a>'
1627
-                                        )
1628
-                                    ),
1629
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1630
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1631
-                                    'session_expiration'      => gmdate(
1632
-                                        'M d, Y H:i:s',
1633
-                                        EE_Registry::instance()->SSN->expiration()
1634
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1635
-                                    ),
1636
-                                ),
1637
-                            )
1638
-                        ),
1639
-                )
1640
-            );
1641
-            // load template and add to output sent that gets filtered into the_content()
1642
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1643
-        }
1644
-    }
1645
-
1646
-
1647
-
1648
-    /**
1649
-     *    add_extra_finalize_registration_inputs
1650
-     *
1651
-     * @access    public
1652
-     * @param $next_step
1653
-     * @internal  param string $label
1654
-     * @return void
1655
-     */
1656
-    public function add_extra_finalize_registration_inputs($next_step)
1657
-    {
1658
-        if ($next_step === 'finalize_registration') {
1659
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1660
-        }
1661
-    }
1662
-
1663
-
1664
-
1665
-    /**
1666
-     *    display_registration_footer
1667
-     *
1668
-     * @access    public
1669
-     * @return    string
1670
-     */
1671
-    public static function display_registration_footer()
1672
-    {
1673
-        if (
1674
-        apply_filters(
1675
-            'FHEE__EE_Front__Controller__show_reg_footer',
1676
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1677
-        )
1678
-        ) {
1679
-            add_filter(
1680
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1681
-                function ($url) {
1682
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1683
-                }
1684
-            );
1685
-            echo apply_filters(
1686
-                'FHEE__EE_Front_Controller__display_registration_footer',
1687
-                \EEH_Template::powered_by_event_espresso(
1688
-                    '',
1689
-                    'espresso-registration-footer-dv',
1690
-                    array('utm_content' => 'registration_checkout')
1691
-                )
1692
-            );
1693
-        }
1694
-        return '';
1695
-    }
1696
-
1697
-
1698
-
1699
-    /**
1700
-     *    unlock_transaction
1701
-     *
1702
-     * @access    public
1703
-     * @return    void
1704
-     * @throws EE_Error
1705
-     */
1706
-    public function unlock_transaction()
1707
-    {
1708
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1709
-            $this->checkout->transaction->unlock();
1710
-        }
1711
-    }
1712
-
1713
-
1714
-
1715
-    /**
1716
-     *        _setup_redirect
1717
-     *
1718
-     * @access    private
1719
-     * @return void
1720
-     */
1721
-    private function _setup_redirect()
1722
-    {
1723
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1724
-            $this->checkout->redirect = true;
1725
-            if (empty($this->checkout->redirect_url)) {
1726
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1727
-            }
1728
-            $this->checkout->redirect_url = apply_filters(
1729
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1730
-                $this->checkout->redirect_url,
1731
-                $this->checkout
1732
-            );
1733
-        }
1734
-    }
1735
-
1736
-
1737
-
1738
-    /**
1739
-     *   handle ajax message responses and redirects
1740
-     *
1741
-     * @access public
1742
-     * @return void
1743
-     * @throws EE_Error
1744
-     */
1745
-    public function go_to_next_step()
1746
-    {
1747
-        if (EE_Registry::instance()->REQ->ajax) {
1748
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1749
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1750
-        }
1751
-        $this->unlock_transaction();
1752
-        // just return for these conditions
1753
-        if (
1754
-            $this->checkout->admin_request
1755
-            || $this->checkout->action === 'redirect_form'
1756
-            || $this->checkout->action === 'update_checkout'
1757
-        ) {
1758
-            return;
1759
-        }
1760
-        // AJAX response
1761
-        $this->_handle_json_response();
1762
-        // redirect to next step or the Thank You page
1763
-        $this->_handle_html_redirects();
1764
-        // hmmm... must be something wrong, so let's just display the form again !
1765
-        $this->_display_spco_reg_form();
1766
-    }
1767
-
1768
-
1769
-
1770
-    /**
1771
-     *   _handle_json_response
1772
-     *
1773
-     * @access protected
1774
-     * @return void
1775
-     */
1776
-    protected function _handle_json_response()
1777
-    {
1778
-        // if this is an ajax request
1779
-        if (EE_Registry::instance()->REQ->ajax) {
1780
-            // DEBUG LOG
1781
-            //$this->checkout->log(
1782
-            //	__CLASS__, __FUNCTION__, __LINE__,
1783
-            //	array(
1784
-            //		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1785
-            //		'redirect'                   => $this->checkout->redirect,
1786
-            //		'continue_reg'               => $this->checkout->continue_reg,
1787
-            //	)
1788
-            //);
1789
-            $this->checkout->json_response->set_registration_time_limit(
1790
-                $this->checkout->get_registration_time_limit()
1791
-            );
1792
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1793
-            // just send the ajax (
1794
-            $json_response = apply_filters(
1795
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1796
-                $this->checkout->json_response
1797
-            );
1798
-            echo $json_response;
1799
-            exit();
1800
-        }
1801
-    }
1802
-
1803
-
1804
-
1805
-    /**
1806
-     *   _handle_redirects
1807
-     *
1808
-     * @access protected
1809
-     * @return void
1810
-     */
1811
-    protected function _handle_html_redirects()
1812
-    {
1813
-        // going somewhere ?
1814
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1815
-            // store notices in a transient
1816
-            EE_Error::get_notices(false, true, true);
1817
-            // DEBUG LOG
1818
-            //$this->checkout->log(
1819
-            //	__CLASS__, __FUNCTION__, __LINE__,
1820
-            //	array(
1821
-            //		'headers_sent' => headers_sent(),
1822
-            //		'redirect_url'     => $this->checkout->redirect_url,
1823
-            //		'headers_list'    => headers_list(),
1824
-            //	)
1825
-            //);
1826
-            wp_safe_redirect($this->checkout->redirect_url);
1827
-            exit();
1828
-        }
1829
-    }
1830
-
1831
-
1832
-
1833
-    /**
1834
-     *   set_checkout_anchor
1835
-     *
1836
-     * @access public
1837
-     * @return void
1838
-     */
1839
-    public function set_checkout_anchor()
1840
-    {
1841
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1842
-    }
1843
-
1844
-    /**
1845
-     *    getRegistrationExpirationNotice
1846
-     *
1847
-     * @since $VID:$
1848
-     * @access    public
1849
-     * @return    string
1850
-     */
1851
-    public static function getRegistrationExpirationNotice()
1852
-    {
1853
-        return sprintf(
1854
-            __('%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',
1855
-                'event_espresso'),
1856
-            '<h4 class="important-notice">',
1857
-            '</h4>',
1858
-            '<br />',
1859
-            '<p>',
1860
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1861
-            '">',
1862
-            '</a>',
1863
-            '</p>'
1864
-        );
1865
-    }
23
+	/**
24
+	 * $_initialized - has the SPCO controller already been initialized ?
25
+	 *
26
+	 * @access private
27
+	 * @var bool $_initialized
28
+	 */
29
+	private static $_initialized = false;
30
+
31
+
32
+	/**
33
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
+	 *
35
+	 * @access private
36
+	 * @var bool $_valid_checkout
37
+	 */
38
+	private static $_checkout_verified = true;
39
+
40
+	/**
41
+	 *    $_reg_steps_array - holds initial array of reg steps
42
+	 *
43
+	 * @access private
44
+	 * @var array $_reg_steps_array
45
+	 */
46
+	private static $_reg_steps_array = array();
47
+
48
+	/**
49
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
+	 *
51
+	 * @access public
52
+	 * @var EE_Checkout $checkout
53
+	 */
54
+	public $checkout;
55
+
56
+
57
+
58
+	/**
59
+	 * @return EED_Module|EED_Single_Page_Checkout
60
+	 */
61
+	public static function instance()
62
+	{
63
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
+		return parent::get_instance(__CLASS__);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * @return EE_CART
71
+	 */
72
+	public function cart()
73
+	{
74
+		return $this->checkout->cart;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * @return EE_Transaction
81
+	 */
82
+	public function transaction()
83
+	{
84
+		return $this->checkout->transaction;
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 *    set_hooks - for hooking into EE Core, other modules, etc
91
+	 *
92
+	 * @access    public
93
+	 * @return    void
94
+	 * @throws EE_Error
95
+	 */
96
+	public static function set_hooks()
97
+	{
98
+		EED_Single_Page_Checkout::set_definitions();
99
+	}
100
+
101
+
102
+
103
+	/**
104
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
+	 *
106
+	 * @access    public
107
+	 * @return    void
108
+	 * @throws EE_Error
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		EED_Single_Page_Checkout::set_definitions();
113
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
+			return;
115
+		}
116
+		// going to start an output buffer in case anything gets accidentally output
117
+		// that might disrupt our JSON response
118
+		ob_start();
119
+		EED_Single_Page_Checkout::load_request_handler();
120
+		EED_Single_Page_Checkout::load_reg_steps();
121
+		// set ajax hooks
122
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 *    process ajax request
134
+	 *
135
+	 * @param string $ajax_action
136
+	 * @throws EE_Error
137
+	 */
138
+	public static function process_ajax_request($ajax_action)
139
+	{
140
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
141
+		EED_Single_Page_Checkout::instance()->_initialize();
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 *    ajax display registration step
148
+	 *
149
+	 * @throws EE_Error
150
+	 */
151
+	public static function display_reg_step()
152
+	{
153
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 *    ajax process registration step
160
+	 *
161
+	 * @throws EE_Error
162
+	 */
163
+	public static function process_reg_step()
164
+	{
165
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 *    ajax process registration step
172
+	 *
173
+	 * @throws EE_Error
174
+	 */
175
+	public static function update_reg_step()
176
+	{
177
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 *   update_checkout
184
+	 *
185
+	 * @access public
186
+	 * @return void
187
+	 * @throws EE_Error
188
+	 */
189
+	public static function update_checkout()
190
+	{
191
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
+	}
193
+
194
+
195
+
196
+	/**
197
+	 *    load_request_handler
198
+	 *
199
+	 * @access    public
200
+	 * @return    void
201
+	 */
202
+	public static function load_request_handler()
203
+	{
204
+		// load core Request_Handler class
205
+		if (EE_Registry::instance()->REQ !== null) {
206
+			EE_Registry::instance()->load_core('Request_Handler');
207
+		}
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 *    set_definitions
214
+	 *
215
+	 * @access    public
216
+	 * @return    void
217
+	 * @throws EE_Error
218
+	 */
219
+	public static function set_definitions()
220
+	{
221
+		if(defined('SPCO_BASE_PATH')) {
222
+			return;
223
+		}
224
+		define(
225
+			'SPCO_BASE_PATH',
226
+			rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
+		);
228
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 * load_reg_steps
242
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
243
+	 *
244
+	 * @access    private
245
+	 * @throws EE_Error
246
+	 */
247
+	public static function load_reg_steps()
248
+	{
249
+		static $reg_steps_loaded = false;
250
+		if ($reg_steps_loaded) {
251
+			return;
252
+		}
253
+		// filter list of reg_steps
254
+		$reg_steps_to_load = (array)apply_filters(
255
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
256
+			EED_Single_Page_Checkout::get_reg_steps()
257
+		);
258
+		// sort by key (order)
259
+		ksort($reg_steps_to_load);
260
+		// loop through folders
261
+		foreach ($reg_steps_to_load as $order => $reg_step) {
262
+			// we need a
263
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
264
+				// copy over to the reg_steps_array
265
+				EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
266
+				// register custom key route for each reg step
267
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
268
+				EE_Config::register_route(
269
+					$reg_step['slug'],
270
+					'EED_Single_Page_Checkout',
271
+					'run',
272
+					'step'
273
+				);
274
+				// add AJAX or other hooks
275
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
276
+					// setup autoloaders if necessary
277
+					if ( ! class_exists($reg_step['class_name'])) {
278
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
279
+							$reg_step['file_path'],
280
+							true
281
+						);
282
+					}
283
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
284
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
285
+					}
286
+				}
287
+			}
288
+		}
289
+		$reg_steps_loaded = true;
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 *    get_reg_steps
296
+	 *
297
+	 * @access    public
298
+	 * @return    array
299
+	 */
300
+	public static function get_reg_steps()
301
+	{
302
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
303
+		if (empty($reg_steps)) {
304
+			$reg_steps = array(
305
+				10  => array(
306
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
307
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
308
+					'slug'       => 'attendee_information',
309
+					'has_hooks'  => false,
310
+				),
311
+				20  => array(
312
+					'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
313
+					'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
314
+					'slug'       => 'registration_confirmation',
315
+					'has_hooks'  => false,
316
+				),
317
+				30  => array(
318
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
319
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
320
+					'slug'       => 'payment_options',
321
+					'has_hooks'  => true,
322
+				),
323
+				999 => array(
324
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
325
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
326
+					'slug'       => 'finalize_registration',
327
+					'has_hooks'  => false,
328
+				),
329
+			);
330
+		}
331
+		return $reg_steps;
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 *    registration_checkout_for_admin
338
+	 *
339
+	 * @access    public
340
+	 * @return    string
341
+	 * @throws EE_Error
342
+	 */
343
+	public static function registration_checkout_for_admin()
344
+	{
345
+		EED_Single_Page_Checkout::load_request_handler();
346
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
347
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
348
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
349
+		EED_Single_Page_Checkout::instance()->_initialize();
350
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
351
+		return EE_Registry::instance()->REQ->get_output();
352
+	}
353
+
354
+
355
+
356
+	/**
357
+	 * process_registration_from_admin
358
+	 *
359
+	 * @access public
360
+	 * @return \EE_Transaction
361
+	 * @throws EE_Error
362
+	 */
363
+	public static function process_registration_from_admin()
364
+	{
365
+		EED_Single_Page_Checkout::load_request_handler();
366
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
367
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
368
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
369
+		EED_Single_Page_Checkout::instance()->_initialize();
370
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
371
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
372
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
373
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
374
+				if ($final_reg_step->process_reg_step()) {
375
+					$final_reg_step->set_completed();
376
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
377
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
378
+				}
379
+			}
380
+		}
381
+		return null;
382
+	}
383
+
384
+
385
+
386
+	/**
387
+	 *    run
388
+	 *
389
+	 * @access    public
390
+	 * @param WP_Query $WP_Query
391
+	 * @return    void
392
+	 * @throws EE_Error
393
+	 */
394
+	public function run($WP_Query)
395
+	{
396
+		if (
397
+			$WP_Query instanceof WP_Query
398
+			&& $WP_Query->is_main_query()
399
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
400
+			&& $this->_is_reg_checkout()
401
+		) {
402
+			$this->_initialize();
403
+		}
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * determines whether current url matches reg page url
410
+	 *
411
+	 * @return bool
412
+	 */
413
+	protected function _is_reg_checkout()
414
+	{
415
+		// get current permalink for reg page without any extra query args
416
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
417
+		// get request URI for current request, but without the scheme or host
418
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
419
+		$current_request_uri = html_entity_decode($current_request_uri);
420
+		// get array of query args from the current request URI
421
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
422
+		// grab page id if it is set
423
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
424
+		// and remove the page id from the query args (we will re-add it later)
425
+		unset($query_args['page_id']);
426
+		// now strip all query args from current request URI
427
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
428
+		// and re-add the page id if it was set
429
+		if ($page_id) {
430
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
431
+		}
432
+		// remove slashes and ?
433
+		$current_request_uri = trim($current_request_uri, '?/');
434
+		// is current request URI part of the known full reg page URL ?
435
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
436
+	}
437
+
438
+
439
+
440
+	/**
441
+	 * @param WP_Query $wp_query
442
+	 * @return    void
443
+	 * @throws EE_Error
444
+	 */
445
+	public static function init($wp_query)
446
+	{
447
+		EED_Single_Page_Checkout::instance()->run($wp_query);
448
+	}
449
+
450
+
451
+
452
+	/**
453
+	 *    _initialize - initial module setup
454
+	 *
455
+	 * @access    private
456
+	 * @throws EE_Error
457
+	 * @return    void
458
+	 */
459
+	private function _initialize()
460
+	{
461
+		// ensure SPCO doesn't run twice
462
+		if (EED_Single_Page_Checkout::$_initialized) {
463
+			return;
464
+		}
465
+		try {
466
+			EED_Single_Page_Checkout::load_reg_steps();
467
+			$this->_verify_session();
468
+			// setup the EE_Checkout object
469
+			$this->checkout = $this->_initialize_checkout();
470
+			// filter checkout
471
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
472
+			// get the $_GET
473
+			$this->_get_request_vars();
474
+			if ($this->_block_bots()) {
475
+				return;
476
+			}
477
+			// filter continue_reg
478
+			$this->checkout->continue_reg = apply_filters(
479
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
480
+				true,
481
+				$this->checkout
482
+			);
483
+			// load the reg steps array
484
+			if ( ! $this->_load_and_instantiate_reg_steps()) {
485
+				EED_Single_Page_Checkout::$_initialized = true;
486
+				return;
487
+			}
488
+			// set the current step
489
+			$this->checkout->set_current_step($this->checkout->step);
490
+			// and the next step
491
+			$this->checkout->set_next_step();
492
+			// verify that everything has been setup correctly
493
+			if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
494
+				EED_Single_Page_Checkout::$_initialized = true;
495
+				return;
496
+			}
497
+			// lock the transaction
498
+			$this->checkout->transaction->lock();
499
+			// make sure all of our cached objects are added to their respective model entity mappers
500
+			$this->checkout->refresh_all_entities();
501
+			// set amount owing
502
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
503
+			// initialize each reg step, which gives them the chance to potentially alter the process
504
+			$this->_initialize_reg_steps();
505
+			// DEBUG LOG
506
+			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
507
+			// get reg form
508
+			if( ! $this->_check_form_submission()) {
509
+				EED_Single_Page_Checkout::$_initialized = true;
510
+				return;
511
+			}
512
+			// checkout the action!!!
513
+			$this->_process_form_action();
514
+			// add some style and make it dance
515
+			$this->add_styles_and_scripts();
516
+			// kk... SPCO has successfully run
517
+			EED_Single_Page_Checkout::$_initialized = true;
518
+			// set no cache headers and constants
519
+			EE_System::do_not_cache();
520
+			// add anchor
521
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
522
+			// remove transaction lock
523
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
524
+		} catch (Exception $e) {
525
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
526
+		}
527
+	}
528
+
529
+
530
+
531
+	/**
532
+	 *    _verify_session
533
+	 * checks that the session is valid and not expired
534
+	 *
535
+	 * @access    private
536
+	 * @throws EE_Error
537
+	 */
538
+	private function _verify_session()
539
+	{
540
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
541
+			throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
542
+		}
543
+		$clear_session_requested = filter_var(
544
+			EE_Registry::instance()->REQ->get('clear_session', false),
545
+			FILTER_VALIDATE_BOOLEAN
546
+		);
547
+		// is session still valid ?
548
+		if ($clear_session_requested
549
+			|| ( EE_Registry::instance()->SSN->expired()
550
+			  && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
551
+			)
552
+		) {
553
+			$this->checkout = new EE_Checkout();
554
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
555
+			// EE_Registry::instance()->SSN->reset_cart();
556
+			// EE_Registry::instance()->SSN->reset_checkout();
557
+			// EE_Registry::instance()->SSN->reset_transaction();
558
+			if (! $clear_session_requested) {
559
+				EE_Error::add_attention(
560
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
561
+					__FILE__, __FUNCTION__, __LINE__
562
+				);
563
+			}
564
+			// EE_Registry::instance()->SSN->reset_expired();
565
+		}
566
+	}
567
+
568
+
569
+
570
+	/**
571
+	 *    _initialize_checkout
572
+	 * loads and instantiates EE_Checkout
573
+	 *
574
+	 * @access    private
575
+	 * @throws EE_Error
576
+	 * @return EE_Checkout
577
+	 */
578
+	private function _initialize_checkout()
579
+	{
580
+		// look in session for existing checkout
581
+		/** @type EE_Checkout $checkout */
582
+		$checkout = EE_Registry::instance()->SSN->checkout();
583
+		// verify
584
+		if ( ! $checkout instanceof EE_Checkout) {
585
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
586
+			$checkout = EE_Registry::instance()->load_file(
587
+				SPCO_INC_PATH,
588
+				'EE_Checkout',
589
+				'class', array(),
590
+				false
591
+			);
592
+		} else {
593
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
594
+				$this->unlock_transaction();
595
+				wp_safe_redirect($checkout->redirect_url);
596
+				exit();
597
+			}
598
+		}
599
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
600
+		// verify again
601
+		if ( ! $checkout instanceof EE_Checkout) {
602
+			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
603
+		}
604
+		// reset anything that needs a clean slate for each request
605
+		$checkout->reset_for_current_request();
606
+		return $checkout;
607
+	}
608
+
609
+
610
+
611
+	/**
612
+	 *    _get_request_vars
613
+	 *
614
+	 * @access    private
615
+	 * @return    void
616
+	 * @throws EE_Error
617
+	 */
618
+	private function _get_request_vars()
619
+	{
620
+		// load classes
621
+		EED_Single_Page_Checkout::load_request_handler();
622
+		//make sure this request is marked as belonging to EE
623
+		EE_Registry::instance()->REQ->set_espresso_page(true);
624
+		// which step is being requested ?
625
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
626
+		// which step is being edited ?
627
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
628
+		// and what we're doing on the current step
629
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
630
+		// timestamp
631
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
632
+		// returning to edit ?
633
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
634
+		// add reg url link to registration query params
635
+		if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
636
+			$this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
637
+		}
638
+		// or some other kind of revisit ?
639
+		$this->checkout->revisit = filter_var(
640
+			EE_Registry::instance()->REQ->get('revisit', false),
641
+			FILTER_VALIDATE_BOOLEAN
642
+		);
643
+		// and whether or not to generate a reg form for this request
644
+		$this->checkout->generate_reg_form = filter_var(
645
+			EE_Registry::instance()->REQ->get('generate_reg_form', true),
646
+			FILTER_VALIDATE_BOOLEAN
647
+		);
648
+		// and whether or not to process a reg form submission for this request
649
+		$this->checkout->process_form_submission = filter_var(
650
+			EE_Registry::instance()->REQ->get(
651
+				'process_form_submission',
652
+				$this->checkout->action === 'process_reg_step'
653
+			),
654
+			FILTER_VALIDATE_BOOLEAN
655
+		);
656
+		$this->checkout->process_form_submission = filter_var(
657
+			$this->checkout->action !== 'display_spco_reg_step'
658
+				? $this->checkout->process_form_submission
659
+				: false,
660
+			FILTER_VALIDATE_BOOLEAN
661
+		);
662
+		// $this->_display_request_vars();
663
+	}
664
+
665
+
666
+
667
+	/**
668
+	 *  _display_request_vars
669
+	 *
670
+	 * @access    protected
671
+	 * @return    void
672
+	 */
673
+	protected function _display_request_vars()
674
+	{
675
+		if ( ! WP_DEBUG) {
676
+			return;
677
+		}
678
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
679
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
680
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
681
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
682
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
683
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
684
+		EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
685
+		EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * _block_bots
692
+	 * checks that the incoming request has either of the following set:
693
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
694
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
695
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
696
+	 * then where you coming from man?
697
+	 *
698
+	 * @return boolean
699
+	 */
700
+	private function _block_bots()
701
+	{
702
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
703
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
704
+			return true;
705
+		}
706
+		return false;
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 *    _get_first_step
713
+	 *  gets slug for first step in $_reg_steps_array
714
+	 *
715
+	 * @access    private
716
+	 * @throws EE_Error
717
+	 * @return    string
718
+	 */
719
+	private function _get_first_step()
720
+	{
721
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
722
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
723
+	}
724
+
725
+
726
+
727
+	/**
728
+	 *    _load_and_instantiate_reg_steps
729
+	 *  instantiates each reg step based on the loaded reg_steps array
730
+	 *
731
+	 * @access    private
732
+	 * @throws EE_Error
733
+	 * @return    bool
734
+	 */
735
+	private function _load_and_instantiate_reg_steps()
736
+	{
737
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
738
+		// have reg_steps already been instantiated ?
739
+		if (
740
+			empty($this->checkout->reg_steps)
741
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
742
+		) {
743
+			// if not, then loop through raw reg steps array
744
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
745
+				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
746
+					return false;
747
+				}
748
+			}
749
+			EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
750
+			EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
751
+			// skip the registration_confirmation page ?
752
+			if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
753
+				// just remove it from the reg steps array
754
+				$this->checkout->remove_reg_step('registration_confirmation', false);
755
+			} else if (
756
+				isset($this->checkout->reg_steps['registration_confirmation'])
757
+				&& EE_Registry::instance()->CFG->registration->reg_confirmation_last
758
+			) {
759
+				// set the order to something big like 100
760
+				$this->checkout->set_reg_step_order('registration_confirmation', 100);
761
+			}
762
+			// filter the array for good luck
763
+			$this->checkout->reg_steps = apply_filters(
764
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
765
+				$this->checkout->reg_steps
766
+			);
767
+			// finally re-sort based on the reg step class order properties
768
+			$this->checkout->sort_reg_steps();
769
+		} else {
770
+			foreach ($this->checkout->reg_steps as $reg_step) {
771
+				// set all current step stati to FALSE
772
+				$reg_step->set_is_current_step(false);
773
+			}
774
+		}
775
+		if (empty($this->checkout->reg_steps)) {
776
+			EE_Error::add_error(
777
+				__('No Reg Steps were loaded..', 'event_espresso'),
778
+				__FILE__, __FUNCTION__, __LINE__
779
+			);
780
+			return false;
781
+		}
782
+		// make reg step details available to JS
783
+		$this->checkout->set_reg_step_JSON_info();
784
+		return true;
785
+	}
786
+
787
+
788
+
789
+	/**
790
+	 *     _load_and_instantiate_reg_step
791
+	 *
792
+	 * @access    private
793
+	 * @param array $reg_step
794
+	 * @param int   $order
795
+	 * @return bool
796
+	 */
797
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
798
+	{
799
+		// we need a file_path, class_name, and slug to add a reg step
800
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
801
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
802
+			if (
803
+				$this->checkout->reg_url_link
804
+				&& $this->checkout->step !== $reg_step['slug']
805
+				&& $reg_step['slug'] !== 'finalize_registration'
806
+				// normally at this point we would NOT load the reg step, but this filter can change that
807
+				&& apply_filters(
808
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
809
+					true,
810
+					$reg_step,
811
+					$this->checkout
812
+				)
813
+			) {
814
+				return true;
815
+			}
816
+			// instantiate step class using file path and class name
817
+			$reg_step_obj = EE_Registry::instance()->load_file(
818
+				$reg_step['file_path'],
819
+				$reg_step['class_name'],
820
+				'class',
821
+				$this->checkout,
822
+				false
823
+			);
824
+			// did we gets the goods ?
825
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
826
+				// set reg step order based on config
827
+				$reg_step_obj->set_order($order);
828
+				// add instantiated reg step object to the master reg steps array
829
+				$this->checkout->add_reg_step($reg_step_obj);
830
+			} else {
831
+				EE_Error::add_error(
832
+					__('The current step could not be set.', 'event_espresso'),
833
+					__FILE__, __FUNCTION__, __LINE__
834
+				);
835
+				return false;
836
+			}
837
+		} else {
838
+			if (WP_DEBUG) {
839
+				EE_Error::add_error(
840
+					sprintf(
841
+						__(
842
+							'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',
843
+							'event_espresso'
844
+						),
845
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
846
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
847
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
848
+						'<ul>',
849
+						'<li>',
850
+						'</li>',
851
+						'</ul>'
852
+					),
853
+					__FILE__, __FUNCTION__, __LINE__
854
+				);
855
+			}
856
+			return false;
857
+		}
858
+		return true;
859
+	}
860
+
861
+
862
+	/**
863
+	 * _verify_transaction_and_get_registrations
864
+	 *
865
+	 * @access private
866
+	 * @return bool
867
+	 * @throws InvalidDataTypeException
868
+	 * @throws InvalidEntityException
869
+	 * @throws EE_Error
870
+	 */
871
+	private function _verify_transaction_and_get_registrations()
872
+	{
873
+		// was there already a valid transaction in the checkout from the session ?
874
+		if ( ! $this->checkout->transaction instanceof EE_Transaction) {
875
+			// get transaction from db or session
876
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
877
+				? $this->_get_transaction_and_cart_for_previous_visit()
878
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
879
+			if ( ! $this->checkout->transaction instanceof EE_Transaction) {
880
+				EE_Error::add_error(
881
+					__('Your Registration and Transaction information could not be retrieved from the db.',
882
+						'event_espresso'),
883
+					__FILE__, __FUNCTION__, __LINE__
884
+				);
885
+				$this->checkout->transaction = EE_Transaction::new_instance();
886
+				// add some style and make it dance
887
+				$this->add_styles_and_scripts();
888
+				EED_Single_Page_Checkout::$_initialized = true;
889
+				return false;
890
+			}
891
+			// and the registrations for the transaction
892
+			$this->_get_registrations($this->checkout->transaction);
893
+		}
894
+		return true;
895
+	}
896
+
897
+
898
+
899
+	/**
900
+	 * _get_transaction_and_cart_for_previous_visit
901
+	 *
902
+	 * @access private
903
+	 * @return mixed EE_Transaction|NULL
904
+	 */
905
+	private function _get_transaction_and_cart_for_previous_visit()
906
+	{
907
+		/** @var $TXN_model EEM_Transaction */
908
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
909
+		// because the reg_url_link is present in the request,
910
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
911
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
912
+		// verify transaction
913
+		if ($transaction instanceof EE_Transaction) {
914
+			// and get the cart that was used for that transaction
915
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
916
+			return $transaction;
917
+		}
918
+		EE_Error::add_error(
919
+			__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
920
+			__FILE__, __FUNCTION__, __LINE__
921
+		);
922
+		return null;
923
+
924
+	}
925
+
926
+
927
+
928
+	/**
929
+	 * _get_cart_for_transaction
930
+	 *
931
+	 * @access private
932
+	 * @param EE_Transaction $transaction
933
+	 * @return EE_Cart
934
+	 */
935
+	private function _get_cart_for_transaction($transaction)
936
+	{
937
+		return $this->checkout->get_cart_for_transaction($transaction);
938
+	}
939
+
940
+
941
+
942
+	/**
943
+	 * get_cart_for_transaction
944
+	 *
945
+	 * @access public
946
+	 * @param EE_Transaction $transaction
947
+	 * @return EE_Cart
948
+	 */
949
+	public function get_cart_for_transaction(EE_Transaction $transaction)
950
+	{
951
+		return $this->checkout->get_cart_for_transaction($transaction);
952
+	}
953
+
954
+
955
+
956
+	/**
957
+	 * _get_transaction_and_cart_for_current_session
958
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
959
+	 *
960
+	 * @access private
961
+	 * @return EE_Transaction
962
+	 * @throws EE_Error
963
+	 */
964
+	private function _get_cart_for_current_session_and_setup_new_transaction()
965
+	{
966
+		//  if there's no transaction, then this is the FIRST visit to SPCO
967
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
968
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
969
+		// and then create a new transaction
970
+		$transaction = $this->_initialize_transaction();
971
+		// verify transaction
972
+		if ($transaction instanceof EE_Transaction) {
973
+			// save it so that we have an ID for other objects to use
974
+			$transaction->save();
975
+			// and save TXN data to the cart
976
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
977
+		} else {
978
+			EE_Error::add_error(
979
+				__('A Valid Transaction could not be initialized.', 'event_espresso'),
980
+				__FILE__, __FUNCTION__, __LINE__
981
+			);
982
+		}
983
+		return $transaction;
984
+	}
985
+
986
+
987
+
988
+	/**
989
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
990
+	 *
991
+	 * @access private
992
+	 * @return mixed EE_Transaction|NULL
993
+	 */
994
+	private function _initialize_transaction()
995
+	{
996
+		try {
997
+			// ensure cart totals have been calculated
998
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
999
+			// grab the cart grand total
1000
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
1001
+			// create new TXN
1002
+			$transaction = EE_Transaction::new_instance(
1003
+				array(
1004
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1005
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1006
+					'TXN_paid'      => 0,
1007
+					'STS_ID'        => EEM_Transaction::failed_status_code,
1008
+				)
1009
+			);
1010
+			// save it so that we have an ID for other objects to use
1011
+			$transaction->save();
1012
+			// set cron job for following up on TXNs after their session has expired
1013
+			EE_Cron_Tasks::schedule_expired_transaction_check(
1014
+				EE_Registry::instance()->SSN->expiration() + 1,
1015
+				$transaction->ID()
1016
+			);
1017
+			return $transaction;
1018
+		} catch (Exception $e) {
1019
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1020
+		}
1021
+		return null;
1022
+	}
1023
+
1024
+
1025
+	/**
1026
+	 * _get_registrations
1027
+	 *
1028
+	 * @access private
1029
+	 * @param EE_Transaction $transaction
1030
+	 * @return void
1031
+	 * @throws InvalidDataTypeException
1032
+	 * @throws InvalidEntityException
1033
+	 * @throws EE_Error
1034
+	 */
1035
+	private function _get_registrations(EE_Transaction $transaction)
1036
+	{
1037
+		// first step: grab the registrants  { : o
1038
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1039
+		$this->checkout->total_ticket_count = count($registrations);
1040
+		// verify registrations have been set
1041
+		if (empty($registrations)) {
1042
+			// if no cached registrations, then check the db
1043
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1044
+			// still nothing ? well as long as this isn't a revisit
1045
+			if (empty($registrations) && ! $this->checkout->revisit) {
1046
+				// generate new registrations from scratch
1047
+				$registrations = $this->_initialize_registrations($transaction);
1048
+			}
1049
+		}
1050
+		// sort by their original registration order
1051
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1052
+		// then loop thru the array
1053
+		foreach ($registrations as $registration) {
1054
+			// verify each registration
1055
+			if ($registration instanceof EE_Registration) {
1056
+				// we display all attendee info for the primary registrant
1057
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
1058
+					&& $registration->is_primary_registrant()
1059
+				) {
1060
+					$this->checkout->primary_revisit = true;
1061
+					break;
1062
+				}
1063
+				if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1064
+					// but hide info if it doesn't belong to you
1065
+					$transaction->clear_cache('Registration', $registration->ID());
1066
+					$this->checkout->total_ticket_count--;
1067
+				}
1068
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1069
+			}
1070
+		}
1071
+	}
1072
+
1073
+
1074
+	/**
1075
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1076
+	 *
1077
+	 * @access private
1078
+	 * @param EE_Transaction $transaction
1079
+	 * @return    array
1080
+	 * @throws InvalidDataTypeException
1081
+	 * @throws InvalidEntityException
1082
+	 * @throws EE_Error
1083
+	 */
1084
+	private function _initialize_registrations(EE_Transaction $transaction)
1085
+	{
1086
+		$att_nmbr = 0;
1087
+		$registrations = array();
1088
+		if ($transaction instanceof EE_Transaction) {
1089
+			/** @type EE_Registration_Processor $registration_processor */
1090
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1091
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1092
+			// now let's add the cart items to the $transaction
1093
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1094
+				//do the following for each ticket of this type they selected
1095
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1096
+					$att_nmbr++;
1097
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1098
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1099
+						'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1100
+						array(
1101
+							$transaction,
1102
+							$line_item,
1103
+							$att_nmbr,
1104
+							$this->checkout->total_ticket_count,
1105
+						)
1106
+					);
1107
+					// override capabilities for frontend registrations
1108
+					if ( ! is_admin()) {
1109
+						$CreateRegistrationCommand->setCapCheck(
1110
+							new PublicCapabilities('', 'create_new_registration')
1111
+						);
1112
+					}
1113
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1114
+					if ( ! $registration instanceof EE_Registration) {
1115
+						throw new InvalidEntityException($registration, 'EE_Registration');
1116
+					}
1117
+					$registrations[ $registration->ID() ] = $registration;
1118
+				}
1119
+			}
1120
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1121
+		}
1122
+		return $registrations;
1123
+	}
1124
+
1125
+
1126
+
1127
+	/**
1128
+	 * sorts registrations by REG_count
1129
+	 *
1130
+	 * @access public
1131
+	 * @param EE_Registration $reg_A
1132
+	 * @param EE_Registration $reg_B
1133
+	 * @return int
1134
+	 */
1135
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1136
+	{
1137
+		// this shouldn't ever happen within the same TXN, but oh well
1138
+		if ($reg_A->count() === $reg_B->count()) {
1139
+			return 0;
1140
+		}
1141
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1142
+	}
1143
+
1144
+
1145
+
1146
+	/**
1147
+	 *    _final_verifications
1148
+	 * just makes sure that everything is set up correctly before proceeding
1149
+	 *
1150
+	 * @access    private
1151
+	 * @return    bool
1152
+	 * @throws EE_Error
1153
+	 */
1154
+	private function _final_verifications()
1155
+	{
1156
+		// filter checkout
1157
+		$this->checkout = apply_filters(
1158
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1159
+			$this->checkout
1160
+		);
1161
+		//verify that current step is still set correctly
1162
+		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1163
+			EE_Error::add_error(
1164
+				__('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.', 'event_espresso'),
1165
+				__FILE__,
1166
+				__FUNCTION__,
1167
+				__LINE__
1168
+			);
1169
+			return false;
1170
+		}
1171
+		// if returning to SPCO, then verify that primary registrant is set
1172
+		if ( ! empty($this->checkout->reg_url_link)) {
1173
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1174
+			if ( ! $valid_registrant instanceof EE_Registration) {
1175
+				EE_Error::add_error(
1176
+					__('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.', 'event_espresso'),
1177
+					__FILE__,
1178
+					__FUNCTION__,
1179
+					__LINE__
1180
+				);
1181
+				return false;
1182
+			}
1183
+			$valid_registrant = null;
1184
+			foreach (
1185
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1186
+			) {
1187
+				if (
1188
+					$registration instanceof EE_Registration
1189
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1190
+				) {
1191
+					$valid_registrant = $registration;
1192
+				}
1193
+			}
1194
+			if ( ! $valid_registrant instanceof EE_Registration) {
1195
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1196
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1197
+					// clear the session, mark the checkout as unverified, and try again
1198
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1199
+					EED_Single_Page_Checkout::$_initialized = false;
1200
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1201
+					$this->_initialize();
1202
+					EE_Error::reset_notices();
1203
+					return false;
1204
+				}
1205
+				EE_Error::add_error(
1206
+					__(
1207
+						'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.',
1208
+						'event_espresso'
1209
+					),
1210
+					__FILE__,
1211
+					__FUNCTION__,
1212
+					__LINE__
1213
+				);
1214
+				return false;
1215
+			}
1216
+		}
1217
+		// now that things have been kinda sufficiently verified,
1218
+		// let's add the checkout to the session so that it's available to other systems
1219
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1220
+		return true;
1221
+	}
1222
+
1223
+
1224
+
1225
+	/**
1226
+	 *    _initialize_reg_steps
1227
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1228
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1229
+	 *
1230
+	 * @access    private
1231
+	 * @param bool $reinitializing
1232
+	 * @throws EE_Error
1233
+	 */
1234
+	private function _initialize_reg_steps($reinitializing = false)
1235
+	{
1236
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1237
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1238
+		foreach ($this->checkout->reg_steps as $reg_step) {
1239
+			if ( ! $reg_step->initialize_reg_step()) {
1240
+				// if not initialized then maybe this step is being removed...
1241
+				if ( ! $reinitializing && $reg_step->is_current_step()) {
1242
+					// if it was the current step, then we need to start over here
1243
+					$this->_initialize_reg_steps(true);
1244
+					return;
1245
+				}
1246
+				continue;
1247
+			}
1248
+			// add css and JS for current step
1249
+			$reg_step->enqueue_styles_and_scripts();
1250
+			// i18n
1251
+			$reg_step->translate_js_strings();
1252
+			if ($reg_step->is_current_step()) {
1253
+				// the text that appears on the reg step form submit button
1254
+				$reg_step->set_submit_button_text();
1255
+			}
1256
+		}
1257
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1258
+		do_action(
1259
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1260
+			$this->checkout->current_step
1261
+		);
1262
+	}
1263
+
1264
+
1265
+
1266
+	/**
1267
+	 * _check_form_submission
1268
+	 *
1269
+	 * @access private
1270
+	 * @return boolean
1271
+	 */
1272
+	private function _check_form_submission()
1273
+	{
1274
+		//does this request require the reg form to be generated ?
1275
+		if ($this->checkout->generate_reg_form) {
1276
+			// ever heard that song by Blue Rodeo ?
1277
+			try {
1278
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1279
+				// if not displaying a form, then check for form submission
1280
+				if (
1281
+					$this->checkout->process_form_submission
1282
+					&& $this->checkout->current_step->reg_form->was_submitted()
1283
+				) {
1284
+					// clear out any old data in case this step is being run again
1285
+					$this->checkout->current_step->set_valid_data(array());
1286
+					// capture submitted form data
1287
+					$this->checkout->current_step->reg_form->receive_form_submission(
1288
+						apply_filters(
1289
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1290
+							EE_Registry::instance()->REQ->params(),
1291
+							$this->checkout
1292
+						)
1293
+					);
1294
+					// validate submitted form data
1295
+					if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1296
+						// thou shall not pass !!!
1297
+						$this->checkout->continue_reg = false;
1298
+						// any form validation errors?
1299
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1300
+							EE_Error::add_error(
1301
+								$this->checkout->current_step->reg_form->submission_error_message(),
1302
+								__FILE__, __FUNCTION__, __LINE__
1303
+							);
1304
+						}
1305
+						// well not really... what will happen is
1306
+						// we'll just get redirected back to redo the current step
1307
+						$this->go_to_next_step();
1308
+						return false;
1309
+					}
1310
+				}
1311
+			} catch (EE_Error $e) {
1312
+				$e->get_error();
1313
+			}
1314
+		}
1315
+		return true;
1316
+	}
1317
+
1318
+
1319
+
1320
+	/**
1321
+	 * _process_action
1322
+	 *
1323
+	 * @access private
1324
+	 * @return void
1325
+	 * @throws EE_Error
1326
+	 */
1327
+	private function _process_form_action()
1328
+	{
1329
+		// what cha wanna do?
1330
+		switch ($this->checkout->action) {
1331
+			// AJAX next step reg form
1332
+			case 'display_spco_reg_step' :
1333
+				$this->checkout->redirect = false;
1334
+				if (EE_Registry::instance()->REQ->ajax) {
1335
+					$this->checkout->json_response->set_reg_step_html(
1336
+						$this->checkout->current_step->display_reg_form()
1337
+					);
1338
+				}
1339
+				break;
1340
+			default :
1341
+				// meh... do one of those other steps first
1342
+				if (
1343
+					! empty($this->checkout->action)
1344
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1345
+				) {
1346
+					// dynamically creates hook point like:
1347
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1348
+					do_action(
1349
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1350
+						$this->checkout->current_step
1351
+					);
1352
+					// call action on current step
1353
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1354
+						// good registrant, you get to proceed
1355
+						if (
1356
+							$this->checkout->current_step->success_message() !== ''
1357
+							&& apply_filters(
1358
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1359
+								false
1360
+							)
1361
+						) {
1362
+							EE_Error::add_success(
1363
+								$this->checkout->current_step->success_message()
1364
+								. '<br />' . $this->checkout->next_step->_instructions()
1365
+							);
1366
+						}
1367
+						// pack it up, pack it in...
1368
+						$this->_setup_redirect();
1369
+					}
1370
+					// dynamically creates hook point like:
1371
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1372
+					do_action(
1373
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1374
+						$this->checkout->current_step
1375
+					);
1376
+				} else {
1377
+					EE_Error::add_error(
1378
+						sprintf(
1379
+							__(
1380
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1381
+								'event_espresso'
1382
+							),
1383
+							$this->checkout->action,
1384
+							$this->checkout->current_step->name()
1385
+						),
1386
+						__FILE__,
1387
+						__FUNCTION__,
1388
+						__LINE__
1389
+					);
1390
+				}
1391
+			// end default
1392
+		}
1393
+		// store our progress so far
1394
+		$this->checkout->stash_transaction_and_checkout();
1395
+		// advance to the next step! If you pass GO, collect $200
1396
+		$this->go_to_next_step();
1397
+	}
1398
+
1399
+
1400
+
1401
+	/**
1402
+	 *        add_styles_and_scripts
1403
+	 *
1404
+	 * @access        public
1405
+	 * @return        void
1406
+	 */
1407
+	public function add_styles_and_scripts()
1408
+	{
1409
+		// i18n
1410
+		$this->translate_js_strings();
1411
+		if ($this->checkout->admin_request) {
1412
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1413
+		} else {
1414
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1415
+		}
1416
+	}
1417
+
1418
+
1419
+
1420
+	/**
1421
+	 *        translate_js_strings
1422
+	 *
1423
+	 * @access        public
1424
+	 * @return        void
1425
+	 */
1426
+	public function translate_js_strings()
1427
+	{
1428
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1429
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1430
+		EE_Registry::$i18n_js_strings['server_error'] = __(
1431
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1432
+			'event_espresso'
1433
+		);
1434
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1435
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1436
+			'event_espresso'
1437
+		);
1438
+		EE_Registry::$i18n_js_strings['validation_error'] = __(
1439
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1440
+			'event_espresso'
1441
+		);
1442
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1443
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1444
+			'event_espresso'
1445
+		);
1446
+		EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1447
+			'This registration step could not be completed. Please refresh the page and try again.',
1448
+			'event_espresso'
1449
+		);
1450
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1451
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1452
+			'event_espresso'
1453
+		);
1454
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1455
+			__(
1456
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1457
+				'event_espresso'
1458
+			),
1459
+			'<br/>',
1460
+			'<br/>'
1461
+		);
1462
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1463
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1464
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1465
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1466
+		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1467
+		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1468
+		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1469
+		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1470
+		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1471
+		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1472
+		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1473
+		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1474
+		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1475
+		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1476
+		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1477
+		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1478
+		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1479
+		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1480
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
1481
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1482
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1483
+			true
1484
+		);
1485
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1486
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1487
+		);
1488
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1489
+			'M d, Y H:i:s',
1490
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1491
+		);
1492
+	}
1493
+
1494
+
1495
+
1496
+	/**
1497
+	 *    enqueue_styles_and_scripts
1498
+	 *
1499
+	 * @access        public
1500
+	 * @return        void
1501
+	 * @throws EE_Error
1502
+	 */
1503
+	public function enqueue_styles_and_scripts()
1504
+	{
1505
+		// load css
1506
+		wp_register_style(
1507
+			'single_page_checkout',
1508
+			SPCO_CSS_URL . 'single_page_checkout.css',
1509
+			array('espresso_default'),
1510
+			EVENT_ESPRESSO_VERSION
1511
+		);
1512
+		wp_enqueue_style('single_page_checkout');
1513
+		// load JS
1514
+		wp_register_script(
1515
+			'jquery_plugin',
1516
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1517
+			array('jquery'),
1518
+			'1.0.1',
1519
+			true
1520
+		);
1521
+		wp_register_script(
1522
+			'jquery_countdown',
1523
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1524
+			array('jquery_plugin'),
1525
+			'2.0.2',
1526
+			true
1527
+		);
1528
+		wp_register_script(
1529
+			'single_page_checkout',
1530
+			SPCO_JS_URL . 'single_page_checkout.js',
1531
+			array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1532
+			EVENT_ESPRESSO_VERSION,
1533
+			true
1534
+		);
1535
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1536
+			$this->checkout->registration_form->enqueue_js();
1537
+		}
1538
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1539
+			$this->checkout->current_step->reg_form->enqueue_js();
1540
+		}
1541
+		wp_enqueue_script('single_page_checkout');
1542
+		/**
1543
+		 * global action hook for enqueueing styles and scripts with
1544
+		 * spco calls.
1545
+		 */
1546
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1547
+		/**
1548
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1549
+		 * The hook will end up being something like:
1550
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1551
+		 */
1552
+		do_action(
1553
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1554
+			$this
1555
+		);
1556
+	}
1557
+
1558
+
1559
+
1560
+	/**
1561
+	 *    display the Registration Single Page Checkout Form
1562
+	 *
1563
+	 * @access    private
1564
+	 * @return    void
1565
+	 * @throws EE_Error
1566
+	 */
1567
+	private function _display_spco_reg_form()
1568
+	{
1569
+		// if registering via the admin, just display the reg form for the current step
1570
+		if ($this->checkout->admin_request) {
1571
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1572
+		} else {
1573
+			// add powered by EE msg
1574
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1575
+			$empty_cart = count(
1576
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1577
+			) < 1;
1578
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1579
+			$cookies_not_set_msg = '';
1580
+			if ($empty_cart) {
1581
+				$cookies_not_set_msg = apply_filters(
1582
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1583
+					sprintf(
1584
+						__(
1585
+							'%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',
1586
+							'event_espresso'
1587
+						),
1588
+						'<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1589
+						'</div>',
1590
+						'<h6 class="important-notice">',
1591
+						'</h6>',
1592
+						'<p>',
1593
+						'</p>',
1594
+						'<br />',
1595
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1596
+						'</a>'
1597
+					)
1598
+				);
1599
+			}
1600
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1601
+				array(
1602
+					'name'            => 'single-page-checkout',
1603
+					'html_id'         => 'ee-single-page-checkout-dv',
1604
+					'layout_strategy' =>
1605
+						new EE_Template_Layout(
1606
+							array(
1607
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1608
+								'template_args'        => array(
1609
+									'empty_cart'              => $empty_cart,
1610
+									'revisit'                 => $this->checkout->revisit,
1611
+									'reg_steps'               => $this->checkout->reg_steps,
1612
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1613
+										? $this->checkout->next_step->slug()
1614
+										: '',
1615
+									'empty_msg'               => apply_filters(
1616
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1617
+										sprintf(
1618
+											__(
1619
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1620
+												'event_espresso'
1621
+											),
1622
+											'<a href="'
1623
+											. get_post_type_archive_link('espresso_events')
1624
+											. '" title="',
1625
+											'">',
1626
+											'</a>'
1627
+										)
1628
+									),
1629
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1630
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1631
+									'session_expiration'      => gmdate(
1632
+										'M d, Y H:i:s',
1633
+										EE_Registry::instance()->SSN->expiration()
1634
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1635
+									),
1636
+								),
1637
+							)
1638
+						),
1639
+				)
1640
+			);
1641
+			// load template and add to output sent that gets filtered into the_content()
1642
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1643
+		}
1644
+	}
1645
+
1646
+
1647
+
1648
+	/**
1649
+	 *    add_extra_finalize_registration_inputs
1650
+	 *
1651
+	 * @access    public
1652
+	 * @param $next_step
1653
+	 * @internal  param string $label
1654
+	 * @return void
1655
+	 */
1656
+	public function add_extra_finalize_registration_inputs($next_step)
1657
+	{
1658
+		if ($next_step === 'finalize_registration') {
1659
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1660
+		}
1661
+	}
1662
+
1663
+
1664
+
1665
+	/**
1666
+	 *    display_registration_footer
1667
+	 *
1668
+	 * @access    public
1669
+	 * @return    string
1670
+	 */
1671
+	public static function display_registration_footer()
1672
+	{
1673
+		if (
1674
+		apply_filters(
1675
+			'FHEE__EE_Front__Controller__show_reg_footer',
1676
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1677
+		)
1678
+		) {
1679
+			add_filter(
1680
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1681
+				function ($url) {
1682
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1683
+				}
1684
+			);
1685
+			echo apply_filters(
1686
+				'FHEE__EE_Front_Controller__display_registration_footer',
1687
+				\EEH_Template::powered_by_event_espresso(
1688
+					'',
1689
+					'espresso-registration-footer-dv',
1690
+					array('utm_content' => 'registration_checkout')
1691
+				)
1692
+			);
1693
+		}
1694
+		return '';
1695
+	}
1696
+
1697
+
1698
+
1699
+	/**
1700
+	 *    unlock_transaction
1701
+	 *
1702
+	 * @access    public
1703
+	 * @return    void
1704
+	 * @throws EE_Error
1705
+	 */
1706
+	public function unlock_transaction()
1707
+	{
1708
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1709
+			$this->checkout->transaction->unlock();
1710
+		}
1711
+	}
1712
+
1713
+
1714
+
1715
+	/**
1716
+	 *        _setup_redirect
1717
+	 *
1718
+	 * @access    private
1719
+	 * @return void
1720
+	 */
1721
+	private function _setup_redirect()
1722
+	{
1723
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1724
+			$this->checkout->redirect = true;
1725
+			if (empty($this->checkout->redirect_url)) {
1726
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1727
+			}
1728
+			$this->checkout->redirect_url = apply_filters(
1729
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1730
+				$this->checkout->redirect_url,
1731
+				$this->checkout
1732
+			);
1733
+		}
1734
+	}
1735
+
1736
+
1737
+
1738
+	/**
1739
+	 *   handle ajax message responses and redirects
1740
+	 *
1741
+	 * @access public
1742
+	 * @return void
1743
+	 * @throws EE_Error
1744
+	 */
1745
+	public function go_to_next_step()
1746
+	{
1747
+		if (EE_Registry::instance()->REQ->ajax) {
1748
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1749
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1750
+		}
1751
+		$this->unlock_transaction();
1752
+		// just return for these conditions
1753
+		if (
1754
+			$this->checkout->admin_request
1755
+			|| $this->checkout->action === 'redirect_form'
1756
+			|| $this->checkout->action === 'update_checkout'
1757
+		) {
1758
+			return;
1759
+		}
1760
+		// AJAX response
1761
+		$this->_handle_json_response();
1762
+		// redirect to next step or the Thank You page
1763
+		$this->_handle_html_redirects();
1764
+		// hmmm... must be something wrong, so let's just display the form again !
1765
+		$this->_display_spco_reg_form();
1766
+	}
1767
+
1768
+
1769
+
1770
+	/**
1771
+	 *   _handle_json_response
1772
+	 *
1773
+	 * @access protected
1774
+	 * @return void
1775
+	 */
1776
+	protected function _handle_json_response()
1777
+	{
1778
+		// if this is an ajax request
1779
+		if (EE_Registry::instance()->REQ->ajax) {
1780
+			// DEBUG LOG
1781
+			//$this->checkout->log(
1782
+			//	__CLASS__, __FUNCTION__, __LINE__,
1783
+			//	array(
1784
+			//		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1785
+			//		'redirect'                   => $this->checkout->redirect,
1786
+			//		'continue_reg'               => $this->checkout->continue_reg,
1787
+			//	)
1788
+			//);
1789
+			$this->checkout->json_response->set_registration_time_limit(
1790
+				$this->checkout->get_registration_time_limit()
1791
+			);
1792
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1793
+			// just send the ajax (
1794
+			$json_response = apply_filters(
1795
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1796
+				$this->checkout->json_response
1797
+			);
1798
+			echo $json_response;
1799
+			exit();
1800
+		}
1801
+	}
1802
+
1803
+
1804
+
1805
+	/**
1806
+	 *   _handle_redirects
1807
+	 *
1808
+	 * @access protected
1809
+	 * @return void
1810
+	 */
1811
+	protected function _handle_html_redirects()
1812
+	{
1813
+		// going somewhere ?
1814
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1815
+			// store notices in a transient
1816
+			EE_Error::get_notices(false, true, true);
1817
+			// DEBUG LOG
1818
+			//$this->checkout->log(
1819
+			//	__CLASS__, __FUNCTION__, __LINE__,
1820
+			//	array(
1821
+			//		'headers_sent' => headers_sent(),
1822
+			//		'redirect_url'     => $this->checkout->redirect_url,
1823
+			//		'headers_list'    => headers_list(),
1824
+			//	)
1825
+			//);
1826
+			wp_safe_redirect($this->checkout->redirect_url);
1827
+			exit();
1828
+		}
1829
+	}
1830
+
1831
+
1832
+
1833
+	/**
1834
+	 *   set_checkout_anchor
1835
+	 *
1836
+	 * @access public
1837
+	 * @return void
1838
+	 */
1839
+	public function set_checkout_anchor()
1840
+	{
1841
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1842
+	}
1843
+
1844
+	/**
1845
+	 *    getRegistrationExpirationNotice
1846
+	 *
1847
+	 * @since $VID:$
1848
+	 * @access    public
1849
+	 * @return    string
1850
+	 */
1851
+	public static function getRegistrationExpirationNotice()
1852
+	{
1853
+		return sprintf(
1854
+			__('%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',
1855
+				'event_espresso'),
1856
+			'<h4 class="important-notice">',
1857
+			'</h4>',
1858
+			'<br />',
1859
+			'<p>',
1860
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1861
+			'">',
1862
+			'</a>',
1863
+			'</p>'
1864
+		);
1865
+	}
1866 1866
 
1867 1867
 }
1868 1868
 // End of file EED_Single_Page_Checkout.module.php
Please login to merge, or discard this patch.
modules/ticket_sales_monitor/EED_Ticket_Sales_Monitor.module.php 2 patches
Indentation   +999 added lines, -999 removed lines patch added patch discarded remove patch
@@ -23,1006 +23,1006 @@
 block discarded – undo
23 23
 class EED_Ticket_Sales_Monitor extends EED_Module
24 24
 {
25 25
 
26
-    const debug = false;    //	true false
27
-
28
-    /**
29
-     * an array of raw ticket data from EED_Ticket_Selector
30
-     *
31
-     * @var array $ticket_selections
32
-     */
33
-    protected $ticket_selections = array();
34
-
35
-    /**
36
-     * the raw ticket data from EED_Ticket_Selector is organized in rows
37
-     * according to how they are displayed in the actual Ticket_Selector
38
-     * this tracks the current row being processed
39
-     *
40
-     * @var int $current_row
41
-     */
42
-    protected $current_row = 0;
43
-
44
-    /**
45
-     * an array for tracking names of tickets that have sold out
46
-     *
47
-     * @var array $sold_out_tickets
48
-     */
49
-    protected $sold_out_tickets = array();
50
-
51
-    /**
52
-     * an array for tracking names of tickets that have had their quantities reduced
53
-     *
54
-     * @var array $decremented_tickets
55
-     */
56
-    protected $decremented_tickets = array();
57
-
58
-
59
-
60
-    /**
61
-     * set_hooks - for hooking into EE Core, other modules, etc
62
-     *
63
-     * @return    void
64
-     */
65
-    public static function set_hooks()
66
-    {
67
-        // release tickets for expired carts
68
-        add_action(
69
-            'EED_Ticket_Selector__process_ticket_selections__before',
70
-            array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'),
71
-            1
72
-        );
73
-        // check ticket reserves AFTER MER does it's check (hence priority 20)
74
-        add_filter(
75
-            'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty',
76
-            array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'),
77
-            20,
78
-            3
79
-        );
80
-        // add notices for sold out tickets
81
-        add_action(
82
-            'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
83
-            array('EED_Ticket_Sales_Monitor', 'post_notices'),
84
-            10
85
-        );
86
-        // handle ticket quantities adjusted in cart
87
-        //add_action(
88
-        //	'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated',
89
-        //	array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ),
90
-        //	10, 2
91
-        //);
92
-        // handle tickets deleted from cart
93
-        add_action(
94
-            'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart',
95
-            array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'),
96
-            10,
97
-            2
98
-        );
99
-        // handle emptied carts
100
-        add_action(
101
-            'AHEE__EE_Session__reset_cart__before_reset',
102
-            array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
103
-            10,
104
-            1
105
-        );
106
-        add_action(
107
-            'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart',
108
-            array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
109
-            10,
110
-            1
111
-        );
112
-        // handle cancelled registrations
113
-        add_action(
114
-            'AHEE__EE_Session__reset_checkout__before_reset',
115
-            array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'),
116
-            10,
117
-            1
118
-        );
119
-        // cron tasks
120
-        add_action(
121
-            'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
122
-            array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
123
-            10,
124
-            1
125
-        );
126
-        add_action(
127
-            'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
128
-            array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
129
-            10,
130
-            1
131
-        );
132
-        add_action(
133
-            'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
134
-            array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'),
135
-            10,
136
-            1
137
-        );
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
144
-     *
145
-     * @return void
146
-     */
147
-    public static function set_hooks_admin()
148
-    {
149
-        EED_Ticket_Sales_Monitor::set_hooks();
150
-    }
151
-
152
-
153
-
154
-    /**
155
-     * @return EED_Ticket_Sales_Monitor|EED_Module
156
-     */
157
-    public static function instance()
158
-    {
159
-        return parent::get_instance(__CLASS__);
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     * @param WP_Query $WP_Query
166
-     * @return    void
167
-     */
168
-    public function run($WP_Query)
169
-    {
170
-    }
171
-
172
-
173
-
174
-    /********************************** PRE_TICKET_SALES  **********************************/
175
-
176
-
177
-
178
-    /**
179
-     * Retrieves grand totals from the line items that have no TXN ID
180
-     * and timestamps less than the current time minus the session lifespan.
181
-     * These are carts that have been abandoned before the "registrant" even attempted to checkout.
182
-     * We're going to release the tickets for these line items before attempting to add more to the cart.
183
-     *
184
-     * @return void
185
-     * @throws DomainException
186
-     * @throws EE_Error
187
-     * @throws InvalidArgumentException
188
-     * @throws InvalidDataTypeException
189
-     * @throws InvalidInterfaceException
190
-     * @throws UnexpectedEntityException
191
-     */
192
-    public static function release_tickets_for_expired_carts()
193
-    {
194
-        do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin');
195
-        $expired_ticket_IDs      = array();
196
-        $valid_ticket_line_items = array();
197
-        $total_line_items        = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction();
198
-        if (empty($total_line_items)) {
199
-            do_action(
200
-                'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end',
201
-                $total_line_items,
202
-                $valid_ticket_line_items,
203
-                $expired_ticket_IDs
204
-            );
205
-            return;
206
-        }
207
-        $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan();
208
-        foreach ($total_line_items as $total_line_item) {
209
-            /** @var EE_Line_Item $total_line_item */
210
-            $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item);
211
-            foreach ($ticket_line_items as $ticket_line_item) {
212
-                if (! $ticket_line_item instanceof EE_Line_Item) {
213
-                    continue;
214
-                }
215
-                if ($total_line_item->timestamp(true) <= $expired) {
216
-                    $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID();
217
-                } else {
218
-                    $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item;
219
-                }
220
-            }
221
-        }
222
-        if (! empty($expired_ticket_IDs)) {
223
-            EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
224
-                \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs),
225
-                $valid_ticket_line_items
226
-            );
227
-            // let's get rid of expired line items so that they can't interfere with tracking
228
-            add_action(
229
-                'shutdown',
230
-                array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'),
231
-                999
232
-            );
233
-        }
234
-        do_action(
235
-            'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end',
236
-            $total_line_items,
237
-            $valid_ticket_line_items,
238
-            $expired_ticket_IDs
239
-        );
240
-    }
241
-
242
-
243
-
244
-    /********************************** VALIDATE_TICKET_SALE  **********************************/
245
-
246
-
247
-
248
-    /**
249
-     * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data'
250
-     *
251
-     * @param int       $qty
252
-     * @param EE_Ticket $ticket
253
-     * @return bool
254
-     * @throws UnexpectedEntityException
255
-     * @throws EE_Error
256
-     */
257
-    public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket)
258
-    {
259
-        $qty = absint($qty);
260
-        if ($qty > 0) {
261
-            $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
262
-        }
263
-        if (self::debug) {
264
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()';
265
-            echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>';
266
-        }
267
-        return $qty;
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * checks whether an individual ticket is available for purchase based on datetime, and ticket details
274
-     *
275
-     * @param   EE_Ticket $ticket
276
-     * @param int         $qty
277
-     * @return int
278
-     * @throws UnexpectedEntityException
279
-     * @throws EE_Error
280
-     */
281
-    protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
282
-    {
283
-        if (self::debug) {
284
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
285
-        }
286
-        if (! $ticket instanceof EE_Ticket) {
287
-            return 0;
288
-        }
289
-        if (self::debug) {
290
-            echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>';
291
-            echo '<br /> . original ticket->reserved: ' . $ticket->reserved();
292
-        }
293
-        $ticket->refresh_from_db();
294
-        // first let's determine the ticket availability based on sales
295
-        $available = $ticket->qty('saleable');
296
-        if (self::debug) {
297
-            echo '<br /> . . . ticket->qty: ' . $ticket->qty();
298
-            echo '<br /> . . . ticket->sold: ' . $ticket->sold();
299
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
300
-            echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
301
-            echo '<br /> . . . available: ' . $available;
302
-        }
303
-        if ($available < 1) {
304
-            $this->_ticket_sold_out($ticket);
305
-            return 0;
306
-        }
307
-        if (self::debug) {
308
-            echo '<br /> . . . qty: ' . $qty;
309
-        }
310
-        if ($available < $qty) {
311
-            $qty = $available;
312
-            if (self::debug) {
313
-                echo '<br /> . . . QTY ADJUSTED: ' . $qty;
314
-            }
315
-            $this->_ticket_quantity_decremented($ticket);
316
-        }
317
-        $this->_reserve_ticket($ticket, $qty);
318
-        return $qty;
319
-    }
320
-
321
-
322
-
323
-    /**
324
-     * increments ticket reserved based on quantity passed
325
-     *
326
-     * @param    EE_Ticket $ticket
327
-     * @param int          $quantity
328
-     * @return bool
329
-     * @throws EE_Error
330
-     */
331
-    protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
332
-    {
333
-        if (self::debug) {
334
-            echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity;
335
-        }
336
-        $ticket->increase_reserved($quantity);
337
-        return $ticket->save();
338
-    }
339
-
340
-
341
-
342
-    /**
343
-     * @param  EE_Ticket $ticket
344
-     * @param  int       $quantity
345
-     * @return bool
346
-     * @throws EE_Error
347
-     */
348
-    protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
349
-    {
350
-        if (self::debug) {
351
-            echo '<br /> . . . ticket->ID: ' . $ticket->ID();
352
-            echo '<br /> . . . ticket->reserved before: ' . $ticket->reserved();
353
-        }
354
-        $ticket->decrease_reserved($quantity);
355
-        if (self::debug) {
356
-            echo '<br /> . . . ticket->reserved after: ' . $ticket->reserved();
357
-        }
358
-        return $ticket->save() ? 1 : 0;
359
-    }
360
-
361
-
362
-
363
-    /**
364
-     * removes quantities within the ticket selector based on zero ticket availability
365
-     *
366
-     * @param    EE_Ticket $ticket
367
-     * @return    void
368
-     * @throws UnexpectedEntityException
369
-     * @throws EE_Error
370
-     */
371
-    protected function _ticket_sold_out(EE_Ticket $ticket)
372
-    {
373
-        if (self::debug) {
374
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
375
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
376
-        }
377
-        $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * adjusts quantities within the ticket selector based on decreased ticket availability
384
-     *
385
-     * @param    EE_Ticket $ticket
386
-     * @return void
387
-     * @throws UnexpectedEntityException
388
-     * @throws EE_Error
389
-     */
390
-    protected function _ticket_quantity_decremented(EE_Ticket $ticket)
391
-    {
392
-        if (self::debug) {
393
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
394
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
395
-        }
396
-        $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
397
-    }
398
-
399
-
400
-
401
-    /**
402
-     * builds string out of ticket and event name
403
-     *
404
-     * @param    EE_Ticket $ticket
405
-     * @return string
406
-     * @throws UnexpectedEntityException
407
-     * @throws EE_Error
408
-     */
409
-    protected function _get_ticket_and_event_name(EE_Ticket $ticket)
410
-    {
411
-        $event = $ticket->get_related_event();
412
-        if ($event instanceof EE_Event) {
413
-            $ticket_name = sprintf(
414
-                _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'),
415
-                $ticket->name(),
416
-                $event->name()
417
-            );
418
-        } else {
419
-            $ticket_name = $ticket->name();
420
-        }
421
-        return $ticket_name;
422
-    }
423
-
424
-
425
-
426
-    /********************************** EVENT CART  **********************************/
427
-
428
-
429
-
430
-    /**
431
-     * releases or reserves ticket(s) based on quantity passed
432
-     *
433
-     * @param  EE_Line_Item $line_item
434
-     * @param  int          $quantity
435
-     * @return void
436
-     * @throws EE_Error
437
-     * @throws InvalidArgumentException
438
-     * @throws InvalidDataTypeException
439
-     * @throws InvalidInterfaceException
440
-     */
441
-    public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1)
442
-    {
443
-        $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID()));
444
-        if ($ticket instanceof EE_Ticket) {
445
-            if ($quantity > 0) {
446
-                EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity);
447
-            } else {
448
-                EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
449
-            }
450
-        }
451
-    }
452
-
453
-
454
-
455
-    /**
456
-     * releases reserved ticket(s) based on quantity passed
457
-     *
458
-     * @param  EE_Ticket $ticket
459
-     * @param  int       $quantity
460
-     * @return void
461
-     * @throws EE_Error
462
-     */
463
-    public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1)
464
-    {
465
-        EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
466
-    }
467
-
468
-
469
-
470
-    /********************************** POST_NOTICES  **********************************/
471
-
472
-
473
-
474
-    /**
475
-     * @return void
476
-     * @throws EE_Error
477
-     * @throws InvalidArgumentException
478
-     * @throws ReflectionException
479
-     * @throws InvalidDataTypeException
480
-     * @throws InvalidInterfaceException
481
-     */
482
-    public static function post_notices()
483
-    {
484
-        EED_Ticket_Sales_Monitor::instance()->_post_notices();
485
-    }
486
-
487
-
488
-
489
-    /**
490
-     * @return void
491
-     * @throws EE_Error
492
-     * @throws InvalidArgumentException
493
-     * @throws ReflectionException
494
-     * @throws InvalidDataTypeException
495
-     * @throws InvalidInterfaceException
496
-     */
497
-    protected function _post_notices()
498
-    {
499
-        if (self::debug) {
500
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
501
-        }
502
-        $refresh_msg    = '';
503
-        $none_added_msg = '';
504
-        if (defined('DOING_AJAX') && DOING_AJAX) {
505
-            $refresh_msg    = __(
506
-                'Please refresh the page to view updated ticket quantities.',
507
-                'event_espresso'
508
-            );
509
-            $none_added_msg = __('No tickets were added for the event.', 'event_espresso');
510
-        }
511
-        if (! empty($this->sold_out_tickets)) {
512
-            EE_Error::add_attention(
513
-                sprintf(
514
-                    apply_filters(
515
-                        'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice',
516
-                        __(
517
-                            'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s',
518
-                            'event_espresso'
519
-                        )
520
-                    ),
521
-                    '<br />',
522
-                    implode('<br />', $this->sold_out_tickets),
523
-                    $none_added_msg,
524
-                    $refresh_msg
525
-                )
526
-            );
527
-            // alter code flow in the Ticket Selector for better UX
528
-            add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true');
529
-            add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false');
530
-            $this->sold_out_tickets = array();
531
-            // and reset the cart
532
-            EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN);
533
-        }
534
-        if (! empty($this->decremented_tickets)) {
535
-            EE_Error::add_attention(
536
-                sprintf(
537
-                    apply_filters(
538
-                        'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice',
539
-                        __(
540
-                            'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s',
541
-                            'event_espresso'
542
-                        )
543
-                    ),
544
-                    '<br />',
545
-                    implode('<br />', $this->decremented_tickets),
546
-                    $none_added_msg,
547
-                    $refresh_msg
548
-                )
549
-            );
550
-            $this->decremented_tickets = array();
551
-        }
552
-    }
553
-
554
-
555
-
556
-    /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION  **********************************/
557
-
558
-
559
-
560
-    /**
561
-     * releases reserved tickets for all registrations of an EE_Transaction
562
-     * by default, will NOT release tickets for finalized transactions
563
-     *
564
-     * @param    EE_Transaction $transaction
565
-     * @return int
566
-     * @throws EE_Error
567
-     * @throws InvalidSessionDataException
568
-     */
569
-    protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
570
-    {
571
-        if (self::debug) {
572
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
573
-            echo '<br /> . transaction->ID: ' . $transaction->ID();
574
-        }
575
-        // check if 'finalize_registration' step has been completed...
576
-        $finalized = $transaction->reg_step_completed('finalize_registration');
577
-        if (self::debug) {
578
-            // DEBUG LOG
579
-            EEH_Debug_Tools::log(
580
-                __CLASS__,
581
-                __FUNCTION__,
582
-                __LINE__,
583
-                array('finalized' => $finalized),
584
-                false,
585
-                'EE_Transaction: ' . $transaction->ID()
586
-            );
587
-        }
588
-        // how many tickets were released
589
-        $count = 0;
590
-        if (self::debug) {
591
-            echo '<br /> . . . finalized: ' . $finalized;
592
-        }
593
-        $release_tickets_with_TXN_status = array(
594
-            EEM_Transaction::failed_status_code,
595
-            EEM_Transaction::abandoned_status_code,
596
-            EEM_Transaction::incomplete_status_code,
597
-        );
598
-        // if the session is getting cleared BEFORE the TXN has been finalized
599
-        if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
600
-            // let's cancel any reserved tickets
601
-            $registrations = $transaction->registrations();
602
-            if (! empty($registrations)) {
603
-                foreach ($registrations as $registration) {
604
-                    if ($registration instanceof EE_Registration) {
605
-                        $count += $this->_release_reserved_ticket_for_registration($registration, $transaction);
606
-                    }
607
-                }
608
-            }
609
-        }
610
-        return $count;
611
-    }
612
-
613
-
614
-
615
-    /**
616
-     * releases reserved tickets for an EE_Registration
617
-     * by default, will NOT release tickets for APPROVED registrations
618
-     *
619
-     * @param EE_Registration $registration
620
-     * @param EE_Transaction  $transaction
621
-     * @return int
622
-     * @throws EE_Error
623
-     */
624
-    protected function _release_reserved_ticket_for_registration(
625
-        EE_Registration $registration,
626
-        EE_Transaction $transaction
627
-    ) {
628
-        $STS_ID = $transaction->status_ID();
629
-        if (self::debug) {
630
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
631
-            echo '<br /> . . registration->ID: ' . $registration->ID();
632
-            echo '<br /> . . registration->status_ID: ' . $registration->status_ID();
633
-            echo '<br /> . . transaction->status_ID(): ' . $STS_ID;
634
-        }
635
-        if (
636
-            // release Tickets for Failed Transactions and Abandoned Transactions
637
-            $STS_ID === EEM_Transaction::failed_status_code
638
-            || $STS_ID === EEM_Transaction::abandoned_status_code
639
-            || (
640
-                // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved
641
-                $STS_ID === EEM_Transaction::incomplete_status_code
642
-                && $registration->status_ID() !== EEM_Registration::status_id_approved
643
-            )
644
-        ) {
645
-            $ticket = $registration->ticket();
646
-            if ($ticket instanceof EE_Ticket) {
647
-                return $this->_release_reserved_ticket($ticket);
648
-            }
649
-        }
650
-        return 0;
651
-    }
652
-
653
-
654
-
655
-    /********************************** SESSION_CART_RESET  **********************************/
656
-
657
-
658
-
659
-    /**
660
-     * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset'
661
-     *
662
-     * @param EE_Session $session
663
-     * @return void
664
-     * @throws EE_Error
665
-     * @throws InvalidArgumentException
666
-     * @throws ReflectionException
667
-     * @throws InvalidDataTypeException
668
-     * @throws InvalidInterfaceException
669
-     */
670
-    public static function session_cart_reset(EE_Session $session)
671
-    {
672
-        // don't release tickets if checkout was already reset
673
-        if (did_action('AHEE__EE_Session__reset_checkout__before_reset')) {
674
-            return;
675
-        }
676
-        if (self::debug) {
677
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
678
-        }
679
-        $cart = $session->cart();
680
-        if ($cart instanceof EE_Cart) {
681
-            if (self::debug) {
682
-                echo '<br /><br /> cart instance of EE_Cart: ';
683
-            }
684
-            EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart);
685
-        } else {
686
-            if (self::debug) {
687
-                echo '<br /><br /> invalid EE_Cart: ';
688
-                var_export($cart, true);
689
-            }
690
-        }
691
-    }
692
-
693
-
694
-
695
-    /**
696
-     * releases reserved tickets in the EE_Cart
697
-     *
698
-     * @param EE_Cart $cart
699
-     * @return void
700
-     * @throws EE_Error
701
-     * @throws InvalidArgumentException
702
-     * @throws ReflectionException
703
-     * @throws InvalidDataTypeException
704
-     * @throws InvalidInterfaceException
705
-     */
706
-    protected function _session_cart_reset(EE_Cart $cart)
707
-    {
708
-        if (self::debug) {
709
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
710
-        }
711
-        $ticket_line_items = $cart->get_tickets();
712
-        if (empty($ticket_line_items)) {
713
-            return;
714
-        }
715
-        if (self::debug) {
716
-            echo '<br /> . ticket_line_item count: ' . count($ticket_line_items);
717
-        }
718
-        foreach ($ticket_line_items as $ticket_line_item) {
719
-            if (self::debug) {
720
-                echo '<br /> . . ticket_line_item->ID(): ' . $ticket_line_item->ID();
721
-            }
722
-            if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
723
-                if (self::debug) {
724
-                    echo '<br /> . . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
725
-                }
726
-                $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
727
-                if ($ticket instanceof EE_Ticket) {
728
-                    if (self::debug) {
729
-                        echo '<br /> . . . ticket->ID(): ' . $ticket->ID();
730
-                        echo '<br /> . . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
731
-                    }
732
-                    $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
733
-                }
734
-            }
735
-        }
736
-        if (self::debug) {
737
-            echo '<br /><br /> RESET COMPLETED ';
738
-        }
739
-    }
740
-
741
-
742
-
743
-    /********************************** SESSION_CHECKOUT_RESET  **********************************/
744
-
745
-
746
-
747
-    /**
748
-     * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset'
749
-     *
750
-     * @param EE_Session $session
751
-     * @return void
752
-     * @throws EE_Error
753
-     * @throws InvalidSessionDataException
754
-     */
755
-    public static function session_checkout_reset(EE_Session $session)
756
-    {
757
-        // don't release tickets if cart was already reset
758
-        if(did_action('AHEE__EE_Session__reset_cart__before_reset')) {
759
-            return;
760
-        }
761
-        $checkout = $session->checkout();
762
-        if ($checkout instanceof EE_Checkout) {
763
-            EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout);
764
-        }
765
-    }
766
-
767
-
768
-
769
-    /**
770
-     * releases reserved tickets for the EE_Checkout->transaction
771
-     *
772
-     * @param EE_Checkout $checkout
773
-     * @return void
774
-     * @throws EE_Error
775
-     * @throws InvalidSessionDataException
776
-     */
777
-    protected function _session_checkout_reset(EE_Checkout $checkout)
778
-    {
779
-        if (self::debug) {
780
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
781
-        }
782
-        // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
783
-        if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
784
-            return;
785
-        }
786
-        $this->_release_all_reserved_tickets_for_transaction($checkout->transaction);
787
-    }
788
-
789
-
790
-
791
-    /********************************** SESSION_EXPIRED_RESET  **********************************/
792
-
793
-
794
-
795
-    /**
796
-     * @param    EE_Session $session
797
-     * @return    void
798
-     */
799
-    public static function session_expired_reset(EE_Session $session)
800
-    {
801
-    }
802
-
803
-
804
-
805
-    /********************************** PROCESS_ABANDONED_TRANSACTIONS  **********************************/
806
-
807
-
808
-
809
-    /**
810
-     * releases reserved tickets for all registrations of an ABANDONED EE_Transaction
811
-     * by default, will NOT release tickets for free transactions, or any that have received a payment
812
-     *
813
-     * @param EE_Transaction $transaction
814
-     * @return void
815
-     * @throws EE_Error
816
-     * @throws InvalidSessionDataException
817
-     */
818
-    public static function process_abandoned_transactions(EE_Transaction $transaction)
819
-    {
820
-        // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone
821
-        if ($transaction->is_free() || $transaction->paid() > 0) {
822
-            if (self::debug) {
823
-                // DEBUG LOG
824
-                EEH_Debug_Tools::log(
825
-                    __CLASS__,
826
-                    __FUNCTION__,
827
-                    __LINE__,
828
-                    array($transaction),
829
-                    false,
830
-                    'EE_Transaction: ' . $transaction->ID()
831
-                );
832
-            }
833
-            return;
834
-        }
835
-        // have their been any successful payments made ?
836
-        $payments = $transaction->payments();
837
-        foreach ($payments as $payment) {
838
-            if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) {
839
-                if (self::debug) {
840
-                    // DEBUG LOG
841
-                    EEH_Debug_Tools::log(
842
-                        __CLASS__,
843
-                        __FUNCTION__,
844
-                        __LINE__,
845
-                        array($payment),
846
-                        false,
847
-                        'EE_Transaction: ' . $transaction->ID()
848
-                    );
849
-                }
850
-                return;
851
-            }
852
-        }
853
-        // since you haven't even attempted to pay for your ticket...
854
-        EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
855
-    }
856
-
857
-
858
-
859
-    /********************************** PROCESS_FAILED_TRANSACTIONS  **********************************/
860
-
861
-
862
-
863
-    /**
864
-     * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction
865
-     *
866
-     * @param EE_Transaction $transaction
867
-     * @return void
868
-     * @throws EE_Error
869
-     * @throws InvalidSessionDataException
870
-     */
871
-    public static function process_failed_transactions(EE_Transaction $transaction)
872
-    {
873
-        // since you haven't even attempted to pay for your ticket...
874
-        EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
875
-    }
876
-
877
-
878
-
879
-    /********************************** RESET RESERVATION COUNTS  *********************************/
880
-
881
-
882
-
883
-    /**
884
-     * Resets all ticket and datetime reserved counts to zero
885
-     * Tickets that are currently associated with a Transaction that is in progress
886
-     *
887
-     * @throws EE_Error
888
-     * @throws DomainException
889
-     * @throws InvalidDataTypeException
890
-     * @throws InvalidInterfaceException
891
-     * @throws InvalidArgumentException
892
-     * @throws UnexpectedEntityException
893
-     */
894
-    public static function reset_reservation_counts()
895
-    {
896
-        /** @var EE_Line_Item[] $valid_reserved_tickets */
897
-        $valid_reserved_tickets = array();
898
-        /** @var EE_Transaction[] $transactions_not_in_progress */
899
-        $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress();
900
-        foreach ($transactions_not_in_progress as $transaction) {
901
-            // if this TXN has been fully completed, then skip it
902
-            if ($transaction->reg_step_completed('finalize_registration')) {
903
-                continue;
904
-            }
905
-            $total_line_item = $transaction->total_line_item();
906
-            // $transaction_in_progress->line
907
-            if (! $total_line_item instanceof EE_Line_Item) {
908
-                throw new DomainException(
909
-                    esc_html__(
910
-                        'Transaction does not have a valid Total Line Item associated with it.',
911
-                        'event_espresso'
912
-                    )
913
-                );
914
-            }
915
-            $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
916
-                $total_line_item
917
-            );
918
-        }
919
-        $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts();
920
-        foreach ($total_line_items as $total_line_item) {
921
-            $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
922
-                $total_line_item
923
-            );
924
-        }
925
-        return EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
926
-            EEM_Ticket::instance()->get_tickets_with_reservations(),
927
-            $valid_reserved_tickets
928
-        );
929
-    }
930
-
931
-
932
-
933
-    /**
934
-     * @param EE_Line_Item $total_line_item
935
-     * @return EE_Line_Item[]
936
-     */
937
-    private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item)
938
-    {
939
-        /** @var EE_Line_Item[] $valid_reserved_tickets */
940
-        $valid_reserved_tickets = array();
941
-        $ticket_line_items      = EEH_Line_Item::get_ticket_line_items($total_line_item);
942
-        foreach ($ticket_line_items as $ticket_line_item) {
943
-            if ($ticket_line_item instanceof EE_Line_Item) {
944
-                $valid_reserved_tickets[] = $ticket_line_item;
945
-            }
946
-        }
947
-        return $valid_reserved_tickets;
948
-    }
949
-
950
-
951
-
952
-    /**
953
-     * @param EE_Ticket[]    $tickets_with_reservations
954
-     * @param EE_Line_Item[] $valid_reserved_ticket_line_items
955
-     * @return int
956
-     * @throws UnexpectedEntityException
957
-     * @throws DomainException
958
-     * @throws EE_Error
959
-     */
960
-    private static function release_reservations_for_tickets(
961
-        array $tickets_with_reservations,
962
-        array $valid_reserved_ticket_line_items = array()
963
-    ) {
964
-        $total_tickets_released = 0;
965
-        $sold_out_events = array();
966
-        foreach ($tickets_with_reservations as $ticket_with_reservations) {
967
-            if (! $ticket_with_reservations instanceof EE_Ticket) {
968
-                continue;
969
-            }
970
-            $reserved_qty = $ticket_with_reservations->reserved();
971
-            foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) {
972
-                if (
973
-                    $valid_reserved_ticket_line_item instanceof EE_Line_Item
974
-                    && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID()
975
-                ) {
976
-                    $reserved_qty -= $valid_reserved_ticket_line_item->quantity();
977
-                }
978
-            }
979
-            if ($reserved_qty > 0) {
980
-                $ticket_with_reservations->decrease_reserved($reserved_qty);
981
-                $ticket_with_reservations->save();
982
-                $total_tickets_released += $reserved_qty;
983
-                $event = $ticket_with_reservations->get_related_event();
984
-                // track sold out events
985
-                if ($event instanceof EE_Event && $event->is_sold_out()) {
986
-                    $sold_out_events[] = $event;
987
-                }
988
-            }
989
-        }
990
-        // double check whether sold out events should remain sold out after releasing tickets
991
-        if($sold_out_events !== array()){
992
-            foreach ($sold_out_events as $sold_out_event) {
993
-                /** @var EE_Event $sold_out_event */
994
-                $sold_out_event->perform_sold_out_status_check();
995
-            }
996
-        }
997
-        return $total_tickets_released;
998
-    }
999
-
1000
-
1001
-
1002
-    /********************************** SHUTDOWN  **********************************/
1003
-
1004
-
1005
-
1006
-    /**
1007
-     * @return false|int
1008
-     * @throws EE_Error
1009
-     * @throws InvalidArgumentException
1010
-     * @throws InvalidDataTypeException
1011
-     * @throws InvalidInterfaceException
1012
-     */
1013
-    public static function clear_expired_line_items_with_no_transaction()
1014
-    {
1015
-        /** @type WPDB $wpdb */
1016
-        global $wpdb;
1017
-        return $wpdb->query(
1018
-            $wpdb->prepare(
1019
-                'DELETE FROM ' . EEM_Line_Item::instance()->table() . '
26
+	const debug = false;    //	true false
27
+
28
+	/**
29
+	 * an array of raw ticket data from EED_Ticket_Selector
30
+	 *
31
+	 * @var array $ticket_selections
32
+	 */
33
+	protected $ticket_selections = array();
34
+
35
+	/**
36
+	 * the raw ticket data from EED_Ticket_Selector is organized in rows
37
+	 * according to how they are displayed in the actual Ticket_Selector
38
+	 * this tracks the current row being processed
39
+	 *
40
+	 * @var int $current_row
41
+	 */
42
+	protected $current_row = 0;
43
+
44
+	/**
45
+	 * an array for tracking names of tickets that have sold out
46
+	 *
47
+	 * @var array $sold_out_tickets
48
+	 */
49
+	protected $sold_out_tickets = array();
50
+
51
+	/**
52
+	 * an array for tracking names of tickets that have had their quantities reduced
53
+	 *
54
+	 * @var array $decremented_tickets
55
+	 */
56
+	protected $decremented_tickets = array();
57
+
58
+
59
+
60
+	/**
61
+	 * set_hooks - for hooking into EE Core, other modules, etc
62
+	 *
63
+	 * @return    void
64
+	 */
65
+	public static function set_hooks()
66
+	{
67
+		// release tickets for expired carts
68
+		add_action(
69
+			'EED_Ticket_Selector__process_ticket_selections__before',
70
+			array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'),
71
+			1
72
+		);
73
+		// check ticket reserves AFTER MER does it's check (hence priority 20)
74
+		add_filter(
75
+			'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty',
76
+			array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'),
77
+			20,
78
+			3
79
+		);
80
+		// add notices for sold out tickets
81
+		add_action(
82
+			'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
83
+			array('EED_Ticket_Sales_Monitor', 'post_notices'),
84
+			10
85
+		);
86
+		// handle ticket quantities adjusted in cart
87
+		//add_action(
88
+		//	'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated',
89
+		//	array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ),
90
+		//	10, 2
91
+		//);
92
+		// handle tickets deleted from cart
93
+		add_action(
94
+			'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart',
95
+			array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'),
96
+			10,
97
+			2
98
+		);
99
+		// handle emptied carts
100
+		add_action(
101
+			'AHEE__EE_Session__reset_cart__before_reset',
102
+			array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
103
+			10,
104
+			1
105
+		);
106
+		add_action(
107
+			'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart',
108
+			array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
109
+			10,
110
+			1
111
+		);
112
+		// handle cancelled registrations
113
+		add_action(
114
+			'AHEE__EE_Session__reset_checkout__before_reset',
115
+			array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'),
116
+			10,
117
+			1
118
+		);
119
+		// cron tasks
120
+		add_action(
121
+			'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
122
+			array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
123
+			10,
124
+			1
125
+		);
126
+		add_action(
127
+			'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
128
+			array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
129
+			10,
130
+			1
131
+		);
132
+		add_action(
133
+			'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
134
+			array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'),
135
+			10,
136
+			1
137
+		);
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
144
+	 *
145
+	 * @return void
146
+	 */
147
+	public static function set_hooks_admin()
148
+	{
149
+		EED_Ticket_Sales_Monitor::set_hooks();
150
+	}
151
+
152
+
153
+
154
+	/**
155
+	 * @return EED_Ticket_Sales_Monitor|EED_Module
156
+	 */
157
+	public static function instance()
158
+	{
159
+		return parent::get_instance(__CLASS__);
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 * @param WP_Query $WP_Query
166
+	 * @return    void
167
+	 */
168
+	public function run($WP_Query)
169
+	{
170
+	}
171
+
172
+
173
+
174
+	/********************************** PRE_TICKET_SALES  **********************************/
175
+
176
+
177
+
178
+	/**
179
+	 * Retrieves grand totals from the line items that have no TXN ID
180
+	 * and timestamps less than the current time minus the session lifespan.
181
+	 * These are carts that have been abandoned before the "registrant" even attempted to checkout.
182
+	 * We're going to release the tickets for these line items before attempting to add more to the cart.
183
+	 *
184
+	 * @return void
185
+	 * @throws DomainException
186
+	 * @throws EE_Error
187
+	 * @throws InvalidArgumentException
188
+	 * @throws InvalidDataTypeException
189
+	 * @throws InvalidInterfaceException
190
+	 * @throws UnexpectedEntityException
191
+	 */
192
+	public static function release_tickets_for_expired_carts()
193
+	{
194
+		do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin');
195
+		$expired_ticket_IDs      = array();
196
+		$valid_ticket_line_items = array();
197
+		$total_line_items        = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction();
198
+		if (empty($total_line_items)) {
199
+			do_action(
200
+				'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end',
201
+				$total_line_items,
202
+				$valid_ticket_line_items,
203
+				$expired_ticket_IDs
204
+			);
205
+			return;
206
+		}
207
+		$expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan();
208
+		foreach ($total_line_items as $total_line_item) {
209
+			/** @var EE_Line_Item $total_line_item */
210
+			$ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item);
211
+			foreach ($ticket_line_items as $ticket_line_item) {
212
+				if (! $ticket_line_item instanceof EE_Line_Item) {
213
+					continue;
214
+				}
215
+				if ($total_line_item->timestamp(true) <= $expired) {
216
+					$expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID();
217
+				} else {
218
+					$valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item;
219
+				}
220
+			}
221
+		}
222
+		if (! empty($expired_ticket_IDs)) {
223
+			EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
224
+				\EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs),
225
+				$valid_ticket_line_items
226
+			);
227
+			// let's get rid of expired line items so that they can't interfere with tracking
228
+			add_action(
229
+				'shutdown',
230
+				array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'),
231
+				999
232
+			);
233
+		}
234
+		do_action(
235
+			'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end',
236
+			$total_line_items,
237
+			$valid_ticket_line_items,
238
+			$expired_ticket_IDs
239
+		);
240
+	}
241
+
242
+
243
+
244
+	/********************************** VALIDATE_TICKET_SALE  **********************************/
245
+
246
+
247
+
248
+	/**
249
+	 * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data'
250
+	 *
251
+	 * @param int       $qty
252
+	 * @param EE_Ticket $ticket
253
+	 * @return bool
254
+	 * @throws UnexpectedEntityException
255
+	 * @throws EE_Error
256
+	 */
257
+	public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket)
258
+	{
259
+		$qty = absint($qty);
260
+		if ($qty > 0) {
261
+			$qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
262
+		}
263
+		if (self::debug) {
264
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()';
265
+			echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>';
266
+		}
267
+		return $qty;
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * checks whether an individual ticket is available for purchase based on datetime, and ticket details
274
+	 *
275
+	 * @param   EE_Ticket $ticket
276
+	 * @param int         $qty
277
+	 * @return int
278
+	 * @throws UnexpectedEntityException
279
+	 * @throws EE_Error
280
+	 */
281
+	protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
282
+	{
283
+		if (self::debug) {
284
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
285
+		}
286
+		if (! $ticket instanceof EE_Ticket) {
287
+			return 0;
288
+		}
289
+		if (self::debug) {
290
+			echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>';
291
+			echo '<br /> . original ticket->reserved: ' . $ticket->reserved();
292
+		}
293
+		$ticket->refresh_from_db();
294
+		// first let's determine the ticket availability based on sales
295
+		$available = $ticket->qty('saleable');
296
+		if (self::debug) {
297
+			echo '<br /> . . . ticket->qty: ' . $ticket->qty();
298
+			echo '<br /> . . . ticket->sold: ' . $ticket->sold();
299
+			echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
300
+			echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
301
+			echo '<br /> . . . available: ' . $available;
302
+		}
303
+		if ($available < 1) {
304
+			$this->_ticket_sold_out($ticket);
305
+			return 0;
306
+		}
307
+		if (self::debug) {
308
+			echo '<br /> . . . qty: ' . $qty;
309
+		}
310
+		if ($available < $qty) {
311
+			$qty = $available;
312
+			if (self::debug) {
313
+				echo '<br /> . . . QTY ADJUSTED: ' . $qty;
314
+			}
315
+			$this->_ticket_quantity_decremented($ticket);
316
+		}
317
+		$this->_reserve_ticket($ticket, $qty);
318
+		return $qty;
319
+	}
320
+
321
+
322
+
323
+	/**
324
+	 * increments ticket reserved based on quantity passed
325
+	 *
326
+	 * @param    EE_Ticket $ticket
327
+	 * @param int          $quantity
328
+	 * @return bool
329
+	 * @throws EE_Error
330
+	 */
331
+	protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
332
+	{
333
+		if (self::debug) {
334
+			echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity;
335
+		}
336
+		$ticket->increase_reserved($quantity);
337
+		return $ticket->save();
338
+	}
339
+
340
+
341
+
342
+	/**
343
+	 * @param  EE_Ticket $ticket
344
+	 * @param  int       $quantity
345
+	 * @return bool
346
+	 * @throws EE_Error
347
+	 */
348
+	protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
349
+	{
350
+		if (self::debug) {
351
+			echo '<br /> . . . ticket->ID: ' . $ticket->ID();
352
+			echo '<br /> . . . ticket->reserved before: ' . $ticket->reserved();
353
+		}
354
+		$ticket->decrease_reserved($quantity);
355
+		if (self::debug) {
356
+			echo '<br /> . . . ticket->reserved after: ' . $ticket->reserved();
357
+		}
358
+		return $ticket->save() ? 1 : 0;
359
+	}
360
+
361
+
362
+
363
+	/**
364
+	 * removes quantities within the ticket selector based on zero ticket availability
365
+	 *
366
+	 * @param    EE_Ticket $ticket
367
+	 * @return    void
368
+	 * @throws UnexpectedEntityException
369
+	 * @throws EE_Error
370
+	 */
371
+	protected function _ticket_sold_out(EE_Ticket $ticket)
372
+	{
373
+		if (self::debug) {
374
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
375
+			echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
376
+		}
377
+		$this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * adjusts quantities within the ticket selector based on decreased ticket availability
384
+	 *
385
+	 * @param    EE_Ticket $ticket
386
+	 * @return void
387
+	 * @throws UnexpectedEntityException
388
+	 * @throws EE_Error
389
+	 */
390
+	protected function _ticket_quantity_decremented(EE_Ticket $ticket)
391
+	{
392
+		if (self::debug) {
393
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
394
+			echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
395
+		}
396
+		$this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
397
+	}
398
+
399
+
400
+
401
+	/**
402
+	 * builds string out of ticket and event name
403
+	 *
404
+	 * @param    EE_Ticket $ticket
405
+	 * @return string
406
+	 * @throws UnexpectedEntityException
407
+	 * @throws EE_Error
408
+	 */
409
+	protected function _get_ticket_and_event_name(EE_Ticket $ticket)
410
+	{
411
+		$event = $ticket->get_related_event();
412
+		if ($event instanceof EE_Event) {
413
+			$ticket_name = sprintf(
414
+				_x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'),
415
+				$ticket->name(),
416
+				$event->name()
417
+			);
418
+		} else {
419
+			$ticket_name = $ticket->name();
420
+		}
421
+		return $ticket_name;
422
+	}
423
+
424
+
425
+
426
+	/********************************** EVENT CART  **********************************/
427
+
428
+
429
+
430
+	/**
431
+	 * releases or reserves ticket(s) based on quantity passed
432
+	 *
433
+	 * @param  EE_Line_Item $line_item
434
+	 * @param  int          $quantity
435
+	 * @return void
436
+	 * @throws EE_Error
437
+	 * @throws InvalidArgumentException
438
+	 * @throws InvalidDataTypeException
439
+	 * @throws InvalidInterfaceException
440
+	 */
441
+	public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1)
442
+	{
443
+		$ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID()));
444
+		if ($ticket instanceof EE_Ticket) {
445
+			if ($quantity > 0) {
446
+				EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity);
447
+			} else {
448
+				EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
449
+			}
450
+		}
451
+	}
452
+
453
+
454
+
455
+	/**
456
+	 * releases reserved ticket(s) based on quantity passed
457
+	 *
458
+	 * @param  EE_Ticket $ticket
459
+	 * @param  int       $quantity
460
+	 * @return void
461
+	 * @throws EE_Error
462
+	 */
463
+	public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1)
464
+	{
465
+		EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
466
+	}
467
+
468
+
469
+
470
+	/********************************** POST_NOTICES  **********************************/
471
+
472
+
473
+
474
+	/**
475
+	 * @return void
476
+	 * @throws EE_Error
477
+	 * @throws InvalidArgumentException
478
+	 * @throws ReflectionException
479
+	 * @throws InvalidDataTypeException
480
+	 * @throws InvalidInterfaceException
481
+	 */
482
+	public static function post_notices()
483
+	{
484
+		EED_Ticket_Sales_Monitor::instance()->_post_notices();
485
+	}
486
+
487
+
488
+
489
+	/**
490
+	 * @return void
491
+	 * @throws EE_Error
492
+	 * @throws InvalidArgumentException
493
+	 * @throws ReflectionException
494
+	 * @throws InvalidDataTypeException
495
+	 * @throws InvalidInterfaceException
496
+	 */
497
+	protected function _post_notices()
498
+	{
499
+		if (self::debug) {
500
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
501
+		}
502
+		$refresh_msg    = '';
503
+		$none_added_msg = '';
504
+		if (defined('DOING_AJAX') && DOING_AJAX) {
505
+			$refresh_msg    = __(
506
+				'Please refresh the page to view updated ticket quantities.',
507
+				'event_espresso'
508
+			);
509
+			$none_added_msg = __('No tickets were added for the event.', 'event_espresso');
510
+		}
511
+		if (! empty($this->sold_out_tickets)) {
512
+			EE_Error::add_attention(
513
+				sprintf(
514
+					apply_filters(
515
+						'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice',
516
+						__(
517
+							'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s',
518
+							'event_espresso'
519
+						)
520
+					),
521
+					'<br />',
522
+					implode('<br />', $this->sold_out_tickets),
523
+					$none_added_msg,
524
+					$refresh_msg
525
+				)
526
+			);
527
+			// alter code flow in the Ticket Selector for better UX
528
+			add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true');
529
+			add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false');
530
+			$this->sold_out_tickets = array();
531
+			// and reset the cart
532
+			EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN);
533
+		}
534
+		if (! empty($this->decremented_tickets)) {
535
+			EE_Error::add_attention(
536
+				sprintf(
537
+					apply_filters(
538
+						'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice',
539
+						__(
540
+							'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s',
541
+							'event_espresso'
542
+						)
543
+					),
544
+					'<br />',
545
+					implode('<br />', $this->decremented_tickets),
546
+					$none_added_msg,
547
+					$refresh_msg
548
+				)
549
+			);
550
+			$this->decremented_tickets = array();
551
+		}
552
+	}
553
+
554
+
555
+
556
+	/********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION  **********************************/
557
+
558
+
559
+
560
+	/**
561
+	 * releases reserved tickets for all registrations of an EE_Transaction
562
+	 * by default, will NOT release tickets for finalized transactions
563
+	 *
564
+	 * @param    EE_Transaction $transaction
565
+	 * @return int
566
+	 * @throws EE_Error
567
+	 * @throws InvalidSessionDataException
568
+	 */
569
+	protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
570
+	{
571
+		if (self::debug) {
572
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
573
+			echo '<br /> . transaction->ID: ' . $transaction->ID();
574
+		}
575
+		// check if 'finalize_registration' step has been completed...
576
+		$finalized = $transaction->reg_step_completed('finalize_registration');
577
+		if (self::debug) {
578
+			// DEBUG LOG
579
+			EEH_Debug_Tools::log(
580
+				__CLASS__,
581
+				__FUNCTION__,
582
+				__LINE__,
583
+				array('finalized' => $finalized),
584
+				false,
585
+				'EE_Transaction: ' . $transaction->ID()
586
+			);
587
+		}
588
+		// how many tickets were released
589
+		$count = 0;
590
+		if (self::debug) {
591
+			echo '<br /> . . . finalized: ' . $finalized;
592
+		}
593
+		$release_tickets_with_TXN_status = array(
594
+			EEM_Transaction::failed_status_code,
595
+			EEM_Transaction::abandoned_status_code,
596
+			EEM_Transaction::incomplete_status_code,
597
+		);
598
+		// if the session is getting cleared BEFORE the TXN has been finalized
599
+		if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
600
+			// let's cancel any reserved tickets
601
+			$registrations = $transaction->registrations();
602
+			if (! empty($registrations)) {
603
+				foreach ($registrations as $registration) {
604
+					if ($registration instanceof EE_Registration) {
605
+						$count += $this->_release_reserved_ticket_for_registration($registration, $transaction);
606
+					}
607
+				}
608
+			}
609
+		}
610
+		return $count;
611
+	}
612
+
613
+
614
+
615
+	/**
616
+	 * releases reserved tickets for an EE_Registration
617
+	 * by default, will NOT release tickets for APPROVED registrations
618
+	 *
619
+	 * @param EE_Registration $registration
620
+	 * @param EE_Transaction  $transaction
621
+	 * @return int
622
+	 * @throws EE_Error
623
+	 */
624
+	protected function _release_reserved_ticket_for_registration(
625
+		EE_Registration $registration,
626
+		EE_Transaction $transaction
627
+	) {
628
+		$STS_ID = $transaction->status_ID();
629
+		if (self::debug) {
630
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
631
+			echo '<br /> . . registration->ID: ' . $registration->ID();
632
+			echo '<br /> . . registration->status_ID: ' . $registration->status_ID();
633
+			echo '<br /> . . transaction->status_ID(): ' . $STS_ID;
634
+		}
635
+		if (
636
+			// release Tickets for Failed Transactions and Abandoned Transactions
637
+			$STS_ID === EEM_Transaction::failed_status_code
638
+			|| $STS_ID === EEM_Transaction::abandoned_status_code
639
+			|| (
640
+				// also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved
641
+				$STS_ID === EEM_Transaction::incomplete_status_code
642
+				&& $registration->status_ID() !== EEM_Registration::status_id_approved
643
+			)
644
+		) {
645
+			$ticket = $registration->ticket();
646
+			if ($ticket instanceof EE_Ticket) {
647
+				return $this->_release_reserved_ticket($ticket);
648
+			}
649
+		}
650
+		return 0;
651
+	}
652
+
653
+
654
+
655
+	/********************************** SESSION_CART_RESET  **********************************/
656
+
657
+
658
+
659
+	/**
660
+	 * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset'
661
+	 *
662
+	 * @param EE_Session $session
663
+	 * @return void
664
+	 * @throws EE_Error
665
+	 * @throws InvalidArgumentException
666
+	 * @throws ReflectionException
667
+	 * @throws InvalidDataTypeException
668
+	 * @throws InvalidInterfaceException
669
+	 */
670
+	public static function session_cart_reset(EE_Session $session)
671
+	{
672
+		// don't release tickets if checkout was already reset
673
+		if (did_action('AHEE__EE_Session__reset_checkout__before_reset')) {
674
+			return;
675
+		}
676
+		if (self::debug) {
677
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
678
+		}
679
+		$cart = $session->cart();
680
+		if ($cart instanceof EE_Cart) {
681
+			if (self::debug) {
682
+				echo '<br /><br /> cart instance of EE_Cart: ';
683
+			}
684
+			EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart);
685
+		} else {
686
+			if (self::debug) {
687
+				echo '<br /><br /> invalid EE_Cart: ';
688
+				var_export($cart, true);
689
+			}
690
+		}
691
+	}
692
+
693
+
694
+
695
+	/**
696
+	 * releases reserved tickets in the EE_Cart
697
+	 *
698
+	 * @param EE_Cart $cart
699
+	 * @return void
700
+	 * @throws EE_Error
701
+	 * @throws InvalidArgumentException
702
+	 * @throws ReflectionException
703
+	 * @throws InvalidDataTypeException
704
+	 * @throws InvalidInterfaceException
705
+	 */
706
+	protected function _session_cart_reset(EE_Cart $cart)
707
+	{
708
+		if (self::debug) {
709
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
710
+		}
711
+		$ticket_line_items = $cart->get_tickets();
712
+		if (empty($ticket_line_items)) {
713
+			return;
714
+		}
715
+		if (self::debug) {
716
+			echo '<br /> . ticket_line_item count: ' . count($ticket_line_items);
717
+		}
718
+		foreach ($ticket_line_items as $ticket_line_item) {
719
+			if (self::debug) {
720
+				echo '<br /> . . ticket_line_item->ID(): ' . $ticket_line_item->ID();
721
+			}
722
+			if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
723
+				if (self::debug) {
724
+					echo '<br /> . . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
725
+				}
726
+				$ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
727
+				if ($ticket instanceof EE_Ticket) {
728
+					if (self::debug) {
729
+						echo '<br /> . . . ticket->ID(): ' . $ticket->ID();
730
+						echo '<br /> . . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
731
+					}
732
+					$this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
733
+				}
734
+			}
735
+		}
736
+		if (self::debug) {
737
+			echo '<br /><br /> RESET COMPLETED ';
738
+		}
739
+	}
740
+
741
+
742
+
743
+	/********************************** SESSION_CHECKOUT_RESET  **********************************/
744
+
745
+
746
+
747
+	/**
748
+	 * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset'
749
+	 *
750
+	 * @param EE_Session $session
751
+	 * @return void
752
+	 * @throws EE_Error
753
+	 * @throws InvalidSessionDataException
754
+	 */
755
+	public static function session_checkout_reset(EE_Session $session)
756
+	{
757
+		// don't release tickets if cart was already reset
758
+		if(did_action('AHEE__EE_Session__reset_cart__before_reset')) {
759
+			return;
760
+		}
761
+		$checkout = $session->checkout();
762
+		if ($checkout instanceof EE_Checkout) {
763
+			EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout);
764
+		}
765
+	}
766
+
767
+
768
+
769
+	/**
770
+	 * releases reserved tickets for the EE_Checkout->transaction
771
+	 *
772
+	 * @param EE_Checkout $checkout
773
+	 * @return void
774
+	 * @throws EE_Error
775
+	 * @throws InvalidSessionDataException
776
+	 */
777
+	protected function _session_checkout_reset(EE_Checkout $checkout)
778
+	{
779
+		if (self::debug) {
780
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
781
+		}
782
+		// we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
783
+		if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
784
+			return;
785
+		}
786
+		$this->_release_all_reserved_tickets_for_transaction($checkout->transaction);
787
+	}
788
+
789
+
790
+
791
+	/********************************** SESSION_EXPIRED_RESET  **********************************/
792
+
793
+
794
+
795
+	/**
796
+	 * @param    EE_Session $session
797
+	 * @return    void
798
+	 */
799
+	public static function session_expired_reset(EE_Session $session)
800
+	{
801
+	}
802
+
803
+
804
+
805
+	/********************************** PROCESS_ABANDONED_TRANSACTIONS  **********************************/
806
+
807
+
808
+
809
+	/**
810
+	 * releases reserved tickets for all registrations of an ABANDONED EE_Transaction
811
+	 * by default, will NOT release tickets for free transactions, or any that have received a payment
812
+	 *
813
+	 * @param EE_Transaction $transaction
814
+	 * @return void
815
+	 * @throws EE_Error
816
+	 * @throws InvalidSessionDataException
817
+	 */
818
+	public static function process_abandoned_transactions(EE_Transaction $transaction)
819
+	{
820
+		// is this TXN free or has any money been paid towards this TXN? If so, then leave it alone
821
+		if ($transaction->is_free() || $transaction->paid() > 0) {
822
+			if (self::debug) {
823
+				// DEBUG LOG
824
+				EEH_Debug_Tools::log(
825
+					__CLASS__,
826
+					__FUNCTION__,
827
+					__LINE__,
828
+					array($transaction),
829
+					false,
830
+					'EE_Transaction: ' . $transaction->ID()
831
+				);
832
+			}
833
+			return;
834
+		}
835
+		// have their been any successful payments made ?
836
+		$payments = $transaction->payments();
837
+		foreach ($payments as $payment) {
838
+			if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) {
839
+				if (self::debug) {
840
+					// DEBUG LOG
841
+					EEH_Debug_Tools::log(
842
+						__CLASS__,
843
+						__FUNCTION__,
844
+						__LINE__,
845
+						array($payment),
846
+						false,
847
+						'EE_Transaction: ' . $transaction->ID()
848
+					);
849
+				}
850
+				return;
851
+			}
852
+		}
853
+		// since you haven't even attempted to pay for your ticket...
854
+		EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
855
+	}
856
+
857
+
858
+
859
+	/********************************** PROCESS_FAILED_TRANSACTIONS  **********************************/
860
+
861
+
862
+
863
+	/**
864
+	 * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction
865
+	 *
866
+	 * @param EE_Transaction $transaction
867
+	 * @return void
868
+	 * @throws EE_Error
869
+	 * @throws InvalidSessionDataException
870
+	 */
871
+	public static function process_failed_transactions(EE_Transaction $transaction)
872
+	{
873
+		// since you haven't even attempted to pay for your ticket...
874
+		EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
875
+	}
876
+
877
+
878
+
879
+	/********************************** RESET RESERVATION COUNTS  *********************************/
880
+
881
+
882
+
883
+	/**
884
+	 * Resets all ticket and datetime reserved counts to zero
885
+	 * Tickets that are currently associated with a Transaction that is in progress
886
+	 *
887
+	 * @throws EE_Error
888
+	 * @throws DomainException
889
+	 * @throws InvalidDataTypeException
890
+	 * @throws InvalidInterfaceException
891
+	 * @throws InvalidArgumentException
892
+	 * @throws UnexpectedEntityException
893
+	 */
894
+	public static function reset_reservation_counts()
895
+	{
896
+		/** @var EE_Line_Item[] $valid_reserved_tickets */
897
+		$valid_reserved_tickets = array();
898
+		/** @var EE_Transaction[] $transactions_not_in_progress */
899
+		$transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress();
900
+		foreach ($transactions_not_in_progress as $transaction) {
901
+			// if this TXN has been fully completed, then skip it
902
+			if ($transaction->reg_step_completed('finalize_registration')) {
903
+				continue;
904
+			}
905
+			$total_line_item = $transaction->total_line_item();
906
+			// $transaction_in_progress->line
907
+			if (! $total_line_item instanceof EE_Line_Item) {
908
+				throw new DomainException(
909
+					esc_html__(
910
+						'Transaction does not have a valid Total Line Item associated with it.',
911
+						'event_espresso'
912
+					)
913
+				);
914
+			}
915
+			$valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
916
+				$total_line_item
917
+			);
918
+		}
919
+		$total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts();
920
+		foreach ($total_line_items as $total_line_item) {
921
+			$valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
922
+				$total_line_item
923
+			);
924
+		}
925
+		return EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
926
+			EEM_Ticket::instance()->get_tickets_with_reservations(),
927
+			$valid_reserved_tickets
928
+		);
929
+	}
930
+
931
+
932
+
933
+	/**
934
+	 * @param EE_Line_Item $total_line_item
935
+	 * @return EE_Line_Item[]
936
+	 */
937
+	private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item)
938
+	{
939
+		/** @var EE_Line_Item[] $valid_reserved_tickets */
940
+		$valid_reserved_tickets = array();
941
+		$ticket_line_items      = EEH_Line_Item::get_ticket_line_items($total_line_item);
942
+		foreach ($ticket_line_items as $ticket_line_item) {
943
+			if ($ticket_line_item instanceof EE_Line_Item) {
944
+				$valid_reserved_tickets[] = $ticket_line_item;
945
+			}
946
+		}
947
+		return $valid_reserved_tickets;
948
+	}
949
+
950
+
951
+
952
+	/**
953
+	 * @param EE_Ticket[]    $tickets_with_reservations
954
+	 * @param EE_Line_Item[] $valid_reserved_ticket_line_items
955
+	 * @return int
956
+	 * @throws UnexpectedEntityException
957
+	 * @throws DomainException
958
+	 * @throws EE_Error
959
+	 */
960
+	private static function release_reservations_for_tickets(
961
+		array $tickets_with_reservations,
962
+		array $valid_reserved_ticket_line_items = array()
963
+	) {
964
+		$total_tickets_released = 0;
965
+		$sold_out_events = array();
966
+		foreach ($tickets_with_reservations as $ticket_with_reservations) {
967
+			if (! $ticket_with_reservations instanceof EE_Ticket) {
968
+				continue;
969
+			}
970
+			$reserved_qty = $ticket_with_reservations->reserved();
971
+			foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) {
972
+				if (
973
+					$valid_reserved_ticket_line_item instanceof EE_Line_Item
974
+					&& $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID()
975
+				) {
976
+					$reserved_qty -= $valid_reserved_ticket_line_item->quantity();
977
+				}
978
+			}
979
+			if ($reserved_qty > 0) {
980
+				$ticket_with_reservations->decrease_reserved($reserved_qty);
981
+				$ticket_with_reservations->save();
982
+				$total_tickets_released += $reserved_qty;
983
+				$event = $ticket_with_reservations->get_related_event();
984
+				// track sold out events
985
+				if ($event instanceof EE_Event && $event->is_sold_out()) {
986
+					$sold_out_events[] = $event;
987
+				}
988
+			}
989
+		}
990
+		// double check whether sold out events should remain sold out after releasing tickets
991
+		if($sold_out_events !== array()){
992
+			foreach ($sold_out_events as $sold_out_event) {
993
+				/** @var EE_Event $sold_out_event */
994
+				$sold_out_event->perform_sold_out_status_check();
995
+			}
996
+		}
997
+		return $total_tickets_released;
998
+	}
999
+
1000
+
1001
+
1002
+	/********************************** SHUTDOWN  **********************************/
1003
+
1004
+
1005
+
1006
+	/**
1007
+	 * @return false|int
1008
+	 * @throws EE_Error
1009
+	 * @throws InvalidArgumentException
1010
+	 * @throws InvalidDataTypeException
1011
+	 * @throws InvalidInterfaceException
1012
+	 */
1013
+	public static function clear_expired_line_items_with_no_transaction()
1014
+	{
1015
+		/** @type WPDB $wpdb */
1016
+		global $wpdb;
1017
+		return $wpdb->query(
1018
+			$wpdb->prepare(
1019
+				'DELETE FROM ' . EEM_Line_Item::instance()->table() . '
1020 1020
                 WHERE TXN_ID = 0 AND LIN_timestamp <= %s',
1021
-                // use GMT time because that's what LIN_timestamps are in
1022
-                date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan())
1023
-            )
1024
-        );
1025
-    }
1021
+				// use GMT time because that's what LIN_timestamps are in
1022
+				date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan())
1023
+			)
1024
+		);
1025
+	}
1026 1026
 
1027 1027
 }
1028 1028
 // End of file EED_Ticket_Sales_Monitor.module.php
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 class EED_Ticket_Sales_Monitor extends EED_Module
24 24
 {
25 25
 
26
-    const debug = false;    //	true false
26
+    const debug = false; //	true false
27 27
 
28 28
     /**
29 29
      * an array of raw ticket data from EED_Ticket_Selector
@@ -209,17 +209,17 @@  discard block
 block discarded – undo
209 209
             /** @var EE_Line_Item $total_line_item */
210 210
             $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item);
211 211
             foreach ($ticket_line_items as $ticket_line_item) {
212
-                if (! $ticket_line_item instanceof EE_Line_Item) {
212
+                if ( ! $ticket_line_item instanceof EE_Line_Item) {
213 213
                     continue;
214 214
                 }
215 215
                 if ($total_line_item->timestamp(true) <= $expired) {
216
-                    $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID();
216
+                    $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID();
217 217
                 } else {
218
-                    $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item;
218
+                    $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item;
219 219
                 }
220 220
             }
221 221
         }
222
-        if (! empty($expired_ticket_IDs)) {
222
+        if ( ! empty($expired_ticket_IDs)) {
223 223
             EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
224 224
                 \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs),
225 225
                 $valid_ticket_line_items
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
             $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
262 262
         }
263 263
         if (self::debug) {
264
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()';
265
-            echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>';
264
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'()';
265
+            echo '<br /><br /><b> RETURNED QTY: '.$qty.'</b>';
266 266
         }
267 267
         return $qty;
268 268
     }
@@ -281,36 +281,36 @@  discard block
 block discarded – undo
281 281
     protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
282 282
     {
283 283
         if (self::debug) {
284
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
284
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
285 285
         }
286
-        if (! $ticket instanceof EE_Ticket) {
286
+        if ( ! $ticket instanceof EE_Ticket) {
287 287
             return 0;
288 288
         }
289 289
         if (self::debug) {
290
-            echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>';
291
-            echo '<br /> . original ticket->reserved: ' . $ticket->reserved();
290
+            echo '<br /><b> . ticket->ID: '.$ticket->ID().'</b>';
291
+            echo '<br /> . original ticket->reserved: '.$ticket->reserved();
292 292
         }
293 293
         $ticket->refresh_from_db();
294 294
         // first let's determine the ticket availability based on sales
295 295
         $available = $ticket->qty('saleable');
296 296
         if (self::debug) {
297
-            echo '<br /> . . . ticket->qty: ' . $ticket->qty();
298
-            echo '<br /> . . . ticket->sold: ' . $ticket->sold();
299
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
300
-            echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
301
-            echo '<br /> . . . available: ' . $available;
297
+            echo '<br /> . . . ticket->qty: '.$ticket->qty();
298
+            echo '<br /> . . . ticket->sold: '.$ticket->sold();
299
+            echo '<br /> . . . ticket->reserved: '.$ticket->reserved();
300
+            echo '<br /> . . . ticket->qty(saleable): '.$ticket->qty('saleable');
301
+            echo '<br /> . . . available: '.$available;
302 302
         }
303 303
         if ($available < 1) {
304 304
             $this->_ticket_sold_out($ticket);
305 305
             return 0;
306 306
         }
307 307
         if (self::debug) {
308
-            echo '<br /> . . . qty: ' . $qty;
308
+            echo '<br /> . . . qty: '.$qty;
309 309
         }
310 310
         if ($available < $qty) {
311 311
             $qty = $available;
312 312
             if (self::debug) {
313
-                echo '<br /> . . . QTY ADJUSTED: ' . $qty;
313
+                echo '<br /> . . . QTY ADJUSTED: '.$qty;
314 314
             }
315 315
             $this->_ticket_quantity_decremented($ticket);
316 316
         }
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
     protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
332 332
     {
333 333
         if (self::debug) {
334
-            echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity;
334
+            echo '<br /><br /> . . . INCREASE RESERVED: '.$quantity;
335 335
         }
336 336
         $ticket->increase_reserved($quantity);
337 337
         return $ticket->save();
@@ -348,12 +348,12 @@  discard block
 block discarded – undo
348 348
     protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
349 349
     {
350 350
         if (self::debug) {
351
-            echo '<br /> . . . ticket->ID: ' . $ticket->ID();
352
-            echo '<br /> . . . ticket->reserved before: ' . $ticket->reserved();
351
+            echo '<br /> . . . ticket->ID: '.$ticket->ID();
352
+            echo '<br /> . . . ticket->reserved before: '.$ticket->reserved();
353 353
         }
354 354
         $ticket->decrease_reserved($quantity);
355 355
         if (self::debug) {
356
-            echo '<br /> . . . ticket->reserved after: ' . $ticket->reserved();
356
+            echo '<br /> . . . ticket->reserved after: '.$ticket->reserved();
357 357
         }
358 358
         return $ticket->save() ? 1 : 0;
359 359
     }
@@ -371,8 +371,8 @@  discard block
 block discarded – undo
371 371
     protected function _ticket_sold_out(EE_Ticket $ticket)
372 372
     {
373 373
         if (self::debug) {
374
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
375
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
374
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
375
+            echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket);
376 376
         }
377 377
         $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
378 378
     }
@@ -390,8 +390,8 @@  discard block
 block discarded – undo
390 390
     protected function _ticket_quantity_decremented(EE_Ticket $ticket)
391 391
     {
392 392
         if (self::debug) {
393
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
394
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
393
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
394
+            echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket);
395 395
         }
396 396
         $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
397 397
     }
@@ -497,18 +497,18 @@  discard block
 block discarded – undo
497 497
     protected function _post_notices()
498 498
     {
499 499
         if (self::debug) {
500
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
500
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
501 501
         }
502 502
         $refresh_msg    = '';
503 503
         $none_added_msg = '';
504 504
         if (defined('DOING_AJAX') && DOING_AJAX) {
505
-            $refresh_msg    = __(
505
+            $refresh_msg = __(
506 506
                 'Please refresh the page to view updated ticket quantities.',
507 507
                 'event_espresso'
508 508
             );
509 509
             $none_added_msg = __('No tickets were added for the event.', 'event_espresso');
510 510
         }
511
-        if (! empty($this->sold_out_tickets)) {
511
+        if ( ! empty($this->sold_out_tickets)) {
512 512
             EE_Error::add_attention(
513 513
                 sprintf(
514 514
                     apply_filters(
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
             // and reset the cart
532 532
             EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN);
533 533
         }
534
-        if (! empty($this->decremented_tickets)) {
534
+        if ( ! empty($this->decremented_tickets)) {
535 535
             EE_Error::add_attention(
536 536
                 sprintf(
537 537
                     apply_filters(
@@ -569,8 +569,8 @@  discard block
 block discarded – undo
569 569
     protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
570 570
     {
571 571
         if (self::debug) {
572
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
573
-            echo '<br /> . transaction->ID: ' . $transaction->ID();
572
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
573
+            echo '<br /> . transaction->ID: '.$transaction->ID();
574 574
         }
575 575
         // check if 'finalize_registration' step has been completed...
576 576
         $finalized = $transaction->reg_step_completed('finalize_registration');
@@ -582,13 +582,13 @@  discard block
 block discarded – undo
582 582
                 __LINE__,
583 583
                 array('finalized' => $finalized),
584 584
                 false,
585
-                'EE_Transaction: ' . $transaction->ID()
585
+                'EE_Transaction: '.$transaction->ID()
586 586
             );
587 587
         }
588 588
         // how many tickets were released
589 589
         $count = 0;
590 590
         if (self::debug) {
591
-            echo '<br /> . . . finalized: ' . $finalized;
591
+            echo '<br /> . . . finalized: '.$finalized;
592 592
         }
593 593
         $release_tickets_with_TXN_status = array(
594 594
             EEM_Transaction::failed_status_code,
@@ -596,10 +596,10 @@  discard block
 block discarded – undo
596 596
             EEM_Transaction::incomplete_status_code,
597 597
         );
598 598
         // if the session is getting cleared BEFORE the TXN has been finalized
599
-        if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
599
+        if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
600 600
             // let's cancel any reserved tickets
601 601
             $registrations = $transaction->registrations();
602
-            if (! empty($registrations)) {
602
+            if ( ! empty($registrations)) {
603 603
                 foreach ($registrations as $registration) {
604 604
                     if ($registration instanceof EE_Registration) {
605 605
                         $count += $this->_release_reserved_ticket_for_registration($registration, $transaction);
@@ -627,10 +627,10 @@  discard block
 block discarded – undo
627 627
     ) {
628 628
         $STS_ID = $transaction->status_ID();
629 629
         if (self::debug) {
630
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
631
-            echo '<br /> . . registration->ID: ' . $registration->ID();
632
-            echo '<br /> . . registration->status_ID: ' . $registration->status_ID();
633
-            echo '<br /> . . transaction->status_ID(): ' . $STS_ID;
630
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
631
+            echo '<br /> . . registration->ID: '.$registration->ID();
632
+            echo '<br /> . . registration->status_ID: '.$registration->status_ID();
633
+            echo '<br /> . . transaction->status_ID(): '.$STS_ID;
634 634
         }
635 635
         if (
636 636
             // release Tickets for Failed Transactions and Abandoned Transactions
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
             return;
675 675
         }
676 676
         if (self::debug) {
677
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
677
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
678 678
         }
679 679
         $cart = $session->cart();
680 680
         if ($cart instanceof EE_Cart) {
@@ -706,28 +706,28 @@  discard block
 block discarded – undo
706 706
     protected function _session_cart_reset(EE_Cart $cart)
707 707
     {
708 708
         if (self::debug) {
709
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
709
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
710 710
         }
711 711
         $ticket_line_items = $cart->get_tickets();
712 712
         if (empty($ticket_line_items)) {
713 713
             return;
714 714
         }
715 715
         if (self::debug) {
716
-            echo '<br /> . ticket_line_item count: ' . count($ticket_line_items);
716
+            echo '<br /> . ticket_line_item count: '.count($ticket_line_items);
717 717
         }
718 718
         foreach ($ticket_line_items as $ticket_line_item) {
719 719
             if (self::debug) {
720
-                echo '<br /> . . ticket_line_item->ID(): ' . $ticket_line_item->ID();
720
+                echo '<br /> . . ticket_line_item->ID(): '.$ticket_line_item->ID();
721 721
             }
722 722
             if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
723 723
                 if (self::debug) {
724
-                    echo '<br /> . . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
724
+                    echo '<br /> . . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID();
725 725
                 }
726 726
                 $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
727 727
                 if ($ticket instanceof EE_Ticket) {
728 728
                     if (self::debug) {
729
-                        echo '<br /> . . . ticket->ID(): ' . $ticket->ID();
730
-                        echo '<br /> . . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
729
+                        echo '<br /> . . . ticket->ID(): '.$ticket->ID();
730
+                        echo '<br /> . . . ticket_line_item->quantity(): '.$ticket_line_item->quantity();
731 731
                     }
732 732
                     $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
733 733
                 }
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
     public static function session_checkout_reset(EE_Session $session)
756 756
     {
757 757
         // don't release tickets if cart was already reset
758
-        if(did_action('AHEE__EE_Session__reset_cart__before_reset')) {
758
+        if (did_action('AHEE__EE_Session__reset_cart__before_reset')) {
759 759
             return;
760 760
         }
761 761
         $checkout = $session->checkout();
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
     protected function _session_checkout_reset(EE_Checkout $checkout)
778 778
     {
779 779
         if (self::debug) {
780
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
780
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
781 781
         }
782 782
         // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
783 783
         if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
                     __LINE__,
828 828
                     array($transaction),
829 829
                     false,
830
-                    'EE_Transaction: ' . $transaction->ID()
830
+                    'EE_Transaction: '.$transaction->ID()
831 831
                 );
832 832
             }
833 833
             return;
@@ -844,7 +844,7 @@  discard block
 block discarded – undo
844 844
                         __LINE__,
845 845
                         array($payment),
846 846
                         false,
847
-                        'EE_Transaction: ' . $transaction->ID()
847
+                        'EE_Transaction: '.$transaction->ID()
848 848
                     );
849 849
                 }
850 850
                 return;
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
             }
905 905
             $total_line_item = $transaction->total_line_item();
906 906
             // $transaction_in_progress->line
907
-            if (! $total_line_item instanceof EE_Line_Item) {
907
+            if ( ! $total_line_item instanceof EE_Line_Item) {
908 908
                 throw new DomainException(
909 909
                     esc_html__(
910 910
                         'Transaction does not have a valid Total Line Item associated with it.',
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
         $total_tickets_released = 0;
965 965
         $sold_out_events = array();
966 966
         foreach ($tickets_with_reservations as $ticket_with_reservations) {
967
-            if (! $ticket_with_reservations instanceof EE_Ticket) {
967
+            if ( ! $ticket_with_reservations instanceof EE_Ticket) {
968 968
                 continue;
969 969
             }
970 970
             $reserved_qty = $ticket_with_reservations->reserved();
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
             }
989 989
         }
990 990
         // double check whether sold out events should remain sold out after releasing tickets
991
-        if($sold_out_events !== array()){
991
+        if ($sold_out_events !== array()) {
992 992
             foreach ($sold_out_events as $sold_out_event) {
993 993
                 /** @var EE_Event $sold_out_event */
994 994
                 $sold_out_event->perform_sold_out_status_check();
@@ -1016,7 +1016,7 @@  discard block
 block discarded – undo
1016 1016
         global $wpdb;
1017 1017
         return $wpdb->query(
1018 1018
             $wpdb->prepare(
1019
-                'DELETE FROM ' . EEM_Line_Item::instance()->table() . '
1019
+                'DELETE FROM '.EEM_Line_Item::instance()->table().'
1020 1020
                 WHERE TXN_ID = 0 AND LIN_timestamp <= %s',
1021 1021
                 // use GMT time because that's what LIN_timestamps are in
1022 1022
                 date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan())
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -38,216 +38,216 @@
 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
 
64 64
 } else {
65
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
-        /**
68
-         * espresso_minimum_php_version_error
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
+		/**
68
+		 * espresso_minimum_php_version_error
69
+		 * @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.9.59.rc.008');
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.9.59.rc.008');
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');
118
-        /**
119
-         *    espresso_load_error_handling
120
-         *    this function loads EE's class for handling exceptions and errors
121
-         */
122
-        function espresso_load_error_handling()
123
-        {
124
-            static $error_handling_loaded = false;
125
-            if ($error_handling_loaded) {
126
-                return;
127
-            }
128
-            // load debugging tools
129
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
130
-                require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
131
-                \EEH_Debug_Tools::instance();
132
-            }
133
-            // load error handling
134
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
135
-                require_once EE_CORE . 'EE_Error.core.php';
136
-            } else {
137
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
138
-            }
139
-            $error_handling_loaded = true;
140
-        }
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118
+		/**
119
+		 *    espresso_load_error_handling
120
+		 *    this function loads EE's class for handling exceptions and errors
121
+		 */
122
+		function espresso_load_error_handling()
123
+		{
124
+			static $error_handling_loaded = false;
125
+			if ($error_handling_loaded) {
126
+				return;
127
+			}
128
+			// load debugging tools
129
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
130
+				require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
131
+				\EEH_Debug_Tools::instance();
132
+			}
133
+			// load error handling
134
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
135
+				require_once EE_CORE . 'EE_Error.core.php';
136
+			} else {
137
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
138
+			}
139
+			$error_handling_loaded = true;
140
+		}
141 141
 
142
-        /**
143
-         *    espresso_load_required
144
-         *    given a class name and path, this function will load that file or throw an exception
145
-         *
146
-         * @param    string $classname
147
-         * @param    string $full_path_to_file
148
-         * @throws    EE_Error
149
-         */
150
-        function espresso_load_required($classname, $full_path_to_file)
151
-        {
152
-            if (is_readable($full_path_to_file)) {
153
-                require_once $full_path_to_file;
154
-            } else {
155
-                throw new \EE_Error (
156
-                    sprintf(
157
-                        esc_html__(
158
-                            'The %s class file could not be located or is not readable due to file permissions.',
159
-                            'event_espresso'
160
-                        ),
161
-                        $classname
162
-                    )
163
-                );
164
-            }
165
-        }
142
+		/**
143
+		 *    espresso_load_required
144
+		 *    given a class name and path, this function will load that file or throw an exception
145
+		 *
146
+		 * @param    string $classname
147
+		 * @param    string $full_path_to_file
148
+		 * @throws    EE_Error
149
+		 */
150
+		function espresso_load_required($classname, $full_path_to_file)
151
+		{
152
+			if (is_readable($full_path_to_file)) {
153
+				require_once $full_path_to_file;
154
+			} else {
155
+				throw new \EE_Error (
156
+					sprintf(
157
+						esc_html__(
158
+							'The %s class file could not be located or is not readable due to file permissions.',
159
+							'event_espresso'
160
+						),
161
+						$classname
162
+					)
163
+				);
164
+			}
165
+		}
166 166
 
167
-        /**
168
-         * @since 4.9.27
169
-         * @throws \EE_Error
170
-         * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
171
-         * @throws \EventEspresso\core\exceptions\InvalidEntityException
172
-         * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
173
-         * @throws \EventEspresso\core\exceptions\InvalidClassException
174
-         * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
175
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
176
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
177
-         * @throws \OutOfBoundsException
178
-         */
179
-        function bootstrap_espresso()
180
-        {
181
-            require_once __DIR__ . '/core/espresso_definitions.php';
182
-            try {
183
-                espresso_load_error_handling();
184
-                espresso_load_required(
185
-                    'EEH_Base',
186
-                    EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
187
-                );
188
-                espresso_load_required(
189
-                    'EEH_File',
190
-                    EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
191
-                );
192
-                espresso_load_required(
193
-                    'EEH_File',
194
-                    EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
195
-                );
196
-                espresso_load_required(
197
-                    'EEH_Array',
198
-                    EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
199
-                );
200
-                // instantiate and configure PSR4 autoloader
201
-                espresso_load_required(
202
-                    'Psr4Autoloader',
203
-                    EE_CORE . 'Psr4Autoloader.php'
204
-                );
205
-                espresso_load_required(
206
-                    'EE_Psr4AutoloaderInit',
207
-                    EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
208
-                );
209
-                $AutoloaderInit = new EE_Psr4AutoloaderInit();
210
-                $AutoloaderInit->initializeAutoloader();
211
-                espresso_load_required(
212
-                    'EE_Request',
213
-                    EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
214
-                );
215
-                espresso_load_required(
216
-                    'EE_Response',
217
-                    EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
218
-                );
219
-                espresso_load_required(
220
-                    'EE_Bootstrap',
221
-                    EE_CORE . 'EE_Bootstrap.core.php'
222
-                );
223
-                // bootstrap EE and the request stack
224
-                new EE_Bootstrap(
225
-                    new EE_Request($_GET, $_POST, $_COOKIE),
226
-                    new EE_Response()
227
-                );
228
-            } catch (Exception $e) {
229
-                require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
230
-                new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
231
-            }
232
-        }
233
-        bootstrap_espresso();
234
-    }
167
+		/**
168
+		 * @since 4.9.27
169
+		 * @throws \EE_Error
170
+		 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
171
+		 * @throws \EventEspresso\core\exceptions\InvalidEntityException
172
+		 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
173
+		 * @throws \EventEspresso\core\exceptions\InvalidClassException
174
+		 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
175
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
176
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
177
+		 * @throws \OutOfBoundsException
178
+		 */
179
+		function bootstrap_espresso()
180
+		{
181
+			require_once __DIR__ . '/core/espresso_definitions.php';
182
+			try {
183
+				espresso_load_error_handling();
184
+				espresso_load_required(
185
+					'EEH_Base',
186
+					EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
187
+				);
188
+				espresso_load_required(
189
+					'EEH_File',
190
+					EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
191
+				);
192
+				espresso_load_required(
193
+					'EEH_File',
194
+					EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
195
+				);
196
+				espresso_load_required(
197
+					'EEH_Array',
198
+					EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
199
+				);
200
+				// instantiate and configure PSR4 autoloader
201
+				espresso_load_required(
202
+					'Psr4Autoloader',
203
+					EE_CORE . 'Psr4Autoloader.php'
204
+				);
205
+				espresso_load_required(
206
+					'EE_Psr4AutoloaderInit',
207
+					EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
208
+				);
209
+				$AutoloaderInit = new EE_Psr4AutoloaderInit();
210
+				$AutoloaderInit->initializeAutoloader();
211
+				espresso_load_required(
212
+					'EE_Request',
213
+					EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
214
+				);
215
+				espresso_load_required(
216
+					'EE_Response',
217
+					EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
218
+				);
219
+				espresso_load_required(
220
+					'EE_Bootstrap',
221
+					EE_CORE . 'EE_Bootstrap.core.php'
222
+				);
223
+				// bootstrap EE and the request stack
224
+				new EE_Bootstrap(
225
+					new EE_Request($_GET, $_POST, $_COOKIE),
226
+					new EE_Response()
227
+				);
228
+			} catch (Exception $e) {
229
+				require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
230
+				new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
231
+			}
232
+		}
233
+		bootstrap_espresso();
234
+	}
235 235
 }
236 236
 if (! function_exists('espresso_deactivate_plugin')) {
237
-    /**
238
-     *    deactivate_plugin
239
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
240
-     *
241
-     * @access public
242
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
243
-     * @return    void
244
-     */
245
-    function espresso_deactivate_plugin($plugin_basename = '')
246
-    {
247
-        if (! function_exists('deactivate_plugins')) {
248
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
249
-        }
250
-        unset($_GET['activate'], $_REQUEST['activate']);
251
-        deactivate_plugins($plugin_basename);
252
-    }
237
+	/**
238
+	 *    deactivate_plugin
239
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
240
+	 *
241
+	 * @access public
242
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
243
+	 * @return    void
244
+	 */
245
+	function espresso_deactivate_plugin($plugin_basename = '')
246
+	{
247
+		if (! function_exists('deactivate_plugins')) {
248
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
249
+		}
250
+		unset($_GET['activate'], $_REQUEST['activate']);
251
+		deactivate_plugins($plugin_basename);
252
+	}
253 253
 }
Please login to merge, or discard this patch.