Completed
Branch master (cea33b)
by
unknown
69:30 queued 59:24
created
attendee_information/EE_SPCO_Reg_Step_Attendee_Information.class.php 1 patch
Indentation   +1425 added lines, -1425 removed lines patch added patch discarded remove patch
@@ -18,1433 +18,1433 @@
 block discarded – undo
18 18
 class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step
19 19
 {
20 20
 
21
-    /**
22
-     * @type bool $_print_copy_info
23
-     */
24
-    private $_print_copy_info = false;
25
-
26
-    /**
27
-     * @type array $_attendee_data
28
-     */
29
-    private $_attendee_data = array();
30
-
31
-    /**
32
-     * @type array $_required_questions
33
-     */
34
-    private $_required_questions = array();
35
-
36
-    /**
37
-     * @type array $_registration_answers
38
-     */
39
-    private $_registration_answers = array();
40
-
41
-
42
-    /**
43
-     *    class constructor
44
-     *
45
-     * @access    public
46
-     * @param    EE_Checkout $checkout
47
-     */
48
-    public function __construct(EE_Checkout $checkout)
49
-    {
50
-        $this->_slug = 'attendee_information';
51
-        $this->_name = esc_html__('Attendee Information', 'event_espresso');
52
-        $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_main.template.php';
53
-        $this->checkout = $checkout;
54
-        $this->_reset_success_message();
55
-        $this->set_instructions(
56
-            esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso')
57
-        );
58
-    }
59
-
60
-
61
-    public function translate_js_strings()
62
-    {
63
-        EE_Registry::$i18n_js_strings['required_field'] = esc_html__(
64
-            ' is a required question.',
65
-            'event_espresso'
66
-        );
67
-        EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__(
68
-            ' is a required question. Please enter a value for at least one of the options.',
69
-            'event_espresso'
70
-        );
71
-        EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__(
72
-            'Please answer all required questions correctly before proceeding.',
73
-            'event_espresso'
74
-        );
75
-        EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf(
76
-            esc_html_x(
77
-                'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
78
-                'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.',
79
-                'event_espresso'
80
-            ),
81
-            '<br/>'
82
-        );
83
-        EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__(
84
-            'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
85
-            'event_espresso'
86
-        );
87
-        EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__(
88
-            'You must enter a valid email address.',
89
-            'event_espresso'
90
-        );
91
-        EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__(
92
-            'You must enter a valid email address and answer all other required questions before you can proceed.',
93
-            'event_espresso'
94
-        );
95
-    }
96
-
97
-
98
-    public function enqueue_styles_and_scripts()
99
-    {
100
-    }
101
-
102
-
103
-    /**
104
-     * @return boolean
105
-     */
106
-    public function initialize_reg_step()
107
-    {
108
-        return true;
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EE_Form_Section_Proper
114
-     * @throws DomainException
115
-     * @throws EE_Error
116
-     * @throws InvalidArgumentException
117
-     * @throws ReflectionException
118
-     * @throws EntityNotFoundException
119
-     * @throws InvalidDataTypeException
120
-     * @throws InvalidInterfaceException
121
-     */
122
-    public function generate_reg_form()
123
-    {
124
-        /**
125
-         * @var $reg_config EE_Registration_Config
126
-         */
127
-        $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
21
+	/**
22
+	 * @type bool $_print_copy_info
23
+	 */
24
+	private $_print_copy_info = false;
25
+
26
+	/**
27
+	 * @type array $_attendee_data
28
+	 */
29
+	private $_attendee_data = array();
30
+
31
+	/**
32
+	 * @type array $_required_questions
33
+	 */
34
+	private $_required_questions = array();
35
+
36
+	/**
37
+	 * @type array $_registration_answers
38
+	 */
39
+	private $_registration_answers = array();
40
+
41
+
42
+	/**
43
+	 *    class constructor
44
+	 *
45
+	 * @access    public
46
+	 * @param    EE_Checkout $checkout
47
+	 */
48
+	public function __construct(EE_Checkout $checkout)
49
+	{
50
+		$this->_slug = 'attendee_information';
51
+		$this->_name = esc_html__('Attendee Information', 'event_espresso');
52
+		$this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_main.template.php';
53
+		$this->checkout = $checkout;
54
+		$this->_reset_success_message();
55
+		$this->set_instructions(
56
+			esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso')
57
+		);
58
+	}
59
+
60
+
61
+	public function translate_js_strings()
62
+	{
63
+		EE_Registry::$i18n_js_strings['required_field'] = esc_html__(
64
+			' is a required question.',
65
+			'event_espresso'
66
+		);
67
+		EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__(
68
+			' is a required question. Please enter a value for at least one of the options.',
69
+			'event_espresso'
70
+		);
71
+		EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__(
72
+			'Please answer all required questions correctly before proceeding.',
73
+			'event_espresso'
74
+		);
75
+		EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf(
76
+			esc_html_x(
77
+				'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
78
+				'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.',
79
+				'event_espresso'
80
+			),
81
+			'<br/>'
82
+		);
83
+		EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__(
84
+			'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
85
+			'event_espresso'
86
+		);
87
+		EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__(
88
+			'You must enter a valid email address.',
89
+			'event_espresso'
90
+		);
91
+		EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__(
92
+			'You must enter a valid email address and answer all other required questions before you can proceed.',
93
+			'event_espresso'
94
+		);
95
+	}
96
+
97
+
98
+	public function enqueue_styles_and_scripts()
99
+	{
100
+	}
101
+
102
+
103
+	/**
104
+	 * @return boolean
105
+	 */
106
+	public function initialize_reg_step()
107
+	{
108
+		return true;
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EE_Form_Section_Proper
114
+	 * @throws DomainException
115
+	 * @throws EE_Error
116
+	 * @throws InvalidArgumentException
117
+	 * @throws ReflectionException
118
+	 * @throws EntityNotFoundException
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws InvalidInterfaceException
121
+	 */
122
+	public function generate_reg_form()
123
+	{
124
+		/**
125
+		 * @var $reg_config EE_Registration_Config
126
+		 */
127
+		$reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
128 128
  
129
-        $this->_print_copy_info = $reg_config->copyAttendeeInfo();
130
-
131
-        $primary_registrant = null;
132
-        // autoload Line_Item_Display classes
133
-        EEH_Autoloader::register_line_item_display_autoloaders();
134
-        $Line_Item_Display = new EE_Line_Item_Display();
135
-        // calculate taxes
136
-        $Line_Item_Display->display_line_item(
137
-            $this->checkout->cart->get_grand_total(),
138
-            array('set_tax_rate' => true)
139
-        );
140
-        /** @var $subsections EE_Form_Section_Proper[] */
141
-        $extra_inputs_section = $this->reg_step_hidden_inputs();
142
-        $subsections = array(
143
-            'default_hidden_inputs' => $extra_inputs_section,
144
-        );
145
-
146
-        // if this isn't a revisit, and they have the privacy consent box enalbed, add it
147
-        if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) {
148
-            $extra_inputs_section->add_subsections(
149
-                array(
150
-                    'consent_box' => new EE_Form_Section_Proper(
151
-                        array(
152
-                            'layout_strategy' =>
153
-                                new EE_Template_Layout(
154
-                                    array(
155
-                                        'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . '/privacy_consent.template.php',
156
-                                    )
157
-                                ),
158
-                            'subsections'     => array(
159
-                                'consent' => new EE_Checkbox_Multi_Input(
160
-                                    array(
161
-                                        'consent' => $reg_config->getConsentCheckboxLabelText(),
162
-                                    ),
163
-                                    array(
164
-                                        'required'                          => true,
165
-                                        'required_validation_error_message' => esc_html__(
166
-                                            'You must consent to these terms in order to register.',
167
-                                            'event_espresso'
168
-                                        ),
169
-                                        'html_label_text'                   => '',
170
-                                    )
171
-                                ),
172
-                            ),
173
-                        )
174
-                    ),
175
-                ),
176
-                null,
177
-                false
178
-            );
179
-        }
180
-        $template_args = array(
181
-            'revisit'       => $this->checkout->revisit,
182
-            'registrations' => array(),
183
-            'ticket_count'  => array(),
184
-        );
185
-        // grab the saved registrations from the transaction
186
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
187
-        if ($registrations) {
188
-            foreach ($registrations as $registration) {
189
-                // can this registration be processed during this visit ?
190
-                if ($registration instanceof EE_Registration
191
-                    && $this->checkout->visit_allows_processing_of_this_registration($registration)
192
-                ) {
193
-                    $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration);
194
-                    $template_args['registrations'][ $registration->reg_url_link() ] = $registration;
195
-                    $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset(
196
-                        $template_args['ticket_count'][ $registration->ticket()->ID() ]
197
-                    )
198
-                        ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1
199
-                        : 1;
200
-                    $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
201
-                        $this->checkout->cart->get_grand_total(),
202
-                        'Ticket',
203
-                        array($registration->ticket()->ID())
204
-                    );
205
-                    $ticket_line_item = is_array($ticket_line_item)
206
-                        ? reset($ticket_line_item)
207
-                        : $ticket_line_item;
208
-                    $template_args['ticket_line_item'][ $registration->ticket()->ID() ] =
209
-                        $Line_Item_Display->display_line_item($ticket_line_item);
210
-                    if ($registration->is_primary_registrant()) {
211
-                        $primary_registrant = $registration->reg_url_link();
212
-                    }
213
-                }
214
-            }
215
-
216
-            if ($primary_registrant && count($registrations) > 1) {
217
-                $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info
218
-                    ? $this->_copy_attendee_info_form()
219
-                    : $this->_auto_copy_attendee_info();
220
-                // generate hidden input
221
-                if (isset($subsections[ $primary_registrant ])
222
-                    && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper
223
-                ) {
224
-                    $subsections[ $primary_registrant ]->add_subsections(
225
-                        $copy_options,
226
-                        'primary_registrant',
227
-                        false
228
-                    );
229
-                }
230
-            }
231
-        }
232
-        return new EE_Form_Section_Proper(
233
-            array(
234
-                'name'            => $this->reg_form_name(),
235
-                'html_id'         => $this->reg_form_name(),
236
-                'subsections'     => $subsections,
237
-                'layout_strategy' => new EE_Template_Layout(
238
-                    array(
239
-                        'layout_template_file' => $this->_template, // layout_template
240
-                        'template_args'        => $template_args,
241
-                    )
242
-                ),
243
-            )
244
-        );
245
-    }
246
-
247
-
248
-    /**
249
-     * @param EE_Registration $registration
250
-     * @return EE_Form_Section_Base
251
-     * @throws EE_Error
252
-     * @throws InvalidArgumentException
253
-     * @throws EntityNotFoundException
254
-     * @throws InvalidDataTypeException
255
-     * @throws InvalidInterfaceException
256
-     * @throws ReflectionException
257
-     */
258
-    private function _registrations_reg_form(EE_Registration $registration)
259
-    {
260
-        static $attendee_nmbr = 1;
261
-        $form_args = array();
262
-        // verify that registration has valid event
263
-        if ($registration->event() instanceof EE_Event) {
264
-            $field_name = 'Event_Question_Group.'
265
-                . EEM_Event_Question_Group::instance()->fieldNameForContext(
266
-                    $registration->is_primary_registrant()
267
-                );
268
-            $question_groups = $registration->event()->question_groups(
269
-                apply_filters(
270
-                    // @codingStandardsIgnoreStart
271
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters',
272
-                    // @codingStandardsIgnoreEnd
273
-                    [
274
-                        [
275
-                            'Event.EVT_ID'                     => $registration->event()->ID(),
276
-                            $field_name => true,
277
-                        ],
278
-                        'order_by' => ['QSG_order' => 'ASC'],
279
-                    ],
280
-                    $registration,
281
-                    $this
282
-                )
283
-            );
284
-            if ($question_groups) {
285
-                // array of params to pass to parent constructor
286
-                $form_args = array(
287
-                    'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
288
-                    'html_class'      => 'ee-reg-form-attendee-dv',
289
-                    'html_style'      => $this->checkout->admin_request
290
-                        ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
291
-                        : '',
292
-                    'subsections'     => array(),
293
-                    'layout_strategy' => new EE_Fieldset_Section_Layout(
294
-                        array(
295
-                            'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text',
296
-                            'legend_text'  => sprintf(
297
-                                esc_html_x(
298
-                                    'Attendee %d',
299
-                                    'Attendee 123',
300
-                                    'event_espresso'
301
-                                ),
302
-                                $attendee_nmbr
303
-                            ),
304
-                        )
305
-                    ),
306
-                );
307
-                foreach ($question_groups as $question_group) {
308
-                    if ($question_group instanceof EE_Question_Group) {
309
-                        $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form(
310
-                            $registration,
311
-                            $question_group
312
-                        );
313
-                    }
314
-                }
315
-                // add hidden input
316
-                $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input(
317
-                    $registration
318
-                );
319
-
320
-                /**
321
-                 * @var $reg_config EE_Registration_Config
322
-                 */
323
-                $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
324
-
325
-                // If we have question groups for additional attendees, then display the copy options
326
-                $this->_print_copy_info = apply_filters(
327
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo',
328
-                    $attendee_nmbr > 1 ? $reg_config->copyAttendeeInfo() : false,
329
-                    $attendee_nmbr
330
-                );
331
-
332
-                if ($registration->is_primary_registrant()) {
333
-                    // generate hidden input
334
-                    $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs(
335
-                        $registration
336
-                    );
337
-                }
338
-            }
339
-        }
340
-        $attendee_nmbr++;
341
-        return ! empty($form_args)
342
-            ? new EE_Form_Section_Proper($form_args)
343
-            : new EE_Form_Section_HTML();
344
-    }
345
-
346
-
347
-    /**
348
-     * @param EE_Registration $registration
349
-     * @param bool            $additional_attendee_reg_info
350
-     * @return EE_Form_Input_Base
351
-     * @throws EE_Error
352
-     */
353
-    private function _additional_attendee_reg_info_input(
354
-        EE_Registration $registration,
355
-        $additional_attendee_reg_info = true
356
-    ) {
357
-        // generate hidden input
358
-        return new EE_Hidden_Input(
359
-            array(
360
-                'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
361
-                'default' => $additional_attendee_reg_info,
362
-            )
363
-        );
364
-    }
365
-
366
-
367
-    /**
368
-     * @param EE_Registration   $registration
369
-     * @param EE_Question_Group $question_group
370
-     * @return EE_Form_Section_Proper
371
-     * @throws EE_Error
372
-     * @throws InvalidArgumentException
373
-     * @throws InvalidDataTypeException
374
-     * @throws InvalidInterfaceException
375
-     * @throws ReflectionException
376
-     */
377
-    private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group)
378
-    {
379
-        // array of params to pass to parent constructor
380
-        $form_args = array(
381
-            'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(),
382
-            'html_class'      => $this->checkout->admin_request
383
-                ? 'form-table ee-reg-form-qstn-grp-dv'
384
-                : 'ee-reg-form-qstn-grp-dv',
385
-            'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-'
386
-                                 . $registration->ID() . '-lbl',
387
-            'subsections'     => array(
388
-                'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group),
389
-            ),
390
-            'layout_strategy' => $this->checkout->admin_request
391
-                ? new EE_Admin_Two_Column_Layout()
392
-                : new EE_Div_Per_Section_Layout(),
393
-        );
394
-        // where params
395
-        $query_params = array('QST_deleted' => 0);
396
-        // don't load admin only questions on the frontend
397
-        if (! $this->checkout->admin_request) {
398
-            $query_params['QST_admin_only'] = array('!=', true);
399
-        }
400
-        $questions = $question_group->get_many_related(
401
-            'Question',
402
-            apply_filters(
403
-                'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params',
404
-                array(
405
-                    $query_params,
406
-                    'order_by' => array(
407
-                        'Question_Group_Question.QGQ_order' => 'ASC',
408
-                    ),
409
-                ),
410
-                $question_group,
411
-                $registration,
412
-                $this
413
-            )
414
-        );
415
-        // filter for additional content before questions
416
-        $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML(
417
-            apply_filters(
418
-                'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
419
-                '',
420
-                $registration,
421
-                $question_group,
422
-                $this
423
-            )
424
-        );
425
-        // loop thru questions
426
-        foreach ($questions as $question) {
427
-            if ($question instanceof EE_Question) {
428
-                $identifier = $question->is_system_question()
429
-                    ? $question->system_ID()
430
-                    : $question->ID();
431
-                $form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question);
432
-            }
433
-        }
434
-        $form_args['subsections'] = apply_filters(
435
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array',
436
-            $form_args['subsections'],
437
-            $registration,
438
-            $question_group,
439
-            $this
440
-        );
441
-        // filter for additional content after questions
442
-        $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML(
443
-            apply_filters(
444
-                'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
445
-                '',
446
-                $registration,
447
-                $question_group,
448
-                $this
449
-            )
450
-        );
451
-        // d($form_args);
452
-        $question_group_reg_form = new EE_Form_Section_Proper($form_args);
453
-        return apply_filters(
454
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
455
-            $question_group_reg_form,
456
-            $registration,
457
-            $question_group,
458
-            $this
459
-        );
460
-    }
461
-
462
-
463
-    /**
464
-     * @param EE_Question_Group $question_group
465
-     * @return    EE_Form_Section_HTML
466
-     */
467
-    private function _question_group_header(EE_Question_Group $question_group)
468
-    {
469
-        $html = '';
470
-        // group_name
471
-        if ($question_group->show_group_name() && $question_group->name() !== '') {
472
-            if ($this->checkout->admin_request) {
473
-                $html .= EEH_HTML::br();
474
-                $html .= EEH_HTML::h3(
475
-                    $question_group->name(),
476
-                    '',
477
-                    'ee-reg-form-qstn-grp-title title',
478
-                    'font-size: 1.3em; padding-left:0;'
479
-                );
480
-            } else {
481
-                $html .= EEH_HTML::h4(
482
-                    $question_group->name(),
483
-                    '',
484
-                    'ee-reg-form-qstn-grp-title section-title'
485
-                );
486
-            }
487
-        }
488
-        // group_desc
489
-        if ($question_group->show_group_desc() && $question_group->desc() !== '') {
490
-            $html .= EEH_HTML::p(
491
-                $question_group->desc(),
492
-                '',
493
-                $this->checkout->admin_request
494
-                    ? 'ee-reg-form-qstn-grp-desc-pg'
495
-                    : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text'
496
-            );
497
-        }
498
-        return new EE_Form_Section_HTML($html);
499
-    }
500
-
501
-
502
-    /**
503
-     * @return    EE_Form_Section_Proper
504
-     * @throws EE_Error
505
-     * @throws InvalidArgumentException
506
-     * @throws ReflectionException
507
-     * @throws InvalidDataTypeException
508
-     * @throws InvalidInterfaceException
509
-     */
510
-    private function _copy_attendee_info_form()
511
-    {
512
-        // array of params to pass to parent constructor
513
-        return new EE_Form_Section_Proper(
514
-            array(
515
-                'subsections'     => $this->_copy_attendee_info_inputs(),
516
-                'layout_strategy' => new EE_Template_Layout(
517
-                    array(
518
-                        'layout_template_file'     => SPCO_REG_STEPS_PATH
519
-                                                      . $this->_slug
520
-                                                      . '/copy_attendee_info.template.php',
521
-                        'begin_template_file'      => null,
522
-                        'input_template_file'      => null,
523
-                        'subsection_template_file' => null,
524
-                        'end_template_file'        => null,
525
-                    )
526
-                ),
527
-            )
528
-        );
529
-    }
530
-
531
-
532
-    /**
533
-     * @return EE_Form_Section_HTML
534
-     * @throws DomainException
535
-     * @throws InvalidArgumentException
536
-     * @throws InvalidDataTypeException
537
-     * @throws InvalidInterfaceException
538
-     */
539
-    private function _auto_copy_attendee_info()
540
-    {
541
-        return new EE_Form_Section_HTML(
542
-            EEH_Template::locate_template(
543
-                SPCO_REG_STEPS_PATH . $this->_slug . '/_auto_copy_attendee_info.template.php',
544
-                apply_filters(
545
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
546
-                    array()
547
-                ),
548
-                true,
549
-                true
550
-            )
551
-        );
552
-    }
553
-
554
-
555
-    /**
556
-     * @return array
557
-     * @throws EE_Error
558
-     * @throws InvalidArgumentException
559
-     * @throws ReflectionException
560
-     * @throws InvalidDataTypeException
561
-     * @throws InvalidInterfaceException
562
-     */
563
-    private function _copy_attendee_info_inputs()
564
-    {
565
-        $copy_attendee_info_inputs = array();
566
-        $prev_ticket = null;
567
-        // grab the saved registrations from the transaction
568
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
569
-        foreach ($registrations as $registration) {
570
-            // for all  attendees other than the primary attendee
571
-            if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) {
572
-                // if this is a new ticket OR if this is the very first additional attendee after the primary attendee
573
-                if ($registration->ticket()->ID() !== $prev_ticket) {
574
-                    $item_name = $registration->ticket()->name();
575
-                    $item_name .= $registration->ticket()->description() !== ''
576
-                        ? ' - ' . $registration->ticket()->description()
577
-                        : '';
578
-                    $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID(
579
-                    ) . ']' ] =
580
-                        new EE_Form_Section_HTML(
581
-                            '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>'
582
-                        );
583
-                    $prev_ticket = $registration->ticket()->ID();
584
-                }
585
-
586
-                $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] =
587
-                    new EE_Checkbox_Multi_Input(
588
-                        array(
589
-                            $registration->ID() => sprintf(
590
-                                esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'),
591
-                                $registration->count()
592
-                            ),
593
-                        ),
594
-                        array(
595
-                            'html_id'                 => 'spco-copy-attendee-chk-' . $registration->reg_url_link(),
596
-                            'html_class'              => 'spco-copy-attendee-chk ee-do-not-validate',
597
-                            'display_html_label_text' => false,
598
-                        )
599
-                    );
600
-            }
601
-        }
602
-        return $copy_attendee_info_inputs;
603
-    }
604
-
605
-
606
-    /**
607
-     * @param EE_Registration $registration
608
-     * @return    EE_Form_Input_Base
609
-     * @throws EE_Error
610
-     */
611
-    private function _additional_primary_registrant_inputs(EE_Registration $registration)
612
-    {
613
-        // generate hidden input
614
-        return new EE_Hidden_Input(
615
-            array(
616
-                'html_id' => 'primary_registrant',
617
-                'default' => $registration->reg_url_link(),
618
-            )
619
-        );
620
-    }
621
-
622
-
623
-    /**
624
-     * @param EE_Registration $registration
625
-     * @param EE_Question     $question
626
-     * @return EE_Form_Input_Base
627
-     * @throws EE_Error
628
-     * @throws InvalidArgumentException
629
-     * @throws InvalidDataTypeException
630
-     * @throws InvalidInterfaceException
631
-     * @throws ReflectionException
632
-     */
633
-    public function reg_form_question(EE_Registration $registration, EE_Question $question)
634
-    {
635
-
636
-        // if this question was for an attendee detail, then check for that answer
637
-        $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value(
638
-            $registration,
639
-            $question->system_ID()
640
-        );
641
-        $answer = $answer_value === null
642
-            ? EEM_Answer::instance()->get_one(
643
-                array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
644
-            )
645
-            : null;
646
-        // if NOT returning to edit an existing registration
647
-        // OR if this question is for an attendee property
648
-        // OR we still don't have an EE_Answer object
649
-        if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
650
-            // create an EE_Answer object for storing everything in
651
-            $answer = EE_Answer::new_instance(
652
-                array(
653
-                    'QST_ID' => $question->ID(),
654
-                    'REG_ID' => $registration->ID(),
655
-                )
656
-            );
657
-        }
658
-        // verify instance
659
-        if ($answer instanceof EE_Answer) {
660
-            if (! empty($answer_value)) {
661
-                $answer->set('ANS_value', $answer_value);
662
-            }
663
-            $answer->cache('Question', $question);
664
-            // remember system ID had a bug where sometimes it could be null
665
-            $answer_cache_id = $question->is_system_question()
666
-                ? $question->system_ID() . '-' . $registration->reg_url_link()
667
-                : $question->ID() . '-' . $registration->reg_url_link();
668
-            $registration->cache('Answer', $answer, $answer_cache_id);
669
-        }
670
-        return $this->_generate_question_input($registration, $question, $answer);
671
-    }
672
-
673
-
674
-    /**
675
-     * @param EE_Registration $registration
676
-     * @param EE_Question     $question
677
-     * @param                 $answer
678
-     * @return EE_Form_Input_Base
679
-     * @throws EE_Error
680
-     * @throws InvalidArgumentException
681
-     * @throws ReflectionException
682
-     * @throws InvalidDataTypeException
683
-     * @throws InvalidInterfaceException
684
-     */
685
-    private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer)
686
-    {
687
-        $identifier = $question->is_system_question()
688
-            ? $question->system_ID()
689
-            : $question->ID();
690
-        $this->_required_questions[ $identifier ] = $question->required() ? true : false;
691
-        add_filter(
692
-            'FHEE__EE_Question__generate_form_input__country_options',
693
-            array($this, 'use_cached_countries_for_form_input'),
694
-            10,
695
-            4
696
-        );
697
-        add_filter(
698
-            'FHEE__EE_Question__generate_form_input__state_options',
699
-            array($this, 'use_cached_states_for_form_input'),
700
-            10,
701
-            4
702
-        );
703
-        $input_constructor_args = array(
704
-            'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
705
-            'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
706
-            'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
707
-            'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
708
-            'html_label_class' => 'ee-reg-qstn',
709
-        );
710
-        $input_constructor_args['html_label_id'] .= '-lbl';
711
-        if ($answer instanceof EE_Answer && $answer->ID()) {
712
-            $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']';
713
-            $input_constructor_args['html_id'] .= '-' . $answer->ID();
714
-            $input_constructor_args['html_label_id'] .= '-' . $answer->ID();
715
-        }
716
-        $form_input = $question->generate_form_input(
717
-            $registration,
718
-            $answer,
719
-            $input_constructor_args
720
-        );
721
-        remove_filter(
722
-            'FHEE__EE_Question__generate_form_input__country_options',
723
-            array($this, 'use_cached_countries_for_form_input')
724
-        );
725
-        remove_filter(
726
-            'FHEE__EE_Question__generate_form_input__state_options',
727
-            array($this, 'use_cached_states_for_form_input')
728
-        );
729
-        return $form_input;
730
-    }
731
-
732
-
733
-    /**
734
-     * Gets the list of countries for the form input
735
-     *
736
-     * @param array|null      $countries_list
737
-     * @param EE_Question     $question
738
-     * @param EE_Registration $registration
739
-     * @param EE_Answer       $answer
740
-     * @return array 2d keys are country IDs, values are their names
741
-     * @throws EE_Error
742
-     * @throws InvalidArgumentException
743
-     * @throws InvalidDataTypeException
744
-     * @throws InvalidInterfaceException
745
-     * @throws ReflectionException
746
-     */
747
-    public function use_cached_countries_for_form_input(
748
-        $countries_list,
749
-        EE_Question $question = null,
750
-        EE_Registration $registration = null,
751
-        EE_Answer $answer = null
752
-    ) {
753
-        $country_options = array('' => '');
754
-        // get possibly cached list of countries
755
-        $countries = $this->checkout->action === 'process_reg_step'
756
-            ? EEM_Country::instance()->get_all_countries()
757
-            : EEM_Country::instance()->get_all_active_countries();
758
-        if (! empty($countries)) {
759
-            foreach ($countries as $country) {
760
-                if ($country instanceof EE_Country) {
761
-                    $country_options[ $country->ID() ] = $country->name();
762
-                }
763
-            }
764
-        }
765
-        if ($question instanceof EE_Question && $registration instanceof EE_Registration) {
766
-            $answer = EEM_Answer::instance()->get_one(
767
-                array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
768
-            );
769
-        } else {
770
-            $answer = EE_Answer::new_instance();
771
-        }
772
-        $country_options = apply_filters(
773
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
774
-            $country_options,
775
-            $this,
776
-            $registration,
777
-            $question,
778
-            $answer
779
-        );
780
-        return $country_options;
781
-    }
782
-
783
-
784
-    /**
785
-     * Gets the list of states for the form input
786
-     *
787
-     * @param array|null      $states_list
788
-     * @param EE_Question     $question
789
-     * @param EE_Registration $registration
790
-     * @param EE_Answer       $answer
791
-     * @return array 2d keys are state IDs, values are their names
792
-     * @throws EE_Error
793
-     * @throws InvalidArgumentException
794
-     * @throws InvalidDataTypeException
795
-     * @throws InvalidInterfaceException
796
-     * @throws ReflectionException
797
-     */
798
-    public function use_cached_states_for_form_input(
799
-        $states_list,
800
-        EE_Question $question = null,
801
-        EE_Registration $registration = null,
802
-        EE_Answer $answer = null
803
-    ) {
804
-        $state_options = array('' => array('' => ''));
805
-        $states = $this->checkout->action === 'process_reg_step'
806
-            ? EEM_State::instance()->get_all_states()
807
-            : EEM_State::instance()->get_all_active_states();
808
-        if (! empty($states)) {
809
-            foreach ($states as $state) {
810
-                if ($state instanceof EE_State) {
811
-                    $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name();
812
-                }
813
-            }
814
-        }
815
-        $state_options = apply_filters(
816
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
817
-            $state_options,
818
-            $this,
819
-            $registration,
820
-            $question,
821
-            $answer
822
-        );
823
-        return $state_options;
824
-    }
825
-
826
-
827
-    /********************************************************************************************************/
828
-    /****************************************  PROCESS REG STEP  ****************************************/
829
-    /********************************************************************************************************/
830
-
831
-
832
-    /**
833
-     * @return bool
834
-     * @throws EE_Error
835
-     * @throws InvalidArgumentException
836
-     * @throws ReflectionException
837
-     * @throws RuntimeException
838
-     * @throws InvalidDataTypeException
839
-     * @throws InvalidInterfaceException
840
-     */
841
-    public function process_reg_step()
842
-    {
843
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
844
-        // grab validated data from form
845
-        $valid_data = $this->checkout->current_step->valid_data();
846
-        // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
847
-        // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ );
848
-        // if we don't have any $valid_data then something went TERRIBLY WRONG !!!
849
-        if (empty($valid_data)) {
850
-            EE_Error::add_error(
851
-                esc_html__('No valid question responses were received.', 'event_espresso'),
852
-                __FILE__,
853
-                __FUNCTION__,
854
-                __LINE__
855
-            );
856
-            return false;
857
-        }
858
-        if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
859
-            EE_Error::add_error(
860
-                esc_html__(
861
-                    'A valid transaction could not be initiated for processing your registrations.',
862
-                    'event_espresso'
863
-                ),
864
-                __FILE__,
865
-                __FUNCTION__,
866
-                __LINE__
867
-            );
868
-            return false;
869
-        }
870
-        // get cached registrations
871
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
872
-        // verify we got the goods
873
-        if (empty($registrations)) {
874
-            // combine the old translated string with a new one, in order to not break translations
875
-            $error_message = esc_html__(
876
-                'Your form data could not be applied to any valid registrations.',
877
-                'event_espresso'
878
-            )
879
-            . sprintf(
880
-                esc_html_x(
881
-                    '%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.',
882
-                    '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.',
883
-                    'event_espresso'
884
-                ),
885
-                '<a href="' . get_post_type_archive_link('espresso_events') . '" >',
886
-                '</a>',
887
-                '<br />'
888
-            );
889
-            EE_Error::add_error(
890
-                $error_message,
891
-                __FILE__,
892
-                __FUNCTION__,
893
-                __LINE__
894
-            );
895
-            return false;
896
-        }
897
-        // extract attendee info from form data and save to model objects
898
-        $registrations_processed = $this->_process_registrations($registrations, $valid_data);
899
-        // if first pass thru SPCO,
900
-        // then let's check processed registrations against the total number of tickets in the cart
901
-        if ($registrations_processed === false) {
902
-            // but return immediately if the previous step exited early due to errors
903
-            return false;
904
-        }
905
-        if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
906
-            // generate a correctly translated string for all possible singular/plural combinations
907
-            if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
908
-                $error_msg = sprintf(
909
-                    esc_html_x(
910
-                        'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
911
-                        'There was 1 ticket in the Event Queue, but 2 registrations were processed',
912
-                        'event_espresso'
913
-                    ),
914
-                    $this->checkout->total_ticket_count,
915
-                    $registrations_processed
916
-                );
917
-            } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
918
-                $error_msg = sprintf(
919
-                    esc_html_x(
920
-                        'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
921
-                        'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed',
922
-                        'event_espresso'
923
-                    ),
924
-                    $this->checkout->total_ticket_count,
925
-                    $registrations_processed
926
-                );
927
-            } else {
928
-                $error_msg = sprintf(
929
-                    esc_html__(
930
-                        'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed',
931
-                        'event_espresso'
932
-                    ),
933
-                    $this->checkout->total_ticket_count,
934
-                    $registrations_processed
935
-                );
936
-            }
937
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
938
-            return false;
939
-        }
940
-        // mark this reg step as completed
941
-        $this->set_completed();
942
-        $this->_set_success_message(
943
-            esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso')
944
-        );
945
-        // do action in case a plugin wants to do something with the data submitted in step 1.
946
-        // passes EE_Single_Page_Checkout, and it's posted data
947
-        do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
948
-        return true;
949
-    }
950
-
951
-
952
-    /**
953
-     *    _process_registrations
954
-     *
955
-     * @param EE_Registration[] $registrations
956
-     * @param array[][]         $valid_data
957
-     * @return bool|int
958
-     * @throws EntityNotFoundException
959
-     * @throws EE_Error
960
-     * @throws InvalidArgumentException
961
-     * @throws ReflectionException
962
-     * @throws RuntimeException
963
-     * @throws InvalidDataTypeException
964
-     * @throws InvalidInterfaceException
965
-     */
966
-    private function _process_registrations($registrations = array(), $valid_data = array())
967
-    {
968
-        // load resources and set some defaults
969
-        EE_Registry::instance()->load_model('Attendee');
970
-        // holder for primary registrant attendee object
971
-        $this->checkout->primary_attendee_obj = null;
972
-        // array for tracking reg form data for the primary registrant
973
-        $primary_registrant = array(
974
-            'line_item_id' => null,
975
-        );
976
-        $copy_primary = false;
977
-        // reg form sections that do not contain inputs
978
-        $non_input_form_sections = array(
979
-            'primary_registrant',
980
-            'additional_attendee_reg_info',
981
-            'spco_copy_attendee_chk',
982
-        );
983
-        // attendee counter
984
-        $att_nmbr = 0;
985
-        // grab the saved registrations from the transaction
986
-        foreach ($registrations as $registration) {
987
-            // verify EE_Registration object
988
-            if (! $registration instanceof EE_Registration) {
989
-                EE_Error::add_error(
990
-                    esc_html__(
991
-                        'An invalid Registration object was discovered when attempting to process your registration information.',
992
-                        'event_espresso'
993
-                    ),
994
-                    __FILE__,
995
-                    __FUNCTION__,
996
-                    __LINE__
997
-                );
998
-                return false;
999
-            }
1000
-            /** @var string $reg_url_link */
1001
-            $reg_url_link = $registration->reg_url_link();
1002
-            // reg_url_link exists ?
1003
-            if (! empty($reg_url_link)) {
1004
-                // should this registration be processed during this visit ?
1005
-                if ($this->checkout->visit_allows_processing_of_this_registration($registration)) {
1006
-                    // if NOT revisiting, then let's save the registration now,
1007
-                    // so that we have a REG_ID to use when generating other objects
1008
-                    if (! $this->checkout->revisit) {
1009
-                        $registration->save();
1010
-                    }
1011
-                    /**
1012
-                     * This allows plugins to trigger a fail on processing of a
1013
-                     * registration for any conditions they may have for it to pass.
1014
-                     *
1015
-                     * @var bool   if true is returned by the plugin then the
1016
-                     *            registration processing is halted.
1017
-                     */
1018
-                    if (apply_filters(
1019
-                        'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
1020
-                        false,
1021
-                        $att_nmbr,
1022
-                        $registration,
1023
-                        $registrations,
1024
-                        $valid_data,
1025
-                        $this
1026
-                    )) {
1027
-                        return false;
1028
-                    }
1029
-
1030
-                    // Houston, we have a registration!
1031
-                    $att_nmbr++;
1032
-                    $this->_attendee_data[ $reg_url_link ] = array();
1033
-                    // grab any existing related answer objects
1034
-                    $this->_registration_answers = $registration->answers();
1035
-                    // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] );
1036
-                    if (isset($valid_data[ $reg_url_link ])) {
1037
-                        // do we need to copy basic info from primary attendee ?
1038
-                        $copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info'])
1039
-                                        && absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0;
1040
-                        // filter form input data for this registration
1041
-                        $valid_data[ $reg_url_link ] = (array) apply_filters(
1042
-                            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
1043
-                            $valid_data[ $reg_url_link ]
1044
-                        );
1045
-                        if (isset($valid_data['primary_attendee'])) {
1046
-                            $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee'])
1047
-                                ? $valid_data['primary_attendee']
1048
-                                : false;
1049
-                            unset($valid_data['primary_attendee']);
1050
-                        }
1051
-                        // now loop through our array of valid post data && process attendee reg forms
1052
-                        foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) {
1053
-                            if (! in_array($form_section, $non_input_form_sections, true)) {
1054
-                                foreach ($form_inputs as $form_input => $input_value) {
1055
-                                    // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ );
1056
-                                    // check for critical inputs
1057
-                                    if (! $this->_verify_critical_attendee_details_are_set_and_validate_email(
1058
-                                        $form_input,
1059
-                                        $input_value
1060
-                                    )
1061
-                                    ) {
1062
-                                        return false;
1063
-                                    }
1064
-                                    // store a bit of data about the primary attendee
1065
-                                    if ($att_nmbr === 1
1066
-                                        && ! empty($input_value)
1067
-                                        && $reg_url_link === $primary_registrant['line_item_id']
1068
-                                    ) {
1069
-                                        $primary_registrant[ $form_input ] = $input_value;
1070
-                                    } elseif ($copy_primary
1071
-                                              && $input_value === null
1072
-                                              && isset($primary_registrant[ $form_input ])
1073
-                                    ) {
1074
-                                        $input_value = $primary_registrant[ $form_input ];
1075
-                                    }
1076
-                                    // now attempt to save the input data
1077
-                                    if (! $this->_save_registration_form_input(
1078
-                                        $registration,
1079
-                                        $form_input,
1080
-                                        $input_value
1081
-                                    )
1082
-                                    ) {
1083
-                                        EE_Error::add_error(
1084
-                                            sprintf(
1085
-                                                esc_html_x(
1086
-                                                    'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"',
1087
-                                                    'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"',
1088
-                                                    'event_espresso'
1089
-                                                ),
1090
-                                                $form_input,
1091
-                                                $input_value
1092
-                                            ),
1093
-                                            __FILE__,
1094
-                                            __FUNCTION__,
1095
-                                            __LINE__
1096
-                                        );
1097
-                                        return false;
1098
-                                    }
1099
-                                }
1100
-                            }
1101
-                        }  // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs )
1102
-                    }
1103
-                    // EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ );
1104
-                    // this registration does not require additional attendee information ?
1105
-                    if ($copy_primary
1106
-                        && $att_nmbr > 1
1107
-                        && $this->checkout->primary_attendee_obj instanceof EE_Attendee
1108
-                    ) {
1109
-                        // just copy the primary registrant
1110
-                        $attendee = $this->checkout->primary_attendee_obj;
1111
-                    } else {
1112
-                        // ensure critical details are set for additional attendees
1113
-                        $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1
1114
-                            ? $this->_copy_critical_attendee_details_from_primary_registrant(
1115
-                                $this->_attendee_data[ $reg_url_link ]
1116
-                            )
1117
-                            : $this->_attendee_data[ $reg_url_link ];
1118
-                        // execute create attendee command (which may return an existing attendee)
1119
-                        $attendee = EE_Registry::instance()->BUS->execute(
1120
-                            new CreateAttendeeCommand(
1121
-                                $this->_attendee_data[ $reg_url_link ],
1122
-                                $registration
1123
-                            )
1124
-                        );
1125
-                        // who's #1 ?
1126
-                        if ($att_nmbr === 1) {
1127
-                            $this->checkout->primary_attendee_obj = $attendee;
1128
-                        }
1129
-                    }
1130
-                    // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ );
1131
-                    // add relation to registration, set attendee ID, and cache attendee
1132
-                    $this->_associate_attendee_with_registration($registration, $attendee);
1133
-                    // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ );
1134
-                    if (! $registration->attendee() instanceof EE_Attendee) {
1135
-                        EE_Error::add_error(
1136
-                            sprintf(
1137
-                                esc_html_x(
1138
-                                    'Registration %s has an invalid or missing Attendee object.',
1139
-                                    'Registration 123-456-789 has an invalid or missing Attendee object.',
1140
-                                    'event_espresso'
1141
-                                ),
1142
-                                $reg_url_link
1143
-                            ),
1144
-                            __FILE__,
1145
-                            __FUNCTION__,
1146
-                            __LINE__
1147
-                        );
1148
-                        return false;
1149
-                    }
1150
-                    /** @type EE_Registration_Processor $registration_processor */
1151
-                    $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1152
-                    // at this point, we should have enough details about the registrant to consider the registration
1153
-                    // NOT incomplete
1154
-                    $registration_processor->toggle_incomplete_registration_status_to_default(
1155
-                        $registration,
1156
-                        false,
1157
-                        new Context(
1158
-                            'spco_reg_step_attendee_information_process_registrations',
1159
-                            esc_html__(
1160
-                                'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.',
1161
-                                'event_espresso'
1162
-                            )
1163
-                        )
1164
-                    );
1165
-                    // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to
1166
-                    // abandoned
1167
-                    $this->checkout->transaction->toggle_failed_transaction_status();
1168
-                    // if we've gotten this far, then let's save what we have
1169
-                    $registration->save();
1170
-                    // add relation between TXN and registration
1171
-                    $this->_associate_registration_with_transaction($registration);
1172
-                }
1173
-            } else {
1174
-                EE_Error::add_error(
1175
-                    esc_html__(
1176
-                        'An invalid or missing line item ID was encountered while attempting to process the registration form.',
1177
-                        'event_espresso'
1178
-                    ),
1179
-                    __FILE__,
1180
-                    __FUNCTION__,
1181
-                    __LINE__
1182
-                );
1183
-                // remove malformed data
1184
-                unset($valid_data[ $reg_url_link ]);
1185
-                return false;
1186
-            }
1187
-        } // end of foreach ( $this->checkout->transaction->registrations()  as $registration )
1188
-        return $att_nmbr;
1189
-    }
1190
-
1191
-
1192
-    /**
1193
-     *    _save_registration_form_input
1194
-     *
1195
-     * @param EE_Registration $registration
1196
-     * @param string          $form_input
1197
-     * @param string          $input_value
1198
-     * @return bool
1199
-     * @throws EE_Error
1200
-     * @throws InvalidArgumentException
1201
-     * @throws InvalidDataTypeException
1202
-     * @throws InvalidInterfaceException
1203
-     * @throws ReflectionException
1204
-     */
1205
-    private function _save_registration_form_input(
1206
-        EE_Registration $registration,
1207
-        $form_input = '',
1208
-        $input_value = ''
1209
-    ) {
1210
-        // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 );
1211
-        // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ );
1212
-        // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ );
1213
-        // allow for plugins to hook in and do their own processing of the form input.
1214
-        // For plugins to bypass normal processing here, they just need to return a boolean value.
1215
-        if (apply_filters(
1216
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
1217
-            false,
1218
-            $registration,
1219
-            $form_input,
1220
-            $input_value,
1221
-            $this
1222
-        )) {
1223
-            return true;
1224
-        }
1225
-        /*
129
+		$this->_print_copy_info = $reg_config->copyAttendeeInfo();
130
+
131
+		$primary_registrant = null;
132
+		// autoload Line_Item_Display classes
133
+		EEH_Autoloader::register_line_item_display_autoloaders();
134
+		$Line_Item_Display = new EE_Line_Item_Display();
135
+		// calculate taxes
136
+		$Line_Item_Display->display_line_item(
137
+			$this->checkout->cart->get_grand_total(),
138
+			array('set_tax_rate' => true)
139
+		);
140
+		/** @var $subsections EE_Form_Section_Proper[] */
141
+		$extra_inputs_section = $this->reg_step_hidden_inputs();
142
+		$subsections = array(
143
+			'default_hidden_inputs' => $extra_inputs_section,
144
+		);
145
+
146
+		// if this isn't a revisit, and they have the privacy consent box enalbed, add it
147
+		if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) {
148
+			$extra_inputs_section->add_subsections(
149
+				array(
150
+					'consent_box' => new EE_Form_Section_Proper(
151
+						array(
152
+							'layout_strategy' =>
153
+								new EE_Template_Layout(
154
+									array(
155
+										'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . '/privacy_consent.template.php',
156
+									)
157
+								),
158
+							'subsections'     => array(
159
+								'consent' => new EE_Checkbox_Multi_Input(
160
+									array(
161
+										'consent' => $reg_config->getConsentCheckboxLabelText(),
162
+									),
163
+									array(
164
+										'required'                          => true,
165
+										'required_validation_error_message' => esc_html__(
166
+											'You must consent to these terms in order to register.',
167
+											'event_espresso'
168
+										),
169
+										'html_label_text'                   => '',
170
+									)
171
+								),
172
+							),
173
+						)
174
+					),
175
+				),
176
+				null,
177
+				false
178
+			);
179
+		}
180
+		$template_args = array(
181
+			'revisit'       => $this->checkout->revisit,
182
+			'registrations' => array(),
183
+			'ticket_count'  => array(),
184
+		);
185
+		// grab the saved registrations from the transaction
186
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
187
+		if ($registrations) {
188
+			foreach ($registrations as $registration) {
189
+				// can this registration be processed during this visit ?
190
+				if ($registration instanceof EE_Registration
191
+					&& $this->checkout->visit_allows_processing_of_this_registration($registration)
192
+				) {
193
+					$subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration);
194
+					$template_args['registrations'][ $registration->reg_url_link() ] = $registration;
195
+					$template_args['ticket_count'][ $registration->ticket()->ID() ] = isset(
196
+						$template_args['ticket_count'][ $registration->ticket()->ID() ]
197
+					)
198
+						? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1
199
+						: 1;
200
+					$ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
201
+						$this->checkout->cart->get_grand_total(),
202
+						'Ticket',
203
+						array($registration->ticket()->ID())
204
+					);
205
+					$ticket_line_item = is_array($ticket_line_item)
206
+						? reset($ticket_line_item)
207
+						: $ticket_line_item;
208
+					$template_args['ticket_line_item'][ $registration->ticket()->ID() ] =
209
+						$Line_Item_Display->display_line_item($ticket_line_item);
210
+					if ($registration->is_primary_registrant()) {
211
+						$primary_registrant = $registration->reg_url_link();
212
+					}
213
+				}
214
+			}
215
+
216
+			if ($primary_registrant && count($registrations) > 1) {
217
+				$copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info
218
+					? $this->_copy_attendee_info_form()
219
+					: $this->_auto_copy_attendee_info();
220
+				// generate hidden input
221
+				if (isset($subsections[ $primary_registrant ])
222
+					&& $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper
223
+				) {
224
+					$subsections[ $primary_registrant ]->add_subsections(
225
+						$copy_options,
226
+						'primary_registrant',
227
+						false
228
+					);
229
+				}
230
+			}
231
+		}
232
+		return new EE_Form_Section_Proper(
233
+			array(
234
+				'name'            => $this->reg_form_name(),
235
+				'html_id'         => $this->reg_form_name(),
236
+				'subsections'     => $subsections,
237
+				'layout_strategy' => new EE_Template_Layout(
238
+					array(
239
+						'layout_template_file' => $this->_template, // layout_template
240
+						'template_args'        => $template_args,
241
+					)
242
+				),
243
+			)
244
+		);
245
+	}
246
+
247
+
248
+	/**
249
+	 * @param EE_Registration $registration
250
+	 * @return EE_Form_Section_Base
251
+	 * @throws EE_Error
252
+	 * @throws InvalidArgumentException
253
+	 * @throws EntityNotFoundException
254
+	 * @throws InvalidDataTypeException
255
+	 * @throws InvalidInterfaceException
256
+	 * @throws ReflectionException
257
+	 */
258
+	private function _registrations_reg_form(EE_Registration $registration)
259
+	{
260
+		static $attendee_nmbr = 1;
261
+		$form_args = array();
262
+		// verify that registration has valid event
263
+		if ($registration->event() instanceof EE_Event) {
264
+			$field_name = 'Event_Question_Group.'
265
+				. EEM_Event_Question_Group::instance()->fieldNameForContext(
266
+					$registration->is_primary_registrant()
267
+				);
268
+			$question_groups = $registration->event()->question_groups(
269
+				apply_filters(
270
+					// @codingStandardsIgnoreStart
271
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters',
272
+					// @codingStandardsIgnoreEnd
273
+					[
274
+						[
275
+							'Event.EVT_ID'                     => $registration->event()->ID(),
276
+							$field_name => true,
277
+						],
278
+						'order_by' => ['QSG_order' => 'ASC'],
279
+					],
280
+					$registration,
281
+					$this
282
+				)
283
+			);
284
+			if ($question_groups) {
285
+				// array of params to pass to parent constructor
286
+				$form_args = array(
287
+					'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
288
+					'html_class'      => 'ee-reg-form-attendee-dv',
289
+					'html_style'      => $this->checkout->admin_request
290
+						? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
291
+						: '',
292
+					'subsections'     => array(),
293
+					'layout_strategy' => new EE_Fieldset_Section_Layout(
294
+						array(
295
+							'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text',
296
+							'legend_text'  => sprintf(
297
+								esc_html_x(
298
+									'Attendee %d',
299
+									'Attendee 123',
300
+									'event_espresso'
301
+								),
302
+								$attendee_nmbr
303
+							),
304
+						)
305
+					),
306
+				);
307
+				foreach ($question_groups as $question_group) {
308
+					if ($question_group instanceof EE_Question_Group) {
309
+						$form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form(
310
+							$registration,
311
+							$question_group
312
+						);
313
+					}
314
+				}
315
+				// add hidden input
316
+				$form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input(
317
+					$registration
318
+				);
319
+
320
+				/**
321
+				 * @var $reg_config EE_Registration_Config
322
+				 */
323
+				$reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
324
+
325
+				// If we have question groups for additional attendees, then display the copy options
326
+				$this->_print_copy_info = apply_filters(
327
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo',
328
+					$attendee_nmbr > 1 ? $reg_config->copyAttendeeInfo() : false,
329
+					$attendee_nmbr
330
+				);
331
+
332
+				if ($registration->is_primary_registrant()) {
333
+					// generate hidden input
334
+					$form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs(
335
+						$registration
336
+					);
337
+				}
338
+			}
339
+		}
340
+		$attendee_nmbr++;
341
+		return ! empty($form_args)
342
+			? new EE_Form_Section_Proper($form_args)
343
+			: new EE_Form_Section_HTML();
344
+	}
345
+
346
+
347
+	/**
348
+	 * @param EE_Registration $registration
349
+	 * @param bool            $additional_attendee_reg_info
350
+	 * @return EE_Form_Input_Base
351
+	 * @throws EE_Error
352
+	 */
353
+	private function _additional_attendee_reg_info_input(
354
+		EE_Registration $registration,
355
+		$additional_attendee_reg_info = true
356
+	) {
357
+		// generate hidden input
358
+		return new EE_Hidden_Input(
359
+			array(
360
+				'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
361
+				'default' => $additional_attendee_reg_info,
362
+			)
363
+		);
364
+	}
365
+
366
+
367
+	/**
368
+	 * @param EE_Registration   $registration
369
+	 * @param EE_Question_Group $question_group
370
+	 * @return EE_Form_Section_Proper
371
+	 * @throws EE_Error
372
+	 * @throws InvalidArgumentException
373
+	 * @throws InvalidDataTypeException
374
+	 * @throws InvalidInterfaceException
375
+	 * @throws ReflectionException
376
+	 */
377
+	private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group)
378
+	{
379
+		// array of params to pass to parent constructor
380
+		$form_args = array(
381
+			'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(),
382
+			'html_class'      => $this->checkout->admin_request
383
+				? 'form-table ee-reg-form-qstn-grp-dv'
384
+				: 'ee-reg-form-qstn-grp-dv',
385
+			'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-'
386
+								 . $registration->ID() . '-lbl',
387
+			'subsections'     => array(
388
+				'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group),
389
+			),
390
+			'layout_strategy' => $this->checkout->admin_request
391
+				? new EE_Admin_Two_Column_Layout()
392
+				: new EE_Div_Per_Section_Layout(),
393
+		);
394
+		// where params
395
+		$query_params = array('QST_deleted' => 0);
396
+		// don't load admin only questions on the frontend
397
+		if (! $this->checkout->admin_request) {
398
+			$query_params['QST_admin_only'] = array('!=', true);
399
+		}
400
+		$questions = $question_group->get_many_related(
401
+			'Question',
402
+			apply_filters(
403
+				'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params',
404
+				array(
405
+					$query_params,
406
+					'order_by' => array(
407
+						'Question_Group_Question.QGQ_order' => 'ASC',
408
+					),
409
+				),
410
+				$question_group,
411
+				$registration,
412
+				$this
413
+			)
414
+		);
415
+		// filter for additional content before questions
416
+		$form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML(
417
+			apply_filters(
418
+				'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
419
+				'',
420
+				$registration,
421
+				$question_group,
422
+				$this
423
+			)
424
+		);
425
+		// loop thru questions
426
+		foreach ($questions as $question) {
427
+			if ($question instanceof EE_Question) {
428
+				$identifier = $question->is_system_question()
429
+					? $question->system_ID()
430
+					: $question->ID();
431
+				$form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question);
432
+			}
433
+		}
434
+		$form_args['subsections'] = apply_filters(
435
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array',
436
+			$form_args['subsections'],
437
+			$registration,
438
+			$question_group,
439
+			$this
440
+		);
441
+		// filter for additional content after questions
442
+		$form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML(
443
+			apply_filters(
444
+				'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
445
+				'',
446
+				$registration,
447
+				$question_group,
448
+				$this
449
+			)
450
+		);
451
+		// d($form_args);
452
+		$question_group_reg_form = new EE_Form_Section_Proper($form_args);
453
+		return apply_filters(
454
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
455
+			$question_group_reg_form,
456
+			$registration,
457
+			$question_group,
458
+			$this
459
+		);
460
+	}
461
+
462
+
463
+	/**
464
+	 * @param EE_Question_Group $question_group
465
+	 * @return    EE_Form_Section_HTML
466
+	 */
467
+	private function _question_group_header(EE_Question_Group $question_group)
468
+	{
469
+		$html = '';
470
+		// group_name
471
+		if ($question_group->show_group_name() && $question_group->name() !== '') {
472
+			if ($this->checkout->admin_request) {
473
+				$html .= EEH_HTML::br();
474
+				$html .= EEH_HTML::h3(
475
+					$question_group->name(),
476
+					'',
477
+					'ee-reg-form-qstn-grp-title title',
478
+					'font-size: 1.3em; padding-left:0;'
479
+				);
480
+			} else {
481
+				$html .= EEH_HTML::h4(
482
+					$question_group->name(),
483
+					'',
484
+					'ee-reg-form-qstn-grp-title section-title'
485
+				);
486
+			}
487
+		}
488
+		// group_desc
489
+		if ($question_group->show_group_desc() && $question_group->desc() !== '') {
490
+			$html .= EEH_HTML::p(
491
+				$question_group->desc(),
492
+				'',
493
+				$this->checkout->admin_request
494
+					? 'ee-reg-form-qstn-grp-desc-pg'
495
+					: 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text'
496
+			);
497
+		}
498
+		return new EE_Form_Section_HTML($html);
499
+	}
500
+
501
+
502
+	/**
503
+	 * @return    EE_Form_Section_Proper
504
+	 * @throws EE_Error
505
+	 * @throws InvalidArgumentException
506
+	 * @throws ReflectionException
507
+	 * @throws InvalidDataTypeException
508
+	 * @throws InvalidInterfaceException
509
+	 */
510
+	private function _copy_attendee_info_form()
511
+	{
512
+		// array of params to pass to parent constructor
513
+		return new EE_Form_Section_Proper(
514
+			array(
515
+				'subsections'     => $this->_copy_attendee_info_inputs(),
516
+				'layout_strategy' => new EE_Template_Layout(
517
+					array(
518
+						'layout_template_file'     => SPCO_REG_STEPS_PATH
519
+													  . $this->_slug
520
+													  . '/copy_attendee_info.template.php',
521
+						'begin_template_file'      => null,
522
+						'input_template_file'      => null,
523
+						'subsection_template_file' => null,
524
+						'end_template_file'        => null,
525
+					)
526
+				),
527
+			)
528
+		);
529
+	}
530
+
531
+
532
+	/**
533
+	 * @return EE_Form_Section_HTML
534
+	 * @throws DomainException
535
+	 * @throws InvalidArgumentException
536
+	 * @throws InvalidDataTypeException
537
+	 * @throws InvalidInterfaceException
538
+	 */
539
+	private function _auto_copy_attendee_info()
540
+	{
541
+		return new EE_Form_Section_HTML(
542
+			EEH_Template::locate_template(
543
+				SPCO_REG_STEPS_PATH . $this->_slug . '/_auto_copy_attendee_info.template.php',
544
+				apply_filters(
545
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
546
+					array()
547
+				),
548
+				true,
549
+				true
550
+			)
551
+		);
552
+	}
553
+
554
+
555
+	/**
556
+	 * @return array
557
+	 * @throws EE_Error
558
+	 * @throws InvalidArgumentException
559
+	 * @throws ReflectionException
560
+	 * @throws InvalidDataTypeException
561
+	 * @throws InvalidInterfaceException
562
+	 */
563
+	private function _copy_attendee_info_inputs()
564
+	{
565
+		$copy_attendee_info_inputs = array();
566
+		$prev_ticket = null;
567
+		// grab the saved registrations from the transaction
568
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
569
+		foreach ($registrations as $registration) {
570
+			// for all  attendees other than the primary attendee
571
+			if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) {
572
+				// if this is a new ticket OR if this is the very first additional attendee after the primary attendee
573
+				if ($registration->ticket()->ID() !== $prev_ticket) {
574
+					$item_name = $registration->ticket()->name();
575
+					$item_name .= $registration->ticket()->description() !== ''
576
+						? ' - ' . $registration->ticket()->description()
577
+						: '';
578
+					$copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID(
579
+					) . ']' ] =
580
+						new EE_Form_Section_HTML(
581
+							'<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>'
582
+						);
583
+					$prev_ticket = $registration->ticket()->ID();
584
+				}
585
+
586
+				$copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] =
587
+					new EE_Checkbox_Multi_Input(
588
+						array(
589
+							$registration->ID() => sprintf(
590
+								esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'),
591
+								$registration->count()
592
+							),
593
+						),
594
+						array(
595
+							'html_id'                 => 'spco-copy-attendee-chk-' . $registration->reg_url_link(),
596
+							'html_class'              => 'spco-copy-attendee-chk ee-do-not-validate',
597
+							'display_html_label_text' => false,
598
+						)
599
+					);
600
+			}
601
+		}
602
+		return $copy_attendee_info_inputs;
603
+	}
604
+
605
+
606
+	/**
607
+	 * @param EE_Registration $registration
608
+	 * @return    EE_Form_Input_Base
609
+	 * @throws EE_Error
610
+	 */
611
+	private function _additional_primary_registrant_inputs(EE_Registration $registration)
612
+	{
613
+		// generate hidden input
614
+		return new EE_Hidden_Input(
615
+			array(
616
+				'html_id' => 'primary_registrant',
617
+				'default' => $registration->reg_url_link(),
618
+			)
619
+		);
620
+	}
621
+
622
+
623
+	/**
624
+	 * @param EE_Registration $registration
625
+	 * @param EE_Question     $question
626
+	 * @return EE_Form_Input_Base
627
+	 * @throws EE_Error
628
+	 * @throws InvalidArgumentException
629
+	 * @throws InvalidDataTypeException
630
+	 * @throws InvalidInterfaceException
631
+	 * @throws ReflectionException
632
+	 */
633
+	public function reg_form_question(EE_Registration $registration, EE_Question $question)
634
+	{
635
+
636
+		// if this question was for an attendee detail, then check for that answer
637
+		$answer_value = EEM_Answer::instance()->get_attendee_property_answer_value(
638
+			$registration,
639
+			$question->system_ID()
640
+		);
641
+		$answer = $answer_value === null
642
+			? EEM_Answer::instance()->get_one(
643
+				array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
644
+			)
645
+			: null;
646
+		// if NOT returning to edit an existing registration
647
+		// OR if this question is for an attendee property
648
+		// OR we still don't have an EE_Answer object
649
+		if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
650
+			// create an EE_Answer object for storing everything in
651
+			$answer = EE_Answer::new_instance(
652
+				array(
653
+					'QST_ID' => $question->ID(),
654
+					'REG_ID' => $registration->ID(),
655
+				)
656
+			);
657
+		}
658
+		// verify instance
659
+		if ($answer instanceof EE_Answer) {
660
+			if (! empty($answer_value)) {
661
+				$answer->set('ANS_value', $answer_value);
662
+			}
663
+			$answer->cache('Question', $question);
664
+			// remember system ID had a bug where sometimes it could be null
665
+			$answer_cache_id = $question->is_system_question()
666
+				? $question->system_ID() . '-' . $registration->reg_url_link()
667
+				: $question->ID() . '-' . $registration->reg_url_link();
668
+			$registration->cache('Answer', $answer, $answer_cache_id);
669
+		}
670
+		return $this->_generate_question_input($registration, $question, $answer);
671
+	}
672
+
673
+
674
+	/**
675
+	 * @param EE_Registration $registration
676
+	 * @param EE_Question     $question
677
+	 * @param                 $answer
678
+	 * @return EE_Form_Input_Base
679
+	 * @throws EE_Error
680
+	 * @throws InvalidArgumentException
681
+	 * @throws ReflectionException
682
+	 * @throws InvalidDataTypeException
683
+	 * @throws InvalidInterfaceException
684
+	 */
685
+	private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer)
686
+	{
687
+		$identifier = $question->is_system_question()
688
+			? $question->system_ID()
689
+			: $question->ID();
690
+		$this->_required_questions[ $identifier ] = $question->required() ? true : false;
691
+		add_filter(
692
+			'FHEE__EE_Question__generate_form_input__country_options',
693
+			array($this, 'use_cached_countries_for_form_input'),
694
+			10,
695
+			4
696
+		);
697
+		add_filter(
698
+			'FHEE__EE_Question__generate_form_input__state_options',
699
+			array($this, 'use_cached_states_for_form_input'),
700
+			10,
701
+			4
702
+		);
703
+		$input_constructor_args = array(
704
+			'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
705
+			'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
706
+			'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
707
+			'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
708
+			'html_label_class' => 'ee-reg-qstn',
709
+		);
710
+		$input_constructor_args['html_label_id'] .= '-lbl';
711
+		if ($answer instanceof EE_Answer && $answer->ID()) {
712
+			$input_constructor_args['html_name'] .= '[' . $answer->ID() . ']';
713
+			$input_constructor_args['html_id'] .= '-' . $answer->ID();
714
+			$input_constructor_args['html_label_id'] .= '-' . $answer->ID();
715
+		}
716
+		$form_input = $question->generate_form_input(
717
+			$registration,
718
+			$answer,
719
+			$input_constructor_args
720
+		);
721
+		remove_filter(
722
+			'FHEE__EE_Question__generate_form_input__country_options',
723
+			array($this, 'use_cached_countries_for_form_input')
724
+		);
725
+		remove_filter(
726
+			'FHEE__EE_Question__generate_form_input__state_options',
727
+			array($this, 'use_cached_states_for_form_input')
728
+		);
729
+		return $form_input;
730
+	}
731
+
732
+
733
+	/**
734
+	 * Gets the list of countries for the form input
735
+	 *
736
+	 * @param array|null      $countries_list
737
+	 * @param EE_Question     $question
738
+	 * @param EE_Registration $registration
739
+	 * @param EE_Answer       $answer
740
+	 * @return array 2d keys are country IDs, values are their names
741
+	 * @throws EE_Error
742
+	 * @throws InvalidArgumentException
743
+	 * @throws InvalidDataTypeException
744
+	 * @throws InvalidInterfaceException
745
+	 * @throws ReflectionException
746
+	 */
747
+	public function use_cached_countries_for_form_input(
748
+		$countries_list,
749
+		EE_Question $question = null,
750
+		EE_Registration $registration = null,
751
+		EE_Answer $answer = null
752
+	) {
753
+		$country_options = array('' => '');
754
+		// get possibly cached list of countries
755
+		$countries = $this->checkout->action === 'process_reg_step'
756
+			? EEM_Country::instance()->get_all_countries()
757
+			: EEM_Country::instance()->get_all_active_countries();
758
+		if (! empty($countries)) {
759
+			foreach ($countries as $country) {
760
+				if ($country instanceof EE_Country) {
761
+					$country_options[ $country->ID() ] = $country->name();
762
+				}
763
+			}
764
+		}
765
+		if ($question instanceof EE_Question && $registration instanceof EE_Registration) {
766
+			$answer = EEM_Answer::instance()->get_one(
767
+				array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
768
+			);
769
+		} else {
770
+			$answer = EE_Answer::new_instance();
771
+		}
772
+		$country_options = apply_filters(
773
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
774
+			$country_options,
775
+			$this,
776
+			$registration,
777
+			$question,
778
+			$answer
779
+		);
780
+		return $country_options;
781
+	}
782
+
783
+
784
+	/**
785
+	 * Gets the list of states for the form input
786
+	 *
787
+	 * @param array|null      $states_list
788
+	 * @param EE_Question     $question
789
+	 * @param EE_Registration $registration
790
+	 * @param EE_Answer       $answer
791
+	 * @return array 2d keys are state IDs, values are their names
792
+	 * @throws EE_Error
793
+	 * @throws InvalidArgumentException
794
+	 * @throws InvalidDataTypeException
795
+	 * @throws InvalidInterfaceException
796
+	 * @throws ReflectionException
797
+	 */
798
+	public function use_cached_states_for_form_input(
799
+		$states_list,
800
+		EE_Question $question = null,
801
+		EE_Registration $registration = null,
802
+		EE_Answer $answer = null
803
+	) {
804
+		$state_options = array('' => array('' => ''));
805
+		$states = $this->checkout->action === 'process_reg_step'
806
+			? EEM_State::instance()->get_all_states()
807
+			: EEM_State::instance()->get_all_active_states();
808
+		if (! empty($states)) {
809
+			foreach ($states as $state) {
810
+				if ($state instanceof EE_State) {
811
+					$state_options[ $state->country()->name() ][ $state->ID() ] = $state->name();
812
+				}
813
+			}
814
+		}
815
+		$state_options = apply_filters(
816
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
817
+			$state_options,
818
+			$this,
819
+			$registration,
820
+			$question,
821
+			$answer
822
+		);
823
+		return $state_options;
824
+	}
825
+
826
+
827
+	/********************************************************************************************************/
828
+	/****************************************  PROCESS REG STEP  ****************************************/
829
+	/********************************************************************************************************/
830
+
831
+
832
+	/**
833
+	 * @return bool
834
+	 * @throws EE_Error
835
+	 * @throws InvalidArgumentException
836
+	 * @throws ReflectionException
837
+	 * @throws RuntimeException
838
+	 * @throws InvalidDataTypeException
839
+	 * @throws InvalidInterfaceException
840
+	 */
841
+	public function process_reg_step()
842
+	{
843
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
844
+		// grab validated data from form
845
+		$valid_data = $this->checkout->current_step->valid_data();
846
+		// EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
847
+		// EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ );
848
+		// if we don't have any $valid_data then something went TERRIBLY WRONG !!!
849
+		if (empty($valid_data)) {
850
+			EE_Error::add_error(
851
+				esc_html__('No valid question responses were received.', 'event_espresso'),
852
+				__FILE__,
853
+				__FUNCTION__,
854
+				__LINE__
855
+			);
856
+			return false;
857
+		}
858
+		if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
859
+			EE_Error::add_error(
860
+				esc_html__(
861
+					'A valid transaction could not be initiated for processing your registrations.',
862
+					'event_espresso'
863
+				),
864
+				__FILE__,
865
+				__FUNCTION__,
866
+				__LINE__
867
+			);
868
+			return false;
869
+		}
870
+		// get cached registrations
871
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
872
+		// verify we got the goods
873
+		if (empty($registrations)) {
874
+			// combine the old translated string with a new one, in order to not break translations
875
+			$error_message = esc_html__(
876
+				'Your form data could not be applied to any valid registrations.',
877
+				'event_espresso'
878
+			)
879
+			. sprintf(
880
+				esc_html_x(
881
+					'%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.',
882
+					'(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.',
883
+					'event_espresso'
884
+				),
885
+				'<a href="' . get_post_type_archive_link('espresso_events') . '" >',
886
+				'</a>',
887
+				'<br />'
888
+			);
889
+			EE_Error::add_error(
890
+				$error_message,
891
+				__FILE__,
892
+				__FUNCTION__,
893
+				__LINE__
894
+			);
895
+			return false;
896
+		}
897
+		// extract attendee info from form data and save to model objects
898
+		$registrations_processed = $this->_process_registrations($registrations, $valid_data);
899
+		// if first pass thru SPCO,
900
+		// then let's check processed registrations against the total number of tickets in the cart
901
+		if ($registrations_processed === false) {
902
+			// but return immediately if the previous step exited early due to errors
903
+			return false;
904
+		}
905
+		if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
906
+			// generate a correctly translated string for all possible singular/plural combinations
907
+			if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
908
+				$error_msg = sprintf(
909
+					esc_html_x(
910
+						'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
911
+						'There was 1 ticket in the Event Queue, but 2 registrations were processed',
912
+						'event_espresso'
913
+					),
914
+					$this->checkout->total_ticket_count,
915
+					$registrations_processed
916
+				);
917
+			} elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
918
+				$error_msg = sprintf(
919
+					esc_html_x(
920
+						'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
921
+						'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed',
922
+						'event_espresso'
923
+					),
924
+					$this->checkout->total_ticket_count,
925
+					$registrations_processed
926
+				);
927
+			} else {
928
+				$error_msg = sprintf(
929
+					esc_html__(
930
+						'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed',
931
+						'event_espresso'
932
+					),
933
+					$this->checkout->total_ticket_count,
934
+					$registrations_processed
935
+				);
936
+			}
937
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
938
+			return false;
939
+		}
940
+		// mark this reg step as completed
941
+		$this->set_completed();
942
+		$this->_set_success_message(
943
+			esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso')
944
+		);
945
+		// do action in case a plugin wants to do something with the data submitted in step 1.
946
+		// passes EE_Single_Page_Checkout, and it's posted data
947
+		do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
948
+		return true;
949
+	}
950
+
951
+
952
+	/**
953
+	 *    _process_registrations
954
+	 *
955
+	 * @param EE_Registration[] $registrations
956
+	 * @param array[][]         $valid_data
957
+	 * @return bool|int
958
+	 * @throws EntityNotFoundException
959
+	 * @throws EE_Error
960
+	 * @throws InvalidArgumentException
961
+	 * @throws ReflectionException
962
+	 * @throws RuntimeException
963
+	 * @throws InvalidDataTypeException
964
+	 * @throws InvalidInterfaceException
965
+	 */
966
+	private function _process_registrations($registrations = array(), $valid_data = array())
967
+	{
968
+		// load resources and set some defaults
969
+		EE_Registry::instance()->load_model('Attendee');
970
+		// holder for primary registrant attendee object
971
+		$this->checkout->primary_attendee_obj = null;
972
+		// array for tracking reg form data for the primary registrant
973
+		$primary_registrant = array(
974
+			'line_item_id' => null,
975
+		);
976
+		$copy_primary = false;
977
+		// reg form sections that do not contain inputs
978
+		$non_input_form_sections = array(
979
+			'primary_registrant',
980
+			'additional_attendee_reg_info',
981
+			'spco_copy_attendee_chk',
982
+		);
983
+		// attendee counter
984
+		$att_nmbr = 0;
985
+		// grab the saved registrations from the transaction
986
+		foreach ($registrations as $registration) {
987
+			// verify EE_Registration object
988
+			if (! $registration instanceof EE_Registration) {
989
+				EE_Error::add_error(
990
+					esc_html__(
991
+						'An invalid Registration object was discovered when attempting to process your registration information.',
992
+						'event_espresso'
993
+					),
994
+					__FILE__,
995
+					__FUNCTION__,
996
+					__LINE__
997
+				);
998
+				return false;
999
+			}
1000
+			/** @var string $reg_url_link */
1001
+			$reg_url_link = $registration->reg_url_link();
1002
+			// reg_url_link exists ?
1003
+			if (! empty($reg_url_link)) {
1004
+				// should this registration be processed during this visit ?
1005
+				if ($this->checkout->visit_allows_processing_of_this_registration($registration)) {
1006
+					// if NOT revisiting, then let's save the registration now,
1007
+					// so that we have a REG_ID to use when generating other objects
1008
+					if (! $this->checkout->revisit) {
1009
+						$registration->save();
1010
+					}
1011
+					/**
1012
+					 * This allows plugins to trigger a fail on processing of a
1013
+					 * registration for any conditions they may have for it to pass.
1014
+					 *
1015
+					 * @var bool   if true is returned by the plugin then the
1016
+					 *            registration processing is halted.
1017
+					 */
1018
+					if (apply_filters(
1019
+						'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
1020
+						false,
1021
+						$att_nmbr,
1022
+						$registration,
1023
+						$registrations,
1024
+						$valid_data,
1025
+						$this
1026
+					)) {
1027
+						return false;
1028
+					}
1029
+
1030
+					// Houston, we have a registration!
1031
+					$att_nmbr++;
1032
+					$this->_attendee_data[ $reg_url_link ] = array();
1033
+					// grab any existing related answer objects
1034
+					$this->_registration_answers = $registration->answers();
1035
+					// unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] );
1036
+					if (isset($valid_data[ $reg_url_link ])) {
1037
+						// do we need to copy basic info from primary attendee ?
1038
+						$copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info'])
1039
+										&& absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0;
1040
+						// filter form input data for this registration
1041
+						$valid_data[ $reg_url_link ] = (array) apply_filters(
1042
+							'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
1043
+							$valid_data[ $reg_url_link ]
1044
+						);
1045
+						if (isset($valid_data['primary_attendee'])) {
1046
+							$primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee'])
1047
+								? $valid_data['primary_attendee']
1048
+								: false;
1049
+							unset($valid_data['primary_attendee']);
1050
+						}
1051
+						// now loop through our array of valid post data && process attendee reg forms
1052
+						foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) {
1053
+							if (! in_array($form_section, $non_input_form_sections, true)) {
1054
+								foreach ($form_inputs as $form_input => $input_value) {
1055
+									// \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ );
1056
+									// check for critical inputs
1057
+									if (! $this->_verify_critical_attendee_details_are_set_and_validate_email(
1058
+										$form_input,
1059
+										$input_value
1060
+									)
1061
+									) {
1062
+										return false;
1063
+									}
1064
+									// store a bit of data about the primary attendee
1065
+									if ($att_nmbr === 1
1066
+										&& ! empty($input_value)
1067
+										&& $reg_url_link === $primary_registrant['line_item_id']
1068
+									) {
1069
+										$primary_registrant[ $form_input ] = $input_value;
1070
+									} elseif ($copy_primary
1071
+											  && $input_value === null
1072
+											  && isset($primary_registrant[ $form_input ])
1073
+									) {
1074
+										$input_value = $primary_registrant[ $form_input ];
1075
+									}
1076
+									// now attempt to save the input data
1077
+									if (! $this->_save_registration_form_input(
1078
+										$registration,
1079
+										$form_input,
1080
+										$input_value
1081
+									)
1082
+									) {
1083
+										EE_Error::add_error(
1084
+											sprintf(
1085
+												esc_html_x(
1086
+													'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"',
1087
+													'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"',
1088
+													'event_espresso'
1089
+												),
1090
+												$form_input,
1091
+												$input_value
1092
+											),
1093
+											__FILE__,
1094
+											__FUNCTION__,
1095
+											__LINE__
1096
+										);
1097
+										return false;
1098
+									}
1099
+								}
1100
+							}
1101
+						}  // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs )
1102
+					}
1103
+					// EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ );
1104
+					// this registration does not require additional attendee information ?
1105
+					if ($copy_primary
1106
+						&& $att_nmbr > 1
1107
+						&& $this->checkout->primary_attendee_obj instanceof EE_Attendee
1108
+					) {
1109
+						// just copy the primary registrant
1110
+						$attendee = $this->checkout->primary_attendee_obj;
1111
+					} else {
1112
+						// ensure critical details are set for additional attendees
1113
+						$this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1
1114
+							? $this->_copy_critical_attendee_details_from_primary_registrant(
1115
+								$this->_attendee_data[ $reg_url_link ]
1116
+							)
1117
+							: $this->_attendee_data[ $reg_url_link ];
1118
+						// execute create attendee command (which may return an existing attendee)
1119
+						$attendee = EE_Registry::instance()->BUS->execute(
1120
+							new CreateAttendeeCommand(
1121
+								$this->_attendee_data[ $reg_url_link ],
1122
+								$registration
1123
+							)
1124
+						);
1125
+						// who's #1 ?
1126
+						if ($att_nmbr === 1) {
1127
+							$this->checkout->primary_attendee_obj = $attendee;
1128
+						}
1129
+					}
1130
+					// EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ );
1131
+					// add relation to registration, set attendee ID, and cache attendee
1132
+					$this->_associate_attendee_with_registration($registration, $attendee);
1133
+					// \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ );
1134
+					if (! $registration->attendee() instanceof EE_Attendee) {
1135
+						EE_Error::add_error(
1136
+							sprintf(
1137
+								esc_html_x(
1138
+									'Registration %s has an invalid or missing Attendee object.',
1139
+									'Registration 123-456-789 has an invalid or missing Attendee object.',
1140
+									'event_espresso'
1141
+								),
1142
+								$reg_url_link
1143
+							),
1144
+							__FILE__,
1145
+							__FUNCTION__,
1146
+							__LINE__
1147
+						);
1148
+						return false;
1149
+					}
1150
+					/** @type EE_Registration_Processor $registration_processor */
1151
+					$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1152
+					// at this point, we should have enough details about the registrant to consider the registration
1153
+					// NOT incomplete
1154
+					$registration_processor->toggle_incomplete_registration_status_to_default(
1155
+						$registration,
1156
+						false,
1157
+						new Context(
1158
+							'spco_reg_step_attendee_information_process_registrations',
1159
+							esc_html__(
1160
+								'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.',
1161
+								'event_espresso'
1162
+							)
1163
+						)
1164
+					);
1165
+					// we can also consider the TXN to not have been failed, so temporarily upgrade it's status to
1166
+					// abandoned
1167
+					$this->checkout->transaction->toggle_failed_transaction_status();
1168
+					// if we've gotten this far, then let's save what we have
1169
+					$registration->save();
1170
+					// add relation between TXN and registration
1171
+					$this->_associate_registration_with_transaction($registration);
1172
+				}
1173
+			} else {
1174
+				EE_Error::add_error(
1175
+					esc_html__(
1176
+						'An invalid or missing line item ID was encountered while attempting to process the registration form.',
1177
+						'event_espresso'
1178
+					),
1179
+					__FILE__,
1180
+					__FUNCTION__,
1181
+					__LINE__
1182
+				);
1183
+				// remove malformed data
1184
+				unset($valid_data[ $reg_url_link ]);
1185
+				return false;
1186
+			}
1187
+		} // end of foreach ( $this->checkout->transaction->registrations()  as $registration )
1188
+		return $att_nmbr;
1189
+	}
1190
+
1191
+
1192
+	/**
1193
+	 *    _save_registration_form_input
1194
+	 *
1195
+	 * @param EE_Registration $registration
1196
+	 * @param string          $form_input
1197
+	 * @param string          $input_value
1198
+	 * @return bool
1199
+	 * @throws EE_Error
1200
+	 * @throws InvalidArgumentException
1201
+	 * @throws InvalidDataTypeException
1202
+	 * @throws InvalidInterfaceException
1203
+	 * @throws ReflectionException
1204
+	 */
1205
+	private function _save_registration_form_input(
1206
+		EE_Registration $registration,
1207
+		$form_input = '',
1208
+		$input_value = ''
1209
+	) {
1210
+		// \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 );
1211
+		// \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ );
1212
+		// \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ );
1213
+		// allow for plugins to hook in and do their own processing of the form input.
1214
+		// For plugins to bypass normal processing here, they just need to return a boolean value.
1215
+		if (apply_filters(
1216
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
1217
+			false,
1218
+			$registration,
1219
+			$form_input,
1220
+			$input_value,
1221
+			$this
1222
+		)) {
1223
+			return true;
1224
+		}
1225
+		/*
1226 1226
          * $answer_cache_id is the key used to find the EE_Answer we want
1227 1227
          * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477
1228 1228
          */
1229
-        $answer_cache_id = $this->checkout->reg_url_link
1230
-            ? $form_input . '-' . $registration->reg_url_link()
1231
-            : $form_input;
1232
-        $answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ])
1233
-                         && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer;
1234
-        // rename form_inputs if they are EE_Attendee properties
1235
-        switch ((string) $form_input) {
1236
-            case 'state':
1237
-            case 'STA_ID':
1238
-                $attendee_property = true;
1239
-                $form_input = 'STA_ID';
1240
-                break;
1241
-
1242
-            case 'country':
1243
-            case 'CNT_ISO':
1244
-                $attendee_property = true;
1245
-                $form_input = 'CNT_ISO';
1246
-                break;
1247
-
1248
-            default:
1249
-                $ATT_input = 'ATT_' . $form_input;
1250
-                // EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ );
1251
-                $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false;
1252
-                $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input;
1253
-        }
1254
-        // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ );
1255
-        // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ );
1256
-        // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ );
1257
-        // if this form input has a corresponding attendee property
1258
-        if ($attendee_property) {
1259
-            $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value;
1260
-            if ($answer_is_obj) {
1261
-                // and delete the corresponding answer since we won't be storing this data in that object
1262
-                $registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer');
1263
-                $this->_registration_answers[ $answer_cache_id ]->delete_permanently();
1264
-            }
1265
-            return true;
1266
-        }
1267
-        if ($answer_is_obj) {
1268
-            // save this data to the answer object
1269
-            $this->_registration_answers[ $answer_cache_id ]->set_value($input_value);
1270
-            $result = $this->_registration_answers[ $answer_cache_id ]->save();
1271
-            return $result !== false;
1272
-        }
1273
-        foreach ($this->_registration_answers as $answer) {
1274
-            if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) {
1275
-                $answer->set_value($input_value);
1276
-                $result = $answer->save();
1277
-                return $result !== false;
1278
-            }
1279
-        }
1280
-        return false;
1281
-    }
1282
-
1283
-
1284
-    /**
1285
-     *    _verify_critical_attendee_details_are_set
1286
-     *
1287
-     * @param string $form_input
1288
-     * @param string $input_value
1289
-     * @return boolean
1290
-     */
1291
-    private function _verify_critical_attendee_details_are_set_and_validate_email(
1292
-        $form_input = '',
1293
-        $input_value = ''
1294
-    ) {
1295
-        if (empty($input_value)) {
1296
-            // if the form input isn't marked as being required, then just return
1297
-            if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) {
1298
-                return true;
1299
-            }
1300
-            switch ($form_input) {
1301
-                case 'fname':
1302
-                    EE_Error::add_error(
1303
-                        esc_html__('First Name is a required value.', 'event_espresso'),
1304
-                        __FILE__,
1305
-                        __FUNCTION__,
1306
-                        __LINE__
1307
-                    );
1308
-                    return false;
1309
-                    break;
1310
-                case 'lname':
1311
-                    EE_Error::add_error(
1312
-                        esc_html__('Last Name is a required value.', 'event_espresso'),
1313
-                        __FILE__,
1314
-                        __FUNCTION__,
1315
-                        __LINE__
1316
-                    );
1317
-                    return false;
1318
-                    break;
1319
-                case 'email':
1320
-                    EE_Error::add_error(
1321
-                        esc_html__('Please enter a valid email address.', 'event_espresso'),
1322
-                        __FILE__,
1323
-                        __FUNCTION__,
1324
-                        __LINE__
1325
-                    );
1326
-                    return false;
1327
-                    break;
1328
-            }
1329
-        }
1330
-        return true;
1331
-    }
1332
-
1333
-
1334
-    /**
1335
-     *    _associate_attendee_with_registration
1336
-     *
1337
-     * @param EE_Registration $registration
1338
-     * @param EE_Attendee     $attendee
1339
-     * @return void
1340
-     * @throws EE_Error
1341
-     * @throws InvalidArgumentException
1342
-     * @throws ReflectionException
1343
-     * @throws RuntimeException
1344
-     * @throws InvalidDataTypeException
1345
-     * @throws InvalidInterfaceException
1346
-     */
1347
-    private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee)
1348
-    {
1349
-        // add relation to attendee
1350
-        $registration->_add_relation_to($attendee, 'Attendee');
1351
-        $registration->set_attendee_id($attendee->ID());
1352
-        $registration->update_cache_after_object_save('Attendee', $attendee);
1353
-    }
1354
-
1355
-
1356
-    /**
1357
-     *    _associate_registration_with_transaction
1358
-     *
1359
-     * @param EE_Registration $registration
1360
-     * @return void
1361
-     * @throws EE_Error
1362
-     * @throws InvalidArgumentException
1363
-     * @throws ReflectionException
1364
-     * @throws InvalidDataTypeException
1365
-     * @throws InvalidInterfaceException
1366
-     */
1367
-    private function _associate_registration_with_transaction(EE_Registration $registration)
1368
-    {
1369
-        // add relation to registration
1370
-        $this->checkout->transaction->_add_relation_to($registration, 'Registration');
1371
-        $this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
1372
-    }
1373
-
1374
-
1375
-    /**
1376
-     *    _copy_critical_attendee_details_from_primary_registrant
1377
-     *    ensures that all attendees at least have data for first name, last name, and email address
1378
-     *
1379
-     * @param array $attendee_data
1380
-     * @return array
1381
-     * @throws EE_Error
1382
-     * @throws InvalidArgumentException
1383
-     * @throws ReflectionException
1384
-     * @throws InvalidDataTypeException
1385
-     * @throws InvalidInterfaceException
1386
-     */
1387
-    private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array())
1388
-    {
1389
-        // bare minimum critical details include first name, last name, email address
1390
-        $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email');
1391
-        // add address info to critical details?
1392
-        if (apply_filters(
1393
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
1394
-            false
1395
-        )) {
1396
-            $address_details = array(
1397
-                'ATT_address',
1398
-                'ATT_address2',
1399
-                'ATT_city',
1400
-                'STA_ID',
1401
-                'CNT_ISO',
1402
-                'ATT_zip',
1403
-                'ATT_phone',
1404
-            );
1405
-            $critical_attendee_details = array_merge($critical_attendee_details, $address_details);
1406
-        }
1407
-        foreach ($critical_attendee_details as $critical_attendee_detail) {
1408
-            if (! isset($attendee_data[ $critical_attendee_detail ])
1409
-                || empty($attendee_data[ $critical_attendee_detail ])
1410
-            ) {
1411
-                $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get(
1412
-                    $critical_attendee_detail
1413
-                );
1414
-            }
1415
-        }
1416
-        return $attendee_data;
1417
-    }
1418
-
1419
-
1420
-    /**
1421
-     *    update_reg_step
1422
-     *    this is the final step after a user  revisits the site to edit their attendee information
1423
-     *    this gets called AFTER the process_reg_step() method above
1424
-     *
1425
-     * @return bool
1426
-     * @throws EE_Error
1427
-     * @throws InvalidArgumentException
1428
-     * @throws ReflectionException
1429
-     * @throws RuntimeException
1430
-     * @throws InvalidDataTypeException
1431
-     * @throws InvalidInterfaceException
1432
-     */
1433
-    public function update_reg_step()
1434
-    {
1435
-        // save everything
1436
-        if ($this->process_reg_step()) {
1437
-            $this->checkout->redirect = true;
1438
-            $this->checkout->redirect_url = add_query_arg(
1439
-                array(
1440
-                    'e_reg_url_link' => $this->checkout->reg_url_link,
1441
-                    'revisit'        => true,
1442
-                ),
1443
-                $this->checkout->thank_you_page_url
1444
-            );
1445
-            $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1446
-            return true;
1447
-        }
1448
-        return false;
1449
-    }
1229
+		$answer_cache_id = $this->checkout->reg_url_link
1230
+			? $form_input . '-' . $registration->reg_url_link()
1231
+			: $form_input;
1232
+		$answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ])
1233
+						 && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer;
1234
+		// rename form_inputs if they are EE_Attendee properties
1235
+		switch ((string) $form_input) {
1236
+			case 'state':
1237
+			case 'STA_ID':
1238
+				$attendee_property = true;
1239
+				$form_input = 'STA_ID';
1240
+				break;
1241
+
1242
+			case 'country':
1243
+			case 'CNT_ISO':
1244
+				$attendee_property = true;
1245
+				$form_input = 'CNT_ISO';
1246
+				break;
1247
+
1248
+			default:
1249
+				$ATT_input = 'ATT_' . $form_input;
1250
+				// EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ );
1251
+				$attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false;
1252
+				$form_input = $attendee_property ? 'ATT_' . $form_input : $form_input;
1253
+		}
1254
+		// EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ );
1255
+		// EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ );
1256
+		// EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ );
1257
+		// if this form input has a corresponding attendee property
1258
+		if ($attendee_property) {
1259
+			$this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value;
1260
+			if ($answer_is_obj) {
1261
+				// and delete the corresponding answer since we won't be storing this data in that object
1262
+				$registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer');
1263
+				$this->_registration_answers[ $answer_cache_id ]->delete_permanently();
1264
+			}
1265
+			return true;
1266
+		}
1267
+		if ($answer_is_obj) {
1268
+			// save this data to the answer object
1269
+			$this->_registration_answers[ $answer_cache_id ]->set_value($input_value);
1270
+			$result = $this->_registration_answers[ $answer_cache_id ]->save();
1271
+			return $result !== false;
1272
+		}
1273
+		foreach ($this->_registration_answers as $answer) {
1274
+			if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) {
1275
+				$answer->set_value($input_value);
1276
+				$result = $answer->save();
1277
+				return $result !== false;
1278
+			}
1279
+		}
1280
+		return false;
1281
+	}
1282
+
1283
+
1284
+	/**
1285
+	 *    _verify_critical_attendee_details_are_set
1286
+	 *
1287
+	 * @param string $form_input
1288
+	 * @param string $input_value
1289
+	 * @return boolean
1290
+	 */
1291
+	private function _verify_critical_attendee_details_are_set_and_validate_email(
1292
+		$form_input = '',
1293
+		$input_value = ''
1294
+	) {
1295
+		if (empty($input_value)) {
1296
+			// if the form input isn't marked as being required, then just return
1297
+			if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) {
1298
+				return true;
1299
+			}
1300
+			switch ($form_input) {
1301
+				case 'fname':
1302
+					EE_Error::add_error(
1303
+						esc_html__('First Name is a required value.', 'event_espresso'),
1304
+						__FILE__,
1305
+						__FUNCTION__,
1306
+						__LINE__
1307
+					);
1308
+					return false;
1309
+					break;
1310
+				case 'lname':
1311
+					EE_Error::add_error(
1312
+						esc_html__('Last Name is a required value.', 'event_espresso'),
1313
+						__FILE__,
1314
+						__FUNCTION__,
1315
+						__LINE__
1316
+					);
1317
+					return false;
1318
+					break;
1319
+				case 'email':
1320
+					EE_Error::add_error(
1321
+						esc_html__('Please enter a valid email address.', 'event_espresso'),
1322
+						__FILE__,
1323
+						__FUNCTION__,
1324
+						__LINE__
1325
+					);
1326
+					return false;
1327
+					break;
1328
+			}
1329
+		}
1330
+		return true;
1331
+	}
1332
+
1333
+
1334
+	/**
1335
+	 *    _associate_attendee_with_registration
1336
+	 *
1337
+	 * @param EE_Registration $registration
1338
+	 * @param EE_Attendee     $attendee
1339
+	 * @return void
1340
+	 * @throws EE_Error
1341
+	 * @throws InvalidArgumentException
1342
+	 * @throws ReflectionException
1343
+	 * @throws RuntimeException
1344
+	 * @throws InvalidDataTypeException
1345
+	 * @throws InvalidInterfaceException
1346
+	 */
1347
+	private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee)
1348
+	{
1349
+		// add relation to attendee
1350
+		$registration->_add_relation_to($attendee, 'Attendee');
1351
+		$registration->set_attendee_id($attendee->ID());
1352
+		$registration->update_cache_after_object_save('Attendee', $attendee);
1353
+	}
1354
+
1355
+
1356
+	/**
1357
+	 *    _associate_registration_with_transaction
1358
+	 *
1359
+	 * @param EE_Registration $registration
1360
+	 * @return void
1361
+	 * @throws EE_Error
1362
+	 * @throws InvalidArgumentException
1363
+	 * @throws ReflectionException
1364
+	 * @throws InvalidDataTypeException
1365
+	 * @throws InvalidInterfaceException
1366
+	 */
1367
+	private function _associate_registration_with_transaction(EE_Registration $registration)
1368
+	{
1369
+		// add relation to registration
1370
+		$this->checkout->transaction->_add_relation_to($registration, 'Registration');
1371
+		$this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
1372
+	}
1373
+
1374
+
1375
+	/**
1376
+	 *    _copy_critical_attendee_details_from_primary_registrant
1377
+	 *    ensures that all attendees at least have data for first name, last name, and email address
1378
+	 *
1379
+	 * @param array $attendee_data
1380
+	 * @return array
1381
+	 * @throws EE_Error
1382
+	 * @throws InvalidArgumentException
1383
+	 * @throws ReflectionException
1384
+	 * @throws InvalidDataTypeException
1385
+	 * @throws InvalidInterfaceException
1386
+	 */
1387
+	private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array())
1388
+	{
1389
+		// bare minimum critical details include first name, last name, email address
1390
+		$critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email');
1391
+		// add address info to critical details?
1392
+		if (apply_filters(
1393
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
1394
+			false
1395
+		)) {
1396
+			$address_details = array(
1397
+				'ATT_address',
1398
+				'ATT_address2',
1399
+				'ATT_city',
1400
+				'STA_ID',
1401
+				'CNT_ISO',
1402
+				'ATT_zip',
1403
+				'ATT_phone',
1404
+			);
1405
+			$critical_attendee_details = array_merge($critical_attendee_details, $address_details);
1406
+		}
1407
+		foreach ($critical_attendee_details as $critical_attendee_detail) {
1408
+			if (! isset($attendee_data[ $critical_attendee_detail ])
1409
+				|| empty($attendee_data[ $critical_attendee_detail ])
1410
+			) {
1411
+				$attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get(
1412
+					$critical_attendee_detail
1413
+				);
1414
+			}
1415
+		}
1416
+		return $attendee_data;
1417
+	}
1418
+
1419
+
1420
+	/**
1421
+	 *    update_reg_step
1422
+	 *    this is the final step after a user  revisits the site to edit their attendee information
1423
+	 *    this gets called AFTER the process_reg_step() method above
1424
+	 *
1425
+	 * @return bool
1426
+	 * @throws EE_Error
1427
+	 * @throws InvalidArgumentException
1428
+	 * @throws ReflectionException
1429
+	 * @throws RuntimeException
1430
+	 * @throws InvalidDataTypeException
1431
+	 * @throws InvalidInterfaceException
1432
+	 */
1433
+	public function update_reg_step()
1434
+	{
1435
+		// save everything
1436
+		if ($this->process_reg_step()) {
1437
+			$this->checkout->redirect = true;
1438
+			$this->checkout->redirect_url = add_query_arg(
1439
+				array(
1440
+					'e_reg_url_link' => $this->checkout->reg_url_link,
1441
+					'revisit'        => true,
1442
+				),
1443
+				$this->checkout->thank_you_page_url
1444
+			);
1445
+			$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1446
+			return true;
1447
+		}
1448
+		return false;
1449
+	}
1450 1450
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.2.rc.069');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.2.rc.069');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.