Completed
Branch BUG-11107-submit-button-text (879795)
by
unknown
11:38
created
attendee_information/EE_SPCO_Reg_Step_Attendee_Information.class.php 2 patches
Indentation   +1335 added lines, -1335 removed lines patch added patch discarded remove patch
@@ -17,1343 +17,1343 @@
 block discarded – undo
17 17
 class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step
18 18
 {
19 19
 
20
-    /**
21
-     * @type bool $_print_copy_info
22
-     */
23
-    private $_print_copy_info = false;
24
-
25
-    /**
26
-     * @type array $_attendee_data
27
-     */
28
-    private $_attendee_data = array();
29
-
30
-    /**
31
-     * @type array $_required_questions
32
-     */
33
-    private $_required_questions = array();
34
-
35
-    /**
36
-     * @type array $_registration_answers
37
-     */
38
-    private $_registration_answers = array();
39
-
40
-
41
-    /**
42
-     *    class constructor
43
-     *
44
-     * @access    public
45
-     * @param    EE_Checkout $checkout
46
-     */
47
-    public function __construct(EE_Checkout $checkout)
48
-    {
49
-        $this->_slug     = 'attendee_information';
50
-        $this->_name     = esc_html__('Attendee Information', 'event_espresso');
51
-        $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php';
52
-        $this->checkout  = $checkout;
53
-        $this->_reset_success_message();
54
-        $this->set_instructions(
55
-            esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso')
56
-        );
57
-    }
58
-
59
-
60
-    public function translate_js_strings()
61
-    {
62
-        EE_Registry::$i18n_js_strings['required_field']            = esc_html__(
63
-            ' is a required question.',
64
-            'event_espresso'
65
-        );
66
-        EE_Registry::$i18n_js_strings['required_multi_field']      = esc_html__(
67
-            ' is a required question. Please enter a value for at least one of the options.',
68
-            'event_espresso'
69
-        );
70
-        EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__(
71
-            'Please answer all required questions correctly before proceeding.',
72
-            'event_espresso'
73
-        );
74
-        EE_Registry::$i18n_js_strings['attendee_info_copied']      = sprintf(
75
-            esc_html__(
76
-                'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
77
-                'event_espresso'
78
-            ),
79
-            '<br/>'
80
-        );
81
-        EE_Registry::$i18n_js_strings['attendee_info_copy_error']  = esc_html__(
82
-            'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
83
-            'event_espresso'
84
-        );
85
-        EE_Registry::$i18n_js_strings['enter_valid_email']         = esc_html__(
86
-            'You must enter a valid email address.',
87
-            'event_espresso'
88
-        );
89
-        EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__(
90
-            'You must enter a valid email address and answer all other required questions before you can proceed.',
91
-            'event_espresso'
92
-        );
93
-    }
94
-
95
-
96
-    public function enqueue_styles_and_scripts()
97
-    {
98
-    }
99
-
100
-
101
-    /**
102
-     * @return boolean
103
-     */
104
-    public function initialize_reg_step()
105
-    {
106
-        return true;
107
-    }
108
-
109
-
110
-    /**
111
-     * @return EE_Form_Section_Proper
112
-     * @throws EE_Error
113
-     * @throws InvalidArgumentException
114
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
115
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
116
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
117
-     */
118
-    public function generate_reg_form()
119
-    {
120
-        $this->_print_copy_info = false;
121
-        $primary_registrant     = null;
122
-        // autoload Line_Item_Display classes
123
-        EEH_Autoloader::register_line_item_display_autoloaders();
124
-        $Line_Item_Display = new EE_Line_Item_Display();
125
-        // calculate taxes
126
-        $Line_Item_Display->display_line_item(
127
-            $this->checkout->cart->get_grand_total(),
128
-            array('set_tax_rate' => true)
129
-        );
130
-        /** @var $subsections EE_Form_Section_Proper[] */
131
-        $subsections   = array(
132
-            'default_hidden_inputs' => $this->reg_step_hidden_inputs(),
133
-        );
134
-        $template_args = array(
135
-            'revisit'       => $this->checkout->revisit,
136
-            'registrations' => array(),
137
-            'ticket_count'  => array(),
138
-        );
139
-        // grab the saved registrations from the transaction
140
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
141
-        if ($registrations) {
142
-            foreach ($registrations as $registration) {
143
-                // can this registration be processed during this visit ?
144
-                if ($registration instanceof EE_Registration
145
-                    && $this->checkout->visit_allows_processing_of_this_registration($registration)
146
-                ) {
147
-                    $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration);
148
-                    if (! $this->checkout->admin_request) {
149
-                        $template_args['registrations'][$registration->reg_url_link()]    = $registration;
150
-                        $template_args['ticket_count'][$registration->ticket()->ID()]     = isset(
151
-                            $template_args['ticket_count'][$registration->ticket()->ID()]
152
-                        )
153
-                            ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1
154
-                            : 1;
155
-                        $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
156
-                            $this->checkout->cart->get_grand_total(),
157
-                            'Ticket',
158
-                            array($registration->ticket()->ID())
159
-                        );
160
-                        $ticket_line_item = is_array($ticket_line_item)
161
-                            ? reset($ticket_line_item)
162
-                            : $ticket_line_item;
163
-                        $template_args['ticket_line_item'][$registration->ticket()->ID()] =
164
-                            $Line_Item_Display->display_line_item($ticket_line_item);
165
-                    }
166
-                    if ($registration->is_primary_registrant()) {
167
-                        $primary_registrant = $registration->reg_url_link();
168
-                    }
169
-                }
170
-            }
171
-            // print_copy_info ?
172
-            if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) {
173
-                // TODO: add admin option for toggling copy attendee info,
174
-                // then use that value to change $this->_print_copy_info
175
-                $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info
176
-                    ? $this->_copy_attendee_info_form()
177
-                    : $this->_auto_copy_attendee_info();
178
-                // generate hidden input
179
-                if (isset($subsections[$primary_registrant])
180
-                    && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper
181
-                ) {
182
-                    $subsections[$primary_registrant]->add_subsections(
183
-                        $copy_options,
184
-                        'primary_registrant',
185
-                        false
186
-                    );
187
-                }
188
-            }
189
-        }
190
-
191
-        return new EE_Form_Section_Proper(
192
-            array(
193
-                'name'            => $this->reg_form_name(),
194
-                'html_id'         => $this->reg_form_name(),
195
-                'subsections'     => $subsections,
196
-                'layout_strategy' => $this->checkout->admin_request ?
197
-                    new EE_Div_Per_Section_Layout() :
198
-                    new EE_Template_Layout(
199
-                        array(
200
-                            'layout_template_file' => $this->_template, // layout_template
201
-                            'template_args'        => $template_args,
202
-                        )
203
-                    ),
204
-            )
205
-        );
206
-    }
207
-
208
-
209
-    /**
210
-     * @param EE_Registration $registration
211
-     * @return EE_Form_Section_Base
212
-     * @throws EE_Error
213
-     * @throws InvalidArgumentException
214
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
215
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
216
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
217
-     */
218
-    private function _registrations_reg_form(EE_Registration $registration)
219
-    {
220
-        static $attendee_nmbr = 1;
221
-        $form_args = array();
222
-        // verify that registration has valid event
223
-        if ($registration->event() instanceof EE_Event) {
224
-            $question_groups = $registration->event()->question_groups(
225
-                apply_filters(
226
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters',
227
-                    array(
228
-                        array(
229
-                            'Event.EVT_ID'                     => $registration->event()->ID(),
230
-                            'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
231
-                        ),
232
-                        'order_by' => array('QSG_order' => 'ASC'),
233
-                    ),
234
-                    $registration,
235
-                    $this
236
-                )
237
-            );
238
-            if ($question_groups) {
239
-                // array of params to pass to parent constructor
240
-                $form_args = array(
241
-                    'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
242
-                    'html_class'      => 'ee-reg-form-attendee-dv',
243
-                    'html_style'      => $this->checkout->admin_request
244
-                        ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
245
-                        : '',
246
-                    'subsections'     => array(),
247
-                    'layout_strategy' => new EE_Fieldset_Section_Layout(
248
-                        array(
249
-                            'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text',
250
-                            'legend_text'  => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr),
251
-                        )
252
-                    ),
253
-                );
254
-                foreach ($question_groups as $question_group) {
255
-                    if ($question_group instanceof EE_Question_Group) {
256
-                        $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form(
257
-                            $registration,
258
-                            $question_group
259
-                        );
260
-                    }
261
-                }
262
-                // add hidden input
263
-                $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input(
264
-                    $registration
265
-                );
266
-                // if we have question groups for additional attendees, then display the copy options
267
-                $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info;
268
-                if ($registration->is_primary_registrant()) {
269
-                    // generate hidden input
270
-                    $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs(
271
-                        $registration
272
-                    );
273
-                }
274
-            }
275
-        }
276
-        $attendee_nmbr++;
277
-        return ! empty($form_args) ? new EE_Form_Section_Proper($form_args) : new EE_Form_Section_HTML();
278
-    }
279
-
280
-
281
-    /**
282
-     * _additional_attendee_reg_info_input
283
-     *
284
-     * @access public
285
-     * @param EE_Registration $registration
286
-     * @param bool            $additional_attendee_reg_info
287
-     * @return    EE_Form_Input_Base
288
-     * @throws \EE_Error
289
-     */
290
-    private function _additional_attendee_reg_info_input(
291
-        EE_Registration $registration,
292
-        $additional_attendee_reg_info = true
293
-    ) {
294
-        // generate hidden input
295
-        return new EE_Hidden_Input(
296
-            array(
297
-                'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
298
-                'default' => $additional_attendee_reg_info,
299
-            )
300
-        );
301
-    }
302
-
303
-
304
-    /**
305
-     * @param EE_Registration   $registration
306
-     * @param EE_Question_Group $question_group
307
-     * @return EE_Form_Section_Proper
308
-     * @throws EE_Error
309
-     * @throws InvalidArgumentException
310
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
311
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
312
-     */
313
-    private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group)
314
-    {
315
-        // array of params to pass to parent constructor
316
-        $form_args = array(
317
-            'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier(),
318
-            'html_class'      => $this->checkout->admin_request
319
-                ? 'form-table ee-reg-form-qstn-grp-dv'
320
-                : 'ee-reg-form-qstn-grp-dv',
321
-            'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-lbl',
322
-            'subsections'     => array(
323
-                'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group),
324
-            ),
325
-            'layout_strategy' => $this->checkout->admin_request
326
-                ? new EE_Admin_Two_Column_Layout()
327
-                : new EE_Div_Per_Section_Layout(),
328
-        );
329
-        // where params
330
-        $query_params = array('QST_deleted' => 0);
331
-        // don't load admin only questions on the frontend
332
-        if (! $this->checkout->admin_request) {
333
-            $query_params['QST_admin_only'] = array('!=', true);
334
-        }
335
-        $questions = $question_group->get_many_related(
336
-            'Question',
337
-            apply_filters(
338
-                'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params',
339
-                array(
340
-                    $query_params,
341
-                    'order_by' => array(
342
-                        'Question_Group_Question.QGQ_order' => 'ASC',
343
-                    ),
344
-                ),
345
-                $question_group,
346
-                $registration,
347
-                $this
348
-            )
349
-        );
350
-        // filter for additional content before questions
351
-        $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML(
352
-            apply_filters(
353
-                'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
354
-                '',
355
-                $registration,
356
-                $question_group,
357
-                $this
358
-            )
359
-        );
360
-        // loop thru questions
361
-        foreach ($questions as $question) {
362
-            if ($question instanceof EE_Question) {
363
-                $identifier                            = $question->is_system_question()
364
-                    ? $question->system_ID()
365
-                    : $question->ID();
366
-                $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question);
367
-            }
368
-        }
369
-        $form_args['subsections'] = apply_filters(
370
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array',
371
-            $form_args['subsections'],
372
-            $registration,
373
-            $question_group,
374
-            $this
375
-        );
376
-        // filter for additional content after questions
377
-        $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML(
378
-            apply_filters(
379
-                'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
380
-                '',
381
-                $registration,
382
-                $question_group,
383
-                $this
384
-            )
385
-        );
20
+	/**
21
+	 * @type bool $_print_copy_info
22
+	 */
23
+	private $_print_copy_info = false;
24
+
25
+	/**
26
+	 * @type array $_attendee_data
27
+	 */
28
+	private $_attendee_data = array();
29
+
30
+	/**
31
+	 * @type array $_required_questions
32
+	 */
33
+	private $_required_questions = array();
34
+
35
+	/**
36
+	 * @type array $_registration_answers
37
+	 */
38
+	private $_registration_answers = array();
39
+
40
+
41
+	/**
42
+	 *    class constructor
43
+	 *
44
+	 * @access    public
45
+	 * @param    EE_Checkout $checkout
46
+	 */
47
+	public function __construct(EE_Checkout $checkout)
48
+	{
49
+		$this->_slug     = 'attendee_information';
50
+		$this->_name     = esc_html__('Attendee Information', 'event_espresso');
51
+		$this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php';
52
+		$this->checkout  = $checkout;
53
+		$this->_reset_success_message();
54
+		$this->set_instructions(
55
+			esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso')
56
+		);
57
+	}
58
+
59
+
60
+	public function translate_js_strings()
61
+	{
62
+		EE_Registry::$i18n_js_strings['required_field']            = esc_html__(
63
+			' is a required question.',
64
+			'event_espresso'
65
+		);
66
+		EE_Registry::$i18n_js_strings['required_multi_field']      = esc_html__(
67
+			' is a required question. Please enter a value for at least one of the options.',
68
+			'event_espresso'
69
+		);
70
+		EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__(
71
+			'Please answer all required questions correctly before proceeding.',
72
+			'event_espresso'
73
+		);
74
+		EE_Registry::$i18n_js_strings['attendee_info_copied']      = sprintf(
75
+			esc_html__(
76
+				'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
77
+				'event_espresso'
78
+			),
79
+			'<br/>'
80
+		);
81
+		EE_Registry::$i18n_js_strings['attendee_info_copy_error']  = esc_html__(
82
+			'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
83
+			'event_espresso'
84
+		);
85
+		EE_Registry::$i18n_js_strings['enter_valid_email']         = esc_html__(
86
+			'You must enter a valid email address.',
87
+			'event_espresso'
88
+		);
89
+		EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__(
90
+			'You must enter a valid email address and answer all other required questions before you can proceed.',
91
+			'event_espresso'
92
+		);
93
+	}
94
+
95
+
96
+	public function enqueue_styles_and_scripts()
97
+	{
98
+	}
99
+
100
+
101
+	/**
102
+	 * @return boolean
103
+	 */
104
+	public function initialize_reg_step()
105
+	{
106
+		return true;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @return EE_Form_Section_Proper
112
+	 * @throws EE_Error
113
+	 * @throws InvalidArgumentException
114
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
115
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
116
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
117
+	 */
118
+	public function generate_reg_form()
119
+	{
120
+		$this->_print_copy_info = false;
121
+		$primary_registrant     = null;
122
+		// autoload Line_Item_Display classes
123
+		EEH_Autoloader::register_line_item_display_autoloaders();
124
+		$Line_Item_Display = new EE_Line_Item_Display();
125
+		// calculate taxes
126
+		$Line_Item_Display->display_line_item(
127
+			$this->checkout->cart->get_grand_total(),
128
+			array('set_tax_rate' => true)
129
+		);
130
+		/** @var $subsections EE_Form_Section_Proper[] */
131
+		$subsections   = array(
132
+			'default_hidden_inputs' => $this->reg_step_hidden_inputs(),
133
+		);
134
+		$template_args = array(
135
+			'revisit'       => $this->checkout->revisit,
136
+			'registrations' => array(),
137
+			'ticket_count'  => array(),
138
+		);
139
+		// grab the saved registrations from the transaction
140
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
141
+		if ($registrations) {
142
+			foreach ($registrations as $registration) {
143
+				// can this registration be processed during this visit ?
144
+				if ($registration instanceof EE_Registration
145
+					&& $this->checkout->visit_allows_processing_of_this_registration($registration)
146
+				) {
147
+					$subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration);
148
+					if (! $this->checkout->admin_request) {
149
+						$template_args['registrations'][$registration->reg_url_link()]    = $registration;
150
+						$template_args['ticket_count'][$registration->ticket()->ID()]     = isset(
151
+							$template_args['ticket_count'][$registration->ticket()->ID()]
152
+						)
153
+							? $template_args['ticket_count'][$registration->ticket()->ID()] + 1
154
+							: 1;
155
+						$ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
156
+							$this->checkout->cart->get_grand_total(),
157
+							'Ticket',
158
+							array($registration->ticket()->ID())
159
+						);
160
+						$ticket_line_item = is_array($ticket_line_item)
161
+							? reset($ticket_line_item)
162
+							: $ticket_line_item;
163
+						$template_args['ticket_line_item'][$registration->ticket()->ID()] =
164
+							$Line_Item_Display->display_line_item($ticket_line_item);
165
+					}
166
+					if ($registration->is_primary_registrant()) {
167
+						$primary_registrant = $registration->reg_url_link();
168
+					}
169
+				}
170
+			}
171
+			// print_copy_info ?
172
+			if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) {
173
+				// TODO: add admin option for toggling copy attendee info,
174
+				// then use that value to change $this->_print_copy_info
175
+				$copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info
176
+					? $this->_copy_attendee_info_form()
177
+					: $this->_auto_copy_attendee_info();
178
+				// generate hidden input
179
+				if (isset($subsections[$primary_registrant])
180
+					&& $subsections[$primary_registrant] instanceof EE_Form_Section_Proper
181
+				) {
182
+					$subsections[$primary_registrant]->add_subsections(
183
+						$copy_options,
184
+						'primary_registrant',
185
+						false
186
+					);
187
+				}
188
+			}
189
+		}
190
+
191
+		return new EE_Form_Section_Proper(
192
+			array(
193
+				'name'            => $this->reg_form_name(),
194
+				'html_id'         => $this->reg_form_name(),
195
+				'subsections'     => $subsections,
196
+				'layout_strategy' => $this->checkout->admin_request ?
197
+					new EE_Div_Per_Section_Layout() :
198
+					new EE_Template_Layout(
199
+						array(
200
+							'layout_template_file' => $this->_template, // layout_template
201
+							'template_args'        => $template_args,
202
+						)
203
+					),
204
+			)
205
+		);
206
+	}
207
+
208
+
209
+	/**
210
+	 * @param EE_Registration $registration
211
+	 * @return EE_Form_Section_Base
212
+	 * @throws EE_Error
213
+	 * @throws InvalidArgumentException
214
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
215
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
216
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
217
+	 */
218
+	private function _registrations_reg_form(EE_Registration $registration)
219
+	{
220
+		static $attendee_nmbr = 1;
221
+		$form_args = array();
222
+		// verify that registration has valid event
223
+		if ($registration->event() instanceof EE_Event) {
224
+			$question_groups = $registration->event()->question_groups(
225
+				apply_filters(
226
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters',
227
+					array(
228
+						array(
229
+							'Event.EVT_ID'                     => $registration->event()->ID(),
230
+							'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
231
+						),
232
+						'order_by' => array('QSG_order' => 'ASC'),
233
+					),
234
+					$registration,
235
+					$this
236
+				)
237
+			);
238
+			if ($question_groups) {
239
+				// array of params to pass to parent constructor
240
+				$form_args = array(
241
+					'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
242
+					'html_class'      => 'ee-reg-form-attendee-dv',
243
+					'html_style'      => $this->checkout->admin_request
244
+						? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
245
+						: '',
246
+					'subsections'     => array(),
247
+					'layout_strategy' => new EE_Fieldset_Section_Layout(
248
+						array(
249
+							'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text',
250
+							'legend_text'  => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr),
251
+						)
252
+					),
253
+				);
254
+				foreach ($question_groups as $question_group) {
255
+					if ($question_group instanceof EE_Question_Group) {
256
+						$form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form(
257
+							$registration,
258
+							$question_group
259
+						);
260
+					}
261
+				}
262
+				// add hidden input
263
+				$form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input(
264
+					$registration
265
+				);
266
+				// if we have question groups for additional attendees, then display the copy options
267
+				$this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info;
268
+				if ($registration->is_primary_registrant()) {
269
+					// generate hidden input
270
+					$form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs(
271
+						$registration
272
+					);
273
+				}
274
+			}
275
+		}
276
+		$attendee_nmbr++;
277
+		return ! empty($form_args) ? new EE_Form_Section_Proper($form_args) : new EE_Form_Section_HTML();
278
+	}
279
+
280
+
281
+	/**
282
+	 * _additional_attendee_reg_info_input
283
+	 *
284
+	 * @access public
285
+	 * @param EE_Registration $registration
286
+	 * @param bool            $additional_attendee_reg_info
287
+	 * @return    EE_Form_Input_Base
288
+	 * @throws \EE_Error
289
+	 */
290
+	private function _additional_attendee_reg_info_input(
291
+		EE_Registration $registration,
292
+		$additional_attendee_reg_info = true
293
+	) {
294
+		// generate hidden input
295
+		return new EE_Hidden_Input(
296
+			array(
297
+				'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
298
+				'default' => $additional_attendee_reg_info,
299
+			)
300
+		);
301
+	}
302
+
303
+
304
+	/**
305
+	 * @param EE_Registration   $registration
306
+	 * @param EE_Question_Group $question_group
307
+	 * @return EE_Form_Section_Proper
308
+	 * @throws EE_Error
309
+	 * @throws InvalidArgumentException
310
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
311
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
312
+	 */
313
+	private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group)
314
+	{
315
+		// array of params to pass to parent constructor
316
+		$form_args = array(
317
+			'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier(),
318
+			'html_class'      => $this->checkout->admin_request
319
+				? 'form-table ee-reg-form-qstn-grp-dv'
320
+				: 'ee-reg-form-qstn-grp-dv',
321
+			'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-lbl',
322
+			'subsections'     => array(
323
+				'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group),
324
+			),
325
+			'layout_strategy' => $this->checkout->admin_request
326
+				? new EE_Admin_Two_Column_Layout()
327
+				: new EE_Div_Per_Section_Layout(),
328
+		);
329
+		// where params
330
+		$query_params = array('QST_deleted' => 0);
331
+		// don't load admin only questions on the frontend
332
+		if (! $this->checkout->admin_request) {
333
+			$query_params['QST_admin_only'] = array('!=', true);
334
+		}
335
+		$questions = $question_group->get_many_related(
336
+			'Question',
337
+			apply_filters(
338
+				'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params',
339
+				array(
340
+					$query_params,
341
+					'order_by' => array(
342
+						'Question_Group_Question.QGQ_order' => 'ASC',
343
+					),
344
+				),
345
+				$question_group,
346
+				$registration,
347
+				$this
348
+			)
349
+		);
350
+		// filter for additional content before questions
351
+		$form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML(
352
+			apply_filters(
353
+				'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
354
+				'',
355
+				$registration,
356
+				$question_group,
357
+				$this
358
+			)
359
+		);
360
+		// loop thru questions
361
+		foreach ($questions as $question) {
362
+			if ($question instanceof EE_Question) {
363
+				$identifier                            = $question->is_system_question()
364
+					? $question->system_ID()
365
+					: $question->ID();
366
+				$form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question);
367
+			}
368
+		}
369
+		$form_args['subsections'] = apply_filters(
370
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array',
371
+			$form_args['subsections'],
372
+			$registration,
373
+			$question_group,
374
+			$this
375
+		);
376
+		// filter for additional content after questions
377
+		$form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML(
378
+			apply_filters(
379
+				'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
380
+				'',
381
+				$registration,
382
+				$question_group,
383
+				$this
384
+			)
385
+		);
386 386
 //		d( $form_args );
387
-        $question_group_reg_form = new EE_Form_Section_Proper($form_args);
388
-        return apply_filters(
389
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
390
-            $question_group_reg_form,
391
-            $registration,
392
-            $question_group,
393
-            $this
394
-        );
395
-    }
396
-
397
-
398
-    /**
399
-     * @access public
400
-     * @param EE_Question_Group $question_group
401
-     * @return    EE_Form_Section_HTML
402
-     */
403
-    private function _question_group_header(EE_Question_Group $question_group)
404
-    {
405
-        $html = '';
406
-        // group_name
407
-        if ($question_group->show_group_name() && $question_group->name() !== '') {
408
-            if ($this->checkout->admin_request) {
409
-                $html .= EEH_HTML::br();
410
-                $html .= EEH_HTML::h3(
411
-                    $question_group->name(),
412
-                    '',
413
-                    'ee-reg-form-qstn-grp-title title',
414
-                    'font-size: 1.3em; padding-left:0;'
415
-                );
416
-            } else {
417
-                $html .= EEH_HTML::h4(
418
-                    $question_group->name(),
419
-                    '',
420
-                    'ee-reg-form-qstn-grp-title section-title'
421
-                );
422
-            }
423
-        }
424
-        // group_desc
425
-        if ($question_group->show_group_desc() && $question_group->desc() !== '') {
426
-            $html .= EEH_HTML::p(
427
-                $question_group->desc(),
428
-                '',
429
-                $this->checkout->admin_request
430
-                    ? 'ee-reg-form-qstn-grp-desc-pg'
431
-                    : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text'
432
-            );
433
-        }
434
-        return new EE_Form_Section_HTML($html);
435
-    }
436
-
437
-
438
-    /**
439
-     * @access public
440
-     * @return    EE_Form_Section_Proper
441
-     * @throws \EE_Error
442
-     */
443
-    private function _copy_attendee_info_form()
444
-    {
445
-        // array of params to pass to parent constructor
446
-        return new EE_Form_Section_Proper(
447
-            array(
448
-                'subsections'     => $this->_copy_attendee_info_inputs(),
449
-                'layout_strategy' => new EE_Template_Layout(
450
-                    array(
451
-                        'layout_template_file'     => SPCO_REG_STEPS_PATH
452
-                                                      . $this->_slug
453
-                                                      . DS
454
-                                                      . 'copy_attendee_info.template.php',
455
-                        'begin_template_file'      => null,
456
-                        'input_template_file'      => null,
457
-                        'subsection_template_file' => null,
458
-                        'end_template_file'        => null,
459
-                    )
460
-                ),
461
-            )
462
-        );
463
-    }
464
-
465
-
466
-    /**
467
-     * _auto_copy_attendee_info
468
-     *
469
-     * @access public
470
-     * @return EE_Form_Section_HTML
471
-     */
472
-    private function _auto_copy_attendee_info()
473
-    {
474
-        return new EE_Form_Section_HTML(
475
-            EEH_Template::locate_template(
476
-                SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php',
477
-                apply_filters(
478
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
479
-                    array()
480
-                ),
481
-                true,
482
-                true
483
-            )
484
-        );
485
-    }
486
-
487
-
488
-    /**
489
-     * _copy_attendee_info_inputs
490
-     *
491
-     * @access public
492
-     * @return array
493
-     * @throws \EE_Error
494
-     */
495
-    private function _copy_attendee_info_inputs()
496
-    {
497
-        $copy_attendee_info_inputs = array();
498
-        $prev_ticket               = null;
499
-        // grab the saved registrations from the transaction
500
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
501
-        foreach ($registrations as $registration) {
502
-            // for all  attendees other than the primary attendee
503
-            if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) {
504
-                // if this is a new ticket OR if this is the very first additional attendee after the primary attendee
505
-                if ($registration->ticket()->ID() !== $prev_ticket) {
506
-                    $item_name = $registration->ticket()->name();
507
-                    $item_name .= $registration->ticket()->description() !== ''
508
-                        ? ' - ' . $registration->ticket()->description()
509
-                        : '';
510
-                    $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']'] =
511
-                        new EE_Form_Section_HTML(
512
-                            '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>'
513
-                        );
514
-                    $prev_ticket = $registration->ticket()->ID();
515
-                }
516
-
517
-                $copy_attendee_info_inputs['spco_copy_attendee_chk[' . $registration->ID() . ']'] =
518
-                    new EE_Checkbox_Multi_Input(
519
-                        array(
520
-                            $registration->ID() => sprintf(
521
-                                esc_html__('Attendee #%s', 'event_espresso'),
522
-                                $registration->count()
523
-                            ),
524
-                        ),
525
-                        array(
526
-                            'html_id'                 => 'spco-copy-attendee-chk-' . $registration->reg_url_link(),
527
-                            'html_class'              => 'spco-copy-attendee-chk ee-do-not-validate',
528
-                            'display_html_label_text' => false,
529
-                        )
530
-                    );
531
-            }
532
-        }
533
-        return $copy_attendee_info_inputs;
534
-    }
535
-
536
-
537
-    /**
538
-     * _additional_primary_registrant_inputs
539
-     *
540
-     * @access public
541
-     * @param EE_Registration $registration
542
-     * @return    EE_Form_Input_Base
543
-     * @throws \EE_Error
544
-     */
545
-    private function _additional_primary_registrant_inputs(EE_Registration $registration)
546
-    {
547
-        // generate hidden input
548
-        return new EE_Hidden_Input(
549
-            array(
550
-                'html_id' => 'primary_registrant',
551
-                'default' => $registration->reg_url_link(),
552
-            )
553
-        );
554
-    }
555
-
556
-
557
-    /**
558
-     * @access public
559
-     * @param EE_Registration $registration
560
-     * @param EE_Question     $question
561
-     * @return EE_Form_Input_Base
562
-     * @throws EE_Error
563
-     * @throws InvalidArgumentException
564
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
565
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
566
-     */
567
-    public function reg_form_question(EE_Registration $registration, EE_Question $question)
568
-    {
569
-
570
-        // if this question was for an attendee detail, then check for that answer
571
-        $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value(
572
-            $registration,
573
-            $question->system_ID()
574
-        );
575
-        $answer       = $answer_value === null
576
-            ? EEM_Answer::instance()->get_one(
577
-                array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
578
-            )
579
-            : null;
580
-        // if NOT returning to edit an existing registration
581
-        // OR if this question is for an attendee property
582
-        // OR we still don't have an EE_Answer object
583
-        if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
584
-            // create an EE_Answer object for storing everything in
585
-            $answer = EE_Answer::new_instance(array(
586
-                'QST_ID' => $question->ID(),
587
-                'REG_ID' => $registration->ID(),
588
-            ));
589
-        }
590
-        // verify instance
591
-        if ($answer instanceof EE_Answer) {
592
-            if (! empty($answer_value)) {
593
-                $answer->set('ANS_value', $answer_value);
594
-            }
595
-            $answer->cache('Question', $question);
596
-            //remember system ID had a bug where sometimes it could be null
597
-            $answer_cache_id = $question->is_system_question()
598
-                ? $question->system_ID() . '-' . $registration->reg_url_link()
599
-                : $question->ID() . '-' . $registration->reg_url_link();
600
-            $registration->cache('Answer', $answer, $answer_cache_id);
601
-        }
602
-        return $this->_generate_question_input($registration, $question, $answer);
603
-    }
604
-
605
-
606
-    /**
607
-     * @param EE_Registration $registration
608
-     * @param EE_Question     $question
609
-     * @param                 mixed EE_Answer|NULL      $answer
610
-     * @return EE_Form_Input_Base
611
-     * @throws \EE_Error
612
-     */
613
-    private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer)
614
-    {
615
-        $identifier                             = $question->is_system_question()
616
-            ? $question->system_ID()
617
-            : $question->ID();
618
-        $this->_required_questions[$identifier] = $question->required() ? true : false;
619
-        add_filter(
620
-            'FHEE__EE_Question__generate_form_input__country_options',
621
-            array($this, 'use_cached_countries_for_form_input'),
622
-            10,
623
-            4
624
-        );
625
-        add_filter(
626
-            'FHEE__EE_Question__generate_form_input__state_options',
627
-            array($this, 'use_cached_states_for_form_input'),
628
-            10,
629
-            4
630
-        );
631
-        $input_constructor_args                  = array(
632
-            'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
633
-            'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
634
-            'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
635
-            'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
636
-            'html_label_class' => 'ee-reg-qstn',
637
-        );
638
-        $input_constructor_args['html_label_id'] .= '-lbl';
639
-        if ($answer instanceof EE_Answer && $answer->ID()) {
640
-            $input_constructor_args['html_name']     .= '[' . $answer->ID() . ']';
641
-            $input_constructor_args['html_id']       .= '-' . $answer->ID();
642
-            $input_constructor_args['html_label_id'] .= '-' . $answer->ID();
643
-        }
644
-        $form_input = $question->generate_form_input(
645
-            $registration,
646
-            $answer,
647
-            $input_constructor_args
648
-        );
649
-        remove_filter(
650
-            'FHEE__EE_Question__generate_form_input__country_options',
651
-            array($this, 'use_cached_countries_for_form_input')
652
-        );
653
-        remove_filter(
654
-            'FHEE__EE_Question__generate_form_input__state_options',
655
-            array($this, 'use_cached_states_for_form_input')
656
-        );
657
-        return $form_input;
658
-    }
659
-
660
-
661
-    /**
662
-     * Gets the list of countries for the form input
663
-     *
664
-     * @param array|null       $countries_list
665
-     * @param \EE_Question     $question
666
-     * @param \EE_Registration $registration
667
-     * @param \EE_Answer       $answer
668
-     * @return array 2d keys are country IDs, values are their names
669
-     * @throws EE_Error
670
-     * @throws InvalidArgumentException
671
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
672
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
673
-     */
674
-    public function use_cached_countries_for_form_input(
675
-        $countries_list,
676
-        \EE_Question $question = null,
677
-        \EE_Registration $registration = null,
678
-        \EE_Answer $answer = null
679
-    ) {
680
-        $country_options = array('' => '');
681
-        // get possibly cached list of countries
682
-        $countries = $this->checkout->action === 'process_reg_step'
683
-            ? EEM_Country::instance()->get_all_countries()
684
-            : EEM_Country::instance()->get_all_active_countries();
685
-        if (! empty($countries)) {
686
-            foreach ($countries as $country) {
687
-                if ($country instanceof EE_Country) {
688
-                    $country_options[$country->ID()] = $country->name();
689
-                }
690
-            }
691
-        }
692
-        if ($question instanceof EE_Question
693
-            && $registration instanceof EE_Registration) {
694
-            $answer = EEM_Answer::instance()->get_one(
695
-                array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
696
-            );
697
-        } else {
698
-            $answer = EE_Answer::new_instance();
699
-        }
700
-        $country_options = apply_filters(
701
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
702
-            $country_options,
703
-            $this,
704
-            $registration,
705
-            $question,
706
-            $answer
707
-        );
708
-        return $country_options;
709
-    }
710
-
711
-
712
-    /**
713
-     * Gets the list of states for the form input
714
-     *
715
-     * @param array|null       $states_list
716
-     * @param \EE_Question     $question
717
-     * @param \EE_Registration $registration
718
-     * @param \EE_Answer       $answer
719
-     * @return array 2d keys are state IDs, values are their names
720
-     * @throws EE_Error
721
-     * @throws InvalidArgumentException
722
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
723
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
724
-     */
725
-    public function use_cached_states_for_form_input(
726
-        $states_list,
727
-        \EE_Question $question = null,
728
-        \EE_Registration $registration = null,
729
-        \EE_Answer $answer = null
730
-    ) {
731
-        $state_options = array('' => array('' => ''));
732
-        $states        = $this->checkout->action === 'process_reg_step'
733
-            ? EEM_State::instance()->get_all_states()
734
-            : EEM_State::instance()->get_all_active_states();
735
-        if (! empty($states)) {
736
-            foreach ($states as $state) {
737
-                if ($state instanceof EE_State) {
738
-                    $state_options[$state->country()->name()][$state->ID()] = $state->name();
739
-                }
740
-            }
741
-        }
742
-        $state_options = apply_filters(
743
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
744
-            $state_options,
745
-            $this,
746
-            $registration,
747
-            $question,
748
-            $answer
749
-        );
750
-        return $state_options;
751
-    }
752
-
753
-
754
-
755
-
756
-
757
-
758
-    /********************************************************************************************************/
759
-    /****************************************  PROCESS REG STEP  ****************************************/
760
-    /********************************************************************************************************/
761
-    /**
762
-     * @return bool
763
-     * @throws EE_Error
764
-     * @throws InvalidArgumentException
765
-     * @throws ReflectionException
766
-     * @throws RuntimeException
767
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
768
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
769
-     */
770
-    public function process_reg_step()
771
-    {
772
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
773
-        // grab validated data from form
774
-        $valid_data = $this->checkout->current_step->valid_data();
775
-        // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
776
-        // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ );
777
-        // if we don't have any $valid_data then something went TERRIBLY WRONG !!!
778
-        if (empty($valid_data)) {
779
-            EE_Error::add_error(
780
-                esc_html__('No valid question responses were received.', 'event_espresso'),
781
-                __FILE__,
782
-                __FUNCTION__,
783
-                __LINE__
784
-            );
785
-            return false;
786
-        }
787
-        if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
788
-            EE_Error::add_error(
789
-                esc_html__(
790
-                    'A valid transaction could not be initiated for processing your registrations.',
791
-                    'event_espresso'
792
-                ),
793
-                __FILE__,
794
-                __FUNCTION__,
795
-                __LINE__
796
-            );
797
-            return false;
798
-        }
799
-        // get cached registrations
800
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
801
-        // verify we got the goods
802
-        if (empty($registrations)) {
803
-            //combine the old translated string with a new one, in order to not break translations
804
-            $error_message = esc_html__( 'Your form data could not be applied to any valid registrations.', 'event_espresso' )
805
-                             . sprintf(
806
-                                 esc_html__('%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.', 'event_espresso'),
807
-                                 '<a href="' . get_post_type_archive_link('espresso_events') . '" >',
808
-                                 '</a>',
809
-                                 '<br />'
810
-                             );
811
-            EE_Error::add_error(
812
-                $error_message,
813
-                __FILE__,
814
-                __FUNCTION__,
815
-                __LINE__
816
-            );
817
-            return false;
818
-        }
819
-        // extract attendee info from form data and save to model objects
820
-        $registrations_processed = $this->_process_registrations($registrations, $valid_data);
821
-        // if first pass thru SPCO,
822
-        // then let's check processed registrations against the total number of tickets in the cart
823
-        if ($registrations_processed === false) {
824
-            // but return immediately if the previous step exited early due to errors
825
-            return false;
826
-        } elseif (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
827
-            // generate a correctly translated string for all possible singular/plural combinations
828
-            if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
829
-                $error_msg = sprintf(
830
-                    esc_html__(
831
-                        'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
832
-                        'event_espresso'
833
-                    ),
834
-                    $this->checkout->total_ticket_count,
835
-                    $registrations_processed
836
-                );
837
-            } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
838
-                $error_msg = sprintf(
839
-                    esc_html__(
840
-                        'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
841
-                        'event_espresso'
842
-                    ),
843
-                    $this->checkout->total_ticket_count,
844
-                    $registrations_processed
845
-                );
846
-            } else {
847
-                $error_msg = sprintf(
848
-                    esc_html__(
849
-                        'There was a total of %1$d tickets in the Event Queue, but %2$ds registrations were processed',
850
-                        'event_espresso'
851
-                    ),
852
-                    $this->checkout->total_ticket_count,
853
-                    $registrations_processed
854
-                );
855
-            }
856
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
857
-            return false;
858
-        }
859
-        // mark this reg step as completed
860
-        $this->set_completed();
861
-        $this->_set_success_message(
862
-            esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso')
863
-        );
864
-        //do action in case a plugin wants to do something with the data submitted in step 1.
865
-        //passes EE_Single_Page_Checkout, and it's posted data
866
-        do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
867
-        return true;
868
-    }
869
-
870
-
871
-    /**
872
-     *    _process_registrations
873
-     *
874
-     * @param EE_Registration[] $registrations
875
-     * @param array             $valid_data
876
-     * @return bool|int
877
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
878
-     * @throws EE_Error
879
-     * @throws InvalidArgumentException
880
-     * @throws ReflectionException
881
-     * @throws RuntimeException
882
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
883
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
884
-     */
885
-    private function _process_registrations($registrations = array(), $valid_data = array())
886
-    {
887
-        // load resources and set some defaults
888
-        EE_Registry::instance()->load_model('Attendee');
889
-        // holder for primary registrant attendee object
890
-        $this->checkout->primary_attendee_obj = null;
891
-        // array for tracking reg form data for the primary registrant
892
-        $primary_registrant = array(
893
-            'line_item_id' => null,
894
-        );
895
-        $copy_primary       = false;
896
-        // reg form sections that do not contain inputs
897
-        $non_input_form_sections = array(
898
-            'primary_registrant',
899
-            'additional_attendee_reg_info',
900
-            'spco_copy_attendee_chk',
901
-        );
902
-        // attendee counter
903
-        $att_nmbr = 0;
904
-        // grab the saved registrations from the transaction
905
-        foreach ($registrations as $registration) {
906
-            // verify EE_Registration object
907
-            if (! $registration instanceof EE_Registration) {
908
-                EE_Error::add_error(
909
-                    esc_html__(
910
-                        'An invalid Registration object was discovered when attempting to process your registration information.',
911
-                        'event_espresso'
912
-                    ),
913
-                    __FILE__,
914
-                    __FUNCTION__,
915
-                    __LINE__
916
-                );
917
-                return false;
918
-            }
919
-            /** @var string $reg_url_link */
920
-            $reg_url_link = $registration->reg_url_link();
921
-            // reg_url_link exists ?
922
-            if (! empty($reg_url_link)) {
923
-                // should this registration be processed during this visit ?
924
-                if ($this->checkout->visit_allows_processing_of_this_registration($registration)) {
925
-                    // if NOT revisiting, then let's save the registration now,
926
-                    // so that we have a REG_ID to use when generating other objects
927
-                    if (! $this->checkout->revisit) {
928
-                        $registration->save();
929
-                    }
930
-                    /**
931
-                     * This allows plugins to trigger a fail on processing of a
932
-                     * registration for any conditions they may have for it to pass.
933
-                     *
934
-                     * @var bool   if true is returned by the plugin then the
935
-                     *            registration processing is halted.
936
-                     */
937
-                    if (apply_filters(
938
-                        'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
939
-                        false,
940
-                        $att_nmbr,
941
-                        $registration,
942
-                        $registrations,
943
-                        $valid_data,
944
-                        $this
945
-                    )) {
946
-                        return false;
947
-                    }
948
-
949
-                    // Houston, we have a registration!
950
-                    $att_nmbr++;
951
-                    $this->_attendee_data[$reg_url_link] = array();
952
-                    // grab any existing related answer objects
953
-                    $this->_registration_answers = $registration->answers();
954
-                    // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] );
955
-                    if (isset($valid_data[$reg_url_link])) {
956
-                        // do we need to copy basic info from primary attendee ?
957
-                        $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info'])
958
-                                        && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0
959
-                            ? true
960
-                            : false;
961
-                        // filter form input data for this registration
962
-                        $valid_data[$reg_url_link] = (array)apply_filters(
963
-                            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
964
-                            $valid_data[$reg_url_link]
965
-                        );
966
-                        if (isset($valid_data['primary_attendee'])) {
967
-                            $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee'])
968
-                                ? $valid_data['primary_attendee']
969
-                                : false;
970
-                            unset($valid_data['primary_attendee']);
971
-                        }
972
-                        // now loop through our array of valid post data && process attendee reg forms
973
-                        foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) {
974
-                            if (! in_array($form_section, $non_input_form_sections)) {
975
-                                foreach ($form_inputs as $form_input => $input_value) {
976
-                                    // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ );
977
-                                    // check for critical inputs
978
-                                    if (! $this->_verify_critical_attendee_details_are_set_and_validate_email(
979
-                                        $form_input,
980
-                                        $input_value
981
-                                    )
982
-                                    ) {
983
-                                        return false;
984
-                                    }
985
-                                    // store a bit of data about the primary attendee
986
-                                    if ($att_nmbr === 1
987
-                                        && ! empty($input_value)
988
-                                        && $reg_url_link === $primary_registrant['line_item_id']
989
-                                    ) {
990
-                                        $primary_registrant[$form_input] = $input_value;
991
-                                    } elseif ($copy_primary
992
-                                        && $input_value === null
993
-                                        && isset($primary_registrant[$form_input])
994
-                                    ) {
995
-                                        $input_value = $primary_registrant[$form_input];
996
-                                    }
997
-                                    // now attempt to save the input data
998
-                                    if (! $this->_save_registration_form_input(
999
-                                        $registration,
1000
-                                        $form_input,
1001
-                                        $input_value
1002
-                                    )
1003
-                                    ) {
1004
-                                        EE_Error::add_error(
1005
-                                            sprintf(
1006
-                                                esc_html__(
1007
-                                                    'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"',
1008
-                                                    'event_espresso'
1009
-                                                ),
1010
-                                                $form_input,
1011
-                                                $input_value
1012
-                                            ),
1013
-                                            __FILE__,
1014
-                                            __FUNCTION__,
1015
-                                            __LINE__
1016
-                                        );
1017
-                                        return false;
1018
-                                    }
1019
-                                }
1020
-                            }
1021
-                        }  // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs )
1022
-                    }
1023
-                    //EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ );
1024
-                    // this registration does not require additional attendee information ?
1025
-                    if ($copy_primary
1026
-                        && $att_nmbr > 1
1027
-                        && $this->checkout->primary_attendee_obj instanceof EE_Attendee
1028
-                    ) {
1029
-                        // just copy the primary registrant
1030
-                        $attendee = $this->checkout->primary_attendee_obj;
1031
-                    } else {
1032
-                        // ensure critical details are set for additional attendees
1033
-                        $this->_attendee_data[$reg_url_link] = $att_nmbr > 1
1034
-                            ? $this->_copy_critical_attendee_details_from_primary_registrant(
1035
-                                $this->_attendee_data[$reg_url_link]
1036
-                            )
1037
-                            : $this->_attendee_data[$reg_url_link];
1038
-                        // execute create attendee command (which may return an existing attendee)
1039
-                        $attendee = EE_Registry::instance()->BUS->execute(
1040
-                            new CreateAttendeeCommand(
1041
-                                $this->_attendee_data[$reg_url_link],
1042
-                                $registration
1043
-                            )
1044
-                        );
1045
-                        // who's #1 ?
1046
-                        if ($att_nmbr === 1) {
1047
-                            $this->checkout->primary_attendee_obj = $attendee;
1048
-                        }
1049
-                    }
1050
-                    // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ );
1051
-                    // add relation to registration, set attendee ID, and cache attendee
1052
-                    $this->_associate_attendee_with_registration($registration, $attendee);
1053
-                    // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ );
1054
-                    if (! $registration->attendee() instanceof EE_Attendee) {
1055
-                        EE_Error::add_error(
1056
-                            sprintf(
1057
-                                esc_html__(
1058
-                                    'Registration %s has an invalid or missing Attendee object.',
1059
-                                    'event_espresso'
1060
-                                ),
1061
-                                $reg_url_link
1062
-                            ),
1063
-                            __FILE__,
1064
-                            __FUNCTION__,
1065
-                            __LINE__
1066
-                        );
1067
-                        return false;
1068
-                    }
1069
-                    /** @type EE_Registration_Processor $registration_processor */
1070
-                    $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1071
-                    // at this point, we should have enough details about the registrant to consider the registration
1072
-                    // NOT incomplete
1073
-                    $registration_processor->toggle_incomplete_registration_status_to_default(
1074
-                        $registration,
1075
-                        false,
1076
-                        new Context(
1077
-                            'spco_reg_step_attendee_information_process_registrations',
1078
-                            esc_html__(
1079
-                                'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.',
1080
-                                'event_espresso'
1081
-                            )
1082
-                        )
1083
-                    );
1084
-                    // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to
1085
-                    // abandoned
1086
-                    $this->checkout->transaction->toggle_failed_transaction_status();
1087
-                    // if we've gotten this far, then let's save what we have
1088
-                    $registration->save();
1089
-                    // add relation between TXN and registration
1090
-                    $this->_associate_registration_with_transaction($registration);
1091
-                }
1092
-            } else {
1093
-                EE_Error::add_error(
1094
-                    esc_html__(
1095
-                        'An invalid or missing line item ID was encountered while attempting to process the registration form.',
1096
-                        'event_espresso'
1097
-                    ),
1098
-                    __FILE__,
1099
-                    __FUNCTION__,
1100
-                    __LINE__
1101
-                );
1102
-                // remove malformed data
1103
-                unset($valid_data[$reg_url_link]);
1104
-                return false;
1105
-            }
1106
-
1107
-        } // end of foreach ( $this->checkout->transaction->registrations()  as $registration )
1108
-        return $att_nmbr;
1109
-    }
1110
-
1111
-
1112
-    /**
1113
-     *    _save_registration_form_input
1114
-     *
1115
-     * @param EE_Registration $registration
1116
-     * @param string          $form_input
1117
-     * @param string          $input_value
1118
-     * @return bool
1119
-     * @throws EE_Error
1120
-     * @throws InvalidArgumentException
1121
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1122
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1123
-     */
1124
-    private function _save_registration_form_input(
1125
-        EE_Registration $registration,
1126
-        $form_input = '',
1127
-        $input_value = ''
1128
-    ) {
1129
-        // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 );
1130
-        // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ );
1131
-        // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ );
1132
-        // allow for plugins to hook in and do their own processing of the form input.
1133
-        // For plugins to bypass normal processing here, they just need to return a boolean value.
1134
-        if (apply_filters(
1135
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
1136
-            false,
1137
-            $registration,
1138
-            $form_input,
1139
-            $input_value,
1140
-            $this
1141
-        )) {
1142
-            return true;
1143
-        }
1144
-        /*
387
+		$question_group_reg_form = new EE_Form_Section_Proper($form_args);
388
+		return apply_filters(
389
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
390
+			$question_group_reg_form,
391
+			$registration,
392
+			$question_group,
393
+			$this
394
+		);
395
+	}
396
+
397
+
398
+	/**
399
+	 * @access public
400
+	 * @param EE_Question_Group $question_group
401
+	 * @return    EE_Form_Section_HTML
402
+	 */
403
+	private function _question_group_header(EE_Question_Group $question_group)
404
+	{
405
+		$html = '';
406
+		// group_name
407
+		if ($question_group->show_group_name() && $question_group->name() !== '') {
408
+			if ($this->checkout->admin_request) {
409
+				$html .= EEH_HTML::br();
410
+				$html .= EEH_HTML::h3(
411
+					$question_group->name(),
412
+					'',
413
+					'ee-reg-form-qstn-grp-title title',
414
+					'font-size: 1.3em; padding-left:0;'
415
+				);
416
+			} else {
417
+				$html .= EEH_HTML::h4(
418
+					$question_group->name(),
419
+					'',
420
+					'ee-reg-form-qstn-grp-title section-title'
421
+				);
422
+			}
423
+		}
424
+		// group_desc
425
+		if ($question_group->show_group_desc() && $question_group->desc() !== '') {
426
+			$html .= EEH_HTML::p(
427
+				$question_group->desc(),
428
+				'',
429
+				$this->checkout->admin_request
430
+					? 'ee-reg-form-qstn-grp-desc-pg'
431
+					: 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text'
432
+			);
433
+		}
434
+		return new EE_Form_Section_HTML($html);
435
+	}
436
+
437
+
438
+	/**
439
+	 * @access public
440
+	 * @return    EE_Form_Section_Proper
441
+	 * @throws \EE_Error
442
+	 */
443
+	private function _copy_attendee_info_form()
444
+	{
445
+		// array of params to pass to parent constructor
446
+		return new EE_Form_Section_Proper(
447
+			array(
448
+				'subsections'     => $this->_copy_attendee_info_inputs(),
449
+				'layout_strategy' => new EE_Template_Layout(
450
+					array(
451
+						'layout_template_file'     => SPCO_REG_STEPS_PATH
452
+													  . $this->_slug
453
+													  . DS
454
+													  . 'copy_attendee_info.template.php',
455
+						'begin_template_file'      => null,
456
+						'input_template_file'      => null,
457
+						'subsection_template_file' => null,
458
+						'end_template_file'        => null,
459
+					)
460
+				),
461
+			)
462
+		);
463
+	}
464
+
465
+
466
+	/**
467
+	 * _auto_copy_attendee_info
468
+	 *
469
+	 * @access public
470
+	 * @return EE_Form_Section_HTML
471
+	 */
472
+	private function _auto_copy_attendee_info()
473
+	{
474
+		return new EE_Form_Section_HTML(
475
+			EEH_Template::locate_template(
476
+				SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php',
477
+				apply_filters(
478
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
479
+					array()
480
+				),
481
+				true,
482
+				true
483
+			)
484
+		);
485
+	}
486
+
487
+
488
+	/**
489
+	 * _copy_attendee_info_inputs
490
+	 *
491
+	 * @access public
492
+	 * @return array
493
+	 * @throws \EE_Error
494
+	 */
495
+	private function _copy_attendee_info_inputs()
496
+	{
497
+		$copy_attendee_info_inputs = array();
498
+		$prev_ticket               = null;
499
+		// grab the saved registrations from the transaction
500
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
501
+		foreach ($registrations as $registration) {
502
+			// for all  attendees other than the primary attendee
503
+			if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) {
504
+				// if this is a new ticket OR if this is the very first additional attendee after the primary attendee
505
+				if ($registration->ticket()->ID() !== $prev_ticket) {
506
+					$item_name = $registration->ticket()->name();
507
+					$item_name .= $registration->ticket()->description() !== ''
508
+						? ' - ' . $registration->ticket()->description()
509
+						: '';
510
+					$copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']'] =
511
+						new EE_Form_Section_HTML(
512
+							'<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>'
513
+						);
514
+					$prev_ticket = $registration->ticket()->ID();
515
+				}
516
+
517
+				$copy_attendee_info_inputs['spco_copy_attendee_chk[' . $registration->ID() . ']'] =
518
+					new EE_Checkbox_Multi_Input(
519
+						array(
520
+							$registration->ID() => sprintf(
521
+								esc_html__('Attendee #%s', 'event_espresso'),
522
+								$registration->count()
523
+							),
524
+						),
525
+						array(
526
+							'html_id'                 => 'spco-copy-attendee-chk-' . $registration->reg_url_link(),
527
+							'html_class'              => 'spco-copy-attendee-chk ee-do-not-validate',
528
+							'display_html_label_text' => false,
529
+						)
530
+					);
531
+			}
532
+		}
533
+		return $copy_attendee_info_inputs;
534
+	}
535
+
536
+
537
+	/**
538
+	 * _additional_primary_registrant_inputs
539
+	 *
540
+	 * @access public
541
+	 * @param EE_Registration $registration
542
+	 * @return    EE_Form_Input_Base
543
+	 * @throws \EE_Error
544
+	 */
545
+	private function _additional_primary_registrant_inputs(EE_Registration $registration)
546
+	{
547
+		// generate hidden input
548
+		return new EE_Hidden_Input(
549
+			array(
550
+				'html_id' => 'primary_registrant',
551
+				'default' => $registration->reg_url_link(),
552
+			)
553
+		);
554
+	}
555
+
556
+
557
+	/**
558
+	 * @access public
559
+	 * @param EE_Registration $registration
560
+	 * @param EE_Question     $question
561
+	 * @return EE_Form_Input_Base
562
+	 * @throws EE_Error
563
+	 * @throws InvalidArgumentException
564
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
565
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
566
+	 */
567
+	public function reg_form_question(EE_Registration $registration, EE_Question $question)
568
+	{
569
+
570
+		// if this question was for an attendee detail, then check for that answer
571
+		$answer_value = EEM_Answer::instance()->get_attendee_property_answer_value(
572
+			$registration,
573
+			$question->system_ID()
574
+		);
575
+		$answer       = $answer_value === null
576
+			? EEM_Answer::instance()->get_one(
577
+				array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
578
+			)
579
+			: null;
580
+		// if NOT returning to edit an existing registration
581
+		// OR if this question is for an attendee property
582
+		// OR we still don't have an EE_Answer object
583
+		if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
584
+			// create an EE_Answer object for storing everything in
585
+			$answer = EE_Answer::new_instance(array(
586
+				'QST_ID' => $question->ID(),
587
+				'REG_ID' => $registration->ID(),
588
+			));
589
+		}
590
+		// verify instance
591
+		if ($answer instanceof EE_Answer) {
592
+			if (! empty($answer_value)) {
593
+				$answer->set('ANS_value', $answer_value);
594
+			}
595
+			$answer->cache('Question', $question);
596
+			//remember system ID had a bug where sometimes it could be null
597
+			$answer_cache_id = $question->is_system_question()
598
+				? $question->system_ID() . '-' . $registration->reg_url_link()
599
+				: $question->ID() . '-' . $registration->reg_url_link();
600
+			$registration->cache('Answer', $answer, $answer_cache_id);
601
+		}
602
+		return $this->_generate_question_input($registration, $question, $answer);
603
+	}
604
+
605
+
606
+	/**
607
+	 * @param EE_Registration $registration
608
+	 * @param EE_Question     $question
609
+	 * @param                 mixed EE_Answer|NULL      $answer
610
+	 * @return EE_Form_Input_Base
611
+	 * @throws \EE_Error
612
+	 */
613
+	private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer)
614
+	{
615
+		$identifier                             = $question->is_system_question()
616
+			? $question->system_ID()
617
+			: $question->ID();
618
+		$this->_required_questions[$identifier] = $question->required() ? true : false;
619
+		add_filter(
620
+			'FHEE__EE_Question__generate_form_input__country_options',
621
+			array($this, 'use_cached_countries_for_form_input'),
622
+			10,
623
+			4
624
+		);
625
+		add_filter(
626
+			'FHEE__EE_Question__generate_form_input__state_options',
627
+			array($this, 'use_cached_states_for_form_input'),
628
+			10,
629
+			4
630
+		);
631
+		$input_constructor_args                  = array(
632
+			'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
633
+			'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
634
+			'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
635
+			'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
636
+			'html_label_class' => 'ee-reg-qstn',
637
+		);
638
+		$input_constructor_args['html_label_id'] .= '-lbl';
639
+		if ($answer instanceof EE_Answer && $answer->ID()) {
640
+			$input_constructor_args['html_name']     .= '[' . $answer->ID() . ']';
641
+			$input_constructor_args['html_id']       .= '-' . $answer->ID();
642
+			$input_constructor_args['html_label_id'] .= '-' . $answer->ID();
643
+		}
644
+		$form_input = $question->generate_form_input(
645
+			$registration,
646
+			$answer,
647
+			$input_constructor_args
648
+		);
649
+		remove_filter(
650
+			'FHEE__EE_Question__generate_form_input__country_options',
651
+			array($this, 'use_cached_countries_for_form_input')
652
+		);
653
+		remove_filter(
654
+			'FHEE__EE_Question__generate_form_input__state_options',
655
+			array($this, 'use_cached_states_for_form_input')
656
+		);
657
+		return $form_input;
658
+	}
659
+
660
+
661
+	/**
662
+	 * Gets the list of countries for the form input
663
+	 *
664
+	 * @param array|null       $countries_list
665
+	 * @param \EE_Question     $question
666
+	 * @param \EE_Registration $registration
667
+	 * @param \EE_Answer       $answer
668
+	 * @return array 2d keys are country IDs, values are their names
669
+	 * @throws EE_Error
670
+	 * @throws InvalidArgumentException
671
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
672
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
673
+	 */
674
+	public function use_cached_countries_for_form_input(
675
+		$countries_list,
676
+		\EE_Question $question = null,
677
+		\EE_Registration $registration = null,
678
+		\EE_Answer $answer = null
679
+	) {
680
+		$country_options = array('' => '');
681
+		// get possibly cached list of countries
682
+		$countries = $this->checkout->action === 'process_reg_step'
683
+			? EEM_Country::instance()->get_all_countries()
684
+			: EEM_Country::instance()->get_all_active_countries();
685
+		if (! empty($countries)) {
686
+			foreach ($countries as $country) {
687
+				if ($country instanceof EE_Country) {
688
+					$country_options[$country->ID()] = $country->name();
689
+				}
690
+			}
691
+		}
692
+		if ($question instanceof EE_Question
693
+			&& $registration instanceof EE_Registration) {
694
+			$answer = EEM_Answer::instance()->get_one(
695
+				array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
696
+			);
697
+		} else {
698
+			$answer = EE_Answer::new_instance();
699
+		}
700
+		$country_options = apply_filters(
701
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
702
+			$country_options,
703
+			$this,
704
+			$registration,
705
+			$question,
706
+			$answer
707
+		);
708
+		return $country_options;
709
+	}
710
+
711
+
712
+	/**
713
+	 * Gets the list of states for the form input
714
+	 *
715
+	 * @param array|null       $states_list
716
+	 * @param \EE_Question     $question
717
+	 * @param \EE_Registration $registration
718
+	 * @param \EE_Answer       $answer
719
+	 * @return array 2d keys are state IDs, values are their names
720
+	 * @throws EE_Error
721
+	 * @throws InvalidArgumentException
722
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
723
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
724
+	 */
725
+	public function use_cached_states_for_form_input(
726
+		$states_list,
727
+		\EE_Question $question = null,
728
+		\EE_Registration $registration = null,
729
+		\EE_Answer $answer = null
730
+	) {
731
+		$state_options = array('' => array('' => ''));
732
+		$states        = $this->checkout->action === 'process_reg_step'
733
+			? EEM_State::instance()->get_all_states()
734
+			: EEM_State::instance()->get_all_active_states();
735
+		if (! empty($states)) {
736
+			foreach ($states as $state) {
737
+				if ($state instanceof EE_State) {
738
+					$state_options[$state->country()->name()][$state->ID()] = $state->name();
739
+				}
740
+			}
741
+		}
742
+		$state_options = apply_filters(
743
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
744
+			$state_options,
745
+			$this,
746
+			$registration,
747
+			$question,
748
+			$answer
749
+		);
750
+		return $state_options;
751
+	}
752
+
753
+
754
+
755
+
756
+
757
+
758
+	/********************************************************************************************************/
759
+	/****************************************  PROCESS REG STEP  ****************************************/
760
+	/********************************************************************************************************/
761
+	/**
762
+	 * @return bool
763
+	 * @throws EE_Error
764
+	 * @throws InvalidArgumentException
765
+	 * @throws ReflectionException
766
+	 * @throws RuntimeException
767
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
768
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
769
+	 */
770
+	public function process_reg_step()
771
+	{
772
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
773
+		// grab validated data from form
774
+		$valid_data = $this->checkout->current_step->valid_data();
775
+		// EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
776
+		// EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ );
777
+		// if we don't have any $valid_data then something went TERRIBLY WRONG !!!
778
+		if (empty($valid_data)) {
779
+			EE_Error::add_error(
780
+				esc_html__('No valid question responses were received.', 'event_espresso'),
781
+				__FILE__,
782
+				__FUNCTION__,
783
+				__LINE__
784
+			);
785
+			return false;
786
+		}
787
+		if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
788
+			EE_Error::add_error(
789
+				esc_html__(
790
+					'A valid transaction could not be initiated for processing your registrations.',
791
+					'event_espresso'
792
+				),
793
+				__FILE__,
794
+				__FUNCTION__,
795
+				__LINE__
796
+			);
797
+			return false;
798
+		}
799
+		// get cached registrations
800
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
801
+		// verify we got the goods
802
+		if (empty($registrations)) {
803
+			//combine the old translated string with a new one, in order to not break translations
804
+			$error_message = esc_html__( 'Your form data could not be applied to any valid registrations.', 'event_espresso' )
805
+							 . sprintf(
806
+								 esc_html__('%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.', 'event_espresso'),
807
+								 '<a href="' . get_post_type_archive_link('espresso_events') . '" >',
808
+								 '</a>',
809
+								 '<br />'
810
+							 );
811
+			EE_Error::add_error(
812
+				$error_message,
813
+				__FILE__,
814
+				__FUNCTION__,
815
+				__LINE__
816
+			);
817
+			return false;
818
+		}
819
+		// extract attendee info from form data and save to model objects
820
+		$registrations_processed = $this->_process_registrations($registrations, $valid_data);
821
+		// if first pass thru SPCO,
822
+		// then let's check processed registrations against the total number of tickets in the cart
823
+		if ($registrations_processed === false) {
824
+			// but return immediately if the previous step exited early due to errors
825
+			return false;
826
+		} elseif (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
827
+			// generate a correctly translated string for all possible singular/plural combinations
828
+			if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
829
+				$error_msg = sprintf(
830
+					esc_html__(
831
+						'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
832
+						'event_espresso'
833
+					),
834
+					$this->checkout->total_ticket_count,
835
+					$registrations_processed
836
+				);
837
+			} elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
838
+				$error_msg = sprintf(
839
+					esc_html__(
840
+						'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
841
+						'event_espresso'
842
+					),
843
+					$this->checkout->total_ticket_count,
844
+					$registrations_processed
845
+				);
846
+			} else {
847
+				$error_msg = sprintf(
848
+					esc_html__(
849
+						'There was a total of %1$d tickets in the Event Queue, but %2$ds registrations were processed',
850
+						'event_espresso'
851
+					),
852
+					$this->checkout->total_ticket_count,
853
+					$registrations_processed
854
+				);
855
+			}
856
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
857
+			return false;
858
+		}
859
+		// mark this reg step as completed
860
+		$this->set_completed();
861
+		$this->_set_success_message(
862
+			esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso')
863
+		);
864
+		//do action in case a plugin wants to do something with the data submitted in step 1.
865
+		//passes EE_Single_Page_Checkout, and it's posted data
866
+		do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
867
+		return true;
868
+	}
869
+
870
+
871
+	/**
872
+	 *    _process_registrations
873
+	 *
874
+	 * @param EE_Registration[] $registrations
875
+	 * @param array             $valid_data
876
+	 * @return bool|int
877
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
878
+	 * @throws EE_Error
879
+	 * @throws InvalidArgumentException
880
+	 * @throws ReflectionException
881
+	 * @throws RuntimeException
882
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
883
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
884
+	 */
885
+	private function _process_registrations($registrations = array(), $valid_data = array())
886
+	{
887
+		// load resources and set some defaults
888
+		EE_Registry::instance()->load_model('Attendee');
889
+		// holder for primary registrant attendee object
890
+		$this->checkout->primary_attendee_obj = null;
891
+		// array for tracking reg form data for the primary registrant
892
+		$primary_registrant = array(
893
+			'line_item_id' => null,
894
+		);
895
+		$copy_primary       = false;
896
+		// reg form sections that do not contain inputs
897
+		$non_input_form_sections = array(
898
+			'primary_registrant',
899
+			'additional_attendee_reg_info',
900
+			'spco_copy_attendee_chk',
901
+		);
902
+		// attendee counter
903
+		$att_nmbr = 0;
904
+		// grab the saved registrations from the transaction
905
+		foreach ($registrations as $registration) {
906
+			// verify EE_Registration object
907
+			if (! $registration instanceof EE_Registration) {
908
+				EE_Error::add_error(
909
+					esc_html__(
910
+						'An invalid Registration object was discovered when attempting to process your registration information.',
911
+						'event_espresso'
912
+					),
913
+					__FILE__,
914
+					__FUNCTION__,
915
+					__LINE__
916
+				);
917
+				return false;
918
+			}
919
+			/** @var string $reg_url_link */
920
+			$reg_url_link = $registration->reg_url_link();
921
+			// reg_url_link exists ?
922
+			if (! empty($reg_url_link)) {
923
+				// should this registration be processed during this visit ?
924
+				if ($this->checkout->visit_allows_processing_of_this_registration($registration)) {
925
+					// if NOT revisiting, then let's save the registration now,
926
+					// so that we have a REG_ID to use when generating other objects
927
+					if (! $this->checkout->revisit) {
928
+						$registration->save();
929
+					}
930
+					/**
931
+					 * This allows plugins to trigger a fail on processing of a
932
+					 * registration for any conditions they may have for it to pass.
933
+					 *
934
+					 * @var bool   if true is returned by the plugin then the
935
+					 *            registration processing is halted.
936
+					 */
937
+					if (apply_filters(
938
+						'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
939
+						false,
940
+						$att_nmbr,
941
+						$registration,
942
+						$registrations,
943
+						$valid_data,
944
+						$this
945
+					)) {
946
+						return false;
947
+					}
948
+
949
+					// Houston, we have a registration!
950
+					$att_nmbr++;
951
+					$this->_attendee_data[$reg_url_link] = array();
952
+					// grab any existing related answer objects
953
+					$this->_registration_answers = $registration->answers();
954
+					// unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] );
955
+					if (isset($valid_data[$reg_url_link])) {
956
+						// do we need to copy basic info from primary attendee ?
957
+						$copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info'])
958
+										&& absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0
959
+							? true
960
+							: false;
961
+						// filter form input data for this registration
962
+						$valid_data[$reg_url_link] = (array)apply_filters(
963
+							'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
964
+							$valid_data[$reg_url_link]
965
+						);
966
+						if (isset($valid_data['primary_attendee'])) {
967
+							$primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee'])
968
+								? $valid_data['primary_attendee']
969
+								: false;
970
+							unset($valid_data['primary_attendee']);
971
+						}
972
+						// now loop through our array of valid post data && process attendee reg forms
973
+						foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) {
974
+							if (! in_array($form_section, $non_input_form_sections)) {
975
+								foreach ($form_inputs as $form_input => $input_value) {
976
+									// \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ );
977
+									// check for critical inputs
978
+									if (! $this->_verify_critical_attendee_details_are_set_and_validate_email(
979
+										$form_input,
980
+										$input_value
981
+									)
982
+									) {
983
+										return false;
984
+									}
985
+									// store a bit of data about the primary attendee
986
+									if ($att_nmbr === 1
987
+										&& ! empty($input_value)
988
+										&& $reg_url_link === $primary_registrant['line_item_id']
989
+									) {
990
+										$primary_registrant[$form_input] = $input_value;
991
+									} elseif ($copy_primary
992
+										&& $input_value === null
993
+										&& isset($primary_registrant[$form_input])
994
+									) {
995
+										$input_value = $primary_registrant[$form_input];
996
+									}
997
+									// now attempt to save the input data
998
+									if (! $this->_save_registration_form_input(
999
+										$registration,
1000
+										$form_input,
1001
+										$input_value
1002
+									)
1003
+									) {
1004
+										EE_Error::add_error(
1005
+											sprintf(
1006
+												esc_html__(
1007
+													'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"',
1008
+													'event_espresso'
1009
+												),
1010
+												$form_input,
1011
+												$input_value
1012
+											),
1013
+											__FILE__,
1014
+											__FUNCTION__,
1015
+											__LINE__
1016
+										);
1017
+										return false;
1018
+									}
1019
+								}
1020
+							}
1021
+						}  // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs )
1022
+					}
1023
+					//EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ );
1024
+					// this registration does not require additional attendee information ?
1025
+					if ($copy_primary
1026
+						&& $att_nmbr > 1
1027
+						&& $this->checkout->primary_attendee_obj instanceof EE_Attendee
1028
+					) {
1029
+						// just copy the primary registrant
1030
+						$attendee = $this->checkout->primary_attendee_obj;
1031
+					} else {
1032
+						// ensure critical details are set for additional attendees
1033
+						$this->_attendee_data[$reg_url_link] = $att_nmbr > 1
1034
+							? $this->_copy_critical_attendee_details_from_primary_registrant(
1035
+								$this->_attendee_data[$reg_url_link]
1036
+							)
1037
+							: $this->_attendee_data[$reg_url_link];
1038
+						// execute create attendee command (which may return an existing attendee)
1039
+						$attendee = EE_Registry::instance()->BUS->execute(
1040
+							new CreateAttendeeCommand(
1041
+								$this->_attendee_data[$reg_url_link],
1042
+								$registration
1043
+							)
1044
+						);
1045
+						// who's #1 ?
1046
+						if ($att_nmbr === 1) {
1047
+							$this->checkout->primary_attendee_obj = $attendee;
1048
+						}
1049
+					}
1050
+					// EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ );
1051
+					// add relation to registration, set attendee ID, and cache attendee
1052
+					$this->_associate_attendee_with_registration($registration, $attendee);
1053
+					// \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ );
1054
+					if (! $registration->attendee() instanceof EE_Attendee) {
1055
+						EE_Error::add_error(
1056
+							sprintf(
1057
+								esc_html__(
1058
+									'Registration %s has an invalid or missing Attendee object.',
1059
+									'event_espresso'
1060
+								),
1061
+								$reg_url_link
1062
+							),
1063
+							__FILE__,
1064
+							__FUNCTION__,
1065
+							__LINE__
1066
+						);
1067
+						return false;
1068
+					}
1069
+					/** @type EE_Registration_Processor $registration_processor */
1070
+					$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1071
+					// at this point, we should have enough details about the registrant to consider the registration
1072
+					// NOT incomplete
1073
+					$registration_processor->toggle_incomplete_registration_status_to_default(
1074
+						$registration,
1075
+						false,
1076
+						new Context(
1077
+							'spco_reg_step_attendee_information_process_registrations',
1078
+							esc_html__(
1079
+								'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.',
1080
+								'event_espresso'
1081
+							)
1082
+						)
1083
+					);
1084
+					// we can also consider the TXN to not have been failed, so temporarily upgrade it's status to
1085
+					// abandoned
1086
+					$this->checkout->transaction->toggle_failed_transaction_status();
1087
+					// if we've gotten this far, then let's save what we have
1088
+					$registration->save();
1089
+					// add relation between TXN and registration
1090
+					$this->_associate_registration_with_transaction($registration);
1091
+				}
1092
+			} else {
1093
+				EE_Error::add_error(
1094
+					esc_html__(
1095
+						'An invalid or missing line item ID was encountered while attempting to process the registration form.',
1096
+						'event_espresso'
1097
+					),
1098
+					__FILE__,
1099
+					__FUNCTION__,
1100
+					__LINE__
1101
+				);
1102
+				// remove malformed data
1103
+				unset($valid_data[$reg_url_link]);
1104
+				return false;
1105
+			}
1106
+
1107
+		} // end of foreach ( $this->checkout->transaction->registrations()  as $registration )
1108
+		return $att_nmbr;
1109
+	}
1110
+
1111
+
1112
+	/**
1113
+	 *    _save_registration_form_input
1114
+	 *
1115
+	 * @param EE_Registration $registration
1116
+	 * @param string          $form_input
1117
+	 * @param string          $input_value
1118
+	 * @return bool
1119
+	 * @throws EE_Error
1120
+	 * @throws InvalidArgumentException
1121
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1122
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1123
+	 */
1124
+	private function _save_registration_form_input(
1125
+		EE_Registration $registration,
1126
+		$form_input = '',
1127
+		$input_value = ''
1128
+	) {
1129
+		// \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 );
1130
+		// \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ );
1131
+		// \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ );
1132
+		// allow for plugins to hook in and do their own processing of the form input.
1133
+		// For plugins to bypass normal processing here, they just need to return a boolean value.
1134
+		if (apply_filters(
1135
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
1136
+			false,
1137
+			$registration,
1138
+			$form_input,
1139
+			$input_value,
1140
+			$this
1141
+		)) {
1142
+			return true;
1143
+		}
1144
+		/*
1145 1145
          * $answer_cache_id is the key used to find the EE_Answer we want
1146 1146
          * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477
1147 1147
          */
1148
-        $answer_cache_id = $this->checkout->reg_url_link
1149
-            ? $form_input . '-' . $registration->reg_url_link()
1150
-            : $form_input;
1151
-        $answer_is_obj   = isset($this->_registration_answers[$answer_cache_id])
1152
-                           && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer
1153
-            ? true
1154
-            : false;
1155
-        //rename form_inputs if they are EE_Attendee properties
1156
-        switch ((string) $form_input) {
1157
-            case 'state':
1158
-            case 'STA_ID':
1159
-                $attendee_property = true;
1160
-                $form_input        = 'STA_ID';
1161
-                break;
1162
-
1163
-            case 'country':
1164
-            case 'CNT_ISO':
1165
-                $attendee_property = true;
1166
-                $form_input        = 'CNT_ISO';
1167
-                break;
1168
-
1169
-            default:
1170
-                $ATT_input = 'ATT_' . $form_input;
1171
-                //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ );
1172
-                $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false;
1173
-                $form_input        = $attendee_property ? 'ATT_' . $form_input : $form_input;
1174
-        }
1175
-        // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ );
1176
-        // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ );
1177
-        // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ );
1178
-        // if this form input has a corresponding attendee property
1179
-        if ($attendee_property) {
1180
-            $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value;
1181
-            if ($answer_is_obj) {
1182
-                // and delete the corresponding answer since we won't be storing this data in that object
1183
-                $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer');
1184
-                $this->_registration_answers[$answer_cache_id]->delete_permanently();
1185
-            }
1186
-            return true;
1187
-        } elseif ($answer_is_obj) {
1188
-            // save this data to the answer object
1189
-            $this->_registration_answers[$answer_cache_id]->set_value($input_value);
1190
-            $result = $this->_registration_answers[$answer_cache_id]->save();
1191
-            return $result !== false ? true : false;
1192
-        } else {
1193
-            foreach ($this->_registration_answers as $answer) {
1194
-                if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) {
1195
-                    $answer->set_value($input_value);
1196
-                    $result = $answer->save();
1197
-                    return $result !== false ? true : false;
1198
-                }
1199
-            }
1200
-        }
1201
-        return false;
1202
-    }
1203
-
1204
-
1205
-    /**
1206
-     *    _verify_critical_attendee_details_are_set
1207
-     *
1208
-     * @param string $form_input
1209
-     * @param string $input_value
1210
-     * @return boolean
1211
-     */
1212
-    private function _verify_critical_attendee_details_are_set_and_validate_email(
1213
-        $form_input = '',
1214
-        $input_value = ''
1215
-    ) {
1216
-        if (empty($input_value)) {
1217
-            // if the form input isn't marked as being required, then just return
1218
-            if (! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) {
1219
-                return true;
1220
-            }
1221
-            switch ($form_input) {
1222
-                case 'fname':
1223
-                    EE_Error::add_error(
1224
-                        esc_html__('First Name is a required value.', 'event_espresso'),
1225
-                        __FILE__,
1226
-                        __FUNCTION__,
1227
-                        __LINE__
1228
-                    );
1229
-                    return false;
1230
-                    break;
1231
-                case 'lname':
1232
-                    EE_Error::add_error(
1233
-                        esc_html__('Last Name is a required value.', 'event_espresso'),
1234
-                        __FILE__,
1235
-                        __FUNCTION__,
1236
-                        __LINE__
1237
-                    );
1238
-                    return false;
1239
-                    break;
1240
-                case 'email':
1241
-                    EE_Error::add_error(
1242
-                        esc_html__('Please enter a valid email address.', 'event_espresso'),
1243
-                        __FILE__,
1244
-                        __FUNCTION__,
1245
-                        __LINE__
1246
-                    );
1247
-                    return false;
1248
-                    break;
1249
-            }
1250
-        }
1251
-        return true;
1252
-    }
1253
-
1254
-
1255
-    /**
1256
-     *    _associate_attendee_with_registration
1257
-     *
1258
-     * @param EE_Registration $registration
1259
-     * @param EE_Attendee     $attendee
1260
-     * @return void
1261
-     * @throws EE_Error
1262
-     * @throws RuntimeException
1263
-     */
1264
-    private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee)
1265
-    {
1266
-        // add relation to attendee
1267
-        $registration->_add_relation_to($attendee, 'Attendee');
1268
-        $registration->set_attendee_id($attendee->ID());
1269
-        $registration->update_cache_after_object_save('Attendee', $attendee);
1270
-    }
1271
-
1272
-
1273
-    /**
1274
-     *    _associate_registration_with_transaction
1275
-     *
1276
-     * @param EE_Registration $registration
1277
-     * @return void
1278
-     * @throws \EE_Error
1279
-     */
1280
-    private function _associate_registration_with_transaction(EE_Registration $registration)
1281
-    {
1282
-        // add relation to registration
1283
-        $this->checkout->transaction->_add_relation_to($registration, 'Registration');
1284
-        $this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
1285
-    }
1286
-
1287
-
1288
-    /**
1289
-     *    _copy_critical_attendee_details_from_primary_registrant
1290
-     *    ensures that all attendees at least have data for first name, last name, and email address
1291
-     *
1292
-     * @param array $attendee_data
1293
-     * @return array
1294
-     * @throws \EE_Error
1295
-     */
1296
-    private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array())
1297
-    {
1298
-        // bare minimum critical details include first name, last name, email address
1299
-        $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email');
1300
-        // add address info to critical details?
1301
-        if (apply_filters(
1302
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
1303
-            false
1304
-        )) {
1305
-            $address_details           = array(
1306
-                'ATT_address',
1307
-                'ATT_address2',
1308
-                'ATT_city',
1309
-                'STA_ID',
1310
-                'CNT_ISO',
1311
-                'ATT_zip',
1312
-                'ATT_phone',
1313
-            );
1314
-            $critical_attendee_details = array_merge($critical_attendee_details, $address_details);
1315
-        }
1316
-        foreach ($critical_attendee_details as $critical_attendee_detail) {
1317
-            if (! isset($attendee_data[$critical_attendee_detail])
1318
-                || empty($attendee_data[$critical_attendee_detail])
1319
-            ) {
1320
-                $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get(
1321
-                    $critical_attendee_detail
1322
-                );
1323
-            }
1324
-        }
1325
-        return $attendee_data;
1326
-    }
1327
-
1328
-
1329
-    /**
1330
-     *    update_reg_step
1331
-     *    this is the final step after a user  revisits the site to edit their attendee information
1332
-     *    this gets called AFTER the process_reg_step() method above
1333
-     *
1334
-     * @return bool
1335
-     * @throws EE_Error
1336
-     * @throws InvalidArgumentException
1337
-     * @throws ReflectionException
1338
-     * @throws RuntimeException
1339
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1340
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1341
-     */
1342
-    public function update_reg_step()
1343
-    {
1344
-        // save everything
1345
-        if ($this->process_reg_step()) {
1346
-            $this->checkout->redirect     = true;
1347
-            $this->checkout->redirect_url = add_query_arg(
1348
-                array(
1349
-                    'e_reg_url_link' => $this->checkout->reg_url_link,
1350
-                    'revisit'        => true,
1351
-                ),
1352
-                $this->checkout->thank_you_page_url
1353
-            );
1354
-            $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1355
-            return true;
1356
-        }
1357
-        return false;
1358
-    }
1148
+		$answer_cache_id = $this->checkout->reg_url_link
1149
+			? $form_input . '-' . $registration->reg_url_link()
1150
+			: $form_input;
1151
+		$answer_is_obj   = isset($this->_registration_answers[$answer_cache_id])
1152
+						   && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer
1153
+			? true
1154
+			: false;
1155
+		//rename form_inputs if they are EE_Attendee properties
1156
+		switch ((string) $form_input) {
1157
+			case 'state':
1158
+			case 'STA_ID':
1159
+				$attendee_property = true;
1160
+				$form_input        = 'STA_ID';
1161
+				break;
1162
+
1163
+			case 'country':
1164
+			case 'CNT_ISO':
1165
+				$attendee_property = true;
1166
+				$form_input        = 'CNT_ISO';
1167
+				break;
1168
+
1169
+			default:
1170
+				$ATT_input = 'ATT_' . $form_input;
1171
+				//EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ );
1172
+				$attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false;
1173
+				$form_input        = $attendee_property ? 'ATT_' . $form_input : $form_input;
1174
+		}
1175
+		// EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ );
1176
+		// EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ );
1177
+		// EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ );
1178
+		// if this form input has a corresponding attendee property
1179
+		if ($attendee_property) {
1180
+			$this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value;
1181
+			if ($answer_is_obj) {
1182
+				// and delete the corresponding answer since we won't be storing this data in that object
1183
+				$registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer');
1184
+				$this->_registration_answers[$answer_cache_id]->delete_permanently();
1185
+			}
1186
+			return true;
1187
+		} elseif ($answer_is_obj) {
1188
+			// save this data to the answer object
1189
+			$this->_registration_answers[$answer_cache_id]->set_value($input_value);
1190
+			$result = $this->_registration_answers[$answer_cache_id]->save();
1191
+			return $result !== false ? true : false;
1192
+		} else {
1193
+			foreach ($this->_registration_answers as $answer) {
1194
+				if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) {
1195
+					$answer->set_value($input_value);
1196
+					$result = $answer->save();
1197
+					return $result !== false ? true : false;
1198
+				}
1199
+			}
1200
+		}
1201
+		return false;
1202
+	}
1203
+
1204
+
1205
+	/**
1206
+	 *    _verify_critical_attendee_details_are_set
1207
+	 *
1208
+	 * @param string $form_input
1209
+	 * @param string $input_value
1210
+	 * @return boolean
1211
+	 */
1212
+	private function _verify_critical_attendee_details_are_set_and_validate_email(
1213
+		$form_input = '',
1214
+		$input_value = ''
1215
+	) {
1216
+		if (empty($input_value)) {
1217
+			// if the form input isn't marked as being required, then just return
1218
+			if (! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) {
1219
+				return true;
1220
+			}
1221
+			switch ($form_input) {
1222
+				case 'fname':
1223
+					EE_Error::add_error(
1224
+						esc_html__('First Name is a required value.', 'event_espresso'),
1225
+						__FILE__,
1226
+						__FUNCTION__,
1227
+						__LINE__
1228
+					);
1229
+					return false;
1230
+					break;
1231
+				case 'lname':
1232
+					EE_Error::add_error(
1233
+						esc_html__('Last Name is a required value.', 'event_espresso'),
1234
+						__FILE__,
1235
+						__FUNCTION__,
1236
+						__LINE__
1237
+					);
1238
+					return false;
1239
+					break;
1240
+				case 'email':
1241
+					EE_Error::add_error(
1242
+						esc_html__('Please enter a valid email address.', 'event_espresso'),
1243
+						__FILE__,
1244
+						__FUNCTION__,
1245
+						__LINE__
1246
+					);
1247
+					return false;
1248
+					break;
1249
+			}
1250
+		}
1251
+		return true;
1252
+	}
1253
+
1254
+
1255
+	/**
1256
+	 *    _associate_attendee_with_registration
1257
+	 *
1258
+	 * @param EE_Registration $registration
1259
+	 * @param EE_Attendee     $attendee
1260
+	 * @return void
1261
+	 * @throws EE_Error
1262
+	 * @throws RuntimeException
1263
+	 */
1264
+	private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee)
1265
+	{
1266
+		// add relation to attendee
1267
+		$registration->_add_relation_to($attendee, 'Attendee');
1268
+		$registration->set_attendee_id($attendee->ID());
1269
+		$registration->update_cache_after_object_save('Attendee', $attendee);
1270
+	}
1271
+
1272
+
1273
+	/**
1274
+	 *    _associate_registration_with_transaction
1275
+	 *
1276
+	 * @param EE_Registration $registration
1277
+	 * @return void
1278
+	 * @throws \EE_Error
1279
+	 */
1280
+	private function _associate_registration_with_transaction(EE_Registration $registration)
1281
+	{
1282
+		// add relation to registration
1283
+		$this->checkout->transaction->_add_relation_to($registration, 'Registration');
1284
+		$this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
1285
+	}
1286
+
1287
+
1288
+	/**
1289
+	 *    _copy_critical_attendee_details_from_primary_registrant
1290
+	 *    ensures that all attendees at least have data for first name, last name, and email address
1291
+	 *
1292
+	 * @param array $attendee_data
1293
+	 * @return array
1294
+	 * @throws \EE_Error
1295
+	 */
1296
+	private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array())
1297
+	{
1298
+		// bare minimum critical details include first name, last name, email address
1299
+		$critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email');
1300
+		// add address info to critical details?
1301
+		if (apply_filters(
1302
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
1303
+			false
1304
+		)) {
1305
+			$address_details           = array(
1306
+				'ATT_address',
1307
+				'ATT_address2',
1308
+				'ATT_city',
1309
+				'STA_ID',
1310
+				'CNT_ISO',
1311
+				'ATT_zip',
1312
+				'ATT_phone',
1313
+			);
1314
+			$critical_attendee_details = array_merge($critical_attendee_details, $address_details);
1315
+		}
1316
+		foreach ($critical_attendee_details as $critical_attendee_detail) {
1317
+			if (! isset($attendee_data[$critical_attendee_detail])
1318
+				|| empty($attendee_data[$critical_attendee_detail])
1319
+			) {
1320
+				$attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get(
1321
+					$critical_attendee_detail
1322
+				);
1323
+			}
1324
+		}
1325
+		return $attendee_data;
1326
+	}
1327
+
1328
+
1329
+	/**
1330
+	 *    update_reg_step
1331
+	 *    this is the final step after a user  revisits the site to edit their attendee information
1332
+	 *    this gets called AFTER the process_reg_step() method above
1333
+	 *
1334
+	 * @return bool
1335
+	 * @throws EE_Error
1336
+	 * @throws InvalidArgumentException
1337
+	 * @throws ReflectionException
1338
+	 * @throws RuntimeException
1339
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1340
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1341
+	 */
1342
+	public function update_reg_step()
1343
+	{
1344
+		// save everything
1345
+		if ($this->process_reg_step()) {
1346
+			$this->checkout->redirect     = true;
1347
+			$this->checkout->redirect_url = add_query_arg(
1348
+				array(
1349
+					'e_reg_url_link' => $this->checkout->reg_url_link,
1350
+					'revisit'        => true,
1351
+				),
1352
+				$this->checkout->thank_you_page_url
1353
+			);
1354
+			$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1355
+			return true;
1356
+		}
1357
+		return false;
1358
+	}
1359 1359
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -52 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
     {
49 49
         $this->_slug     = 'attendee_information';
50 50
         $this->_name     = esc_html__('Attendee Information', 'event_espresso');
51
-        $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php';
51
+        $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'attendee_info_main.template.php';
52 52
         $this->checkout  = $checkout;
53 53
         $this->_reset_success_message();
54 54
         $this->set_instructions(
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
 
60 60
     public function translate_js_strings()
61 61
     {
62
-        EE_Registry::$i18n_js_strings['required_field']            = esc_html__(
62
+        EE_Registry::$i18n_js_strings['required_field'] = esc_html__(
63 63
             ' is a required question.',
64 64
             'event_espresso'
65 65
         );
66
-        EE_Registry::$i18n_js_strings['required_multi_field']      = esc_html__(
66
+        EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__(
67 67
             ' is a required question. Please enter a value for at least one of the options.',
68 68
             'event_espresso'
69 69
         );
@@ -71,18 +71,18 @@  discard block
 block discarded – undo
71 71
             'Please answer all required questions correctly before proceeding.',
72 72
             'event_espresso'
73 73
         );
74
-        EE_Registry::$i18n_js_strings['attendee_info_copied']      = sprintf(
74
+        EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf(
75 75
             esc_html__(
76 76
                 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
77 77
                 'event_espresso'
78 78
             ),
79 79
             '<br/>'
80 80
         );
81
-        EE_Registry::$i18n_js_strings['attendee_info_copy_error']  = esc_html__(
81
+        EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__(
82 82
             'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
83 83
             'event_espresso'
84 84
         );
85
-        EE_Registry::$i18n_js_strings['enter_valid_email']         = esc_html__(
85
+        EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__(
86 86
             'You must enter a valid email address.',
87 87
             'event_espresso'
88 88
         );
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
                     && $this->checkout->visit_allows_processing_of_this_registration($registration)
146 146
                 ) {
147 147
                     $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration);
148
-                    if (! $this->checkout->admin_request) {
148
+                    if ( ! $this->checkout->admin_request) {
149 149
                         $template_args['registrations'][$registration->reg_url_link()]    = $registration;
150 150
                         $template_args['ticket_count'][$registration->ticket()->ID()]     = isset(
151 151
                             $template_args['ticket_count'][$registration->ticket()->ID()]
@@ -194,8 +194,7 @@  discard block
 block discarded – undo
194 194
                 'html_id'         => $this->reg_form_name(),
195 195
                 'subsections'     => $subsections,
196 196
                 'layout_strategy' => $this->checkout->admin_request ?
197
-                    new EE_Div_Per_Section_Layout() :
198
-                    new EE_Template_Layout(
197
+                    new EE_Div_Per_Section_Layout() : new EE_Template_Layout(
199 198
                         array(
200 199
                             'layout_template_file' => $this->_template, // layout_template
201 200
                             'template_args'        => $template_args,
@@ -238,7 +237,7 @@  discard block
 block discarded – undo
238 237
             if ($question_groups) {
239 238
                 // array of params to pass to parent constructor
240 239
                 $form_args = array(
241
-                    'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
240
+                    'html_id'         => 'ee-registration-'.$registration->reg_url_link(),
242 241
                     'html_class'      => 'ee-reg-form-attendee-dv',
243 242
                     'html_style'      => $this->checkout->admin_request
244 243
                         ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
@@ -294,7 +293,7 @@  discard block
 block discarded – undo
294 293
         // generate hidden input
295 294
         return new EE_Hidden_Input(
296 295
             array(
297
-                'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
296
+                'html_id' => 'additional-attendee-reg-info-'.$registration->reg_url_link(),
298 297
                 'default' => $additional_attendee_reg_info,
299 298
             )
300 299
         );
@@ -314,11 +313,11 @@  discard block
 block discarded – undo
314 313
     {
315 314
         // array of params to pass to parent constructor
316 315
         $form_args = array(
317
-            'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier(),
316
+            'html_id'         => 'ee-reg-form-qstn-grp-'.$question_group->identifier(),
318 317
             'html_class'      => $this->checkout->admin_request
319 318
                 ? 'form-table ee-reg-form-qstn-grp-dv'
320 319
                 : 'ee-reg-form-qstn-grp-dv',
321
-            'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-lbl',
320
+            'html_label_id'   => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-lbl',
322 321
             'subsections'     => array(
323 322
                 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group),
324 323
             ),
@@ -329,7 +328,7 @@  discard block
 block discarded – undo
329 328
         // where params
330 329
         $query_params = array('QST_deleted' => 0);
331 330
         // don't load admin only questions on the frontend
332
-        if (! $this->checkout->admin_request) {
331
+        if ( ! $this->checkout->admin_request) {
333 332
             $query_params['QST_admin_only'] = array('!=', true);
334 333
         }
335 334
         $questions = $question_group->get_many_related(
@@ -473,7 +472,7 @@  discard block
 block discarded – undo
473 472
     {
474 473
         return new EE_Form_Section_HTML(
475 474
             EEH_Template::locate_template(
476
-                SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php',
475
+                SPCO_REG_STEPS_PATH.$this->_slug.DS.'_auto_copy_attendee_info.template.php',
477 476
                 apply_filters(
478 477
                     'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
479 478
                     array()
@@ -505,16 +504,16 @@  discard block
 block discarded – undo
505 504
                 if ($registration->ticket()->ID() !== $prev_ticket) {
506 505
                     $item_name = $registration->ticket()->name();
507 506
                     $item_name .= $registration->ticket()->description() !== ''
508
-                        ? ' - ' . $registration->ticket()->description()
507
+                        ? ' - '.$registration->ticket()->description()
509 508
                         : '';
510
-                    $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']'] =
509
+                    $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID().']'] =
511 510
                         new EE_Form_Section_HTML(
512
-                            '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>'
511
+                            '<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>'
513 512
                         );
514 513
                     $prev_ticket = $registration->ticket()->ID();
515 514
                 }
516 515
 
517
-                $copy_attendee_info_inputs['spco_copy_attendee_chk[' . $registration->ID() . ']'] =
516
+                $copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] =
518 517
                     new EE_Checkbox_Multi_Input(
519 518
                         array(
520 519
                             $registration->ID() => sprintf(
@@ -523,7 +522,7 @@  discard block
 block discarded – undo
523 522
                             ),
524 523
                         ),
525 524
                         array(
526
-                            'html_id'                 => 'spco-copy-attendee-chk-' . $registration->reg_url_link(),
525
+                            'html_id'                 => 'spco-copy-attendee-chk-'.$registration->reg_url_link(),
527 526
                             'html_class'              => 'spco-copy-attendee-chk ee-do-not-validate',
528 527
                             'display_html_label_text' => false,
529 528
                         )
@@ -572,7 +571,7 @@  discard block
 block discarded – undo
572 571
             $registration,
573 572
             $question->system_ID()
574 573
         );
575
-        $answer       = $answer_value === null
574
+        $answer = $answer_value === null
576 575
             ? EEM_Answer::instance()->get_one(
577 576
                 array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
578 577
             )
@@ -589,14 +588,14 @@  discard block
 block discarded – undo
589 588
         }
590 589
         // verify instance
591 590
         if ($answer instanceof EE_Answer) {
592
-            if (! empty($answer_value)) {
591
+            if ( ! empty($answer_value)) {
593 592
                 $answer->set('ANS_value', $answer_value);
594 593
             }
595 594
             $answer->cache('Question', $question);
596 595
             //remember system ID had a bug where sometimes it could be null
597 596
             $answer_cache_id = $question->is_system_question()
598
-                ? $question->system_ID() . '-' . $registration->reg_url_link()
599
-                : $question->ID() . '-' . $registration->reg_url_link();
597
+                ? $question->system_ID().'-'.$registration->reg_url_link()
598
+                : $question->ID().'-'.$registration->reg_url_link();
600 599
             $registration->cache('Answer', $answer, $answer_cache_id);
601 600
         }
602 601
         return $this->_generate_question_input($registration, $question, $answer);
@@ -628,18 +627,18 @@  discard block
 block discarded – undo
628 627
             10,
629 628
             4
630 629
         );
631
-        $input_constructor_args                  = array(
632
-            'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
633
-            'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
634
-            'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
635
-            'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
630
+        $input_constructor_args = array(
631
+            'html_name'        => 'ee_reg_qstn['.$registration->ID().']['.$identifier.']',
632
+            'html_id'          => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier,
633
+            'html_class'       => 'ee-reg-qstn ee-reg-qstn-'.$identifier,
634
+            'html_label_id'    => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier,
636 635
             'html_label_class' => 'ee-reg-qstn',
637 636
         );
638 637
         $input_constructor_args['html_label_id'] .= '-lbl';
639 638
         if ($answer instanceof EE_Answer && $answer->ID()) {
640
-            $input_constructor_args['html_name']     .= '[' . $answer->ID() . ']';
641
-            $input_constructor_args['html_id']       .= '-' . $answer->ID();
642
-            $input_constructor_args['html_label_id'] .= '-' . $answer->ID();
639
+            $input_constructor_args['html_name']     .= '['.$answer->ID().']';
640
+            $input_constructor_args['html_id']       .= '-'.$answer->ID();
641
+            $input_constructor_args['html_label_id'] .= '-'.$answer->ID();
643 642
         }
644 643
         $form_input = $question->generate_form_input(
645 644
             $registration,
@@ -682,7 +681,7 @@  discard block
 block discarded – undo
682 681
         $countries = $this->checkout->action === 'process_reg_step'
683 682
             ? EEM_Country::instance()->get_all_countries()
684 683
             : EEM_Country::instance()->get_all_active_countries();
685
-        if (! empty($countries)) {
684
+        if ( ! empty($countries)) {
686 685
             foreach ($countries as $country) {
687 686
                 if ($country instanceof EE_Country) {
688 687
                     $country_options[$country->ID()] = $country->name();
@@ -732,7 +731,7 @@  discard block
 block discarded – undo
732 731
         $states        = $this->checkout->action === 'process_reg_step'
733 732
             ? EEM_State::instance()->get_all_states()
734 733
             : EEM_State::instance()->get_all_active_states();
735
-        if (! empty($states)) {
734
+        if ( ! empty($states)) {
736 735
             foreach ($states as $state) {
737 736
                 if ($state instanceof EE_State) {
738 737
                     $state_options[$state->country()->name()][$state->ID()] = $state->name();
@@ -784,7 +783,7 @@  discard block
 block discarded – undo
784 783
             );
785 784
             return false;
786 785
         }
787
-        if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
786
+        if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
788 787
             EE_Error::add_error(
789 788
                 esc_html__(
790 789
                     'A valid transaction could not be initiated for processing your registrations.',
@@ -801,10 +800,10 @@  discard block
 block discarded – undo
801 800
         // verify we got the goods
802 801
         if (empty($registrations)) {
803 802
             //combine the old translated string with a new one, in order to not break translations
804
-            $error_message = esc_html__( 'Your form data could not be applied to any valid registrations.', 'event_espresso' )
803
+            $error_message = esc_html__('Your form data could not be applied to any valid registrations.', 'event_espresso')
805 804
                              . sprintf(
806 805
                                  esc_html__('%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.', 'event_espresso'),
807
-                                 '<a href="' . get_post_type_archive_link('espresso_events') . '" >',
806
+                                 '<a href="'.get_post_type_archive_link('espresso_events').'" >',
808 807
                                  '</a>',
809 808
                                  '<br />'
810 809
                              );
@@ -823,7 +822,7 @@  discard block
 block discarded – undo
823 822
         if ($registrations_processed === false) {
824 823
             // but return immediately if the previous step exited early due to errors
825 824
             return false;
826
-        } elseif (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
825
+        } elseif ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
827 826
             // generate a correctly translated string for all possible singular/plural combinations
828 827
             if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
829 828
                 $error_msg = sprintf(
@@ -904,7 +903,7 @@  discard block
 block discarded – undo
904 903
         // grab the saved registrations from the transaction
905 904
         foreach ($registrations as $registration) {
906 905
             // verify EE_Registration object
907
-            if (! $registration instanceof EE_Registration) {
906
+            if ( ! $registration instanceof EE_Registration) {
908 907
                 EE_Error::add_error(
909 908
                     esc_html__(
910 909
                         'An invalid Registration object was discovered when attempting to process your registration information.',
@@ -919,12 +918,12 @@  discard block
 block discarded – undo
919 918
             /** @var string $reg_url_link */
920 919
             $reg_url_link = $registration->reg_url_link();
921 920
             // reg_url_link exists ?
922
-            if (! empty($reg_url_link)) {
921
+            if ( ! empty($reg_url_link)) {
923 922
                 // should this registration be processed during this visit ?
924 923
                 if ($this->checkout->visit_allows_processing_of_this_registration($registration)) {
925 924
                     // if NOT revisiting, then let's save the registration now,
926 925
                     // so that we have a REG_ID to use when generating other objects
927
-                    if (! $this->checkout->revisit) {
926
+                    if ( ! $this->checkout->revisit) {
928 927
                         $registration->save();
929 928
                     }
930 929
                     /**
@@ -959,7 +958,7 @@  discard block
 block discarded – undo
959 958
                             ? true
960 959
                             : false;
961 960
                         // filter form input data for this registration
962
-                        $valid_data[$reg_url_link] = (array)apply_filters(
961
+                        $valid_data[$reg_url_link] = (array) apply_filters(
963 962
                             'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
964 963
                             $valid_data[$reg_url_link]
965 964
                         );
@@ -971,11 +970,11 @@  discard block
 block discarded – undo
971 970
                         }
972 971
                         // now loop through our array of valid post data && process attendee reg forms
973 972
                         foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) {
974
-                            if (! in_array($form_section, $non_input_form_sections)) {
973
+                            if ( ! in_array($form_section, $non_input_form_sections)) {
975 974
                                 foreach ($form_inputs as $form_input => $input_value) {
976 975
                                     // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ );
977 976
                                     // check for critical inputs
978
-                                    if (! $this->_verify_critical_attendee_details_are_set_and_validate_email(
977
+                                    if ( ! $this->_verify_critical_attendee_details_are_set_and_validate_email(
979 978
                                         $form_input,
980 979
                                         $input_value
981 980
                                     )
@@ -995,7 +994,7 @@  discard block
 block discarded – undo
995 994
                                         $input_value = $primary_registrant[$form_input];
996 995
                                     }
997 996
                                     // now attempt to save the input data
998
-                                    if (! $this->_save_registration_form_input(
997
+                                    if ( ! $this->_save_registration_form_input(
999 998
                                         $registration,
1000 999
                                         $form_input,
1001 1000
                                         $input_value
@@ -1051,7 +1050,7 @@  discard block
 block discarded – undo
1051 1050
                     // add relation to registration, set attendee ID, and cache attendee
1052 1051
                     $this->_associate_attendee_with_registration($registration, $attendee);
1053 1052
                     // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ );
1054
-                    if (! $registration->attendee() instanceof EE_Attendee) {
1053
+                    if ( ! $registration->attendee() instanceof EE_Attendee) {
1055 1054
                         EE_Error::add_error(
1056 1055
                             sprintf(
1057 1056
                                 esc_html__(
@@ -1146,7 +1145,7 @@  discard block
 block discarded – undo
1146 1145
          * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477
1147 1146
          */
1148 1147
         $answer_cache_id = $this->checkout->reg_url_link
1149
-            ? $form_input . '-' . $registration->reg_url_link()
1148
+            ? $form_input.'-'.$registration->reg_url_link()
1150 1149
             : $form_input;
1151 1150
         $answer_is_obj   = isset($this->_registration_answers[$answer_cache_id])
1152 1151
                            && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer
@@ -1167,10 +1166,10 @@  discard block
 block discarded – undo
1167 1166
                 break;
1168 1167
 
1169 1168
             default:
1170
-                $ATT_input = 'ATT_' . $form_input;
1169
+                $ATT_input = 'ATT_'.$form_input;
1171 1170
                 //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ );
1172 1171
                 $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false;
1173
-                $form_input        = $attendee_property ? 'ATT_' . $form_input : $form_input;
1172
+                $form_input        = $attendee_property ? 'ATT_'.$form_input : $form_input;
1174 1173
         }
1175 1174
         // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ );
1176 1175
         // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ );
@@ -1215,7 +1214,7 @@  discard block
 block discarded – undo
1215 1214
     ) {
1216 1215
         if (empty($input_value)) {
1217 1216
             // if the form input isn't marked as being required, then just return
1218
-            if (! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) {
1217
+            if ( ! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) {
1219 1218
                 return true;
1220 1219
             }
1221 1220
             switch ($form_input) {
@@ -1302,7 +1301,7 @@  discard block
 block discarded – undo
1302 1301
             'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
1303 1302
             false
1304 1303
         )) {
1305
-            $address_details           = array(
1304
+            $address_details = array(
1306 1305
                 'ATT_address',
1307 1306
                 'ATT_address2',
1308 1307
                 'ATT_city',
@@ -1314,7 +1313,7 @@  discard block
 block discarded – undo
1314 1313
             $critical_attendee_details = array_merge($critical_attendee_details, $address_details);
1315 1314
         }
1316 1315
         foreach ($critical_attendee_details as $critical_attendee_detail) {
1317
-            if (! isset($attendee_data[$critical_attendee_detail])
1316
+            if ( ! isset($attendee_data[$critical_attendee_detail])
1318 1317
                 || empty($attendee_data[$critical_attendee_detail])
1319 1318
             ) {
1320 1319
                 $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get(
Please login to merge, or discard this patch.
admin_pages/maintenance/templates/ee_data_reset_and_delete.template.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
 /** @var string $delete_db_url */
8 8
 ?>
9 9
 <h2>
10
-	<?php esc_html_e( 'Reset/Delete Data for Event Espresso', 'event_espresso' );?>
10
+	<?php esc_html_e('Reset/Delete Data for Event Espresso', 'event_espresso'); ?>
11 11
 </h2>
12 12
 <br />
13 13
 
14 14
 <div class="padding">
15
-	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Ticket and Datetime Reserved Counts', 'event_espresso');?></h4>
16
-	<p><?php esc_html_e('Use this to reset the counts for ticket and datetime reservations.', 'event_espresso');?></p>
15
+	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Ticket and Datetime Reserved Counts', 'event_espresso'); ?></h4>
16
+	<p><?php esc_html_e('Use this to reset the counts for ticket and datetime reservations.', 'event_espresso'); ?></p>
17 17
 	<div class="float-right"><?php echo $reset_reservations_button; ?></div>
18 18
 	<div class="clear"></div>
19 19
 </div>
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
 
23 23
 <!-- reset DB url is here. Just need to make it look pretty and unhide it-->
24 24
 <div class="padding">
25
-	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Capabilities', 'event_espresso');?></h4>
26
-	<p><?php esc_html_e('Use this to reset the capabilities on WP roles to the defaults as defined via EE_Capabilities.  Note this reset does not REMOVE any existing capabilities, it just ensures that all the defaults are ADDED to the roles.', 'event_espresso');?></p>
25
+	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Capabilities', 'event_espresso'); ?></h4>
26
+	<p><?php esc_html_e('Use this to reset the capabilities on WP roles to the defaults as defined via EE_Capabilities.  Note this reset does not REMOVE any existing capabilities, it just ensures that all the defaults are ADDED to the roles.', 'event_espresso'); ?></p>
27 27
 	<div class="float-right"><?php echo $reset_capabilities_button; ?></div>
28 28
 	<div class="clear"></div>
29 29
 </div>
@@ -31,29 +31,29 @@  discard block
 block discarded – undo
31 31
 <br />
32 32
 
33 33
 <div class="padding">
34
-	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Data', 'event_espresso');?></h4>
35
-    <p><?php esc_html_e(' This will reset data for Event Espresso 4, and for all active add-ons. Inactive add-ons will not be affected.', 'event_espresso');?></p>
36
-    <p><?php esc_html_e('Your Event Espresso data will return to its default settings. The rest of your website will be unaffected.', 'event_espresso');?></p>
37
-	<div class="float-right"><a class="button button-primary ee-confirm" href="<?php echo $reset_db_url;?>"><?php esc_html_e('Reset Event Espresso Tables', 'event_espresso');?></a></div>
34
+	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Data', 'event_espresso'); ?></h4>
35
+    <p><?php esc_html_e(' This will reset data for Event Espresso 4, and for all active add-ons. Inactive add-ons will not be affected.', 'event_espresso'); ?></p>
36
+    <p><?php esc_html_e('Your Event Espresso data will return to its default settings. The rest of your website will be unaffected.', 'event_espresso'); ?></p>
37
+	<div class="float-right"><a class="button button-primary ee-confirm" href="<?php echo $reset_db_url; ?>"><?php esc_html_e('Reset Event Espresso Tables', 'event_espresso'); ?></a></div>
38 38
 	<div class="clear"></div>
39 39
 </div>
40 40
 <br />
41 41
 <br />
42 42
 
43 43
 <div class="padding">
44
-	<h4 class="espresso-header"><span class="dashicons dashicons-post-trash ee-icon-size-22"></span><?php esc_html_e('Permanently Delete ALL Event Espresso Data', 'event_espresso');?></h4>
44
+	<h4 class="espresso-header"><span class="dashicons dashicons-post-trash ee-icon-size-22"></span><?php esc_html_e('Permanently Delete ALL Event Espresso Data', 'event_espresso'); ?></h4>
45 45
     <p><?php esc_html_e(' This will delete data for Event Espresso 4, and all currently active add-ons. Event Espresso will then be deactivated. You may need to manually deactivate each add-on individually.',
46
-            'event_espresso');?></p>
47
-	<p><?php esc_html_e('If you know for certain that you will no longer be using Event Espresso and you wish to remove ALL traces of the plugin from your system, then perform the following steps.', 'event_espresso');?></p>
48
-	<p class="important-notice"><?php printf( esc_html__('Please note: %sThis is permanent and can NOT be undone.%s', 'event_espresso'), '<em>', '</em>' ); ?><br/></p>
46
+            'event_espresso'); ?></p>
47
+	<p><?php esc_html_e('If you know for certain that you will no longer be using Event Espresso and you wish to remove ALL traces of the plugin from your system, then perform the following steps.', 'event_espresso'); ?></p>
48
+	<p class="important-notice"><?php printf(esc_html__('Please note: %sThis is permanent and can NOT be undone.%s', 'event_espresso'), '<em>', '</em>'); ?><br/></p>
49 49
 	<ol>
50
-		<li><?php  printf( esc_html__('First, click the button below to permanently delete all Event Espresso tables, records, and options from your WordPress database . If you receive a "500 Internal Server Error" or a blank white screen, it means the server has timed out due to the large number of records being updated. This is not a cause for concern. Simply %1$srefresh the page%2$s and the Database Update will continue where it left off.', 'event_espresso'), '<strong>', '</strong>' );?></li>
51
-		<li><?php printf( esc_html__('Then, locate Event Espresso on the WordPress Plugins page, and click on %sDelete%s', 'event_espresso'), '<strong>', '</strong>' ); ?></li>
52
-        <li><?php printf( esc_html__('Once you are on the Delete Plugin page, click on %sYes, Delete these files and data%s', 'event_espresso'), '<strong>', '</strong>' ); ?></li>
53
-		<li><?php printf( esc_html__('Note: Event Espresso 4 categories are %snot%s deleted by this script', 'event_espresso'), '<strong>', '</strong>' ); ?>
50
+		<li><?php  printf(esc_html__('First, click the button below to permanently delete all Event Espresso tables, records, and options from your WordPress database . If you receive a "500 Internal Server Error" or a blank white screen, it means the server has timed out due to the large number of records being updated. This is not a cause for concern. Simply %1$srefresh the page%2$s and the Database Update will continue where it left off.', 'event_espresso'), '<strong>', '</strong>'); ?></li>
51
+		<li><?php printf(esc_html__('Then, locate Event Espresso on the WordPress Plugins page, and click on %sDelete%s', 'event_espresso'), '<strong>', '</strong>'); ?></li>
52
+        <li><?php printf(esc_html__('Once you are on the Delete Plugin page, click on %sYes, Delete these files and data%s', 'event_espresso'), '<strong>', '</strong>'); ?></li>
53
+		<li><?php printf(esc_html__('Note: Event Espresso 4 categories are %snot%s deleted by this script', 'event_espresso'), '<strong>', '</strong>'); ?>
54 54
 		<br><a href="<?php echo admin_url('edit-tags.php?taxonomy=espresso_event_categories'); ?>"><?php esc_html_e('You can go here to delete Event Espresso categories', 'event_espresso'); ?></a></li>
55 55
 	</ol>
56
-	<div class="float-right"><a href="<?php echo $delete_db_url; ?>" id="delete-all-data-btn" class="button-primary ee-confirm"><?php esc_html_e('Permanently Delete All Event Espresso Data', 'event_espresso');?></a></div>
56
+	<div class="float-right"><a href="<?php echo $delete_db_url; ?>" id="delete-all-data-btn" class="button-primary ee-confirm"><?php esc_html_e('Permanently Delete All Event Espresso Data', 'event_espresso'); ?></a></div>
57 57
 	<div class="clear"></div>
58 58
 </div>
59 59
 <br/>
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_DMS_Core_4_9_0.dms.php 2 patches
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@  discard block
 block discarded – undo
12 12
 $stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*');
13 13
 $class_to_filepath = array();
14 14
 foreach ($stages as $filepath) {
15
-    $matches = array();
16
-    preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
-    $class_to_filepath[$matches[1]] = $filepath;
15
+	$matches = array();
16
+	preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
+	$class_to_filepath[$matches[1]] = $filepath;
18 18
 }
19 19
 //give addons a chance to autoload their stages too
20 20
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath);
@@ -33,68 +33,68 @@  discard block
 block discarded – undo
33 33
 class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base
34 34
 {
35 35
 
36
-    /**
37
-     * return EE_DMS_Core_4_9_0
38
-     *
39
-     * @param TableManager  $table_manager
40
-     * @param TableAnalysis $table_analysis
41
-     */
42
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
-    {
44
-        $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso");
45
-        $this->_priority = 10;
46
-        $this->_migration_stages = array(
47
-            new EE_DMS_4_9_0_Email_System_Question(),
48
-            new EE_DMS_4_9_0_Answers_With_No_Registration(),
49
-        );
50
-        parent::__construct($table_manager, $table_analysis);
51
-    }
36
+	/**
37
+	 * return EE_DMS_Core_4_9_0
38
+	 *
39
+	 * @param TableManager  $table_manager
40
+	 * @param TableAnalysis $table_analysis
41
+	 */
42
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
+	{
44
+		$this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso");
45
+		$this->_priority = 10;
46
+		$this->_migration_stages = array(
47
+			new EE_DMS_4_9_0_Email_System_Question(),
48
+			new EE_DMS_4_9_0_Answers_With_No_Registration(),
49
+		);
50
+		parent::__construct($table_manager, $table_analysis);
51
+	}
52 52
 
53 53
 
54 54
 
55
-    /**
56
-     * Whether to migrate or not.
57
-     *
58
-     * @param array $version_array
59
-     * @return bool
60
-     */
61
-    public function can_migrate_from_version($version_array)
62
-    {
63
-        $version_string = $version_array['Core'];
64
-        if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) {
65
-            //			echo "$version_string can be migrated from";
66
-            return true;
67
-        } elseif ( ! $version_string) {
68
-            //			echo "no version string provided: $version_string";
69
-            //no version string provided... this must be pre 4.3
70
-            return false;//changed mind. dont want people thinking they should migrate yet because they cant
71
-        } else {
72
-            //			echo "$version_string doesnt apply";
73
-            return false;
74
-        }
75
-    }
55
+	/**
56
+	 * Whether to migrate or not.
57
+	 *
58
+	 * @param array $version_array
59
+	 * @return bool
60
+	 */
61
+	public function can_migrate_from_version($version_array)
62
+	{
63
+		$version_string = $version_array['Core'];
64
+		if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) {
65
+			//			echo "$version_string can be migrated from";
66
+			return true;
67
+		} elseif ( ! $version_string) {
68
+			//			echo "no version string provided: $version_string";
69
+			//no version string provided... this must be pre 4.3
70
+			return false;//changed mind. dont want people thinking they should migrate yet because they cant
71
+		} else {
72
+			//			echo "$version_string doesnt apply";
73
+			return false;
74
+		}
75
+	}
76 76
 
77 77
 
78 78
 
79
-    /**
80
-     * @return bool
81
-     */
82
-    public function schema_changes_before_migration()
83
-    {
84
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
-        $now_in_mysql = current_time('mysql', true);
86
-        $table_name = 'esp_answer';
87
-        $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
79
+	/**
80
+	 * @return bool
81
+	 */
82
+	public function schema_changes_before_migration()
83
+	{
84
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
+		$now_in_mysql = current_time('mysql', true);
86
+		$table_name = 'esp_answer';
87
+		$sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
88 88
 					REG_ID int(10) unsigned NOT NULL,
89 89
 					QST_ID int(10) unsigned NOT NULL,
90 90
 					ANS_value text NOT NULL,
91 91
 					PRIMARY KEY  (ANS_ID),
92 92
 					KEY REG_ID (REG_ID),
93 93
 					KEY QST_ID (QST_ID)";
94
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
95
-        $table_name = 'esp_attendee_meta';
96
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email');
97
-        $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
94
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
95
+		$table_name = 'esp_attendee_meta';
96
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email');
97
+		$sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
98 98
 				ATT_ID bigint(20) unsigned NOT NULL,
99 99
 				ATT_fname varchar(45) NOT NULL,
100 100
 				ATT_lname varchar(45) NOT NULL,
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 				KEY ATT_email (ATT_email(191)),
112 112
 				KEY ATT_lname (ATT_lname),
113 113
 				KEY ATT_fname (ATT_fname)";
114
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
115
-        $table_name = 'esp_checkin';
116
-        $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
114
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
115
+		$table_name = 'esp_checkin';
116
+		$sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
117 117
 				REG_ID int(10) unsigned NOT NULL,
118 118
 				DTT_ID int(10) unsigned NOT NULL,
119 119
 				CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 				PRIMARY KEY  (CHK_ID),
122 122
 				KEY REG_ID (REG_ID),
123 123
 				KEY DTT_ID (DTT_ID)";
124
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
125
-        $table_name = 'esp_country';
126
-        $sql = "CNT_ISO varchar(2) NOT NULL,
124
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
125
+		$table_name = 'esp_country';
126
+		$sql = "CNT_ISO varchar(2) NOT NULL,
127 127
 				CNT_ISO3 varchar(3) NOT NULL,
128 128
 				RGN_ID tinyint(3) unsigned DEFAULT NULL,
129 129
 				CNT_name varchar(45) NOT NULL,
@@ -139,29 +139,29 @@  discard block
 block discarded – undo
139 139
 				CNT_is_EU tinyint(1) DEFAULT '0',
140 140
 				CNT_active tinyint(1) DEFAULT '0',
141 141
 				PRIMARY KEY  (CNT_ISO)";
142
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
143
-        $table_name = 'esp_currency';
144
-        $sql = "CUR_code varchar(6) NOT NULL,
142
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
143
+		$table_name = 'esp_currency';
144
+		$sql = "CUR_code varchar(6) NOT NULL,
145 145
 				CUR_single varchar(45) DEFAULT 'dollar',
146 146
 				CUR_plural varchar(45) DEFAULT 'dollars',
147 147
 				CUR_sign varchar(45) DEFAULT '$',
148 148
 				CUR_dec_plc varchar(1) NOT NULL DEFAULT '2',
149 149
 				CUR_active tinyint(1) DEFAULT '0',
150 150
 				PRIMARY KEY  (CUR_code)";
151
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
152
-        //note: although this table is no longer in use,
153
-        //it hasn't been removed because then queries to the model will have errors.
154
-        //but you should expect this table and its corresponding model to be removed in
155
-        //the next few months
156
-        $table_name = 'esp_currency_payment_method';
157
-        $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT,
151
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
152
+		//note: although this table is no longer in use,
153
+		//it hasn't been removed because then queries to the model will have errors.
154
+		//but you should expect this table and its corresponding model to be removed in
155
+		//the next few months
156
+		$table_name = 'esp_currency_payment_method';
157
+		$sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT,
158 158
 				CUR_code varchar(6) NOT NULL,
159 159
 				PMD_ID int(11) NOT NULL,
160 160
 				PRIMARY KEY  (CPM_ID),
161 161
 				KEY PMD_ID (PMD_ID)";
162
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
163
-        $table_name = 'esp_datetime';
164
-        $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
162
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
163
+		$table_name = 'esp_datetime';
164
+		$sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
165 165
 				EVT_ID bigint(20) unsigned NOT NULL,
166 166
 				DTT_name varchar(255) NOT NULL DEFAULT '',
167 167
 				DTT_description text NOT NULL,
@@ -178,25 +178,25 @@  discard block
 block discarded – undo
178 178
 				KEY DTT_EVT_start (DTT_EVT_start),
179 179
 				KEY EVT_ID (EVT_ID),
180 180
 				KEY DTT_is_primary (DTT_is_primary)";
181
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
182
-        $table_name = "esp_datetime_ticket";
183
-        $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
181
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
182
+		$table_name = "esp_datetime_ticket";
183
+		$sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
184 184
 				DTT_ID int(10) unsigned NOT NULL,
185 185
 				TKT_ID int(10) unsigned NOT NULL,
186 186
 				PRIMARY KEY  (DTK_ID),
187 187
 				KEY DTT_ID (DTT_ID),
188 188
 				KEY TKT_ID (TKT_ID)";
189
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
190
-        $table_name = 'esp_event_message_template';
191
-        $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
189
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
190
+		$table_name = 'esp_event_message_template';
191
+		$sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
192 192
 				EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0,
193 193
 				GRP_ID int(10) unsigned NOT NULL DEFAULT 0,
194 194
 				PRIMARY KEY  (EMT_ID),
195 195
 				KEY EVT_ID (EVT_ID),
196 196
 				KEY GRP_ID (GRP_ID)";
197
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
198
-        $table_name = 'esp_event_meta';
199
-        $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
197
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
198
+		$table_name = 'esp_event_meta';
199
+		$sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
200 200
 				EVT_ID bigint(20) unsigned NOT NULL,
201 201
 				EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1,
202 202
 				EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -211,34 +211,34 @@  discard block
 block discarded – undo
211 211
 				EVT_donations tinyint(1) NULL,
212 212
 				PRIMARY KEY  (EVTM_ID),
213 213
 				KEY EVT_ID (EVT_ID)";
214
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
215
-        $table_name = 'esp_event_question_group';
216
-        $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
214
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
215
+		$table_name = 'esp_event_question_group';
216
+		$sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
217 217
 				EVT_ID bigint(20) unsigned NOT NULL,
218 218
 				QSG_ID int(10) unsigned NOT NULL,
219 219
 				EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
220 220
 				PRIMARY KEY  (EQG_ID),
221 221
 				KEY EVT_ID (EVT_ID),
222 222
 				KEY QSG_ID (QSG_ID)";
223
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
224
-        $table_name = 'esp_event_venue';
225
-        $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
223
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
224
+		$table_name = 'esp_event_venue';
225
+		$sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
226 226
 				EVT_ID bigint(20) unsigned NOT NULL,
227 227
 				VNU_ID bigint(20) unsigned NOT NULL,
228 228
 				EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
229 229
 				PRIMARY KEY  (EVV_ID)";
230
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
231
-        $table_name = 'esp_extra_meta';
232
-        $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
230
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
231
+		$table_name = 'esp_extra_meta';
232
+		$sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
233 233
 				OBJ_ID int(11) DEFAULT NULL,
234 234
 				EXM_type varchar(45) DEFAULT NULL,
235 235
 				EXM_key varchar(45) DEFAULT NULL,
236 236
 				EXM_value text,
237 237
 				PRIMARY KEY  (EXM_ID),
238 238
 				KEY EXM_type (EXM_type,OBJ_ID,EXM_key)";
239
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
240
-        $table_name = 'esp_extra_join';
241
-        $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
239
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
240
+		$table_name = 'esp_extra_join';
241
+		$sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
242 242
 				EXJ_first_model_id varchar(6) NOT NULL,
243 243
 				EXJ_first_model_name varchar(20) NOT NULL,
244 244
 				EXJ_second_model_id varchar(6) NOT NULL,
@@ -246,9 +246,9 @@  discard block
 block discarded – undo
246 246
 				PRIMARY KEY  (EXJ_ID),
247 247
 				KEY first_model (EXJ_first_model_name,EXJ_first_model_id),
248 248
 				KEY second_model (EXJ_second_model_name,EXJ_second_model_id)";
249
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
250
-        $table_name = 'esp_line_item';
251
-        $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
249
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
250
+		$table_name = 'esp_line_item';
251
+		$sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
252 252
 				LIN_code varchar(245) NOT NULL DEFAULT '',
253 253
 				TXN_ID int(11) DEFAULT NULL,
254 254
 				LIN_name varchar(245) NOT NULL DEFAULT '',
@@ -267,9 +267,9 @@  discard block
 block discarded – undo
267 267
 				PRIMARY KEY  (LIN_ID),
268 268
 				KEY LIN_code (LIN_code(191)),
269 269
 				KEY TXN_ID (TXN_ID)";
270
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
271
-        $table_name = 'esp_log';
272
-        $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
270
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
271
+		$table_name = 'esp_log';
272
+		$sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
273 273
 				LOG_time datetime DEFAULT NULL,
274 274
 				OBJ_ID varchar(45) DEFAULT NULL,
275 275
 				OBJ_type varchar(45) DEFAULT NULL,
@@ -280,12 +280,12 @@  discard block
 block discarded – undo
280 280
 				KEY LOG_time (LOG_time),
281 281
 				KEY OBJ (OBJ_type,OBJ_ID),
282 282
 				KEY LOG_type (LOG_type)";
283
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
284
-        $table_name = 'esp_message';
285
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to');
286
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from');
287
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject');
288
-        $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
283
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
284
+		$table_name = 'esp_message';
285
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to');
286
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from');
287
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject');
288
+		$sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
289 289
 				GRP_ID int(10) unsigned NULL,
290 290
 				MSG_token varchar(255) NULL,
291 291
 				TXN_ID int(10) unsigned NULL,
@@ -317,18 +317,18 @@  discard block
 block discarded – undo
317 317
 				KEY STS_ID (STS_ID),
318 318
 				KEY MSG_created (MSG_created),
319 319
 				KEY MSG_modified (MSG_modified)";
320
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
321
-        $table_name = 'esp_message_template';
322
-        $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
320
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
321
+		$table_name = 'esp_message_template';
322
+		$sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
323 323
 				GRP_ID int(10) unsigned NOT NULL,
324 324
 				MTP_context varchar(50) NOT NULL,
325 325
 				MTP_template_field varchar(30) NOT NULL,
326 326
 				MTP_content text NOT NULL,
327 327
 				PRIMARY KEY  (MTP_ID),
328 328
 				KEY GRP_ID (GRP_ID)";
329
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
330
-        $table_name = 'esp_message_template_group';
331
-        $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
329
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
330
+		$table_name = 'esp_message_template_group';
331
+		$sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
332 332
 				MTP_user_id int(10) NOT NULL DEFAULT '1',
333 333
 				MTP_name varchar(245) NOT NULL DEFAULT '',
334 334
 				MTP_description varchar(245) NOT NULL DEFAULT '',
@@ -340,9 +340,9 @@  discard block
 block discarded – undo
340 340
 				MTP_is_active tinyint(1) NOT NULL DEFAULT '1',
341 341
 				PRIMARY KEY  (GRP_ID),
342 342
 				KEY MTP_user_id (MTP_user_id)";
343
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
344
-        $table_name = 'esp_payment';
345
-        $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
343
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
344
+		$table_name = 'esp_payment';
345
+		$sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
346 346
 				TXN_ID int(10) unsigned DEFAULT NULL,
347 347
 				STS_ID varchar(3) DEFAULT NULL,
348 348
 				PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -359,9 +359,9 @@  discard block
 block discarded – undo
359 359
 				PRIMARY KEY  (PAY_ID),
360 360
 				KEY PAY_timestamp (PAY_timestamp),
361 361
 				KEY TXN_ID (TXN_ID)";
362
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
363
-        $table_name = 'esp_payment_method';
364
-        $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
362
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
363
+		$table_name = 'esp_payment_method';
364
+		$sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
365 365
 				PMD_type varchar(124) DEFAULT NULL,
366 366
 				PMD_name varchar(255) DEFAULT NULL,
367 367
 				PMD_desc text,
@@ -377,24 +377,24 @@  discard block
 block discarded – undo
377 377
 				PRIMARY KEY  (PMD_ID),
378 378
 				UNIQUE KEY PMD_slug_UNIQUE (PMD_slug),
379 379
 				KEY PMD_type (PMD_type)";
380
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
381
-        $table_name = "esp_ticket_price";
382
-        $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
380
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
381
+		$table_name = "esp_ticket_price";
382
+		$sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
383 383
 				TKT_ID int(10) unsigned NOT NULL,
384 384
 				PRC_ID int(10) unsigned NOT NULL,
385 385
 				PRIMARY KEY  (TKP_ID),
386 386
 				KEY TKT_ID (TKT_ID),
387 387
 				KEY PRC_ID (PRC_ID)";
388
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
389
-        $table_name = "esp_ticket_template";
390
-        $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
388
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
389
+		$table_name = "esp_ticket_template";
390
+		$sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
391 391
 				TTM_name varchar(45) NOT NULL,
392 392
 				TTM_description text,
393 393
 				TTM_file varchar(45),
394 394
 				PRIMARY KEY  (TTM_ID)";
395
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
396
-        $table_name = 'esp_question';
397
-        $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
395
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
396
+		$table_name = 'esp_question';
397
+		$sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
398 398
 				QST_display_text text NOT NULL,
399 399
 				QST_admin_label varchar(255) NOT NULL,
400 400
 				QST_system varchar(25) DEFAULT NULL,
@@ -408,18 +408,18 @@  discard block
 block discarded – undo
408 408
 				QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0,
409 409
 				PRIMARY KEY  (QST_ID),
410 410
 				KEY QST_order (QST_order)';
411
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
412
-        $table_name = 'esp_question_group_question';
413
-        $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
411
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
412
+		$table_name = 'esp_question_group_question';
413
+		$sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
414 414
 				QSG_ID int(10) unsigned NOT NULL,
415 415
 				QST_ID int(10) unsigned NOT NULL,
416 416
 				QGQ_order int(10) unsigned NOT NULL DEFAULT 0,
417 417
 				PRIMARY KEY  (QGQ_ID),
418 418
 				KEY QST_ID (QST_ID),
419 419
 				KEY QSG_ID_order (QSG_ID,QGQ_order)";
420
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
421
-        $table_name = 'esp_question_option';
422
-        $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
420
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
421
+		$table_name = 'esp_question_option';
422
+		$sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
423 423
 				QSO_value varchar(255) NOT NULL,
424 424
 				QSO_desc text NOT NULL,
425 425
 				QST_ID int(10) unsigned NOT NULL,
@@ -429,9 +429,9 @@  discard block
 block discarded – undo
429 429
 				PRIMARY KEY  (QSO_ID),
430 430
 				KEY QST_ID (QST_ID),
431 431
 				KEY QSO_order (QSO_order)";
432
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
433
-        $table_name = 'esp_registration';
434
-        $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
432
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
433
+		$table_name = 'esp_registration';
434
+		$sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
435 435
 				EVT_ID bigint(20) unsigned NOT NULL,
436 436
 				ATT_ID bigint(20) unsigned NOT NULL,
437 437
 				TXN_ID int(10) unsigned NOT NULL,
@@ -455,18 +455,18 @@  discard block
 block discarded – undo
455 455
 				KEY TKT_ID (TKT_ID),
456 456
 				KEY EVT_ID (EVT_ID),
457 457
 				KEY STS_ID (STS_ID)";
458
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
459
-        $table_name = 'esp_registration_payment';
460
-        $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
458
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
459
+		$table_name = 'esp_registration_payment';
460
+		$sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
461 461
 					  REG_ID int(10) unsigned NOT NULL,
462 462
 					  PAY_ID int(10) unsigned NULL,
463 463
 					  RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00',
464 464
 					  PRIMARY KEY  (RPY_ID),
465 465
 					  KEY REG_ID (REG_ID),
466 466
 					  KEY PAY_ID (PAY_ID)";
467
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
468
-        $table_name = 'esp_state';
469
-        $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
467
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
468
+		$table_name = 'esp_state';
469
+		$sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
470 470
 				CNT_ISO varchar(2) NOT NULL,
471 471
 				STA_abbrev varchar(24) NOT NULL,
472 472
 				STA_name varchar(100) NOT NULL,
@@ -474,9 +474,9 @@  discard block
 block discarded – undo
474 474
 				PRIMARY KEY  (STA_ID),
475 475
 				KEY STA_abbrev (STA_abbrev),
476 476
 				KEY CNT_ISO (CNT_ISO)";
477
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
478
-        $table_name = 'esp_status';
479
-        $sql = "STS_ID varchar(3) NOT NULL,
477
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
478
+		$table_name = 'esp_status';
479
+		$sql = "STS_ID varchar(3) NOT NULL,
480 480
 				STS_code varchar(45) NOT NULL,
481 481
 				STS_type varchar(45) NOT NULL,
482 482
 				STS_can_edit tinyint(1) NOT NULL DEFAULT 0,
@@ -484,9 +484,9 @@  discard block
 block discarded – undo
484 484
 				STS_open tinyint(1) NOT NULL DEFAULT 1,
485 485
 				UNIQUE KEY STS_ID_UNIQUE (STS_ID),
486 486
 				KEY STS_type (STS_type)";
487
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
488
-        $table_name = 'esp_transaction';
489
-        $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
487
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
488
+		$table_name = 'esp_transaction';
489
+		$sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
490 490
 				TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
491 491
 				TXN_total decimal(12,3) DEFAULT '0.00',
492 492
 				TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00',
@@ -498,9 +498,9 @@  discard block
 block discarded – undo
498 498
 				PRIMARY KEY  (TXN_ID),
499 499
 				KEY TXN_timestamp (TXN_timestamp),
500 500
 				KEY STS_ID (STS_ID)";
501
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
502
-        $table_name = 'esp_venue_meta';
503
-        $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
501
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
502
+		$table_name = 'esp_venue_meta';
503
+		$sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
504 504
 			VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0,
505 505
 			VNU_address varchar(255) DEFAULT NULL,
506 506
 			VNU_address2 varchar(255) DEFAULT NULL,
@@ -519,10 +519,10 @@  discard block
 block discarded – undo
519 519
 			KEY VNU_ID (VNU_ID),
520 520
 			KEY STA_ID (STA_ID),
521 521
 			KEY CNT_ISO (CNT_ISO)";
522
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
523
-        //modified tables
524
-        $table_name = "esp_price";
525
-        $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
522
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
523
+		//modified tables
524
+		$table_name = "esp_price";
525
+		$sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
526 526
 				PRT_ID tinyint(3) unsigned NOT NULL,
527 527
 				PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00',
528 528
 				PRC_name varchar(245) NOT NULL,
@@ -535,9 +535,9 @@  discard block
 block discarded – undo
535 535
 				PRC_parent int(10) unsigned DEFAULT 0,
536 536
 				PRIMARY KEY  (PRC_ID),
537 537
 				KEY PRT_ID (PRT_ID)";
538
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
539
-        $table_name = "esp_price_type";
540
-        $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
538
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
539
+		$table_name = "esp_price_type";
540
+		$sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
541 541
 				PRT_name varchar(45) NOT NULL,
542 542
 				PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1',
543 543
 				PRT_is_percent tinyint(1) NOT NULL DEFAULT '0',
@@ -546,9 +546,9 @@  discard block
 block discarded – undo
546 546
 				PRT_deleted tinyint(1) NOT NULL DEFAULT '0',
547 547
 				UNIQUE KEY PRT_name_UNIQUE (PRT_name),
548 548
 				PRIMARY KEY  (PRT_ID)";
549
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
550
-        $table_name = "esp_ticket";
551
-        $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
549
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
550
+		$table_name = "esp_ticket";
551
+		$sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
552 552
 				TTM_ID int(10) unsigned NOT NULL,
553 553
 				TKT_name varchar(245) NOT NULL DEFAULT '',
554 554
 				TKT_description text NOT NULL,
@@ -571,9 +571,9 @@  discard block
 block discarded – undo
571 571
 				TKT_deleted tinyint(1) NOT NULL DEFAULT '0',
572 572
 				PRIMARY KEY  (TKT_ID),
573 573
 				KEY TKT_start_date (TKT_start_date)";
574
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
575
-        $table_name = 'esp_question_group';
576
-        $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
574
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
575
+		$table_name = 'esp_question_group';
576
+		$sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
577 577
 				QSG_name varchar(255) NOT NULL,
578 578
 				QSG_identifier varchar(100) NOT NULL,
579 579
 				QSG_desc text NULL,
@@ -586,145 +586,145 @@  discard block
 block discarded – undo
586 586
 				PRIMARY KEY  (QSG_ID),
587 587
 				UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier),
588 588
 				KEY QSG_order (QSG_order)';
589
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
590
-        /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
591
-        $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
592
-        //(because many need to convert old string states to foreign keys into the states table)
593
-        $script_4_1_defaults->insert_default_states();
594
-        $script_4_1_defaults->insert_default_countries();
595
-        /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
596
-        $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
597
-        $script_4_5_defaults->insert_default_price_types();
598
-        $script_4_5_defaults->insert_default_prices();
599
-        $script_4_5_defaults->insert_default_tickets();
600
-        /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
601
-        $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
602
-        $script_4_6_defaults->add_default_admin_only_payments();
603
-        $script_4_6_defaults->insert_default_currencies();
604
-        /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */
605
-        $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0');
606
-        $script_4_8_defaults->verify_new_countries();
607
-        $script_4_8_defaults->verify_new_currencies();
608
-        $this->verify_db_collations();
609
-        $this->verify_db_collations_again();
610
-        return true;
611
-    }
589
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
590
+		/** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
591
+		$script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
592
+		//(because many need to convert old string states to foreign keys into the states table)
593
+		$script_4_1_defaults->insert_default_states();
594
+		$script_4_1_defaults->insert_default_countries();
595
+		/** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
596
+		$script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
597
+		$script_4_5_defaults->insert_default_price_types();
598
+		$script_4_5_defaults->insert_default_prices();
599
+		$script_4_5_defaults->insert_default_tickets();
600
+		/** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
601
+		$script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
602
+		$script_4_6_defaults->add_default_admin_only_payments();
603
+		$script_4_6_defaults->insert_default_currencies();
604
+		/** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */
605
+		$script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0');
606
+		$script_4_8_defaults->verify_new_countries();
607
+		$script_4_8_defaults->verify_new_currencies();
608
+		$this->verify_db_collations();
609
+		$this->verify_db_collations_again();
610
+		return true;
611
+	}
612 612
 
613 613
 
614 614
 
615
-    /**
616
-     * @return boolean
617
-     */
618
-    public function schema_changes_after_migration()
619
-    {
620
-        return true;
621
-    }
615
+	/**
616
+	 * @return boolean
617
+	 */
618
+	public function schema_changes_after_migration()
619
+	{
620
+		return true;
621
+	}
622 622
 
623 623
 
624 624
 
625
-    public function migration_page_hooks()
626
-    {
627
-    }
625
+	public function migration_page_hooks()
626
+	{
627
+	}
628 628
 
629 629
 
630 630
 
631
-    /**
632
-     * Verify all EE4 models' tables use utf8mb4 collation
633
-     *
634
-     * @return void
635
-     */
636
-    public function verify_db_collations()
637
-    {
638
-        global $wpdb;
639
-        //double-check we haven't already done it or that that the DB doesn't support utf8mb4
640
-        if ('utf8mb4' !== $wpdb->charset
641
-            || get_option('ee_verified_db_collations', false)) {
642
-            return;
643
-        }
644
-        // grab tables from each model
645
-        $tables_to_check = array();
646
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
647
-            if (method_exists($model_name, 'instance')) {
648
-                $model_obj = call_user_func(array($model_name, 'instance'));
649
-                if ($model_obj instanceof EEM_Base) {
650
-                    foreach ($model_obj->get_tables() as $table) {
651
-                        if (
652
-                            strpos($table->get_table_name(), 'esp_')
653
-                            && (is_main_site()//for main tables, verify global tables
654
-                                || ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up)
655
-                            )
656
-                            && function_exists('maybe_convert_table_to_utf8mb4')
657
-                        ) {
658
-                            $tables_to_check[] = $table->get_table_name();
659
-                        }
660
-                    }
661
-                }
662
-            }
663
-        }
664
-        //and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active
665
-        //when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead
666
-        //of hard-coding this
667
-        $addon_tables = array(
668
-            //mailchimp
669
-            'esp_event_mailchimp_list_group',
670
-            'esp_event_question_mailchimp_field',
671
-            //multisite
672
-            'esp_blog_meta',
673
-            //people
674
-            'esp_people_to_post',
675
-            //promotions
676
-            'esp_promotion',
677
-            'esp_promotion_object',
678
-        );
679
-        foreach ($addon_tables as $table_name) {
680
-                $tables_to_check[] = $table_name;
681
-        }
682
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
683
-        //ok and now let's remember this was done (without needing to check the db schemas all over again)
684
-        add_option('ee_verified_db_collations', true, null, 'no');
685
-        //seeing how this ran with the fix from 10435, no need to check again
686
-        add_option('ee_verified_db_collations_again',true,null,'no');
687
-    }
631
+	/**
632
+	 * Verify all EE4 models' tables use utf8mb4 collation
633
+	 *
634
+	 * @return void
635
+	 */
636
+	public function verify_db_collations()
637
+	{
638
+		global $wpdb;
639
+		//double-check we haven't already done it or that that the DB doesn't support utf8mb4
640
+		if ('utf8mb4' !== $wpdb->charset
641
+			|| get_option('ee_verified_db_collations', false)) {
642
+			return;
643
+		}
644
+		// grab tables from each model
645
+		$tables_to_check = array();
646
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
647
+			if (method_exists($model_name, 'instance')) {
648
+				$model_obj = call_user_func(array($model_name, 'instance'));
649
+				if ($model_obj instanceof EEM_Base) {
650
+					foreach ($model_obj->get_tables() as $table) {
651
+						if (
652
+							strpos($table->get_table_name(), 'esp_')
653
+							&& (is_main_site()//for main tables, verify global tables
654
+								|| ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up)
655
+							)
656
+							&& function_exists('maybe_convert_table_to_utf8mb4')
657
+						) {
658
+							$tables_to_check[] = $table->get_table_name();
659
+						}
660
+					}
661
+				}
662
+			}
663
+		}
664
+		//and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active
665
+		//when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead
666
+		//of hard-coding this
667
+		$addon_tables = array(
668
+			//mailchimp
669
+			'esp_event_mailchimp_list_group',
670
+			'esp_event_question_mailchimp_field',
671
+			//multisite
672
+			'esp_blog_meta',
673
+			//people
674
+			'esp_people_to_post',
675
+			//promotions
676
+			'esp_promotion',
677
+			'esp_promotion_object',
678
+		);
679
+		foreach ($addon_tables as $table_name) {
680
+				$tables_to_check[] = $table_name;
681
+		}
682
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
683
+		//ok and now let's remember this was done (without needing to check the db schemas all over again)
684
+		add_option('ee_verified_db_collations', true, null, 'no');
685
+		//seeing how this ran with the fix from 10435, no need to check again
686
+		add_option('ee_verified_db_collations_again',true,null,'no');
687
+	}
688 688
 
689 689
 
690 690
 
691
-    /**
692
-     * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
693
-     * which meant some DB collations might not have been updated
694
-     * @return void
695
-     */
696
-    public function verify_db_collations_again(){
697
-        global $wpdb;
698
-        //double-check we haven't already done this or that the DB doesn't support it
699
-        //compare to how WordPress' upgrade_430() function does this check
700
-        if ('utf8mb4' !== $wpdb->charset
701
-            || get_option('ee_verified_db_collations_again', false)) {
702
-            return;
703
-        }
704
-        $tables_to_check = array(
705
-            'esp_attendee_meta',
706
-            'esp_message'
707
-        );
708
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
709
-        add_option('ee_verified_db_collations_again',true,null,'no');
710
-    }
691
+	/**
692
+	 * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
693
+	 * which meant some DB collations might not have been updated
694
+	 * @return void
695
+	 */
696
+	public function verify_db_collations_again(){
697
+		global $wpdb;
698
+		//double-check we haven't already done this or that the DB doesn't support it
699
+		//compare to how WordPress' upgrade_430() function does this check
700
+		if ('utf8mb4' !== $wpdb->charset
701
+			|| get_option('ee_verified_db_collations_again', false)) {
702
+			return;
703
+		}
704
+		$tables_to_check = array(
705
+			'esp_attendee_meta',
706
+			'esp_message'
707
+		);
708
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
709
+		add_option('ee_verified_db_collations_again',true,null,'no');
710
+	}
711 711
 
712 712
 
713 713
 
714
-    /**
715
-     * Runs maybe_convert_table_to_utf8mb4 on the specified tables
716
-     * @param $tables_to_check
717
-     * @return boolean true if logic ran, false if it didn't
718
-     */
719
-    protected function _verify_db_collations_for_tables($tables_to_check)
720
-    {
721
-        foreach ($tables_to_check as $table_name) {
722
-            $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
723
-            if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name )
724
-                && $this->_get_table_analysis()->tableExists($table_name)
725
-            ) {
726
-                maybe_convert_table_to_utf8mb4($table_name);
727
-            }
728
-        }
729
-    }
714
+	/**
715
+	 * Runs maybe_convert_table_to_utf8mb4 on the specified tables
716
+	 * @param $tables_to_check
717
+	 * @return boolean true if logic ran, false if it didn't
718
+	 */
719
+	protected function _verify_db_collations_for_tables($tables_to_check)
720
+	{
721
+		foreach ($tables_to_check as $table_name) {
722
+			$table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
723
+			if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name )
724
+				&& $this->_get_table_analysis()->tableExists($table_name)
725
+			) {
726
+				maybe_convert_table_to_utf8mb4($table_name);
727
+			}
728
+		}
729
+	}
730 730
 }
731 731
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 //unfortunately, this needs to be done upon INCLUSION of this file,
10 10
 //instead of construction, because it only gets constructed on first page load
11 11
 //(all other times it gets resurrected from a wordpress option)
12
-$stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*');
12
+$stages = glob(EE_CORE.'data_migration_scripts/4_9_0_stages/*');
13 13
 $class_to_filepath = array();
14 14
 foreach ($stages as $filepath) {
15 15
     $matches = array();
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         } elseif ( ! $version_string) {
68 68
             //			echo "no version string provided: $version_string";
69 69
             //no version string provided... this must be pre 4.3
70
-            return false;//changed mind. dont want people thinking they should migrate yet because they cant
70
+            return false; //changed mind. dont want people thinking they should migrate yet because they cant
71 71
         } else {
72 72
             //			echo "$version_string doesnt apply";
73 73
             return false;
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function schema_changes_before_migration()
83 83
     {
84
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
84
+        require_once(EE_HELPERS.'EEH_Activation.helper.php');
85 85
         $now_in_mysql = current_time('mysql', true);
86 86
         $table_name = 'esp_answer';
87 87
         $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
         //ok and now let's remember this was done (without needing to check the db schemas all over again)
684 684
         add_option('ee_verified_db_collations', true, null, 'no');
685 685
         //seeing how this ran with the fix from 10435, no need to check again
686
-        add_option('ee_verified_db_collations_again',true,null,'no');
686
+        add_option('ee_verified_db_collations_again', true, null, 'no');
687 687
     }
688 688
 
689 689
 
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
      * which meant some DB collations might not have been updated
694 694
      * @return void
695 695
      */
696
-    public function verify_db_collations_again(){
696
+    public function verify_db_collations_again() {
697 697
         global $wpdb;
698 698
         //double-check we haven't already done this or that the DB doesn't support it
699 699
         //compare to how WordPress' upgrade_430() function does this check
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
             'esp_message'
707 707
         );
708 708
         $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
709
-        add_option('ee_verified_db_collations_again',true,null,'no');
709
+        add_option('ee_verified_db_collations_again', true, null, 'no');
710 710
     }
711 711
 
712 712
 
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
     {
721 721
         foreach ($tables_to_check as $table_name) {
722 722
             $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
723
-            if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name )
723
+            if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name)
724 724
                 && $this->_get_table_analysis()->tableExists($table_name)
725 725
             ) {
726 726
                 maybe_convert_table_to_utf8mb4($table_name);
Please login to merge, or discard this patch.
admin/extend/registrations/Extend_Registrations_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -924,7 +924,7 @@
 block discarded – undo
924 924
      * handles toggling the checkin status for the registration,
925 925
      *
926 926
      * @access protected
927
-     * @return int|void
927
+     * @return integer
928 928
      * @throws EE_Error
929 929
      * @throws InvalidArgumentException
930 930
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Indentation   +1197 added lines, -1197 removed lines patch added patch discarded remove patch
@@ -18,1256 +18,1256 @@
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * This is used to hold the reports template data which is setup early in the request.
23
-     *
24
-     * @type array
25
-     */
26
-    protected $_reports_template_data = array();
21
+	/**
22
+	 * This is used to hold the reports template data which is setup early in the request.
23
+	 *
24
+	 * @type array
25
+	 */
26
+	protected $_reports_template_data = array();
27 27
 
28 28
 
29 29
 
30
-    /**
31
-     * Extend_Registrations_Admin_Page constructor.
32
-     *
33
-     * @param bool $routing
34
-     */
35
-    public function __construct($routing = true)
36
-    {
37
-        parent::__construct($routing);
38
-        if (! defined('REG_CAF_TEMPLATE_PATH')) {
39
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
40
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
41
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
42
-        }
43
-    }
30
+	/**
31
+	 * Extend_Registrations_Admin_Page constructor.
32
+	 *
33
+	 * @param bool $routing
34
+	 */
35
+	public function __construct($routing = true)
36
+	{
37
+		parent::__construct($routing);
38
+		if (! defined('REG_CAF_TEMPLATE_PATH')) {
39
+			define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
40
+			define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
41
+			define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
42
+		}
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     * Extending page configuration.
48
-     */
49
-    protected function _extend_page_config()
50
-    {
51
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
52
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
53
-            ? $this->_req_data['_REG_ID']
54
-            : 0;
55
-        $new_page_routes = array(
56
-            'reports'                  => array(
57
-                'func'       => '_registration_reports',
58
-                'capability' => 'ee_read_registrations',
59
-            ),
60
-            'registration_checkins'    => array(
61
-                'func'       => '_registration_checkin_list_table',
62
-                'capability' => 'ee_read_checkins',
63
-            ),
64
-            'newsletter_selected_send' => array(
65
-                'func'       => '_newsletter_selected_send',
66
-                'noheader'   => true,
67
-                'capability' => 'ee_send_message',
68
-            ),
69
-            'delete_checkin_rows'      => array(
70
-                'func'       => '_delete_checkin_rows',
71
-                'noheader'   => true,
72
-                'capability' => 'ee_delete_checkins',
73
-            ),
74
-            'delete_checkin_row'       => array(
75
-                'func'       => '_delete_checkin_row',
76
-                'noheader'   => true,
77
-                'capability' => 'ee_delete_checkin',
78
-                'obj_id'     => $reg_id,
79
-            ),
80
-            'toggle_checkin_status'    => array(
81
-                'func'       => '_toggle_checkin_status',
82
-                'noheader'   => true,
83
-                'capability' => 'ee_edit_checkin',
84
-                'obj_id'     => $reg_id,
85
-            ),
86
-            'toggle_checkin_status_bulk' => array(
87
-                'func' => '_toggle_checkin_status',
88
-                'noheader' => true,
89
-                'capability' => 'ee_edit_checkins'
90
-            ),
91
-            'event_registrations'      => array(
92
-                'func'       => '_event_registrations_list_table',
93
-                'capability' => 'ee_read_checkins',
94
-            ),
95
-            'registrations_checkin_report' => array(
96
-                'func'       => '_registrations_checkin_report',
97
-                'noheader'   => true,
98
-                'capability' => 'ee_read_registrations',
99
-            ),
100
-        );
101
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
102
-        $new_page_config = array(
103
-            'reports'               => array(
104
-                'nav'           => array(
105
-                    'label' => esc_html__('Reports', 'event_espresso'),
106
-                    'order' => 30,
107
-                ),
108
-                'help_tabs'     => array(
109
-                    'registrations_reports_help_tab' => array(
110
-                        'title'    => esc_html__('Registration Reports', 'event_espresso'),
111
-                        'filename' => 'registrations_reports',
112
-                    ),
113
-                ),
114
-                /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
115
-                'require_nonce' => false,
116
-            ),
117
-            'event_registrations'   => array(
118
-                'nav'           => array(
119
-                    'label'      => esc_html__('Event Check-In', 'event_espresso'),
120
-                    'order'      => 10,
121
-                    'persistent' => true,
122
-                ),
123
-                'help_tabs'     => array(
124
-                    'registrations_event_checkin_help_tab'                       => array(
125
-                        'title'    => esc_html__('Registrations Event Check-In', 'event_espresso'),
126
-                        'filename' => 'registrations_event_checkin',
127
-                    ),
128
-                    'registrations_event_checkin_table_column_headings_help_tab' => array(
129
-                        'title'    => esc_html__('Event Check-In Table Column Headings', 'event_espresso'),
130
-                        'filename' => 'registrations_event_checkin_table_column_headings',
131
-                    ),
132
-                    'registrations_event_checkin_filters_help_tab'               => array(
133
-                        'title'    => esc_html__('Event Check-In Filters', 'event_espresso'),
134
-                        'filename' => 'registrations_event_checkin_filters',
135
-                    ),
136
-                    'registrations_event_checkin_views_help_tab'                 => array(
137
-                        'title'    => esc_html__('Event Check-In Views', 'event_espresso'),
138
-                        'filename' => 'registrations_event_checkin_views',
139
-                    ),
140
-                    'registrations_event_checkin_other_help_tab'                 => array(
141
-                        'title'    => esc_html__('Event Check-In Other', 'event_espresso'),
142
-                        'filename' => 'registrations_event_checkin_other',
143
-                    ),
144
-                ),
145
-                'help_tour'     => array('Event_Checkin_Help_Tour'),
146
-                'qtips'         => array('Registration_List_Table_Tips'),
147
-                'list_table'    => 'EE_Event_Registrations_List_Table',
148
-                'metaboxes'     => array(),
149
-                'require_nonce' => false,
150
-            ),
151
-            'registration_checkins' => array(
152
-                'nav'           => array(
153
-                    'label'      => esc_html__('Check-In Records', 'event_espresso'),
154
-                    'order'      => 15,
155
-                    'persistent' => false,
156
-                ),
157
-                'list_table'    => 'EE_Registration_CheckIn_List_Table',
158
-                //'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
159
-                'metaboxes'     => array(),
160
-                'require_nonce' => false,
161
-            ),
162
-        );
163
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
164
-        $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
165
-        $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
166
-    }
46
+	/**
47
+	 * Extending page configuration.
48
+	 */
49
+	protected function _extend_page_config()
50
+	{
51
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
52
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
53
+			? $this->_req_data['_REG_ID']
54
+			: 0;
55
+		$new_page_routes = array(
56
+			'reports'                  => array(
57
+				'func'       => '_registration_reports',
58
+				'capability' => 'ee_read_registrations',
59
+			),
60
+			'registration_checkins'    => array(
61
+				'func'       => '_registration_checkin_list_table',
62
+				'capability' => 'ee_read_checkins',
63
+			),
64
+			'newsletter_selected_send' => array(
65
+				'func'       => '_newsletter_selected_send',
66
+				'noheader'   => true,
67
+				'capability' => 'ee_send_message',
68
+			),
69
+			'delete_checkin_rows'      => array(
70
+				'func'       => '_delete_checkin_rows',
71
+				'noheader'   => true,
72
+				'capability' => 'ee_delete_checkins',
73
+			),
74
+			'delete_checkin_row'       => array(
75
+				'func'       => '_delete_checkin_row',
76
+				'noheader'   => true,
77
+				'capability' => 'ee_delete_checkin',
78
+				'obj_id'     => $reg_id,
79
+			),
80
+			'toggle_checkin_status'    => array(
81
+				'func'       => '_toggle_checkin_status',
82
+				'noheader'   => true,
83
+				'capability' => 'ee_edit_checkin',
84
+				'obj_id'     => $reg_id,
85
+			),
86
+			'toggle_checkin_status_bulk' => array(
87
+				'func' => '_toggle_checkin_status',
88
+				'noheader' => true,
89
+				'capability' => 'ee_edit_checkins'
90
+			),
91
+			'event_registrations'      => array(
92
+				'func'       => '_event_registrations_list_table',
93
+				'capability' => 'ee_read_checkins',
94
+			),
95
+			'registrations_checkin_report' => array(
96
+				'func'       => '_registrations_checkin_report',
97
+				'noheader'   => true,
98
+				'capability' => 'ee_read_registrations',
99
+			),
100
+		);
101
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
102
+		$new_page_config = array(
103
+			'reports'               => array(
104
+				'nav'           => array(
105
+					'label' => esc_html__('Reports', 'event_espresso'),
106
+					'order' => 30,
107
+				),
108
+				'help_tabs'     => array(
109
+					'registrations_reports_help_tab' => array(
110
+						'title'    => esc_html__('Registration Reports', 'event_espresso'),
111
+						'filename' => 'registrations_reports',
112
+					),
113
+				),
114
+				/*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
115
+				'require_nonce' => false,
116
+			),
117
+			'event_registrations'   => array(
118
+				'nav'           => array(
119
+					'label'      => esc_html__('Event Check-In', 'event_espresso'),
120
+					'order'      => 10,
121
+					'persistent' => true,
122
+				),
123
+				'help_tabs'     => array(
124
+					'registrations_event_checkin_help_tab'                       => array(
125
+						'title'    => esc_html__('Registrations Event Check-In', 'event_espresso'),
126
+						'filename' => 'registrations_event_checkin',
127
+					),
128
+					'registrations_event_checkin_table_column_headings_help_tab' => array(
129
+						'title'    => esc_html__('Event Check-In Table Column Headings', 'event_espresso'),
130
+						'filename' => 'registrations_event_checkin_table_column_headings',
131
+					),
132
+					'registrations_event_checkin_filters_help_tab'               => array(
133
+						'title'    => esc_html__('Event Check-In Filters', 'event_espresso'),
134
+						'filename' => 'registrations_event_checkin_filters',
135
+					),
136
+					'registrations_event_checkin_views_help_tab'                 => array(
137
+						'title'    => esc_html__('Event Check-In Views', 'event_espresso'),
138
+						'filename' => 'registrations_event_checkin_views',
139
+					),
140
+					'registrations_event_checkin_other_help_tab'                 => array(
141
+						'title'    => esc_html__('Event Check-In Other', 'event_espresso'),
142
+						'filename' => 'registrations_event_checkin_other',
143
+					),
144
+				),
145
+				'help_tour'     => array('Event_Checkin_Help_Tour'),
146
+				'qtips'         => array('Registration_List_Table_Tips'),
147
+				'list_table'    => 'EE_Event_Registrations_List_Table',
148
+				'metaboxes'     => array(),
149
+				'require_nonce' => false,
150
+			),
151
+			'registration_checkins' => array(
152
+				'nav'           => array(
153
+					'label'      => esc_html__('Check-In Records', 'event_espresso'),
154
+					'order'      => 15,
155
+					'persistent' => false,
156
+				),
157
+				'list_table'    => 'EE_Registration_CheckIn_List_Table',
158
+				//'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
159
+				'metaboxes'     => array(),
160
+				'require_nonce' => false,
161
+			),
162
+		);
163
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
164
+		$this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
165
+		$this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
166
+	}
167 167
 
168 168
 
169
-    /**
170
-     * Ajax hooks for all routes in this page.
171
-     */
172
-    protected function _ajax_hooks()
173
-    {
174
-        parent::_ajax_hooks();
175
-        add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
176
-    }
169
+	/**
170
+	 * Ajax hooks for all routes in this page.
171
+	 */
172
+	protected function _ajax_hooks()
173
+	{
174
+		parent::_ajax_hooks();
175
+		add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
176
+	}
177 177
 
178 178
 
179
-    /**
180
-     * Global scripts for all routes in this page.
181
-     */
182
-    public function load_scripts_styles()
183
-    {
184
-        parent::load_scripts_styles();
185
-        //if newsletter message type is active then let's add filter and load js for it.
186
-        if (EEH_MSG_Template::is_mt_active('newsletter')) {
187
-            //enqueue newsletter js
188
-            wp_enqueue_script(
189
-                'ee-newsletter-trigger',
190
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
191
-                array('ee-dialog'),
192
-                EVENT_ESPRESSO_VERSION,
193
-                true
194
-            );
195
-            wp_enqueue_style(
196
-                'ee-newsletter-trigger-css',
197
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
198
-                array(),
199
-                EVENT_ESPRESSO_VERSION
200
-            );
201
-            //hook in buttons for newsletter message type trigger.
202
-            add_action(
203
-                'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
204
-                array($this, 'add_newsletter_action_buttons'),
205
-                10
206
-            );
207
-        }
208
-    }
179
+	/**
180
+	 * Global scripts for all routes in this page.
181
+	 */
182
+	public function load_scripts_styles()
183
+	{
184
+		parent::load_scripts_styles();
185
+		//if newsletter message type is active then let's add filter and load js for it.
186
+		if (EEH_MSG_Template::is_mt_active('newsletter')) {
187
+			//enqueue newsletter js
188
+			wp_enqueue_script(
189
+				'ee-newsletter-trigger',
190
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
191
+				array('ee-dialog'),
192
+				EVENT_ESPRESSO_VERSION,
193
+				true
194
+			);
195
+			wp_enqueue_style(
196
+				'ee-newsletter-trigger-css',
197
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
198
+				array(),
199
+				EVENT_ESPRESSO_VERSION
200
+			);
201
+			//hook in buttons for newsletter message type trigger.
202
+			add_action(
203
+				'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
204
+				array($this, 'add_newsletter_action_buttons'),
205
+				10
206
+			);
207
+		}
208
+	}
209 209
 
210 210
 
211
-    /**
212
-     * Scripts and styles for just the reports route.
213
-     */
214
-    public function load_scripts_styles_reports()
215
-    {
216
-        wp_register_script(
217
-            'ee-reg-reports-js',
218
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
219
-            array('google-charts'),
220
-            EVENT_ESPRESSO_VERSION,
221
-            true
222
-        );
223
-        wp_enqueue_script('ee-reg-reports-js');
224
-        $this->_registration_reports_js_setup();
225
-    }
211
+	/**
212
+	 * Scripts and styles for just the reports route.
213
+	 */
214
+	public function load_scripts_styles_reports()
215
+	{
216
+		wp_register_script(
217
+			'ee-reg-reports-js',
218
+			REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
219
+			array('google-charts'),
220
+			EVENT_ESPRESSO_VERSION,
221
+			true
222
+		);
223
+		wp_enqueue_script('ee-reg-reports-js');
224
+		$this->_registration_reports_js_setup();
225
+	}
226 226
 
227 227
 
228
-    /**
229
-     * Register screen options for event_registrations route.
230
-     */
231
-    protected function _add_screen_options_event_registrations()
232
-    {
233
-        $this->_per_page_screen_option();
234
-    }
228
+	/**
229
+	 * Register screen options for event_registrations route.
230
+	 */
231
+	protected function _add_screen_options_event_registrations()
232
+	{
233
+		$this->_per_page_screen_option();
234
+	}
235 235
 
236 236
 
237
-    /**
238
-     * Register screen options for registration_checkins route
239
-     */
240
-    protected function _add_screen_options_registration_checkins()
241
-    {
242
-        $page_title = $this->_admin_page_title;
243
-        $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso');
244
-        $this->_per_page_screen_option();
245
-        $this->_admin_page_title = $page_title;
246
-    }
237
+	/**
238
+	 * Register screen options for registration_checkins route
239
+	 */
240
+	protected function _add_screen_options_registration_checkins()
241
+	{
242
+		$page_title = $this->_admin_page_title;
243
+		$this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso');
244
+		$this->_per_page_screen_option();
245
+		$this->_admin_page_title = $page_title;
246
+	}
247 247
 
248 248
 
249
-    /**
250
-     * Set views property for event_registrations route.
251
-     */
252
-    protected function _set_list_table_views_event_registrations()
253
-    {
254
-        $this->_views = array(
255
-            'all' => array(
256
-                'slug'        => 'all',
257
-                'label'       => esc_html__('All', 'event_espresso'),
258
-                'count'       => 0,
259
-                'bulk_action' => ! isset($this->_req_data['event_id'])
260
-                    ? array()
261
-                    : array(
262
-                        'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'),
263
-                    ),
264
-            ),
265
-        );
266
-    }
249
+	/**
250
+	 * Set views property for event_registrations route.
251
+	 */
252
+	protected function _set_list_table_views_event_registrations()
253
+	{
254
+		$this->_views = array(
255
+			'all' => array(
256
+				'slug'        => 'all',
257
+				'label'       => esc_html__('All', 'event_espresso'),
258
+				'count'       => 0,
259
+				'bulk_action' => ! isset($this->_req_data['event_id'])
260
+					? array()
261
+					: array(
262
+						'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'),
263
+					),
264
+			),
265
+		);
266
+	}
267 267
 
268 268
 
269
-    /**
270
-     * Set views property for registration_checkins route.
271
-     */
272
-    protected function _set_list_table_views_registration_checkins()
273
-    {
274
-        $this->_views = array(
275
-            'all' => array(
276
-                'slug'        => 'all',
277
-                'label'       => esc_html__('All', 'event_espresso'),
278
-                'count'       => 0,
279
-                'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')),
280
-            ),
281
-        );
282
-    }
269
+	/**
270
+	 * Set views property for registration_checkins route.
271
+	 */
272
+	protected function _set_list_table_views_registration_checkins()
273
+	{
274
+		$this->_views = array(
275
+			'all' => array(
276
+				'slug'        => 'all',
277
+				'label'       => esc_html__('All', 'event_espresso'),
278
+				'count'       => 0,
279
+				'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')),
280
+			),
281
+		);
282
+	}
283 283
 
284 284
 
285
-    /**
286
-     * callback for ajax action.
287
-     *
288
-     * @since 4.3.0
289
-     * @return void (JSON)
290
-     * @throws EE_Error
291
-     * @throws InvalidArgumentException
292
-     * @throws InvalidDataTypeException
293
-     * @throws InvalidInterfaceException
294
-     */
295
-    public function get_newsletter_form_content()
296
-    {
297
-        //do a nonce check cause we're not coming in from an normal route here.
298
-        $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
299
-            $this->_req_data['get_newsletter_form_content_nonce']
300
-        ) : '';
301
-        $nonce_ref = 'get_newsletter_form_content_nonce';
302
-        $this->_verify_nonce($nonce, $nonce_ref);
303
-        //let's get the mtp for the incoming MTP_ ID
304
-        if (! isset($this->_req_data['GRP_ID'])) {
305
-            EE_Error::add_error(
306
-                esc_html__(
307
-                    'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
308
-                    'event_espresso'
309
-                ),
310
-                __FILE__,
311
-                __FUNCTION__,
312
-                __LINE__
313
-            );
314
-            $this->_template_args['success'] = false;
315
-            $this->_template_args['error'] = true;
316
-            $this->_return_json();
317
-        }
318
-        $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
319
-        if (! $MTPG instanceof EE_Message_Template_Group) {
320
-            EE_Error::add_error(
321
-                sprintf(
322
-                    esc_html__(
323
-                        'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
324
-                        'event_espresso'
325
-                    ),
326
-                    $this->_req_data['GRP_ID']
327
-                ),
328
-                __FILE__,
329
-                __FUNCTION__,
330
-                __LINE__
331
-            );
332
-            $this->_template_args['success'] = false;
333
-            $this->_template_args['error'] = true;
334
-            $this->_return_json();
335
-        }
336
-        $MTPs = $MTPG->context_templates();
337
-        $MTPs = $MTPs['attendee'];
338
-        $template_fields = array();
339
-        /** @var EE_Message_Template $MTP */
340
-        foreach ($MTPs as $MTP) {
341
-            $field = $MTP->get('MTP_template_field');
342
-            if ($field === 'content') {
343
-                $content = $MTP->get('MTP_content');
344
-                if (! empty($content['newsletter_content'])) {
345
-                    $template_fields['newsletter_content'] = $content['newsletter_content'];
346
-                }
347
-                continue;
348
-            }
349
-            $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
350
-        }
351
-        $this->_template_args['success'] = true;
352
-        $this->_template_args['error'] = false;
353
-        $this->_template_args['data'] = array(
354
-            'batch_message_from'    => isset($template_fields['from'])
355
-                ? $template_fields['from']
356
-                : '',
357
-            'batch_message_subject' => isset($template_fields['subject'])
358
-                ? $template_fields['subject']
359
-                : '',
360
-            'batch_message_content' => isset($template_fields['newsletter_content'])
361
-                ? $template_fields['newsletter_content']
362
-                : '',
363
-        );
364
-        $this->_return_json();
365
-    }
285
+	/**
286
+	 * callback for ajax action.
287
+	 *
288
+	 * @since 4.3.0
289
+	 * @return void (JSON)
290
+	 * @throws EE_Error
291
+	 * @throws InvalidArgumentException
292
+	 * @throws InvalidDataTypeException
293
+	 * @throws InvalidInterfaceException
294
+	 */
295
+	public function get_newsletter_form_content()
296
+	{
297
+		//do a nonce check cause we're not coming in from an normal route here.
298
+		$nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
299
+			$this->_req_data['get_newsletter_form_content_nonce']
300
+		) : '';
301
+		$nonce_ref = 'get_newsletter_form_content_nonce';
302
+		$this->_verify_nonce($nonce, $nonce_ref);
303
+		//let's get the mtp for the incoming MTP_ ID
304
+		if (! isset($this->_req_data['GRP_ID'])) {
305
+			EE_Error::add_error(
306
+				esc_html__(
307
+					'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
308
+					'event_espresso'
309
+				),
310
+				__FILE__,
311
+				__FUNCTION__,
312
+				__LINE__
313
+			);
314
+			$this->_template_args['success'] = false;
315
+			$this->_template_args['error'] = true;
316
+			$this->_return_json();
317
+		}
318
+		$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
319
+		if (! $MTPG instanceof EE_Message_Template_Group) {
320
+			EE_Error::add_error(
321
+				sprintf(
322
+					esc_html__(
323
+						'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
324
+						'event_espresso'
325
+					),
326
+					$this->_req_data['GRP_ID']
327
+				),
328
+				__FILE__,
329
+				__FUNCTION__,
330
+				__LINE__
331
+			);
332
+			$this->_template_args['success'] = false;
333
+			$this->_template_args['error'] = true;
334
+			$this->_return_json();
335
+		}
336
+		$MTPs = $MTPG->context_templates();
337
+		$MTPs = $MTPs['attendee'];
338
+		$template_fields = array();
339
+		/** @var EE_Message_Template $MTP */
340
+		foreach ($MTPs as $MTP) {
341
+			$field = $MTP->get('MTP_template_field');
342
+			if ($field === 'content') {
343
+				$content = $MTP->get('MTP_content');
344
+				if (! empty($content['newsletter_content'])) {
345
+					$template_fields['newsletter_content'] = $content['newsletter_content'];
346
+				}
347
+				continue;
348
+			}
349
+			$template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
350
+		}
351
+		$this->_template_args['success'] = true;
352
+		$this->_template_args['error'] = false;
353
+		$this->_template_args['data'] = array(
354
+			'batch_message_from'    => isset($template_fields['from'])
355
+				? $template_fields['from']
356
+				: '',
357
+			'batch_message_subject' => isset($template_fields['subject'])
358
+				? $template_fields['subject']
359
+				: '',
360
+			'batch_message_content' => isset($template_fields['newsletter_content'])
361
+				? $template_fields['newsletter_content']
362
+				: '',
363
+		);
364
+		$this->_return_json();
365
+	}
366 366
 
367 367
 
368
-    /**
369
-     * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
370
-     *
371
-     * @since 4.3.0
372
-     * @param EE_Admin_List_Table $list_table
373
-     * @return void
374
-     * @throws InvalidArgumentException
375
-     * @throws InvalidDataTypeException
376
-     * @throws InvalidInterfaceException
377
-     */
378
-    public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
379
-    {
380
-        if (! EE_Registry::instance()->CAP->current_user_can(
381
-            'ee_send_message',
382
-            'espresso_registrations_newsletter_selected_send'
383
-        )
384
-        ) {
385
-            return;
386
-        }
387
-        $routes_to_add_to = array(
388
-            'contact_list',
389
-            'event_registrations',
390
-            'default',
391
-        );
392
-        if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
393
-            if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
394
-                || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
395
-            ) {
396
-                echo '';
397
-            } else {
398
-                $button_text = sprintf(
399
-                    esc_html__('Send Batch Message (%s selected)', 'event_espresso'),
400
-                    '<span class="send-selected-newsletter-count">0</span>'
401
-                );
402
-                echo '<button id="selected-batch-send-trigger" class="button secondary-button">'
403
-                     . '<span class="dashicons dashicons-email "></span>'
404
-                     . $button_text
405
-                     . '</button>';
406
-                add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
407
-            }
408
-        }
409
-    }
368
+	/**
369
+	 * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
370
+	 *
371
+	 * @since 4.3.0
372
+	 * @param EE_Admin_List_Table $list_table
373
+	 * @return void
374
+	 * @throws InvalidArgumentException
375
+	 * @throws InvalidDataTypeException
376
+	 * @throws InvalidInterfaceException
377
+	 */
378
+	public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
379
+	{
380
+		if (! EE_Registry::instance()->CAP->current_user_can(
381
+			'ee_send_message',
382
+			'espresso_registrations_newsletter_selected_send'
383
+		)
384
+		) {
385
+			return;
386
+		}
387
+		$routes_to_add_to = array(
388
+			'contact_list',
389
+			'event_registrations',
390
+			'default',
391
+		);
392
+		if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
393
+			if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
394
+				|| (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
395
+			) {
396
+				echo '';
397
+			} else {
398
+				$button_text = sprintf(
399
+					esc_html__('Send Batch Message (%s selected)', 'event_espresso'),
400
+					'<span class="send-selected-newsletter-count">0</span>'
401
+				);
402
+				echo '<button id="selected-batch-send-trigger" class="button secondary-button">'
403
+					 . '<span class="dashicons dashicons-email "></span>'
404
+					 . $button_text
405
+					 . '</button>';
406
+				add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
407
+			}
408
+		}
409
+	}
410 410
 
411 411
 
412
-    /**
413
-     * @throws DomainException
414
-     * @throws EE_Error
415
-     * @throws InvalidArgumentException
416
-     * @throws InvalidDataTypeException
417
-     * @throws InvalidInterfaceException
418
-     */
419
-    public function newsletter_send_form_skeleton()
420
-    {
421
-        $list_table = $this->_list_table_object;
422
-        $codes = array();
423
-        //need to templates for the newsletter message type for the template selector.
424
-        $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0);
425
-        $mtps = EEM_Message_Template_Group::instance()->get_all(
426
-            array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
427
-        );
428
-        foreach ($mtps as $mtp) {
429
-            $name = $mtp->name();
430
-            $values[] = array(
431
-                'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name,
432
-                'id'   => $mtp->ID(),
433
-            );
434
-        }
435
-        //need to get a list of shortcodes that are available for the newsletter message type.
436
-        $shortcodes = EEH_MSG_Template::get_shortcodes(
437
-            'newsletter',
438
-            'email',
439
-            array(),
440
-            'attendee',
441
-            false
442
-        );
443
-        foreach ($shortcodes as $field => $shortcode_array) {
444
-            $available_shortcodes = array();
445
-            foreach ($shortcode_array as $shortcode => $shortcode_details) {
446
-                $field_id = $field === '[NEWSLETTER_CONTENT]'
447
-                    ? 'content'
448
-                    : $field;
449
-                $field_id = 'batch-message-' . strtolower($field_id);
450
-                $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
451
-                                          . $shortcode
452
-                                          . '" data-linked-input-id="' . $field_id . '">'
453
-                                          . $shortcode
454
-                                          . '</span>';
455
-            }
456
-            $codes[$field] = implode(', ', $available_shortcodes);
457
-        }
458
-        $shortcodes = $codes;
459
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
460
-        $form_template_args = array(
461
-            'form_action'       => admin_url('admin.php?page=espresso_registrations'),
462
-            'form_route'        => 'newsletter_selected_send',
463
-            'form_nonce_name'   => 'newsletter_selected_send_nonce',
464
-            'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
465
-            'redirect_back_to'  => $this->_req_action,
466
-            'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
467
-            'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
468
-            'shortcodes'        => $shortcodes,
469
-            'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
470
-        );
471
-        EEH_Template::display_template($form_template, $form_template_args);
472
-    }
412
+	/**
413
+	 * @throws DomainException
414
+	 * @throws EE_Error
415
+	 * @throws InvalidArgumentException
416
+	 * @throws InvalidDataTypeException
417
+	 * @throws InvalidInterfaceException
418
+	 */
419
+	public function newsletter_send_form_skeleton()
420
+	{
421
+		$list_table = $this->_list_table_object;
422
+		$codes = array();
423
+		//need to templates for the newsletter message type for the template selector.
424
+		$values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0);
425
+		$mtps = EEM_Message_Template_Group::instance()->get_all(
426
+			array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
427
+		);
428
+		foreach ($mtps as $mtp) {
429
+			$name = $mtp->name();
430
+			$values[] = array(
431
+				'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name,
432
+				'id'   => $mtp->ID(),
433
+			);
434
+		}
435
+		//need to get a list of shortcodes that are available for the newsletter message type.
436
+		$shortcodes = EEH_MSG_Template::get_shortcodes(
437
+			'newsletter',
438
+			'email',
439
+			array(),
440
+			'attendee',
441
+			false
442
+		);
443
+		foreach ($shortcodes as $field => $shortcode_array) {
444
+			$available_shortcodes = array();
445
+			foreach ($shortcode_array as $shortcode => $shortcode_details) {
446
+				$field_id = $field === '[NEWSLETTER_CONTENT]'
447
+					? 'content'
448
+					: $field;
449
+				$field_id = 'batch-message-' . strtolower($field_id);
450
+				$available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
451
+										  . $shortcode
452
+										  . '" data-linked-input-id="' . $field_id . '">'
453
+										  . $shortcode
454
+										  . '</span>';
455
+			}
456
+			$codes[$field] = implode(', ', $available_shortcodes);
457
+		}
458
+		$shortcodes = $codes;
459
+		$form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
460
+		$form_template_args = array(
461
+			'form_action'       => admin_url('admin.php?page=espresso_registrations'),
462
+			'form_route'        => 'newsletter_selected_send',
463
+			'form_nonce_name'   => 'newsletter_selected_send_nonce',
464
+			'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
465
+			'redirect_back_to'  => $this->_req_action,
466
+			'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
467
+			'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
468
+			'shortcodes'        => $shortcodes,
469
+			'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
470
+		);
471
+		EEH_Template::display_template($form_template, $form_template_args);
472
+	}
473 473
 
474 474
 
475
-    /**
476
-     * Handles sending selected registrations/contacts a newsletter.
477
-     *
478
-     * @since  4.3.0
479
-     * @return void
480
-     * @throws EE_Error
481
-     * @throws InvalidArgumentException
482
-     * @throws InvalidDataTypeException
483
-     * @throws InvalidInterfaceException
484
-     */
485
-    protected function _newsletter_selected_send()
486
-    {
487
-        $success = true;
488
-        //first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
489
-        if (empty($this->_req_data['newsletter_mtp_selected'])) {
490
-            EE_Error::add_error(
491
-                esc_html__(
492
-                    'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
493
-                    'event_espresso'
494
-                ),
495
-                __FILE__,
496
-                __FUNCTION__,
497
-                __LINE__
498
-            );
499
-            $success = false;
500
-        }
501
-        if ($success) {
502
-            //update Message template in case there are any changes
503
-            $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
504
-                $this->_req_data['newsletter_mtp_selected']
505
-            );
506
-            $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
507
-                ? $Message_Template_Group->context_templates()
508
-                : array();
509
-            if (empty($Message_Templates)) {
510
-                EE_Error::add_error(
511
-                    esc_html__(
512
-                        'Unable to retrieve message template fields from the db. Messages not sent.',
513
-                        'event_espresso'
514
-                    ),
515
-                    __FILE__,
516
-                    __FUNCTION__,
517
-                    __LINE__
518
-                );
519
-            }
520
-            //let's just update the specific fields
521
-            foreach ($Message_Templates['attendee'] as $Message_Template) {
522
-                if ($Message_Template instanceof EE_Message_Template) {
523
-                    $field = $Message_Template->get('MTP_template_field');
524
-                    $content = $Message_Template->get('MTP_content');
525
-                    $new_content = $content;
526
-                    switch ($field) {
527
-                        case 'from':
528
-                            $new_content = ! empty($this->_req_data['batch_message']['from'])
529
-                                ? $this->_req_data['batch_message']['from']
530
-                                : $content;
531
-                            break;
532
-                        case 'subject':
533
-                            $new_content = ! empty($this->_req_data['batch_message']['subject'])
534
-                                ? $this->_req_data['batch_message']['subject']
535
-                                : $content;
536
-                            break;
537
-                        case 'content':
538
-                            $new_content = $content;
539
-                            $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
540
-                                ? $this->_req_data['batch_message']['content']
541
-                                : $content['newsletter_content'];
542
-                            break;
543
-                        default:
544
-                            //continue the foreach loop, we don't want to set $new_content nor save.
545
-                            continue 2;
546
-                    }
547
-                    $Message_Template->set('MTP_content', $new_content);
548
-                    $Message_Template->save();
549
-                }
550
-            }
551
-            //great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
552
-            $id_type = ! empty($this->_req_data['batch_message']['id_type'])
553
-                ? $this->_req_data['batch_message']['id_type']
554
-                : 'registration';
555
-            //id_type will affect how we assemble the ids.
556
-            $ids = ! empty($this->_req_data['batch_message']['ids'])
557
-                ? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
558
-                : array();
559
-            $registrations_used_for_contact_data = array();
560
-            //using switch because eventually we'll have other contexts that will be used for generating messages.
561
-            switch ($id_type) {
562
-                case 'registration':
563
-                    $registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
564
-                        array(
565
-                            array(
566
-                                'REG_ID' => array('IN', $ids),
567
-                            ),
568
-                        )
569
-                    );
570
-                    break;
571
-                case 'contact':
572
-                    $registrations_used_for_contact_data = EEM_Registration::instance()
573
-                        ->get_latest_registration_for_each_of_given_contacts($ids);
574
-                    break;
575
-            }
576
-            do_action_ref_array(
577
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
578
-                array(
579
-                    $registrations_used_for_contact_data,
580
-                    $Message_Template_Group->ID()
581
-                )
582
-            );
583
-            //kept for backward compat, internally we no longer use this action.
584
-            //@deprecated 4.8.36.rc.002
585
-            $contacts = $id_type === 'registration'
586
-                ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
587
-                : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
588
-            do_action_ref_array(
589
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
590
-                array(
591
-                    $contacts,
592
-                    $Message_Template_Group->ID()
593
-                )
594
-            );
595
-        }
596
-        $query_args = array(
597
-            'action' => ! empty($this->_req_data['redirect_back_to'])
598
-                ? $this->_req_data['redirect_back_to']
599
-                : 'default',
600
-        );
601
-        $this->_redirect_after_action(false, '', '', $query_args, true);
602
-    }
475
+	/**
476
+	 * Handles sending selected registrations/contacts a newsletter.
477
+	 *
478
+	 * @since  4.3.0
479
+	 * @return void
480
+	 * @throws EE_Error
481
+	 * @throws InvalidArgumentException
482
+	 * @throws InvalidDataTypeException
483
+	 * @throws InvalidInterfaceException
484
+	 */
485
+	protected function _newsletter_selected_send()
486
+	{
487
+		$success = true;
488
+		//first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
489
+		if (empty($this->_req_data['newsletter_mtp_selected'])) {
490
+			EE_Error::add_error(
491
+				esc_html__(
492
+					'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
493
+					'event_espresso'
494
+				),
495
+				__FILE__,
496
+				__FUNCTION__,
497
+				__LINE__
498
+			);
499
+			$success = false;
500
+		}
501
+		if ($success) {
502
+			//update Message template in case there are any changes
503
+			$Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
504
+				$this->_req_data['newsletter_mtp_selected']
505
+			);
506
+			$Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
507
+				? $Message_Template_Group->context_templates()
508
+				: array();
509
+			if (empty($Message_Templates)) {
510
+				EE_Error::add_error(
511
+					esc_html__(
512
+						'Unable to retrieve message template fields from the db. Messages not sent.',
513
+						'event_espresso'
514
+					),
515
+					__FILE__,
516
+					__FUNCTION__,
517
+					__LINE__
518
+				);
519
+			}
520
+			//let's just update the specific fields
521
+			foreach ($Message_Templates['attendee'] as $Message_Template) {
522
+				if ($Message_Template instanceof EE_Message_Template) {
523
+					$field = $Message_Template->get('MTP_template_field');
524
+					$content = $Message_Template->get('MTP_content');
525
+					$new_content = $content;
526
+					switch ($field) {
527
+						case 'from':
528
+							$new_content = ! empty($this->_req_data['batch_message']['from'])
529
+								? $this->_req_data['batch_message']['from']
530
+								: $content;
531
+							break;
532
+						case 'subject':
533
+							$new_content = ! empty($this->_req_data['batch_message']['subject'])
534
+								? $this->_req_data['batch_message']['subject']
535
+								: $content;
536
+							break;
537
+						case 'content':
538
+							$new_content = $content;
539
+							$new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
540
+								? $this->_req_data['batch_message']['content']
541
+								: $content['newsletter_content'];
542
+							break;
543
+						default:
544
+							//continue the foreach loop, we don't want to set $new_content nor save.
545
+							continue 2;
546
+					}
547
+					$Message_Template->set('MTP_content', $new_content);
548
+					$Message_Template->save();
549
+				}
550
+			}
551
+			//great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
552
+			$id_type = ! empty($this->_req_data['batch_message']['id_type'])
553
+				? $this->_req_data['batch_message']['id_type']
554
+				: 'registration';
555
+			//id_type will affect how we assemble the ids.
556
+			$ids = ! empty($this->_req_data['batch_message']['ids'])
557
+				? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
558
+				: array();
559
+			$registrations_used_for_contact_data = array();
560
+			//using switch because eventually we'll have other contexts that will be used for generating messages.
561
+			switch ($id_type) {
562
+				case 'registration':
563
+					$registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
564
+						array(
565
+							array(
566
+								'REG_ID' => array('IN', $ids),
567
+							),
568
+						)
569
+					);
570
+					break;
571
+				case 'contact':
572
+					$registrations_used_for_contact_data = EEM_Registration::instance()
573
+						->get_latest_registration_for_each_of_given_contacts($ids);
574
+					break;
575
+			}
576
+			do_action_ref_array(
577
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
578
+				array(
579
+					$registrations_used_for_contact_data,
580
+					$Message_Template_Group->ID()
581
+				)
582
+			);
583
+			//kept for backward compat, internally we no longer use this action.
584
+			//@deprecated 4.8.36.rc.002
585
+			$contacts = $id_type === 'registration'
586
+				? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
587
+				: EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
588
+			do_action_ref_array(
589
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
590
+				array(
591
+					$contacts,
592
+					$Message_Template_Group->ID()
593
+				)
594
+			);
595
+		}
596
+		$query_args = array(
597
+			'action' => ! empty($this->_req_data['redirect_back_to'])
598
+				? $this->_req_data['redirect_back_to']
599
+				: 'default',
600
+		);
601
+		$this->_redirect_after_action(false, '', '', $query_args, true);
602
+	}
603 603
 
604 604
 
605 605
 
606
-    /**
607
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
608
-     * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
609
-     */
610
-    protected function _registration_reports_js_setup()
611
-    {
612
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
613
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
614
-    }
606
+	/**
607
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
608
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
609
+	 */
610
+	protected function _registration_reports_js_setup()
611
+	{
612
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
613
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
614
+	}
615 615
 
616 616
 
617
-    /**
618
-     *        generates Business Reports regarding Registrations
619
-     *
620
-     * @access protected
621
-     * @return void
622
-     * @throws DomainException
623
-     */
624
-    protected function _registration_reports()
625
-    {
626
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
627
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
628
-            $template_path,
629
-            $this->_reports_template_data,
630
-            true
631
-        );
632
-        // the final template wrapper
633
-        $this->display_admin_page_with_no_sidebar();
634
-    }
617
+	/**
618
+	 *        generates Business Reports regarding Registrations
619
+	 *
620
+	 * @access protected
621
+	 * @return void
622
+	 * @throws DomainException
623
+	 */
624
+	protected function _registration_reports()
625
+	{
626
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
627
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
628
+			$template_path,
629
+			$this->_reports_template_data,
630
+			true
631
+		);
632
+		// the final template wrapper
633
+		$this->display_admin_page_with_no_sidebar();
634
+	}
635 635
 
636 636
 
637
-    /**
638
-     * Generates Business Report showing total registrations per day.
639
-     *
640
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
641
-     * @return string
642
-     * @throws EE_Error
643
-     * @throws InvalidArgumentException
644
-     * @throws InvalidDataTypeException
645
-     * @throws InvalidInterfaceException
646
-     */
647
-    private function _registrations_per_day_report($period = '-1 month')
648
-    {
649
-        $report_ID = 'reg-admin-registrations-per-day-report-dv';
650
-        $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
651
-        $results = (array)$results;
652
-        $regs = array();
653
-        $subtitle = '';
654
-        if ($results) {
655
-            $column_titles = array();
656
-            $tracker = 0;
657
-            foreach ($results as $result) {
658
-                $report_column_values = array();
659
-                foreach ($result as $property_name => $property_value) {
660
-                    $property_value = $property_name === 'Registration_REG_date' ? $property_value
661
-                        : (int)$property_value;
662
-                    $report_column_values[] = $property_value;
663
-                    if ($tracker === 0) {
664
-                        if ($property_name === 'Registration_REG_date') {
665
-                            $column_titles[] = esc_html__('Date (only days with registrations are shown)', 'event_espresso');
666
-                        } else {
667
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
668
-                        }
669
-                    }
670
-                }
671
-                $tracker++;
672
-                $regs[] = $report_column_values;
673
-            }
674
-            //make sure the column_titles is pushed to the beginning of the array
675
-            array_unshift($regs, $column_titles);
676
-            //setup the date range.
677
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
678
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
679
-            $ending_date = new DateTime("now", $DateTimeZone);
680
-            $subtitle = sprintf(
681
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
682
-                $beginning_date->format('Y-m-d'),
683
-                $ending_date->format('Y-m-d')
684
-            );
685
-        }
686
-        $report_title = esc_html__('Total Registrations per Day', 'event_espresso');
687
-        $report_params = array(
688
-            'title'     => $report_title,
689
-            'subtitle'  => $subtitle,
690
-            'id'        => $report_ID,
691
-            'regs'      => $regs,
692
-            'noResults' => empty($regs),
693
-            'noRegsMsg' => sprintf(
694
-                esc_html__(
695
-                    '%sThere are currently no registration records in the last month for this report.%s',
696
-                    'event_espresso'
697
-                ),
698
-                '<h2>' . $report_title . '</h2><p>',
699
-                '</p>'
700
-            ),
701
-        );
702
-        wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
703
-        return $report_ID;
704
-    }
637
+	/**
638
+	 * Generates Business Report showing total registrations per day.
639
+	 *
640
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
641
+	 * @return string
642
+	 * @throws EE_Error
643
+	 * @throws InvalidArgumentException
644
+	 * @throws InvalidDataTypeException
645
+	 * @throws InvalidInterfaceException
646
+	 */
647
+	private function _registrations_per_day_report($period = '-1 month')
648
+	{
649
+		$report_ID = 'reg-admin-registrations-per-day-report-dv';
650
+		$results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
651
+		$results = (array)$results;
652
+		$regs = array();
653
+		$subtitle = '';
654
+		if ($results) {
655
+			$column_titles = array();
656
+			$tracker = 0;
657
+			foreach ($results as $result) {
658
+				$report_column_values = array();
659
+				foreach ($result as $property_name => $property_value) {
660
+					$property_value = $property_name === 'Registration_REG_date' ? $property_value
661
+						: (int)$property_value;
662
+					$report_column_values[] = $property_value;
663
+					if ($tracker === 0) {
664
+						if ($property_name === 'Registration_REG_date') {
665
+							$column_titles[] = esc_html__('Date (only days with registrations are shown)', 'event_espresso');
666
+						} else {
667
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
668
+						}
669
+					}
670
+				}
671
+				$tracker++;
672
+				$regs[] = $report_column_values;
673
+			}
674
+			//make sure the column_titles is pushed to the beginning of the array
675
+			array_unshift($regs, $column_titles);
676
+			//setup the date range.
677
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
678
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
679
+			$ending_date = new DateTime("now", $DateTimeZone);
680
+			$subtitle = sprintf(
681
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
682
+				$beginning_date->format('Y-m-d'),
683
+				$ending_date->format('Y-m-d')
684
+			);
685
+		}
686
+		$report_title = esc_html__('Total Registrations per Day', 'event_espresso');
687
+		$report_params = array(
688
+			'title'     => $report_title,
689
+			'subtitle'  => $subtitle,
690
+			'id'        => $report_ID,
691
+			'regs'      => $regs,
692
+			'noResults' => empty($regs),
693
+			'noRegsMsg' => sprintf(
694
+				esc_html__(
695
+					'%sThere are currently no registration records in the last month for this report.%s',
696
+					'event_espresso'
697
+				),
698
+				'<h2>' . $report_title . '</h2><p>',
699
+				'</p>'
700
+			),
701
+		);
702
+		wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
703
+		return $report_ID;
704
+	}
705 705
 
706 706
 
707
-    /**
708
-     * Generates Business Report showing total registrations per event.
709
-     *
710
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
711
-     * @return string
712
-     * @throws EE_Error
713
-     * @throws InvalidArgumentException
714
-     * @throws InvalidDataTypeException
715
-     * @throws InvalidInterfaceException
716
-     */
717
-    private function _registrations_per_event_report($period = '-1 month')
718
-    {
719
-        $report_ID = 'reg-admin-registrations-per-event-report-dv';
720
-        $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
721
-        $results = (array)$results;
722
-        $regs = array();
723
-        $subtitle = '';
724
-        if ($results) {
725
-            $column_titles = array();
726
-            $tracker = 0;
727
-            foreach ($results as $result) {
728
-                $report_column_values = array();
729
-                foreach ($result as $property_name => $property_value) {
730
-                    $property_value = $property_name === 'Registration_Event' ? wp_trim_words(
731
-                        $property_value,
732
-                        4,
733
-                        '...'
734
-                    ) : (int)$property_value;
735
-                    $report_column_values[] = $property_value;
736
-                    if ($tracker === 0) {
737
-                        if ($property_name === 'Registration_Event') {
738
-                            $column_titles[] = esc_html__('Event', 'event_espresso');
739
-                        } else {
740
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
741
-                        }
742
-                    }
743
-                }
744
-                $tracker++;
745
-                $regs[] = $report_column_values;
746
-            }
747
-            //make sure the column_titles is pushed to the beginning of the array
748
-            array_unshift($regs, $column_titles);
749
-            //setup the date range.
750
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
751
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
752
-            $ending_date = new DateTime("now", $DateTimeZone);
753
-            $subtitle = sprintf(
754
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
755
-                $beginning_date->format('Y-m-d'),
756
-                $ending_date->format('Y-m-d')
757
-            );
758
-        }
759
-        $report_title = esc_html__('Total Registrations per Event', 'event_espresso');
760
-        $report_params = array(
761
-            'title'     => $report_title,
762
-            'subtitle'  => $subtitle,
763
-            'id'        => $report_ID,
764
-            'regs'      => $regs,
765
-            'noResults' => empty($regs),
766
-            'noRegsMsg' => sprintf(
767
-                esc_html__(
768
-                    '%sThere are currently no registration records in the last month for this report.%s',
769
-                    'event_espresso'
770
-                ),
771
-                '<h2>' . $report_title . '</h2><p>',
772
-                '</p>'
773
-            ),
774
-        );
775
-        wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
776
-        return $report_ID;
777
-    }
707
+	/**
708
+	 * Generates Business Report showing total registrations per event.
709
+	 *
710
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
711
+	 * @return string
712
+	 * @throws EE_Error
713
+	 * @throws InvalidArgumentException
714
+	 * @throws InvalidDataTypeException
715
+	 * @throws InvalidInterfaceException
716
+	 */
717
+	private function _registrations_per_event_report($period = '-1 month')
718
+	{
719
+		$report_ID = 'reg-admin-registrations-per-event-report-dv';
720
+		$results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
721
+		$results = (array)$results;
722
+		$regs = array();
723
+		$subtitle = '';
724
+		if ($results) {
725
+			$column_titles = array();
726
+			$tracker = 0;
727
+			foreach ($results as $result) {
728
+				$report_column_values = array();
729
+				foreach ($result as $property_name => $property_value) {
730
+					$property_value = $property_name === 'Registration_Event' ? wp_trim_words(
731
+						$property_value,
732
+						4,
733
+						'...'
734
+					) : (int)$property_value;
735
+					$report_column_values[] = $property_value;
736
+					if ($tracker === 0) {
737
+						if ($property_name === 'Registration_Event') {
738
+							$column_titles[] = esc_html__('Event', 'event_espresso');
739
+						} else {
740
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
741
+						}
742
+					}
743
+				}
744
+				$tracker++;
745
+				$regs[] = $report_column_values;
746
+			}
747
+			//make sure the column_titles is pushed to the beginning of the array
748
+			array_unshift($regs, $column_titles);
749
+			//setup the date range.
750
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
751
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
752
+			$ending_date = new DateTime("now", $DateTimeZone);
753
+			$subtitle = sprintf(
754
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
755
+				$beginning_date->format('Y-m-d'),
756
+				$ending_date->format('Y-m-d')
757
+			);
758
+		}
759
+		$report_title = esc_html__('Total Registrations per Event', 'event_espresso');
760
+		$report_params = array(
761
+			'title'     => $report_title,
762
+			'subtitle'  => $subtitle,
763
+			'id'        => $report_ID,
764
+			'regs'      => $regs,
765
+			'noResults' => empty($regs),
766
+			'noRegsMsg' => sprintf(
767
+				esc_html__(
768
+					'%sThere are currently no registration records in the last month for this report.%s',
769
+					'event_espresso'
770
+				),
771
+				'<h2>' . $report_title . '</h2><p>',
772
+				'</p>'
773
+			),
774
+		);
775
+		wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
776
+		return $report_ID;
777
+	}
778 778
 
779 779
 
780
-    /**
781
-     * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
782
-     *
783
-     * @access protected
784
-     * @return void
785
-     * @throws EE_Error
786
-     * @throws InvalidArgumentException
787
-     * @throws InvalidDataTypeException
788
-     * @throws InvalidInterfaceException
789
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
790
-     */
791
-    protected function _registration_checkin_list_table()
792
-    {
793
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
794
-        $reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null;
795
-        /** @var EE_Registration $registration */
796
-        $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
797
-        $attendee = $registration->attendee();
798
-        $this->_admin_page_title .= $this->get_action_link_or_button(
799
-            'new_registration',
800
-            'add-registrant',
801
-            array('event_id' => $registration->event_ID()),
802
-            'add-new-h2'
803
-        );
804
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
805
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
806
-        $legend_items = array(
807
-            'checkin'  => array(
808
-                'class' => $checked_in->cssClasses(),
809
-                'desc'  => $checked_in->legendLabel(),
810
-            ),
811
-            'checkout' => array(
812
-                'class' => $checked_out->cssClasses(),
813
-                'desc'  => $checked_out->legendLabel(),
814
-            ),
815
-        );
816
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
817
-        $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
818
-        /** @var EE_Datetime $datetime */
819
-        $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
820
-        $datetime_label = '';
821
-        if ($datetime instanceof EE_Datetime) {
822
-            $datetime_label = $datetime->get_dtt_display_name(true);
823
-            $datetime_label .= ! empty($datetime_label)
824
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
825
-                : $datetime->get_dtt_display_name();
826
-        }
827
-        $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
828
-            ? EE_Admin_Page::add_query_args_and_nonce(
829
-                array(
830
-                    'action'   => 'event_registrations',
831
-                    'event_id' => $registration->event_ID(),
832
-                    'DTT_ID'   => $dtt_id,
833
-                ),
834
-                $this->_admin_base_url
835
-            )
836
-            : '';
837
-        $datetime_link = ! empty($datetime_link)
838
-            ? '<a href="' . $datetime_link . '">'
839
-              . '<span id="checkin-dtt">'
840
-              . $datetime_label
841
-              . '</span></a>'
842
-            : $datetime_label;
843
-        $attendee_name = $attendee instanceof EE_Attendee
844
-            ? $attendee->full_name()
845
-            : '';
846
-        $attendee_link = $attendee instanceof EE_Attendee
847
-            ? $attendee->get_admin_details_link()
848
-            : '';
849
-        $attendee_link = ! empty($attendee_link)
850
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
851
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
852
-              . '<span id="checkin-attendee-name">'
853
-              . $attendee_name
854
-              . '</span></a>'
855
-            : '';
856
-        $event_link = $registration->event() instanceof EE_Event
857
-            ? $registration->event()->get_admin_details_link()
858
-            : '';
859
-        $event_link = ! empty($event_link)
860
-            ? '<a href="' . $event_link . '"'
861
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
862
-              . '<span id="checkin-event-name">'
863
-              . $registration->event_name()
864
-              . '</span>'
865
-              . '</a>'
866
-            : '';
867
-        $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
868
-            ? '<h2>' . sprintf(
869
-                esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
870
-                $attendee_link,
871
-                $datetime_link,
872
-                $event_link
873
-            ) . '</h2>'
874
-            : '';
875
-        $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
876
-            ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
877
-        $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
878
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
879
-        $this->display_admin_list_table_page_with_no_sidebar();
880
-    }
780
+	/**
781
+	 * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
782
+	 *
783
+	 * @access protected
784
+	 * @return void
785
+	 * @throws EE_Error
786
+	 * @throws InvalidArgumentException
787
+	 * @throws InvalidDataTypeException
788
+	 * @throws InvalidInterfaceException
789
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
790
+	 */
791
+	protected function _registration_checkin_list_table()
792
+	{
793
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
794
+		$reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null;
795
+		/** @var EE_Registration $registration */
796
+		$registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
797
+		$attendee = $registration->attendee();
798
+		$this->_admin_page_title .= $this->get_action_link_or_button(
799
+			'new_registration',
800
+			'add-registrant',
801
+			array('event_id' => $registration->event_ID()),
802
+			'add-new-h2'
803
+		);
804
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
805
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
806
+		$legend_items = array(
807
+			'checkin'  => array(
808
+				'class' => $checked_in->cssClasses(),
809
+				'desc'  => $checked_in->legendLabel(),
810
+			),
811
+			'checkout' => array(
812
+				'class' => $checked_out->cssClasses(),
813
+				'desc'  => $checked_out->legendLabel(),
814
+			),
815
+		);
816
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
817
+		$dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
818
+		/** @var EE_Datetime $datetime */
819
+		$datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
820
+		$datetime_label = '';
821
+		if ($datetime instanceof EE_Datetime) {
822
+			$datetime_label = $datetime->get_dtt_display_name(true);
823
+			$datetime_label .= ! empty($datetime_label)
824
+				? ' (' . $datetime->get_dtt_display_name() . ')'
825
+				: $datetime->get_dtt_display_name();
826
+		}
827
+		$datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
828
+			? EE_Admin_Page::add_query_args_and_nonce(
829
+				array(
830
+					'action'   => 'event_registrations',
831
+					'event_id' => $registration->event_ID(),
832
+					'DTT_ID'   => $dtt_id,
833
+				),
834
+				$this->_admin_base_url
835
+			)
836
+			: '';
837
+		$datetime_link = ! empty($datetime_link)
838
+			? '<a href="' . $datetime_link . '">'
839
+			  . '<span id="checkin-dtt">'
840
+			  . $datetime_label
841
+			  . '</span></a>'
842
+			: $datetime_label;
843
+		$attendee_name = $attendee instanceof EE_Attendee
844
+			? $attendee->full_name()
845
+			: '';
846
+		$attendee_link = $attendee instanceof EE_Attendee
847
+			? $attendee->get_admin_details_link()
848
+			: '';
849
+		$attendee_link = ! empty($attendee_link)
850
+			? '<a href="' . $attendee->get_admin_details_link() . '"'
851
+			  . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
852
+			  . '<span id="checkin-attendee-name">'
853
+			  . $attendee_name
854
+			  . '</span></a>'
855
+			: '';
856
+		$event_link = $registration->event() instanceof EE_Event
857
+			? $registration->event()->get_admin_details_link()
858
+			: '';
859
+		$event_link = ! empty($event_link)
860
+			? '<a href="' . $event_link . '"'
861
+			  . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
862
+			  . '<span id="checkin-event-name">'
863
+			  . $registration->event_name()
864
+			  . '</span>'
865
+			  . '</a>'
866
+			: '';
867
+		$this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
868
+			? '<h2>' . sprintf(
869
+				esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
870
+				$attendee_link,
871
+				$datetime_link,
872
+				$event_link
873
+			) . '</h2>'
874
+			: '';
875
+		$this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
876
+			? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
877
+		$this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
878
+			? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
879
+		$this->display_admin_list_table_page_with_no_sidebar();
880
+	}
881 881
 
882 882
 
883
-    /**
884
-     * toggle the Check-in status for the given registration (coming from ajax)
885
-     *
886
-     * @return void (JSON)
887
-     * @throws EE_Error
888
-     * @throws InvalidArgumentException
889
-     * @throws InvalidDataTypeException
890
-     * @throws InvalidInterfaceException
891
-     */
892
-    public function toggle_checkin_status()
893
-    {
894
-        //first make sure we have the necessary data
895
-        if ( ! isset($this->_req_data['_regid'])) {
896
-            EE_Error::add_error(
897
-                esc_html__(
898
-                    'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
899
-                    'event_espresso'
900
-                ),
901
-                __FILE__,
902
-                __FUNCTION__,
903
-                __LINE__
904
-            );
905
-            $this->_template_args['success'] = false;
906
-            $this->_template_args['error'] = true;
907
-            $this->_return_json();
908
-        };
909
-        //do a nonce check cause we're not coming in from an normal route here.
910
-        $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
911
-            : '';
912
-        $nonce_ref = 'checkin_nonce';
913
-        $this->_verify_nonce($nonce, $nonce_ref);
914
-        //beautiful! Made it this far so let's get the status.
915
-        $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
916
-        //setup new class to return via ajax
917
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
918
-        $this->_template_args['success'] = true;
919
-        $this->_return_json();
920
-    }
883
+	/**
884
+	 * toggle the Check-in status for the given registration (coming from ajax)
885
+	 *
886
+	 * @return void (JSON)
887
+	 * @throws EE_Error
888
+	 * @throws InvalidArgumentException
889
+	 * @throws InvalidDataTypeException
890
+	 * @throws InvalidInterfaceException
891
+	 */
892
+	public function toggle_checkin_status()
893
+	{
894
+		//first make sure we have the necessary data
895
+		if ( ! isset($this->_req_data['_regid'])) {
896
+			EE_Error::add_error(
897
+				esc_html__(
898
+					'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
899
+					'event_espresso'
900
+				),
901
+				__FILE__,
902
+				__FUNCTION__,
903
+				__LINE__
904
+			);
905
+			$this->_template_args['success'] = false;
906
+			$this->_template_args['error'] = true;
907
+			$this->_return_json();
908
+		};
909
+		//do a nonce check cause we're not coming in from an normal route here.
910
+		$nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
911
+			: '';
912
+		$nonce_ref = 'checkin_nonce';
913
+		$this->_verify_nonce($nonce, $nonce_ref);
914
+		//beautiful! Made it this far so let's get the status.
915
+		$new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
916
+		//setup new class to return via ajax
917
+		$this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
918
+		$this->_template_args['success'] = true;
919
+		$this->_return_json();
920
+	}
921 921
 
922 922
 
923
-    /**
924
-     * handles toggling the checkin status for the registration,
925
-     *
926
-     * @access protected
927
-     * @return int|void
928
-     * @throws EE_Error
929
-     * @throws InvalidArgumentException
930
-     * @throws InvalidDataTypeException
931
-     * @throws InvalidInterfaceException
932
-     */
933
-    protected function _toggle_checkin_status()
934
-    {
935
-        //first let's get the query args out of the way for the redirect
936
-        $query_args = array(
937
-            'action'   => 'event_registrations',
938
-            'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
939
-            'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
940
-        );
941
-        $new_status = false;
942
-        // bulk action check in toggle
943
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
944
-            // cycle thru checkboxes
945
-            while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
946
-                $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
947
-                $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
948
-            }
949
-        } elseif (isset($this->_req_data['_regid'])) {
950
-            //coming from ajax request
951
-            $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
952
-            $query_args['DTT_ID'] = $DTT_ID;
953
-            $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
954
-        } else {
955
-            EE_Error::add_error(
956
-                esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'),
957
-                __FILE__,
958
-                __FUNCTION__,
959
-                __LINE__
960
-            );
961
-        }
962
-        if (defined('DOING_AJAX')) {
963
-            return $new_status;
964
-        }
965
-        $this->_redirect_after_action(false, '', '', $query_args, true);
966
-    }
923
+	/**
924
+	 * handles toggling the checkin status for the registration,
925
+	 *
926
+	 * @access protected
927
+	 * @return int|void
928
+	 * @throws EE_Error
929
+	 * @throws InvalidArgumentException
930
+	 * @throws InvalidDataTypeException
931
+	 * @throws InvalidInterfaceException
932
+	 */
933
+	protected function _toggle_checkin_status()
934
+	{
935
+		//first let's get the query args out of the way for the redirect
936
+		$query_args = array(
937
+			'action'   => 'event_registrations',
938
+			'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
939
+			'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
940
+		);
941
+		$new_status = false;
942
+		// bulk action check in toggle
943
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
944
+			// cycle thru checkboxes
945
+			while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
946
+				$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
947
+				$new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
948
+			}
949
+		} elseif (isset($this->_req_data['_regid'])) {
950
+			//coming from ajax request
951
+			$DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
952
+			$query_args['DTT_ID'] = $DTT_ID;
953
+			$new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
954
+		} else {
955
+			EE_Error::add_error(
956
+				esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'),
957
+				__FILE__,
958
+				__FUNCTION__,
959
+				__LINE__
960
+			);
961
+		}
962
+		if (defined('DOING_AJAX')) {
963
+			return $new_status;
964
+		}
965
+		$this->_redirect_after_action(false, '', '', $query_args, true);
966
+	}
967 967
 
968 968
 
969
-    /**
970
-     * This is toggles a single Check-in for the given registration and datetime.
971
-     *
972
-     * @param  int $REG_ID The registration we're toggling
973
-     * @param  int $DTT_ID The datetime we're toggling
974
-     * @return int The new status toggled to.
975
-     * @throws EE_Error
976
-     * @throws InvalidArgumentException
977
-     * @throws InvalidDataTypeException
978
-     * @throws InvalidInterfaceException
979
-     */
980
-    private function _toggle_checkin($REG_ID, $DTT_ID)
981
-    {
982
-        /** @var EE_Registration $REG */
983
-        $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
984
-        $new_status = $REG->toggle_checkin_status($DTT_ID);
985
-        if ($new_status !== false) {
986
-            EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
987
-        } else {
988
-            EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
989
-            $new_status = false;
990
-        }
991
-        return $new_status;
992
-    }
969
+	/**
970
+	 * This is toggles a single Check-in for the given registration and datetime.
971
+	 *
972
+	 * @param  int $REG_ID The registration we're toggling
973
+	 * @param  int $DTT_ID The datetime we're toggling
974
+	 * @return int The new status toggled to.
975
+	 * @throws EE_Error
976
+	 * @throws InvalidArgumentException
977
+	 * @throws InvalidDataTypeException
978
+	 * @throws InvalidInterfaceException
979
+	 */
980
+	private function _toggle_checkin($REG_ID, $DTT_ID)
981
+	{
982
+		/** @var EE_Registration $REG */
983
+		$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
984
+		$new_status = $REG->toggle_checkin_status($DTT_ID);
985
+		if ($new_status !== false) {
986
+			EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
987
+		} else {
988
+			EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
989
+			$new_status = false;
990
+		}
991
+		return $new_status;
992
+	}
993 993
 
994 994
 
995
-    /**
996
-     * Takes care of deleting multiple EE_Checkin table rows
997
-     *
998
-     * @access protected
999
-     * @return void
1000
-     * @throws EE_Error
1001
-     * @throws InvalidArgumentException
1002
-     * @throws InvalidDataTypeException
1003
-     * @throws InvalidInterfaceException
1004
-     */
1005
-    protected function _delete_checkin_rows()
1006
-    {
1007
-        $query_args = array(
1008
-            'action' => 'registration_checkins',
1009
-            'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1010
-            '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
1011
-        );
1012
-        $errors = 0;
1013
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1014
-            while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1015
-                if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1016
-                    $errors++;
1017
-                }
1018
-            }
1019
-        } else {
1020
-            EE_Error::add_error(
1021
-                esc_html__(
1022
-                    'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
1023
-                    'event_espresso'
1024
-                ),
1025
-                __FILE__,
1026
-                __FUNCTION__,
1027
-                __LINE__
1028
-            );
1029
-            $this->_redirect_after_action(false, '', '', $query_args, true);
1030
-        }
1031
-        if ($errors > 0) {
1032
-            EE_Error::add_error(
1033
-                sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
1034
-                __FILE__,
1035
-                __FUNCTION__,
1036
-                __LINE__
1037
-            );
1038
-        } else {
1039
-            EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
1040
-        }
1041
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1042
-    }
995
+	/**
996
+	 * Takes care of deleting multiple EE_Checkin table rows
997
+	 *
998
+	 * @access protected
999
+	 * @return void
1000
+	 * @throws EE_Error
1001
+	 * @throws InvalidArgumentException
1002
+	 * @throws InvalidDataTypeException
1003
+	 * @throws InvalidInterfaceException
1004
+	 */
1005
+	protected function _delete_checkin_rows()
1006
+	{
1007
+		$query_args = array(
1008
+			'action' => 'registration_checkins',
1009
+			'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1010
+			'_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
1011
+		);
1012
+		$errors = 0;
1013
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1014
+			while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1015
+				if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1016
+					$errors++;
1017
+				}
1018
+			}
1019
+		} else {
1020
+			EE_Error::add_error(
1021
+				esc_html__(
1022
+					'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
1023
+					'event_espresso'
1024
+				),
1025
+				__FILE__,
1026
+				__FUNCTION__,
1027
+				__LINE__
1028
+			);
1029
+			$this->_redirect_after_action(false, '', '', $query_args, true);
1030
+		}
1031
+		if ($errors > 0) {
1032
+			EE_Error::add_error(
1033
+				sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
1034
+				__FILE__,
1035
+				__FUNCTION__,
1036
+				__LINE__
1037
+			);
1038
+		} else {
1039
+			EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
1040
+		}
1041
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1042
+	}
1043 1043
 
1044 1044
 
1045
-    /**
1046
-     * Deletes a single EE_Checkin row
1047
-     *
1048
-     * @return void
1049
-     * @throws EE_Error
1050
-     * @throws InvalidArgumentException
1051
-     * @throws InvalidDataTypeException
1052
-     * @throws InvalidInterfaceException
1053
-     */
1054
-    protected function _delete_checkin_row()
1055
-    {
1056
-        $query_args = array(
1057
-            'action' => 'registration_checkins',
1058
-            'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1059
-            '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
1060
-        );
1061
-        if ( ! empty($this->_req_data['CHK_ID'])) {
1062
-            if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1063
-                EE_Error::add_error(
1064
-                    esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1065
-                    __FILE__,
1066
-                    __FUNCTION__,
1067
-                    __LINE__
1068
-                );
1069
-            } else {
1070
-                EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
1071
-            }
1072
-        } else {
1073
-            EE_Error::add_error(
1074
-                esc_html__(
1075
-                    'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1076
-                    'event_espresso'
1077
-                ),
1078
-                __FILE__,
1079
-                __FUNCTION__,
1080
-                __LINE__
1081
-            );
1082
-        }
1083
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1084
-    }
1045
+	/**
1046
+	 * Deletes a single EE_Checkin row
1047
+	 *
1048
+	 * @return void
1049
+	 * @throws EE_Error
1050
+	 * @throws InvalidArgumentException
1051
+	 * @throws InvalidDataTypeException
1052
+	 * @throws InvalidInterfaceException
1053
+	 */
1054
+	protected function _delete_checkin_row()
1055
+	{
1056
+		$query_args = array(
1057
+			'action' => 'registration_checkins',
1058
+			'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1059
+			'_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
1060
+		);
1061
+		if ( ! empty($this->_req_data['CHK_ID'])) {
1062
+			if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1063
+				EE_Error::add_error(
1064
+					esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1065
+					__FILE__,
1066
+					__FUNCTION__,
1067
+					__LINE__
1068
+				);
1069
+			} else {
1070
+				EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
1071
+			}
1072
+		} else {
1073
+			EE_Error::add_error(
1074
+				esc_html__(
1075
+					'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1076
+					'event_espresso'
1077
+				),
1078
+				__FILE__,
1079
+				__FUNCTION__,
1080
+				__LINE__
1081
+			);
1082
+		}
1083
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1084
+	}
1085 1085
 
1086 1086
 
1087
-    /**
1088
-     *        generates HTML for the Event Registrations List Table
1089
-     *
1090
-     * @access protected
1091
-     * @return void
1092
-     * @throws EE_Error
1093
-     * @throws InvalidArgumentException
1094
-     * @throws InvalidDataTypeException
1095
-     * @throws InvalidInterfaceException
1096
-     */
1097
-    protected function _event_registrations_list_table()
1098
-    {
1099
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1100
-        $this->_admin_page_title .= isset($this->_req_data['event_id'])
1101
-            ? $this->get_action_link_or_button(
1102
-                'new_registration',
1103
-                'add-registrant',
1104
-                array('event_id' => $this->_req_data['event_id']),
1105
-                'add-new-h2',
1106
-                '',
1107
-                false
1108
-            )
1109
-            : '';
1110
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1111
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1112
-        $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1113
-        $legend_items = array(
1114
-            'star-icon'        => array(
1115
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1116
-                'desc'  => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'),
1117
-            ),
1118
-            'checkin'          => array(
1119
-                'class' => $checked_in->cssClasses(),
1120
-                'desc'  => $checked_in->legendLabel(),
1121
-            ),
1122
-            'checkout'         => array(
1123
-                'class' => $checked_out->cssClasses(),
1124
-                'desc'  => $checked_out->legendLabel(),
1125
-            ),
1126
-            'nocheckinrecord'  => array(
1127
-                'class' => $checked_never->cssClasses(),
1128
-                'desc'  => $checked_never->legendLabel(),
1129
-            ),
1130
-            'view_details'     => array(
1131
-                'class' => 'dashicons dashicons-search',
1132
-                'desc'  => esc_html__('View All Check-in Records for this Registrant', 'event_espresso'),
1133
-            ),
1134
-            'approved_status'  => array(
1135
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1136
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1137
-            ),
1138
-            'cancelled_status' => array(
1139
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1140
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1141
-            ),
1142
-            'declined_status'  => array(
1143
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1144
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1145
-            ),
1146
-            'not_approved'     => array(
1147
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1148
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1149
-            ),
1150
-            'pending_status'   => array(
1151
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1152
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1153
-            ),
1154
-            'wait_list'        => array(
1155
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1156
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1157
-            ),
1158
-        );
1159
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1160
-        $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1161
-        $this->_template_args['before_list_table'] = ! empty($event_id)
1162
-            ? '<h2>' . sprintf(
1163
-                esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1164
-                EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1165
-            ) . '</h2>'
1166
-            : '';
1167
-        //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1168
-        // the event.
1169
-        /** @var EE_Event $event */
1170
-        $event = EEM_Event::instance()->get_one_by_ID($event_id);
1171
-        $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1172
-        $datetime = null;
1173
-        if ($event instanceof EE_Event) {
1174
-            $datetimes_on_event = $event->datetimes();
1175
-            if (count($datetimes_on_event) === 1) {
1176
-                $datetime = reset($datetimes_on_event);
1177
-            }
1178
-        }
1179
-        $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1180
-        if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1181
-            $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1182
-            $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1183
-            $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1184
-            $this->_template_args['before_list_table'] .= $datetime->name();
1185
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1186
-            $this->_template_args['before_list_table'] .= '</span></h2>';
1187
-        }
1188
-        //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1189
-        // column represents
1190
-        if (! $datetime instanceof EE_Datetime) {
1191
-            $this->_template_args['before_list_table'] .= '<br><p class="description">'
1192
-                . esc_html__(
1193
-                    'In this view, the check-in status represents the latest check-in record for the registration in that row.',
1194
-                    'event_espresso'
1195
-                )
1196
-                . '</p>';
1197
-        }
1198
-        $this->display_admin_list_table_page_with_no_sidebar();
1199
-    }
1087
+	/**
1088
+	 *        generates HTML for the Event Registrations List Table
1089
+	 *
1090
+	 * @access protected
1091
+	 * @return void
1092
+	 * @throws EE_Error
1093
+	 * @throws InvalidArgumentException
1094
+	 * @throws InvalidDataTypeException
1095
+	 * @throws InvalidInterfaceException
1096
+	 */
1097
+	protected function _event_registrations_list_table()
1098
+	{
1099
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1100
+		$this->_admin_page_title .= isset($this->_req_data['event_id'])
1101
+			? $this->get_action_link_or_button(
1102
+				'new_registration',
1103
+				'add-registrant',
1104
+				array('event_id' => $this->_req_data['event_id']),
1105
+				'add-new-h2',
1106
+				'',
1107
+				false
1108
+			)
1109
+			: '';
1110
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1111
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1112
+		$checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1113
+		$legend_items = array(
1114
+			'star-icon'        => array(
1115
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1116
+				'desc'  => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'),
1117
+			),
1118
+			'checkin'          => array(
1119
+				'class' => $checked_in->cssClasses(),
1120
+				'desc'  => $checked_in->legendLabel(),
1121
+			),
1122
+			'checkout'         => array(
1123
+				'class' => $checked_out->cssClasses(),
1124
+				'desc'  => $checked_out->legendLabel(),
1125
+			),
1126
+			'nocheckinrecord'  => array(
1127
+				'class' => $checked_never->cssClasses(),
1128
+				'desc'  => $checked_never->legendLabel(),
1129
+			),
1130
+			'view_details'     => array(
1131
+				'class' => 'dashicons dashicons-search',
1132
+				'desc'  => esc_html__('View All Check-in Records for this Registrant', 'event_espresso'),
1133
+			),
1134
+			'approved_status'  => array(
1135
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1136
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1137
+			),
1138
+			'cancelled_status' => array(
1139
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1140
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1141
+			),
1142
+			'declined_status'  => array(
1143
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1144
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1145
+			),
1146
+			'not_approved'     => array(
1147
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1148
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1149
+			),
1150
+			'pending_status'   => array(
1151
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1152
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1153
+			),
1154
+			'wait_list'        => array(
1155
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1156
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1157
+			),
1158
+		);
1159
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1160
+		$event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1161
+		$this->_template_args['before_list_table'] = ! empty($event_id)
1162
+			? '<h2>' . sprintf(
1163
+				esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1164
+				EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1165
+			) . '</h2>'
1166
+			: '';
1167
+		//need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1168
+		// the event.
1169
+		/** @var EE_Event $event */
1170
+		$event = EEM_Event::instance()->get_one_by_ID($event_id);
1171
+		$DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1172
+		$datetime = null;
1173
+		if ($event instanceof EE_Event) {
1174
+			$datetimes_on_event = $event->datetimes();
1175
+			if (count($datetimes_on_event) === 1) {
1176
+				$datetime = reset($datetimes_on_event);
1177
+			}
1178
+		}
1179
+		$datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1180
+		if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1181
+			$this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1182
+			$this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1183
+			$this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1184
+			$this->_template_args['before_list_table'] .= $datetime->name();
1185
+			$this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1186
+			$this->_template_args['before_list_table'] .= '</span></h2>';
1187
+		}
1188
+		//if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1189
+		// column represents
1190
+		if (! $datetime instanceof EE_Datetime) {
1191
+			$this->_template_args['before_list_table'] .= '<br><p class="description">'
1192
+				. esc_html__(
1193
+					'In this view, the check-in status represents the latest check-in record for the registration in that row.',
1194
+					'event_espresso'
1195
+				)
1196
+				. '</p>';
1197
+		}
1198
+		$this->display_admin_list_table_page_with_no_sidebar();
1199
+	}
1200 1200
 
1201
-    /**
1202
-     * Download the registrations check-in report (same as the normal registration report, but with different where
1203
-     * conditions)
1204
-     *
1205
-     * @return void ends the request by a redirect or download
1206
-     */
1207
-    public function _registrations_checkin_report()
1208
-    {
1209
-        $this->_registrations_report_base('_get_checkin_query_params_from_request');
1210
-    }
1201
+	/**
1202
+	 * Download the registrations check-in report (same as the normal registration report, but with different where
1203
+	 * conditions)
1204
+	 *
1205
+	 * @return void ends the request by a redirect or download
1206
+	 */
1207
+	public function _registrations_checkin_report()
1208
+	{
1209
+		$this->_registrations_report_base('_get_checkin_query_params_from_request');
1210
+	}
1211 1211
 
1212
-    /**
1213
-     * Gets the query params from the request, plus adds a where condition for the registration status,
1214
-     * because on the checkin page we only ever want to see approved and pending-approval registrations
1215
-     *
1216
-     * @param array $request
1217
-     * @param int   $per_page
1218
-     * @param bool  $count
1219
-     * @return array
1220
-     * @throws EE_Error
1221
-     */
1222
-    protected function _get_checkin_query_params_from_request(
1223
-        $request,
1224
-        $per_page = 10,
1225
-        $count = false
1226
-    ) {
1227
-        $query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1228
-        //unlike the regular registrations list table,
1229
-        $status_ids_array = apply_filters(
1230
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1231
-            array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1232
-        );
1233
-        $query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1234
-        return $query_params;
1235
-    }
1212
+	/**
1213
+	 * Gets the query params from the request, plus adds a where condition for the registration status,
1214
+	 * because on the checkin page we only ever want to see approved and pending-approval registrations
1215
+	 *
1216
+	 * @param array $request
1217
+	 * @param int   $per_page
1218
+	 * @param bool  $count
1219
+	 * @return array
1220
+	 * @throws EE_Error
1221
+	 */
1222
+	protected function _get_checkin_query_params_from_request(
1223
+		$request,
1224
+		$per_page = 10,
1225
+		$count = false
1226
+	) {
1227
+		$query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1228
+		//unlike the regular registrations list table,
1229
+		$status_ids_array = apply_filters(
1230
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1231
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1232
+		);
1233
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1234
+		return $query_params;
1235
+	}
1236 1236
 
1237 1237
 
1238
-    /**
1239
-     * Gets registrations for an event
1240
-     *
1241
-     * @param int    $per_page
1242
-     * @param bool   $count whether to return count or data.
1243
-     * @param bool   $trash
1244
-     * @param string $orderby
1245
-     * @return EE_Registration[]|int
1246
-     * @throws EE_Error
1247
-     * @throws InvalidArgumentException
1248
-     * @throws InvalidDataTypeException
1249
-     * @throws InvalidInterfaceException
1250
-     */
1251
-    public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1252
-    {
1253
-        //normalize some request params that get setup by the parent `get_registrations` method.
1254
-        $request = $this->_req_data;
1255
-        $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1256
-        $request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1257
-        if ($trash) {
1258
-            $request['status'] = 'trash';
1259
-        }
1260
-        $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1261
-        /**
1262
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1263
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1264
-         * @see EEM_Base::get_all()
1265
-         */
1266
-        $query_params['group_by'] = '';
1238
+	/**
1239
+	 * Gets registrations for an event
1240
+	 *
1241
+	 * @param int    $per_page
1242
+	 * @param bool   $count whether to return count or data.
1243
+	 * @param bool   $trash
1244
+	 * @param string $orderby
1245
+	 * @return EE_Registration[]|int
1246
+	 * @throws EE_Error
1247
+	 * @throws InvalidArgumentException
1248
+	 * @throws InvalidDataTypeException
1249
+	 * @throws InvalidInterfaceException
1250
+	 */
1251
+	public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1252
+	{
1253
+		//normalize some request params that get setup by the parent `get_registrations` method.
1254
+		$request = $this->_req_data;
1255
+		$request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1256
+		$request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1257
+		if ($trash) {
1258
+			$request['status'] = 'trash';
1259
+		}
1260
+		$query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1261
+		/**
1262
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1263
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1264
+		 * @see EEM_Base::get_all()
1265
+		 */
1266
+		$query_params['group_by'] = '';
1267 1267
 
1268
-        return $count
1269
-            ? EEM_Registration::instance()->count($query_params)
1270
-            /** @type EE_Registration[] */
1271
-            : EEM_Registration::instance()->get_all($query_params);
1272
-    }
1268
+		return $count
1269
+			? EEM_Registration::instance()->count($query_params)
1270
+			/** @type EE_Registration[] */
1271
+			: EEM_Registration::instance()->get_all($query_params);
1272
+	}
1273 1273
 }
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
     public function __construct($routing = true)
36 36
     {
37 37
         parent::__construct($routing);
38
-        if (! defined('REG_CAF_TEMPLATE_PATH')) {
39
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
40
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
41
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
38
+        if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
39
+            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/');
40
+            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/');
41
+            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/');
42 42
         }
43 43
     }
44 44
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      */
49 49
     protected function _extend_page_config()
50 50
     {
51
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
51
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations';
52 52
         $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
53 53
             ? $this->_req_data['_REG_ID']
54 54
             : 0;
@@ -187,14 +187,14 @@  discard block
 block discarded – undo
187 187
             //enqueue newsletter js
188 188
             wp_enqueue_script(
189 189
                 'ee-newsletter-trigger',
190
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
190
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js',
191 191
                 array('ee-dialog'),
192 192
                 EVENT_ESPRESSO_VERSION,
193 193
                 true
194 194
             );
195 195
             wp_enqueue_style(
196 196
                 'ee-newsletter-trigger-css',
197
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
197
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css',
198 198
                 array(),
199 199
                 EVENT_ESPRESSO_VERSION
200 200
             );
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
     {
216 216
         wp_register_script(
217 217
             'ee-reg-reports-js',
218
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
218
+            REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js',
219 219
             array('google-charts'),
220 220
             EVENT_ESPRESSO_VERSION,
221 221
             true
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
         $nonce_ref = 'get_newsletter_form_content_nonce';
302 302
         $this->_verify_nonce($nonce, $nonce_ref);
303 303
         //let's get the mtp for the incoming MTP_ ID
304
-        if (! isset($this->_req_data['GRP_ID'])) {
304
+        if ( ! isset($this->_req_data['GRP_ID'])) {
305 305
             EE_Error::add_error(
306 306
                 esc_html__(
307 307
                     'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
             $this->_return_json();
317 317
         }
318 318
         $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
319
-        if (! $MTPG instanceof EE_Message_Template_Group) {
319
+        if ( ! $MTPG instanceof EE_Message_Template_Group) {
320 320
             EE_Error::add_error(
321 321
                 sprintf(
322 322
                     esc_html__(
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
             $field = $MTP->get('MTP_template_field');
342 342
             if ($field === 'content') {
343 343
                 $content = $MTP->get('MTP_content');
344
-                if (! empty($content['newsletter_content'])) {
344
+                if ( ! empty($content['newsletter_content'])) {
345 345
                     $template_fields['newsletter_content'] = $content['newsletter_content'];
346 346
                 }
347 347
                 continue;
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
      */
378 378
     public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
379 379
     {
380
-        if (! EE_Registry::instance()->CAP->current_user_can(
380
+        if ( ! EE_Registry::instance()->CAP->current_user_can(
381 381
             'ee_send_message',
382 382
             'espresso_registrations_newsletter_selected_send'
383 383
         )
@@ -446,17 +446,17 @@  discard block
 block discarded – undo
446 446
                 $field_id = $field === '[NEWSLETTER_CONTENT]'
447 447
                     ? 'content'
448 448
                     : $field;
449
-                $field_id = 'batch-message-' . strtolower($field_id);
449
+                $field_id = 'batch-message-'.strtolower($field_id);
450 450
                 $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
451 451
                                           . $shortcode
452
-                                          . '" data-linked-input-id="' . $field_id . '">'
452
+                                          . '" data-linked-input-id="'.$field_id.'">'
453 453
                                           . $shortcode
454 454
                                           . '</span>';
455 455
             }
456 456
             $codes[$field] = implode(', ', $available_shortcodes);
457 457
         }
458 458
         $shortcodes = $codes;
459
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
459
+        $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php';
460 460
         $form_template_args = array(
461 461
             'form_action'       => admin_url('admin.php?page=espresso_registrations'),
462 462
             'form_route'        => 'newsletter_selected_send',
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
      */
624 624
     protected function _registration_reports()
625 625
     {
626
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
626
+        $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
627 627
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
628 628
             $template_path,
629 629
             $this->_reports_template_data,
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
     {
649 649
         $report_ID = 'reg-admin-registrations-per-day-report-dv';
650 650
         $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
651
-        $results = (array)$results;
651
+        $results = (array) $results;
652 652
         $regs = array();
653 653
         $subtitle = '';
654 654
         if ($results) {
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
                 $report_column_values = array();
659 659
                 foreach ($result as $property_name => $property_value) {
660 660
                     $property_value = $property_name === 'Registration_REG_date' ? $property_value
661
-                        : (int)$property_value;
661
+                        : (int) $property_value;
662 662
                     $report_column_values[] = $property_value;
663 663
                     if ($tracker === 0) {
664 664
                         if ($property_name === 'Registration_REG_date') {
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
             array_unshift($regs, $column_titles);
676 676
             //setup the date range.
677 677
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
678
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
678
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
679 679
             $ending_date = new DateTime("now", $DateTimeZone);
680 680
             $subtitle = sprintf(
681 681
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
                     '%sThere are currently no registration records in the last month for this report.%s',
696 696
                     'event_espresso'
697 697
                 ),
698
-                '<h2>' . $report_title . '</h2><p>',
698
+                '<h2>'.$report_title.'</h2><p>',
699 699
                 '</p>'
700 700
             ),
701 701
         );
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
     {
719 719
         $report_ID = 'reg-admin-registrations-per-event-report-dv';
720 720
         $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
721
-        $results = (array)$results;
721
+        $results = (array) $results;
722 722
         $regs = array();
723 723
         $subtitle = '';
724 724
         if ($results) {
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
                         $property_value,
732 732
                         4,
733 733
                         '...'
734
-                    ) : (int)$property_value;
734
+                    ) : (int) $property_value;
735 735
                     $report_column_values[] = $property_value;
736 736
                     if ($tracker === 0) {
737 737
                         if ($property_name === 'Registration_Event') {
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
             array_unshift($regs, $column_titles);
749 749
             //setup the date range.
750 750
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
751
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
751
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
752 752
             $ending_date = new DateTime("now", $DateTimeZone);
753 753
             $subtitle = sprintf(
754 754
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
                     '%sThere are currently no registration records in the last month for this report.%s',
769 769
                     'event_espresso'
770 770
                 ),
771
-                '<h2>' . $report_title . '</h2><p>',
771
+                '<h2>'.$report_title.'</h2><p>',
772 772
                 '</p>'
773 773
             ),
774 774
         );
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
         if ($datetime instanceof EE_Datetime) {
822 822
             $datetime_label = $datetime->get_dtt_display_name(true);
823 823
             $datetime_label .= ! empty($datetime_label)
824
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
824
+                ? ' ('.$datetime->get_dtt_display_name().')'
825 825
                 : $datetime->get_dtt_display_name();
826 826
         }
827 827
         $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
             )
836 836
             : '';
837 837
         $datetime_link = ! empty($datetime_link)
838
-            ? '<a href="' . $datetime_link . '">'
838
+            ? '<a href="'.$datetime_link.'">'
839 839
               . '<span id="checkin-dtt">'
840 840
               . $datetime_label
841 841
               . '</span></a>'
@@ -847,8 +847,8 @@  discard block
 block discarded – undo
847 847
             ? $attendee->get_admin_details_link()
848 848
             : '';
849 849
         $attendee_link = ! empty($attendee_link)
850
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
851
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
850
+            ? '<a href="'.$attendee->get_admin_details_link().'"'
851
+              . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">'
852 852
               . '<span id="checkin-attendee-name">'
853 853
               . $attendee_name
854 854
               . '</span></a>'
@@ -857,25 +857,25 @@  discard block
 block discarded – undo
857 857
             ? $registration->event()->get_admin_details_link()
858 858
             : '';
859 859
         $event_link = ! empty($event_link)
860
-            ? '<a href="' . $event_link . '"'
861
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
860
+            ? '<a href="'.$event_link.'"'
861
+              . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">'
862 862
               . '<span id="checkin-event-name">'
863 863
               . $registration->event_name()
864 864
               . '</span>'
865 865
               . '</a>'
866 866
             : '';
867 867
         $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
868
-            ? '<h2>' . sprintf(
868
+            ? '<h2>'.sprintf(
869 869
                 esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
870 870
                 $attendee_link,
871 871
                 $datetime_link,
872 872
                 $event_link
873
-            ) . '</h2>'
873
+            ).'</h2>'
874 874
             : '';
875 875
         $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
876
-            ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
876
+            ? '<input type="hidden" name="_REGID" value="'.$reg_id.'">' : '';
877 877
         $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
878
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
878
+            ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : '';
879 879
         $this->display_admin_list_table_page_with_no_sidebar();
880 880
     }
881 881
 
@@ -914,7 +914,7 @@  discard block
 block discarded – undo
914 914
         //beautiful! Made it this far so let's get the status.
915 915
         $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
916 916
         //setup new class to return via ajax
917
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
917
+        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin '.$new_status->cssClasses();
918 918
         $this->_template_args['success'] = true;
919 919
         $this->_return_json();
920 920
     }
@@ -1132,37 +1132,37 @@  discard block
 block discarded – undo
1132 1132
                 'desc'  => esc_html__('View All Check-in Records for this Registrant', 'event_espresso'),
1133 1133
             ),
1134 1134
             'approved_status'  => array(
1135
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1135
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
1136 1136
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1137 1137
             ),
1138 1138
             'cancelled_status' => array(
1139
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1139
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1140 1140
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1141 1141
             ),
1142 1142
             'declined_status'  => array(
1143
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1143
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
1144 1144
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1145 1145
             ),
1146 1146
             'not_approved'     => array(
1147
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1147
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
1148 1148
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1149 1149
             ),
1150 1150
             'pending_status'   => array(
1151
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1151
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
1152 1152
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1153 1153
             ),
1154 1154
             'wait_list'        => array(
1155
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1155
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
1156 1156
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1157 1157
             ),
1158 1158
         );
1159 1159
         $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1160 1160
         $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1161 1161
         $this->_template_args['before_list_table'] = ! empty($event_id)
1162
-            ? '<h2>' . sprintf(
1162
+            ? '<h2>'.sprintf(
1163 1163
                 esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1164 1164
                 EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1165
-            ) . '</h2>'
1165
+            ).'</h2>'
1166 1166
             : '';
1167 1167
         //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1168 1168
         // the event.
@@ -1182,12 +1182,12 @@  discard block
 block discarded – undo
1182 1182
             $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1183 1183
             $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1184 1184
             $this->_template_args['before_list_table'] .= $datetime->name();
1185
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1185
+            $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )';
1186 1186
             $this->_template_args['before_list_table'] .= '</span></h2>';
1187 1187
         }
1188 1188
         //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1189 1189
         // column represents
1190
-        if (! $datetime instanceof EE_Datetime) {
1190
+        if ( ! $datetime instanceof EE_Datetime) {
1191 1191
             $this->_template_args['before_list_table'] .= '<br><p class="description">'
1192 1192
                 . esc_html__(
1193 1193
                     'In this view, the check-in status represents the latest check-in record for the registration in that row.',
@@ -1253,7 +1253,7 @@  discard block
 block discarded – undo
1253 1253
         //normalize some request params that get setup by the parent `get_registrations` method.
1254 1254
         $request = $this->_req_data;
1255 1255
         $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1256
-        $request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1256
+        $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1257 1257
         if ($trash) {
1258 1258
             $request['status'] = 'trash';
1259 1259
         }
Please login to merge, or discard this patch.
core/services/cache/TransientCacheStorage.php 2 patches
Indentation   +367 added lines, -367 removed lines patch added patch discarded remove patch
@@ -19,373 +19,373 @@
 block discarded – undo
19 19
 class TransientCacheStorage implements CacheStorageInterface
20 20
 {
21 21
 
22
-    /**
23
-     * wp-option option_name for tracking transients
24
-     *
25
-     * @type string
26
-     */
27
-    const TRANSIENT_SCHEDULE_OPTIONS_KEY = 'ee_transient_schedule';
28
-
29
-    /**
30
-     * @var int $current_time
31
-     */
32
-    private $current_time;
33
-
34
-    /**
35
-     * how often to perform transient cleanup
36
-     *
37
-     * @var string $transient_cleanup_frequency
38
-     */
39
-    private $transient_cleanup_frequency;
40
-
41
-    /**
42
-     * options for how often to perform transient cleanup
43
-     *
44
-     * @var array $transient_cleanup_frequency_options
45
-     */
46
-    private $transient_cleanup_frequency_options = array();
47
-
48
-    /**
49
-     * @var array $transients
50
-     */
51
-    private $transients;
52
-
53
-
54
-
55
-    /**
56
-     * TransientCacheStorage constructor.
57
-     */
58
-    public function __construct()
59
-    {
60
-        $this->transient_cleanup_frequency = $this->setTransientCleanupFrequency();
61
-        // round current time down to closest 5 minutes to simplify scheduling
62
-        $this->current_time = $this->roundTimestamp(time(), '5-minutes', false);
63
-        $this->transients = (array)get_option(TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY, array());
64
-        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && $this->transient_cleanup_frequency !== 'off') {
65
-            add_action('shutdown', array($this, 'checkTransientCleanupSchedule'), 999);
66
-        }
67
-    }
68
-
69
-
70
-
71
-    /**
72
-     * Sets how often transient cleanup occurs
73
-     *
74
-     * @return string
75
-     */
76
-    private function setTransientCleanupFrequency()
77
-    {
78
-        // sets how often transients are cleaned up
79
-        $this->transient_cleanup_frequency_options = apply_filters(
80
-            'FHEE__TransientCacheStorage__transient_cleanup_schedule_options',
81
-            array(
82
-                'off',
83
-                '15-minutes',
84
-                'hour',
85
-                '12-hours',
86
-                'day',
87
-            )
88
-        );
89
-        $transient_cleanup_frequency = apply_filters(
90
-            'FHEE__TransientCacheStorage__transient_cleanup_schedule',
91
-            'hour'
92
-        );
93
-        return in_array(
94
-            $transient_cleanup_frequency,
95
-            $this->transient_cleanup_frequency_options,
96
-            true
97
-        )
98
-            ? $transient_cleanup_frequency
99
-            : 'hour';
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     * we need to be able to round timestamps off to match the set transient cleanup frequency
106
-     * so if a transient is set to expire at 1:17 pm for example, and our cleanup schedule is every hour,
107
-     * then that timestamp needs to be rounded up to 2:00 pm so that it is removed
108
-     * during the next scheduled cleanup after its expiration.
109
-     * We also round off the current time timestamp to the closest 5 minutes
110
-     * just to make the timestamps a little easier to round which helps with debugging.
111
-     *
112
-     * @param int    $timestamp [required]
113
-     * @param string $cleanup_frequency
114
-     * @param bool   $round_up
115
-     * @return int
116
-     */
117
-    private function roundTimestamp($timestamp, $cleanup_frequency = 'hour', $round_up = true)
118
-    {
119
-        $cleanup_frequency = $cleanup_frequency ? $cleanup_frequency : $this->transient_cleanup_frequency;
120
-        // in order to round the time to the closest xx minutes (or hours),
121
-        // we take the minutes (or hours) portion of the timestamp and divide it by xx,
122
-        // round down to a whole number, then multiply by xx to bring us almost back up to where we were
123
-        // why round down ? so the minutes (or hours) don't go over 60 (or 24)
124
-        // and bump the hour, which could bump the day, which could bump the month, etc,
125
-        // which would be bad because we don't always want to round up,
126
-        // but when we do we can easily achieve that by simply adding the desired offset,
127
-        $minutes = '00';
128
-        $hours = 'H';
129
-        switch ($cleanup_frequency) {
130
-            case '5-minutes' :
131
-                $minutes = floor((int)date('i', $timestamp) / 5) * 5;
132
-                $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);
133
-                $offset = MINUTE_IN_SECONDS * 5;
134
-                break;
135
-            case '15-minutes' :
136
-                $minutes = floor((int)date('i', $timestamp) / 15) * 15;
137
-                $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);
138
-                $offset = MINUTE_IN_SECONDS * 15;
139
-                break;
140
-            case '12-hours' :
141
-                $hours = floor((int)date('H', $timestamp) / 12) * 12;
142
-                $hours = str_pad($hours, 2, '0', STR_PAD_LEFT);
143
-                $offset = HOUR_IN_SECONDS * 12;
144
-                break;
145
-            case 'day' :
146
-                $hours = '03'; // run cleanup at 3:00 am (or first site hit after that)
147
-                $offset = DAY_IN_SECONDS;
148
-                break;
149
-            case 'hour' :
150
-            default :
151
-                $offset = HOUR_IN_SECONDS;
152
-                break;
153
-        }
154
-        $rounded_timestamp = (int) strtotime(date("Y-m-d {$hours}:{$minutes}:00", $timestamp));
155
-        $rounded_timestamp += $round_up ? $offset : 0;
156
-        return apply_filters(
157
-            'FHEE__TransientCacheStorage__roundTimestamp__timestamp',
158
-            $rounded_timestamp,
159
-            $timestamp,
160
-            $cleanup_frequency,
161
-            $round_up
162
-        );
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * Saves supplied data to a transient
169
-     * if an expiration is set, then it automatically schedules the transient for cleanup
170
-     *
171
-     * @param string $transient_key [required]
172
-     * @param string $data          [required]
173
-     * @param int    $expiration    number of seconds until the cache expires
174
-     * @return bool
175
-     */
176
-    public function add($transient_key, $data, $expiration = 0)
177
-    {
178
-        $expiration = (int)abs($expiration);
179
-        $saved = set_transient($transient_key, $data, $expiration);
180
-        if ($saved && $expiration) {
181
-            $this->scheduleTransientCleanup($transient_key, $expiration);
182
-        }
183
-        return $saved;
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * retrieves transient data
190
-     * automatically triggers early cache refresh for standard cache items
191
-     * in order to avoid cache stampedes on busy sites.
192
-     * For non-standard cache items like PHP Session data where early refreshing is not wanted,
193
-     * the $standard_cache parameter should be set to false when retrieving data
194
-     *
195
-     * @param string $transient_key [required]
196
-     * @param bool   $standard_cache
197
-     * @return mixed|null
198
-     */
199
-    public function get($transient_key, $standard_cache = true)
200
-    {
201
-        // to avoid cache stampedes (AKA:dogpiles) for standard cache items,
202
-        // check if known cache expires within the next minute,
203
-        // and if so, remove it from our tracking and and return nothing.
204
-        // this should trigger the cache content to be regenerated during this request,
205
-        // while allowing any following requests to still access the existing cache
206
-        // until it gets replaced with the refreshed content
207
-        if (
208
-            $standard_cache
209
-            && isset($this->transients[$transient_key])
210
-            && $this->transients[$transient_key] - time() <= MINUTE_IN_SECONDS
211
-        ) {
212
-            unset($this->transients[$transient_key]);
213
-            $this->updateTransients();
214
-            return null;
215
-        }
216
-        $content = get_transient($transient_key);
217
-        return $content !== false ? $content : null;
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * delete a single transient and remove tracking
224
-     *
225
-     * @param string $transient_key [required] full or partial transient key to be deleted
226
-     */
227
-    public function delete($transient_key)
228
-    {
229
-        $this->deleteMany(array($transient_key));
230
-    }
231
-
232
-
233
-
234
-    /**
235
-     * delete multiple transients and remove tracking
236
-     *
237
-     * @param array $transient_keys [required] array of full or partial transient keys to be deleted
238
-     * @param bool  $force_delete   [optional] if true, then will not check incoming keys against those being tracked
239
-     *                              and proceed directly to deleting those entries from the cache storage
240
-     */
241
-    public function deleteMany(array $transient_keys, $force_delete = false)
242
-    {
243
-        $full_transient_keys = $force_delete ? $transient_keys : array();
244
-        if(empty($full_transient_keys)){
245
-            foreach ($this->transients as $transient_key => $expiration) {
246
-                foreach ($transient_keys as $transient_key_to_delete) {
247
-                    if (strpos($transient_key, $transient_key_to_delete) !== false) {
248
-                        $full_transient_keys[] = $transient_key;
249
-                    }
250
-                }
251
-            }
252
-        }
253
-        if ($this->deleteTransientKeys($full_transient_keys)) {
254
-            $this->updateTransients();
255
-        }
256
-    }
257
-
258
-
259
-
260
-    /**
261
-     * sorts transients numerically by timestamp
262
-     * then saves the transient schedule to a WP option
263
-     */
264
-    private function updateTransients()
265
-    {
266
-        asort($this->transients, SORT_NUMERIC);
267
-        update_option(
268
-            TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY,
269
-            $this->transients
270
-        );
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * schedules a transient for cleanup by adding it to the transient tracking
277
-     *
278
-     * @param string $transient_key [required]
279
-     * @param int    $expiration    [required]
280
-     */
281
-    private function scheduleTransientCleanup($transient_key, $expiration)
282
-    {
283
-        // make sure a valid future timestamp is set
284
-        $expiration += $expiration < time() ? time() : 0;
285
-        // and round to the closest 15 minutes
286
-        $expiration = $this->roundTimestamp($expiration);
287
-        // save transients to clear using their ID as the key to avoid duplicates
288
-        $this->transients[$transient_key] = $expiration;
289
-        $this->updateTransients();
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     * Since our tracked transients are sorted by their timestamps
296
-     * we can grab the first transient and see when it is scheduled for cleanup.
297
-     * If that timestamp is less than or equal to the current time,
298
-     * then cleanup is triggered
299
-     */
300
-    public function checkTransientCleanupSchedule()
301
-    {
302
-        if (empty($this->transients)) {
303
-            return;
304
-        }
305
-        // when do we run the next cleanup job?
306
-        reset($this->transients);
307
-        $next_scheduled_cleanup = current($this->transients);
308
-        // if the next cleanup job is scheduled for the current hour
309
-        if ($next_scheduled_cleanup <= $this->current_time) {
310
-            if ($this->cleanupExpiredTransients()) {
311
-                $this->updateTransients();
312
-            }
313
-        }
314
-    }
315
-
316
-
317
-
318
-    /**
319
-     * loops through the array of tracked transients,
320
-     * compiles a list of those that have expired, and sends that list off for deletion.
321
-     * Also removes any bad records from the transients array
322
-     *
323
-     * @return bool
324
-     */
325
-    private function cleanupExpiredTransients()
326
-    {
327
-        $update = false;
328
-        // filter the query limit. Set to 0 to turn off garbage collection
329
-        $limit = (int)abs(
330
-            apply_filters(
331
-                'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
332
-                50
333
-            )
334
-        );
335
-        // non-zero LIMIT means take out the trash
336
-        if ($limit) {
337
-            $transient_keys = array();
338
-            foreach ($this->transients as $transient_key => $expiration) {
339
-                if ($expiration > $this->current_time) {
340
-                    continue;
341
-                }
342
-                if ( ! $expiration || ! $transient_key) {
343
-                    unset($this->transients[$transient_key]);
344
-                    $update = true;
345
-                    continue;
346
-                }
347
-                $transient_keys[] = $transient_key;
348
-            }
349
-            // delete expired keys, but maintain value of $update if nothing is deleted
350
-            $update = $this->deleteTransientKeys($transient_keys, $limit) ? true : $update;
351
-            do_action( 'FHEE__TransientCacheStorage__clearExpiredTransients__end', $this);
352
-        }
353
-        return $update;
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * calls delete_transient() on each transient key provided, up to the specified limit
360
-     *
361
-     * @param array $transient_keys [required]
362
-     * @param int   $limit
363
-     * @return bool
364
-     */
365
-    private function deleteTransientKeys(array $transient_keys, $limit = 50)
366
-    {
367
-        if (empty($transient_keys)) {
368
-            return false;
369
-        }
370
-        $counter = 0;
371
-        foreach ($transient_keys as $transient_key) {
372
-            if($counter === $limit){
373
-                break;
374
-            }
375
-            // remove any transient prefixes
376
-            $transient_key = strpos($transient_key,  '_transient_timeout_') === 0
377
-                ? str_replace('_transient_timeout_', '', $transient_key)
378
-                : $transient_key;
379
-            $transient_key = strpos($transient_key,  '_transient_') === 0
380
-                ? str_replace('_transient_', '', $transient_key)
381
-                : $transient_key;
382
-            if(delete_transient($transient_key)){
383
-                unset($this->transients[$transient_key]);
384
-                $counter++;
385
-            }
386
-        }
387
-        return $counter > 0;
388
-    }
22
+	/**
23
+	 * wp-option option_name for tracking transients
24
+	 *
25
+	 * @type string
26
+	 */
27
+	const TRANSIENT_SCHEDULE_OPTIONS_KEY = 'ee_transient_schedule';
28
+
29
+	/**
30
+	 * @var int $current_time
31
+	 */
32
+	private $current_time;
33
+
34
+	/**
35
+	 * how often to perform transient cleanup
36
+	 *
37
+	 * @var string $transient_cleanup_frequency
38
+	 */
39
+	private $transient_cleanup_frequency;
40
+
41
+	/**
42
+	 * options for how often to perform transient cleanup
43
+	 *
44
+	 * @var array $transient_cleanup_frequency_options
45
+	 */
46
+	private $transient_cleanup_frequency_options = array();
47
+
48
+	/**
49
+	 * @var array $transients
50
+	 */
51
+	private $transients;
52
+
53
+
54
+
55
+	/**
56
+	 * TransientCacheStorage constructor.
57
+	 */
58
+	public function __construct()
59
+	{
60
+		$this->transient_cleanup_frequency = $this->setTransientCleanupFrequency();
61
+		// round current time down to closest 5 minutes to simplify scheduling
62
+		$this->current_time = $this->roundTimestamp(time(), '5-minutes', false);
63
+		$this->transients = (array)get_option(TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY, array());
64
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX) && $this->transient_cleanup_frequency !== 'off') {
65
+			add_action('shutdown', array($this, 'checkTransientCleanupSchedule'), 999);
66
+		}
67
+	}
68
+
69
+
70
+
71
+	/**
72
+	 * Sets how often transient cleanup occurs
73
+	 *
74
+	 * @return string
75
+	 */
76
+	private function setTransientCleanupFrequency()
77
+	{
78
+		// sets how often transients are cleaned up
79
+		$this->transient_cleanup_frequency_options = apply_filters(
80
+			'FHEE__TransientCacheStorage__transient_cleanup_schedule_options',
81
+			array(
82
+				'off',
83
+				'15-minutes',
84
+				'hour',
85
+				'12-hours',
86
+				'day',
87
+			)
88
+		);
89
+		$transient_cleanup_frequency = apply_filters(
90
+			'FHEE__TransientCacheStorage__transient_cleanup_schedule',
91
+			'hour'
92
+		);
93
+		return in_array(
94
+			$transient_cleanup_frequency,
95
+			$this->transient_cleanup_frequency_options,
96
+			true
97
+		)
98
+			? $transient_cleanup_frequency
99
+			: 'hour';
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 * we need to be able to round timestamps off to match the set transient cleanup frequency
106
+	 * so if a transient is set to expire at 1:17 pm for example, and our cleanup schedule is every hour,
107
+	 * then that timestamp needs to be rounded up to 2:00 pm so that it is removed
108
+	 * during the next scheduled cleanup after its expiration.
109
+	 * We also round off the current time timestamp to the closest 5 minutes
110
+	 * just to make the timestamps a little easier to round which helps with debugging.
111
+	 *
112
+	 * @param int    $timestamp [required]
113
+	 * @param string $cleanup_frequency
114
+	 * @param bool   $round_up
115
+	 * @return int
116
+	 */
117
+	private function roundTimestamp($timestamp, $cleanup_frequency = 'hour', $round_up = true)
118
+	{
119
+		$cleanup_frequency = $cleanup_frequency ? $cleanup_frequency : $this->transient_cleanup_frequency;
120
+		// in order to round the time to the closest xx minutes (or hours),
121
+		// we take the minutes (or hours) portion of the timestamp and divide it by xx,
122
+		// round down to a whole number, then multiply by xx to bring us almost back up to where we were
123
+		// why round down ? so the minutes (or hours) don't go over 60 (or 24)
124
+		// and bump the hour, which could bump the day, which could bump the month, etc,
125
+		// which would be bad because we don't always want to round up,
126
+		// but when we do we can easily achieve that by simply adding the desired offset,
127
+		$minutes = '00';
128
+		$hours = 'H';
129
+		switch ($cleanup_frequency) {
130
+			case '5-minutes' :
131
+				$minutes = floor((int)date('i', $timestamp) / 5) * 5;
132
+				$minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);
133
+				$offset = MINUTE_IN_SECONDS * 5;
134
+				break;
135
+			case '15-minutes' :
136
+				$minutes = floor((int)date('i', $timestamp) / 15) * 15;
137
+				$minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);
138
+				$offset = MINUTE_IN_SECONDS * 15;
139
+				break;
140
+			case '12-hours' :
141
+				$hours = floor((int)date('H', $timestamp) / 12) * 12;
142
+				$hours = str_pad($hours, 2, '0', STR_PAD_LEFT);
143
+				$offset = HOUR_IN_SECONDS * 12;
144
+				break;
145
+			case 'day' :
146
+				$hours = '03'; // run cleanup at 3:00 am (or first site hit after that)
147
+				$offset = DAY_IN_SECONDS;
148
+				break;
149
+			case 'hour' :
150
+			default :
151
+				$offset = HOUR_IN_SECONDS;
152
+				break;
153
+		}
154
+		$rounded_timestamp = (int) strtotime(date("Y-m-d {$hours}:{$minutes}:00", $timestamp));
155
+		$rounded_timestamp += $round_up ? $offset : 0;
156
+		return apply_filters(
157
+			'FHEE__TransientCacheStorage__roundTimestamp__timestamp',
158
+			$rounded_timestamp,
159
+			$timestamp,
160
+			$cleanup_frequency,
161
+			$round_up
162
+		);
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * Saves supplied data to a transient
169
+	 * if an expiration is set, then it automatically schedules the transient for cleanup
170
+	 *
171
+	 * @param string $transient_key [required]
172
+	 * @param string $data          [required]
173
+	 * @param int    $expiration    number of seconds until the cache expires
174
+	 * @return bool
175
+	 */
176
+	public function add($transient_key, $data, $expiration = 0)
177
+	{
178
+		$expiration = (int)abs($expiration);
179
+		$saved = set_transient($transient_key, $data, $expiration);
180
+		if ($saved && $expiration) {
181
+			$this->scheduleTransientCleanup($transient_key, $expiration);
182
+		}
183
+		return $saved;
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * retrieves transient data
190
+	 * automatically triggers early cache refresh for standard cache items
191
+	 * in order to avoid cache stampedes on busy sites.
192
+	 * For non-standard cache items like PHP Session data where early refreshing is not wanted,
193
+	 * the $standard_cache parameter should be set to false when retrieving data
194
+	 *
195
+	 * @param string $transient_key [required]
196
+	 * @param bool   $standard_cache
197
+	 * @return mixed|null
198
+	 */
199
+	public function get($transient_key, $standard_cache = true)
200
+	{
201
+		// to avoid cache stampedes (AKA:dogpiles) for standard cache items,
202
+		// check if known cache expires within the next minute,
203
+		// and if so, remove it from our tracking and and return nothing.
204
+		// this should trigger the cache content to be regenerated during this request,
205
+		// while allowing any following requests to still access the existing cache
206
+		// until it gets replaced with the refreshed content
207
+		if (
208
+			$standard_cache
209
+			&& isset($this->transients[$transient_key])
210
+			&& $this->transients[$transient_key] - time() <= MINUTE_IN_SECONDS
211
+		) {
212
+			unset($this->transients[$transient_key]);
213
+			$this->updateTransients();
214
+			return null;
215
+		}
216
+		$content = get_transient($transient_key);
217
+		return $content !== false ? $content : null;
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * delete a single transient and remove tracking
224
+	 *
225
+	 * @param string $transient_key [required] full or partial transient key to be deleted
226
+	 */
227
+	public function delete($transient_key)
228
+	{
229
+		$this->deleteMany(array($transient_key));
230
+	}
231
+
232
+
233
+
234
+	/**
235
+	 * delete multiple transients and remove tracking
236
+	 *
237
+	 * @param array $transient_keys [required] array of full or partial transient keys to be deleted
238
+	 * @param bool  $force_delete   [optional] if true, then will not check incoming keys against those being tracked
239
+	 *                              and proceed directly to deleting those entries from the cache storage
240
+	 */
241
+	public function deleteMany(array $transient_keys, $force_delete = false)
242
+	{
243
+		$full_transient_keys = $force_delete ? $transient_keys : array();
244
+		if(empty($full_transient_keys)){
245
+			foreach ($this->transients as $transient_key => $expiration) {
246
+				foreach ($transient_keys as $transient_key_to_delete) {
247
+					if (strpos($transient_key, $transient_key_to_delete) !== false) {
248
+						$full_transient_keys[] = $transient_key;
249
+					}
250
+				}
251
+			}
252
+		}
253
+		if ($this->deleteTransientKeys($full_transient_keys)) {
254
+			$this->updateTransients();
255
+		}
256
+	}
257
+
258
+
259
+
260
+	/**
261
+	 * sorts transients numerically by timestamp
262
+	 * then saves the transient schedule to a WP option
263
+	 */
264
+	private function updateTransients()
265
+	{
266
+		asort($this->transients, SORT_NUMERIC);
267
+		update_option(
268
+			TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY,
269
+			$this->transients
270
+		);
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * schedules a transient for cleanup by adding it to the transient tracking
277
+	 *
278
+	 * @param string $transient_key [required]
279
+	 * @param int    $expiration    [required]
280
+	 */
281
+	private function scheduleTransientCleanup($transient_key, $expiration)
282
+	{
283
+		// make sure a valid future timestamp is set
284
+		$expiration += $expiration < time() ? time() : 0;
285
+		// and round to the closest 15 minutes
286
+		$expiration = $this->roundTimestamp($expiration);
287
+		// save transients to clear using their ID as the key to avoid duplicates
288
+		$this->transients[$transient_key] = $expiration;
289
+		$this->updateTransients();
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 * Since our tracked transients are sorted by their timestamps
296
+	 * we can grab the first transient and see when it is scheduled for cleanup.
297
+	 * If that timestamp is less than or equal to the current time,
298
+	 * then cleanup is triggered
299
+	 */
300
+	public function checkTransientCleanupSchedule()
301
+	{
302
+		if (empty($this->transients)) {
303
+			return;
304
+		}
305
+		// when do we run the next cleanup job?
306
+		reset($this->transients);
307
+		$next_scheduled_cleanup = current($this->transients);
308
+		// if the next cleanup job is scheduled for the current hour
309
+		if ($next_scheduled_cleanup <= $this->current_time) {
310
+			if ($this->cleanupExpiredTransients()) {
311
+				$this->updateTransients();
312
+			}
313
+		}
314
+	}
315
+
316
+
317
+
318
+	/**
319
+	 * loops through the array of tracked transients,
320
+	 * compiles a list of those that have expired, and sends that list off for deletion.
321
+	 * Also removes any bad records from the transients array
322
+	 *
323
+	 * @return bool
324
+	 */
325
+	private function cleanupExpiredTransients()
326
+	{
327
+		$update = false;
328
+		// filter the query limit. Set to 0 to turn off garbage collection
329
+		$limit = (int)abs(
330
+			apply_filters(
331
+				'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
332
+				50
333
+			)
334
+		);
335
+		// non-zero LIMIT means take out the trash
336
+		if ($limit) {
337
+			$transient_keys = array();
338
+			foreach ($this->transients as $transient_key => $expiration) {
339
+				if ($expiration > $this->current_time) {
340
+					continue;
341
+				}
342
+				if ( ! $expiration || ! $transient_key) {
343
+					unset($this->transients[$transient_key]);
344
+					$update = true;
345
+					continue;
346
+				}
347
+				$transient_keys[] = $transient_key;
348
+			}
349
+			// delete expired keys, but maintain value of $update if nothing is deleted
350
+			$update = $this->deleteTransientKeys($transient_keys, $limit) ? true : $update;
351
+			do_action( 'FHEE__TransientCacheStorage__clearExpiredTransients__end', $this);
352
+		}
353
+		return $update;
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * calls delete_transient() on each transient key provided, up to the specified limit
360
+	 *
361
+	 * @param array $transient_keys [required]
362
+	 * @param int   $limit
363
+	 * @return bool
364
+	 */
365
+	private function deleteTransientKeys(array $transient_keys, $limit = 50)
366
+	{
367
+		if (empty($transient_keys)) {
368
+			return false;
369
+		}
370
+		$counter = 0;
371
+		foreach ($transient_keys as $transient_key) {
372
+			if($counter === $limit){
373
+				break;
374
+			}
375
+			// remove any transient prefixes
376
+			$transient_key = strpos($transient_key,  '_transient_timeout_') === 0
377
+				? str_replace('_transient_timeout_', '', $transient_key)
378
+				: $transient_key;
379
+			$transient_key = strpos($transient_key,  '_transient_') === 0
380
+				? str_replace('_transient_', '', $transient_key)
381
+				: $transient_key;
382
+			if(delete_transient($transient_key)){
383
+				unset($this->transients[$transient_key]);
384
+				$counter++;
385
+			}
386
+		}
387
+		return $counter > 0;
388
+	}
389 389
 
390 390
 
391 391
 
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         $this->transient_cleanup_frequency = $this->setTransientCleanupFrequency();
61 61
         // round current time down to closest 5 minutes to simplify scheduling
62 62
         $this->current_time = $this->roundTimestamp(time(), '5-minutes', false);
63
-        $this->transients = (array)get_option(TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY, array());
63
+        $this->transients = (array) get_option(TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY, array());
64 64
         if ( ! (defined('DOING_AJAX') && DOING_AJAX) && $this->transient_cleanup_frequency !== 'off') {
65 65
             add_action('shutdown', array($this, 'checkTransientCleanupSchedule'), 999);
66 66
         }
@@ -128,17 +128,17 @@  discard block
 block discarded – undo
128 128
         $hours = 'H';
129 129
         switch ($cleanup_frequency) {
130 130
             case '5-minutes' :
131
-                $minutes = floor((int)date('i', $timestamp) / 5) * 5;
131
+                $minutes = floor((int) date('i', $timestamp) / 5) * 5;
132 132
                 $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);
133 133
                 $offset = MINUTE_IN_SECONDS * 5;
134 134
                 break;
135 135
             case '15-minutes' :
136
-                $minutes = floor((int)date('i', $timestamp) / 15) * 15;
136
+                $minutes = floor((int) date('i', $timestamp) / 15) * 15;
137 137
                 $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);
138 138
                 $offset = MINUTE_IN_SECONDS * 15;
139 139
                 break;
140 140
             case '12-hours' :
141
-                $hours = floor((int)date('H', $timestamp) / 12) * 12;
141
+                $hours = floor((int) date('H', $timestamp) / 12) * 12;
142 142
                 $hours = str_pad($hours, 2, '0', STR_PAD_LEFT);
143 143
                 $offset = HOUR_IN_SECONDS * 12;
144 144
                 break;
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
      */
176 176
     public function add($transient_key, $data, $expiration = 0)
177 177
     {
178
-        $expiration = (int)abs($expiration);
178
+        $expiration = (int) abs($expiration);
179 179
         $saved = set_transient($transient_key, $data, $expiration);
180 180
         if ($saved && $expiration) {
181 181
             $this->scheduleTransientCleanup($transient_key, $expiration);
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
     public function deleteMany(array $transient_keys, $force_delete = false)
242 242
     {
243 243
         $full_transient_keys = $force_delete ? $transient_keys : array();
244
-        if(empty($full_transient_keys)){
244
+        if (empty($full_transient_keys)) {
245 245
             foreach ($this->transients as $transient_key => $expiration) {
246 246
                 foreach ($transient_keys as $transient_key_to_delete) {
247 247
                     if (strpos($transient_key, $transient_key_to_delete) !== false) {
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
     {
327 327
         $update = false;
328 328
         // filter the query limit. Set to 0 to turn off garbage collection
329
-        $limit = (int)abs(
329
+        $limit = (int) abs(
330 330
             apply_filters(
331 331
                 'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
332 332
                 50
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
             }
349 349
             // delete expired keys, but maintain value of $update if nothing is deleted
350 350
             $update = $this->deleteTransientKeys($transient_keys, $limit) ? true : $update;
351
-            do_action( 'FHEE__TransientCacheStorage__clearExpiredTransients__end', $this);
351
+            do_action('FHEE__TransientCacheStorage__clearExpiredTransients__end', $this);
352 352
         }
353 353
         return $update;
354 354
     }
@@ -369,17 +369,17 @@  discard block
 block discarded – undo
369 369
         }
370 370
         $counter = 0;
371 371
         foreach ($transient_keys as $transient_key) {
372
-            if($counter === $limit){
372
+            if ($counter === $limit) {
373 373
                 break;
374 374
             }
375 375
             // remove any transient prefixes
376
-            $transient_key = strpos($transient_key,  '_transient_timeout_') === 0
376
+            $transient_key = strpos($transient_key, '_transient_timeout_') === 0
377 377
                 ? str_replace('_transient_timeout_', '', $transient_key)
378 378
                 : $transient_key;
379
-            $transient_key = strpos($transient_key,  '_transient_') === 0
379
+            $transient_key = strpos($transient_key, '_transient_') === 0
380 380
                 ? str_replace('_transient_', '', $transient_key)
381 381
                 : $transient_key;
382
-            if(delete_transient($transient_key)){
382
+            if (delete_transient($transient_key)) {
383 383
                 unset($this->transients[$transient_key]);
384 384
                 $counter++;
385 385
             }
Please login to merge, or discard this patch.
core/services/cache/CacheStorageInterface.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -15,52 +15,52 @@
 block discarded – undo
15 15
 interface CacheStorageInterface
16 16
 {
17 17
 
18
-    /**
19
-     * Saves supplied data
20
-     * if an expiration is set, then it automatically schedules the cache for deletion
21
-     *
22
-     * @param string $key        [required]
23
-     * @param string $data       [required]
24
-     * @param int    $expiration number of seconds until the cache expires
25
-     * @return bool
26
-     */
27
-    public function add($key, $data, $expiration = 0);
18
+	/**
19
+	 * Saves supplied data
20
+	 * if an expiration is set, then it automatically schedules the cache for deletion
21
+	 *
22
+	 * @param string $key        [required]
23
+	 * @param string $data       [required]
24
+	 * @param int    $expiration number of seconds until the cache expires
25
+	 * @return bool
26
+	 */
27
+	public function add($key, $data, $expiration = 0);
28 28
 
29 29
 
30 30
 
31
-    /**
32
-     * retrieves cache data
33
-     * should automatically trigger early cache refresh for standard cache items
34
-     * in order to avoid cache stampedes on busy sites.
35
-     * For non-standard cache items like PHP Session data where early refreshing is not wanted,
36
-     * the $standard_cache parameter should be set to false when retrieving data
37
-     *
38
-     * @param string $key [required]
39
-     * @param bool   $standard_cache
40
-     * @return mixed
41
-     */
42
-    public function get($key, $standard_cache = true);
31
+	/**
32
+	 * retrieves cache data
33
+	 * should automatically trigger early cache refresh for standard cache items
34
+	 * in order to avoid cache stampedes on busy sites.
35
+	 * For non-standard cache items like PHP Session data where early refreshing is not wanted,
36
+	 * the $standard_cache parameter should be set to false when retrieving data
37
+	 *
38
+	 * @param string $key [required]
39
+	 * @param bool   $standard_cache
40
+	 * @return mixed
41
+	 */
42
+	public function get($key, $standard_cache = true);
43 43
 
44 44
 
45 45
 
46
-    /**
47
-     * delete a single cached item
48
-     *
49
-     * @param string $key [required] full or partial cache key to be deleted
50
-     */
51
-    public function delete($key);
46
+	/**
47
+	 * delete a single cached item
48
+	 *
49
+	 * @param string $key [required] full or partial cache key to be deleted
50
+	 */
51
+	public function delete($key);
52 52
 
53 53
 
54 54
 
55
-    /**
56
-     * delete multiple cached items
57
-     *
58
-     * @param array $keys           [required] array of full or partial cache keys to be deleted
59
-     * @param bool  $force_delete   [optional] if true, then will not check incoming keys against those being tracked
60
-     *                              and proceed directly to deleting those entries from the cache storage
61
-     * @return
62
-     */
63
-    public function deleteMany(array $keys, $force_delete = false);
55
+	/**
56
+	 * delete multiple cached items
57
+	 *
58
+	 * @param array $keys           [required] array of full or partial cache keys to be deleted
59
+	 * @param bool  $force_delete   [optional] if true, then will not check incoming keys against those being tracked
60
+	 *                              and proceed directly to deleting those entries from the cache storage
61
+	 * @return
62
+	 */
63
+	public function deleteMany(array $keys, $force_delete = false);
64 64
 
65 65
 }
66 66
 // End of file CacheStorageInterface.php
Please login to merge, or discard this patch.
core/EE_Session.core.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
      *
485 485
      * @access    public
486 486
      * @param    array $data
487
-     * @return    TRUE on success, FALSE on fail
487
+     * @return    boolean on success, FALSE on fail
488 488
      */
489 489
     public function set_session_data($data)
490 490
     {
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
     /**
512 512
      * @initiate session
513 513
      * @access   private
514
-     * @return TRUE on success, FALSE on fail
514
+     * @return boolean on success, FALSE on fail
515 515
      * @throws EE_Error
516 516
      * @throws InvalidArgumentException
517 517
      * @throws InvalidDataTypeException
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
      * @update session data  prior to saving to the db
747 747
      * @access public
748 748
      * @param bool $new_session
749
-     * @return TRUE on success, FALSE on fail
749
+     * @return boolean on success, FALSE on fail
750 750
      * @throws EE_Error
751 751
      * @throws InvalidArgumentException
752 752
      * @throws InvalidDataTypeException
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
      * _save_session_to_db
848 848
      *
849 849
      * @access public
850
-     * @return string
850
+     * @return boolean
851 851
      * @throws EE_Error
852 852
      * @throws InvalidArgumentException
853 853
      * @throws InvalidDataTypeException
@@ -1023,7 +1023,7 @@  discard block
 block discarded – undo
1023 1023
      * @access public
1024 1024
      * @param array|mixed $data_to_reset
1025 1025
      * @param bool        $show_all_notices
1026
-     * @return TRUE on success, FALSE on fail
1026
+     * @return boolean on success, FALSE on fail
1027 1027
      */
1028 1028
     public function reset_data($data_to_reset = array(), $show_all_notices = false)
1029 1029
     {
Please login to merge, or discard this patch.
Indentation   +1219 added lines, -1219 removed lines patch added patch discarded remove patch
@@ -20,1225 +20,1225 @@  discard block
 block discarded – undo
20 20
 class EE_Session implements SessionIdentifierInterface
21 21
 {
22 22
 
23
-    const session_id_prefix    = 'ee_ssn_';
24
-
25
-    const hash_check_prefix    = 'ee_shc_';
26
-
27
-    const OPTION_NAME_SETTINGS = 'ee_session_settings';
28
-
29
-    /**
30
-     * instance of the EE_Session object
31
-     *
32
-     * @var EE_Session
33
-     */
34
-    private static $_instance;
35
-
36
-    /**
37
-     * @var CacheStorageInterface $cache_storage
38
-     */
39
-    protected $cache_storage;
40
-
41
-    /**
42
-     * EE_Encryption object
43
-     *
44
-     * @var EE_Encryption
45
-     */
46
-    protected $encryption;
47
-
48
-    /**
49
-     * the session id
50
-     *
51
-     * @var string
52
-     */
53
-    private $_sid;
54
-
55
-    /**
56
-     * session id salt
57
-     *
58
-     * @var string
59
-     */
60
-    private $_sid_salt;
61
-
62
-    /**
63
-     * session data
64
-     *
65
-     * @var array
66
-     */
67
-    private $_session_data = array();
68
-
69
-    /**
70
-     * how long an EE session lasts
71
-     * default session lifespan of 2 hours (for not so instant IPNs)
72
-     *
73
-     * @var int
74
-     */
75
-    private $_lifespan;
76
-
77
-    /**
78
-     * session expiration time as Unix timestamp in GMT
79
-     *
80
-     * @var int
81
-     */
82
-    private $_expiration;
83
-
84
-    /**
85
-     * whether or not session has expired at some point
86
-     *
87
-     * @var boolean
88
-     */
89
-    private $_expired = false;
90
-
91
-    /**
92
-     * current time as Unix timestamp in GMT
93
-     *
94
-     * @var int
95
-     */
96
-    private $_time;
97
-
98
-    /**
99
-     * whether to encrypt session data
100
-     *
101
-     * @var bool
102
-     */
103
-    private $_use_encryption;
104
-
105
-    /**
106
-     * well... according to the server...
107
-     *
108
-     * @var null
109
-     */
110
-    private $_user_agent;
111
-
112
-    /**
113
-     * do you really trust the server ?
114
-     *
115
-     * @var null
116
-     */
117
-    private $_ip_address;
118
-
119
-    /**
120
-     * current WP user_id
121
-     *
122
-     * @var null
123
-     */
124
-    private $_wp_user_id;
125
-
126
-    /**
127
-     * array for defining default session vars
128
-     *
129
-     * @var array
130
-     */
131
-    private $_default_session_vars = array(
132
-        'id'            => null,
133
-        'user_id'       => null,
134
-        'ip_address'    => null,
135
-        'user_agent'    => null,
136
-        'init_access'   => null,
137
-        'last_access'   => null,
138
-        'expiration'    => null,
139
-        'pages_visited' => array(),
140
-    );
141
-
142
-    /**
143
-     * timestamp for when last garbage collection cycle was performed
144
-     *
145
-     * @var int $_last_gc
146
-     */
147
-    private $_last_gc;
148
-
149
-
150
-
151
-    /**
152
-     * @singleton method used to instantiate class object
153
-     * @param CacheStorageInterface $cache_storage
154
-     * @param EE_Encryption         $encryption
155
-     * @return EE_Session
156
-     * @throws InvalidArgumentException
157
-     * @throws InvalidDataTypeException
158
-     * @throws InvalidInterfaceException
159
-     */
160
-    public static function instance(
161
-        CacheStorageInterface $cache_storage = null,
162
-        EE_Encryption $encryption = null
163
-    ) {
164
-        // check if class object is instantiated
165
-        // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
166
-        // add_filter( 'FHEE_load_EE_Session', '__return_false' );
167
-        if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
168
-            self::$_instance = new self($cache_storage, $encryption);
169
-        }
170
-        return self::$_instance;
171
-    }
172
-
173
-
174
-
175
-    /**
176
-     * protected constructor to prevent direct creation
177
-     *
178
-     * @param CacheStorageInterface $cache_storage
179
-     * @param EE_Encryption         $encryption
180
-     * @throws InvalidArgumentException
181
-     * @throws InvalidDataTypeException
182
-     * @throws InvalidInterfaceException
183
-     */
184
-    protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null)
185
-    {
186
-
187
-        // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
188
-        if (! apply_filters('FHEE_load_EE_Session', true)) {
189
-            return;
190
-        }
191
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
192
-        if (! defined('ESPRESSO_SESSION')) {
193
-            define('ESPRESSO_SESSION', true);
194
-        }
195
-        // default session lifespan in seconds
196
-        $this->_lifespan = apply_filters(
197
-                               'FHEE__EE_Session__construct___lifespan',
198
-                               60 * MINUTE_IN_SECONDS
199
-                           ) + 1;
200
-        /*
23
+	const session_id_prefix    = 'ee_ssn_';
24
+
25
+	const hash_check_prefix    = 'ee_shc_';
26
+
27
+	const OPTION_NAME_SETTINGS = 'ee_session_settings';
28
+
29
+	/**
30
+	 * instance of the EE_Session object
31
+	 *
32
+	 * @var EE_Session
33
+	 */
34
+	private static $_instance;
35
+
36
+	/**
37
+	 * @var CacheStorageInterface $cache_storage
38
+	 */
39
+	protected $cache_storage;
40
+
41
+	/**
42
+	 * EE_Encryption object
43
+	 *
44
+	 * @var EE_Encryption
45
+	 */
46
+	protected $encryption;
47
+
48
+	/**
49
+	 * the session id
50
+	 *
51
+	 * @var string
52
+	 */
53
+	private $_sid;
54
+
55
+	/**
56
+	 * session id salt
57
+	 *
58
+	 * @var string
59
+	 */
60
+	private $_sid_salt;
61
+
62
+	/**
63
+	 * session data
64
+	 *
65
+	 * @var array
66
+	 */
67
+	private $_session_data = array();
68
+
69
+	/**
70
+	 * how long an EE session lasts
71
+	 * default session lifespan of 2 hours (for not so instant IPNs)
72
+	 *
73
+	 * @var int
74
+	 */
75
+	private $_lifespan;
76
+
77
+	/**
78
+	 * session expiration time as Unix timestamp in GMT
79
+	 *
80
+	 * @var int
81
+	 */
82
+	private $_expiration;
83
+
84
+	/**
85
+	 * whether or not session has expired at some point
86
+	 *
87
+	 * @var boolean
88
+	 */
89
+	private $_expired = false;
90
+
91
+	/**
92
+	 * current time as Unix timestamp in GMT
93
+	 *
94
+	 * @var int
95
+	 */
96
+	private $_time;
97
+
98
+	/**
99
+	 * whether to encrypt session data
100
+	 *
101
+	 * @var bool
102
+	 */
103
+	private $_use_encryption;
104
+
105
+	/**
106
+	 * well... according to the server...
107
+	 *
108
+	 * @var null
109
+	 */
110
+	private $_user_agent;
111
+
112
+	/**
113
+	 * do you really trust the server ?
114
+	 *
115
+	 * @var null
116
+	 */
117
+	private $_ip_address;
118
+
119
+	/**
120
+	 * current WP user_id
121
+	 *
122
+	 * @var null
123
+	 */
124
+	private $_wp_user_id;
125
+
126
+	/**
127
+	 * array for defining default session vars
128
+	 *
129
+	 * @var array
130
+	 */
131
+	private $_default_session_vars = array(
132
+		'id'            => null,
133
+		'user_id'       => null,
134
+		'ip_address'    => null,
135
+		'user_agent'    => null,
136
+		'init_access'   => null,
137
+		'last_access'   => null,
138
+		'expiration'    => null,
139
+		'pages_visited' => array(),
140
+	);
141
+
142
+	/**
143
+	 * timestamp for when last garbage collection cycle was performed
144
+	 *
145
+	 * @var int $_last_gc
146
+	 */
147
+	private $_last_gc;
148
+
149
+
150
+
151
+	/**
152
+	 * @singleton method used to instantiate class object
153
+	 * @param CacheStorageInterface $cache_storage
154
+	 * @param EE_Encryption         $encryption
155
+	 * @return EE_Session
156
+	 * @throws InvalidArgumentException
157
+	 * @throws InvalidDataTypeException
158
+	 * @throws InvalidInterfaceException
159
+	 */
160
+	public static function instance(
161
+		CacheStorageInterface $cache_storage = null,
162
+		EE_Encryption $encryption = null
163
+	) {
164
+		// check if class object is instantiated
165
+		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
166
+		// add_filter( 'FHEE_load_EE_Session', '__return_false' );
167
+		if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
168
+			self::$_instance = new self($cache_storage, $encryption);
169
+		}
170
+		return self::$_instance;
171
+	}
172
+
173
+
174
+
175
+	/**
176
+	 * protected constructor to prevent direct creation
177
+	 *
178
+	 * @param CacheStorageInterface $cache_storage
179
+	 * @param EE_Encryption         $encryption
180
+	 * @throws InvalidArgumentException
181
+	 * @throws InvalidDataTypeException
182
+	 * @throws InvalidInterfaceException
183
+	 */
184
+	protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null)
185
+	{
186
+
187
+		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
188
+		if (! apply_filters('FHEE_load_EE_Session', true)) {
189
+			return;
190
+		}
191
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
192
+		if (! defined('ESPRESSO_SESSION')) {
193
+			define('ESPRESSO_SESSION', true);
194
+		}
195
+		// default session lifespan in seconds
196
+		$this->_lifespan = apply_filters(
197
+							   'FHEE__EE_Session__construct___lifespan',
198
+							   60 * MINUTE_IN_SECONDS
199
+						   ) + 1;
200
+		/*
201 201
          * do something like the following to adjust the session lifespan:
202 202
          * 		public static function session_lifespan() {
203 203
          * 			return 15 * MINUTE_IN_SECONDS;
204 204
          * 		}
205 205
          */
206
-        // retrieve session options from db
207
-        $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
208
-        if (! empty($session_settings)) {
209
-            // cycle though existing session options
210
-            foreach ($session_settings as $var_name => $session_setting) {
211
-                // set values for class properties
212
-                $var_name          = '_' . $var_name;
213
-                $this->{$var_name} = $session_setting;
214
-            }
215
-        }
216
-        $this->cache_storage = $cache_storage;
217
-        // are we using encryption?
218
-        $this->_use_encryption = $encryption instanceof EE_Encryption
219
-                                 && EE_Registry::instance()->CFG->admin->encode_session_data();
220
-        // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__);
221
-        // encrypt data via: $this->encryption->encrypt();
222
-        $this->encryption = $encryption;
223
-        // filter hook allows outside functions/classes/plugins to change default empty cart
224
-        $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
225
-        array_merge($this->_default_session_vars, $extra_default_session_vars);
226
-        // apply default session vars
227
-        $this->_set_defaults();
228
-        add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
229
-        // check request for 'clear_session' param
230
-        add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
231
-        // once everything is all said and done,
232
-        add_action('shutdown', array($this, 'update'), 100);
233
-        add_action('shutdown', array($this, 'garbageCollection'), 1000);
234
-        $this->configure_garbage_collection_filters();
235
-    }
236
-
237
-
238
-
239
-    /**
240
-     * @return void
241
-     * @throws EE_Error
242
-     * @throws InvalidArgumentException
243
-     * @throws InvalidDataTypeException
244
-     * @throws InvalidInterfaceException
245
-     * @throws InvalidSessionDataException
246
-     */
247
-    public function open_session()
248
-    {
249
-        // check for existing session and retrieve it from db
250
-        if (! $this->_espresso_session()) {
251
-            // or just start a new one
252
-            $this->_create_espresso_session();
253
-        }
254
-    }
255
-
256
-
257
-
258
-    /**
259
-     * @return bool
260
-     */
261
-    public function expired()
262
-    {
263
-        return $this->_expired;
264
-    }
265
-
266
-
267
-
268
-    /**
269
-     * @return void
270
-     */
271
-    public function reset_expired()
272
-    {
273
-        $this->_expired = false;
274
-    }
275
-
276
-
277
-    /**
278
-     * @return int
279
-     */
280
-    public function expiration()
281
-    {
282
-        return $this->_expiration;
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * @return int
289
-     */
290
-    public function extension()
291
-    {
292
-        return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS);
293
-    }
294
-
295
-
296
-
297
-    /**
298
-     * @param int $time number of seconds to add to session expiration
299
-     */
300
-    public function extend_expiration($time = 0)
301
-    {
302
-        $time              = $time ? $time : $this->extension();
303
-        $this->_expiration += absint($time);
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     * @return int
310
-     */
311
-    public function lifespan()
312
-    {
313
-        return $this->_lifespan;
314
-    }
315
-
316
-
317
-
318
-    /**
319
-     * This just sets some defaults for the _session data property
320
-     *
321
-     * @access private
322
-     * @return void
323
-     */
324
-    private function _set_defaults()
325
-    {
326
-        // set some defaults
327
-        foreach ($this->_default_session_vars as $key => $default_var) {
328
-            if (is_array($default_var)) {
329
-                $this->_session_data[ $key ] = array();
330
-            } else {
331
-                $this->_session_data[ $key ] = '';
332
-            }
333
-        }
334
-    }
206
+		// retrieve session options from db
207
+		$session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
208
+		if (! empty($session_settings)) {
209
+			// cycle though existing session options
210
+			foreach ($session_settings as $var_name => $session_setting) {
211
+				// set values for class properties
212
+				$var_name          = '_' . $var_name;
213
+				$this->{$var_name} = $session_setting;
214
+			}
215
+		}
216
+		$this->cache_storage = $cache_storage;
217
+		// are we using encryption?
218
+		$this->_use_encryption = $encryption instanceof EE_Encryption
219
+								 && EE_Registry::instance()->CFG->admin->encode_session_data();
220
+		// \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__);
221
+		// encrypt data via: $this->encryption->encrypt();
222
+		$this->encryption = $encryption;
223
+		// filter hook allows outside functions/classes/plugins to change default empty cart
224
+		$extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
225
+		array_merge($this->_default_session_vars, $extra_default_session_vars);
226
+		// apply default session vars
227
+		$this->_set_defaults();
228
+		add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
229
+		// check request for 'clear_session' param
230
+		add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
231
+		// once everything is all said and done,
232
+		add_action('shutdown', array($this, 'update'), 100);
233
+		add_action('shutdown', array($this, 'garbageCollection'), 1000);
234
+		$this->configure_garbage_collection_filters();
235
+	}
236
+
237
+
238
+
239
+	/**
240
+	 * @return void
241
+	 * @throws EE_Error
242
+	 * @throws InvalidArgumentException
243
+	 * @throws InvalidDataTypeException
244
+	 * @throws InvalidInterfaceException
245
+	 * @throws InvalidSessionDataException
246
+	 */
247
+	public function open_session()
248
+	{
249
+		// check for existing session and retrieve it from db
250
+		if (! $this->_espresso_session()) {
251
+			// or just start a new one
252
+			$this->_create_espresso_session();
253
+		}
254
+	}
255
+
256
+
257
+
258
+	/**
259
+	 * @return bool
260
+	 */
261
+	public function expired()
262
+	{
263
+		return $this->_expired;
264
+	}
265
+
266
+
267
+
268
+	/**
269
+	 * @return void
270
+	 */
271
+	public function reset_expired()
272
+	{
273
+		$this->_expired = false;
274
+	}
275
+
276
+
277
+	/**
278
+	 * @return int
279
+	 */
280
+	public function expiration()
281
+	{
282
+		return $this->_expiration;
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * @return int
289
+	 */
290
+	public function extension()
291
+	{
292
+		return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS);
293
+	}
294
+
295
+
296
+
297
+	/**
298
+	 * @param int $time number of seconds to add to session expiration
299
+	 */
300
+	public function extend_expiration($time = 0)
301
+	{
302
+		$time              = $time ? $time : $this->extension();
303
+		$this->_expiration += absint($time);
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 * @return int
310
+	 */
311
+	public function lifespan()
312
+	{
313
+		return $this->_lifespan;
314
+	}
315
+
316
+
317
+
318
+	/**
319
+	 * This just sets some defaults for the _session data property
320
+	 *
321
+	 * @access private
322
+	 * @return void
323
+	 */
324
+	private function _set_defaults()
325
+	{
326
+		// set some defaults
327
+		foreach ($this->_default_session_vars as $key => $default_var) {
328
+			if (is_array($default_var)) {
329
+				$this->_session_data[ $key ] = array();
330
+			} else {
331
+				$this->_session_data[ $key ] = '';
332
+			}
333
+		}
334
+	}
335 335
 
336 336
 
337
-
338
-    /**
339
-     * @retrieve  session data
340
-     * @access    public
341
-     * @return    string
342
-     */
343
-    public function id()
344
-    {
345
-        return $this->_sid;
346
-    }
337
+
338
+	/**
339
+	 * @retrieve  session data
340
+	 * @access    public
341
+	 * @return    string
342
+	 */
343
+	public function id()
344
+	{
345
+		return $this->_sid;
346
+	}
347 347
 
348 348
 
349 349
 
350
-    /**
351
-     * @param \EE_Cart $cart
352
-     * @return bool
353
-     */
354
-    public function set_cart(EE_Cart $cart)
355
-    {
356
-        $this->_session_data['cart'] = $cart;
357
-        return true;
358
-    }
350
+	/**
351
+	 * @param \EE_Cart $cart
352
+	 * @return bool
353
+	 */
354
+	public function set_cart(EE_Cart $cart)
355
+	{
356
+		$this->_session_data['cart'] = $cart;
357
+		return true;
358
+	}
359 359
 
360 360
 
361 361
 
362
-    /**
363
-     * reset_cart
364
-     */
365
-    public function reset_cart()
366
-    {
367
-        do_action('AHEE__EE_Session__reset_cart__before_reset', $this);
368
-        $this->_session_data['cart'] = null;
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * @return \EE_Cart
375
-     */
376
-    public function cart()
377
-    {
378
-        return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart
379
-            ? $this->_session_data['cart']
380
-            : null;
381
-    }
382
-
383
-
384
-
385
-    /**
386
-     * @param \EE_Checkout $checkout
387
-     * @return bool
388
-     */
389
-    public function set_checkout(EE_Checkout $checkout)
390
-    {
391
-        $this->_session_data['checkout'] = $checkout;
392
-        return true;
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     * reset_checkout
399
-     */
400
-    public function reset_checkout()
401
-    {
402
-        do_action('AHEE__EE_Session__reset_checkout__before_reset', $this);
403
-        $this->_session_data['checkout'] = null;
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * @return \EE_Checkout
410
-     */
411
-    public function checkout()
412
-    {
413
-        return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout
414
-            ? $this->_session_data['checkout']
415
-            : null;
416
-    }
417
-
418
-
419
-
420
-    /**
421
-     * @param \EE_Transaction $transaction
422
-     * @return bool
423
-     * @throws EE_Error
424
-     */
425
-    public function set_transaction(EE_Transaction $transaction)
426
-    {
427
-        // first remove the session from the transaction before we save the transaction in the session
428
-        $transaction->set_txn_session_data(null);
429
-        $this->_session_data['transaction'] = $transaction;
430
-        return true;
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * reset_transaction
437
-     */
438
-    public function reset_transaction()
439
-    {
440
-        do_action('AHEE__EE_Session__reset_transaction__before_reset', $this);
441
-        $this->_session_data['transaction'] = null;
442
-    }
443
-
444
-
445
-
446
-    /**
447
-     * @return \EE_Transaction
448
-     */
449
-    public function transaction()
450
-    {
451
-        return isset($this->_session_data['transaction'])
452
-               && $this->_session_data['transaction'] instanceof EE_Transaction
453
-            ? $this->_session_data['transaction']
454
-            : null;
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * retrieve session data
461
-     *
462
-     * @access    public
463
-     * @param null $key
464
-     * @param bool $reset_cache
465
-     * @return    array
466
-     */
467
-    public function get_session_data($key = null, $reset_cache = false)
468
-    {
469
-        if ($reset_cache) {
470
-            $this->reset_cart();
471
-            $this->reset_checkout();
472
-            $this->reset_transaction();
473
-        }
474
-        if (! empty($key)) {
475
-            return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
476
-        }
477
-        return $this->_session_data;
478
-    }
479
-
480
-
481
-
482
-    /**
483
-     * set session data
484
-     *
485
-     * @access    public
486
-     * @param    array $data
487
-     * @return    TRUE on success, FALSE on fail
488
-     */
489
-    public function set_session_data($data)
490
-    {
491
-
492
-        // nothing ??? bad data ??? go home!
493
-        if (empty($data) || ! is_array($data)) {
494
-            EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__,
495
-                __FUNCTION__, __LINE__);
496
-            return false;
497
-        }
498
-        foreach ($data as $key => $value) {
499
-            if (isset($this->_default_session_vars[ $key ])) {
500
-                EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
501
-                    'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__);
502
-                return false;
503
-            }
504
-            $this->_session_data[ $key ] = $value;
505
-        }
506
-        return true;
507
-    }
508
-
509
-
510
-
511
-    /**
512
-     * @initiate session
513
-     * @access   private
514
-     * @return TRUE on success, FALSE on fail
515
-     * @throws EE_Error
516
-     * @throws InvalidArgumentException
517
-     * @throws InvalidDataTypeException
518
-     * @throws InvalidInterfaceException
519
-     * @throws InvalidSessionDataException
520
-     */
521
-    private function _espresso_session()
522
-    {
523
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
524
-        // check that session has started
525
-        if (session_id() === '') {
526
-            //starts a new session if one doesn't already exist, or re-initiates an existing one
527
-            session_start();
528
-        }
529
-        // get our modified session ID
530
-        $this->_sid = $this->_generate_session_id();
531
-        // and the visitors IP
532
-        $this->_ip_address = $this->_visitor_ip();
533
-        // set the "user agent"
534
-        $this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : false;
535
-        // now let's retrieve what's in the db
536
-        $session_data = $this->_retrieve_session_data();
537
-        if (! empty($session_data)) {
538
-            // get the current time in UTC
539
-            $this->_time = $this->_time !== null ? $this->_time : time();
540
-            // and reset the session expiration
541
-            $this->_expiration = isset($session_data['expiration'])
542
-                ? $session_data['expiration']
543
-                : $this->_time + $this->_lifespan;
544
-        } else {
545
-            // set initial site access time and the session expiration
546
-            $this->_set_init_access_and_expiration();
547
-            // set referer
548
-            $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
549
-                ? esc_attr($_SERVER['HTTP_REFERER'])
550
-                : '';
551
-            // no previous session = go back and create one (on top of the data above)
552
-            return false;
553
-        }
554
-        // now the user agent
555
-        if ($session_data['user_agent'] !== $this->_user_agent) {
556
-            return false;
557
-        }
558
-        // wait a minute... how old are you?
559
-        if ($this->_time > $this->_expiration) {
560
-            // yer too old fer me!
561
-            $this->_expired = true;
562
-            // wipe out everything that isn't a default session datum
563
-            $this->clear_session(__CLASS__, __FUNCTION__);
564
-        }
565
-        // make event espresso session data available to plugin
566
-        $this->_session_data = array_merge($this->_session_data, $session_data);
567
-        return true;
568
-    }
569
-
570
-
571
-
572
-    /**
573
-     * _get_session_data
574
-     * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup
575
-     * databases
576
-     *
577
-     * @return array
578
-     * @throws EE_Error
579
-     * @throws InvalidArgumentException
580
-     * @throws InvalidSessionDataException
581
-     * @throws InvalidDataTypeException
582
-     * @throws InvalidInterfaceException
583
-     */
584
-    protected function _retrieve_session_data()
585
-    {
586
-        $ssn_key = EE_Session::session_id_prefix . $this->_sid;
587
-        try {
588
-            // we're using WP's Transient API to store session data using the PHP session ID as the option name
589
-            $session_data = $this->cache_storage->get($ssn_key, false);
590
-            if (empty($session_data)) {
591
-                return array();
592
-            }
593
-            if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
594
-                $hash_check = $this->cache_storage->get(
595
-                    EE_Session::hash_check_prefix . $this->_sid,
596
-                    false
597
-                );
598
-                if ($hash_check && $hash_check !== md5($session_data)) {
599
-                    EE_Error::add_error(
600
-                        sprintf(
601
-                            __(
602
-                                'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
603
-                                'event_espresso'
604
-                            ),
605
-                            EE_Session::session_id_prefix . $this->_sid
606
-                        ),
607
-                        __FILE__, __FUNCTION__, __LINE__
608
-                    );
609
-                }
610
-            }
611
-        } catch (Exception $e) {
612
-            // let's just eat that error for now and attempt to correct any corrupted data
613
-            global $wpdb;
614
-            $row          = $wpdb->get_row(
615
-                $wpdb->prepare(
616
-                    "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
617
-                    '_transient_' . $ssn_key
618
-                )
619
-            );
620
-            $session_data = is_object($row) ? $row->option_value : null;
621
-            if ($session_data) {
622
-                $session_data = preg_replace_callback(
623
-                    '!s:(d+):"(.*?)";!',
624
-                    function ($match)
625
-                    {
626
-                        return $match[1] === strlen($match[2])
627
-                            ? $match[0]
628
-                            : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
629
-                    },
630
-                    $session_data
631
-                );
632
-            }
633
-            $session_data = maybe_unserialize($session_data);
634
-        }
635
-        // in case the data is encoded... try to decode it
636
-        $session_data = $this->encryption instanceof EE_Encryption
637
-            ? $this->encryption->base64_string_decode($session_data)
638
-            : $session_data;
639
-        if (! is_array($session_data)) {
640
-            try {
641
-                $session_data = maybe_unserialize($session_data);
642
-            } catch (Exception $e) {
643
-                $msg = esc_html__(
644
-                    'An error occurred while attempting to unserialize the session data.',
645
-                    'event_espresso'
646
-                );
647
-                $msg .= WP_DEBUG
648
-                    ? '<br><pre>'
649
-                      . print_r($session_data, true)
650
-                      . '</pre><br>'
651
-                      . $this->find_serialize_error($session_data)
652
-                    : '';
653
-                $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
654
-                throw new InvalidSessionDataException($msg, 0, $e);
655
-            }
656
-        }
657
-        // just a check to make sure the session array is indeed an array
658
-        if (! is_array($session_data)) {
659
-            // no?!?! then something is wrong
660
-            $msg = esc_html__(
661
-                'The session data is missing, invalid, or corrupted.',
662
-                'event_espresso'
663
-            );
664
-            $msg .= WP_DEBUG
665
-                ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
666
-                : '';
667
-            $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
668
-            throw new InvalidSessionDataException($msg);
669
-        }
670
-        if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
671
-            $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
672
-                $session_data['transaction']
673
-            );
674
-        }
675
-        return $session_data;
676
-    }
677
-
678
-
679
-
680
-    /**
681
-     * _generate_session_id
682
-     * Retrieves the PHP session id either directly from the PHP session,
683
-     * or from the $_REQUEST array if it was passed in from an AJAX request.
684
-     * The session id is then salted and hashed (mmm sounds tasty)
685
-     * so that it can be safely used as a $_REQUEST param
686
-     *
687
-     * @return string
688
-     */
689
-    protected function _generate_session_id()
690
-    {
691
-        // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
692
-        if (isset($_REQUEST['EESID'])) {
693
-            $session_id = sanitize_text_field($_REQUEST['EESID']);
694
-        } else {
695
-            $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
696
-        }
697
-        return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
698
-    }
699
-
700
-
701
-
702
-    /**
703
-     * _get_sid_salt
704
-     *
705
-     * @return string
706
-     */
707
-    protected function _get_sid_salt()
708
-    {
709
-        // was session id salt already saved to db ?
710
-        if (empty($this->_sid_salt)) {
711
-            // no?  then maybe use WP defined constant
712
-            if (defined('AUTH_SALT')) {
713
-                $this->_sid_salt = AUTH_SALT;
714
-            }
715
-            // if salt doesn't exist or is too short
716
-            if (strlen($this->_sid_salt) < 32) {
717
-                // create a new one
718
-                $this->_sid_salt = wp_generate_password(64);
719
-            }
720
-            // and save it as a permanent session setting
721
-            $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt));
722
-        }
723
-        return $this->_sid_salt;
724
-    }
725
-
726
-
727
-
728
-    /**
729
-     * _set_init_access_and_expiration
730
-     *
731
-     * @return void
732
-     */
733
-    protected function _set_init_access_and_expiration()
734
-    {
735
-        $this->_time       = time();
736
-        $this->_expiration = $this->_time + $this->_lifespan;
737
-        // set initial site access time
738
-        $this->_session_data['init_access'] = $this->_time;
739
-        // and the session expiration
740
-        $this->_session_data['expiration'] = $this->_expiration;
741
-    }
742
-
743
-
744
-
745
-    /**
746
-     * @update session data  prior to saving to the db
747
-     * @access public
748
-     * @param bool $new_session
749
-     * @return TRUE on success, FALSE on fail
750
-     * @throws EE_Error
751
-     * @throws InvalidArgumentException
752
-     * @throws InvalidDataTypeException
753
-     * @throws InvalidInterfaceException
754
-     */
755
-    public function update($new_session = false)
756
-    {
757
-        $this->_session_data = $this->_session_data !== null
758
-                               && is_array($this->_session_data)
759
-                               && isset($this->_session_data['id'])
760
-            ? $this->_session_data
761
-            : array();
762
-        if (empty($this->_session_data)) {
763
-            $this->_set_defaults();
764
-        }
765
-        $session_data = array();
766
-        foreach ($this->_session_data as $key => $value) {
767
-
768
-            switch ($key) {
769
-
770
-                case 'id' :
771
-                    // session ID
772
-                    $session_data['id'] = $this->_sid;
773
-                    break;
774
-                case 'ip_address' :
775
-                    // visitor ip address
776
-                    $session_data['ip_address'] = $this->_visitor_ip();
777
-                    break;
778
-                case 'user_agent' :
779
-                    // visitor user_agent
780
-                    $session_data['user_agent'] = $this->_user_agent;
781
-                    break;
782
-                case 'init_access' :
783
-                    $session_data['init_access'] = absint($value);
784
-                    break;
785
-                case 'last_access' :
786
-                    // current access time
787
-                    $session_data['last_access'] = $this->_time;
788
-                    break;
789
-                case 'expiration' :
790
-                    // when the session expires
791
-                    $session_data['expiration'] = ! empty($this->_expiration)
792
-                        ? $this->_expiration
793
-                        : $session_data['init_access'] + $this->_lifespan;
794
-                    break;
795
-                case 'user_id' :
796
-                    // current user if logged in
797
-                    $session_data['user_id'] = $this->_wp_user_id();
798
-                    break;
799
-                case 'pages_visited' :
800
-                    $page_visit = $this->_get_page_visit();
801
-                    if ($page_visit) {
802
-                        // set pages visited where the first will be the http referrer
803
-                        $this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
804
-                        // we'll only save the last 10 page visits.
805
-                        $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
806
-                    }
807
-                    break;
808
-                default :
809
-                    // carry any other data over
810
-                    $session_data[ $key ] = $this->_session_data[ $key ];
811
-            }
812
-        }
813
-        $this->_session_data = $session_data;
814
-        // creating a new session does not require saving to the db just yet
815
-        if (! $new_session) {
816
-            // ready? let's save
817
-            if ($this->_save_session_to_db()) {
818
-                return true;
819
-            }
820
-            return false;
821
-        }
822
-        // meh, why not?
823
-        return true;
824
-    }
825
-
826
-
827
-
828
-    /**
829
-     * @create session data array
830
-     * @access public
831
-     * @return bool
832
-     * @throws EE_Error
833
-     * @throws InvalidArgumentException
834
-     * @throws InvalidDataTypeException
835
-     * @throws InvalidInterfaceException
836
-     */
837
-    private function _create_espresso_session()
838
-    {
839
-        do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
840
-        // use the update function for now with $new_session arg set to TRUE
841
-        return $this->update(true) ? true : false;
842
-    }
843
-
844
-
845
-
846
-    /**
847
-     * _save_session_to_db
848
-     *
849
-     * @access public
850
-     * @return string
851
-     * @throws EE_Error
852
-     * @throws InvalidArgumentException
853
-     * @throws InvalidDataTypeException
854
-     * @throws InvalidInterfaceException
855
-     */
856
-    private function _save_session_to_db()
857
-    {
858
-        if (
859
-            // if the current request is NOT one of the following
860
-        ! (
861
-            // an an AJAX request from the frontend
862
-            EE_Registry::instance()->REQ->front_ajax
863
-            || (
864
-                // OR an admin request that is NOT AJAX
865
-                ! (defined('DOING_AJAX') && DOING_AJAX)
866
-                && is_admin()
867
-            )
868
-            || (
869
-                // OR an espresso page
870
-                EE_Registry::instance()->REQ instanceof EE_Request_Handler
871
-                && EE_Registry::instance()->REQ->is_espresso_page()
872
-            )
873
-        )
874
-        ) {
875
-            return false;
876
-        }
877
-        $transaction = $this->transaction();
878
-        if ($transaction instanceof EE_Transaction) {
879
-            if (! $transaction->ID()) {
880
-                $transaction->save();
881
-            }
882
-            $this->_session_data['transaction'] = $transaction->ID();
883
-        }
884
-        // then serialize all of our session data
885
-        $session_data = serialize($this->_session_data);
886
-        // do we need to also encode it to avoid corrupted data when saved to the db?
887
-        $session_data = $this->_use_encryption
888
-            ? $this->encryption->base64_string_encode($session_data)
889
-            : $session_data;
890
-        // maybe save hash check
891
-        if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
892
-            $this->cache_storage->add(
893
-                EE_Session::hash_check_prefix . $this->_sid,
894
-                md5($session_data),
895
-                $this->_lifespan
896
-            );
897
-        }
898
-        // we're using the Transient API for storing session data,
899
-        return $this->cache_storage->add(
900
-            EE_Session::session_id_prefix . $this->_sid,
901
-            $session_data,
902
-            $this->_lifespan
903
-        );
904
-    }
905
-
906
-
907
-
908
-    /**
909
-     * _visitor_ip
910
-     *    attempt to get IP address of current visitor from server
911
-     * plz see: http://stackoverflow.com/a/2031935/1475279
912
-     *
913
-     * @access public
914
-     * @return string
915
-     */
916
-    private function _visitor_ip()
917
-    {
918
-        $visitor_ip  = '0.0.0.0';
919
-        $server_keys = array(
920
-            'HTTP_CLIENT_IP',
921
-            'HTTP_X_FORWARDED_FOR',
922
-            'HTTP_X_FORWARDED',
923
-            'HTTP_X_CLUSTER_CLIENT_IP',
924
-            'HTTP_FORWARDED_FOR',
925
-            'HTTP_FORWARDED',
926
-            'REMOTE_ADDR',
927
-        );
928
-        foreach ($server_keys as $key) {
929
-            if (isset($_SERVER[ $key ])) {
930
-                foreach (array_map('trim', explode(',', $_SERVER[ $key ])) as $ip) {
931
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
932
-                        $visitor_ip = $ip;
933
-                    }
934
-                }
935
-            }
936
-        }
937
-        return $visitor_ip;
938
-    }
939
-
940
-
941
-
942
-    /**
943
-     * @get    the full page request the visitor is accessing
944
-     * @access public
945
-     * @return string
946
-     */
947
-    public function _get_page_visit()
948
-    {
949
-        $page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
950
-        // check for request url
951
-        if (isset($_SERVER['REQUEST_URI'])) {
952
-            $http_host   = '';
953
-            $page_id     = '?';
954
-            $e_reg       = '';
955
-            $request_uri = esc_url($_SERVER['REQUEST_URI']);
956
-            $ru_bits     = explode('?', $request_uri);
957
-            $request_uri = $ru_bits[0];
958
-            // check for and grab host as well
959
-            if (isset($_SERVER['HTTP_HOST'])) {
960
-                $http_host = esc_url($_SERVER['HTTP_HOST']);
961
-            }
962
-            // check for page_id in SERVER REQUEST
963
-            if (isset($_REQUEST['page_id'])) {
964
-                // rebuild $e_reg without any of the extra parameters
965
-                $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
966
-            }
967
-            // check for $e_reg in SERVER REQUEST
968
-            if (isset($_REQUEST['ee'])) {
969
-                // rebuild $e_reg without any of the extra parameters
970
-                $e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
971
-            }
972
-            $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
973
-        }
974
-        return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
975
-    }
976
-
977
-
978
-
979
-    /**
980
-     * @the    current wp user id
981
-     * @access public
982
-     * @return int
983
-     */
984
-    public function _wp_user_id()
985
-    {
986
-        // if I need to explain the following lines of code, then you shouldn't be looking at this!
987
-        $this->_wp_user_id = get_current_user_id();
988
-        return $this->_wp_user_id;
989
-    }
990
-
991
-
992
-
993
-    /**
994
-     * Clear EE_Session data
995
-     *
996
-     * @access public
997
-     * @param string $class
998
-     * @param string $function
999
-     * @return void
1000
-     * @throws EE_Error
1001
-     * @throws InvalidArgumentException
1002
-     * @throws InvalidDataTypeException
1003
-     * @throws InvalidInterfaceException
1004
-     */
1005
-    public function clear_session($class = '', $function = '')
1006
-    {
1007
-        //echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
1008
-        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1009
-        $this->reset_cart();
1010
-        $this->reset_checkout();
1011
-        $this->reset_transaction();
1012
-        // wipe out everything that isn't a default session datum
1013
-        $this->reset_data(array_keys($this->_session_data));
1014
-        // reset initial site access time and the session expiration
1015
-        $this->_set_init_access_and_expiration();
1016
-        $this->_save_session_to_db();
1017
-    }
1018
-
1019
-
1020
-
1021
-    /**
1022
-     * @resets all non-default session vars
1023
-     * @access public
1024
-     * @param array|mixed $data_to_reset
1025
-     * @param bool        $show_all_notices
1026
-     * @return TRUE on success, FALSE on fail
1027
-     */
1028
-    public function reset_data($data_to_reset = array(), $show_all_notices = false)
1029
-    {
1030
-        // if $data_to_reset is not in an array, then put it in one
1031
-        if (! is_array($data_to_reset)) {
1032
-            $data_to_reset = array($data_to_reset);
1033
-        }
1034
-        // nothing ??? go home!
1035
-        if (empty($data_to_reset)) {
1036
-            EE_Error::add_error(__('No session data could be reset, because no session var name was provided.',
1037
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1038
-            return false;
1039
-        }
1040
-        $return_value = true;
1041
-        // since $data_to_reset is an array, cycle through the values
1042
-        foreach ($data_to_reset as $reset) {
1043
-
1044
-            // first check to make sure it is a valid session var
1045
-            if (isset($this->_session_data[ $reset ])) {
1046
-                // then check to make sure it is not a default var
1047
-                if (! array_key_exists($reset, $this->_default_session_vars)) {
1048
-                    // remove session var
1049
-                    unset($this->_session_data[ $reset ]);
1050
-                    if ($show_all_notices) {
1051
-                        EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'),
1052
-                            $reset), __FILE__, __FUNCTION__, __LINE__);
1053
-                    }
1054
-                } else {
1055
-                    // yeeeeeeeeerrrrrrrrrrr OUT !!!!
1056
-                    if ($show_all_notices) {
1057
-                        EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
1058
-                            'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1059
-                    }
1060
-                    $return_value = false;
1061
-                }
1062
-            } elseif ($show_all_notices) {
1063
-                // oops! that session var does not exist!
1064
-                EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.',
1065
-                    'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1066
-                $return_value = false;
1067
-            }
1068
-        } // end of foreach
1069
-        return $return_value;
1070
-    }
1071
-
1072
-
1073
-
1074
-    /**
1075
-     *   wp_loaded
1076
-     *
1077
-     * @access public
1078
-     * @throws EE_Error
1079
-     * @throws InvalidDataTypeException
1080
-     * @throws InvalidInterfaceException
1081
-     * @throws InvalidArgumentException
1082
-     */
1083
-    public function wp_loaded()
1084
-    {
1085
-        if (
1086
-            EE_Registry::instance()->REQ instanceof EE_Request_Handler
1087
-            && EE_Registry::instance()->REQ->is_set('clear_session')
1088
-        ) {
1089
-            $this->clear_session(__CLASS__, __FUNCTION__);
1090
-        }
1091
-    }
1092
-
1093
-
1094
-
1095
-    /**
1096
-     * Used to reset the entire object (for tests).
1097
-     *
1098
-     * @since 4.3.0
1099
-     * @throws EE_Error
1100
-     * @throws InvalidDataTypeException
1101
-     * @throws InvalidInterfaceException
1102
-     * @throws InvalidArgumentException
1103
-     */
1104
-    public function reset_instance()
1105
-    {
1106
-        $this->clear_session();
1107
-        self::$_instance = null;
1108
-    }
1109
-
1110
-
1111
-
1112
-    public function configure_garbage_collection_filters()
1113
-    {
1114
-        // run old filter we had for controlling session cleanup
1115
-        $expired_session_transient_delete_query_limit = absint(
1116
-            apply_filters(
1117
-                'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1118
-                50
1119
-            )
1120
-        );
1121
-        // is there a value? or one that is different than the default 50 records?
1122
-        if ($expired_session_transient_delete_query_limit === 0) {
1123
-            // hook into TransientCacheStorage in case Session cleanup was turned off
1124
-            add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero');
1125
-        } elseif ($expired_session_transient_delete_query_limit !== 50) {
1126
-            // or use that for the new transient cleanup query limit
1127
-            add_filter(
1128
-                'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1129
-                function () use ($expired_session_transient_delete_query_limit)
1130
-                {
1131
-                    return $expired_session_transient_delete_query_limit;
1132
-                }
1133
-            );
1134
-        }
1135
-    }
1136
-
1137
-
1138
-
1139
-    /**
1140
-     * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996
1141
-     * @param $data1
1142
-     * @return string
1143
-     */
1144
-    private function find_serialize_error($data1)
1145
-    {
1146
-        $error = '<pre>';
1147
-        $data2 = preg_replace_callback(
1148
-            '!s:(\d+):"(.*?)";!',
1149
-            function ($match)
1150
-            {
1151
-                return ($match[1] === strlen($match[2]))
1152
-                    ? $match[0]
1153
-                    : 's:'
1154
-                      . strlen($match[2])
1155
-                      . ':"'
1156
-                      . $match[2]
1157
-                      . '";';
1158
-            },
1159
-            $data1
1160
-        );
1161
-        $max   = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1162
-        $error .= $data1 . PHP_EOL;
1163
-        $error .= $data2 . PHP_EOL;
1164
-        for ($i = 0; $i < $max; $i++) {
1165
-            if (@$data1[ $i ] !== @$data2[ $i ]) {
1166
-                $error  .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1167
-                $error  .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1168
-                $error  .= "\t-> Line Number = $i" . PHP_EOL;
1169
-                $start  = ($i - 20);
1170
-                $start  = ($start < 0) ? 0 : $start;
1171
-                $length = 40;
1172
-                $point  = $max - $i;
1173
-                if ($point < 20) {
1174
-                    $rlength = 1;
1175
-                    $rpoint  = -$point;
1176
-                } else {
1177
-                    $rpoint  = $length - 20;
1178
-                    $rlength = 1;
1179
-                }
1180
-                $error .= "\t-> Section Data1  = ";
1181
-                $error .= substr_replace(
1182
-                    substr($data1, $start, $length),
1183
-                    "<b style=\"color:green\">{$data1[ $i ]}</b>",
1184
-                    $rpoint,
1185
-                    $rlength
1186
-                );
1187
-                $error .= PHP_EOL;
1188
-                $error .= "\t-> Section Data2  = ";
1189
-                $error .= substr_replace(
1190
-                    substr($data2, $start, $length),
1191
-                    "<b style=\"color:red\">{$data2[ $i ]}</b>",
1192
-                    $rpoint,
1193
-                    $rlength
1194
-                );
1195
-                $error .= PHP_EOL;
1196
-            }
1197
-        }
1198
-        $error .= '</pre>';
1199
-        return $error;
1200
-    }
1201
-
1202
-
1203
-    /**
1204
-     * Saves an  array of settings used for configuring aspects of session behaviour
1205
-     *
1206
-     * @param array $updated_settings
1207
-     */
1208
-    private function updateSessionSettings(array $updated_settings = array())
1209
-    {
1210
-        // add existing settings, but only if not included in incoming $updated_settings array
1211
-        $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array());
1212
-        update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings);
1213
-    }
1214
-
1215
-
1216
-    /**
1217
-     * garbage_collection
1218
-     */
1219
-    public function garbageCollection()
1220
-    {
1221
-        // only perform during regular requests if last garbage collection was over an hour ago
1222
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1223
-            $this->_last_gc = time();
1224
-            $this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1225
-            /** @type WPDB $wpdb */
1226
-            global $wpdb;
1227
-            // filter the query limit. Set to 0 to turn off garbage collection
1228
-            $expired_session_transient_delete_query_limit = absint(
1229
-                apply_filters(
1230
-                    'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1231
-                    50
1232
-                )
1233
-            );
1234
-            // non-zero LIMIT means take out the trash
1235
-            if ($expired_session_transient_delete_query_limit) {
1236
-                $session_key    = str_replace('_', '\_', EE_Session::session_id_prefix);
1237
-                $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix);
1238
-                // since transient expiration timestamps are set in the future, we can compare against NOW
1239
-                // but we only want to pick up any trash that's been around for more than a day
1240
-                $expiration = time() - DAY_IN_SECONDS;
1241
-                $SQL        = "
362
+	/**
363
+	 * reset_cart
364
+	 */
365
+	public function reset_cart()
366
+	{
367
+		do_action('AHEE__EE_Session__reset_cart__before_reset', $this);
368
+		$this->_session_data['cart'] = null;
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * @return \EE_Cart
375
+	 */
376
+	public function cart()
377
+	{
378
+		return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart
379
+			? $this->_session_data['cart']
380
+			: null;
381
+	}
382
+
383
+
384
+
385
+	/**
386
+	 * @param \EE_Checkout $checkout
387
+	 * @return bool
388
+	 */
389
+	public function set_checkout(EE_Checkout $checkout)
390
+	{
391
+		$this->_session_data['checkout'] = $checkout;
392
+		return true;
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 * reset_checkout
399
+	 */
400
+	public function reset_checkout()
401
+	{
402
+		do_action('AHEE__EE_Session__reset_checkout__before_reset', $this);
403
+		$this->_session_data['checkout'] = null;
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * @return \EE_Checkout
410
+	 */
411
+	public function checkout()
412
+	{
413
+		return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout
414
+			? $this->_session_data['checkout']
415
+			: null;
416
+	}
417
+
418
+
419
+
420
+	/**
421
+	 * @param \EE_Transaction $transaction
422
+	 * @return bool
423
+	 * @throws EE_Error
424
+	 */
425
+	public function set_transaction(EE_Transaction $transaction)
426
+	{
427
+		// first remove the session from the transaction before we save the transaction in the session
428
+		$transaction->set_txn_session_data(null);
429
+		$this->_session_data['transaction'] = $transaction;
430
+		return true;
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * reset_transaction
437
+	 */
438
+	public function reset_transaction()
439
+	{
440
+		do_action('AHEE__EE_Session__reset_transaction__before_reset', $this);
441
+		$this->_session_data['transaction'] = null;
442
+	}
443
+
444
+
445
+
446
+	/**
447
+	 * @return \EE_Transaction
448
+	 */
449
+	public function transaction()
450
+	{
451
+		return isset($this->_session_data['transaction'])
452
+			   && $this->_session_data['transaction'] instanceof EE_Transaction
453
+			? $this->_session_data['transaction']
454
+			: null;
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * retrieve session data
461
+	 *
462
+	 * @access    public
463
+	 * @param null $key
464
+	 * @param bool $reset_cache
465
+	 * @return    array
466
+	 */
467
+	public function get_session_data($key = null, $reset_cache = false)
468
+	{
469
+		if ($reset_cache) {
470
+			$this->reset_cart();
471
+			$this->reset_checkout();
472
+			$this->reset_transaction();
473
+		}
474
+		if (! empty($key)) {
475
+			return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
476
+		}
477
+		return $this->_session_data;
478
+	}
479
+
480
+
481
+
482
+	/**
483
+	 * set session data
484
+	 *
485
+	 * @access    public
486
+	 * @param    array $data
487
+	 * @return    TRUE on success, FALSE on fail
488
+	 */
489
+	public function set_session_data($data)
490
+	{
491
+
492
+		// nothing ??? bad data ??? go home!
493
+		if (empty($data) || ! is_array($data)) {
494
+			EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__,
495
+				__FUNCTION__, __LINE__);
496
+			return false;
497
+		}
498
+		foreach ($data as $key => $value) {
499
+			if (isset($this->_default_session_vars[ $key ])) {
500
+				EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
501
+					'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__);
502
+				return false;
503
+			}
504
+			$this->_session_data[ $key ] = $value;
505
+		}
506
+		return true;
507
+	}
508
+
509
+
510
+
511
+	/**
512
+	 * @initiate session
513
+	 * @access   private
514
+	 * @return TRUE on success, FALSE on fail
515
+	 * @throws EE_Error
516
+	 * @throws InvalidArgumentException
517
+	 * @throws InvalidDataTypeException
518
+	 * @throws InvalidInterfaceException
519
+	 * @throws InvalidSessionDataException
520
+	 */
521
+	private function _espresso_session()
522
+	{
523
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
524
+		// check that session has started
525
+		if (session_id() === '') {
526
+			//starts a new session if one doesn't already exist, or re-initiates an existing one
527
+			session_start();
528
+		}
529
+		// get our modified session ID
530
+		$this->_sid = $this->_generate_session_id();
531
+		// and the visitors IP
532
+		$this->_ip_address = $this->_visitor_ip();
533
+		// set the "user agent"
534
+		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : false;
535
+		// now let's retrieve what's in the db
536
+		$session_data = $this->_retrieve_session_data();
537
+		if (! empty($session_data)) {
538
+			// get the current time in UTC
539
+			$this->_time = $this->_time !== null ? $this->_time : time();
540
+			// and reset the session expiration
541
+			$this->_expiration = isset($session_data['expiration'])
542
+				? $session_data['expiration']
543
+				: $this->_time + $this->_lifespan;
544
+		} else {
545
+			// set initial site access time and the session expiration
546
+			$this->_set_init_access_and_expiration();
547
+			// set referer
548
+			$this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
549
+				? esc_attr($_SERVER['HTTP_REFERER'])
550
+				: '';
551
+			// no previous session = go back and create one (on top of the data above)
552
+			return false;
553
+		}
554
+		// now the user agent
555
+		if ($session_data['user_agent'] !== $this->_user_agent) {
556
+			return false;
557
+		}
558
+		// wait a minute... how old are you?
559
+		if ($this->_time > $this->_expiration) {
560
+			// yer too old fer me!
561
+			$this->_expired = true;
562
+			// wipe out everything that isn't a default session datum
563
+			$this->clear_session(__CLASS__, __FUNCTION__);
564
+		}
565
+		// make event espresso session data available to plugin
566
+		$this->_session_data = array_merge($this->_session_data, $session_data);
567
+		return true;
568
+	}
569
+
570
+
571
+
572
+	/**
573
+	 * _get_session_data
574
+	 * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup
575
+	 * databases
576
+	 *
577
+	 * @return array
578
+	 * @throws EE_Error
579
+	 * @throws InvalidArgumentException
580
+	 * @throws InvalidSessionDataException
581
+	 * @throws InvalidDataTypeException
582
+	 * @throws InvalidInterfaceException
583
+	 */
584
+	protected function _retrieve_session_data()
585
+	{
586
+		$ssn_key = EE_Session::session_id_prefix . $this->_sid;
587
+		try {
588
+			// we're using WP's Transient API to store session data using the PHP session ID as the option name
589
+			$session_data = $this->cache_storage->get($ssn_key, false);
590
+			if (empty($session_data)) {
591
+				return array();
592
+			}
593
+			if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
594
+				$hash_check = $this->cache_storage->get(
595
+					EE_Session::hash_check_prefix . $this->_sid,
596
+					false
597
+				);
598
+				if ($hash_check && $hash_check !== md5($session_data)) {
599
+					EE_Error::add_error(
600
+						sprintf(
601
+							__(
602
+								'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
603
+								'event_espresso'
604
+							),
605
+							EE_Session::session_id_prefix . $this->_sid
606
+						),
607
+						__FILE__, __FUNCTION__, __LINE__
608
+					);
609
+				}
610
+			}
611
+		} catch (Exception $e) {
612
+			// let's just eat that error for now and attempt to correct any corrupted data
613
+			global $wpdb;
614
+			$row          = $wpdb->get_row(
615
+				$wpdb->prepare(
616
+					"SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
617
+					'_transient_' . $ssn_key
618
+				)
619
+			);
620
+			$session_data = is_object($row) ? $row->option_value : null;
621
+			if ($session_data) {
622
+				$session_data = preg_replace_callback(
623
+					'!s:(d+):"(.*?)";!',
624
+					function ($match)
625
+					{
626
+						return $match[1] === strlen($match[2])
627
+							? $match[0]
628
+							: 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
629
+					},
630
+					$session_data
631
+				);
632
+			}
633
+			$session_data = maybe_unserialize($session_data);
634
+		}
635
+		// in case the data is encoded... try to decode it
636
+		$session_data = $this->encryption instanceof EE_Encryption
637
+			? $this->encryption->base64_string_decode($session_data)
638
+			: $session_data;
639
+		if (! is_array($session_data)) {
640
+			try {
641
+				$session_data = maybe_unserialize($session_data);
642
+			} catch (Exception $e) {
643
+				$msg = esc_html__(
644
+					'An error occurred while attempting to unserialize the session data.',
645
+					'event_espresso'
646
+				);
647
+				$msg .= WP_DEBUG
648
+					? '<br><pre>'
649
+					  . print_r($session_data, true)
650
+					  . '</pre><br>'
651
+					  . $this->find_serialize_error($session_data)
652
+					: '';
653
+				$this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
654
+				throw new InvalidSessionDataException($msg, 0, $e);
655
+			}
656
+		}
657
+		// just a check to make sure the session array is indeed an array
658
+		if (! is_array($session_data)) {
659
+			// no?!?! then something is wrong
660
+			$msg = esc_html__(
661
+				'The session data is missing, invalid, or corrupted.',
662
+				'event_espresso'
663
+			);
664
+			$msg .= WP_DEBUG
665
+				? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
666
+				: '';
667
+			$this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
668
+			throw new InvalidSessionDataException($msg);
669
+		}
670
+		if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
671
+			$session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
672
+				$session_data['transaction']
673
+			);
674
+		}
675
+		return $session_data;
676
+	}
677
+
678
+
679
+
680
+	/**
681
+	 * _generate_session_id
682
+	 * Retrieves the PHP session id either directly from the PHP session,
683
+	 * or from the $_REQUEST array if it was passed in from an AJAX request.
684
+	 * The session id is then salted and hashed (mmm sounds tasty)
685
+	 * so that it can be safely used as a $_REQUEST param
686
+	 *
687
+	 * @return string
688
+	 */
689
+	protected function _generate_session_id()
690
+	{
691
+		// check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
692
+		if (isset($_REQUEST['EESID'])) {
693
+			$session_id = sanitize_text_field($_REQUEST['EESID']);
694
+		} else {
695
+			$session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
696
+		}
697
+		return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
698
+	}
699
+
700
+
701
+
702
+	/**
703
+	 * _get_sid_salt
704
+	 *
705
+	 * @return string
706
+	 */
707
+	protected function _get_sid_salt()
708
+	{
709
+		// was session id salt already saved to db ?
710
+		if (empty($this->_sid_salt)) {
711
+			// no?  then maybe use WP defined constant
712
+			if (defined('AUTH_SALT')) {
713
+				$this->_sid_salt = AUTH_SALT;
714
+			}
715
+			// if salt doesn't exist or is too short
716
+			if (strlen($this->_sid_salt) < 32) {
717
+				// create a new one
718
+				$this->_sid_salt = wp_generate_password(64);
719
+			}
720
+			// and save it as a permanent session setting
721
+			$this->updateSessionSettings(array('sid_salt' => $this->_sid_salt));
722
+		}
723
+		return $this->_sid_salt;
724
+	}
725
+
726
+
727
+
728
+	/**
729
+	 * _set_init_access_and_expiration
730
+	 *
731
+	 * @return void
732
+	 */
733
+	protected function _set_init_access_and_expiration()
734
+	{
735
+		$this->_time       = time();
736
+		$this->_expiration = $this->_time + $this->_lifespan;
737
+		// set initial site access time
738
+		$this->_session_data['init_access'] = $this->_time;
739
+		// and the session expiration
740
+		$this->_session_data['expiration'] = $this->_expiration;
741
+	}
742
+
743
+
744
+
745
+	/**
746
+	 * @update session data  prior to saving to the db
747
+	 * @access public
748
+	 * @param bool $new_session
749
+	 * @return TRUE on success, FALSE on fail
750
+	 * @throws EE_Error
751
+	 * @throws InvalidArgumentException
752
+	 * @throws InvalidDataTypeException
753
+	 * @throws InvalidInterfaceException
754
+	 */
755
+	public function update($new_session = false)
756
+	{
757
+		$this->_session_data = $this->_session_data !== null
758
+							   && is_array($this->_session_data)
759
+							   && isset($this->_session_data['id'])
760
+			? $this->_session_data
761
+			: array();
762
+		if (empty($this->_session_data)) {
763
+			$this->_set_defaults();
764
+		}
765
+		$session_data = array();
766
+		foreach ($this->_session_data as $key => $value) {
767
+
768
+			switch ($key) {
769
+
770
+				case 'id' :
771
+					// session ID
772
+					$session_data['id'] = $this->_sid;
773
+					break;
774
+				case 'ip_address' :
775
+					// visitor ip address
776
+					$session_data['ip_address'] = $this->_visitor_ip();
777
+					break;
778
+				case 'user_agent' :
779
+					// visitor user_agent
780
+					$session_data['user_agent'] = $this->_user_agent;
781
+					break;
782
+				case 'init_access' :
783
+					$session_data['init_access'] = absint($value);
784
+					break;
785
+				case 'last_access' :
786
+					// current access time
787
+					$session_data['last_access'] = $this->_time;
788
+					break;
789
+				case 'expiration' :
790
+					// when the session expires
791
+					$session_data['expiration'] = ! empty($this->_expiration)
792
+						? $this->_expiration
793
+						: $session_data['init_access'] + $this->_lifespan;
794
+					break;
795
+				case 'user_id' :
796
+					// current user if logged in
797
+					$session_data['user_id'] = $this->_wp_user_id();
798
+					break;
799
+				case 'pages_visited' :
800
+					$page_visit = $this->_get_page_visit();
801
+					if ($page_visit) {
802
+						// set pages visited where the first will be the http referrer
803
+						$this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
804
+						// we'll only save the last 10 page visits.
805
+						$session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
806
+					}
807
+					break;
808
+				default :
809
+					// carry any other data over
810
+					$session_data[ $key ] = $this->_session_data[ $key ];
811
+			}
812
+		}
813
+		$this->_session_data = $session_data;
814
+		// creating a new session does not require saving to the db just yet
815
+		if (! $new_session) {
816
+			// ready? let's save
817
+			if ($this->_save_session_to_db()) {
818
+				return true;
819
+			}
820
+			return false;
821
+		}
822
+		// meh, why not?
823
+		return true;
824
+	}
825
+
826
+
827
+
828
+	/**
829
+	 * @create session data array
830
+	 * @access public
831
+	 * @return bool
832
+	 * @throws EE_Error
833
+	 * @throws InvalidArgumentException
834
+	 * @throws InvalidDataTypeException
835
+	 * @throws InvalidInterfaceException
836
+	 */
837
+	private function _create_espresso_session()
838
+	{
839
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
840
+		// use the update function for now with $new_session arg set to TRUE
841
+		return $this->update(true) ? true : false;
842
+	}
843
+
844
+
845
+
846
+	/**
847
+	 * _save_session_to_db
848
+	 *
849
+	 * @access public
850
+	 * @return string
851
+	 * @throws EE_Error
852
+	 * @throws InvalidArgumentException
853
+	 * @throws InvalidDataTypeException
854
+	 * @throws InvalidInterfaceException
855
+	 */
856
+	private function _save_session_to_db()
857
+	{
858
+		if (
859
+			// if the current request is NOT one of the following
860
+		! (
861
+			// an an AJAX request from the frontend
862
+			EE_Registry::instance()->REQ->front_ajax
863
+			|| (
864
+				// OR an admin request that is NOT AJAX
865
+				! (defined('DOING_AJAX') && DOING_AJAX)
866
+				&& is_admin()
867
+			)
868
+			|| (
869
+				// OR an espresso page
870
+				EE_Registry::instance()->REQ instanceof EE_Request_Handler
871
+				&& EE_Registry::instance()->REQ->is_espresso_page()
872
+			)
873
+		)
874
+		) {
875
+			return false;
876
+		}
877
+		$transaction = $this->transaction();
878
+		if ($transaction instanceof EE_Transaction) {
879
+			if (! $transaction->ID()) {
880
+				$transaction->save();
881
+			}
882
+			$this->_session_data['transaction'] = $transaction->ID();
883
+		}
884
+		// then serialize all of our session data
885
+		$session_data = serialize($this->_session_data);
886
+		// do we need to also encode it to avoid corrupted data when saved to the db?
887
+		$session_data = $this->_use_encryption
888
+			? $this->encryption->base64_string_encode($session_data)
889
+			: $session_data;
890
+		// maybe save hash check
891
+		if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
892
+			$this->cache_storage->add(
893
+				EE_Session::hash_check_prefix . $this->_sid,
894
+				md5($session_data),
895
+				$this->_lifespan
896
+			);
897
+		}
898
+		// we're using the Transient API for storing session data,
899
+		return $this->cache_storage->add(
900
+			EE_Session::session_id_prefix . $this->_sid,
901
+			$session_data,
902
+			$this->_lifespan
903
+		);
904
+	}
905
+
906
+
907
+
908
+	/**
909
+	 * _visitor_ip
910
+	 *    attempt to get IP address of current visitor from server
911
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
912
+	 *
913
+	 * @access public
914
+	 * @return string
915
+	 */
916
+	private function _visitor_ip()
917
+	{
918
+		$visitor_ip  = '0.0.0.0';
919
+		$server_keys = array(
920
+			'HTTP_CLIENT_IP',
921
+			'HTTP_X_FORWARDED_FOR',
922
+			'HTTP_X_FORWARDED',
923
+			'HTTP_X_CLUSTER_CLIENT_IP',
924
+			'HTTP_FORWARDED_FOR',
925
+			'HTTP_FORWARDED',
926
+			'REMOTE_ADDR',
927
+		);
928
+		foreach ($server_keys as $key) {
929
+			if (isset($_SERVER[ $key ])) {
930
+				foreach (array_map('trim', explode(',', $_SERVER[ $key ])) as $ip) {
931
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
932
+						$visitor_ip = $ip;
933
+					}
934
+				}
935
+			}
936
+		}
937
+		return $visitor_ip;
938
+	}
939
+
940
+
941
+
942
+	/**
943
+	 * @get    the full page request the visitor is accessing
944
+	 * @access public
945
+	 * @return string
946
+	 */
947
+	public function _get_page_visit()
948
+	{
949
+		$page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
950
+		// check for request url
951
+		if (isset($_SERVER['REQUEST_URI'])) {
952
+			$http_host   = '';
953
+			$page_id     = '?';
954
+			$e_reg       = '';
955
+			$request_uri = esc_url($_SERVER['REQUEST_URI']);
956
+			$ru_bits     = explode('?', $request_uri);
957
+			$request_uri = $ru_bits[0];
958
+			// check for and grab host as well
959
+			if (isset($_SERVER['HTTP_HOST'])) {
960
+				$http_host = esc_url($_SERVER['HTTP_HOST']);
961
+			}
962
+			// check for page_id in SERVER REQUEST
963
+			if (isset($_REQUEST['page_id'])) {
964
+				// rebuild $e_reg without any of the extra parameters
965
+				$page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
966
+			}
967
+			// check for $e_reg in SERVER REQUEST
968
+			if (isset($_REQUEST['ee'])) {
969
+				// rebuild $e_reg without any of the extra parameters
970
+				$e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
971
+			}
972
+			$page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
973
+		}
974
+		return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
975
+	}
976
+
977
+
978
+
979
+	/**
980
+	 * @the    current wp user id
981
+	 * @access public
982
+	 * @return int
983
+	 */
984
+	public function _wp_user_id()
985
+	{
986
+		// if I need to explain the following lines of code, then you shouldn't be looking at this!
987
+		$this->_wp_user_id = get_current_user_id();
988
+		return $this->_wp_user_id;
989
+	}
990
+
991
+
992
+
993
+	/**
994
+	 * Clear EE_Session data
995
+	 *
996
+	 * @access public
997
+	 * @param string $class
998
+	 * @param string $function
999
+	 * @return void
1000
+	 * @throws EE_Error
1001
+	 * @throws InvalidArgumentException
1002
+	 * @throws InvalidDataTypeException
1003
+	 * @throws InvalidInterfaceException
1004
+	 */
1005
+	public function clear_session($class = '', $function = '')
1006
+	{
1007
+		//echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
1008
+		do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1009
+		$this->reset_cart();
1010
+		$this->reset_checkout();
1011
+		$this->reset_transaction();
1012
+		// wipe out everything that isn't a default session datum
1013
+		$this->reset_data(array_keys($this->_session_data));
1014
+		// reset initial site access time and the session expiration
1015
+		$this->_set_init_access_and_expiration();
1016
+		$this->_save_session_to_db();
1017
+	}
1018
+
1019
+
1020
+
1021
+	/**
1022
+	 * @resets all non-default session vars
1023
+	 * @access public
1024
+	 * @param array|mixed $data_to_reset
1025
+	 * @param bool        $show_all_notices
1026
+	 * @return TRUE on success, FALSE on fail
1027
+	 */
1028
+	public function reset_data($data_to_reset = array(), $show_all_notices = false)
1029
+	{
1030
+		// if $data_to_reset is not in an array, then put it in one
1031
+		if (! is_array($data_to_reset)) {
1032
+			$data_to_reset = array($data_to_reset);
1033
+		}
1034
+		// nothing ??? go home!
1035
+		if (empty($data_to_reset)) {
1036
+			EE_Error::add_error(__('No session data could be reset, because no session var name was provided.',
1037
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1038
+			return false;
1039
+		}
1040
+		$return_value = true;
1041
+		// since $data_to_reset is an array, cycle through the values
1042
+		foreach ($data_to_reset as $reset) {
1043
+
1044
+			// first check to make sure it is a valid session var
1045
+			if (isset($this->_session_data[ $reset ])) {
1046
+				// then check to make sure it is not a default var
1047
+				if (! array_key_exists($reset, $this->_default_session_vars)) {
1048
+					// remove session var
1049
+					unset($this->_session_data[ $reset ]);
1050
+					if ($show_all_notices) {
1051
+						EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'),
1052
+							$reset), __FILE__, __FUNCTION__, __LINE__);
1053
+					}
1054
+				} else {
1055
+					// yeeeeeeeeerrrrrrrrrrr OUT !!!!
1056
+					if ($show_all_notices) {
1057
+						EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
1058
+							'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1059
+					}
1060
+					$return_value = false;
1061
+				}
1062
+			} elseif ($show_all_notices) {
1063
+				// oops! that session var does not exist!
1064
+				EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.',
1065
+					'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1066
+				$return_value = false;
1067
+			}
1068
+		} // end of foreach
1069
+		return $return_value;
1070
+	}
1071
+
1072
+
1073
+
1074
+	/**
1075
+	 *   wp_loaded
1076
+	 *
1077
+	 * @access public
1078
+	 * @throws EE_Error
1079
+	 * @throws InvalidDataTypeException
1080
+	 * @throws InvalidInterfaceException
1081
+	 * @throws InvalidArgumentException
1082
+	 */
1083
+	public function wp_loaded()
1084
+	{
1085
+		if (
1086
+			EE_Registry::instance()->REQ instanceof EE_Request_Handler
1087
+			&& EE_Registry::instance()->REQ->is_set('clear_session')
1088
+		) {
1089
+			$this->clear_session(__CLASS__, __FUNCTION__);
1090
+		}
1091
+	}
1092
+
1093
+
1094
+
1095
+	/**
1096
+	 * Used to reset the entire object (for tests).
1097
+	 *
1098
+	 * @since 4.3.0
1099
+	 * @throws EE_Error
1100
+	 * @throws InvalidDataTypeException
1101
+	 * @throws InvalidInterfaceException
1102
+	 * @throws InvalidArgumentException
1103
+	 */
1104
+	public function reset_instance()
1105
+	{
1106
+		$this->clear_session();
1107
+		self::$_instance = null;
1108
+	}
1109
+
1110
+
1111
+
1112
+	public function configure_garbage_collection_filters()
1113
+	{
1114
+		// run old filter we had for controlling session cleanup
1115
+		$expired_session_transient_delete_query_limit = absint(
1116
+			apply_filters(
1117
+				'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1118
+				50
1119
+			)
1120
+		);
1121
+		// is there a value? or one that is different than the default 50 records?
1122
+		if ($expired_session_transient_delete_query_limit === 0) {
1123
+			// hook into TransientCacheStorage in case Session cleanup was turned off
1124
+			add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero');
1125
+		} elseif ($expired_session_transient_delete_query_limit !== 50) {
1126
+			// or use that for the new transient cleanup query limit
1127
+			add_filter(
1128
+				'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1129
+				function () use ($expired_session_transient_delete_query_limit)
1130
+				{
1131
+					return $expired_session_transient_delete_query_limit;
1132
+				}
1133
+			);
1134
+		}
1135
+	}
1136
+
1137
+
1138
+
1139
+	/**
1140
+	 * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996
1141
+	 * @param $data1
1142
+	 * @return string
1143
+	 */
1144
+	private function find_serialize_error($data1)
1145
+	{
1146
+		$error = '<pre>';
1147
+		$data2 = preg_replace_callback(
1148
+			'!s:(\d+):"(.*?)";!',
1149
+			function ($match)
1150
+			{
1151
+				return ($match[1] === strlen($match[2]))
1152
+					? $match[0]
1153
+					: 's:'
1154
+					  . strlen($match[2])
1155
+					  . ':"'
1156
+					  . $match[2]
1157
+					  . '";';
1158
+			},
1159
+			$data1
1160
+		);
1161
+		$max   = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1162
+		$error .= $data1 . PHP_EOL;
1163
+		$error .= $data2 . PHP_EOL;
1164
+		for ($i = 0; $i < $max; $i++) {
1165
+			if (@$data1[ $i ] !== @$data2[ $i ]) {
1166
+				$error  .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1167
+				$error  .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1168
+				$error  .= "\t-> Line Number = $i" . PHP_EOL;
1169
+				$start  = ($i - 20);
1170
+				$start  = ($start < 0) ? 0 : $start;
1171
+				$length = 40;
1172
+				$point  = $max - $i;
1173
+				if ($point < 20) {
1174
+					$rlength = 1;
1175
+					$rpoint  = -$point;
1176
+				} else {
1177
+					$rpoint  = $length - 20;
1178
+					$rlength = 1;
1179
+				}
1180
+				$error .= "\t-> Section Data1  = ";
1181
+				$error .= substr_replace(
1182
+					substr($data1, $start, $length),
1183
+					"<b style=\"color:green\">{$data1[ $i ]}</b>",
1184
+					$rpoint,
1185
+					$rlength
1186
+				);
1187
+				$error .= PHP_EOL;
1188
+				$error .= "\t-> Section Data2  = ";
1189
+				$error .= substr_replace(
1190
+					substr($data2, $start, $length),
1191
+					"<b style=\"color:red\">{$data2[ $i ]}</b>",
1192
+					$rpoint,
1193
+					$rlength
1194
+				);
1195
+				$error .= PHP_EOL;
1196
+			}
1197
+		}
1198
+		$error .= '</pre>';
1199
+		return $error;
1200
+	}
1201
+
1202
+
1203
+	/**
1204
+	 * Saves an  array of settings used for configuring aspects of session behaviour
1205
+	 *
1206
+	 * @param array $updated_settings
1207
+	 */
1208
+	private function updateSessionSettings(array $updated_settings = array())
1209
+	{
1210
+		// add existing settings, but only if not included in incoming $updated_settings array
1211
+		$updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array());
1212
+		update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings);
1213
+	}
1214
+
1215
+
1216
+	/**
1217
+	 * garbage_collection
1218
+	 */
1219
+	public function garbageCollection()
1220
+	{
1221
+		// only perform during regular requests if last garbage collection was over an hour ago
1222
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1223
+			$this->_last_gc = time();
1224
+			$this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1225
+			/** @type WPDB $wpdb */
1226
+			global $wpdb;
1227
+			// filter the query limit. Set to 0 to turn off garbage collection
1228
+			$expired_session_transient_delete_query_limit = absint(
1229
+				apply_filters(
1230
+					'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1231
+					50
1232
+				)
1233
+			);
1234
+			// non-zero LIMIT means take out the trash
1235
+			if ($expired_session_transient_delete_query_limit) {
1236
+				$session_key    = str_replace('_', '\_', EE_Session::session_id_prefix);
1237
+				$hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix);
1238
+				// since transient expiration timestamps are set in the future, we can compare against NOW
1239
+				// but we only want to pick up any trash that's been around for more than a day
1240
+				$expiration = time() - DAY_IN_SECONDS;
1241
+				$SQL        = "
1242 1242
                     SELECT option_name
1243 1243
                     FROM {$wpdb->options}
1244 1244
                     WHERE
@@ -1247,19 +1247,19 @@  discard block
 block discarded – undo
1247 1247
                     AND option_value < {$expiration}
1248 1248
                     LIMIT {$expired_session_transient_delete_query_limit}
1249 1249
                 ";
1250
-                // produces something like:
1251
-                // SELECT option_name FROM wp_options
1252
-                // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%'
1253
-                // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' )
1254
-                // AND option_value < 1508368198 LIMIT 50
1255
-                $expired_sessions = $wpdb->get_col($SQL);
1256
-                // valid results?
1257
-                if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1258
-                    $this->cache_storage->deleteMany($expired_sessions, true);
1259
-                }
1260
-            }
1261
-        }
1262
-    }
1250
+				// produces something like:
1251
+				// SELECT option_name FROM wp_options
1252
+				// WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%'
1253
+				// OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' )
1254
+				// AND option_value < 1508368198 LIMIT 50
1255
+				$expired_sessions = $wpdb->get_col($SQL);
1256
+				// valid results?
1257
+				if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1258
+					$this->cache_storage->deleteMany($expired_sessions, true);
1259
+				}
1260
+			}
1261
+		}
1262
+	}
1263 1263
 
1264 1264
 
1265 1265
 
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         // check if class object is instantiated
165 165
         // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
166 166
         // add_filter( 'FHEE_load_EE_Session', '__return_false' );
167
-        if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
167
+        if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
168 168
             self::$_instance = new self($cache_storage, $encryption);
169 169
         }
170 170
         return self::$_instance;
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
     {
186 186
 
187 187
         // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
188
-        if (! apply_filters('FHEE_load_EE_Session', true)) {
188
+        if ( ! apply_filters('FHEE_load_EE_Session', true)) {
189 189
             return;
190 190
         }
191 191
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
192
-        if (! defined('ESPRESSO_SESSION')) {
192
+        if ( ! defined('ESPRESSO_SESSION')) {
193 193
             define('ESPRESSO_SESSION', true);
194 194
         }
195 195
         // default session lifespan in seconds
@@ -205,11 +205,11 @@  discard block
 block discarded – undo
205 205
          */
206 206
         // retrieve session options from db
207 207
         $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
208
-        if (! empty($session_settings)) {
208
+        if ( ! empty($session_settings)) {
209 209
             // cycle though existing session options
210 210
             foreach ($session_settings as $var_name => $session_setting) {
211 211
                 // set values for class properties
212
-                $var_name          = '_' . $var_name;
212
+                $var_name          = '_'.$var_name;
213 213
                 $this->{$var_name} = $session_setting;
214 214
             }
215 215
         }
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
     public function open_session()
248 248
     {
249 249
         // check for existing session and retrieve it from db
250
-        if (! $this->_espresso_session()) {
250
+        if ( ! $this->_espresso_session()) {
251 251
             // or just start a new one
252 252
             $this->_create_espresso_session();
253 253
         }
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
      */
300 300
     public function extend_expiration($time = 0)
301 301
     {
302
-        $time              = $time ? $time : $this->extension();
302
+        $time = $time ? $time : $this->extension();
303 303
         $this->_expiration += absint($time);
304 304
     }
305 305
 
@@ -326,9 +326,9 @@  discard block
 block discarded – undo
326 326
         // set some defaults
327 327
         foreach ($this->_default_session_vars as $key => $default_var) {
328 328
             if (is_array($default_var)) {
329
-                $this->_session_data[ $key ] = array();
329
+                $this->_session_data[$key] = array();
330 330
             } else {
331
-                $this->_session_data[ $key ] = '';
331
+                $this->_session_data[$key] = '';
332 332
             }
333 333
         }
334 334
     }
@@ -471,8 +471,8 @@  discard block
 block discarded – undo
471 471
             $this->reset_checkout();
472 472
             $this->reset_transaction();
473 473
         }
474
-        if (! empty($key)) {
475
-            return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
474
+        if ( ! empty($key)) {
475
+            return isset($this->_session_data[$key]) ? $this->_session_data[$key] : null;
476 476
         }
477 477
         return $this->_session_data;
478 478
     }
@@ -496,12 +496,12 @@  discard block
 block discarded – undo
496 496
             return false;
497 497
         }
498 498
         foreach ($data as $key => $value) {
499
-            if (isset($this->_default_session_vars[ $key ])) {
499
+            if (isset($this->_default_session_vars[$key])) {
500 500
                 EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
501 501
                     'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__);
502 502
                 return false;
503 503
             }
504
-            $this->_session_data[ $key ] = $value;
504
+            $this->_session_data[$key] = $value;
505 505
         }
506 506
         return true;
507 507
     }
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
         $this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : false;
535 535
         // now let's retrieve what's in the db
536 536
         $session_data = $this->_retrieve_session_data();
537
-        if (! empty($session_data)) {
537
+        if ( ! empty($session_data)) {
538 538
             // get the current time in UTC
539 539
             $this->_time = $this->_time !== null ? $this->_time : time();
540 540
             // and reset the session expiration
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
             // set initial site access time and the session expiration
546 546
             $this->_set_init_access_and_expiration();
547 547
             // set referer
548
-            $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
548
+            $this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER'])
549 549
                 ? esc_attr($_SERVER['HTTP_REFERER'])
550 550
                 : '';
551 551
             // no previous session = go back and create one (on top of the data above)
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
      */
584 584
     protected function _retrieve_session_data()
585 585
     {
586
-        $ssn_key = EE_Session::session_id_prefix . $this->_sid;
586
+        $ssn_key = EE_Session::session_id_prefix.$this->_sid;
587 587
         try {
588 588
             // we're using WP's Transient API to store session data using the PHP session ID as the option name
589 589
             $session_data = $this->cache_storage->get($ssn_key, false);
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
             }
593 593
             if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
594 594
                 $hash_check = $this->cache_storage->get(
595
-                    EE_Session::hash_check_prefix . $this->_sid,
595
+                    EE_Session::hash_check_prefix.$this->_sid,
596 596
                     false
597 597
                 );
598 598
                 if ($hash_check && $hash_check !== md5($session_data)) {
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
                                 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
603 603
                                 'event_espresso'
604 604
                             ),
605
-                            EE_Session::session_id_prefix . $this->_sid
605
+                            EE_Session::session_id_prefix.$this->_sid
606 606
                         ),
607 607
                         __FILE__, __FUNCTION__, __LINE__
608 608
                     );
@@ -611,21 +611,21 @@  discard block
 block discarded – undo
611 611
         } catch (Exception $e) {
612 612
             // let's just eat that error for now and attempt to correct any corrupted data
613 613
             global $wpdb;
614
-            $row          = $wpdb->get_row(
614
+            $row = $wpdb->get_row(
615 615
                 $wpdb->prepare(
616 616
                     "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
617
-                    '_transient_' . $ssn_key
617
+                    '_transient_'.$ssn_key
618 618
                 )
619 619
             );
620 620
             $session_data = is_object($row) ? $row->option_value : null;
621 621
             if ($session_data) {
622 622
                 $session_data = preg_replace_callback(
623 623
                     '!s:(d+):"(.*?)";!',
624
-                    function ($match)
624
+                    function($match)
625 625
                     {
626 626
                         return $match[1] === strlen($match[2])
627 627
                             ? $match[0]
628
-                            : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
628
+                            : 's:'.strlen($match[2]).':"'.$match[2].'";';
629 629
                     },
630 630
                     $session_data
631 631
                 );
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
         $session_data = $this->encryption instanceof EE_Encryption
637 637
             ? $this->encryption->base64_string_decode($session_data)
638 638
             : $session_data;
639
-        if (! is_array($session_data)) {
639
+        if ( ! is_array($session_data)) {
640 640
             try {
641 641
                 $session_data = maybe_unserialize($session_data);
642 642
             } catch (Exception $e) {
@@ -650,21 +650,21 @@  discard block
 block discarded – undo
650 650
                       . '</pre><br>'
651 651
                       . $this->find_serialize_error($session_data)
652 652
                     : '';
653
-                $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
653
+                $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid);
654 654
                 throw new InvalidSessionDataException($msg, 0, $e);
655 655
             }
656 656
         }
657 657
         // just a check to make sure the session array is indeed an array
658
-        if (! is_array($session_data)) {
658
+        if ( ! is_array($session_data)) {
659 659
             // no?!?! then something is wrong
660 660
             $msg = esc_html__(
661 661
                 'The session data is missing, invalid, or corrupted.',
662 662
                 'event_espresso'
663 663
             );
664 664
             $msg .= WP_DEBUG
665
-                ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
665
+                ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
666 666
                 : '';
667
-            $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
667
+            $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid);
668 668
             throw new InvalidSessionDataException($msg);
669 669
         }
670 670
         if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
         if (isset($_REQUEST['EESID'])) {
693 693
             $session_id = sanitize_text_field($_REQUEST['EESID']);
694 694
         } else {
695
-            $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
695
+            $session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt());
696 696
         }
697 697
         return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
698 698
     }
@@ -800,19 +800,19 @@  discard block
 block discarded – undo
800 800
                     $page_visit = $this->_get_page_visit();
801 801
                     if ($page_visit) {
802 802
                         // set pages visited where the first will be the http referrer
803
-                        $this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
803
+                        $this->_session_data['pages_visited'][$this->_time] = $page_visit;
804 804
                         // we'll only save the last 10 page visits.
805 805
                         $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
806 806
                     }
807 807
                     break;
808 808
                 default :
809 809
                     // carry any other data over
810
-                    $session_data[ $key ] = $this->_session_data[ $key ];
810
+                    $session_data[$key] = $this->_session_data[$key];
811 811
             }
812 812
         }
813 813
         $this->_session_data = $session_data;
814 814
         // creating a new session does not require saving to the db just yet
815
-        if (! $new_session) {
815
+        if ( ! $new_session) {
816 816
             // ready? let's save
817 817
             if ($this->_save_session_to_db()) {
818 818
                 return true;
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
         }
877 877
         $transaction = $this->transaction();
878 878
         if ($transaction instanceof EE_Transaction) {
879
-            if (! $transaction->ID()) {
879
+            if ( ! $transaction->ID()) {
880 880
                 $transaction->save();
881 881
             }
882 882
             $this->_session_data['transaction'] = $transaction->ID();
@@ -890,14 +890,14 @@  discard block
 block discarded – undo
890 890
         // maybe save hash check
891 891
         if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
892 892
             $this->cache_storage->add(
893
-                EE_Session::hash_check_prefix . $this->_sid,
893
+                EE_Session::hash_check_prefix.$this->_sid,
894 894
                 md5($session_data),
895 895
                 $this->_lifespan
896 896
             );
897 897
         }
898 898
         // we're using the Transient API for storing session data,
899 899
         return $this->cache_storage->add(
900
-            EE_Session::session_id_prefix . $this->_sid,
900
+            EE_Session::session_id_prefix.$this->_sid,
901 901
             $session_data,
902 902
             $this->_lifespan
903 903
         );
@@ -926,8 +926,8 @@  discard block
 block discarded – undo
926 926
             'REMOTE_ADDR',
927 927
         );
928 928
         foreach ($server_keys as $key) {
929
-            if (isset($_SERVER[ $key ])) {
930
-                foreach (array_map('trim', explode(',', $_SERVER[ $key ])) as $ip) {
929
+            if (isset($_SERVER[$key])) {
930
+                foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
931 931
                     if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
932 932
                         $visitor_ip = $ip;
933 933
                     }
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
      */
947 947
     public function _get_page_visit()
948 948
     {
949
-        $page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
949
+        $page_visit = home_url('/').'wp-admin/admin-ajax.php';
950 950
         // check for request url
951 951
         if (isset($_SERVER['REQUEST_URI'])) {
952 952
             $http_host   = '';
@@ -962,14 +962,14 @@  discard block
 block discarded – undo
962 962
             // check for page_id in SERVER REQUEST
963 963
             if (isset($_REQUEST['page_id'])) {
964 964
                 // rebuild $e_reg without any of the extra parameters
965
-                $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
965
+                $page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&amp;';
966 966
             }
967 967
             // check for $e_reg in SERVER REQUEST
968 968
             if (isset($_REQUEST['ee'])) {
969 969
                 // rebuild $e_reg without any of the extra parameters
970
-                $e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
970
+                $e_reg = 'ee='.esc_attr($_REQUEST['ee']);
971 971
             }
972
-            $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
972
+            $page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?');
973 973
         }
974 974
         return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
975 975
     }
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
     public function clear_session($class = '', $function = '')
1006 1006
     {
1007 1007
         //echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
1008
-        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1008
+        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()');
1009 1009
         $this->reset_cart();
1010 1010
         $this->reset_checkout();
1011 1011
         $this->reset_transaction();
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
     public function reset_data($data_to_reset = array(), $show_all_notices = false)
1029 1029
     {
1030 1030
         // if $data_to_reset is not in an array, then put it in one
1031
-        if (! is_array($data_to_reset)) {
1031
+        if ( ! is_array($data_to_reset)) {
1032 1032
             $data_to_reset = array($data_to_reset);
1033 1033
         }
1034 1034
         // nothing ??? go home!
@@ -1042,11 +1042,11 @@  discard block
 block discarded – undo
1042 1042
         foreach ($data_to_reset as $reset) {
1043 1043
 
1044 1044
             // first check to make sure it is a valid session var
1045
-            if (isset($this->_session_data[ $reset ])) {
1045
+            if (isset($this->_session_data[$reset])) {
1046 1046
                 // then check to make sure it is not a default var
1047
-                if (! array_key_exists($reset, $this->_default_session_vars)) {
1047
+                if ( ! array_key_exists($reset, $this->_default_session_vars)) {
1048 1048
                     // remove session var
1049
-                    unset($this->_session_data[ $reset ]);
1049
+                    unset($this->_session_data[$reset]);
1050 1050
                     if ($show_all_notices) {
1051 1051
                         EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'),
1052 1052
                             $reset), __FILE__, __FUNCTION__, __LINE__);
@@ -1126,7 +1126,7 @@  discard block
 block discarded – undo
1126 1126
             // or use that for the new transient cleanup query limit
1127 1127
             add_filter(
1128 1128
                 'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1129
-                function () use ($expired_session_transient_delete_query_limit)
1129
+                function() use ($expired_session_transient_delete_query_limit)
1130 1130
                 {
1131 1131
                     return $expired_session_transient_delete_query_limit;
1132 1132
                 }
@@ -1146,7 +1146,7 @@  discard block
 block discarded – undo
1146 1146
         $error = '<pre>';
1147 1147
         $data2 = preg_replace_callback(
1148 1148
             '!s:(\d+):"(.*?)";!',
1149
-            function ($match)
1149
+            function($match)
1150 1150
             {
1151 1151
                 return ($match[1] === strlen($match[2]))
1152 1152
                     ? $match[0]
@@ -1158,14 +1158,14 @@  discard block
 block discarded – undo
1158 1158
             },
1159 1159
             $data1
1160 1160
         );
1161
-        $max   = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1162
-        $error .= $data1 . PHP_EOL;
1163
-        $error .= $data2 . PHP_EOL;
1161
+        $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1162
+        $error .= $data1.PHP_EOL;
1163
+        $error .= $data2.PHP_EOL;
1164 1164
         for ($i = 0; $i < $max; $i++) {
1165
-            if (@$data1[ $i ] !== @$data2[ $i ]) {
1166
-                $error  .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1167
-                $error  .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1168
-                $error  .= "\t-> Line Number = $i" . PHP_EOL;
1165
+            if (@$data1[$i] !== @$data2[$i]) {
1166
+                $error  .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL;
1167
+                $error  .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL;
1168
+                $error  .= "\t-> Line Number = $i".PHP_EOL;
1169 1169
                 $start  = ($i - 20);
1170 1170
                 $start  = ($start < 0) ? 0 : $start;
1171 1171
                 $length = 40;
@@ -1180,7 +1180,7 @@  discard block
 block discarded – undo
1180 1180
                 $error .= "\t-> Section Data1  = ";
1181 1181
                 $error .= substr_replace(
1182 1182
                     substr($data1, $start, $length),
1183
-                    "<b style=\"color:green\">{$data1[ $i ]}</b>",
1183
+                    "<b style=\"color:green\">{$data1[$i]}</b>",
1184 1184
                     $rpoint,
1185 1185
                     $rlength
1186 1186
                 );
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
                 $error .= "\t-> Section Data2  = ";
1189 1189
                 $error .= substr_replace(
1190 1190
                     substr($data2, $start, $length),
1191
-                    "<b style=\"color:red\">{$data2[ $i ]}</b>",
1191
+                    "<b style=\"color:red\">{$data2[$i]}</b>",
1192 1192
                     $rpoint,
1193 1193
                     $rlength
1194 1194
                 );
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
     public function garbageCollection()
1220 1220
     {
1221 1221
         // only perform during regular requests if last garbage collection was over an hour ago
1222
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1222
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1223 1223
             $this->_last_gc = time();
1224 1224
             $this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1225 1225
             /** @type WPDB $wpdb */
@@ -1254,7 +1254,7 @@  discard block
 block discarded – undo
1254 1254
                 // AND option_value < 1508368198 LIMIT 50
1255 1255
                 $expired_sessions = $wpdb->get_col($SQL);
1256 1256
                 // valid results?
1257
-                if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1257
+                if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1258 1258
                     $this->cache_storage->deleteMany($expired_sessions, true);
1259 1259
                 }
1260 1260
             }
Please login to merge, or discard this patch.
admin_pages/maintenance/Maintenance_Admin_Page.core.php 2 patches
Indentation   +749 added lines, -749 removed lines patch added patch discarded remove patch
@@ -28,765 +28,765 @@
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    /**
32
-     * @var EE_Datetime_Offset_Fix_Form
33
-     */
34
-    protected $datetime_fix_offset_form;
35
-
36
-
37
-
38
-    protected function _init_page_props()
39
-    {
40
-        $this->page_slug = EE_MAINTENANCE_PG_SLUG;
41
-        $this->page_label = EE_MAINTENANCE_LABEL;
42
-        $this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL;
43
-        $this->_admin_base_path = EE_MAINTENANCE_ADMIN;
44
-    }
45
-
46
-
47
-
48
-    protected function _ajax_hooks()
49
-    {
50
-        add_action('wp_ajax_migration_step', array($this, 'migration_step'));
51
-        add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran'));
52
-    }
53
-
54
-
55
-
56
-    protected function _define_page_props()
57
-    {
58
-        $this->_admin_page_title = EE_MAINTENANCE_LABEL;
59
-        $this->_labels = array(
60
-            'buttons' => array(
61
-                'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
62
-                'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
63
-            ),
64
-        );
65
-    }
66
-
67
-
68
-
69
-    protected function _set_page_routes()
70
-    {
71
-        $this->_page_routes = array(
72
-            'default'                             => array(
73
-                'func'       => '_maintenance',
74
-                'capability' => 'manage_options',
75
-            ),
76
-            'change_maintenance_level'            => array(
77
-                'func'       => '_change_maintenance_level',
78
-                'capability' => 'manage_options',
79
-                'noheader'   => true,
80
-            ),
81
-            'system_status'                       => array(
82
-                'func'       => '_system_status',
83
-                'capability' => 'manage_options',
84
-            ),
85
-            'download_system_status' => array(
86
-                'func'       => '_download_system_status',
87
-                'capability' => 'manage_options',
88
-                'noheader'   => true,
89
-            ),
90
-            'send_migration_crash_report'         => array(
91
-                'func'       => '_send_migration_crash_report',
92
-                'capability' => 'manage_options',
93
-                'noheader'   => true,
94
-            ),
95
-            'confirm_migration_crash_report_sent' => array(
96
-                'func'       => '_confirm_migration_crash_report_sent',
97
-                'capability' => 'manage_options',
98
-            ),
99
-            'data_reset'                          => array(
100
-                'func'       => '_data_reset_and_delete',
101
-                'capability' => 'manage_options',
102
-            ),
103
-            'reset_db'                            => array(
104
-                'func'       => '_reset_db',
105
-                'capability' => 'manage_options',
106
-                'noheader'   => true,
107
-                'args'       => array('nuke_old_ee4_data' => true),
108
-            ),
109
-            'start_with_fresh_ee4_db'             => array(
110
-                'func'       => '_reset_db',
111
-                'capability' => 'manage_options',
112
-                'noheader'   => true,
113
-                'args'       => array('nuke_old_ee4_data' => false),
114
-            ),
115
-            'delete_db'                           => array(
116
-                'func'       => '_delete_db',
117
-                'capability' => 'manage_options',
118
-                'noheader'   => true,
119
-            ),
120
-            'rerun_migration_from_ee3'            => array(
121
-                'func'       => '_rerun_migration_from_ee3',
122
-                'capability' => 'manage_options',
123
-                'noheader'   => true,
124
-            ),
125
-            'reset_reservations'                  => array(
126
-                'func'       => '_reset_reservations',
127
-                'capability' => 'manage_options',
128
-                'noheader'   => true,
129
-            ),
130
-            'reset_capabilities'                  => array(
131
-                'func'       => '_reset_capabilities',
132
-                'capability' => 'manage_options',
133
-                'noheader'   => true,
134
-            ),
135
-            'reattempt_migration'                 => array(
136
-                'func'       => '_reattempt_migration',
137
-                'capability' => 'manage_options',
138
-                'noheader'   => true,
139
-            ),
140
-            'datetime_tools' => array(
141
-                'func' => '_datetime_tools',
142
-                'capability' => 'manage_options'
143
-            ),
144
-            'run_datetime_offset_fix' => array(
145
-                'func' => '_apply_datetime_offset',
146
-                'noheader' => true,
147
-                'headers_sent_route' => 'datetime_tools',
148
-                'capability' => 'manage_options'
149
-            )
150
-        );
151
-    }
152
-
153
-
154
-
155
-    protected function _set_page_config()
156
-    {
157
-        $this->_page_config = array(
158
-            'default'       => array(
159
-                'nav'           => array(
160
-                    'label' => esc_html__('Maintenance', 'event_espresso'),
161
-                    'order' => 10,
162
-                ),
163
-                'require_nonce' => false,
164
-            ),
165
-            'data_reset'    => array(
166
-                'nav'           => array(
167
-                    'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
168
-                    'order' => 20,
169
-                ),
170
-                'require_nonce' => false,
171
-            ),
172
-            'datetime_tools' => array(
173
-                'nav' => array(
174
-                    'label' => esc_html__('Datetime Utilities', 'event_espresso'),
175
-                    'order' => 25
176
-                ),
177
-                'require_nonce' => false,
178
-            ),
179
-            'system_status' => array(
180
-                'nav'           => array(
181
-                    'label' => esc_html__("System Information", "event_espresso"),
182
-                    'order' => 30,
183
-                ),
184
-                'require_nonce' => false,
185
-            ),
186
-        );
187
-    }
188
-
189
-
190
-
191
-    /**
192
-     * default maintenance page. If we're in maintenance mode level 2, then we need to show
193
-     * the migration scripts and all that UI.
194
-     */
195
-    public function _maintenance()
196
-    {
197
-        //it all depends if we're in maintenance model level 1 (frontend-only) or
198
-        //level 2 (everything except maintenance page)
199
-        try {
200
-            //get the current maintenance level and check if
201
-            //we are removed
202
-            $mm = EE_Maintenance_Mode::instance()->level();
203
-            $placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
204
-            if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
205
-                //we just took the site out of maintenance mode, so notify the user.
206
-                //unfortunately this message appears to be echoed on the NEXT page load...
207
-                //oh well, we should really be checking for this on addon deactivation anyways
208
-                EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required',
209
-                    'event_espresso'));
210
-                $this->_process_notices(array('page' => 'espresso_maintenance_settings'), false);
211
-            }
212
-            //in case an exception is thrown while trying to handle migrations
213
-            switch (EE_Maintenance_Mode::instance()->level()) {
214
-                case EE_Maintenance_Mode::level_0_not_in_maintenance:
215
-                case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
216
-                    $show_maintenance_switch = true;
217
-                    $show_backup_db_text = false;
218
-                    $show_migration_progress = false;
219
-                    $script_names = array();
220
-                    $addons_should_be_upgraded_first = false;
221
-                    break;
222
-                case EE_Maintenance_Mode::level_2_complete_maintenance:
223
-                    $show_maintenance_switch = false;
224
-                    $show_migration_progress = true;
225
-                    if (isset($this->_req_data['continue_migration'])) {
226
-                        $show_backup_db_text = false;
227
-                    } else {
228
-                        $show_backup_db_text = true;
229
-                    }
230
-                    $scripts_needing_to_run = EE_Data_Migration_Manager::instance()
231
-                                                                       ->check_for_applicable_data_migration_scripts();
232
-                    $addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating();
233
-                    $script_names = array();
234
-                    $current_script = null;
235
-                    foreach ($scripts_needing_to_run as $script) {
236
-                        if ($script instanceof EE_Data_Migration_Script_Base) {
237
-                            if ( ! $current_script) {
238
-                                $current_script = $script;
239
-                                $current_script->migration_page_hooks();
240
-                            }
241
-                            $script_names[] = $script->pretty_name();
242
-                        }
243
-                    }
244
-                    break;
245
-            }
246
-            $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
247
-            $exception_thrown = false;
248
-        } catch (EE_Error $e) {
249
-            EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
250
-            //now, just so we can display the page correctly, make a error migration script stage object
251
-            //and also put the error on it. It only persists for the duration of this request
252
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
253
-            $most_recent_migration->add_error($e->getMessage());
254
-            $exception_thrown = true;
255
-        }
256
-        $current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set();
257
-        $current_db_state = str_replace('.decaf', '', $current_db_state);
258
-        if ($exception_thrown
259
-            || ($most_recent_migration
260
-                && $most_recent_migration instanceof EE_Data_Migration_Script_Base
261
-                && $most_recent_migration->is_broken()
262
-            )
263
-        ) {
264
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
265
-            $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
266
-            $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
267
-                                                                                        'success' => '0',
268
-            ), EE_MAINTENANCE_ADMIN_URL);
269
-        } elseif ($addons_should_be_upgraded_first) {
270
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
271
-        } else {
272
-            if ($most_recent_migration
273
-                && $most_recent_migration instanceof EE_Data_Migration_Script_Base
274
-                && $most_recent_migration->can_continue()
275
-            ) {
276
-                $show_backup_db_text = false;
277
-                $show_continue_current_migration_script = true;
278
-                $show_most_recent_migration = true;
279
-            } elseif (isset($this->_req_data['continue_migration'])) {
280
-                $show_most_recent_migration = true;
281
-                $show_continue_current_migration_script = false;
282
-            } else {
283
-                $show_most_recent_migration = false;
284
-                $show_continue_current_migration_script = false;
285
-            }
286
-            if (isset($current_script)) {
287
-                $migrates_to = $current_script->migrates_to_version();
288
-                $plugin_slug = $migrates_to['slug'];
289
-                $new_version = $migrates_to['version'];
290
-                $this->_template_args = array_merge($this->_template_args, array(
291
-                    'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"),
292
-                        isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug),
293
-                    'next_db_state'    => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'),
294
-                        $new_version, $plugin_slug) : null,
295
-                ));
296
-            } else {
297
-                $this->_template_args['current_db_state'] = null;
298
-                $this->_template_args['next_db_state'] = null;
299
-            }
300
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
301
-            $this->_template_args = array_merge(
302
-                $this->_template_args,
303
-                array(
304
-                    'show_most_recent_migration'             => $show_most_recent_migration,
305
-                    //flag for showing the most recent migration's status and/or errors
306
-                    'show_migration_progress'                => $show_migration_progress,
307
-                    //flag for showing the option to run migrations and see their progress
308
-                    'show_backup_db_text'                    => $show_backup_db_text,
309
-                    //flag for showing text telling the user to backup their DB
310
-                    'show_maintenance_switch'                => $show_maintenance_switch,
311
-                    //flag for showing the option to change maintenance mode between levels 0 and 1
312
-                    'script_names'                           => $script_names,
313
-                    //array of names of scripts that have run
314
-                    'show_continue_current_migration_script' => $show_continue_current_migration_script,
315
-                    //flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
316
-                    'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
317
-                        EE_MAINTENANCE_ADMIN_URL),
318
-                    'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
319
-                        EE_MAINTENANCE_ADMIN_URL),
320
-                    'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'),
321
-                        EE_MAINTENANCE_ADMIN_URL),
322
-                    'ultimate_db_state'                      => sprintf(__("EE%s", 'event_espresso'),
323
-                        espresso_version()),
324
-                )
325
-            );
326
-            //make sure we have the form fields helper available. It usually is, but sometimes it isn't
327
-        }
328
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
329
-        //now render the migration options part, and put it in a variable
330
-        $migration_options_template_file = apply_filters(
331
-            'FHEE__ee_migration_page__migration_options_template',
332
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
333
-        );
334
-        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
335
-        $this->_template_args['migration_options_html'] = $migration_options_html;
336
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
337
-            $this->_template_args, true);
338
-        $this->display_admin_page_with_sidebar();
339
-    }
340
-
341
-
342
-
343
-    /**
344
-     * returns JSON and executes another step of the currently-executing data migration (called via ajax)
345
-     */
346
-    public function migration_step()
347
-    {
348
-        $this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request();
349
-        $this->_return_json();
350
-    }
351
-
352
-
353
-
354
-    /**
355
-     * Can be used by js when it notices a response with HTML in it in order
356
-     * to log the malformed response
357
-     */
358
-    public function add_error_to_migrations_ran()
359
-    {
360
-        EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']);
361
-        $this->_template_args['data'] = array('ok' => true);
362
-        $this->_return_json();
363
-    }
364
-
365
-
366
-
367
-    /**
368
-     * changes the maintenance level, provided there are still no migration scripts that should run
369
-     */
370
-    public function _change_maintenance_level()
371
-    {
372
-        $new_level = absint($this->_req_data['maintenance_mode_level']);
373
-        if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
374
-            EE_Maintenance_Mode::instance()->set_maintenance_level($new_level);
375
-            $success = true;
376
-        } else {
377
-            EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
378
-            $success = false;
379
-        }
380
-        $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
381
-    }
382
-
383
-
384
-
385
-    /**
386
-     * a tab with options for resetting and/or deleting EE data
387
-     *
388
-     * @throws \EE_Error
389
-     * @throws \DomainException
390
-     */
391
-    public function _data_reset_and_delete()
392
-    {
393
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
394
-        $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
395
-            'reset_reservations',
396
-            'reset_reservations',
397
-            array(),
398
-            'button button-primary ee-confirm',
399
-            '',
400
-            false
401
-        );
402
-        $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
403
-            'reset_capabilities',
404
-            'reset_capabilities',
405
-            array(),
406
-            'button button-primary ee-confirm',
407
-            '',
408
-            false
409
-        );
410
-        $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
411
-            array('action' => 'delete_db'),
412
-            EE_MAINTENANCE_ADMIN_URL
413
-        );
414
-        $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
415
-            array('action' => 'reset_db'),
416
-            EE_MAINTENANCE_ADMIN_URL
417
-        );
418
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
419
-            $this->_template_path,
420
-            $this->_template_args,
421
-            true
422
-        );
423
-        $this->display_admin_page_with_sidebar();
424
-    }
425
-
426
-
427
-
428
-    protected function _reset_reservations()
429
-    {
430
-        if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
431
-            EE_Error::add_success(
432
-                __(
433
-                    'Ticket and datetime reserved counts have been successfully reset.',
434
-                    'event_espresso'
435
-                )
436
-            );
437
-        } else {
438
-            EE_Error::add_success(
439
-                __(
440
-                    'Ticket and datetime reserved counts were correct and did not need resetting.',
441
-                    'event_espresso'
442
-                )
443
-            );
444
-        }
445
-        $this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true);
446
-    }
447
-
448
-
449
-
450
-    protected function _reset_capabilities()
451
-    {
452
-        EE_Registry::instance()->CAP->init_caps(true);
453
-        EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.',
454
-            'event_espresso'));
455
-        $this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true);
456
-    }
457
-
458
-
459
-
460
-    /**
461
-     * resets the DMSs so we can attempt to continue migrating after a fatal error
462
-     * (only a good idea when someone has somehow tried ot fix whatever caused
463
-     * the fatal error in teh first place)
464
-     */
465
-    protected function _reattempt_migration()
466
-    {
467
-        EE_Data_Migration_Manager::instance()->reattempt();
468
-        $this->_redirect_after_action(false, '', '', array('action' => 'default'), true);
469
-    }
470
-
471
-
472
-
473
-    /**
474
-     * shows the big ol' System Information page
475
-     */
476
-    public function _system_status()
477
-    {
478
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
479
-        $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
480
-        $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
481
-            array(
482
-                'action' => 'download_system_status',
483
-            ),
484
-            EE_MAINTENANCE_ADMIN_URL
485
-        );
486
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
487
-            $this->_template_args, true);
488
-        $this->display_admin_page_with_sidebar();
489
-    }
490
-
491
-    /**
492
-     * Downloads an HTML file of the system status that can be easily stored or emailed
493
-     */
494
-    public function _download_system_status()
495
-    {
496
-        $status_info = EEM_System_Status::instance()->get_system_stati();
497
-        header( 'Content-Disposition: attachment' );
498
-        header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
499
-        echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
500
-        echo "<h1>System Information for " . site_url() . "</h1>";
501
-        echo EEH_Template::layout_array_as_table( $status_info );
502
-        die;
503
-    }
504
-
505
-
506
-
507
-    public function _send_migration_crash_report()
508
-    {
509
-        $from = $this->_req_data['from'];
510
-        $from_name = $this->_req_data['from_name'];
511
-        $body = $this->_req_data['body'];
512
-        try {
513
-            $success = wp_mail(EE_SUPPORT_EMAIL,
514
-                'Migration Crash Report',
515
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
516
-                array(
517
-                    "from:$from_name<$from>",
518
-                    //					'content-type:text/html charset=UTF-8'
519
-                ));
520
-        } catch (Exception $e) {
521
-            $success = false;
522
-        }
523
-        $this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"),
524
-            esc_html__("sent", "event_espresso"),
525
-            array('success' => $success, 'action' => 'confirm_migration_crash_report_sent'));
526
-    }
527
-
528
-
529
-
530
-    public function _confirm_migration_crash_report_sent()
531
-    {
532
-        try {
533
-            $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
534
-        } catch (EE_Error $e) {
535
-            EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
536
-            //now, just so we can display the page correctly, make a error migration script stage object
537
-            //and also put the error on it. It only persists for the duration of this request
538
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
539
-            $most_recent_migration->add_error($e->getMessage());
540
-        }
541
-        $success = $this->_req_data['success'] == '1' ? true : false;
542
-        $this->_template_args['success'] = $success;
543
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;
544
-        $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
545
-            EE_MAINTENANCE_ADMIN_URL);
546
-        $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
547
-            EE_MAINTENANCE_ADMIN_URL);
548
-        $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
549
-            EE_MAINTENANCE_ADMIN_URL);
550
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
551
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
552
-            $this->_template_args, true);
553
-        $this->display_admin_page_with_sidebar();
554
-    }
555
-
556
-
557
-
558
-    /**
559
-     * Resets the entire EE4 database.
560
-     * Currently basically only sets up ee4 database for a fresh install- doesn't
561
-     * actually clean out the old wp options, or cpts (although does erase old ee table data)
562
-     *
563
-     * @param boolean $nuke_old_ee4_data controls whether or not we
564
-     *                                   destroy the old ee4 data, or just try initializing ee4 default data
565
-     */
566
-    public function _reset_db($nuke_old_ee4_data = true)
567
-    {
568
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
569
-        if ($nuke_old_ee4_data) {
570
-            EEH_Activation::delete_all_espresso_cpt_data();
571
-            EEH_Activation::delete_all_espresso_tables_and_data(false);
572
-            EEH_Activation::remove_cron_tasks();
573
-        }
574
-        //make sure when we reset the registry's config that it
575
-        //switches to using the new singleton
576
-        EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
577
-        EE_System::instance()->initialize_db_if_no_migrations_required(true);
578
-        EE_System::instance()->redirect_to_about_ee();
579
-    }
580
-
581
-
582
-
583
-    /**
584
-     * Deletes ALL EE tables, Records, and Options from the database.
585
-     */
586
-    public function _delete_db()
587
-    {
588
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
589
-        EEH_Activation::delete_all_espresso_cpt_data();
590
-        EEH_Activation::delete_all_espresso_tables_and_data();
591
-        EEH_Activation::remove_cron_tasks();
592
-        EEH_Activation::deactivate_event_espresso();
593
-        wp_safe_redirect(admin_url('plugins.php'));
594
-        exit;
595
-    }
596
-
597
-
598
-
599
-    /**
600
-     * sets up EE4 to rerun the migrations from ee3 to ee4
601
-     */
602
-    public function _rerun_migration_from_ee3()
603
-    {
604
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
605
-        EEH_Activation::delete_all_espresso_cpt_data();
606
-        EEH_Activation::delete_all_espresso_tables_and_data(false);
607
-        //set the db state to something that will require migrations
608
-        update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
609
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
610
-        $this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso'));
611
-    }
612
-
613
-
614
-
615
-    //none of the below group are currently used for Gateway Settings
616
-    protected function _add_screen_options()
617
-    {
618
-    }
619
-
620
-
621
-
622
-    protected function _add_feature_pointers()
623
-    {
624
-    }
625
-
31
+	/**
32
+	 * @var EE_Datetime_Offset_Fix_Form
33
+	 */
34
+	protected $datetime_fix_offset_form;
35
+
36
+
37
+
38
+	protected function _init_page_props()
39
+	{
40
+		$this->page_slug = EE_MAINTENANCE_PG_SLUG;
41
+		$this->page_label = EE_MAINTENANCE_LABEL;
42
+		$this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL;
43
+		$this->_admin_base_path = EE_MAINTENANCE_ADMIN;
44
+	}
45
+
46
+
47
+
48
+	protected function _ajax_hooks()
49
+	{
50
+		add_action('wp_ajax_migration_step', array($this, 'migration_step'));
51
+		add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran'));
52
+	}
53
+
54
+
55
+
56
+	protected function _define_page_props()
57
+	{
58
+		$this->_admin_page_title = EE_MAINTENANCE_LABEL;
59
+		$this->_labels = array(
60
+			'buttons' => array(
61
+				'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
62
+				'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
63
+			),
64
+		);
65
+	}
66
+
67
+
68
+
69
+	protected function _set_page_routes()
70
+	{
71
+		$this->_page_routes = array(
72
+			'default'                             => array(
73
+				'func'       => '_maintenance',
74
+				'capability' => 'manage_options',
75
+			),
76
+			'change_maintenance_level'            => array(
77
+				'func'       => '_change_maintenance_level',
78
+				'capability' => 'manage_options',
79
+				'noheader'   => true,
80
+			),
81
+			'system_status'                       => array(
82
+				'func'       => '_system_status',
83
+				'capability' => 'manage_options',
84
+			),
85
+			'download_system_status' => array(
86
+				'func'       => '_download_system_status',
87
+				'capability' => 'manage_options',
88
+				'noheader'   => true,
89
+			),
90
+			'send_migration_crash_report'         => array(
91
+				'func'       => '_send_migration_crash_report',
92
+				'capability' => 'manage_options',
93
+				'noheader'   => true,
94
+			),
95
+			'confirm_migration_crash_report_sent' => array(
96
+				'func'       => '_confirm_migration_crash_report_sent',
97
+				'capability' => 'manage_options',
98
+			),
99
+			'data_reset'                          => array(
100
+				'func'       => '_data_reset_and_delete',
101
+				'capability' => 'manage_options',
102
+			),
103
+			'reset_db'                            => array(
104
+				'func'       => '_reset_db',
105
+				'capability' => 'manage_options',
106
+				'noheader'   => true,
107
+				'args'       => array('nuke_old_ee4_data' => true),
108
+			),
109
+			'start_with_fresh_ee4_db'             => array(
110
+				'func'       => '_reset_db',
111
+				'capability' => 'manage_options',
112
+				'noheader'   => true,
113
+				'args'       => array('nuke_old_ee4_data' => false),
114
+			),
115
+			'delete_db'                           => array(
116
+				'func'       => '_delete_db',
117
+				'capability' => 'manage_options',
118
+				'noheader'   => true,
119
+			),
120
+			'rerun_migration_from_ee3'            => array(
121
+				'func'       => '_rerun_migration_from_ee3',
122
+				'capability' => 'manage_options',
123
+				'noheader'   => true,
124
+			),
125
+			'reset_reservations'                  => array(
126
+				'func'       => '_reset_reservations',
127
+				'capability' => 'manage_options',
128
+				'noheader'   => true,
129
+			),
130
+			'reset_capabilities'                  => array(
131
+				'func'       => '_reset_capabilities',
132
+				'capability' => 'manage_options',
133
+				'noheader'   => true,
134
+			),
135
+			'reattempt_migration'                 => array(
136
+				'func'       => '_reattempt_migration',
137
+				'capability' => 'manage_options',
138
+				'noheader'   => true,
139
+			),
140
+			'datetime_tools' => array(
141
+				'func' => '_datetime_tools',
142
+				'capability' => 'manage_options'
143
+			),
144
+			'run_datetime_offset_fix' => array(
145
+				'func' => '_apply_datetime_offset',
146
+				'noheader' => true,
147
+				'headers_sent_route' => 'datetime_tools',
148
+				'capability' => 'manage_options'
149
+			)
150
+		);
151
+	}
152
+
153
+
154
+
155
+	protected function _set_page_config()
156
+	{
157
+		$this->_page_config = array(
158
+			'default'       => array(
159
+				'nav'           => array(
160
+					'label' => esc_html__('Maintenance', 'event_espresso'),
161
+					'order' => 10,
162
+				),
163
+				'require_nonce' => false,
164
+			),
165
+			'data_reset'    => array(
166
+				'nav'           => array(
167
+					'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
168
+					'order' => 20,
169
+				),
170
+				'require_nonce' => false,
171
+			),
172
+			'datetime_tools' => array(
173
+				'nav' => array(
174
+					'label' => esc_html__('Datetime Utilities', 'event_espresso'),
175
+					'order' => 25
176
+				),
177
+				'require_nonce' => false,
178
+			),
179
+			'system_status' => array(
180
+				'nav'           => array(
181
+					'label' => esc_html__("System Information", "event_espresso"),
182
+					'order' => 30,
183
+				),
184
+				'require_nonce' => false,
185
+			),
186
+		);
187
+	}
188
+
189
+
190
+
191
+	/**
192
+	 * default maintenance page. If we're in maintenance mode level 2, then we need to show
193
+	 * the migration scripts and all that UI.
194
+	 */
195
+	public function _maintenance()
196
+	{
197
+		//it all depends if we're in maintenance model level 1 (frontend-only) or
198
+		//level 2 (everything except maintenance page)
199
+		try {
200
+			//get the current maintenance level and check if
201
+			//we are removed
202
+			$mm = EE_Maintenance_Mode::instance()->level();
203
+			$placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
204
+			if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
205
+				//we just took the site out of maintenance mode, so notify the user.
206
+				//unfortunately this message appears to be echoed on the NEXT page load...
207
+				//oh well, we should really be checking for this on addon deactivation anyways
208
+				EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required',
209
+					'event_espresso'));
210
+				$this->_process_notices(array('page' => 'espresso_maintenance_settings'), false);
211
+			}
212
+			//in case an exception is thrown while trying to handle migrations
213
+			switch (EE_Maintenance_Mode::instance()->level()) {
214
+				case EE_Maintenance_Mode::level_0_not_in_maintenance:
215
+				case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
216
+					$show_maintenance_switch = true;
217
+					$show_backup_db_text = false;
218
+					$show_migration_progress = false;
219
+					$script_names = array();
220
+					$addons_should_be_upgraded_first = false;
221
+					break;
222
+				case EE_Maintenance_Mode::level_2_complete_maintenance:
223
+					$show_maintenance_switch = false;
224
+					$show_migration_progress = true;
225
+					if (isset($this->_req_data['continue_migration'])) {
226
+						$show_backup_db_text = false;
227
+					} else {
228
+						$show_backup_db_text = true;
229
+					}
230
+					$scripts_needing_to_run = EE_Data_Migration_Manager::instance()
231
+																	   ->check_for_applicable_data_migration_scripts();
232
+					$addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating();
233
+					$script_names = array();
234
+					$current_script = null;
235
+					foreach ($scripts_needing_to_run as $script) {
236
+						if ($script instanceof EE_Data_Migration_Script_Base) {
237
+							if ( ! $current_script) {
238
+								$current_script = $script;
239
+								$current_script->migration_page_hooks();
240
+							}
241
+							$script_names[] = $script->pretty_name();
242
+						}
243
+					}
244
+					break;
245
+			}
246
+			$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
247
+			$exception_thrown = false;
248
+		} catch (EE_Error $e) {
249
+			EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
250
+			//now, just so we can display the page correctly, make a error migration script stage object
251
+			//and also put the error on it. It only persists for the duration of this request
252
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
253
+			$most_recent_migration->add_error($e->getMessage());
254
+			$exception_thrown = true;
255
+		}
256
+		$current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set();
257
+		$current_db_state = str_replace('.decaf', '', $current_db_state);
258
+		if ($exception_thrown
259
+			|| ($most_recent_migration
260
+				&& $most_recent_migration instanceof EE_Data_Migration_Script_Base
261
+				&& $most_recent_migration->is_broken()
262
+			)
263
+		) {
264
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
265
+			$this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
266
+			$this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
267
+																						'success' => '0',
268
+			), EE_MAINTENANCE_ADMIN_URL);
269
+		} elseif ($addons_should_be_upgraded_first) {
270
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
271
+		} else {
272
+			if ($most_recent_migration
273
+				&& $most_recent_migration instanceof EE_Data_Migration_Script_Base
274
+				&& $most_recent_migration->can_continue()
275
+			) {
276
+				$show_backup_db_text = false;
277
+				$show_continue_current_migration_script = true;
278
+				$show_most_recent_migration = true;
279
+			} elseif (isset($this->_req_data['continue_migration'])) {
280
+				$show_most_recent_migration = true;
281
+				$show_continue_current_migration_script = false;
282
+			} else {
283
+				$show_most_recent_migration = false;
284
+				$show_continue_current_migration_script = false;
285
+			}
286
+			if (isset($current_script)) {
287
+				$migrates_to = $current_script->migrates_to_version();
288
+				$plugin_slug = $migrates_to['slug'];
289
+				$new_version = $migrates_to['version'];
290
+				$this->_template_args = array_merge($this->_template_args, array(
291
+					'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"),
292
+						isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug),
293
+					'next_db_state'    => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'),
294
+						$new_version, $plugin_slug) : null,
295
+				));
296
+			} else {
297
+				$this->_template_args['current_db_state'] = null;
298
+				$this->_template_args['next_db_state'] = null;
299
+			}
300
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
301
+			$this->_template_args = array_merge(
302
+				$this->_template_args,
303
+				array(
304
+					'show_most_recent_migration'             => $show_most_recent_migration,
305
+					//flag for showing the most recent migration's status and/or errors
306
+					'show_migration_progress'                => $show_migration_progress,
307
+					//flag for showing the option to run migrations and see their progress
308
+					'show_backup_db_text'                    => $show_backup_db_text,
309
+					//flag for showing text telling the user to backup their DB
310
+					'show_maintenance_switch'                => $show_maintenance_switch,
311
+					//flag for showing the option to change maintenance mode between levels 0 and 1
312
+					'script_names'                           => $script_names,
313
+					//array of names of scripts that have run
314
+					'show_continue_current_migration_script' => $show_continue_current_migration_script,
315
+					//flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
316
+					'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
317
+						EE_MAINTENANCE_ADMIN_URL),
318
+					'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
319
+						EE_MAINTENANCE_ADMIN_URL),
320
+					'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'),
321
+						EE_MAINTENANCE_ADMIN_URL),
322
+					'ultimate_db_state'                      => sprintf(__("EE%s", 'event_espresso'),
323
+						espresso_version()),
324
+				)
325
+			);
326
+			//make sure we have the form fields helper available. It usually is, but sometimes it isn't
327
+		}
328
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
329
+		//now render the migration options part, and put it in a variable
330
+		$migration_options_template_file = apply_filters(
331
+			'FHEE__ee_migration_page__migration_options_template',
332
+			EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
333
+		);
334
+		$migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
335
+		$this->_template_args['migration_options_html'] = $migration_options_html;
336
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
337
+			$this->_template_args, true);
338
+		$this->display_admin_page_with_sidebar();
339
+	}
340
+
341
+
342
+
343
+	/**
344
+	 * returns JSON and executes another step of the currently-executing data migration (called via ajax)
345
+	 */
346
+	public function migration_step()
347
+	{
348
+		$this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request();
349
+		$this->_return_json();
350
+	}
351
+
352
+
353
+
354
+	/**
355
+	 * Can be used by js when it notices a response with HTML in it in order
356
+	 * to log the malformed response
357
+	 */
358
+	public function add_error_to_migrations_ran()
359
+	{
360
+		EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']);
361
+		$this->_template_args['data'] = array('ok' => true);
362
+		$this->_return_json();
363
+	}
364
+
365
+
366
+
367
+	/**
368
+	 * changes the maintenance level, provided there are still no migration scripts that should run
369
+	 */
370
+	public function _change_maintenance_level()
371
+	{
372
+		$new_level = absint($this->_req_data['maintenance_mode_level']);
373
+		if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
374
+			EE_Maintenance_Mode::instance()->set_maintenance_level($new_level);
375
+			$success = true;
376
+		} else {
377
+			EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
378
+			$success = false;
379
+		}
380
+		$this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
381
+	}
382
+
383
+
384
+
385
+	/**
386
+	 * a tab with options for resetting and/or deleting EE data
387
+	 *
388
+	 * @throws \EE_Error
389
+	 * @throws \DomainException
390
+	 */
391
+	public function _data_reset_and_delete()
392
+	{
393
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
394
+		$this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
395
+			'reset_reservations',
396
+			'reset_reservations',
397
+			array(),
398
+			'button button-primary ee-confirm',
399
+			'',
400
+			false
401
+		);
402
+		$this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
403
+			'reset_capabilities',
404
+			'reset_capabilities',
405
+			array(),
406
+			'button button-primary ee-confirm',
407
+			'',
408
+			false
409
+		);
410
+		$this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
411
+			array('action' => 'delete_db'),
412
+			EE_MAINTENANCE_ADMIN_URL
413
+		);
414
+		$this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
415
+			array('action' => 'reset_db'),
416
+			EE_MAINTENANCE_ADMIN_URL
417
+		);
418
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
419
+			$this->_template_path,
420
+			$this->_template_args,
421
+			true
422
+		);
423
+		$this->display_admin_page_with_sidebar();
424
+	}
425
+
426
+
427
+
428
+	protected function _reset_reservations()
429
+	{
430
+		if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
431
+			EE_Error::add_success(
432
+				__(
433
+					'Ticket and datetime reserved counts have been successfully reset.',
434
+					'event_espresso'
435
+				)
436
+			);
437
+		} else {
438
+			EE_Error::add_success(
439
+				__(
440
+					'Ticket and datetime reserved counts were correct and did not need resetting.',
441
+					'event_espresso'
442
+				)
443
+			);
444
+		}
445
+		$this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true);
446
+	}
447
+
448
+
449
+
450
+	protected function _reset_capabilities()
451
+	{
452
+		EE_Registry::instance()->CAP->init_caps(true);
453
+		EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.',
454
+			'event_espresso'));
455
+		$this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true);
456
+	}
457
+
458
+
459
+
460
+	/**
461
+	 * resets the DMSs so we can attempt to continue migrating after a fatal error
462
+	 * (only a good idea when someone has somehow tried ot fix whatever caused
463
+	 * the fatal error in teh first place)
464
+	 */
465
+	protected function _reattempt_migration()
466
+	{
467
+		EE_Data_Migration_Manager::instance()->reattempt();
468
+		$this->_redirect_after_action(false, '', '', array('action' => 'default'), true);
469
+	}
470
+
471
+
472
+
473
+	/**
474
+	 * shows the big ol' System Information page
475
+	 */
476
+	public function _system_status()
477
+	{
478
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
479
+		$this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
480
+		$this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
481
+			array(
482
+				'action' => 'download_system_status',
483
+			),
484
+			EE_MAINTENANCE_ADMIN_URL
485
+		);
486
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
487
+			$this->_template_args, true);
488
+		$this->display_admin_page_with_sidebar();
489
+	}
490
+
491
+	/**
492
+	 * Downloads an HTML file of the system status that can be easily stored or emailed
493
+	 */
494
+	public function _download_system_status()
495
+	{
496
+		$status_info = EEM_System_Status::instance()->get_system_stati();
497
+		header( 'Content-Disposition: attachment' );
498
+		header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
499
+		echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
500
+		echo "<h1>System Information for " . site_url() . "</h1>";
501
+		echo EEH_Template::layout_array_as_table( $status_info );
502
+		die;
503
+	}
504
+
505
+
506
+
507
+	public function _send_migration_crash_report()
508
+	{
509
+		$from = $this->_req_data['from'];
510
+		$from_name = $this->_req_data['from_name'];
511
+		$body = $this->_req_data['body'];
512
+		try {
513
+			$success = wp_mail(EE_SUPPORT_EMAIL,
514
+				'Migration Crash Report',
515
+				$body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
516
+				array(
517
+					"from:$from_name<$from>",
518
+					//					'content-type:text/html charset=UTF-8'
519
+				));
520
+		} catch (Exception $e) {
521
+			$success = false;
522
+		}
523
+		$this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"),
524
+			esc_html__("sent", "event_espresso"),
525
+			array('success' => $success, 'action' => 'confirm_migration_crash_report_sent'));
526
+	}
527
+
528
+
529
+
530
+	public function _confirm_migration_crash_report_sent()
531
+	{
532
+		try {
533
+			$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
534
+		} catch (EE_Error $e) {
535
+			EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
536
+			//now, just so we can display the page correctly, make a error migration script stage object
537
+			//and also put the error on it. It only persists for the duration of this request
538
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
539
+			$most_recent_migration->add_error($e->getMessage());
540
+		}
541
+		$success = $this->_req_data['success'] == '1' ? true : false;
542
+		$this->_template_args['success'] = $success;
543
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;
544
+		$this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
545
+			EE_MAINTENANCE_ADMIN_URL);
546
+		$this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
547
+			EE_MAINTENANCE_ADMIN_URL);
548
+		$this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
549
+			EE_MAINTENANCE_ADMIN_URL);
550
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
551
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
552
+			$this->_template_args, true);
553
+		$this->display_admin_page_with_sidebar();
554
+	}
555
+
556
+
557
+
558
+	/**
559
+	 * Resets the entire EE4 database.
560
+	 * Currently basically only sets up ee4 database for a fresh install- doesn't
561
+	 * actually clean out the old wp options, or cpts (although does erase old ee table data)
562
+	 *
563
+	 * @param boolean $nuke_old_ee4_data controls whether or not we
564
+	 *                                   destroy the old ee4 data, or just try initializing ee4 default data
565
+	 */
566
+	public function _reset_db($nuke_old_ee4_data = true)
567
+	{
568
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
569
+		if ($nuke_old_ee4_data) {
570
+			EEH_Activation::delete_all_espresso_cpt_data();
571
+			EEH_Activation::delete_all_espresso_tables_and_data(false);
572
+			EEH_Activation::remove_cron_tasks();
573
+		}
574
+		//make sure when we reset the registry's config that it
575
+		//switches to using the new singleton
576
+		EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
577
+		EE_System::instance()->initialize_db_if_no_migrations_required(true);
578
+		EE_System::instance()->redirect_to_about_ee();
579
+	}
580
+
581
+
582
+
583
+	/**
584
+	 * Deletes ALL EE tables, Records, and Options from the database.
585
+	 */
586
+	public function _delete_db()
587
+	{
588
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
589
+		EEH_Activation::delete_all_espresso_cpt_data();
590
+		EEH_Activation::delete_all_espresso_tables_and_data();
591
+		EEH_Activation::remove_cron_tasks();
592
+		EEH_Activation::deactivate_event_espresso();
593
+		wp_safe_redirect(admin_url('plugins.php'));
594
+		exit;
595
+	}
596
+
597
+
598
+
599
+	/**
600
+	 * sets up EE4 to rerun the migrations from ee3 to ee4
601
+	 */
602
+	public function _rerun_migration_from_ee3()
603
+	{
604
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
605
+		EEH_Activation::delete_all_espresso_cpt_data();
606
+		EEH_Activation::delete_all_espresso_tables_and_data(false);
607
+		//set the db state to something that will require migrations
608
+		update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
609
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
610
+		$this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso'));
611
+	}
612
+
613
+
614
+
615
+	//none of the below group are currently used for Gateway Settings
616
+	protected function _add_screen_options()
617
+	{
618
+	}
619
+
620
+
621
+
622
+	protected function _add_feature_pointers()
623
+	{
624
+	}
625
+
626 626
 
627 627
 
628
-    public function admin_init()
629
-    {
630
-    }
631
-
632
-
633
-
634
-    public function admin_notices()
635
-    {
636
-    }
637
-
628
+	public function admin_init()
629
+	{
630
+	}
631
+
632
+
633
+
634
+	public function admin_notices()
635
+	{
636
+	}
637
+
638 638
 
639 639
 
640
-    public function admin_footer_scripts()
641
-    {
642
-    }
640
+	public function admin_footer_scripts()
641
+	{
642
+	}
643 643
 
644 644
 
645 645
 
646
-    public function load_scripts_styles()
647
-    {
648
-        wp_enqueue_script('ee_admin_js');
646
+	public function load_scripts_styles()
647
+	{
648
+		wp_enqueue_script('ee_admin_js');
649 649
 //		wp_enqueue_media();
650 650
 //		wp_enqueue_script('media-upload');
651
-        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.js', array('jquery'),
652
-            EVENT_ESPRESSO_VERSION, true);
653
-        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
654
-            EVENT_ESPRESSO_VERSION);
655
-        wp_enqueue_style('espresso_maintenance');
656
-        //localize script stuff
657
-        wp_localize_script('ee-maintenance', 'ee_maintenance', array(
658
-            'migrating'                        => esc_html__("Updating Database...", "event_espresso"),
659
-            'next'                             => esc_html__("Next", "event_espresso"),
660
-            'fatal_error'                      => esc_html__("A Fatal Error Has Occurred", "event_espresso"),
661
-            'click_next_when_ready'            => esc_html__(
662
-                "The current Database Update has ended. Click 'next' when ready to proceed",
663
-                "event_espresso"
664
-            ),
665
-            'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
666
-            'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
667
-            'status_completed'                 => EE_Data_Migration_Manager::status_completed,
668
-            'confirm'                          => esc_html__(
669
-                'Are you sure you want to do this? It CANNOT be undone!',
670
-                'event_espresso'
671
-            ),
672
-            'confirm_skip_migration' => esc_html__(
673
-                'You have chosen to NOT migrate your existing data. Are you sure you want to continue?',
674
-                'event_espresso'
675
-            )
676
-        ));
677
-    }
678
-
679
-
680
-
681
-    public function load_scripts_styles_default()
682
-    {
683
-        //styles
651
+		wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.js', array('jquery'),
652
+			EVENT_ESPRESSO_VERSION, true);
653
+		wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
654
+			EVENT_ESPRESSO_VERSION);
655
+		wp_enqueue_style('espresso_maintenance');
656
+		//localize script stuff
657
+		wp_localize_script('ee-maintenance', 'ee_maintenance', array(
658
+			'migrating'                        => esc_html__("Updating Database...", "event_espresso"),
659
+			'next'                             => esc_html__("Next", "event_espresso"),
660
+			'fatal_error'                      => esc_html__("A Fatal Error Has Occurred", "event_espresso"),
661
+			'click_next_when_ready'            => esc_html__(
662
+				"The current Database Update has ended. Click 'next' when ready to proceed",
663
+				"event_espresso"
664
+			),
665
+			'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
666
+			'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
667
+			'status_completed'                 => EE_Data_Migration_Manager::status_completed,
668
+			'confirm'                          => esc_html__(
669
+				'Are you sure you want to do this? It CANNOT be undone!',
670
+				'event_espresso'
671
+			),
672
+			'confirm_skip_migration' => esc_html__(
673
+				'You have chosen to NOT migrate your existing data. Are you sure you want to continue?',
674
+				'event_espresso'
675
+			)
676
+		));
677
+	}
678
+
679
+
680
+
681
+	public function load_scripts_styles_default()
682
+	{
683
+		//styles
684 684
 //		wp_enqueue_style('ee-text-links');
685 685
 //		//scripts
686 686
 //		wp_enqueue_script('ee-text-links');
687
-    }
688
-
689
-
690
-    protected function _datetime_tools()
691
-    {
692
-        $form_action = EE_Admin_Page::add_query_args_and_nonce(
693
-            array(
694
-                'action' => 'run_datetime_offset_fix',
695
-                'return_action' => $this->_req_action
696
-            ),
697
-            EE_MAINTENANCE_ADMIN_URL
698
-        );
699
-        $form = $this->_get_datetime_offset_fix_form();
700
-        $this->_admin_page_title = esc_html__('Datetime Utilities', 'event_espresso');
701
-        $this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post')
702
-                                                      . $form->get_html_and_js()
703
-                                                      . $form->form_close();
704
-        $this->display_admin_page_with_no_sidebar();
705
-    }
706
-
707
-
708
-
709
-    protected function _get_datetime_offset_fix_form()
710
-    {
711
-        if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
712
-            $this->datetime_fix_offset_form =  new EE_Form_Section_Proper(
713
-                array(
714
-                    'name' => 'datetime_offset_fix_option',
715
-                    'layout_strategy' => new EE_Admin_Two_Column_Layout(),
716
-                    'subsections' => array(
717
-                        'title' => new EE_Form_Section_HTML(
718
-                            EEH_HTML::h2(
719
-                                esc_html__('Datetime Offset Tool', 'event_espresso')
720
-                            )
721
-                        ),
722
-                        'explanation' => new EE_Form_Section_HTML(
723
-                            EEH_HTML::p(
724
-                                esc_html__(
725
-                                    'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.',
726
-                                    'event_espresso'
727
-                                )
728
-                            )
729
-                            . EEH_HTML::p(
730
-                                esc_html__(
731
-                                    'Note: If you enter 1.25, that will result in the offset of 1 hour 15 minutes being applied.  Decimals represent the fraction of hours, not minutes.',
732
-                                    'event_espresso'
733
-                                )
734
-                            )
735
-                        ),
736
-                        'offset_input' => new EE_Float_Input(
737
-                            array(
738
-                                'html_name' => 'offset_for_datetimes',
739
-                                'html_label_text' => esc_html__(
740
-                                    'Offset to apply (in hours):',
741
-                                    'event_espresso'
742
-                                ),
743
-                                'min_value' => '-12',
744
-                                'max_value' => '14',
745
-                                'step_value' => '.25',
746
-                                'default' => DatetimeOffsetFix::getOffset()
747
-                            )
748
-                        ),
749
-                        'submit' => new EE_Submit_Input(
750
-                            array(
751
-                                'html_label_text' => '',
752
-                                'default' => esc_html__('Apply Offset', 'event_espresso')
753
-                            )
754
-                        )
755
-                    )
756
-                )
757
-            );
758
-        }
759
-        return $this->datetime_fix_offset_form;
760
-    }
761
-
762
-
763
-    /**
764
-     * Callback for the run_datetime_offset_fix route.
765
-     * @throws EE_Error
766
-     */
767
-    protected function _apply_datetime_offset()
768
-    {
769
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
770
-            $form = $this->_get_datetime_offset_fix_form();
771
-            $form->receive_form_submission($this->_req_data);
772
-            if ($form->is_valid()) {
773
-                //save offset so batch processor can get it.
774
-                DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input'));
775
-                //redirect to batch tool
776
-                wp_redirect(
777
-                    EE_Admin_Page::add_query_args_and_nonce(
778
-                        array(
779
-                            'page' => 'espresso_batch',
780
-                            'batch' => 'job',
781
-                            'label' => esc_html__('Applying Offset', 'event_espresso'),
782
-                            'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'),
783
-                            'return_url' => urlencode(home_url(add_query_arg(null, null))),
784
-                        ),
785
-                        admin_url()
786
-                    )
787
-                );
788
-                exit;
789
-            }
790
-        }
791
-    }
687
+	}
688
+
689
+
690
+	protected function _datetime_tools()
691
+	{
692
+		$form_action = EE_Admin_Page::add_query_args_and_nonce(
693
+			array(
694
+				'action' => 'run_datetime_offset_fix',
695
+				'return_action' => $this->_req_action
696
+			),
697
+			EE_MAINTENANCE_ADMIN_URL
698
+		);
699
+		$form = $this->_get_datetime_offset_fix_form();
700
+		$this->_admin_page_title = esc_html__('Datetime Utilities', 'event_espresso');
701
+		$this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post')
702
+													  . $form->get_html_and_js()
703
+													  . $form->form_close();
704
+		$this->display_admin_page_with_no_sidebar();
705
+	}
706
+
707
+
708
+
709
+	protected function _get_datetime_offset_fix_form()
710
+	{
711
+		if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
712
+			$this->datetime_fix_offset_form =  new EE_Form_Section_Proper(
713
+				array(
714
+					'name' => 'datetime_offset_fix_option',
715
+					'layout_strategy' => new EE_Admin_Two_Column_Layout(),
716
+					'subsections' => array(
717
+						'title' => new EE_Form_Section_HTML(
718
+							EEH_HTML::h2(
719
+								esc_html__('Datetime Offset Tool', 'event_espresso')
720
+							)
721
+						),
722
+						'explanation' => new EE_Form_Section_HTML(
723
+							EEH_HTML::p(
724
+								esc_html__(
725
+									'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.',
726
+									'event_espresso'
727
+								)
728
+							)
729
+							. EEH_HTML::p(
730
+								esc_html__(
731
+									'Note: If you enter 1.25, that will result in the offset of 1 hour 15 minutes being applied.  Decimals represent the fraction of hours, not minutes.',
732
+									'event_espresso'
733
+								)
734
+							)
735
+						),
736
+						'offset_input' => new EE_Float_Input(
737
+							array(
738
+								'html_name' => 'offset_for_datetimes',
739
+								'html_label_text' => esc_html__(
740
+									'Offset to apply (in hours):',
741
+									'event_espresso'
742
+								),
743
+								'min_value' => '-12',
744
+								'max_value' => '14',
745
+								'step_value' => '.25',
746
+								'default' => DatetimeOffsetFix::getOffset()
747
+							)
748
+						),
749
+						'submit' => new EE_Submit_Input(
750
+							array(
751
+								'html_label_text' => '',
752
+								'default' => esc_html__('Apply Offset', 'event_espresso')
753
+							)
754
+						)
755
+					)
756
+				)
757
+			);
758
+		}
759
+		return $this->datetime_fix_offset_form;
760
+	}
761
+
762
+
763
+	/**
764
+	 * Callback for the run_datetime_offset_fix route.
765
+	 * @throws EE_Error
766
+	 */
767
+	protected function _apply_datetime_offset()
768
+	{
769
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
770
+			$form = $this->_get_datetime_offset_fix_form();
771
+			$form->receive_form_submission($this->_req_data);
772
+			if ($form->is_valid()) {
773
+				//save offset so batch processor can get it.
774
+				DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input'));
775
+				//redirect to batch tool
776
+				wp_redirect(
777
+					EE_Admin_Page::add_query_args_and_nonce(
778
+						array(
779
+							'page' => 'espresso_batch',
780
+							'batch' => 'job',
781
+							'label' => esc_html__('Applying Offset', 'event_espresso'),
782
+							'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'),
783
+							'return_url' => urlencode(home_url(add_query_arg(null, null))),
784
+						),
785
+						admin_url()
786
+					)
787
+				);
788
+				exit;
789
+			}
790
+		}
791
+	}
792 792
 } //end Maintenance_Admin_Page class
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -261,13 +261,13 @@  discard block
 block discarded – undo
261 261
                 && $most_recent_migration->is_broken()
262 262
             )
263 263
         ) {
264
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
264
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_was_borked_page.template.php';
265 265
             $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
266 266
             $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
267 267
                                                                                         'success' => '0',
268 268
             ), EE_MAINTENANCE_ADMIN_URL);
269 269
         } elseif ($addons_should_be_upgraded_first) {
270
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
270
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_upgrade_addons_before_migrating.template.php';
271 271
         } else {
272 272
             if ($most_recent_migration
273 273
                 && $most_recent_migration instanceof EE_Data_Migration_Script_Base
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
                 $this->_template_args['current_db_state'] = null;
298 298
                 $this->_template_args['next_db_state'] = null;
299 299
             }
300
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
300
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_page.template.php';
301 301
             $this->_template_args = array_merge(
302 302
                 $this->_template_args,
303 303
                 array(
@@ -325,13 +325,13 @@  discard block
 block discarded – undo
325 325
             );
326 326
             //make sure we have the form fields helper available. It usually is, but sometimes it isn't
327 327
         }
328
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
328
+        $this->_template_args['most_recent_migration'] = $most_recent_migration; //the actual most recently ran migration
329 329
         //now render the migration options part, and put it in a variable
330 330
         $migration_options_template_file = apply_filters(
331 331
             'FHEE__ee_migration_page__migration_options_template',
332
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
332
+            EE_MAINTENANCE_TEMPLATE_PATH.'migration_options_from_ee4.template.php'
333 333
         );
334
-        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
334
+        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args, true);
335 335
         $this->_template_args['migration_options_html'] = $migration_options_html;
336 336
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
337 337
             $this->_template_args, true);
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
      */
391 391
     public function _data_reset_and_delete()
392 392
     {
393
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
393
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_data_reset_and_delete.template.php';
394 394
         $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
395 395
             'reset_reservations',
396 396
             'reset_reservations',
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
 
428 428
     protected function _reset_reservations()
429 429
     {
430
-        if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
430
+        if (\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
431 431
             EE_Error::add_success(
432 432
                 __(
433 433
                     'Ticket and datetime reserved counts have been successfully reset.',
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
      */
476 476
     public function _system_status()
477 477
     {
478
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
478
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_system_stati_page.template.php';
479 479
         $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
480 480
         $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
481 481
             array(
@@ -494,11 +494,11 @@  discard block
 block discarded – undo
494 494
     public function _download_system_status()
495 495
     {
496 496
         $status_info = EEM_System_Status::instance()->get_system_stati();
497
-        header( 'Content-Disposition: attachment' );
498
-        header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
497
+        header('Content-Disposition: attachment');
498
+        header("Content-Disposition: attachment; filename=system_status_".sanitize_key(site_url()).".html");
499 499
         echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
500
-        echo "<h1>System Information for " . site_url() . "</h1>";
501
-        echo EEH_Template::layout_array_as_table( $status_info );
500
+        echo "<h1>System Information for ".site_url()."</h1>";
501
+        echo EEH_Template::layout_array_as_table($status_info);
502 502
         die;
503 503
     }
504 504
 
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
         try {
513 513
             $success = wp_mail(EE_SUPPORT_EMAIL,
514 514
                 'Migration Crash Report',
515
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
515
+                $body."/r/n<br>".print_r(EEM_System_Status::instance()->get_system_stati(), true),
516 516
                 array(
517 517
                     "from:$from_name<$from>",
518 518
                     //					'content-type:text/html charset=UTF-8'
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
             EE_MAINTENANCE_ADMIN_URL);
548 548
         $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
549 549
             EE_MAINTENANCE_ADMIN_URL);
550
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
550
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_confirm_migration_crash_report_sent.template.php';
551 551
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
552 552
             $this->_template_args, true);
553 553
         $this->display_admin_page_with_sidebar();
@@ -648,9 +648,9 @@  discard block
 block discarded – undo
648 648
         wp_enqueue_script('ee_admin_js');
649 649
 //		wp_enqueue_media();
650 650
 //		wp_enqueue_script('media-upload');
651
-        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.js', array('jquery'),
651
+        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL.'ee-maintenance.js', array('jquery'),
652 652
             EVENT_ESPRESSO_VERSION, true);
653
-        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
653
+        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL.'ee-maintenance.css', array(),
654 654
             EVENT_ESPRESSO_VERSION);
655 655
         wp_enqueue_style('espresso_maintenance');
656 656
         //localize script stuff
@@ -708,8 +708,8 @@  discard block
 block discarded – undo
708 708
 
709 709
     protected function _get_datetime_offset_fix_form()
710 710
     {
711
-        if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
712
-            $this->datetime_fix_offset_form =  new EE_Form_Section_Proper(
711
+        if ( ! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
712
+            $this->datetime_fix_offset_form = new EE_Form_Section_Proper(
713 713
                 array(
714 714
                     'name' => 'datetime_offset_fix_option',
715 715
                     'layout_strategy' => new EE_Admin_Two_Column_Layout(),
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -38,217 +38,217 @@
 block discarded – undo
38 38
  * @since       4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 
64 64
 } else {
65
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
-        /**
68
-         * espresso_minimum_php_version_error
69
-         *
70
-         * @return void
71
-         */
72
-        function espresso_minimum_php_version_error()
73
-        {
74
-            ?>
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
+		/**
68
+		 * espresso_minimum_php_version_error
69
+		 *
70
+		 * @return void
71
+		 */
72
+		function espresso_minimum_php_version_error()
73
+		{
74
+			?>
75 75
             <div class="error">
76 76
                 <p>
77 77
                     <?php
78
-                    printf(
79
-                        esc_html__(
80
-                            '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.',
81
-                            'event_espresso'
82
-                        ),
83
-                        EE_MIN_PHP_VER_REQUIRED,
84
-                        PHP_VERSION,
85
-                        '<br/>',
86
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
-                    );
88
-                    ?>
78
+					printf(
79
+						esc_html__(
80
+							'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.',
81
+							'event_espresso'
82
+						),
83
+						EE_MIN_PHP_VER_REQUIRED,
84
+						PHP_VERSION,
85
+						'<br/>',
86
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
+					);
88
+					?>
89 89
                 </p>
90 90
             </div>
91 91
             <?php
92
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
93
-        }
92
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
93
+		}
94 94
 
95
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
-    } else {
97
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
-        /**
99
-         * espresso_version
100
-         * Returns the plugin version
101
-         *
102
-         * @return string
103
-         */
104
-        function espresso_version()
105
-        {
106
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.50.rc.008');
107
-        }
95
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
+	} else {
97
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
+		/**
99
+		 * espresso_version
100
+		 * Returns the plugin version
101
+		 *
102
+		 * @return string
103
+		 */
104
+		function espresso_version()
105
+		{
106
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.50.rc.008');
107
+		}
108 108
 
109
-        /**
110
-         * espresso_plugin_activation
111
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
-         */
113
-        function espresso_plugin_activation()
114
-        {
115
-            update_option('ee_espresso_activation', true);
116
-        }
109
+		/**
110
+		 * espresso_plugin_activation
111
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
+		 */
113
+		function espresso_plugin_activation()
114
+		{
115
+			update_option('ee_espresso_activation', true);
116
+		}
117 117
 
118
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
-        /**
120
-         *    espresso_load_error_handling
121
-         *    this function loads EE's class for handling exceptions and errors
122
-         */
123
-        function espresso_load_error_handling()
124
-        {
125
-            static $error_handling_loaded = false;
126
-            if ($error_handling_loaded) {
127
-                return;
128
-            }
129
-            // load debugging tools
130
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
-                require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
132
-                \EEH_Debug_Tools::instance();
133
-            }
134
-            // load error handling
135
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
-                require_once EE_CORE . 'EE_Error.core.php';
137
-            } else {
138
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
-            }
140
-            $error_handling_loaded = true;
141
-        }
118
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
+		/**
120
+		 *    espresso_load_error_handling
121
+		 *    this function loads EE's class for handling exceptions and errors
122
+		 */
123
+		function espresso_load_error_handling()
124
+		{
125
+			static $error_handling_loaded = false;
126
+			if ($error_handling_loaded) {
127
+				return;
128
+			}
129
+			// load debugging tools
130
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
+				require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
132
+				\EEH_Debug_Tools::instance();
133
+			}
134
+			// load error handling
135
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
+				require_once EE_CORE . 'EE_Error.core.php';
137
+			} else {
138
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
+			}
140
+			$error_handling_loaded = true;
141
+		}
142 142
 
143
-        /**
144
-         *    espresso_load_required
145
-         *    given a class name and path, this function will load that file or throw an exception
146
-         *
147
-         * @param    string $classname
148
-         * @param    string $full_path_to_file
149
-         * @throws    EE_Error
150
-         */
151
-        function espresso_load_required($classname, $full_path_to_file)
152
-        {
153
-            if (is_readable($full_path_to_file)) {
154
-                require_once $full_path_to_file;
155
-            } else {
156
-                throw new \EE_Error (
157
-                    sprintf(
158
-                        esc_html__(
159
-                            'The %s class file could not be located or is not readable due to file permissions.',
160
-                            'event_espresso'
161
-                        ),
162
-                        $classname
163
-                    )
164
-                );
165
-            }
166
-        }
143
+		/**
144
+		 *    espresso_load_required
145
+		 *    given a class name and path, this function will load that file or throw an exception
146
+		 *
147
+		 * @param    string $classname
148
+		 * @param    string $full_path_to_file
149
+		 * @throws    EE_Error
150
+		 */
151
+		function espresso_load_required($classname, $full_path_to_file)
152
+		{
153
+			if (is_readable($full_path_to_file)) {
154
+				require_once $full_path_to_file;
155
+			} else {
156
+				throw new \EE_Error (
157
+					sprintf(
158
+						esc_html__(
159
+							'The %s class file could not be located or is not readable due to file permissions.',
160
+							'event_espresso'
161
+						),
162
+						$classname
163
+					)
164
+				);
165
+			}
166
+		}
167 167
 
168
-        /**
169
-         * @since 4.9.27
170
-         * @throws \EE_Error
171
-         * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
-         * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
-         * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
-         * @throws \EventEspresso\core\exceptions\InvalidClassException
175
-         * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
-         * @throws \OutOfBoundsException
179
-         */
180
-        function bootstrap_espresso()
181
-        {
182
-            require_once __DIR__ . '/core/espresso_definitions.php';
183
-            try {
184
-                espresso_load_error_handling();
185
-                espresso_load_required(
186
-                    'EEH_Base',
187
-                    EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
-                );
189
-                espresso_load_required(
190
-                    'EEH_File',
191
-                    EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
-                );
193
-                espresso_load_required(
194
-                    'EEH_File',
195
-                    EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
-                );
197
-                espresso_load_required(
198
-                    'EEH_Array',
199
-                    EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
-                );
201
-                // instantiate and configure PSR4 autoloader
202
-                espresso_load_required(
203
-                    'Psr4Autoloader',
204
-                    EE_CORE . 'Psr4Autoloader.php'
205
-                );
206
-                espresso_load_required(
207
-                    'EE_Psr4AutoloaderInit',
208
-                    EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
-                );
210
-                $AutoloaderInit = new EE_Psr4AutoloaderInit();
211
-                $AutoloaderInit->initializeAutoloader();
212
-                espresso_load_required(
213
-                    'EE_Request',
214
-                    EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
-                );
216
-                espresso_load_required(
217
-                    'EE_Response',
218
-                    EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
-                );
220
-                espresso_load_required(
221
-                    'EE_Bootstrap',
222
-                    EE_CORE . 'EE_Bootstrap.core.php'
223
-                );
224
-                // bootstrap EE and the request stack
225
-                new EE_Bootstrap(
226
-                    new EE_Request($_GET, $_POST, $_COOKIE),
227
-                    new EE_Response()
228
-                );
229
-            } catch (Exception $e) {
230
-                require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
231
-                new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
-            }
233
-        }
234
-        bootstrap_espresso();
235
-    }
168
+		/**
169
+		 * @since 4.9.27
170
+		 * @throws \EE_Error
171
+		 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
+		 * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
+		 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
+		 * @throws \EventEspresso\core\exceptions\InvalidClassException
175
+		 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
+		 * @throws \OutOfBoundsException
179
+		 */
180
+		function bootstrap_espresso()
181
+		{
182
+			require_once __DIR__ . '/core/espresso_definitions.php';
183
+			try {
184
+				espresso_load_error_handling();
185
+				espresso_load_required(
186
+					'EEH_Base',
187
+					EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
+				);
189
+				espresso_load_required(
190
+					'EEH_File',
191
+					EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
+				);
193
+				espresso_load_required(
194
+					'EEH_File',
195
+					EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
+				);
197
+				espresso_load_required(
198
+					'EEH_Array',
199
+					EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
+				);
201
+				// instantiate and configure PSR4 autoloader
202
+				espresso_load_required(
203
+					'Psr4Autoloader',
204
+					EE_CORE . 'Psr4Autoloader.php'
205
+				);
206
+				espresso_load_required(
207
+					'EE_Psr4AutoloaderInit',
208
+					EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
+				);
210
+				$AutoloaderInit = new EE_Psr4AutoloaderInit();
211
+				$AutoloaderInit->initializeAutoloader();
212
+				espresso_load_required(
213
+					'EE_Request',
214
+					EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
+				);
216
+				espresso_load_required(
217
+					'EE_Response',
218
+					EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
+				);
220
+				espresso_load_required(
221
+					'EE_Bootstrap',
222
+					EE_CORE . 'EE_Bootstrap.core.php'
223
+				);
224
+				// bootstrap EE and the request stack
225
+				new EE_Bootstrap(
226
+					new EE_Request($_GET, $_POST, $_COOKIE),
227
+					new EE_Response()
228
+				);
229
+			} catch (Exception $e) {
230
+				require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
231
+				new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
+			}
233
+		}
234
+		bootstrap_espresso();
235
+	}
236 236
 }
237 237
 if (! function_exists('espresso_deactivate_plugin')) {
238
-    /**
239
-     *    deactivate_plugin
240
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
-     *
242
-     * @access public
243
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
-     * @return    void
245
-     */
246
-    function espresso_deactivate_plugin($plugin_basename = '')
247
-    {
248
-        if (! function_exists('deactivate_plugins')) {
249
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
250
-        }
251
-        unset($_GET['activate'], $_REQUEST['activate']);
252
-        deactivate_plugins($plugin_basename);
253
-    }
238
+	/**
239
+	 *    deactivate_plugin
240
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
+	 *
242
+	 * @access public
243
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
+	 * @return    void
245
+	 */
246
+	function espresso_deactivate_plugin($plugin_basename = '')
247
+	{
248
+		if (! function_exists('deactivate_plugins')) {
249
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
250
+		}
251
+		unset($_GET['activate'], $_REQUEST['activate']);
252
+		deactivate_plugins($plugin_basename);
253
+	}
254 254
 }
Please login to merge, or discard this patch.