Completed
Branch models-cleanup/main (c8075d)
by
unknown
185:05 queued 175:13
created
core/domain/services/capabilities/PublicCapabilities.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -20,13 +20,13 @@
 block discarded – undo
20 20
 {
21 21
 
22 22
 
23
-    /**
24
-     * @return string
25
-     */
26
-    public function capability()
27
-    {
28
-        return '';
29
-    }
23
+	/**
24
+	 * @return string
25
+	 */
26
+	public function capability()
27
+	{
28
+		return '';
29
+	}
30 30
 
31 31
 
32 32
 }
Please login to merge, or discard this patch.
modules/gateways/Invoice/lib/invoice_functions.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -8,9 +8,9 @@  discard block
 block discarded – undo
8 8
  * @param $class_file
9 9
  * @return array
10 10
  */
11
-function espresso_invoice_template_files( $class_file) {
11
+function espresso_invoice_template_files($class_file) {
12 12
 	// read our template dir and build an array of files
13
-	$dhandle = opendir(dirname($class_file) . '/lib/templates/css/'); //If the template files have been moved to the uploads folder
13
+	$dhandle = opendir(dirname($class_file).'/lib/templates/css/'); //If the template files have been moved to the uploads folder
14 14
 	//} else return FALSE;
15 15
 
16 16
 	$files = array();
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
  * @param string $selected
51 51
  * @return string
52 52
  */
53
-function espresso_invoice_is_selected( $input_item, $selected='') {
54
-	if ( $input_item === $selected ) {
53
+function espresso_invoice_is_selected($input_item, $selected = '') {
54
+	if ($input_item === $selected) {
55 55
 		return 'selected="selected"';
56 56
 	} else {
57 57
 		return '';
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/RegistrationsReport.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -418,7 +418,7 @@
 block discarded – undo
418 418
      * In this case, we delete the temporary file
419 419
      *
420 420
      * @param JobParameters $job_parameters
421
-     * @return boolean
421
+     * @return JobStepResponse
422 422
      */
423 423
     public function cleanup_job(JobParameters $job_parameters)
424 424
     {
Please login to merge, or discard this patch.
Indentation   +521 added lines, -521 removed lines patch added patch discarded remove patch
@@ -31,541 +31,541 @@
 block discarded – undo
31 31
  */
32 32
 class RegistrationsReport extends JobHandlerFile
33 33
 {
34
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
35
-    // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
36
-    /**
37
-     * Performs any necessary setup for starting the job. This is also a good
38
-     * place to setup the $job_arguments which will be used for subsequent HTTP requests
39
-     * when continue_job will be called
40
-     *
41
-     * @param JobParameters $job_parameters
42
-     * @throws BatchRequestException
43
-     * @return JobStepResponse
44
-     */
45
-    public function create_job(JobParameters $job_parameters)
46
-    {
47
-        $event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
48
-        if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
49
-            throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
50
-        }
51
-        $filepath = $this->create_file_from_job_with_name(
52
-            $job_parameters->job_id(),
53
-            $this->get_filename($event_id)
54
-        );
55
-        $job_parameters->add_extra_data('filepath', $filepath);
56
-        if ($job_parameters->request_datum('use_filters', false)) {
57
-            $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
58
-        } else {
59
-            $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
60
-                array(
61
-                    'OR'                 => array(
62
-                        // don't include registrations from failed or abandoned transactions...
63
-                        'Transaction.STS_ID' => array(
64
-                            'NOT IN',
65
-                            array(
66
-                                EEM_Transaction::failed_status_code,
67
-                                EEM_Transaction::abandoned_status_code,
68
-                            ),
69
-                        ),
70
-                        // unless the registration is approved, in which case include it regardless of transaction status
71
-                        'STS_ID'             => \EEM_Registration::status_id_approved,
72
-                    ),
73
-                    'Ticket.TKT_deleted' => array('IN', array(true, false)),
74
-                ),
75
-                'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
76
-                'force_join' => array('Transaction', 'Ticket', 'Attendee'),
77
-                'caps'       => \EEM_Base::caps_read_admin,
78
-            ), $event_id);
79
-            if ($event_id) {
80
-                $query_params[0]['EVT_ID'] = $event_id;
81
-            } else {
82
-                $query_params['force_join'][] = 'Event';
83
-            }
84
-        }
85
-        if (! isset($query_params['force_join'])) {
86
-            $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
87
-        }
88
-        $job_parameters->add_extra_data('query_params', $query_params);
89
-        $question_labels = $this->_get_question_labels($query_params);
90
-        $job_parameters->add_extra_data('question_labels', $question_labels);
91
-        $job_parameters->set_job_size(
92
-            \EEM_Registration::instance()->count(
93
-                array_diff_key(
94
-                    $query_params,
95
-                    array_flip(
96
-                        array('limit')
97
-                    )
98
-                )
99
-            )
100
-        );
101
-        // we should also set the header columns
102
-        $csv_data_for_row = $this->get_csv_data_for(
103
-            $event_id,
104
-            0,
105
-            1,
106
-            $job_parameters->extra_datum('question_labels'),
107
-            $job_parameters->extra_datum('query_params')
108
-        );
109
-        EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
110
-        // if we actually processed a row there, record it
111
-        if ($job_parameters->job_size()) {
112
-            $job_parameters->mark_processed(1);
113
-        }
114
-        return new JobStepResponse(
115
-            $job_parameters,
116
-            __('Registrations report started successfully...', 'event_espresso')
117
-        );
118
-    }
34
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
35
+	// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
36
+	/**
37
+	 * Performs any necessary setup for starting the job. This is also a good
38
+	 * place to setup the $job_arguments which will be used for subsequent HTTP requests
39
+	 * when continue_job will be called
40
+	 *
41
+	 * @param JobParameters $job_parameters
42
+	 * @throws BatchRequestException
43
+	 * @return JobStepResponse
44
+	 */
45
+	public function create_job(JobParameters $job_parameters)
46
+	{
47
+		$event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
48
+		if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
49
+			throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
50
+		}
51
+		$filepath = $this->create_file_from_job_with_name(
52
+			$job_parameters->job_id(),
53
+			$this->get_filename($event_id)
54
+		);
55
+		$job_parameters->add_extra_data('filepath', $filepath);
56
+		if ($job_parameters->request_datum('use_filters', false)) {
57
+			$query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
58
+		} else {
59
+			$query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
60
+				array(
61
+					'OR'                 => array(
62
+						// don't include registrations from failed or abandoned transactions...
63
+						'Transaction.STS_ID' => array(
64
+							'NOT IN',
65
+							array(
66
+								EEM_Transaction::failed_status_code,
67
+								EEM_Transaction::abandoned_status_code,
68
+							),
69
+						),
70
+						// unless the registration is approved, in which case include it regardless of transaction status
71
+						'STS_ID'             => \EEM_Registration::status_id_approved,
72
+					),
73
+					'Ticket.TKT_deleted' => array('IN', array(true, false)),
74
+				),
75
+				'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
76
+				'force_join' => array('Transaction', 'Ticket', 'Attendee'),
77
+				'caps'       => \EEM_Base::caps_read_admin,
78
+			), $event_id);
79
+			if ($event_id) {
80
+				$query_params[0]['EVT_ID'] = $event_id;
81
+			} else {
82
+				$query_params['force_join'][] = 'Event';
83
+			}
84
+		}
85
+		if (! isset($query_params['force_join'])) {
86
+			$query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
87
+		}
88
+		$job_parameters->add_extra_data('query_params', $query_params);
89
+		$question_labels = $this->_get_question_labels($query_params);
90
+		$job_parameters->add_extra_data('question_labels', $question_labels);
91
+		$job_parameters->set_job_size(
92
+			\EEM_Registration::instance()->count(
93
+				array_diff_key(
94
+					$query_params,
95
+					array_flip(
96
+						array('limit')
97
+					)
98
+				)
99
+			)
100
+		);
101
+		// we should also set the header columns
102
+		$csv_data_for_row = $this->get_csv_data_for(
103
+			$event_id,
104
+			0,
105
+			1,
106
+			$job_parameters->extra_datum('question_labels'),
107
+			$job_parameters->extra_datum('query_params')
108
+		);
109
+		EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
110
+		// if we actually processed a row there, record it
111
+		if ($job_parameters->job_size()) {
112
+			$job_parameters->mark_processed(1);
113
+		}
114
+		return new JobStepResponse(
115
+			$job_parameters,
116
+			__('Registrations report started successfully...', 'event_espresso')
117
+		);
118
+	}
119 119
 
120 120
 
121
-    /**
122
-     * Gets the filename
123
-     *
124
-     * @return string
125
-     */
126
-    protected function get_filename()
127
-    {
128
-        return apply_filters(
129
-            'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename',
130
-            sprintf(
131
-                "event-espresso-registrations-%s.csv",
132
-                str_replace(array(':', ' '), '-', current_time('mysql'))
133
-            )
134
-        );
135
-    }
121
+	/**
122
+	 * Gets the filename
123
+	 *
124
+	 * @return string
125
+	 */
126
+	protected function get_filename()
127
+	{
128
+		return apply_filters(
129
+			'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename',
130
+			sprintf(
131
+				"event-espresso-registrations-%s.csv",
132
+				str_replace(array(':', ' '), '-', current_time('mysql'))
133
+			)
134
+		);
135
+	}
136 136
 
137 137
 
138
-    /**
139
-     * Gets the questions which are to be used for this report, so they
140
-     * can be remembered for later
141
-     *
142
-     * @param array $registration_query_params
143
-     * @return array question admin labels to be used for this report
144
-     */
145
-    protected function _get_question_labels($registration_query_params)
146
-    {
147
-        $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
148
-        $question_query_params = array();
149
-        if ($where !== null) {
150
-            $question_query_params = array(
151
-                $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
152
-            );
153
-        }
154
-        // Make sure it's not a system question
155
-        $question_query_params[0]['OR*not-system-questions'] = [
156
-            'QST_system' => '',
157
-            'QST_system*null' => ['IS_NULL']
158
-        ];
159
-        if (
160
-            apply_filters(
161
-                'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
162
-                false,
163
-                $registration_query_params
164
-            )
165
-        ) {
166
-            $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
167
-        }
168
-        $question_query_params['group_by'] = array('QST_ID');
169
-        return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
170
-    }
138
+	/**
139
+	 * Gets the questions which are to be used for this report, so they
140
+	 * can be remembered for later
141
+	 *
142
+	 * @param array $registration_query_params
143
+	 * @return array question admin labels to be used for this report
144
+	 */
145
+	protected function _get_question_labels($registration_query_params)
146
+	{
147
+		$where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
148
+		$question_query_params = array();
149
+		if ($where !== null) {
150
+			$question_query_params = array(
151
+				$this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
152
+			);
153
+		}
154
+		// Make sure it's not a system question
155
+		$question_query_params[0]['OR*not-system-questions'] = [
156
+			'QST_system' => '',
157
+			'QST_system*null' => ['IS_NULL']
158
+		];
159
+		if (
160
+			apply_filters(
161
+				'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
162
+				false,
163
+				$registration_query_params
164
+			)
165
+		) {
166
+			$question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
167
+		}
168
+		$question_query_params['group_by'] = array('QST_ID');
169
+		return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
170
+	}
171 171
 
172 172
 
173
-    /**
174
-     * Takes where params meant for registrations and changes them to work for questions
175
-     *
176
-     * @param array $reg_where_params
177
-     * @return array
178
-     */
179
-    protected function _change_registration_where_params_to_question_where_params($reg_where_params)
180
-    {
181
-        $question_where_params = array();
182
-        foreach ($reg_where_params as $key => $val) {
183
-            if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
184
-                $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
185
-            } else {
186
-                // it's a normal where condition
187
-                $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
188
-            }
189
-        }
190
-        return $question_where_params;
191
-    }
173
+	/**
174
+	 * Takes where params meant for registrations and changes them to work for questions
175
+	 *
176
+	 * @param array $reg_where_params
177
+	 * @return array
178
+	 */
179
+	protected function _change_registration_where_params_to_question_where_params($reg_where_params)
180
+	{
181
+		$question_where_params = array();
182
+		foreach ($reg_where_params as $key => $val) {
183
+			if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
184
+				$question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
185
+			} else {
186
+				// it's a normal where condition
187
+				$question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
188
+			}
189
+		}
190
+		return $question_where_params;
191
+	}
192 192
 
193 193
 
194
-    /**
195
-     * Performs another step of the job
196
-     *
197
-     * @param JobParameters $job_parameters
198
-     * @param int           $batch_size
199
-     * @return JobStepResponse
200
-     * @throws \EE_Error
201
-     */
202
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
203
-    {
204
-        if ($job_parameters->units_processed() < $job_parameters->job_size()) {
205
-            $csv_data = $this->get_csv_data_for(
206
-                $job_parameters->request_datum('EVT_ID', '0'),
207
-                $job_parameters->units_processed(),
208
-                $batch_size,
209
-                $job_parameters->extra_datum('question_labels'),
210
-                $job_parameters->extra_datum('query_params')
211
-            );
212
-            EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
213
-            $units_processed = count($csv_data);
214
-        } else {
215
-            $csv_data = array();
216
-            $units_processed = 0;
217
-        }
218
-        $job_parameters->mark_processed($units_processed);
219
-        $extra_response_data = array(
220
-            'file_url' => '',
221
-        );
222
-        if ($units_processed < $batch_size) {
223
-            $job_parameters->set_status(JobParameters::status_complete);
224
-            $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
225
-        }
194
+	/**
195
+	 * Performs another step of the job
196
+	 *
197
+	 * @param JobParameters $job_parameters
198
+	 * @param int           $batch_size
199
+	 * @return JobStepResponse
200
+	 * @throws \EE_Error
201
+	 */
202
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
203
+	{
204
+		if ($job_parameters->units_processed() < $job_parameters->job_size()) {
205
+			$csv_data = $this->get_csv_data_for(
206
+				$job_parameters->request_datum('EVT_ID', '0'),
207
+				$job_parameters->units_processed(),
208
+				$batch_size,
209
+				$job_parameters->extra_datum('question_labels'),
210
+				$job_parameters->extra_datum('query_params')
211
+			);
212
+			EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
213
+			$units_processed = count($csv_data);
214
+		} else {
215
+			$csv_data = array();
216
+			$units_processed = 0;
217
+		}
218
+		$job_parameters->mark_processed($units_processed);
219
+		$extra_response_data = array(
220
+			'file_url' => '',
221
+		);
222
+		if ($units_processed < $batch_size) {
223
+			$job_parameters->set_status(JobParameters::status_complete);
224
+			$extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
225
+		}
226 226
 
227
-        return new JobStepResponse(
228
-            $job_parameters,
229
-            sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)),
230
-            $extra_response_data
231
-        );
232
-    }
227
+		return new JobStepResponse(
228
+			$job_parameters,
229
+			sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)),
230
+			$extra_response_data
231
+		);
232
+	}
233 233
 
234 234
 
235
-    /**
236
-     * Gets the csv data for a batch of registrations
237
-     *
238
-     * @param int|null $event_id
239
-     * @param int $offset
240
-     * @param int $limit
241
-     * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
242
-     * @param array $query_params for using where querying the model
243
-     * @return array top-level keys are numeric, next-level keys are column headers
244
-     * @throws \EE_Error
245
-     */
246
-    public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
247
-    {
248
-        $reg_fields_to_include = array(
249
-            'TXN_ID',
250
-            'ATT_ID',
251
-            'REG_ID',
252
-            'REG_date',
253
-            'REG_code',
254
-            'REG_count',
255
-            'REG_final_price',
256
-        );
257
-        $att_fields_to_include = array(
258
-            'ATT_fname',
259
-            'ATT_lname',
260
-            'ATT_email',
261
-            'ATT_address',
262
-            'ATT_address2',
263
-            'ATT_city',
264
-            'STA_ID',
265
-            'CNT_ISO',
266
-            'ATT_zip',
267
-            'ATT_phone',
268
-        );
269
-        $registrations_csv_ready_array = array();
270
-        $reg_model = EE_Registry::instance()->load_model('Registration');
271
-        $query_params['limit'] = array($offset, $limit);
272
-        $registration_rows = $reg_model->get_all_wpdb_results($query_params);
273
-        $registration_ids = array();
274
-        foreach ($registration_rows as $reg_row) {
275
-            $registration_ids[] = intval($reg_row['Registration.REG_ID']);
276
-        }
277
-        foreach ($registration_rows as $reg_row) {
278
-            if (is_array($reg_row)) {
279
-                $reg_csv_array = array();
280
-                if (! $event_id) {
281
-                    // get the event's name and Id
282
-                    $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf(
283
-                        /* translators: 1: event name, 2: event ID */
284
-                        __('%1$s (%2$s)', 'event_espresso'),
285
-                        EEH_Export::prepare_value_from_db_for_display(
286
-                            EEM_Event::instance(),
287
-                            'EVT_name',
288
-                            $reg_row['Event_CPT.post_title']
289
-                        ),
290
-                        $reg_row['Event_CPT.ID']
291
-                    );
292
-                }
293
-                $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
294
-                /*@var $reg_row EE_Registration */
295
-                foreach ($reg_fields_to_include as $field_name) {
296
-                    $field = $reg_model->field_settings_for($field_name);
297
-                    if ($field_name == 'REG_final_price') {
298
-                        $value = EEH_Export::prepare_value_from_db_for_display(
299
-                            $reg_model,
300
-                            $field_name,
301
-                            $reg_row['Registration.REG_final_price'],
302
-                            'localized_float'
303
-                        );
304
-                    } elseif ($field_name == 'REG_count') {
305
-                        $value = sprintf(
306
-                            /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
307
-                            __('%1$s of %2$s', 'event_espresso'),
308
-                            EEH_Export::prepare_value_from_db_for_display(
309
-                                $reg_model,
310
-                                'REG_count',
311
-                                $reg_row['Registration.REG_count']
312
-                            ),
313
-                            EEH_Export::prepare_value_from_db_for_display(
314
-                                $reg_model,
315
-                                'REG_group_size',
316
-                                $reg_row['Registration.REG_group_size']
317
-                            )
318
-                        );
319
-                    } elseif ($field_name == 'REG_date') {
320
-                        $value = EEH_Export::prepare_value_from_db_for_display(
321
-                            $reg_model,
322
-                            $field_name,
323
-                            $reg_row['Registration.REG_date'],
324
-                            'no_html'
325
-                        );
326
-                    } else {
327
-                        $value = EEH_Export::prepare_value_from_db_for_display(
328
-                            $reg_model,
329
-                            $field_name,
330
-                            $reg_row[ $field->get_qualified_column() ]
331
-                        );
332
-                    }
333
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
334
-                    if ($field_name == 'REG_final_price') {
335
-                        // add a column named Currency after the final price
336
-                        $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
337
-                    }
338
-                }
339
-                // get pretty status
340
-                $stati = EEM_Status::instance()->localized_status(
341
-                    array(
342
-                        $reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
343
-                        $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
344
-                    ),
345
-                    false,
346
-                    'sentence'
347
-                );
348
-                $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
349
-                // get pretty transaction status
350
-                $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
351
-                $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
352
-                    ? EEH_Export::prepare_value_from_db_for_display(
353
-                        EEM_Transaction::instance(),
354
-                        'TXN_total',
355
-                        $reg_row['TransactionTable.TXN_total'],
356
-                        'localized_float'
357
-                    ) : '0.00';
358
-                $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg
359
-                    ? EEH_Export::prepare_value_from_db_for_display(
360
-                        EEM_Transaction::instance(),
361
-                        'TXN_paid',
362
-                        $reg_row['TransactionTable.TXN_paid'],
363
-                        'localized_float'
364
-                    ) : '0.00';
365
-                $payment_methods = array();
366
-                $gateway_txn_ids_etc = array();
367
-                $payment_times = array();
368
-                if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
369
-                    $payments_info = EEM_Payment::instance()->get_all_wpdb_results(
370
-                        array(
371
-                            array(
372
-                                'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
373
-                                'STS_ID' => EEM_Payment::status_id_approved,
374
-                            ),
375
-                            'force_join' => array('Payment_Method'),
376
-                        ),
377
-                        ARRAY_A,
378
-                        'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
379
-                    );
380
-                    foreach ($payments_info as $payment_method_and_gateway_txn_id) {
381
-                        $payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
382
-                            ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
383
-                        $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
384
-                            ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
385
-                        $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
386
-                            ? $payment_method_and_gateway_txn_id['payment_time'] : '';
387
-                    }
388
-                }
389
-                $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
390
-                $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
391
-                $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
392
-                    ',',
393
-                    $gateway_txn_ids_etc
394
-                );
395
-                // get whether or not the user has checked in
396
-                $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
397
-                    $reg_row['Registration.REG_ID'],
398
-                    'Checkin'
399
-                );
400
-                // get ticket of registration and its price
401
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
402
-                if ($reg_row['Ticket.TKT_ID']) {
403
-                    $ticket_name = EEH_Export::prepare_value_from_db_for_display(
404
-                        $ticket_model,
405
-                        'TKT_name',
406
-                        $reg_row['Ticket.TKT_name']
407
-                    );
408
-                    $datetimes_strings = array();
409
-                    foreach (
410
-                        EEM_Datetime::instance()->get_all_wpdb_results(
411
-                            array(
412
-                            array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
413
-                            'order_by'                 => array('DTT_EVT_start' => 'ASC'),
414
-                            'default_where_conditions' => 'none',
415
-                            )
416
-                        ) as $datetime
417
-                    ) {
418
-                        $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display(
419
-                            EEM_Datetime::instance(),
420
-                            'DTT_EVT_start',
421
-                            $datetime['Datetime.DTT_EVT_start']
422
-                        );
423
-                    }
424
-                } else {
425
-                    $ticket_name = __('Unknown', 'event_espresso');
426
-                    $datetimes_strings = array(__('Unknown', 'event_espresso'));
427
-                }
428
-                $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
429
-                $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
430
-                // get datetime(s) of registration
431
-                // add attendee columns
432
-                foreach ($att_fields_to_include as $att_field_name) {
433
-                    $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
434
-                    if ($reg_row['Attendee_CPT.ID']) {
435
-                        if ($att_field_name == 'STA_ID') {
436
-                            $value = EEM_State::instance()->get_var(
437
-                                array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
438
-                                'STA_name'
439
-                            );
440
-                        } elseif ($att_field_name == 'CNT_ISO') {
441
-                            $value = EEM_Country::instance()->get_var(
442
-                                array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
443
-                                'CNT_name'
444
-                            );
445
-                        } else {
446
-                            $value = EEH_Export::prepare_value_from_db_for_display(
447
-                                EEM_Attendee::instance(),
448
-                                $att_field_name,
449
-                                $reg_row[ $field_obj->get_qualified_column() ]
450
-                            );
451
-                        }
452
-                    } else {
453
-                        $value = '';
454
-                    }
455
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
456
-                }
457
-                // make sure each registration has the same questions in the same order
458
-                foreach ($question_labels as $question_label) {
459
-                    if (! isset($reg_csv_array[ $question_label ])) {
460
-                        $reg_csv_array[ $question_label ] = null;
461
-                    }
462
-                }
463
-                $answers = EEM_Answer::instance()->get_all_wpdb_results(array(
464
-                    array('REG_ID' => $reg_row['Registration.REG_ID']),
465
-                    'force_join' => array('Question'),
466
-                ));
467
-                // now fill out the questions THEY answered
468
-                foreach ($answers as $answer_row) {
469
-                    if ($answer_row['Question.QST_system']) {
470
-                        // it's an answer to a system question. That was already displayed as part of the attendee
471
-                        // fields, so don't write it out again thanks.
472
-                        continue;
473
-                    }
474
-                    if ($answer_row['Question.QST_ID']) {
475
-                        $question_label = EEH_Export::prepare_value_from_db_for_display(
476
-                            EEM_Question::instance(),
477
-                            'QST_admin_label',
478
-                            $answer_row['Question.QST_admin_label']
479
-                        );
480
-                    } else {
481
-                        $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
482
-                    }
483
-                    if (
484
-                        isset($answer_row['Question.QST_type'])
485
-                        && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
486
-                    ) {
487
-                        $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
488
-                            $answer_row['Answer.ANS_value']
489
-                        );
490
-                    } else {
491
-                        // this isn't for html, so don't show html entities
492
-                        $reg_csv_array[ $question_label ] = html_entity_decode(
493
-                            EEH_Export::prepare_value_from_db_for_display(
494
-                                EEM_Answer::instance(),
495
-                                'ANS_value',
496
-                                $answer_row['Answer.ANS_value']
497
-                            )
498
-                        );
499
-                    }
500
-                }
235
+	/**
236
+	 * Gets the csv data for a batch of registrations
237
+	 *
238
+	 * @param int|null $event_id
239
+	 * @param int $offset
240
+	 * @param int $limit
241
+	 * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
242
+	 * @param array $query_params for using where querying the model
243
+	 * @return array top-level keys are numeric, next-level keys are column headers
244
+	 * @throws \EE_Error
245
+	 */
246
+	public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
247
+	{
248
+		$reg_fields_to_include = array(
249
+			'TXN_ID',
250
+			'ATT_ID',
251
+			'REG_ID',
252
+			'REG_date',
253
+			'REG_code',
254
+			'REG_count',
255
+			'REG_final_price',
256
+		);
257
+		$att_fields_to_include = array(
258
+			'ATT_fname',
259
+			'ATT_lname',
260
+			'ATT_email',
261
+			'ATT_address',
262
+			'ATT_address2',
263
+			'ATT_city',
264
+			'STA_ID',
265
+			'CNT_ISO',
266
+			'ATT_zip',
267
+			'ATT_phone',
268
+		);
269
+		$registrations_csv_ready_array = array();
270
+		$reg_model = EE_Registry::instance()->load_model('Registration');
271
+		$query_params['limit'] = array($offset, $limit);
272
+		$registration_rows = $reg_model->get_all_wpdb_results($query_params);
273
+		$registration_ids = array();
274
+		foreach ($registration_rows as $reg_row) {
275
+			$registration_ids[] = intval($reg_row['Registration.REG_ID']);
276
+		}
277
+		foreach ($registration_rows as $reg_row) {
278
+			if (is_array($reg_row)) {
279
+				$reg_csv_array = array();
280
+				if (! $event_id) {
281
+					// get the event's name and Id
282
+					$reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf(
283
+						/* translators: 1: event name, 2: event ID */
284
+						__('%1$s (%2$s)', 'event_espresso'),
285
+						EEH_Export::prepare_value_from_db_for_display(
286
+							EEM_Event::instance(),
287
+							'EVT_name',
288
+							$reg_row['Event_CPT.post_title']
289
+						),
290
+						$reg_row['Event_CPT.ID']
291
+					);
292
+				}
293
+				$is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
294
+				/*@var $reg_row EE_Registration */
295
+				foreach ($reg_fields_to_include as $field_name) {
296
+					$field = $reg_model->field_settings_for($field_name);
297
+					if ($field_name == 'REG_final_price') {
298
+						$value = EEH_Export::prepare_value_from_db_for_display(
299
+							$reg_model,
300
+							$field_name,
301
+							$reg_row['Registration.REG_final_price'],
302
+							'localized_float'
303
+						);
304
+					} elseif ($field_name == 'REG_count') {
305
+						$value = sprintf(
306
+							/* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
307
+							__('%1$s of %2$s', 'event_espresso'),
308
+							EEH_Export::prepare_value_from_db_for_display(
309
+								$reg_model,
310
+								'REG_count',
311
+								$reg_row['Registration.REG_count']
312
+							),
313
+							EEH_Export::prepare_value_from_db_for_display(
314
+								$reg_model,
315
+								'REG_group_size',
316
+								$reg_row['Registration.REG_group_size']
317
+							)
318
+						);
319
+					} elseif ($field_name == 'REG_date') {
320
+						$value = EEH_Export::prepare_value_from_db_for_display(
321
+							$reg_model,
322
+							$field_name,
323
+							$reg_row['Registration.REG_date'],
324
+							'no_html'
325
+						);
326
+					} else {
327
+						$value = EEH_Export::prepare_value_from_db_for_display(
328
+							$reg_model,
329
+							$field_name,
330
+							$reg_row[ $field->get_qualified_column() ]
331
+						);
332
+					}
333
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
334
+					if ($field_name == 'REG_final_price') {
335
+						// add a column named Currency after the final price
336
+						$reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
337
+					}
338
+				}
339
+				// get pretty status
340
+				$stati = EEM_Status::instance()->localized_status(
341
+					array(
342
+						$reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
343
+						$reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
344
+					),
345
+					false,
346
+					'sentence'
347
+				);
348
+				$reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
349
+				// get pretty transaction status
350
+				$reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
351
+				$reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
352
+					? EEH_Export::prepare_value_from_db_for_display(
353
+						EEM_Transaction::instance(),
354
+						'TXN_total',
355
+						$reg_row['TransactionTable.TXN_total'],
356
+						'localized_float'
357
+					) : '0.00';
358
+				$reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg
359
+					? EEH_Export::prepare_value_from_db_for_display(
360
+						EEM_Transaction::instance(),
361
+						'TXN_paid',
362
+						$reg_row['TransactionTable.TXN_paid'],
363
+						'localized_float'
364
+					) : '0.00';
365
+				$payment_methods = array();
366
+				$gateway_txn_ids_etc = array();
367
+				$payment_times = array();
368
+				if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
369
+					$payments_info = EEM_Payment::instance()->get_all_wpdb_results(
370
+						array(
371
+							array(
372
+								'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
373
+								'STS_ID' => EEM_Payment::status_id_approved,
374
+							),
375
+							'force_join' => array('Payment_Method'),
376
+						),
377
+						ARRAY_A,
378
+						'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
379
+					);
380
+					foreach ($payments_info as $payment_method_and_gateway_txn_id) {
381
+						$payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
382
+							? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
383
+						$gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
384
+							? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
385
+						$payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
386
+							? $payment_method_and_gateway_txn_id['payment_time'] : '';
387
+					}
388
+				}
389
+				$reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
390
+				$reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
391
+				$reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
392
+					',',
393
+					$gateway_txn_ids_etc
394
+				);
395
+				// get whether or not the user has checked in
396
+				$reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
397
+					$reg_row['Registration.REG_ID'],
398
+					'Checkin'
399
+				);
400
+				// get ticket of registration and its price
401
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
402
+				if ($reg_row['Ticket.TKT_ID']) {
403
+					$ticket_name = EEH_Export::prepare_value_from_db_for_display(
404
+						$ticket_model,
405
+						'TKT_name',
406
+						$reg_row['Ticket.TKT_name']
407
+					);
408
+					$datetimes_strings = array();
409
+					foreach (
410
+						EEM_Datetime::instance()->get_all_wpdb_results(
411
+							array(
412
+							array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
413
+							'order_by'                 => array('DTT_EVT_start' => 'ASC'),
414
+							'default_where_conditions' => 'none',
415
+							)
416
+						) as $datetime
417
+					) {
418
+						$datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display(
419
+							EEM_Datetime::instance(),
420
+							'DTT_EVT_start',
421
+							$datetime['Datetime.DTT_EVT_start']
422
+						);
423
+					}
424
+				} else {
425
+					$ticket_name = __('Unknown', 'event_espresso');
426
+					$datetimes_strings = array(__('Unknown', 'event_espresso'));
427
+				}
428
+				$reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
429
+				$reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
430
+				// get datetime(s) of registration
431
+				// add attendee columns
432
+				foreach ($att_fields_to_include as $att_field_name) {
433
+					$field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
434
+					if ($reg_row['Attendee_CPT.ID']) {
435
+						if ($att_field_name == 'STA_ID') {
436
+							$value = EEM_State::instance()->get_var(
437
+								array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
438
+								'STA_name'
439
+							);
440
+						} elseif ($att_field_name == 'CNT_ISO') {
441
+							$value = EEM_Country::instance()->get_var(
442
+								array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
443
+								'CNT_name'
444
+							);
445
+						} else {
446
+							$value = EEH_Export::prepare_value_from_db_for_display(
447
+								EEM_Attendee::instance(),
448
+								$att_field_name,
449
+								$reg_row[ $field_obj->get_qualified_column() ]
450
+							);
451
+						}
452
+					} else {
453
+						$value = '';
454
+					}
455
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
456
+				}
457
+				// make sure each registration has the same questions in the same order
458
+				foreach ($question_labels as $question_label) {
459
+					if (! isset($reg_csv_array[ $question_label ])) {
460
+						$reg_csv_array[ $question_label ] = null;
461
+					}
462
+				}
463
+				$answers = EEM_Answer::instance()->get_all_wpdb_results(array(
464
+					array('REG_ID' => $reg_row['Registration.REG_ID']),
465
+					'force_join' => array('Question'),
466
+				));
467
+				// now fill out the questions THEY answered
468
+				foreach ($answers as $answer_row) {
469
+					if ($answer_row['Question.QST_system']) {
470
+						// it's an answer to a system question. That was already displayed as part of the attendee
471
+						// fields, so don't write it out again thanks.
472
+						continue;
473
+					}
474
+					if ($answer_row['Question.QST_ID']) {
475
+						$question_label = EEH_Export::prepare_value_from_db_for_display(
476
+							EEM_Question::instance(),
477
+							'QST_admin_label',
478
+							$answer_row['Question.QST_admin_label']
479
+						);
480
+					} else {
481
+						$question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
482
+					}
483
+					if (
484
+						isset($answer_row['Question.QST_type'])
485
+						&& $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
486
+					) {
487
+						$reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
488
+							$answer_row['Answer.ANS_value']
489
+						);
490
+					} else {
491
+						// this isn't for html, so don't show html entities
492
+						$reg_csv_array[ $question_label ] = html_entity_decode(
493
+							EEH_Export::prepare_value_from_db_for_display(
494
+								EEM_Answer::instance(),
495
+								'ANS_value',
496
+								$answer_row['Answer.ANS_value']
497
+							)
498
+						);
499
+					}
500
+				}
501 501
 
502
-                /**
503
-                 * Filter to change the contents of each row of the registrations report CSV file.
504
-                 * This can be used to add or remote columns from the CSV file, or change their values.
505
-                 * Note when using: all rows in the CSV should have the same columns.
506
-                 * @param array $reg_csv_array keys are the column names, values are their cell values
507
-                 * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results()
508
-                 */
509
-                $registrations_csv_ready_array[] = apply_filters(
510
-                    'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
511
-                    $reg_csv_array,
512
-                    $reg_row
513
-                );
514
-            }
515
-        }
516
-        // if we couldn't export anything, we want to at least show the column headers
517
-        if (empty($registrations_csv_ready_array)) {
518
-            $reg_csv_array = array();
519
-            $model_and_fields_to_include = array(
520
-                'Registration' => $reg_fields_to_include,
521
-                'Attendee'     => $att_fields_to_include,
522
-            );
523
-            foreach ($model_and_fields_to_include as $model_name => $field_list) {
524
-                $model = EE_Registry::instance()->load_model($model_name);
525
-                foreach ($field_list as $field_name) {
526
-                    $field = $model->field_settings_for($field_name);
527
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
528
-                }
529
-            }
530
-            $registrations_csv_ready_array[] = $reg_csv_array;
531
-        }
532
-        return $registrations_csv_ready_array;
533
-    }
502
+				/**
503
+				 * Filter to change the contents of each row of the registrations report CSV file.
504
+				 * This can be used to add or remote columns from the CSV file, or change their values.
505
+				 * Note when using: all rows in the CSV should have the same columns.
506
+				 * @param array $reg_csv_array keys are the column names, values are their cell values
507
+				 * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results()
508
+				 */
509
+				$registrations_csv_ready_array[] = apply_filters(
510
+					'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
511
+					$reg_csv_array,
512
+					$reg_row
513
+				);
514
+			}
515
+		}
516
+		// if we couldn't export anything, we want to at least show the column headers
517
+		if (empty($registrations_csv_ready_array)) {
518
+			$reg_csv_array = array();
519
+			$model_and_fields_to_include = array(
520
+				'Registration' => $reg_fields_to_include,
521
+				'Attendee'     => $att_fields_to_include,
522
+			);
523
+			foreach ($model_and_fields_to_include as $model_name => $field_list) {
524
+				$model = EE_Registry::instance()->load_model($model_name);
525
+				foreach ($field_list as $field_name) {
526
+					$field = $model->field_settings_for($field_name);
527
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
528
+				}
529
+			}
530
+			$registrations_csv_ready_array[] = $reg_csv_array;
531
+		}
532
+		return $registrations_csv_ready_array;
533
+	}
534 534
 
535 535
 
536
-    /**
537
-     * Counts total unit to process
538
-     *
539
-     * @deprecated since 4.9.19
540
-     * @param int|array $event_id
541
-     * @return int
542
-     */
543
-    public function count_units_to_process($event_id)
544
-    {
545
-        // use the legacy filter
546
-        if ($event_id) {
547
-            $query_params[0]['EVT_ID'] = $event_id;
548
-        } else {
549
-            $query_params['force_join'][] = 'Event';
550
-        }
551
-        return \EEM_Registration::instance()->count($query_params);
552
-    }
536
+	/**
537
+	 * Counts total unit to process
538
+	 *
539
+	 * @deprecated since 4.9.19
540
+	 * @param int|array $event_id
541
+	 * @return int
542
+	 */
543
+	public function count_units_to_process($event_id)
544
+	{
545
+		// use the legacy filter
546
+		if ($event_id) {
547
+			$query_params[0]['EVT_ID'] = $event_id;
548
+		} else {
549
+			$query_params['force_join'][] = 'Event';
550
+		}
551
+		return \EEM_Registration::instance()->count($query_params);
552
+	}
553 553
 
554 554
 
555
-    /**
556
-     * Performs any clean-up logic when we know the job is completed.
557
-     * In this case, we delete the temporary file
558
-     *
559
-     * @param JobParameters $job_parameters
560
-     * @return boolean
561
-     */
562
-    public function cleanup_job(JobParameters $job_parameters)
563
-    {
564
-        $this->_file_helper->delete(
565
-            \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
566
-            true,
567
-            'd'
568
-        );
569
-        return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
570
-    }
555
+	/**
556
+	 * Performs any clean-up logic when we know the job is completed.
557
+	 * In this case, we delete the temporary file
558
+	 *
559
+	 * @param JobParameters $job_parameters
560
+	 * @return boolean
561
+	 */
562
+	public function cleanup_job(JobParameters $job_parameters)
563
+	{
564
+		$this->_file_helper->delete(
565
+			\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
566
+			true,
567
+			'd'
568
+		);
569
+		return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
570
+	}
571 571
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     public function create_job(JobParameters $job_parameters)
46 46
     {
47 47
         $event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
48
-        if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
48
+        if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
49 49
             throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
50 50
         }
51 51
         $filepath = $this->create_file_from_job_with_name(
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
                 $query_params['force_join'][] = 'Event';
83 83
             }
84 84
         }
85
-        if (! isset($query_params['force_join'])) {
85
+        if ( ! isset($query_params['force_join'])) {
86 86
             $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
87 87
         }
88 88
         $job_parameters->add_extra_data('query_params', $query_params);
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
         $question_where_params = array();
182 182
         foreach ($reg_where_params as $key => $val) {
183 183
             if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
184
-                $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
184
+                $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val);
185 185
             } else {
186 186
                 // it's a normal where condition
187
-                $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
187
+                $question_where_params['Question_Group.Event.Registration.'.$key] = $val;
188 188
             }
189 189
         }
190 190
         return $question_where_params;
@@ -277,9 +277,9 @@  discard block
 block discarded – undo
277 277
         foreach ($registration_rows as $reg_row) {
278 278
             if (is_array($reg_row)) {
279 279
                 $reg_csv_array = array();
280
-                if (! $event_id) {
280
+                if ( ! $event_id) {
281 281
                     // get the event's name and Id
282
-                    $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf(
282
+                    $reg_csv_array[(string) __('Event', 'event_espresso')] = sprintf(
283 283
                         /* translators: 1: event name, 2: event ID */
284 284
                         __('%1$s (%2$s)', 'event_espresso'),
285 285
                         EEH_Export::prepare_value_from_db_for_display(
@@ -327,13 +327,13 @@  discard block
 block discarded – undo
327 327
                         $value = EEH_Export::prepare_value_from_db_for_display(
328 328
                             $reg_model,
329 329
                             $field_name,
330
-                            $reg_row[ $field->get_qualified_column() ]
330
+                            $reg_row[$field->get_qualified_column()]
331 331
                         );
332 332
                     }
333
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
333
+                    $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = $value;
334 334
                     if ($field_name == 'REG_final_price') {
335 335
                         // add a column named Currency after the final price
336
-                        $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
336
+                        $reg_csv_array[(string) __("Currency", "event_espresso")] = \EE_Config::instance()->currency->code;
337 337
                     }
338 338
                 }
339 339
                 // get pretty status
@@ -345,17 +345,17 @@  discard block
 block discarded – undo
345 345
                     false,
346 346
                     'sentence'
347 347
                 );
348
-                $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
348
+                $reg_csv_array[(string) __("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']];
349 349
                 // get pretty transaction status
350
-                $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
351
-                $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
350
+                $reg_csv_array[(string) __("Transaction Status", 'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']];
351
+                $reg_csv_array[(string) __('Transaction Amount Due', 'event_espresso')] = $is_primary_reg
352 352
                     ? EEH_Export::prepare_value_from_db_for_display(
353 353
                         EEM_Transaction::instance(),
354 354
                         'TXN_total',
355 355
                         $reg_row['TransactionTable.TXN_total'],
356 356
                         'localized_float'
357 357
                     ) : '0.00';
358
-                $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg
358
+                $reg_csv_array[(string) __('Amount Paid', 'event_espresso')] = $is_primary_reg
359 359
                     ? EEH_Export::prepare_value_from_db_for_display(
360 360
                         EEM_Transaction::instance(),
361 361
                         'TXN_paid',
@@ -386,14 +386,14 @@  discard block
 block discarded – undo
386 386
                             ? $payment_method_and_gateway_txn_id['payment_time'] : '';
387 387
                     }
388 388
                 }
389
-                $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
390
-                $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
391
-                $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
389
+                $reg_csv_array[(string) __('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times);
390
+                $reg_csv_array[(string) __('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods);
391
+                $reg_csv_array[(string) __('Gateway Transaction ID(s)', 'event_espresso')] = implode(
392 392
                     ',',
393 393
                     $gateway_txn_ids_etc
394 394
                 );
395 395
                 // get whether or not the user has checked in
396
-                $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
396
+                $reg_csv_array[(string) __("Check-Ins", "event_espresso")] = $reg_model->count_related(
397 397
                     $reg_row['Registration.REG_ID'],
398 398
                     'Checkin'
399 399
                 );
@@ -425,8 +425,8 @@  discard block
 block discarded – undo
425 425
                     $ticket_name = __('Unknown', 'event_espresso');
426 426
                     $datetimes_strings = array(__('Unknown', 'event_espresso'));
427 427
                 }
428
-                $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
429
-                $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
428
+                $reg_csv_array[(string) $ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name;
429
+                $reg_csv_array[(string) __("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings);
430 430
                 // get datetime(s) of registration
431 431
                 // add attendee columns
432 432
                 foreach ($att_fields_to_include as $att_field_name) {
@@ -446,18 +446,18 @@  discard block
 block discarded – undo
446 446
                             $value = EEH_Export::prepare_value_from_db_for_display(
447 447
                                 EEM_Attendee::instance(),
448 448
                                 $att_field_name,
449
-                                $reg_row[ $field_obj->get_qualified_column() ]
449
+                                $reg_row[$field_obj->get_qualified_column()]
450 450
                             );
451 451
                         }
452 452
                     } else {
453 453
                         $value = '';
454 454
                     }
455
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
455
+                    $reg_csv_array[EEH_Export::get_column_name_for_field($field_obj)] = $value;
456 456
                 }
457 457
                 // make sure each registration has the same questions in the same order
458 458
                 foreach ($question_labels as $question_label) {
459
-                    if (! isset($reg_csv_array[ $question_label ])) {
460
-                        $reg_csv_array[ $question_label ] = null;
459
+                    if ( ! isset($reg_csv_array[$question_label])) {
460
+                        $reg_csv_array[$question_label] = null;
461 461
                     }
462 462
                 }
463 463
                 $answers = EEM_Answer::instance()->get_all_wpdb_results(array(
@@ -484,12 +484,12 @@  discard block
 block discarded – undo
484 484
                         isset($answer_row['Question.QST_type'])
485 485
                         && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
486 486
                     ) {
487
-                        $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
487
+                        $reg_csv_array[$question_label] = EEM_State::instance()->get_state_name_by_ID(
488 488
                             $answer_row['Answer.ANS_value']
489 489
                         );
490 490
                     } else {
491 491
                         // this isn't for html, so don't show html entities
492
-                        $reg_csv_array[ $question_label ] = html_entity_decode(
492
+                        $reg_csv_array[$question_label] = html_entity_decode(
493 493
                             EEH_Export::prepare_value_from_db_for_display(
494 494
                                 EEM_Answer::instance(),
495 495
                                 'ANS_value',
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
                 $model = EE_Registry::instance()->load_model($model_name);
525 525
                 foreach ($field_list as $field_name) {
526 526
                     $field = $model->field_settings_for($field_name);
527
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
527
+                    $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = null;
528 528
                 }
529 529
             }
530 530
             $registrations_csv_ready_array[] = $reg_csv_array;
Please login to merge, or discard this patch.
admin_pages/registrations/EE_Registrations_List_Table.class.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -227,7 +227,7 @@
 block discarded – undo
227 227
      *    _get_table_filters
228 228
      *
229 229
      * @access protected
230
-     * @return array
230
+     * @return string[]
231 231
      */
232 232
     protected function _get_table_filters()
233 233
     {
Please login to merge, or discard this patch.
Indentation   +974 added lines, -974 removed lines patch added patch discarded remove patch
@@ -25,1055 +25,1055 @@
 block discarded – undo
25 25
 {
26 26
 
27 27
 
28
-    /**
29
-     * @var array
30
-     */
31
-    private $_status;
28
+	/**
29
+	 * @var array
30
+	 */
31
+	private $_status;
32 32
 
33 33
 
34
-    /**
35
-     * An array of transaction details for the related transaction to the registration being processed.
36
-     * This is set via the _set_related_details method.
37
-     *
38
-     * @var array
39
-     */
40
-    protected $_transaction_details = array();
34
+	/**
35
+	 * An array of transaction details for the related transaction to the registration being processed.
36
+	 * This is set via the _set_related_details method.
37
+	 *
38
+	 * @var array
39
+	 */
40
+	protected $_transaction_details = array();
41 41
 
42 42
 
43
-    /**
44
-     * An array of event details for the related event to the registration being processed.
45
-     * This is set via the _set_related_details method.
46
-     *
47
-     * @var array
48
-     */
49
-    protected $_event_details = array();
43
+	/**
44
+	 * An array of event details for the related event to the registration being processed.
45
+	 * This is set via the _set_related_details method.
46
+	 *
47
+	 * @var array
48
+	 */
49
+	protected $_event_details = array();
50 50
 
51 51
 
52
-    /**
53
-     * @param \Registrations_Admin_Page $admin_page
54
-     */
55
-    public function __construct(Registrations_Admin_Page $admin_page)
56
-    {
57
-        if (! empty($_GET['event_id'])) {
58
-            $extra_query_args = array();
59
-            foreach ($admin_page->get_views() as $key => $view_details) {
60
-                $extra_query_args[ $view_details['slug'] ] = array('event_id' => $_GET['event_id']);
61
-            }
62
-            $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
63
-        }
64
-        parent::__construct($admin_page);
65
-        $this->_status = $this->_admin_page->get_registration_status_array();
66
-    }
52
+	/**
53
+	 * @param \Registrations_Admin_Page $admin_page
54
+	 */
55
+	public function __construct(Registrations_Admin_Page $admin_page)
56
+	{
57
+		if (! empty($_GET['event_id'])) {
58
+			$extra_query_args = array();
59
+			foreach ($admin_page->get_views() as $key => $view_details) {
60
+				$extra_query_args[ $view_details['slug'] ] = array('event_id' => $_GET['event_id']);
61
+			}
62
+			$this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
63
+		}
64
+		parent::__construct($admin_page);
65
+		$this->_status = $this->_admin_page->get_registration_status_array();
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     *    _setup_data
71
-     *
72
-     * @access protected
73
-     * @return void
74
-     */
75
-    protected function _setup_data()
76
-    {
77
-        $this->_data = $this->_admin_page->get_registrations($this->_per_page);
78
-        $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false);
79
-    }
69
+	/**
70
+	 *    _setup_data
71
+	 *
72
+	 * @access protected
73
+	 * @return void
74
+	 */
75
+	protected function _setup_data()
76
+	{
77
+		$this->_data = $this->_admin_page->get_registrations($this->_per_page);
78
+		$this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false);
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     *    _set_properties
84
-     *
85
-     * @access protected
86
-     * @return void
87
-     */
88
-    protected function _set_properties()
89
-    {
90
-        $this->_wp_list_args = array(
91
-            'singular' => __('registration', 'event_espresso'),
92
-            'plural'   => __('registrations', 'event_espresso'),
93
-            'ajax'     => true,
94
-            'screen'   => $this->_admin_page->get_current_screen()->id,
95
-        );
96
-        $ID_column_name = __('ID', 'event_espresso');
97
-        $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
98
-        $ID_column_name .= __('Registrant Name', 'event_espresso');
99
-        $ID_column_name .= '</span> ';
100
-        if (isset($_GET['event_id'])) {
101
-            $this->_columns = array(
102
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
103
-                '_REG_ID'          => $ID_column_name,
104
-                'ATT_fname'        => __('Name', 'event_espresso'),
105
-                'ATT_email'        => __('Email', 'event_espresso'),
106
-                '_REG_date'        => __('Reg Date', 'event_espresso'),
107
-                'PRC_amount'       => __('TKT Price', 'event_espresso'),
108
-                '_REG_final_price' => __('Final Price', 'event_espresso'),
109
-                'TXN_total'        => __('Total Txn', 'event_espresso'),
110
-                'TXN_paid'         => __('Paid', 'event_espresso'),
111
-                'actions'          => __('Actions', 'event_espresso'),
112
-            );
113
-            $this->_bottom_buttons = array(
114
-                'report' => array(
115
-                    'route'         => 'registrations_report',
116
-                    'extra_request' => array(
117
-                        'EVT_ID'     => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
118
-                        'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
119
-                    ),
120
-                ),
121
-            );
122
-        } else {
123
-            $this->_columns = array(
124
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
125
-                '_REG_ID'          => $ID_column_name,
126
-                'ATT_fname'        => __('Name', 'event_espresso'),
127
-                '_REG_date'        => __('TXN Date', 'event_espresso'),
128
-                'event_name'       => __('Event', 'event_espresso'),
129
-                'DTT_EVT_start'    => __('Event Date', 'event_espresso'),
130
-                '_REG_final_price' => __('Price', 'event_espresso'),
131
-                '_REG_paid'        => __('Paid', 'event_espresso'),
132
-                'actions'          => __('Actions', 'event_espresso'),
133
-            );
134
-            $this->_bottom_buttons = array(
135
-                'report_all' => array(
136
-                    'route'         => 'registrations_report',
137
-                    'extra_request' => array(
138
-                        'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
139
-                    ),
140
-                ),
141
-            );
142
-        }
143
-        $this->_bottom_buttons['report_filtered'] = array(
144
-            'route'         => 'registrations_report',
145
-            'extra_request' => array(
146
-                'use_filters' => true,
147
-                'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
148
-            ),
149
-        );
150
-        $filters = array_diff_key(
151
-            $this->_req_data,
152
-            array_flip(
153
-                array(
154
-                    'page',
155
-                    'action',
156
-                    'default_nonce',
157
-                )
158
-            )
159
-        );
160
-        if (!empty($filters)) {
161
-            $this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
162
-        }
163
-        $this->_primary_column = '_REG_ID';
164
-        $this->_sortable_columns = array(
165
-            '_REG_date'     => array('_REG_date' => true),   // true means its already sorted
166
-            /**
167
-             * Allows users to change the default sort if they wish.
168
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
169
-             * name.
170
-             */
171
-            'ATT_fname'     => array(
172
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
173
-                true,
174
-                $this,
175
-            )
176
-                ? array('ATT_lname' => false)
177
-                : array('ATT_fname' => false),
178
-            'event_name'    => array('event_name' => false),
179
-            'DTT_EVT_start' => array('DTT_EVT_start' => false),
180
-            '_REG_ID'       => array('_REG_ID' => false),
181
-        );
182
-        $this->_hidden_columns = array();
183
-    }
82
+	/**
83
+	 *    _set_properties
84
+	 *
85
+	 * @access protected
86
+	 * @return void
87
+	 */
88
+	protected function _set_properties()
89
+	{
90
+		$this->_wp_list_args = array(
91
+			'singular' => __('registration', 'event_espresso'),
92
+			'plural'   => __('registrations', 'event_espresso'),
93
+			'ajax'     => true,
94
+			'screen'   => $this->_admin_page->get_current_screen()->id,
95
+		);
96
+		$ID_column_name = __('ID', 'event_espresso');
97
+		$ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
98
+		$ID_column_name .= __('Registrant Name', 'event_espresso');
99
+		$ID_column_name .= '</span> ';
100
+		if (isset($_GET['event_id'])) {
101
+			$this->_columns = array(
102
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
103
+				'_REG_ID'          => $ID_column_name,
104
+				'ATT_fname'        => __('Name', 'event_espresso'),
105
+				'ATT_email'        => __('Email', 'event_espresso'),
106
+				'_REG_date'        => __('Reg Date', 'event_espresso'),
107
+				'PRC_amount'       => __('TKT Price', 'event_espresso'),
108
+				'_REG_final_price' => __('Final Price', 'event_espresso'),
109
+				'TXN_total'        => __('Total Txn', 'event_espresso'),
110
+				'TXN_paid'         => __('Paid', 'event_espresso'),
111
+				'actions'          => __('Actions', 'event_espresso'),
112
+			);
113
+			$this->_bottom_buttons = array(
114
+				'report' => array(
115
+					'route'         => 'registrations_report',
116
+					'extra_request' => array(
117
+						'EVT_ID'     => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
118
+						'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
119
+					),
120
+				),
121
+			);
122
+		} else {
123
+			$this->_columns = array(
124
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
125
+				'_REG_ID'          => $ID_column_name,
126
+				'ATT_fname'        => __('Name', 'event_espresso'),
127
+				'_REG_date'        => __('TXN Date', 'event_espresso'),
128
+				'event_name'       => __('Event', 'event_espresso'),
129
+				'DTT_EVT_start'    => __('Event Date', 'event_espresso'),
130
+				'_REG_final_price' => __('Price', 'event_espresso'),
131
+				'_REG_paid'        => __('Paid', 'event_espresso'),
132
+				'actions'          => __('Actions', 'event_espresso'),
133
+			);
134
+			$this->_bottom_buttons = array(
135
+				'report_all' => array(
136
+					'route'         => 'registrations_report',
137
+					'extra_request' => array(
138
+						'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
139
+					),
140
+				),
141
+			);
142
+		}
143
+		$this->_bottom_buttons['report_filtered'] = array(
144
+			'route'         => 'registrations_report',
145
+			'extra_request' => array(
146
+				'use_filters' => true,
147
+				'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
148
+			),
149
+		);
150
+		$filters = array_diff_key(
151
+			$this->_req_data,
152
+			array_flip(
153
+				array(
154
+					'page',
155
+					'action',
156
+					'default_nonce',
157
+				)
158
+			)
159
+		);
160
+		if (!empty($filters)) {
161
+			$this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
162
+		}
163
+		$this->_primary_column = '_REG_ID';
164
+		$this->_sortable_columns = array(
165
+			'_REG_date'     => array('_REG_date' => true),   // true means its already sorted
166
+			/**
167
+			 * Allows users to change the default sort if they wish.
168
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
169
+			 * name.
170
+			 */
171
+			'ATT_fname'     => array(
172
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
173
+				true,
174
+				$this,
175
+			)
176
+				? array('ATT_lname' => false)
177
+				: array('ATT_fname' => false),
178
+			'event_name'    => array('event_name' => false),
179
+			'DTT_EVT_start' => array('DTT_EVT_start' => false),
180
+			'_REG_ID'       => array('_REG_ID' => false),
181
+		);
182
+		$this->_hidden_columns = array();
183
+	}
184 184
 
185 185
 
186
-    /**
187
-     * This simply sets up the row class for the table rows.
188
-     * Allows for easier overriding of child methods for setting up sorting.
189
-     *
190
-     * @param  EE_Registration $item the current item
191
-     * @return string
192
-     */
193
-    protected function _get_row_class($item)
194
-    {
195
-        $class = parent::_get_row_class($item);
196
-        // add status class
197
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
198
-        if ($this->_has_checkbox_column) {
199
-            $class .= ' has-checkbox-column';
200
-        }
201
-        return $class;
202
-    }
186
+	/**
187
+	 * This simply sets up the row class for the table rows.
188
+	 * Allows for easier overriding of child methods for setting up sorting.
189
+	 *
190
+	 * @param  EE_Registration $item the current item
191
+	 * @return string
192
+	 */
193
+	protected function _get_row_class($item)
194
+	{
195
+		$class = parent::_get_row_class($item);
196
+		// add status class
197
+		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
198
+		if ($this->_has_checkbox_column) {
199
+			$class .= ' has-checkbox-column';
200
+		}
201
+		return $class;
202
+	}
203 203
 
204 204
 
205
-    /**
206
-     * Set the $_transaction_details property if not set yet.
207
-     *
208
-     * @param EE_Registration $registration
209
-     * @throws EE_Error
210
-     * @throws InvalidArgumentException
211
-     * @throws ReflectionException
212
-     * @throws InvalidDataTypeException
213
-     * @throws InvalidInterfaceException
214
-     */
215
-    protected function _set_related_details(EE_Registration $registration)
216
-    {
217
-        $transaction = $registration->get_first_related('Transaction');
218
-        $status = $transaction instanceof EE_Transaction ? $transaction->status_ID()
219
-            : EEM_Transaction::failed_status_code;
220
-        $this->_transaction_details = array(
221
-            'transaction' => $transaction,
222
-            'status'      => $status,
223
-            'id'          => $transaction instanceof EE_Transaction ? $transaction->ID() : 0,
224
-            'title_attr'  => sprintf(
225
-                __('View Transaction Details (%s)', 'event_espresso'),
226
-                EEH_Template::pretty_status($status, false, 'sentence')
227
-            ),
228
-        );
229
-        try {
230
-            $event = $registration->event();
231
-        } catch (EntityNotFoundException $e) {
232
-            $event = null;
233
-        }
234
-        $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive;
235
-        $this->_event_details = array(
236
-            'event'      => $event,
237
-            'status'     => $status,
238
-            'id'         => $event instanceof EE_Event ? $event->ID() : 0,
239
-            'title_attr' => sprintf(
240
-                __('Edit Event (%s)', 'event_espresso'),
241
-                EEH_Template::pretty_status($status, false, 'sentence')
242
-            ),
243
-        );
244
-    }
205
+	/**
206
+	 * Set the $_transaction_details property if not set yet.
207
+	 *
208
+	 * @param EE_Registration $registration
209
+	 * @throws EE_Error
210
+	 * @throws InvalidArgumentException
211
+	 * @throws ReflectionException
212
+	 * @throws InvalidDataTypeException
213
+	 * @throws InvalidInterfaceException
214
+	 */
215
+	protected function _set_related_details(EE_Registration $registration)
216
+	{
217
+		$transaction = $registration->get_first_related('Transaction');
218
+		$status = $transaction instanceof EE_Transaction ? $transaction->status_ID()
219
+			: EEM_Transaction::failed_status_code;
220
+		$this->_transaction_details = array(
221
+			'transaction' => $transaction,
222
+			'status'      => $status,
223
+			'id'          => $transaction instanceof EE_Transaction ? $transaction->ID() : 0,
224
+			'title_attr'  => sprintf(
225
+				__('View Transaction Details (%s)', 'event_espresso'),
226
+				EEH_Template::pretty_status($status, false, 'sentence')
227
+			),
228
+		);
229
+		try {
230
+			$event = $registration->event();
231
+		} catch (EntityNotFoundException $e) {
232
+			$event = null;
233
+		}
234
+		$status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive;
235
+		$this->_event_details = array(
236
+			'event'      => $event,
237
+			'status'     => $status,
238
+			'id'         => $event instanceof EE_Event ? $event->ID() : 0,
239
+			'title_attr' => sprintf(
240
+				__('Edit Event (%s)', 'event_espresso'),
241
+				EEH_Template::pretty_status($status, false, 'sentence')
242
+			),
243
+		);
244
+	}
245 245
 
246 246
 
247
-    /**
248
-     *    _get_table_filters
249
-     *
250
-     * @access protected
251
-     * @return array
252
-     */
253
-    protected function _get_table_filters()
254
-    {
255
-        $filters = array();
256
-        // todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
257
-        // methods.
258
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
259
-        $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
260
-        $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : '';
261
-        $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
262
-        $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
263
-        $status = array();
264
-        $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso'));
265
-        foreach ($this->_status as $key => $value) {
266
-            $status[] = array('id' => $key, 'text' => $value);
267
-        }
268
-        if ($this->_view !== 'incomplete') {
269
-            $filters[] = EEH_Form_Fields::select_input(
270
-                '_reg_status',
271
-                $status,
272
-                isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
273
-                    : ''
274
-            );
275
-        }
276
-        if (isset($this->_req_data['event_id'])) {
277
-            $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
278
-        }
279
-        return $filters;
280
-    }
247
+	/**
248
+	 *    _get_table_filters
249
+	 *
250
+	 * @access protected
251
+	 * @return array
252
+	 */
253
+	protected function _get_table_filters()
254
+	{
255
+		$filters = array();
256
+		// todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
257
+		// methods.
258
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
259
+		$cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
260
+		$reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : '';
261
+		$filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
262
+		$filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
263
+		$status = array();
264
+		$status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso'));
265
+		foreach ($this->_status as $key => $value) {
266
+			$status[] = array('id' => $key, 'text' => $value);
267
+		}
268
+		if ($this->_view !== 'incomplete') {
269
+			$filters[] = EEH_Form_Fields::select_input(
270
+				'_reg_status',
271
+				$status,
272
+				isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
273
+					: ''
274
+			);
275
+		}
276
+		if (isset($this->_req_data['event_id'])) {
277
+			$filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
278
+		}
279
+		return $filters;
280
+	}
281 281
 
282 282
 
283
-    /**
284
-     *    _add_view_counts
285
-     *
286
-     * @access protected
287
-     * @return void
288
-     * @throws EE_Error
289
-     * @throws InvalidArgumentException
290
-     * @throws InvalidDataTypeException
291
-     * @throws InvalidInterfaceException
292
-     */
293
-    protected function _add_view_counts()
294
-    {
295
-        $this->_views['all']['count'] = $this->_total_registrations();
296
-        $this->_views['month']['count'] = $this->_total_registrations_this_month();
297
-        $this->_views['today']['count'] = $this->_total_registrations_today();
298
-        if (
299
-            EE_Registry::instance()->CAP->current_user_can(
300
-                'ee_delete_registrations',
301
-                'espresso_registrations_trash_registrations'
302
-            )
303
-        ) {
304
-            $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
305
-            $this->_views['trash']['count'] = $this->_total_registrations('trash');
306
-        }
307
-    }
283
+	/**
284
+	 *    _add_view_counts
285
+	 *
286
+	 * @access protected
287
+	 * @return void
288
+	 * @throws EE_Error
289
+	 * @throws InvalidArgumentException
290
+	 * @throws InvalidDataTypeException
291
+	 * @throws InvalidInterfaceException
292
+	 */
293
+	protected function _add_view_counts()
294
+	{
295
+		$this->_views['all']['count'] = $this->_total_registrations();
296
+		$this->_views['month']['count'] = $this->_total_registrations_this_month();
297
+		$this->_views['today']['count'] = $this->_total_registrations_today();
298
+		if (
299
+			EE_Registry::instance()->CAP->current_user_can(
300
+				'ee_delete_registrations',
301
+				'espresso_registrations_trash_registrations'
302
+			)
303
+		) {
304
+			$this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
305
+			$this->_views['trash']['count'] = $this->_total_registrations('trash');
306
+		}
307
+	}
308 308
 
309 309
 
310
-    /**
311
-     * _total_registrations
312
-     *
313
-     * @access protected
314
-     * @param string $view
315
-     * @return int
316
-     * @throws EE_Error
317
-     * @throws InvalidArgumentException
318
-     * @throws InvalidDataTypeException
319
-     * @throws InvalidInterfaceException
320
-     */
321
-    protected function _total_registrations($view = '')
322
-    {
323
-        $_where = array();
324
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
325
-        if ($EVT_ID) {
326
-            $_where['EVT_ID'] = $EVT_ID;
327
-        }
328
-        switch ($view) {
329
-            case 'trash':
330
-                return EEM_Registration::instance()->count_deleted(array($_where));
331
-                break;
332
-            case 'incomplete':
333
-                $_where['STS_ID'] = EEM_Registration::status_id_incomplete;
334
-                break;
335
-            default:
336
-                $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
337
-        }
338
-        return EEM_Registration::instance()->count(array($_where));
339
-    }
310
+	/**
311
+	 * _total_registrations
312
+	 *
313
+	 * @access protected
314
+	 * @param string $view
315
+	 * @return int
316
+	 * @throws EE_Error
317
+	 * @throws InvalidArgumentException
318
+	 * @throws InvalidDataTypeException
319
+	 * @throws InvalidInterfaceException
320
+	 */
321
+	protected function _total_registrations($view = '')
322
+	{
323
+		$_where = array();
324
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
325
+		if ($EVT_ID) {
326
+			$_where['EVT_ID'] = $EVT_ID;
327
+		}
328
+		switch ($view) {
329
+			case 'trash':
330
+				return EEM_Registration::instance()->count_deleted(array($_where));
331
+				break;
332
+			case 'incomplete':
333
+				$_where['STS_ID'] = EEM_Registration::status_id_incomplete;
334
+				break;
335
+			default:
336
+				$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
337
+		}
338
+		return EEM_Registration::instance()->count(array($_where));
339
+	}
340 340
 
341 341
 
342
-    /**
343
-     * _total_registrations_this_month
344
-     *
345
-     * @access protected
346
-     * @return int
347
-     * @throws EE_Error
348
-     * @throws InvalidArgumentException
349
-     * @throws InvalidDataTypeException
350
-     * @throws InvalidInterfaceException
351
-     */
352
-    protected function _total_registrations_this_month()
353
-    {
354
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
355
-        $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
356
-        $this_year_r = date('Y', current_time('timestamp'));
357
-        $time_start = ' 00:00:00';
358
-        $time_end = ' 23:59:59';
359
-        $this_month_r = date('m', current_time('timestamp'));
360
-        $days_this_month = date('t', current_time('timestamp'));
361
-        // setup date query.
362
-        $beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
363
-            'REG_date',
364
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
365
-            'Y-m-d H:i:s'
366
-        );
367
-        $end_string = EEM_Registration::instance()->convert_datetime_for_query(
368
-            'REG_date',
369
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
370
-            'Y-m-d H:i:s'
371
-        );
372
-        $_where['REG_date'] = array(
373
-            'BETWEEN',
374
-            array(
375
-                $beginning_string,
376
-                $end_string,
377
-            ),
378
-        );
379
-        $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
380
-        return EEM_Registration::instance()->count(array($_where));
381
-    }
342
+	/**
343
+	 * _total_registrations_this_month
344
+	 *
345
+	 * @access protected
346
+	 * @return int
347
+	 * @throws EE_Error
348
+	 * @throws InvalidArgumentException
349
+	 * @throws InvalidDataTypeException
350
+	 * @throws InvalidInterfaceException
351
+	 */
352
+	protected function _total_registrations_this_month()
353
+	{
354
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
355
+		$_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
356
+		$this_year_r = date('Y', current_time('timestamp'));
357
+		$time_start = ' 00:00:00';
358
+		$time_end = ' 23:59:59';
359
+		$this_month_r = date('m', current_time('timestamp'));
360
+		$days_this_month = date('t', current_time('timestamp'));
361
+		// setup date query.
362
+		$beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
363
+			'REG_date',
364
+			$this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
365
+			'Y-m-d H:i:s'
366
+		);
367
+		$end_string = EEM_Registration::instance()->convert_datetime_for_query(
368
+			'REG_date',
369
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
370
+			'Y-m-d H:i:s'
371
+		);
372
+		$_where['REG_date'] = array(
373
+			'BETWEEN',
374
+			array(
375
+				$beginning_string,
376
+				$end_string,
377
+			),
378
+		);
379
+		$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
380
+		return EEM_Registration::instance()->count(array($_where));
381
+	}
382 382
 
383 383
 
384
-    /**
385
-     * _total_registrations_today
386
-     *
387
-     * @access protected
388
-     * @return int
389
-     * @throws EE_Error
390
-     * @throws InvalidArgumentException
391
-     * @throws InvalidDataTypeException
392
-     * @throws InvalidInterfaceException
393
-     */
394
-    protected function _total_registrations_today()
395
-    {
396
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
397
-        $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
398
-        $current_date = date('Y-m-d', current_time('timestamp'));
399
-        $time_start = ' 00:00:00';
400
-        $time_end = ' 23:59:59';
401
-        $_where['REG_date'] = array(
402
-            'BETWEEN',
403
-            array(
404
-                EEM_Registration::instance()->convert_datetime_for_query(
405
-                    'REG_date',
406
-                    $current_date . $time_start,
407
-                    'Y-m-d H:i:s'
408
-                ),
409
-                EEM_Registration::instance()->convert_datetime_for_query(
410
-                    'REG_date',
411
-                    $current_date . $time_end,
412
-                    'Y-m-d H:i:s'
413
-                ),
414
-            ),
415
-        );
416
-        $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
417
-        return EEM_Registration::instance()->count(array($_where));
418
-    }
384
+	/**
385
+	 * _total_registrations_today
386
+	 *
387
+	 * @access protected
388
+	 * @return int
389
+	 * @throws EE_Error
390
+	 * @throws InvalidArgumentException
391
+	 * @throws InvalidDataTypeException
392
+	 * @throws InvalidInterfaceException
393
+	 */
394
+	protected function _total_registrations_today()
395
+	{
396
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
397
+		$_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
398
+		$current_date = date('Y-m-d', current_time('timestamp'));
399
+		$time_start = ' 00:00:00';
400
+		$time_end = ' 23:59:59';
401
+		$_where['REG_date'] = array(
402
+			'BETWEEN',
403
+			array(
404
+				EEM_Registration::instance()->convert_datetime_for_query(
405
+					'REG_date',
406
+					$current_date . $time_start,
407
+					'Y-m-d H:i:s'
408
+				),
409
+				EEM_Registration::instance()->convert_datetime_for_query(
410
+					'REG_date',
411
+					$current_date . $time_end,
412
+					'Y-m-d H:i:s'
413
+				),
414
+			),
415
+		);
416
+		$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
417
+		return EEM_Registration::instance()->count(array($_where));
418
+	}
419 419
 
420 420
 
421
-    /**
422
-     * column_cb
423
-     *
424
-     * @access public
425
-     * @param \EE_Registration $item
426
-     * @return string
427
-     * @throws EE_Error
428
-     * @throws InvalidArgumentException
429
-     * @throws InvalidDataTypeException
430
-     * @throws InvalidInterfaceException
431
-     * @throws ReflectionException
432
-     */
433
-    public function column_cb($item)
434
-    {
435
-        /** checkbox/lock **/
436
-        $transaction = $item->get_first_related('Transaction');
437
-        $payment_count = $transaction instanceof EE_Transaction
438
-            ? $transaction->count_related('Payment')
439
-            : 0;
440
-        return $payment_count > 0
441
-               || ! EE_Registry::instance()->CAP->current_user_can(
442
-                   'ee_edit_registration',
443
-                   'registration_list_table_checkbox_input',
444
-                   $item->ID()
445
-               )
446
-            ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID())
447
-              . '<span class="ee-lock-icon"></span>'
448
-            : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID());
449
-    }
421
+	/**
422
+	 * column_cb
423
+	 *
424
+	 * @access public
425
+	 * @param \EE_Registration $item
426
+	 * @return string
427
+	 * @throws EE_Error
428
+	 * @throws InvalidArgumentException
429
+	 * @throws InvalidDataTypeException
430
+	 * @throws InvalidInterfaceException
431
+	 * @throws ReflectionException
432
+	 */
433
+	public function column_cb($item)
434
+	{
435
+		/** checkbox/lock **/
436
+		$transaction = $item->get_first_related('Transaction');
437
+		$payment_count = $transaction instanceof EE_Transaction
438
+			? $transaction->count_related('Payment')
439
+			: 0;
440
+		return $payment_count > 0
441
+			   || ! EE_Registry::instance()->CAP->current_user_can(
442
+				   'ee_edit_registration',
443
+				   'registration_list_table_checkbox_input',
444
+				   $item->ID()
445
+			   )
446
+			? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID())
447
+			  . '<span class="ee-lock-icon"></span>'
448
+			: sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID());
449
+	}
450 450
 
451 451
 
452
-    /**
453
-     * column__REG_ID
454
-     *
455
-     * @access public
456
-     * @param \EE_Registration $item
457
-     * @return string
458
-     * @throws EE_Error
459
-     * @throws InvalidArgumentException
460
-     * @throws InvalidDataTypeException
461
-     * @throws InvalidInterfaceException
462
-     * @throws ReflectionException
463
-     */
464
-    public function column__REG_ID(EE_Registration $item)
465
-    {
466
-        $attendee = $item->attendee();
467
-        $content = $item->ID();
468
-        $content .= '<div class="show-on-mobile-view-only">';
469
-        $content .= '<br>';
470
-        $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
471
-        $content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
472
-        $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
473
-        $content .= '</div>';
474
-        return $content;
475
-    }
452
+	/**
453
+	 * column__REG_ID
454
+	 *
455
+	 * @access public
456
+	 * @param \EE_Registration $item
457
+	 * @return string
458
+	 * @throws EE_Error
459
+	 * @throws InvalidArgumentException
460
+	 * @throws InvalidDataTypeException
461
+	 * @throws InvalidInterfaceException
462
+	 * @throws ReflectionException
463
+	 */
464
+	public function column__REG_ID(EE_Registration $item)
465
+	{
466
+		$attendee = $item->attendee();
467
+		$content = $item->ID();
468
+		$content .= '<div class="show-on-mobile-view-only">';
469
+		$content .= '<br>';
470
+		$content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
471
+		$content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
472
+		$content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
473
+		$content .= '</div>';
474
+		return $content;
475
+	}
476 476
 
477 477
 
478
-    /**
479
-     * column__REG_date
480
-     *
481
-     * @access public
482
-     * @param \EE_Registration $item
483
-     * @return string
484
-     * @throws EE_Error
485
-     * @throws InvalidArgumentException
486
-     * @throws InvalidDataTypeException
487
-     * @throws InvalidInterfaceException
488
-     * @throws ReflectionException
489
-     */
490
-    public function column__REG_date(EE_Registration $item)
491
-    {
492
-        $this->_set_related_details($item);
493
-        // Build row actions
494
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
495
-            array(
496
-                'action' => 'view_transaction',
497
-                'TXN_ID' => $this->_transaction_details['id'],
498
-            ),
499
-            TXN_ADMIN_URL
500
-        );
501
-        $view_link = EE_Registry::instance()->CAP->current_user_can(
502
-            'ee_read_transaction',
503
-            'espresso_transactions_view_transaction'
504
-        )
505
-            ? '<a class="ee-status-color-'
506
-              . $this->_transaction_details['status']
507
-              . '" href="'
508
-              . $view_lnk_url
509
-              . '" title="'
510
-              . esc_attr($this->_transaction_details['title_attr'])
511
-              . '">'
512
-              . $item->get_i18n_datetime('REG_date')
513
-              . '</a>' : $item->get_i18n_datetime('REG_date');
514
-        $view_link .= '<br><span class="ee-status-text-small">'
515
-                      . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
516
-                      . '</span>';
517
-        return $view_link;
518
-    }
478
+	/**
479
+	 * column__REG_date
480
+	 *
481
+	 * @access public
482
+	 * @param \EE_Registration $item
483
+	 * @return string
484
+	 * @throws EE_Error
485
+	 * @throws InvalidArgumentException
486
+	 * @throws InvalidDataTypeException
487
+	 * @throws InvalidInterfaceException
488
+	 * @throws ReflectionException
489
+	 */
490
+	public function column__REG_date(EE_Registration $item)
491
+	{
492
+		$this->_set_related_details($item);
493
+		// Build row actions
494
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
495
+			array(
496
+				'action' => 'view_transaction',
497
+				'TXN_ID' => $this->_transaction_details['id'],
498
+			),
499
+			TXN_ADMIN_URL
500
+		);
501
+		$view_link = EE_Registry::instance()->CAP->current_user_can(
502
+			'ee_read_transaction',
503
+			'espresso_transactions_view_transaction'
504
+		)
505
+			? '<a class="ee-status-color-'
506
+			  . $this->_transaction_details['status']
507
+			  . '" href="'
508
+			  . $view_lnk_url
509
+			  . '" title="'
510
+			  . esc_attr($this->_transaction_details['title_attr'])
511
+			  . '">'
512
+			  . $item->get_i18n_datetime('REG_date')
513
+			  . '</a>' : $item->get_i18n_datetime('REG_date');
514
+		$view_link .= '<br><span class="ee-status-text-small">'
515
+					  . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
516
+					  . '</span>';
517
+		return $view_link;
518
+	}
519 519
 
520 520
 
521
-    /**
522
-     * column_event_name
523
-     *
524
-     * @access public
525
-     * @param \EE_Registration $item
526
-     * @return string
527
-     * @throws EE_Error
528
-     * @throws InvalidArgumentException
529
-     * @throws InvalidDataTypeException
530
-     * @throws InvalidInterfaceException
531
-     * @throws ReflectionException
532
-     */
533
-    public function column_event_name(EE_Registration $item)
534
-    {
535
-        $this->_set_related_details($item);
536
-        // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
537
-        $EVT_ID = $item->event_ID();
538
-        $event_name = $item->event_name();
539
-        $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso');
540
-        $event_name = wp_trim_words($event_name, 30, '...');
541
-        if ($EVT_ID) {
542
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
543
-                array('action' => 'edit', 'post' => $EVT_ID),
544
-                EVENTS_ADMIN_URL
545
-            );
546
-            $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
547
-                ? '<a class="ee-status-color-'
548
-                  . $this->_event_details['status']
549
-                  . '" href="'
550
-                  . $edit_event_url
551
-                  . '" title="'
552
-                  . esc_attr($this->_event_details['title_attr'])
553
-                  . '">'
554
-                  . $event_name
555
-                  . '</a>' : $event_name;
556
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
557
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
558
-            $actions['event_filter'] .= sprintf(
559
-                esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
560
-                $event_name
561
-            );
562
-            $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
563
-        } else {
564
-            $edit_event = $event_name;
565
-            $actions['event_filter'] = '';
566
-        }
567
-        return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
568
-    }
521
+	/**
522
+	 * column_event_name
523
+	 *
524
+	 * @access public
525
+	 * @param \EE_Registration $item
526
+	 * @return string
527
+	 * @throws EE_Error
528
+	 * @throws InvalidArgumentException
529
+	 * @throws InvalidDataTypeException
530
+	 * @throws InvalidInterfaceException
531
+	 * @throws ReflectionException
532
+	 */
533
+	public function column_event_name(EE_Registration $item)
534
+	{
535
+		$this->_set_related_details($item);
536
+		// page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
537
+		$EVT_ID = $item->event_ID();
538
+		$event_name = $item->event_name();
539
+		$event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso');
540
+		$event_name = wp_trim_words($event_name, 30, '...');
541
+		if ($EVT_ID) {
542
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
543
+				array('action' => 'edit', 'post' => $EVT_ID),
544
+				EVENTS_ADMIN_URL
545
+			);
546
+			$edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
547
+				? '<a class="ee-status-color-'
548
+				  . $this->_event_details['status']
549
+				  . '" href="'
550
+				  . $edit_event_url
551
+				  . '" title="'
552
+				  . esc_attr($this->_event_details['title_attr'])
553
+				  . '">'
554
+				  . $event_name
555
+				  . '</a>' : $event_name;
556
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
557
+			$actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
558
+			$actions['event_filter'] .= sprintf(
559
+				esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
560
+				$event_name
561
+			);
562
+			$actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
563
+		} else {
564
+			$edit_event = $event_name;
565
+			$actions['event_filter'] = '';
566
+		}
567
+		return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
568
+	}
569 569
 
570 570
 
571
-    /**
572
-     * column_DTT_EVT_start
573
-     *
574
-     * @access public
575
-     * @param \EE_Registration $item
576
-     * @return string
577
-     * @throws EE_Error
578
-     * @throws InvalidArgumentException
579
-     * @throws InvalidDataTypeException
580
-     * @throws InvalidInterfaceException
581
-     * @throws ReflectionException
582
-     */
583
-    public function column_DTT_EVT_start(EE_Registration $item)
584
-    {
585
-        $datetime_strings = array();
586
-        $ticket = $item->ticket(true);
587
-        if ($ticket instanceof EE_Ticket) {
588
-            $remove_defaults = array('default_where_conditions' => 'none');
589
-            $datetimes = $ticket->datetimes($remove_defaults);
590
-            foreach ($datetimes as $datetime) {
591
-                $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
592
-            }
593
-            return $this->generateDisplayForDatetimes($datetime_strings);
594
-        }
595
-        return __('There is no ticket on this registration', 'event_espresso');
596
-    }
571
+	/**
572
+	 * column_DTT_EVT_start
573
+	 *
574
+	 * @access public
575
+	 * @param \EE_Registration $item
576
+	 * @return string
577
+	 * @throws EE_Error
578
+	 * @throws InvalidArgumentException
579
+	 * @throws InvalidDataTypeException
580
+	 * @throws InvalidInterfaceException
581
+	 * @throws ReflectionException
582
+	 */
583
+	public function column_DTT_EVT_start(EE_Registration $item)
584
+	{
585
+		$datetime_strings = array();
586
+		$ticket = $item->ticket(true);
587
+		if ($ticket instanceof EE_Ticket) {
588
+			$remove_defaults = array('default_where_conditions' => 'none');
589
+			$datetimes = $ticket->datetimes($remove_defaults);
590
+			foreach ($datetimes as $datetime) {
591
+				$datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
592
+			}
593
+			return $this->generateDisplayForDatetimes($datetime_strings);
594
+		}
595
+		return __('There is no ticket on this registration', 'event_espresso');
596
+	}
597 597
 
598 598
 
599
-    /**
600
-     * Receives an array of datetime strings to display and converts them to the html container for the column.
601
-     *
602
-     * @param array $datetime_strings
603
-     * @return string
604
-     */
605
-    public function generateDisplayForDateTimes(array $datetime_strings)
606
-    {
607
-        $content = '<div class="ee-registration-event-datetimes-container">';
608
-        $expand_toggle = count($datetime_strings) > 1
609
-            ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
610
-              . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
611
-            : '';
612
-        // get first item for initial visibility
613
-        $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
614
-        $content .= $expand_toggle;
615
-        if ($datetime_strings) {
616
-            $content .= '<div style="clear:both"></div>';
617
-            $content .= '<div class="ee-registration-event-datetimes-container more-items hidden">';
618
-            $content .= implode("<br />", $datetime_strings);
619
-            $content .= '</div>';
620
-        }
621
-        $content .= '</div>';
622
-        return $content;
623
-    }
599
+	/**
600
+	 * Receives an array of datetime strings to display and converts them to the html container for the column.
601
+	 *
602
+	 * @param array $datetime_strings
603
+	 * @return string
604
+	 */
605
+	public function generateDisplayForDateTimes(array $datetime_strings)
606
+	{
607
+		$content = '<div class="ee-registration-event-datetimes-container">';
608
+		$expand_toggle = count($datetime_strings) > 1
609
+			? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
610
+			  . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
611
+			: '';
612
+		// get first item for initial visibility
613
+		$content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
614
+		$content .= $expand_toggle;
615
+		if ($datetime_strings) {
616
+			$content .= '<div style="clear:both"></div>';
617
+			$content .= '<div class="ee-registration-event-datetimes-container more-items hidden">';
618
+			$content .= implode("<br />", $datetime_strings);
619
+			$content .= '</div>';
620
+		}
621
+		$content .= '</div>';
622
+		return $content;
623
+	}
624 624
 
625 625
 
626
-    /**
627
-     * column_ATT_fname
628
-     *
629
-     * @access public
630
-     * @param \EE_Registration $item
631
-     * @return string
632
-     * @throws EE_Error
633
-     * @throws InvalidArgumentException
634
-     * @throws InvalidDataTypeException
635
-     * @throws InvalidInterfaceException
636
-     * @throws ReflectionException
637
-     */
638
-    public function column_ATT_fname(EE_Registration $item)
639
-    {
640
-        $attendee = $item->attendee();
641
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
642
-            array(
643
-                'action'  => 'view_registration',
644
-                '_REG_ID' => $item->ID(),
645
-            ),
646
-            REG_ADMIN_URL
647
-        );
648
-        $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
649
-        $link = EE_Registry::instance()->CAP->current_user_can(
650
-            'ee_read_registration',
651
-            'espresso_registrations_view_registration',
652
-            $item->ID()
653
-        )
654
-            ? '<a href="'
655
-              . $edit_lnk_url
656
-              . '" title="'
657
-              . esc_attr__('View Registration Details', 'event_espresso')
658
-              . '">'
659
-              . $attendee_name
660
-              . '</a>' : $attendee_name;
661
-        $link .= $item->count() === 1
662
-            ? '&nbsp;<sup><div class="dashicons dashicons-star-filled yellow-icon ee-icon-size-8"></div></sup>' : '';
663
-        $t = $item->get_first_related('Transaction');
664
-        $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
665
-        // append group count to name
666
-        $link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
667
-        // append reg_code
668
-        $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
669
-        // reg status text for accessibility
670
-        $link .= '<br><span class="ee-status-text-small">'
671
-                 . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
672
-                 . '</span>';
673
-        $action = [ '_REG_ID' => $item->ID() ];
674
-        if (isset($this->_req_data['event_id'])) {
675
-            $action['event_id'] = $item->event_ID();
676
-        }
677
-        // trash/restore/delete actions
678
-        $actions = array();
679
-        if (
680
-            $this->_view !== 'trash'
681
-            && $payment_count === 0
682
-            && EE_Registry::instance()->CAP->current_user_can(
683
-                'ee_delete_registration',
684
-                'espresso_registrations_trash_registrations',
685
-                $item->ID()
686
-            )
687
-        ) {
688
-            $action['action'] = 'trash_registrations';
689
-            $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
690
-                $action,
691
-                REG_ADMIN_URL
692
-            );
693
-            $actions['trash'] = '<a href="'
694
-                                . $trash_lnk_url
695
-                                . '" title="'
696
-                                . esc_attr__('Trash Registration', 'event_espresso')
697
-                                . '">' . __('Trash', 'event_espresso') . '</a>';
698
-        } elseif ($this->_view === 'trash') {
699
-            // restore registration link
700
-            if (
701
-                EE_Registry::instance()->CAP->current_user_can(
702
-                    'ee_delete_registration',
703
-                    'espresso_registrations_restore_registrations',
704
-                    $item->ID()
705
-                )
706
-            ) {
707
-                $action['action'] = 'restore_registrations';
708
-                $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
709
-                    $action,
710
-                    REG_ADMIN_URL
711
-                );
712
-                $actions['restore'] = '<a href="'
713
-                                      . $restore_lnk_url
714
-                                      . '" title="'
715
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
716
-                                      . __('Restore', 'event_espresso') . '</a>';
717
-            }
718
-            if (
719
-                EE_Registry::instance()->CAP->current_user_can(
720
-                    'ee_delete_registration',
721
-                    'espresso_registrations_ee_delete_registrations',
722
-                    $item->ID()
723
-                )
724
-            ) {
725
-                $action['action'] = 'delete_registrations';
726
-                $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
727
-                    $action,
728
-                    REG_ADMIN_URL
729
-                );
730
-                $actions['delete'] = '<a href="'
731
-                                     . $delete_lnk_url
732
-                                     . '" title="'
733
-                                     . esc_attr__('Delete Registration Permanently', 'event_espresso')
734
-                                     . '">'
735
-                                     . __('Delete', 'event_espresso')
736
-                                     . '</a>';
737
-            }
738
-        }
739
-        return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
740
-    }
626
+	/**
627
+	 * column_ATT_fname
628
+	 *
629
+	 * @access public
630
+	 * @param \EE_Registration $item
631
+	 * @return string
632
+	 * @throws EE_Error
633
+	 * @throws InvalidArgumentException
634
+	 * @throws InvalidDataTypeException
635
+	 * @throws InvalidInterfaceException
636
+	 * @throws ReflectionException
637
+	 */
638
+	public function column_ATT_fname(EE_Registration $item)
639
+	{
640
+		$attendee = $item->attendee();
641
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
642
+			array(
643
+				'action'  => 'view_registration',
644
+				'_REG_ID' => $item->ID(),
645
+			),
646
+			REG_ADMIN_URL
647
+		);
648
+		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
649
+		$link = EE_Registry::instance()->CAP->current_user_can(
650
+			'ee_read_registration',
651
+			'espresso_registrations_view_registration',
652
+			$item->ID()
653
+		)
654
+			? '<a href="'
655
+			  . $edit_lnk_url
656
+			  . '" title="'
657
+			  . esc_attr__('View Registration Details', 'event_espresso')
658
+			  . '">'
659
+			  . $attendee_name
660
+			  . '</a>' : $attendee_name;
661
+		$link .= $item->count() === 1
662
+			? '&nbsp;<sup><div class="dashicons dashicons-star-filled yellow-icon ee-icon-size-8"></div></sup>' : '';
663
+		$t = $item->get_first_related('Transaction');
664
+		$payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
665
+		// append group count to name
666
+		$link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
667
+		// append reg_code
668
+		$link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
669
+		// reg status text for accessibility
670
+		$link .= '<br><span class="ee-status-text-small">'
671
+				 . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
672
+				 . '</span>';
673
+		$action = [ '_REG_ID' => $item->ID() ];
674
+		if (isset($this->_req_data['event_id'])) {
675
+			$action['event_id'] = $item->event_ID();
676
+		}
677
+		// trash/restore/delete actions
678
+		$actions = array();
679
+		if (
680
+			$this->_view !== 'trash'
681
+			&& $payment_count === 0
682
+			&& EE_Registry::instance()->CAP->current_user_can(
683
+				'ee_delete_registration',
684
+				'espresso_registrations_trash_registrations',
685
+				$item->ID()
686
+			)
687
+		) {
688
+			$action['action'] = 'trash_registrations';
689
+			$trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
690
+				$action,
691
+				REG_ADMIN_URL
692
+			);
693
+			$actions['trash'] = '<a href="'
694
+								. $trash_lnk_url
695
+								. '" title="'
696
+								. esc_attr__('Trash Registration', 'event_espresso')
697
+								. '">' . __('Trash', 'event_espresso') . '</a>';
698
+		} elseif ($this->_view === 'trash') {
699
+			// restore registration link
700
+			if (
701
+				EE_Registry::instance()->CAP->current_user_can(
702
+					'ee_delete_registration',
703
+					'espresso_registrations_restore_registrations',
704
+					$item->ID()
705
+				)
706
+			) {
707
+				$action['action'] = 'restore_registrations';
708
+				$restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
709
+					$action,
710
+					REG_ADMIN_URL
711
+				);
712
+				$actions['restore'] = '<a href="'
713
+									  . $restore_lnk_url
714
+									  . '" title="'
715
+									  . esc_attr__('Restore Registration', 'event_espresso') . '">'
716
+									  . __('Restore', 'event_espresso') . '</a>';
717
+			}
718
+			if (
719
+				EE_Registry::instance()->CAP->current_user_can(
720
+					'ee_delete_registration',
721
+					'espresso_registrations_ee_delete_registrations',
722
+					$item->ID()
723
+				)
724
+			) {
725
+				$action['action'] = 'delete_registrations';
726
+				$delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
727
+					$action,
728
+					REG_ADMIN_URL
729
+				);
730
+				$actions['delete'] = '<a href="'
731
+									 . $delete_lnk_url
732
+									 . '" title="'
733
+									 . esc_attr__('Delete Registration Permanently', 'event_espresso')
734
+									 . '">'
735
+									 . __('Delete', 'event_espresso')
736
+									 . '</a>';
737
+			}
738
+		}
739
+		return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
740
+	}
741 741
 
742 742
 
743
-    /**
744
-     * column_ATT_email
745
-     *
746
-     * @access public
747
-     * @param \EE_Registration $item
748
-     * @return string
749
-     * @throws EE_Error
750
-     * @throws InvalidArgumentException
751
-     * @throws InvalidDataTypeException
752
-     * @throws InvalidInterfaceException
753
-     * @throws ReflectionException
754
-     */
755
-    public function column_ATT_email(EE_Registration $item)
756
-    {
757
-        $attendee = $item->get_first_related('Attendee');
758
-        return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso')
759
-            : $attendee->email();
760
-    }
743
+	/**
744
+	 * column_ATT_email
745
+	 *
746
+	 * @access public
747
+	 * @param \EE_Registration $item
748
+	 * @return string
749
+	 * @throws EE_Error
750
+	 * @throws InvalidArgumentException
751
+	 * @throws InvalidDataTypeException
752
+	 * @throws InvalidInterfaceException
753
+	 * @throws ReflectionException
754
+	 */
755
+	public function column_ATT_email(EE_Registration $item)
756
+	{
757
+		$attendee = $item->get_first_related('Attendee');
758
+		return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso')
759
+			: $attendee->email();
760
+	}
761 761
 
762 762
 
763
-    /**
764
-     * column__REG_count
765
-     *
766
-     * @access public
767
-     * @param \EE_Registration $item
768
-     * @return string
769
-     */
770
-    public function column__REG_count(EE_Registration $item)
771
-    {
772
-        return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
773
-    }
763
+	/**
764
+	 * column__REG_count
765
+	 *
766
+	 * @access public
767
+	 * @param \EE_Registration $item
768
+	 * @return string
769
+	 */
770
+	public function column__REG_count(EE_Registration $item)
771
+	{
772
+		return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
773
+	}
774 774
 
775 775
 
776
-    /**
777
-     * column_PRC_amount
778
-     *
779
-     * @access public
780
-     * @param \EE_Registration $item
781
-     * @return string
782
-     * @throws EE_Error
783
-     */
784
-    public function column_PRC_amount(EE_Registration $item)
785
-    {
786
-        $ticket = $item->ticket();
787
-        $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">'
788
-                                                                              . $ticket->name()
789
-                                                                              . '</span><br />' : '';
790
-        if ($item->final_price() > 0) {
791
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
792
-        } else {
793
-            // free event
794
-            $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
795
-                        . __('free', 'event_espresso')
796
-                        . '</span>';
797
-        }
798
-        return $content;
799
-    }
776
+	/**
777
+	 * column_PRC_amount
778
+	 *
779
+	 * @access public
780
+	 * @param \EE_Registration $item
781
+	 * @return string
782
+	 * @throws EE_Error
783
+	 */
784
+	public function column_PRC_amount(EE_Registration $item)
785
+	{
786
+		$ticket = $item->ticket();
787
+		$content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">'
788
+																			  . $ticket->name()
789
+																			  . '</span><br />' : '';
790
+		if ($item->final_price() > 0) {
791
+			$content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
792
+		} else {
793
+			// free event
794
+			$content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
795
+						. __('free', 'event_espresso')
796
+						. '</span>';
797
+		}
798
+		return $content;
799
+	}
800 800
 
801 801
 
802
-    /**
803
-     * column__REG_final_price
804
-     *
805
-     * @access public
806
-     * @param \EE_Registration $item
807
-     * @return string
808
-     * @throws EE_Error
809
-     */
810
-    public function column__REG_final_price(EE_Registration $item)
811
-    {
812
-        $ticket = $item->ticket();
813
-        $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket
814
-            ? ''
815
-            : '<span class="TKT_name">'
816
-              . $ticket->name()
817
-              . '</span><br />';
818
-        $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
819
-        return $content;
820
-    }
802
+	/**
803
+	 * column__REG_final_price
804
+	 *
805
+	 * @access public
806
+	 * @param \EE_Registration $item
807
+	 * @return string
808
+	 * @throws EE_Error
809
+	 */
810
+	public function column__REG_final_price(EE_Registration $item)
811
+	{
812
+		$ticket = $item->ticket();
813
+		$content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket
814
+			? ''
815
+			: '<span class="TKT_name">'
816
+			  . $ticket->name()
817
+			  . '</span><br />';
818
+		$content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
819
+		return $content;
820
+	}
821 821
 
822 822
 
823
-    /**
824
-     * column__REG_paid
825
-     *
826
-     * @access public
827
-     * @param \EE_Registration $item
828
-     * @return string
829
-     * @throws EE_Error
830
-     */
831
-    public function column__REG_paid(EE_Registration $item)
832
-    {
833
-        $payment_method = $item->payment_method();
834
-        $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
835
-            : __('Unknown', 'event_espresso');
836
-        $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
837
-        if ($item->paid() > 0) {
838
-            $content .= '<br><span class="ee-status-text-small">'
839
-                        . sprintf(
840
-                            __('...via %s', 'event_espresso'),
841
-                            $payment_method_name
842
-                        )
843
-                        . '</span>';
844
-        }
845
-        return $content;
846
-    }
823
+	/**
824
+	 * column__REG_paid
825
+	 *
826
+	 * @access public
827
+	 * @param \EE_Registration $item
828
+	 * @return string
829
+	 * @throws EE_Error
830
+	 */
831
+	public function column__REG_paid(EE_Registration $item)
832
+	{
833
+		$payment_method = $item->payment_method();
834
+		$payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
835
+			: __('Unknown', 'event_espresso');
836
+		$content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
837
+		if ($item->paid() > 0) {
838
+			$content .= '<br><span class="ee-status-text-small">'
839
+						. sprintf(
840
+							__('...via %s', 'event_espresso'),
841
+							$payment_method_name
842
+						)
843
+						. '</span>';
844
+		}
845
+		return $content;
846
+	}
847 847
 
848 848
 
849
-    /**
850
-     * column_TXN_total
851
-     *
852
-     * @access public
853
-     * @param \EE_Registration $item
854
-     * @return string
855
-     * @throws EE_Error
856
-     * @throws EntityNotFoundException
857
-     * @throws InvalidArgumentException
858
-     * @throws InvalidDataTypeException
859
-     * @throws InvalidInterfaceException
860
-     */
861
-    public function column_TXN_total(EE_Registration $item)
862
-    {
863
-        if ($item->transaction()) {
864
-            $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
865
-                array(
866
-                    'action' => 'view_transaction',
867
-                    'TXN_ID' => $item->transaction_ID(),
868
-                ),
869
-                TXN_ADMIN_URL
870
-            );
871
-            return EE_Registry::instance()->CAP->current_user_can(
872
-                'ee_read_transaction',
873
-                'espresso_transactions_view_transaction',
874
-                $item->transaction_ID()
875
-            )
876
-                ? '<span class="reg-pad-rght"><a class="status-'
877
-                  . $item->transaction()->status_ID()
878
-                  . '" href="'
879
-                  . $view_txn_lnk_url
880
-                  . '"  title="'
881
-                  . esc_attr__('View Transaction', 'event_espresso')
882
-                  . '">'
883
-                  . $item->transaction()->pretty_total()
884
-                  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
885
-        } else {
886
-            return __("None", "event_espresso");
887
-        }
888
-    }
849
+	/**
850
+	 * column_TXN_total
851
+	 *
852
+	 * @access public
853
+	 * @param \EE_Registration $item
854
+	 * @return string
855
+	 * @throws EE_Error
856
+	 * @throws EntityNotFoundException
857
+	 * @throws InvalidArgumentException
858
+	 * @throws InvalidDataTypeException
859
+	 * @throws InvalidInterfaceException
860
+	 */
861
+	public function column_TXN_total(EE_Registration $item)
862
+	{
863
+		if ($item->transaction()) {
864
+			$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
865
+				array(
866
+					'action' => 'view_transaction',
867
+					'TXN_ID' => $item->transaction_ID(),
868
+				),
869
+				TXN_ADMIN_URL
870
+			);
871
+			return EE_Registry::instance()->CAP->current_user_can(
872
+				'ee_read_transaction',
873
+				'espresso_transactions_view_transaction',
874
+				$item->transaction_ID()
875
+			)
876
+				? '<span class="reg-pad-rght"><a class="status-'
877
+				  . $item->transaction()->status_ID()
878
+				  . '" href="'
879
+				  . $view_txn_lnk_url
880
+				  . '"  title="'
881
+				  . esc_attr__('View Transaction', 'event_espresso')
882
+				  . '">'
883
+				  . $item->transaction()->pretty_total()
884
+				  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
885
+		} else {
886
+			return __("None", "event_espresso");
887
+		}
888
+	}
889 889
 
890 890
 
891
-    /**
892
-     * column_TXN_paid
893
-     *
894
-     * @access public
895
-     * @param \EE_Registration $item
896
-     * @return string
897
-     * @throws EE_Error
898
-     * @throws EntityNotFoundException
899
-     * @throws InvalidArgumentException
900
-     * @throws InvalidDataTypeException
901
-     * @throws InvalidInterfaceException
902
-     */
903
-    public function column_TXN_paid(EE_Registration $item)
904
-    {
905
-        if ($item->count() === 1) {
906
-            $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance();
907
-            if ($transaction->paid() >= $transaction->total()) {
908
-                return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
909
-            } else {
910
-                $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
911
-                    array(
912
-                        'action' => 'view_transaction',
913
-                        'TXN_ID' => $item->transaction_ID(),
914
-                    ),
915
-                    TXN_ADMIN_URL
916
-                );
917
-                return EE_Registry::instance()->CAP->current_user_can(
918
-                    'ee_read_transaction',
919
-                    'espresso_transactions_view_transaction',
920
-                    $item->transaction_ID()
921
-                )
922
-                    ? '<span class="reg-pad-rght"><a class="status-'
923
-                      . $transaction->status_ID()
924
-                      . '" href="'
925
-                      . $view_txn_lnk_url
926
-                      . '"  title="'
927
-                      . esc_attr__('View Transaction', 'event_espresso')
928
-                      . '">'
929
-                      . $item->transaction()->pretty_paid()
930
-                      . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
931
-            }
932
-        }
933
-        return '&nbsp;';
934
-    }
891
+	/**
892
+	 * column_TXN_paid
893
+	 *
894
+	 * @access public
895
+	 * @param \EE_Registration $item
896
+	 * @return string
897
+	 * @throws EE_Error
898
+	 * @throws EntityNotFoundException
899
+	 * @throws InvalidArgumentException
900
+	 * @throws InvalidDataTypeException
901
+	 * @throws InvalidInterfaceException
902
+	 */
903
+	public function column_TXN_paid(EE_Registration $item)
904
+	{
905
+		if ($item->count() === 1) {
906
+			$transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance();
907
+			if ($transaction->paid() >= $transaction->total()) {
908
+				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
909
+			} else {
910
+				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
911
+					array(
912
+						'action' => 'view_transaction',
913
+						'TXN_ID' => $item->transaction_ID(),
914
+					),
915
+					TXN_ADMIN_URL
916
+				);
917
+				return EE_Registry::instance()->CAP->current_user_can(
918
+					'ee_read_transaction',
919
+					'espresso_transactions_view_transaction',
920
+					$item->transaction_ID()
921
+				)
922
+					? '<span class="reg-pad-rght"><a class="status-'
923
+					  . $transaction->status_ID()
924
+					  . '" href="'
925
+					  . $view_txn_lnk_url
926
+					  . '"  title="'
927
+					  . esc_attr__('View Transaction', 'event_espresso')
928
+					  . '">'
929
+					  . $item->transaction()->pretty_paid()
930
+					  . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
931
+			}
932
+		}
933
+		return '&nbsp;';
934
+	}
935 935
 
936 936
 
937
-    /**
938
-     * column_actions
939
-     *
940
-     * @access public
941
-     * @param \EE_Registration $item
942
-     * @return string
943
-     * @throws EE_Error
944
-     * @throws InvalidArgumentException
945
-     * @throws InvalidDataTypeException
946
-     * @throws InvalidInterfaceException
947
-     * @throws ReflectionException
948
-     */
949
-    public function column_actions(EE_Registration $item)
950
-    {
951
-        $actions = array();
952
-        $attendee = $item->attendee();
953
-        $this->_set_related_details($item);
954
-        // Build row actions
955
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
956
-            array(
957
-                'action'  => 'view_registration',
958
-                '_REG_ID' => $item->ID(),
959
-            ),
960
-            REG_ADMIN_URL
961
-        );
962
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
963
-            array(
964
-                'action' => 'edit_attendee',
965
-                'post'   => $item->attendee_ID(),
966
-            ),
967
-            REG_ADMIN_URL
968
-        );
969
-        // page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
970
-        // $resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
971
-        $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
972
-            array(
973
-                'action'  => 'resend_registration',
974
-                '_REG_ID' => $item->ID(),
975
-            ),
976
-            REG_ADMIN_URL,
977
-            true
978
-        );
979
-        // Build row actions
980
-        $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can(
981
-            'ee_read_registration',
982
-            'espresso_registrations_view_registration',
983
-            $item->ID()
984
-        ) ? '<li><a href="'
985
-            . $view_lnk_url
986
-            . '" title="'
987
-            . esc_attr__('View Registration Details', 'event_espresso')
988
-            . '" class="tiny-text">
937
+	/**
938
+	 * column_actions
939
+	 *
940
+	 * @access public
941
+	 * @param \EE_Registration $item
942
+	 * @return string
943
+	 * @throws EE_Error
944
+	 * @throws InvalidArgumentException
945
+	 * @throws InvalidDataTypeException
946
+	 * @throws InvalidInterfaceException
947
+	 * @throws ReflectionException
948
+	 */
949
+	public function column_actions(EE_Registration $item)
950
+	{
951
+		$actions = array();
952
+		$attendee = $item->attendee();
953
+		$this->_set_related_details($item);
954
+		// Build row actions
955
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
956
+			array(
957
+				'action'  => 'view_registration',
958
+				'_REG_ID' => $item->ID(),
959
+			),
960
+			REG_ADMIN_URL
961
+		);
962
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
963
+			array(
964
+				'action' => 'edit_attendee',
965
+				'post'   => $item->attendee_ID(),
966
+			),
967
+			REG_ADMIN_URL
968
+		);
969
+		// page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
970
+		// $resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
971
+		$resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
972
+			array(
973
+				'action'  => 'resend_registration',
974
+				'_REG_ID' => $item->ID(),
975
+			),
976
+			REG_ADMIN_URL,
977
+			true
978
+		);
979
+		// Build row actions
980
+		$actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can(
981
+			'ee_read_registration',
982
+			'espresso_registrations_view_registration',
983
+			$item->ID()
984
+		) ? '<li><a href="'
985
+			. $view_lnk_url
986
+			. '" title="'
987
+			. esc_attr__('View Registration Details', 'event_espresso')
988
+			. '" class="tiny-text">
989 989
 				<div class="dashicons dashicons-clipboard"></div>
990 990
 			</a>
991 991
 			</li>'
992
-            : '';
993
-        $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can(
994
-            'ee_edit_contacts',
995
-            'espresso_registrations_edit_attendee'
996
-        )
997
-                               && $attendee instanceof EE_Attendee
998
-            ? '
992
+			: '';
993
+		$actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can(
994
+			'ee_edit_contacts',
995
+			'espresso_registrations_edit_attendee'
996
+		)
997
+							   && $attendee instanceof EE_Attendee
998
+			? '
999 999
 			<li>
1000 1000
 			<a href="' . $edit_lnk_url . '" title="'
1001
-              . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
1001
+			  . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
1002 1002
 				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
1003 1003
 			</a>
1004 1004
 			</li>' : '';
1005
-        $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee
1006
-                                     && EE_Registry::instance()->CAP->current_user_can(
1007
-                                         'ee_send_message',
1008
-                                         'espresso_registrations_resend_registration',
1009
-                                         $item->ID()
1010
-                                     )
1011
-            ? '
1005
+		$actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee
1006
+									 && EE_Registry::instance()->CAP->current_user_can(
1007
+										 'ee_send_message',
1008
+										 'espresso_registrations_resend_registration',
1009
+										 $item->ID()
1010
+									 )
1011
+			? '
1012 1012
 			<li>
1013 1013
 			<a href="'
1014
-              . $resend_reg_lnk_url
1015
-              . '" title="'
1016
-              . esc_attr__('Resend Registration Details', 'event_espresso')
1017
-              . '" class="tiny-text">
1014
+			  . $resend_reg_lnk_url
1015
+			  . '" title="'
1016
+			  . esc_attr__('Resend Registration Details', 'event_espresso')
1017
+			  . '" class="tiny-text">
1018 1018
 				<div class="dashicons dashicons-email-alt"></div>
1019 1019
 			</a>
1020 1020
 			</li>' : '';
1021
-        // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
1022
-        $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
1023
-            array(
1024
-                'action' => 'view_transaction',
1025
-                'TXN_ID' => $this->_transaction_details['id'],
1026
-            ),
1027
-            TXN_ADMIN_URL
1028
-        );
1029
-        $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can(
1030
-            'ee_read_transaction',
1031
-            'espresso_transactions_view_transaction',
1032
-            $this->_transaction_details['id']
1033
-        )
1034
-            ? '
1021
+		// page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
1022
+		$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
1023
+			array(
1024
+				'action' => 'view_transaction',
1025
+				'TXN_ID' => $this->_transaction_details['id'],
1026
+			),
1027
+			TXN_ADMIN_URL
1028
+		);
1029
+		$actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can(
1030
+			'ee_read_transaction',
1031
+			'espresso_transactions_view_transaction',
1032
+			$this->_transaction_details['id']
1033
+		)
1034
+			? '
1035 1035
 			<li>
1036 1036
 			<a class="ee-status-color-'
1037
-              . $this->_transaction_details['status']
1038
-              . ' tiny-text" href="'
1039
-              . $view_txn_lnk_url
1040
-              . '"  title="'
1041
-              . $this->_transaction_details['title_attr']
1042
-              . '">
1037
+			  . $this->_transaction_details['status']
1038
+			  . ' tiny-text" href="'
1039
+			  . $view_txn_lnk_url
1040
+			  . '"  title="'
1041
+			  . $this->_transaction_details['title_attr']
1042
+			  . '">
1043 1043
 				<div class="dashicons dashicons-cart"></div>
1044 1044
 			</a>
1045 1045
 			</li>' : '';
1046
-        // invoice link
1047
-        $actions['dl_invoice_lnk'] = '';
1048
-        $dl_invoice_lnk_url = $item->invoice_url();
1049
-        // only show invoice link if message type is active.
1050
-        if (
1051
-            $attendee instanceof EE_Attendee
1052
-            && $item->is_primary_registrant()
1053
-            && EEH_MSG_Template::is_mt_active('invoice')
1054
-        ) {
1055
-            $actions['dl_invoice_lnk'] = '
1046
+		// invoice link
1047
+		$actions['dl_invoice_lnk'] = '';
1048
+		$dl_invoice_lnk_url = $item->invoice_url();
1049
+		// only show invoice link if message type is active.
1050
+		if (
1051
+			$attendee instanceof EE_Attendee
1052
+			&& $item->is_primary_registrant()
1053
+			&& EEH_MSG_Template::is_mt_active('invoice')
1054
+		) {
1055
+			$actions['dl_invoice_lnk'] = '
1056 1056
 		<li>
1057 1057
 			<a title="'
1058
-                                         . esc_attr__('View Transaction Invoice', 'event_espresso')
1059
-                                         . '" target="_blank" href="'
1060
-                                         . $dl_invoice_lnk_url
1061
-                                         . '" class="tiny-text">
1058
+										 . esc_attr__('View Transaction Invoice', 'event_espresso')
1059
+										 . '" target="_blank" href="'
1060
+										 . $dl_invoice_lnk_url
1061
+										 . '" class="tiny-text">
1062 1062
 				<span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
1063 1063
 			</a>
1064 1064
 		</li>';
1065
-        }
1066
-        $actions['filtered_messages_link'] = '';
1067
-        // message list table link (filtered by REG_ID
1068
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
1069
-            $actions['filtered_messages_link'] = '<li>'
1070
-                                                 . EEH_MSG_Template::get_message_action_link(
1071
-                                                     'see_notifications_for',
1072
-                                                     null,
1073
-                                                     array('_REG_ID' => $item->ID())
1074
-                                                 ) . '</li>';
1075
-        }
1076
-        $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1077
-        return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
1078
-    }
1065
+		}
1066
+		$actions['filtered_messages_link'] = '';
1067
+		// message list table link (filtered by REG_ID
1068
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
1069
+			$actions['filtered_messages_link'] = '<li>'
1070
+												 . EEH_MSG_Template::get_message_action_link(
1071
+													 'see_notifications_for',
1072
+													 null,
1073
+													 array('_REG_ID' => $item->ID())
1074
+												 ) . '</li>';
1075
+		}
1076
+		$actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1077
+		return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
1078
+	}
1079 1079
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -54,10 +54,10 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function __construct(Registrations_Admin_Page $admin_page)
56 56
     {
57
-        if (! empty($_GET['event_id'])) {
57
+        if ( ! empty($_GET['event_id'])) {
58 58
             $extra_query_args = array();
59 59
             foreach ($admin_page->get_views() as $key => $view_details) {
60
-                $extra_query_args[ $view_details['slug'] ] = array('event_id' => $_GET['event_id']);
60
+                $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']);
61 61
             }
62 62
             $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
63 63
         }
@@ -157,12 +157,12 @@  discard block
 block discarded – undo
157 157
                 )
158 158
             )
159 159
         );
160
-        if (!empty($filters)) {
160
+        if ( ! empty($filters)) {
161 161
             $this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
162 162
         }
163 163
         $this->_primary_column = '_REG_ID';
164 164
         $this->_sortable_columns = array(
165
-            '_REG_date'     => array('_REG_date' => true),   // true means its already sorted
165
+            '_REG_date'     => array('_REG_date' => true), // true means its already sorted
166 166
             /**
167 167
              * Allows users to change the default sort if they wish.
168 168
              * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
     {
195 195
         $class = parent::_get_row_class($item);
196 196
         // add status class
197
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
197
+        $class .= ' ee-status-strip reg-status-'.$item->status_ID();
198 198
         if ($this->_has_checkbox_column) {
199 199
             $class .= ' has-checkbox-column';
200 200
         }
@@ -361,12 +361,12 @@  discard block
 block discarded – undo
361 361
         // setup date query.
362 362
         $beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
363 363
             'REG_date',
364
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
364
+            $this_year_r.'-'.$this_month_r.'-01'.' '.$time_start,
365 365
             'Y-m-d H:i:s'
366 366
         );
367 367
         $end_string = EEM_Registration::instance()->convert_datetime_for_query(
368 368
             'REG_date',
369
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
369
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' '.$time_end,
370 370
             'Y-m-d H:i:s'
371 371
         );
372 372
         $_where['REG_date'] = array(
@@ -403,12 +403,12 @@  discard block
 block discarded – undo
403 403
             array(
404 404
                 EEM_Registration::instance()->convert_datetime_for_query(
405 405
                     'REG_date',
406
-                    $current_date . $time_start,
406
+                    $current_date.$time_start,
407 407
                     'Y-m-d H:i:s'
408 408
                 ),
409 409
                 EEM_Registration::instance()->convert_datetime_for_query(
410 410
                     'REG_date',
411
-                    $current_date . $time_end,
411
+                    $current_date.$time_end,
412 412
                     'Y-m-d H:i:s'
413 413
                 ),
414 414
             ),
@@ -468,8 +468,8 @@  discard block
 block discarded – undo
468 468
         $content .= '<div class="show-on-mobile-view-only">';
469 469
         $content .= '<br>';
470 470
         $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
471
-        $content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
472
-        $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
471
+        $content .= '&nbsp;'.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
472
+        $content .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
473 473
         $content .= '</div>';
474 474
         return $content;
475 475
     }
@@ -554,12 +554,12 @@  discard block
 block discarded – undo
554 554
                   . $event_name
555 555
                   . '</a>' : $event_name;
556 556
             $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
557
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
557
+            $actions['event_filter'] = '<a href="'.$edit_event_url.'" title="';
558 558
             $actions['event_filter'] .= sprintf(
559 559
                 esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
560 560
                 $event_name
561 561
             );
562
-            $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
562
+            $actions['event_filter'] .= '">'.__('View Registrations', 'event_espresso').'</a>';
563 563
         } else {
564 564
             $edit_event = $event_name;
565 565
             $actions['event_filter'] = '';
@@ -606,11 +606,11 @@  discard block
 block discarded – undo
606 606
     {
607 607
         $content = '<div class="ee-registration-event-datetimes-container">';
608 608
         $expand_toggle = count($datetime_strings) > 1
609
-            ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
609
+            ? ' <span title="'.esc_attr__('Click to view all dates', 'event_espresso')
610 610
               . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
611 611
             : '';
612 612
         // get first item for initial visibility
613
-        $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
613
+        $content .= '<div class="left">'.array_shift($datetime_strings).'</div>';
614 614
         $content .= $expand_toggle;
615 615
         if ($datetime_strings) {
616 616
             $content .= '<div style="clear:both"></div>';
@@ -663,14 +663,14 @@  discard block
 block discarded – undo
663 663
         $t = $item->get_first_related('Transaction');
664 664
         $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
665 665
         // append group count to name
666
-        $link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
666
+        $link .= '&nbsp;'.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
667 667
         // append reg_code
668
-        $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
668
+        $link .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
669 669
         // reg status text for accessibility
670 670
         $link .= '<br><span class="ee-status-text-small">'
671 671
                  . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
672 672
                  . '</span>';
673
-        $action = [ '_REG_ID' => $item->ID() ];
673
+        $action = ['_REG_ID' => $item->ID()];
674 674
         if (isset($this->_req_data['event_id'])) {
675 675
             $action['event_id'] = $item->event_ID();
676 676
         }
@@ -694,7 +694,7 @@  discard block
 block discarded – undo
694 694
                                 . $trash_lnk_url
695 695
                                 . '" title="'
696 696
                                 . esc_attr__('Trash Registration', 'event_espresso')
697
-                                . '">' . __('Trash', 'event_espresso') . '</a>';
697
+                                . '">'.__('Trash', 'event_espresso').'</a>';
698 698
         } elseif ($this->_view === 'trash') {
699 699
             // restore registration link
700 700
             if (
@@ -712,8 +712,8 @@  discard block
 block discarded – undo
712 712
                 $actions['restore'] = '<a href="'
713 713
                                       . $restore_lnk_url
714 714
                                       . '" title="'
715
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
716
-                                      . __('Restore', 'event_espresso') . '</a>';
715
+                                      . esc_attr__('Restore Registration', 'event_espresso').'">'
716
+                                      . __('Restore', 'event_espresso').'</a>';
717 717
             }
718 718
             if (
719 719
                 EE_Registry::instance()->CAP->current_user_can(
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
                                                                               . $ticket->name()
789 789
                                                                               . '</span><br />' : '';
790 790
         if ($item->final_price() > 0) {
791
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
791
+            $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>';
792 792
         } else {
793 793
             // free event
794 794
             $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
             : '<span class="TKT_name">'
816 816
               . $ticket->name()
817 817
               . '</span><br />';
818
-        $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
818
+        $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>';
819 819
         return $content;
820 820
     }
821 821
 
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
         $payment_method = $item->payment_method();
834 834
         $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
835 835
             : __('Unknown', 'event_espresso');
836
-        $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
836
+        $content = '<span class="reg-pad-rght">'.$item->pretty_paid().'</span>';
837 837
         if ($item->paid() > 0) {
838 838
             $content .= '<br><span class="ee-status-text-small">'
839 839
                         . sprintf(
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
                   . esc_attr__('View Transaction', 'event_espresso')
882 882
                   . '">'
883 883
                   . $item->transaction()->pretty_total()
884
-                  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
884
+                  . '</a></span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_total().'</span>';
885 885
         } else {
886 886
             return __("None", "event_espresso");
887 887
         }
@@ -927,7 +927,7 @@  discard block
 block discarded – undo
927 927
                       . esc_attr__('View Transaction', 'event_espresso')
928 928
                       . '">'
929 929
                       . $item->transaction()->pretty_paid()
930
-                      . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
930
+                      . '</a><span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>';
931 931
             }
932 932
         }
933 933
         return '&nbsp;';
@@ -997,8 +997,8 @@  discard block
 block discarded – undo
997 997
                                && $attendee instanceof EE_Attendee
998 998
             ? '
999 999
 			<li>
1000
-			<a href="' . $edit_lnk_url . '" title="'
1001
-              . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
1000
+			<a href="' . $edit_lnk_url.'" title="'
1001
+              . esc_attr__('Edit Contact Details', 'event_espresso').'" class="tiny-text">
1002 1002
 				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
1003 1003
 			</a>
1004 1004
 			</li>' : '';
@@ -1071,7 +1071,7 @@  discard block
 block discarded – undo
1071 1071
                                                      'see_notifications_for',
1072 1072
                                                      null,
1073 1073
                                                      array('_REG_ID' => $item->ID())
1074
-                                                 ) . '</li>';
1074
+                                                 ).'</li>';
1075 1075
         }
1076 1076
         $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1077 1077
         return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
Please login to merge, or discard this patch.
core/EE_Capabilities.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
      * @since                        4.5.0
806 806
      *
807 807
      * @param string $meta_cap   What meta capability is this mapping.
808
-     * @param array  $map_values array {
808
+     * @param string[]  $map_values array {
809 809
      *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
810 810
      *                           capabilities that don't get mapped to.
811 811
      *
@@ -880,8 +880,8 @@  discard block
 block discarded – undo
880 880
      * @since 4.6.x
881 881
      *
882 882
      * @param $caps
883
-     * @param $cap
884
-     * @param $user_id
883
+     * @param string $cap
884
+     * @param integer $user_id
885 885
      * @param $args
886 886
      *
887 887
      * @return array
Please login to merge, or discard this patch.
Indentation   +1373 added lines, -1373 removed lines patch added patch discarded remove patch
@@ -14,984 +14,984 @@  discard block
 block discarded – undo
14 14
 final class EE_Capabilities extends EE_Base
15 15
 {
16 16
 
17
-    /**
18
-     * the name of the wp option used to store caps previously initialized
19
-     */
20
-    const option_name = 'ee_caps_initialized';
21
-
22
-    /**
23
-     * instance of EE_Capabilities object
24
-     *
25
-     * @var EE_Capabilities
26
-     */
27
-    private static $_instance;
28
-
29
-
30
-    /**
31
-     * This is a map of caps that correspond to a default WP_Role.
32
-     * Array is indexed by Role and values are ee capabilities.
33
-     *
34
-     * @since 4.5.0
35
-     *
36
-     * @var array
37
-     */
38
-    private $capabilities_map = array();
39
-
40
-    /**
41
-     * This used to hold an array of EE_Meta_Capability_Map objects
42
-     * that define the granular capabilities mapped to for a user depending on context.
43
-     *
44
-     * @var EE_Meta_Capability_Map[]
45
-     */
46
-    private $_meta_caps = array();
47
-
48
-    /**
49
-     * The internal $capabilities_map needs to be initialized before it can be used.
50
-     * This flag tracks whether that has happened or not.
51
-     * But for this to work, we need three states to indicate:
52
-     *      initialization has not occurred at all
53
-     *      initialization has started but is not complete
54
-     *      initialization is complete
55
-     * The reason this is needed is because the addCaps() method
56
-     * normally requires the $capabilities_map to be initialized,
57
-     * but is also used during the initialization process.
58
-     * So:
59
-     *      If initialized === null, init_caps() will be called before any other methods will run.
60
-     *      If initialized === false, then init_caps() is in the process of running it's logic.
61
-     *      If initialized === true, then init_caps() has completed the initialization process.
62
-     *
63
-     * @var boolean|null $initialized
64
-     */
65
-    private $initialized;
66
-
67
-    /**
68
-     * @var boolean $reset
69
-     */
70
-    private $reset = false;
71
-
72
-
73
-    /**
74
-     * singleton method used to instantiate class object
75
-     *
76
-     * @since 4.5.0
77
-     *
78
-     * @return EE_Capabilities
79
-     */
80
-    public static function instance()
81
-    {
82
-        // check if instantiated, and if not do so.
83
-        if (! self::$_instance instanceof EE_Capabilities) {
84
-            self::$_instance = new self();
85
-        }
86
-        return self::$_instance;
87
-    }
88
-
89
-
90
-    /**
91
-     * private constructor
92
-     *
93
-     * @since 4.5.0
94
-     */
95
-    private function __construct()
96
-    {
97
-    }
98
-
99
-
100
-    /**
101
-     * This delays the initialization of the capabilities class until EE_System core is loaded and ready.
102
-     *
103
-     * @param bool $reset allows for resetting the default capabilities saved on roles.  Note that this doesn't
104
-     *                    actually REMOVE any capabilities from existing roles, it just resaves defaults roles and
105
-     *                    ensures that they are up to date.
106
-     *
107
-     * @since 4.5.0
108
-     * @return bool
109
-     * @throws EE_Error
110
-     */
111
-    public function init_caps($reset = false)
112
-    {
113
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
114
-            return false;
115
-        }
116
-        $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN);
117
-        // if reset, then completely delete the cache option and clear the $capabilities_map property.
118
-        if ($this->reset) {
119
-            $this->initialized = null;
120
-            $this->capabilities_map = array();
121
-            delete_option(self::option_name);
122
-        }
123
-        if ($this->initialized === null) {
124
-            $this->initialized = false;
125
-            do_action(
126
-                'AHEE__EE_Capabilities__init_caps__before_initialization',
127
-                $this->reset
128
-            );
129
-            $this->addCaps($this->_init_caps_map());
130
-            $this->_set_meta_caps();
131
-            do_action(
132
-                'AHEE__EE_Capabilities__init_caps__after_initialization',
133
-                $this->capabilities_map
134
-            );
135
-            $this->initialized = true;
136
-        }
137
-        // reset $this->reset so that it's not stuck on true if init_caps() gets called again
138
-        $this->reset = false;
139
-        return true;
140
-    }
141
-
142
-
143
-    /**
144
-     * This sets the meta caps property.
145
-     *
146
-     * @since 4.5.0
147
-     * @return void
148
-     * @throws EE_Error
149
-     */
150
-    private function _set_meta_caps()
151
-    {
152
-        // get default meta caps and filter the returned array
153
-        $this->_meta_caps = apply_filters(
154
-            'FHEE__EE_Capabilities___set_meta_caps__meta_caps',
155
-            $this->_get_default_meta_caps_array()
156
-        );
157
-        // add filter for map_meta_caps but only if models can query.
158
-        if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
159
-            add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
160
-        }
161
-    }
162
-
163
-
164
-    /**
165
-     * This builds and returns the default meta_caps array only once.
166
-     *
167
-     * @since  4.8.28.rc.012
168
-     * @return array
169
-     * @throws EE_Error
170
-     */
171
-    private function _get_default_meta_caps_array()
172
-    {
173
-        static $default_meta_caps = array();
174
-        // make sure we're only ever initializing the default _meta_caps array once if it's empty.
175
-        if (empty($default_meta_caps)) {
176
-            $default_meta_caps = array(
177
-                // edits
178
-                new EE_Meta_Capability_Map_Edit(
179
-                    'ee_edit_event',
180
-                    array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')
181
-                ),
182
-                new EE_Meta_Capability_Map_Edit(
183
-                    'ee_edit_venue',
184
-                    array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')
185
-                ),
186
-                new EE_Meta_Capability_Map_Edit(
187
-                    'ee_edit_registration',
188
-                    array('Registration', '', 'ee_edit_others_registrations', '')
189
-                ),
190
-                new EE_Meta_Capability_Map_Edit(
191
-                    'ee_edit_checkin',
192
-                    array('Registration', '', 'ee_edit_others_checkins', '')
193
-                ),
194
-                new EE_Meta_Capability_Map_Messages_Cap(
195
-                    'ee_edit_message',
196
-                    array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')
197
-                ),
198
-                new EE_Meta_Capability_Map_Edit(
199
-                    'ee_edit_default_ticket',
200
-                    array('Ticket', '', 'ee_edit_others_default_tickets', '')
201
-                ),
202
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
203
-                    'ee_edit_question',
204
-                    array('Question', '', '', 'ee_edit_system_questions')
205
-                ),
206
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
207
-                    'ee_edit_question_group',
208
-                    array('Question_Group', '', '', 'ee_edit_system_question_groups')
209
-                ),
210
-                new EE_Meta_Capability_Map_Edit(
211
-                    'ee_edit_payment_method',
212
-                    array('Payment_Method', '', 'ee_edit_others_payment_methods', '')
213
-                ),
214
-                // reads
215
-                new EE_Meta_Capability_Map_Read(
216
-                    'ee_read_event',
217
-                    array('Event', '', 'ee_read_others_events', 'ee_read_private_events')
218
-                ),
219
-                new EE_Meta_Capability_Map_Read(
220
-                    'ee_read_venue',
221
-                    array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')
222
-                ),
223
-                new EE_Meta_Capability_Map_Read(
224
-                    'ee_read_registration',
225
-                    array('Registration', '', 'ee_read_others_registrations', '')
226
-                ),
227
-                new EE_Meta_Capability_Map_Read(
228
-                    'ee_read_checkin',
229
-                    array('Registration', '', 'ee_read_others_checkins', '')
230
-                ),
231
-                new EE_Meta_Capability_Map_Messages_Cap(
232
-                    'ee_read_message',
233
-                    array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')
234
-                ),
235
-                new EE_Meta_Capability_Map_Read(
236
-                    'ee_read_default_ticket',
237
-                    array('Ticket', '', 'ee_read_others_default_tickets', '')
238
-                ),
239
-                new EE_Meta_Capability_Map_Read(
240
-                    'ee_read_payment_method',
241
-                    array('Payment_Method', '', 'ee_read_others_payment_methods', '')
242
-                ),
243
-                // deletes
244
-                new EE_Meta_Capability_Map_Delete(
245
-                    'ee_delete_event',
246
-                    array(
247
-                        'Event',
248
-                        'ee_delete_published_events',
249
-                        'ee_delete_others_events',
250
-                        'ee_delete_private_events',
251
-                    )
252
-                ),
253
-                new EE_Meta_Capability_Map_Delete(
254
-                    'ee_delete_venue',
255
-                    array(
256
-                        'Venue',
257
-                        'ee_delete_published_venues',
258
-                        'ee_delete_others_venues',
259
-                        'ee_delete_private_venues',
260
-                    )
261
-                ),
262
-                new EE_Meta_Capability_Map_Delete(
263
-                    'ee_delete_registration',
264
-                    array('Registration', '', 'ee_delete_others_registrations', '')
265
-                ),
266
-                new EE_Meta_Capability_Map_Delete(
267
-                    'ee_delete_checkin',
268
-                    array('Registration', '', 'ee_delete_others_checkins', '')
269
-                ),
270
-                new EE_Meta_Capability_Map_Messages_Cap(
271
-                    'ee_delete_message',
272
-                    array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')
273
-                ),
274
-                new EE_Meta_Capability_Map_Delete(
275
-                    'ee_delete_default_ticket',
276
-                    array('Ticket', '', 'ee_delete_others_default_tickets', '')
277
-                ),
278
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
279
-                    'ee_delete_question',
280
-                    array('Question', '', '', 'delete_system_questions')
281
-                ),
282
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
283
-                    'ee_delete_question_group',
284
-                    array('Question_Group', '', '', 'delete_system_question_groups')
285
-                ),
286
-                new EE_Meta_Capability_Map_Delete(
287
-                    'ee_delete_payment_method',
288
-                    array('Payment_Method', '', 'ee_delete_others_payment_methods', '')
289
-                ),
290
-            );
291
-        }
292
-        return $default_meta_caps;
293
-    }
294
-
295
-
296
-    /**
297
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
298
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
299
-     *
300
-     * The actual logic is carried out by implementer classes in their definition of _map_meta_caps.
301
-     *
302
-     * @since 4.5.0
303
-     * @see   wp-includes/capabilities.php
304
-     *
305
-     * @param array  $caps    actual users capabilities
306
-     * @param string $cap     initial capability name that is being checked (the "map" key)
307
-     * @param int    $user_id The user id
308
-     * @param array  $args    Adds context to the cap. Typically the object ID.
309
-     * @return array actual users capabilities
310
-     * @throws EE_Error
311
-     */
312
-    public function map_meta_caps($caps, $cap, $user_id, $args)
313
-    {
314
-        if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
315
-            // loop through our _meta_caps array
316
-            foreach ($this->_meta_caps as $meta_map) {
317
-                if (! $meta_map instanceof EE_Meta_Capability_Map) {
318
-                    continue;
319
-                }
320
-                // don't load models if there is no object ID in the args
321
-                if (! empty($args[0])) {
322
-                    $meta_map->ensure_is_model();
323
-                }
324
-                $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
325
-            }
326
-        }
327
-        return $caps;
328
-    }
329
-
330
-
331
-    /**
332
-     * This sets up and returns the initial capabilities map for Event Espresso
333
-     * Note this array is filtered.
334
-     * It is assumed that all available EE capabilities are assigned to the administrator role.
335
-     *
336
-     * @since 4.5.0
337
-     *
338
-     * @return array
339
-     */
340
-    private function _init_caps_map()
341
-    {
342
-        return apply_filters(
343
-            'FHEE__EE_Capabilities__init_caps_map__caps',
344
-            array(
345
-                'administrator'           => array(
346
-                    // basic access
347
-                    'ee_read_ee',
348
-                    // gateways
349
-                    /**
350
-                     * note that with payment method capabilities, although we've implemented
351
-                     * capability mapping which will be used for accessing payment methods owned by
352
-                     * other users.  This is not fully implemented yet in the payment method ui.
353
-                     * Currently only the "plural" caps are in active use.
354
-                     * (Specific payment method caps are in use as well).
355
-                     **/
356
-                    'ee_manage_gateways',
357
-                    'ee_read_payment_methods',
358
-                    'ee_read_others_payment_methods',
359
-                    'ee_edit_payment_methods',
360
-                    'ee_edit_others_payment_methods',
361
-                    'ee_delete_payment_methods',
362
-                    // events
363
-                    'ee_publish_events',
364
-                    'ee_read_private_events',
365
-                    'ee_read_others_events',
366
-                    'ee_read_events',
367
-                    'ee_edit_events',
368
-                    'ee_edit_published_events',
369
-                    'ee_edit_others_events',
370
-                    'ee_edit_private_events',
371
-                    'ee_delete_published_events',
372
-                    'ee_delete_private_events',
373
-                    'ee_delete_events',
374
-                    'ee_delete_others_events',
375
-                    // event categories
376
-                    'ee_manage_event_categories',
377
-                    'ee_edit_event_category',
378
-                    'ee_delete_event_category',
379
-                    'ee_assign_event_category',
380
-                    // venues
381
-                    'ee_publish_venues',
382
-                    'ee_read_venues',
383
-                    'ee_read_others_venues',
384
-                    'ee_read_private_venues',
385
-                    'ee_edit_venues',
386
-                    'ee_edit_others_venues',
387
-                    'ee_edit_published_venues',
388
-                    'ee_edit_private_venues',
389
-                    'ee_delete_venues',
390
-                    'ee_delete_others_venues',
391
-                    'ee_delete_private_venues',
392
-                    'ee_delete_published_venues',
393
-                    // venue categories
394
-                    'ee_manage_venue_categories',
395
-                    'ee_edit_venue_category',
396
-                    'ee_delete_venue_category',
397
-                    'ee_assign_venue_category',
398
-                    // contacts
399
-                    'ee_read_contacts',
400
-                    'ee_edit_contacts',
401
-                    'ee_delete_contacts',
402
-                    // registrations
403
-                    'ee_read_registrations',
404
-                    'ee_read_others_registrations',
405
-                    'ee_edit_registrations',
406
-                    'ee_edit_others_registrations',
407
-                    'ee_delete_registrations',
408
-                    'ee_delete_others_registrations',
409
-                    // checkins
410
-                    'ee_read_others_checkins',
411
-                    'ee_read_checkins',
412
-                    'ee_edit_checkins',
413
-                    'ee_edit_others_checkins',
414
-                    'ee_delete_checkins',
415
-                    'ee_delete_others_checkins',
416
-                    // transactions && payments
417
-                    'ee_read_transaction',
418
-                    'ee_read_transactions',
419
-                    'ee_edit_payments',
420
-                    'ee_delete_payments',
421
-                    // messages
422
-                    'ee_read_messages',
423
-                    'ee_read_others_messages',
424
-                    'ee_read_global_messages',
425
-                    'ee_edit_global_messages',
426
-                    'ee_edit_messages',
427
-                    'ee_edit_others_messages',
428
-                    'ee_delete_messages',
429
-                    'ee_delete_others_messages',
430
-                    'ee_delete_global_messages',
431
-                    'ee_send_message',
432
-                    // tickets
433
-                    'ee_read_default_tickets',
434
-                    'ee_read_others_default_tickets',
435
-                    'ee_edit_default_tickets',
436
-                    'ee_edit_others_default_tickets',
437
-                    'ee_delete_default_tickets',
438
-                    'ee_delete_others_default_tickets',
439
-                    // prices
440
-                    'ee_edit_default_price',
441
-                    'ee_edit_default_prices',
442
-                    'ee_delete_default_price',
443
-                    'ee_delete_default_prices',
444
-                    'ee_edit_default_price_type',
445
-                    'ee_edit_default_price_types',
446
-                    'ee_delete_default_price_type',
447
-                    'ee_delete_default_price_types',
448
-                    'ee_read_default_prices',
449
-                    'ee_read_default_price_types',
450
-                    // registration form
451
-                    'ee_edit_questions',
452
-                    'ee_edit_system_questions',
453
-                    'ee_read_questions',
454
-                    'ee_delete_questions',
455
-                    'ee_edit_question_groups',
456
-                    'ee_read_question_groups',
457
-                    'ee_edit_system_question_groups',
458
-                    'ee_delete_question_groups',
459
-                    // event_type taxonomy
460
-                    'ee_assign_event_type',
461
-                    'ee_manage_event_types',
462
-                    'ee_edit_event_type',
463
-                    'ee_delete_event_type',
464
-                ),
465
-                'ee_events_administrator' => array(
466
-                    // core wp caps
467
-                    'read',
468
-                    'read_private_pages',
469
-                    'read_private_posts',
470
-                    'edit_users',
471
-                    'edit_posts',
472
-                    'edit_pages',
473
-                    'edit_published_posts',
474
-                    'edit_published_pages',
475
-                    'edit_private_pages',
476
-                    'edit_private_posts',
477
-                    'edit_others_posts',
478
-                    'edit_others_pages',
479
-                    'publish_posts',
480
-                    'publish_pages',
481
-                    'delete_posts',
482
-                    'delete_pages',
483
-                    'delete_private_pages',
484
-                    'delete_private_posts',
485
-                    'delete_published_pages',
486
-                    'delete_published_posts',
487
-                    'delete_others_posts',
488
-                    'delete_others_pages',
489
-                    'manage_categories',
490
-                    'manage_links',
491
-                    'moderate_comments',
492
-                    'unfiltered_html',
493
-                    'upload_files',
494
-                    'export',
495
-                    'import',
496
-                    'list_users',
497
-                    'level_1', // required if user with this role shows up in author dropdowns
498
-                    // basic ee access
499
-                    'ee_read_ee',
500
-                    // events
501
-                    'ee_publish_events',
502
-                    'ee_read_private_events',
503
-                    'ee_read_others_events',
504
-                    'ee_read_event',
505
-                    'ee_read_events',
506
-                    'ee_edit_event',
507
-                    'ee_edit_events',
508
-                    'ee_edit_published_events',
509
-                    'ee_edit_others_events',
510
-                    'ee_edit_private_events',
511
-                    'ee_delete_published_events',
512
-                    'ee_delete_private_events',
513
-                    'ee_delete_event',
514
-                    'ee_delete_events',
515
-                    'ee_delete_others_events',
516
-                    // event categories
517
-                    'ee_manage_event_categories',
518
-                    'ee_edit_event_category',
519
-                    'ee_delete_event_category',
520
-                    'ee_assign_event_category',
521
-                    // venues
522
-                    'ee_publish_venues',
523
-                    'ee_read_venue',
524
-                    'ee_read_venues',
525
-                    'ee_read_others_venues',
526
-                    'ee_read_private_venues',
527
-                    'ee_edit_venue',
528
-                    'ee_edit_venues',
529
-                    'ee_edit_others_venues',
530
-                    'ee_edit_published_venues',
531
-                    'ee_edit_private_venues',
532
-                    'ee_delete_venue',
533
-                    'ee_delete_venues',
534
-                    'ee_delete_others_venues',
535
-                    'ee_delete_private_venues',
536
-                    'ee_delete_published_venues',
537
-                    // venue categories
538
-                    'ee_manage_venue_categories',
539
-                    'ee_edit_venue_category',
540
-                    'ee_delete_venue_category',
541
-                    'ee_assign_venue_category',
542
-                    // contacts
543
-                    'ee_read_contacts',
544
-                    'ee_edit_contacts',
545
-                    'ee_delete_contacts',
546
-                    // registrations
547
-                    'ee_read_registrations',
548
-                    'ee_read_others_registrations',
549
-                    'ee_edit_registration',
550
-                    'ee_edit_registrations',
551
-                    'ee_edit_others_registrations',
552
-                    'ee_delete_registration',
553
-                    'ee_delete_registrations',
554
-                    'ee_delete_others_registrations',
555
-                    // checkins
556
-                    'ee_read_others_checkins',
557
-                    'ee_read_checkins',
558
-                    'ee_edit_checkins',
559
-                    'ee_edit_others_checkins',
560
-                    'ee_delete_checkins',
561
-                    'ee_delete_others_checkins',
562
-                    // transactions && payments
563
-                    'ee_read_transaction',
564
-                    'ee_read_transactions',
565
-                    'ee_edit_payments',
566
-                    'ee_delete_payments',
567
-                    // messages
568
-                    'ee_read_messages',
569
-                    'ee_read_others_messages',
570
-                    'ee_read_global_messages',
571
-                    'ee_edit_global_messages',
572
-                    'ee_edit_messages',
573
-                    'ee_edit_others_messages',
574
-                    'ee_delete_messages',
575
-                    'ee_delete_others_messages',
576
-                    'ee_delete_global_messages',
577
-                    'ee_send_message',
578
-                    // tickets
579
-                    'ee_read_default_tickets',
580
-                    'ee_read_others_default_tickets',
581
-                    'ee_edit_default_tickets',
582
-                    'ee_edit_others_default_tickets',
583
-                    'ee_delete_default_tickets',
584
-                    'ee_delete_others_default_tickets',
585
-                    // prices
586
-                    'ee_edit_default_price',
587
-                    'ee_edit_default_prices',
588
-                    'ee_delete_default_price',
589
-                    'ee_delete_default_prices',
590
-                    'ee_edit_default_price_type',
591
-                    'ee_edit_default_price_types',
592
-                    'ee_delete_default_price_type',
593
-                    'ee_delete_default_price_types',
594
-                    'ee_read_default_prices',
595
-                    'ee_read_default_price_types',
596
-                    // registration form
597
-                    'ee_edit_questions',
598
-                    'ee_edit_system_questions',
599
-                    'ee_read_questions',
600
-                    'ee_delete_questions',
601
-                    'ee_edit_question_groups',
602
-                    'ee_read_question_groups',
603
-                    'ee_edit_system_question_groups',
604
-                    'ee_delete_question_groups',
605
-                    // event_type taxonomy
606
-                    'ee_assign_event_type',
607
-                    'ee_manage_event_types',
608
-                    'ee_edit_event_type',
609
-                    'ee_delete_event_type',
610
-                ),
611
-            )
612
-        );
613
-    }
614
-
615
-
616
-    /**
617
-     * @return bool
618
-     * @throws EE_Error
619
-     */
620
-    private function setupCapabilitiesMap()
621
-    {
622
-        // if the initialization process hasn't even started, then we need to call init_caps()
623
-        if ($this->initialized === null) {
624
-            return $this->init_caps();
625
-        }
626
-        // unless resetting, get caps from db if we haven't already
627
-        $this->capabilities_map = $this->reset || ! empty($this->capabilities_map)
628
-            ? $this->capabilities_map
629
-            : get_option(self::option_name, array());
630
-        return true;
631
-    }
632
-
633
-
634
-    /**
635
-     * @param bool $update
636
-     * @return bool
637
-     */
638
-    private function updateCapabilitiesMap($update = true)
639
-    {
640
-        return $update ? update_option(self::option_name, $this->capabilities_map) : false;
641
-    }
642
-
643
-
644
-    /**
645
-     * Adds capabilities to roles.
646
-     *
647
-     * @since 4.9.42
648
-     * @param array $capabilities_to_add array of capabilities to add, indexed by roles.
649
-     *                                   Note that this should ONLY be called on activation hook
650
-     *                                   otherwise the caps will be added on every request.
651
-     * @return bool
652
-     * @throws \EE_Error
653
-     */
654
-    public function addCaps(array $capabilities_to_add)
655
-    {
656
-        // don't do anything if the capabilities map can not be initialized
657
-        if (! $this->setupCapabilitiesMap()) {
658
-            return false;
659
-        }
660
-        // and filter the array so others can get in on the fun during resets
661
-        $capabilities_to_add = apply_filters(
662
-            'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
663
-            $capabilities_to_add,
664
-            $this->reset,
665
-            $this->capabilities_map
666
-        );
667
-        $update_capabilities_map = false;
668
-        // if not reset, see what caps are new for each role. if they're new, add them.
669
-        foreach ($capabilities_to_add as $role => $caps_for_role) {
670
-            if (is_array($caps_for_role)) {
671
-                foreach ($caps_for_role as $cap) {
672
-                    if (
673
-                        ! $this->capHasBeenAddedToRole($role, $cap)
674
-                        && $this->add_cap_to_role($role, $cap, true, false)
675
-                    ) {
676
-                        $update_capabilities_map = true;
677
-                    }
678
-                }
679
-            }
680
-        }
681
-        // now let's just save the cap that has been set but only if there's been a change.
682
-        $updated = $this->updateCapabilitiesMap($update_capabilities_map);
683
-        $this->flushWpUser($updated);
684
-        do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated);
685
-        return $updated;
686
-    }
687
-
688
-
689
-    /**
690
-     * Loops through the capabilities map and removes the role caps specified by the incoming array
691
-     *
692
-     * @param array $caps_map map of capabilities to be removed (indexed by roles)
693
-     * @return bool
694
-     * @throws \EE_Error
695
-     */
696
-    public function removeCaps($caps_map)
697
-    {
698
-        // don't do anything if the capabilities map can not be initialized
699
-        if (! $this->setupCapabilitiesMap()) {
700
-            return false;
701
-        }
702
-        $update_capabilities_map = false;
703
-        foreach ($caps_map as $role => $caps_for_role) {
704
-            if (is_array($caps_for_role)) {
705
-                foreach ($caps_for_role as $cap) {
706
-                    if (
707
-                        $this->capHasBeenAddedToRole($role, $cap)
708
-                        && $this->remove_cap_from_role($role, $cap, false)
709
-                    ) {
710
-                        $update_capabilities_map = true;
711
-                    }
712
-                }
713
-            }
714
-        }
715
-        // maybe resave the caps
716
-        $updated = $this->updateCapabilitiesMap($update_capabilities_map);
717
-        $this->flushWpUser($updated);
718
-        return $updated;
719
-    }
720
-
721
-
722
-    /**
723
-     * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from
724
-     * the roles on that user.
725
-     *
726
-     * @param bool $flush Default is to flush the WP_User object.  If false, then this method effectively does nothing.
727
-     */
728
-    private function flushWpUser($flush = true)
729
-    {
730
-        if ($flush) {
731
-            $user = wp_get_current_user();
732
-            if ($user instanceof WP_User) {
733
-                $user->get_role_caps();
734
-            }
735
-        }
736
-    }
737
-
738
-
739
-    /**
740
-     * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
741
-     * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
742
-     * this is a wrapper for $wp_role->add_cap()
743
-     *
744
-     * @see   wp-includes/capabilities.php
745
-     * @since 4.5.0
746
-     * @param string|WP_Role $role  A WordPress role the capability is being added to
747
-     * @param string         $cap   The capability being added to the role
748
-     * @param bool           $grant Whether to grant access to this cap on this role.
749
-     * @param bool           $update_capabilities_map
750
-     * @return bool
751
-     * @throws \EE_Error
752
-     */
753
-    public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true)
754
-    {
755
-        // capture incoming value for $role because we may need it to create a new WP_Role
756
-        $orig_role = $role;
757
-        $role = $role instanceof WP_Role ? $role : get_role($role);
758
-        // if the role isn't available then we create it.
759
-        if (! $role instanceof WP_Role) {
760
-            // if a plugin wants to create a specific role name then they should create the role before
761
-            // EE_Capabilities does.  Otherwise this function will create the role name from the slug:
762
-            // - removes any `ee_` namespacing from the start of the slug.
763
-            // - replaces `_` with ` ` (empty space).
764
-            // - sentence case on the resulting string.
765
-            $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role));
766
-            $role = add_role($orig_role, $role_label);
767
-        }
768
-        if ($role instanceof WP_Role) {
769
-            // don't do anything if the capabilities map can not be initialized
770
-            if (! $this->setupCapabilitiesMap()) {
771
-                return false;
772
-            }
773
-            if (! $this->capHasBeenAddedToRole($role->name, $cap)) {
774
-                $role->add_cap($cap, $grant);
775
-                $this->capabilities_map[ $role->name ][] = $cap;
776
-                $this->updateCapabilitiesMap($update_capabilities_map);
777
-                return true;
778
-            }
779
-        }
780
-        return false;
781
-    }
782
-
783
-
784
-    /**
785
-     * Functions similarly to add_cap_to_role except removes cap from given role.
786
-     * Wrapper for $wp_role->remove_cap()
787
-     *
788
-     * @see   wp-includes/capabilities.php
789
-     * @since 4.5.0
790
-     * @param string|WP_Role $role A WordPress role the capability is being removed from.
791
-     * @param string         $cap  The capability being removed
792
-     * @param bool           $update_capabilities_map
793
-     * @return bool
794
-     * @throws \EE_Error
795
-     */
796
-    public function remove_cap_from_role($role, $cap, $update_capabilities_map = true)
797
-    {
798
-        // don't do anything if the capabilities map can not be initialized
799
-        if (! $this->setupCapabilitiesMap()) {
800
-            return false;
801
-        }
802
-
803
-        $role = $role instanceof WP_Role ? $role : get_role($role);
804
-        if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) {
805
-            $role->remove_cap($cap);
806
-            unset($this->capabilities_map[ $role->name ][ $index ]);
807
-            $this->updateCapabilitiesMap($update_capabilities_map);
808
-            return true;
809
-        }
810
-        return false;
811
-    }
812
-
813
-
814
-    /**
815
-     * @param string $role_name
816
-     * @param string $cap
817
-     * @param bool   $get_index
818
-     * @return bool|mixed
819
-     */
820
-    private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false)
821
-    {
822
-        if (
823
-            isset($this->capabilities_map[ $role_name ])
824
-            && ($index = array_search($cap, $this->capabilities_map[ $role_name ], true)) !== false
825
-        ) {
826
-            return $get_index ? $index : true;
827
-        }
828
-        return false;
829
-    }
830
-
831
-
832
-    /**
833
-     * Wrapper for the native WP current_user_can() method.
834
-     * This is provided as a handy method for a couple things:
835
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
836
-     * write those filters wherever current_user_can is called).
837
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
838
-     *
839
-     * @since 4.5.0
840
-     *
841
-     * @param string $cap     The cap being checked.
842
-     * @param string $context The context where the current_user_can is being called from.
843
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
844
-     *                        filters.
845
-     *
846
-     * @return bool  Whether user can or not.
847
-     */
848
-    public function current_user_can($cap, $context, $id = 0)
849
-    {
850
-        // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
851
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
852
-        $filtered_cap = apply_filters(
853
-            'FHEE__EE_Capabilities__current_user_can__cap',
854
-            $filtered_cap,
855
-            $context,
856
-            $cap,
857
-            $id
858
-        );
859
-        return ! empty($id)
860
-            ? current_user_can($filtered_cap, $id)
861
-            : current_user_can($filtered_cap);
862
-    }
863
-
864
-
865
-    /**
866
-     * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
867
-     *
868
-     * @param int|WP_User $user    Either the user_id or a WP_User object
869
-     * @param string      $cap     The capability string being checked
870
-     * @param string      $context The context where the user_can is being called from (used in filters).
871
-     * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
872
-     *                             filters)
873
-     *
874
-     * @return bool Whether user can or not.
875
-     */
876
-    public function user_can($user, $cap, $context, $id = 0)
877
-    {
878
-        // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
879
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
880
-        $filtered_cap = apply_filters(
881
-            'FHEE__EE_Capabilities__user_can__cap',
882
-            $filtered_cap,
883
-            $context,
884
-            $cap,
885
-            $user,
886
-            $id
887
-        );
888
-        return ! empty($id)
889
-            ? user_can($user, $filtered_cap, $id)
890
-            : user_can($user, $filtered_cap);
891
-    }
892
-
893
-
894
-    /**
895
-     * Wrapper for the native WP current_user_can_for_blog() method.
896
-     * This is provided as a handy method for a couple things:
897
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
898
-     * write those filters wherever current_user_can is called).
899
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
900
-     *
901
-     * @since 4.5.0
902
-     *
903
-     * @param int    $blog_id The blog id that is being checked for.
904
-     * @param string $cap     The cap being checked.
905
-     * @param string $context The context where the current_user_can is being called from.
906
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
907
-     *                        filters.
908
-     *
909
-     * @return bool  Whether user can or not.
910
-     */
911
-    public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
912
-    {
913
-        $user_can = ! empty($id)
914
-            ? current_user_can_for_blog($blog_id, $cap, $id)
915
-            : current_user_can($blog_id, $cap);
916
-        // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
917
-        $user_can = apply_filters(
918
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
919
-            $user_can,
920
-            $blog_id,
921
-            $cap,
922
-            $id
923
-        );
924
-        $user_can = apply_filters(
925
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
926
-            $user_can,
927
-            $context,
928
-            $blog_id,
929
-            $cap,
930
-            $id
931
-        );
932
-        return $user_can;
933
-    }
934
-
935
-
936
-    /**
937
-     * This helper method just returns an array of registered EE capabilities.
938
-     *
939
-     * @since 4.5.0
940
-     * @param string $role If empty then the entire role/capability map is returned.
941
-     *                     Otherwise just the capabilities for the given role are returned.
942
-     * @return array
943
-     * @throws EE_Error
944
-     */
945
-    public function get_ee_capabilities($role = 'administrator')
946
-    {
947
-        if (! $this->initialized) {
948
-            $this->init_caps();
949
-        }
950
-        if (empty($role)) {
951
-            return $this->capabilities_map;
952
-        }
953
-        return isset($this->capabilities_map[ $role ])
954
-            ? $this->capabilities_map[ $role ]
955
-            : array();
956
-    }
957
-
958
-
959
-    /**
960
-     * @deprecated 4.9.42
961
-     * @param bool  $reset      If you need to reset Event Espresso's capabilities,
962
-     *                          then please use the init_caps() method with the "$reset" parameter set to "true"
963
-     * @param array $caps_map   Optional.
964
-     *                          Can be used to send a custom map of roles and capabilities for setting them up.
965
-     *                          Note that this should ONLY be called on activation hook or some other one-time
966
-     *                          task otherwise the caps will be added on every request.
967
-     * @return void
968
-     * @throws EE_Error
969
-     */
970
-    public function init_role_caps($reset = false, $caps_map = array())
971
-    {
972
-        // If this method is called directly and reset is set as 'true',
973
-        // then display a doing it wrong notice, because we want resets to go through init_caps()
974
-        // to guarantee that everything is set up correctly.
975
-        // This prevents the capabilities map getting reset incorrectly by direct calls to this method.
976
-        if ($reset) {
977
-            EE_Error::doing_it_wrong(
978
-                __METHOD__,
979
-                sprintf(
980
-                    esc_html__(
981
-                        'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".',
982
-                        'event_espresso'
983
-                    ),
984
-                    '$reset',
985
-                    __METHOD__ . '()',
986
-                    'EE_Capabilities::init_caps()',
987
-                    'true'
988
-                ),
989
-                '4.9.42',
990
-                '5.0.0'
991
-            );
992
-        }
993
-        $this->addCaps($caps_map);
994
-    }
17
+	/**
18
+	 * the name of the wp option used to store caps previously initialized
19
+	 */
20
+	const option_name = 'ee_caps_initialized';
21
+
22
+	/**
23
+	 * instance of EE_Capabilities object
24
+	 *
25
+	 * @var EE_Capabilities
26
+	 */
27
+	private static $_instance;
28
+
29
+
30
+	/**
31
+	 * This is a map of caps that correspond to a default WP_Role.
32
+	 * Array is indexed by Role and values are ee capabilities.
33
+	 *
34
+	 * @since 4.5.0
35
+	 *
36
+	 * @var array
37
+	 */
38
+	private $capabilities_map = array();
39
+
40
+	/**
41
+	 * This used to hold an array of EE_Meta_Capability_Map objects
42
+	 * that define the granular capabilities mapped to for a user depending on context.
43
+	 *
44
+	 * @var EE_Meta_Capability_Map[]
45
+	 */
46
+	private $_meta_caps = array();
47
+
48
+	/**
49
+	 * The internal $capabilities_map needs to be initialized before it can be used.
50
+	 * This flag tracks whether that has happened or not.
51
+	 * But for this to work, we need three states to indicate:
52
+	 *      initialization has not occurred at all
53
+	 *      initialization has started but is not complete
54
+	 *      initialization is complete
55
+	 * The reason this is needed is because the addCaps() method
56
+	 * normally requires the $capabilities_map to be initialized,
57
+	 * but is also used during the initialization process.
58
+	 * So:
59
+	 *      If initialized === null, init_caps() will be called before any other methods will run.
60
+	 *      If initialized === false, then init_caps() is in the process of running it's logic.
61
+	 *      If initialized === true, then init_caps() has completed the initialization process.
62
+	 *
63
+	 * @var boolean|null $initialized
64
+	 */
65
+	private $initialized;
66
+
67
+	/**
68
+	 * @var boolean $reset
69
+	 */
70
+	private $reset = false;
71
+
72
+
73
+	/**
74
+	 * singleton method used to instantiate class object
75
+	 *
76
+	 * @since 4.5.0
77
+	 *
78
+	 * @return EE_Capabilities
79
+	 */
80
+	public static function instance()
81
+	{
82
+		// check if instantiated, and if not do so.
83
+		if (! self::$_instance instanceof EE_Capabilities) {
84
+			self::$_instance = new self();
85
+		}
86
+		return self::$_instance;
87
+	}
88
+
89
+
90
+	/**
91
+	 * private constructor
92
+	 *
93
+	 * @since 4.5.0
94
+	 */
95
+	private function __construct()
96
+	{
97
+	}
98
+
99
+
100
+	/**
101
+	 * This delays the initialization of the capabilities class until EE_System core is loaded and ready.
102
+	 *
103
+	 * @param bool $reset allows for resetting the default capabilities saved on roles.  Note that this doesn't
104
+	 *                    actually REMOVE any capabilities from existing roles, it just resaves defaults roles and
105
+	 *                    ensures that they are up to date.
106
+	 *
107
+	 * @since 4.5.0
108
+	 * @return bool
109
+	 * @throws EE_Error
110
+	 */
111
+	public function init_caps($reset = false)
112
+	{
113
+		if (! EE_Maintenance_Mode::instance()->models_can_query()) {
114
+			return false;
115
+		}
116
+		$this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN);
117
+		// if reset, then completely delete the cache option and clear the $capabilities_map property.
118
+		if ($this->reset) {
119
+			$this->initialized = null;
120
+			$this->capabilities_map = array();
121
+			delete_option(self::option_name);
122
+		}
123
+		if ($this->initialized === null) {
124
+			$this->initialized = false;
125
+			do_action(
126
+				'AHEE__EE_Capabilities__init_caps__before_initialization',
127
+				$this->reset
128
+			);
129
+			$this->addCaps($this->_init_caps_map());
130
+			$this->_set_meta_caps();
131
+			do_action(
132
+				'AHEE__EE_Capabilities__init_caps__after_initialization',
133
+				$this->capabilities_map
134
+			);
135
+			$this->initialized = true;
136
+		}
137
+		// reset $this->reset so that it's not stuck on true if init_caps() gets called again
138
+		$this->reset = false;
139
+		return true;
140
+	}
141
+
142
+
143
+	/**
144
+	 * This sets the meta caps property.
145
+	 *
146
+	 * @since 4.5.0
147
+	 * @return void
148
+	 * @throws EE_Error
149
+	 */
150
+	private function _set_meta_caps()
151
+	{
152
+		// get default meta caps and filter the returned array
153
+		$this->_meta_caps = apply_filters(
154
+			'FHEE__EE_Capabilities___set_meta_caps__meta_caps',
155
+			$this->_get_default_meta_caps_array()
156
+		);
157
+		// add filter for map_meta_caps but only if models can query.
158
+		if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
159
+			add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
160
+		}
161
+	}
162
+
163
+
164
+	/**
165
+	 * This builds and returns the default meta_caps array only once.
166
+	 *
167
+	 * @since  4.8.28.rc.012
168
+	 * @return array
169
+	 * @throws EE_Error
170
+	 */
171
+	private function _get_default_meta_caps_array()
172
+	{
173
+		static $default_meta_caps = array();
174
+		// make sure we're only ever initializing the default _meta_caps array once if it's empty.
175
+		if (empty($default_meta_caps)) {
176
+			$default_meta_caps = array(
177
+				// edits
178
+				new EE_Meta_Capability_Map_Edit(
179
+					'ee_edit_event',
180
+					array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')
181
+				),
182
+				new EE_Meta_Capability_Map_Edit(
183
+					'ee_edit_venue',
184
+					array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')
185
+				),
186
+				new EE_Meta_Capability_Map_Edit(
187
+					'ee_edit_registration',
188
+					array('Registration', '', 'ee_edit_others_registrations', '')
189
+				),
190
+				new EE_Meta_Capability_Map_Edit(
191
+					'ee_edit_checkin',
192
+					array('Registration', '', 'ee_edit_others_checkins', '')
193
+				),
194
+				new EE_Meta_Capability_Map_Messages_Cap(
195
+					'ee_edit_message',
196
+					array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')
197
+				),
198
+				new EE_Meta_Capability_Map_Edit(
199
+					'ee_edit_default_ticket',
200
+					array('Ticket', '', 'ee_edit_others_default_tickets', '')
201
+				),
202
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
203
+					'ee_edit_question',
204
+					array('Question', '', '', 'ee_edit_system_questions')
205
+				),
206
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
207
+					'ee_edit_question_group',
208
+					array('Question_Group', '', '', 'ee_edit_system_question_groups')
209
+				),
210
+				new EE_Meta_Capability_Map_Edit(
211
+					'ee_edit_payment_method',
212
+					array('Payment_Method', '', 'ee_edit_others_payment_methods', '')
213
+				),
214
+				// reads
215
+				new EE_Meta_Capability_Map_Read(
216
+					'ee_read_event',
217
+					array('Event', '', 'ee_read_others_events', 'ee_read_private_events')
218
+				),
219
+				new EE_Meta_Capability_Map_Read(
220
+					'ee_read_venue',
221
+					array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')
222
+				),
223
+				new EE_Meta_Capability_Map_Read(
224
+					'ee_read_registration',
225
+					array('Registration', '', 'ee_read_others_registrations', '')
226
+				),
227
+				new EE_Meta_Capability_Map_Read(
228
+					'ee_read_checkin',
229
+					array('Registration', '', 'ee_read_others_checkins', '')
230
+				),
231
+				new EE_Meta_Capability_Map_Messages_Cap(
232
+					'ee_read_message',
233
+					array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')
234
+				),
235
+				new EE_Meta_Capability_Map_Read(
236
+					'ee_read_default_ticket',
237
+					array('Ticket', '', 'ee_read_others_default_tickets', '')
238
+				),
239
+				new EE_Meta_Capability_Map_Read(
240
+					'ee_read_payment_method',
241
+					array('Payment_Method', '', 'ee_read_others_payment_methods', '')
242
+				),
243
+				// deletes
244
+				new EE_Meta_Capability_Map_Delete(
245
+					'ee_delete_event',
246
+					array(
247
+						'Event',
248
+						'ee_delete_published_events',
249
+						'ee_delete_others_events',
250
+						'ee_delete_private_events',
251
+					)
252
+				),
253
+				new EE_Meta_Capability_Map_Delete(
254
+					'ee_delete_venue',
255
+					array(
256
+						'Venue',
257
+						'ee_delete_published_venues',
258
+						'ee_delete_others_venues',
259
+						'ee_delete_private_venues',
260
+					)
261
+				),
262
+				new EE_Meta_Capability_Map_Delete(
263
+					'ee_delete_registration',
264
+					array('Registration', '', 'ee_delete_others_registrations', '')
265
+				),
266
+				new EE_Meta_Capability_Map_Delete(
267
+					'ee_delete_checkin',
268
+					array('Registration', '', 'ee_delete_others_checkins', '')
269
+				),
270
+				new EE_Meta_Capability_Map_Messages_Cap(
271
+					'ee_delete_message',
272
+					array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')
273
+				),
274
+				new EE_Meta_Capability_Map_Delete(
275
+					'ee_delete_default_ticket',
276
+					array('Ticket', '', 'ee_delete_others_default_tickets', '')
277
+				),
278
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
279
+					'ee_delete_question',
280
+					array('Question', '', '', 'delete_system_questions')
281
+				),
282
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
283
+					'ee_delete_question_group',
284
+					array('Question_Group', '', '', 'delete_system_question_groups')
285
+				),
286
+				new EE_Meta_Capability_Map_Delete(
287
+					'ee_delete_payment_method',
288
+					array('Payment_Method', '', 'ee_delete_others_payment_methods', '')
289
+				),
290
+			);
291
+		}
292
+		return $default_meta_caps;
293
+	}
294
+
295
+
296
+	/**
297
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
298
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
299
+	 *
300
+	 * The actual logic is carried out by implementer classes in their definition of _map_meta_caps.
301
+	 *
302
+	 * @since 4.5.0
303
+	 * @see   wp-includes/capabilities.php
304
+	 *
305
+	 * @param array  $caps    actual users capabilities
306
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
307
+	 * @param int    $user_id The user id
308
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
309
+	 * @return array actual users capabilities
310
+	 * @throws EE_Error
311
+	 */
312
+	public function map_meta_caps($caps, $cap, $user_id, $args)
313
+	{
314
+		if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
315
+			// loop through our _meta_caps array
316
+			foreach ($this->_meta_caps as $meta_map) {
317
+				if (! $meta_map instanceof EE_Meta_Capability_Map) {
318
+					continue;
319
+				}
320
+				// don't load models if there is no object ID in the args
321
+				if (! empty($args[0])) {
322
+					$meta_map->ensure_is_model();
323
+				}
324
+				$caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
325
+			}
326
+		}
327
+		return $caps;
328
+	}
329
+
330
+
331
+	/**
332
+	 * This sets up and returns the initial capabilities map for Event Espresso
333
+	 * Note this array is filtered.
334
+	 * It is assumed that all available EE capabilities are assigned to the administrator role.
335
+	 *
336
+	 * @since 4.5.0
337
+	 *
338
+	 * @return array
339
+	 */
340
+	private function _init_caps_map()
341
+	{
342
+		return apply_filters(
343
+			'FHEE__EE_Capabilities__init_caps_map__caps',
344
+			array(
345
+				'administrator'           => array(
346
+					// basic access
347
+					'ee_read_ee',
348
+					// gateways
349
+					/**
350
+					 * note that with payment method capabilities, although we've implemented
351
+					 * capability mapping which will be used for accessing payment methods owned by
352
+					 * other users.  This is not fully implemented yet in the payment method ui.
353
+					 * Currently only the "plural" caps are in active use.
354
+					 * (Specific payment method caps are in use as well).
355
+					 **/
356
+					'ee_manage_gateways',
357
+					'ee_read_payment_methods',
358
+					'ee_read_others_payment_methods',
359
+					'ee_edit_payment_methods',
360
+					'ee_edit_others_payment_methods',
361
+					'ee_delete_payment_methods',
362
+					// events
363
+					'ee_publish_events',
364
+					'ee_read_private_events',
365
+					'ee_read_others_events',
366
+					'ee_read_events',
367
+					'ee_edit_events',
368
+					'ee_edit_published_events',
369
+					'ee_edit_others_events',
370
+					'ee_edit_private_events',
371
+					'ee_delete_published_events',
372
+					'ee_delete_private_events',
373
+					'ee_delete_events',
374
+					'ee_delete_others_events',
375
+					// event categories
376
+					'ee_manage_event_categories',
377
+					'ee_edit_event_category',
378
+					'ee_delete_event_category',
379
+					'ee_assign_event_category',
380
+					// venues
381
+					'ee_publish_venues',
382
+					'ee_read_venues',
383
+					'ee_read_others_venues',
384
+					'ee_read_private_venues',
385
+					'ee_edit_venues',
386
+					'ee_edit_others_venues',
387
+					'ee_edit_published_venues',
388
+					'ee_edit_private_venues',
389
+					'ee_delete_venues',
390
+					'ee_delete_others_venues',
391
+					'ee_delete_private_venues',
392
+					'ee_delete_published_venues',
393
+					// venue categories
394
+					'ee_manage_venue_categories',
395
+					'ee_edit_venue_category',
396
+					'ee_delete_venue_category',
397
+					'ee_assign_venue_category',
398
+					// contacts
399
+					'ee_read_contacts',
400
+					'ee_edit_contacts',
401
+					'ee_delete_contacts',
402
+					// registrations
403
+					'ee_read_registrations',
404
+					'ee_read_others_registrations',
405
+					'ee_edit_registrations',
406
+					'ee_edit_others_registrations',
407
+					'ee_delete_registrations',
408
+					'ee_delete_others_registrations',
409
+					// checkins
410
+					'ee_read_others_checkins',
411
+					'ee_read_checkins',
412
+					'ee_edit_checkins',
413
+					'ee_edit_others_checkins',
414
+					'ee_delete_checkins',
415
+					'ee_delete_others_checkins',
416
+					// transactions && payments
417
+					'ee_read_transaction',
418
+					'ee_read_transactions',
419
+					'ee_edit_payments',
420
+					'ee_delete_payments',
421
+					// messages
422
+					'ee_read_messages',
423
+					'ee_read_others_messages',
424
+					'ee_read_global_messages',
425
+					'ee_edit_global_messages',
426
+					'ee_edit_messages',
427
+					'ee_edit_others_messages',
428
+					'ee_delete_messages',
429
+					'ee_delete_others_messages',
430
+					'ee_delete_global_messages',
431
+					'ee_send_message',
432
+					// tickets
433
+					'ee_read_default_tickets',
434
+					'ee_read_others_default_tickets',
435
+					'ee_edit_default_tickets',
436
+					'ee_edit_others_default_tickets',
437
+					'ee_delete_default_tickets',
438
+					'ee_delete_others_default_tickets',
439
+					// prices
440
+					'ee_edit_default_price',
441
+					'ee_edit_default_prices',
442
+					'ee_delete_default_price',
443
+					'ee_delete_default_prices',
444
+					'ee_edit_default_price_type',
445
+					'ee_edit_default_price_types',
446
+					'ee_delete_default_price_type',
447
+					'ee_delete_default_price_types',
448
+					'ee_read_default_prices',
449
+					'ee_read_default_price_types',
450
+					// registration form
451
+					'ee_edit_questions',
452
+					'ee_edit_system_questions',
453
+					'ee_read_questions',
454
+					'ee_delete_questions',
455
+					'ee_edit_question_groups',
456
+					'ee_read_question_groups',
457
+					'ee_edit_system_question_groups',
458
+					'ee_delete_question_groups',
459
+					// event_type taxonomy
460
+					'ee_assign_event_type',
461
+					'ee_manage_event_types',
462
+					'ee_edit_event_type',
463
+					'ee_delete_event_type',
464
+				),
465
+				'ee_events_administrator' => array(
466
+					// core wp caps
467
+					'read',
468
+					'read_private_pages',
469
+					'read_private_posts',
470
+					'edit_users',
471
+					'edit_posts',
472
+					'edit_pages',
473
+					'edit_published_posts',
474
+					'edit_published_pages',
475
+					'edit_private_pages',
476
+					'edit_private_posts',
477
+					'edit_others_posts',
478
+					'edit_others_pages',
479
+					'publish_posts',
480
+					'publish_pages',
481
+					'delete_posts',
482
+					'delete_pages',
483
+					'delete_private_pages',
484
+					'delete_private_posts',
485
+					'delete_published_pages',
486
+					'delete_published_posts',
487
+					'delete_others_posts',
488
+					'delete_others_pages',
489
+					'manage_categories',
490
+					'manage_links',
491
+					'moderate_comments',
492
+					'unfiltered_html',
493
+					'upload_files',
494
+					'export',
495
+					'import',
496
+					'list_users',
497
+					'level_1', // required if user with this role shows up in author dropdowns
498
+					// basic ee access
499
+					'ee_read_ee',
500
+					// events
501
+					'ee_publish_events',
502
+					'ee_read_private_events',
503
+					'ee_read_others_events',
504
+					'ee_read_event',
505
+					'ee_read_events',
506
+					'ee_edit_event',
507
+					'ee_edit_events',
508
+					'ee_edit_published_events',
509
+					'ee_edit_others_events',
510
+					'ee_edit_private_events',
511
+					'ee_delete_published_events',
512
+					'ee_delete_private_events',
513
+					'ee_delete_event',
514
+					'ee_delete_events',
515
+					'ee_delete_others_events',
516
+					// event categories
517
+					'ee_manage_event_categories',
518
+					'ee_edit_event_category',
519
+					'ee_delete_event_category',
520
+					'ee_assign_event_category',
521
+					// venues
522
+					'ee_publish_venues',
523
+					'ee_read_venue',
524
+					'ee_read_venues',
525
+					'ee_read_others_venues',
526
+					'ee_read_private_venues',
527
+					'ee_edit_venue',
528
+					'ee_edit_venues',
529
+					'ee_edit_others_venues',
530
+					'ee_edit_published_venues',
531
+					'ee_edit_private_venues',
532
+					'ee_delete_venue',
533
+					'ee_delete_venues',
534
+					'ee_delete_others_venues',
535
+					'ee_delete_private_venues',
536
+					'ee_delete_published_venues',
537
+					// venue categories
538
+					'ee_manage_venue_categories',
539
+					'ee_edit_venue_category',
540
+					'ee_delete_venue_category',
541
+					'ee_assign_venue_category',
542
+					// contacts
543
+					'ee_read_contacts',
544
+					'ee_edit_contacts',
545
+					'ee_delete_contacts',
546
+					// registrations
547
+					'ee_read_registrations',
548
+					'ee_read_others_registrations',
549
+					'ee_edit_registration',
550
+					'ee_edit_registrations',
551
+					'ee_edit_others_registrations',
552
+					'ee_delete_registration',
553
+					'ee_delete_registrations',
554
+					'ee_delete_others_registrations',
555
+					// checkins
556
+					'ee_read_others_checkins',
557
+					'ee_read_checkins',
558
+					'ee_edit_checkins',
559
+					'ee_edit_others_checkins',
560
+					'ee_delete_checkins',
561
+					'ee_delete_others_checkins',
562
+					// transactions && payments
563
+					'ee_read_transaction',
564
+					'ee_read_transactions',
565
+					'ee_edit_payments',
566
+					'ee_delete_payments',
567
+					// messages
568
+					'ee_read_messages',
569
+					'ee_read_others_messages',
570
+					'ee_read_global_messages',
571
+					'ee_edit_global_messages',
572
+					'ee_edit_messages',
573
+					'ee_edit_others_messages',
574
+					'ee_delete_messages',
575
+					'ee_delete_others_messages',
576
+					'ee_delete_global_messages',
577
+					'ee_send_message',
578
+					// tickets
579
+					'ee_read_default_tickets',
580
+					'ee_read_others_default_tickets',
581
+					'ee_edit_default_tickets',
582
+					'ee_edit_others_default_tickets',
583
+					'ee_delete_default_tickets',
584
+					'ee_delete_others_default_tickets',
585
+					// prices
586
+					'ee_edit_default_price',
587
+					'ee_edit_default_prices',
588
+					'ee_delete_default_price',
589
+					'ee_delete_default_prices',
590
+					'ee_edit_default_price_type',
591
+					'ee_edit_default_price_types',
592
+					'ee_delete_default_price_type',
593
+					'ee_delete_default_price_types',
594
+					'ee_read_default_prices',
595
+					'ee_read_default_price_types',
596
+					// registration form
597
+					'ee_edit_questions',
598
+					'ee_edit_system_questions',
599
+					'ee_read_questions',
600
+					'ee_delete_questions',
601
+					'ee_edit_question_groups',
602
+					'ee_read_question_groups',
603
+					'ee_edit_system_question_groups',
604
+					'ee_delete_question_groups',
605
+					// event_type taxonomy
606
+					'ee_assign_event_type',
607
+					'ee_manage_event_types',
608
+					'ee_edit_event_type',
609
+					'ee_delete_event_type',
610
+				),
611
+			)
612
+		);
613
+	}
614
+
615
+
616
+	/**
617
+	 * @return bool
618
+	 * @throws EE_Error
619
+	 */
620
+	private function setupCapabilitiesMap()
621
+	{
622
+		// if the initialization process hasn't even started, then we need to call init_caps()
623
+		if ($this->initialized === null) {
624
+			return $this->init_caps();
625
+		}
626
+		// unless resetting, get caps from db if we haven't already
627
+		$this->capabilities_map = $this->reset || ! empty($this->capabilities_map)
628
+			? $this->capabilities_map
629
+			: get_option(self::option_name, array());
630
+		return true;
631
+	}
632
+
633
+
634
+	/**
635
+	 * @param bool $update
636
+	 * @return bool
637
+	 */
638
+	private function updateCapabilitiesMap($update = true)
639
+	{
640
+		return $update ? update_option(self::option_name, $this->capabilities_map) : false;
641
+	}
642
+
643
+
644
+	/**
645
+	 * Adds capabilities to roles.
646
+	 *
647
+	 * @since 4.9.42
648
+	 * @param array $capabilities_to_add array of capabilities to add, indexed by roles.
649
+	 *                                   Note that this should ONLY be called on activation hook
650
+	 *                                   otherwise the caps will be added on every request.
651
+	 * @return bool
652
+	 * @throws \EE_Error
653
+	 */
654
+	public function addCaps(array $capabilities_to_add)
655
+	{
656
+		// don't do anything if the capabilities map can not be initialized
657
+		if (! $this->setupCapabilitiesMap()) {
658
+			return false;
659
+		}
660
+		// and filter the array so others can get in on the fun during resets
661
+		$capabilities_to_add = apply_filters(
662
+			'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
663
+			$capabilities_to_add,
664
+			$this->reset,
665
+			$this->capabilities_map
666
+		);
667
+		$update_capabilities_map = false;
668
+		// if not reset, see what caps are new for each role. if they're new, add them.
669
+		foreach ($capabilities_to_add as $role => $caps_for_role) {
670
+			if (is_array($caps_for_role)) {
671
+				foreach ($caps_for_role as $cap) {
672
+					if (
673
+						! $this->capHasBeenAddedToRole($role, $cap)
674
+						&& $this->add_cap_to_role($role, $cap, true, false)
675
+					) {
676
+						$update_capabilities_map = true;
677
+					}
678
+				}
679
+			}
680
+		}
681
+		// now let's just save the cap that has been set but only if there's been a change.
682
+		$updated = $this->updateCapabilitiesMap($update_capabilities_map);
683
+		$this->flushWpUser($updated);
684
+		do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated);
685
+		return $updated;
686
+	}
687
+
688
+
689
+	/**
690
+	 * Loops through the capabilities map and removes the role caps specified by the incoming array
691
+	 *
692
+	 * @param array $caps_map map of capabilities to be removed (indexed by roles)
693
+	 * @return bool
694
+	 * @throws \EE_Error
695
+	 */
696
+	public function removeCaps($caps_map)
697
+	{
698
+		// don't do anything if the capabilities map can not be initialized
699
+		if (! $this->setupCapabilitiesMap()) {
700
+			return false;
701
+		}
702
+		$update_capabilities_map = false;
703
+		foreach ($caps_map as $role => $caps_for_role) {
704
+			if (is_array($caps_for_role)) {
705
+				foreach ($caps_for_role as $cap) {
706
+					if (
707
+						$this->capHasBeenAddedToRole($role, $cap)
708
+						&& $this->remove_cap_from_role($role, $cap, false)
709
+					) {
710
+						$update_capabilities_map = true;
711
+					}
712
+				}
713
+			}
714
+		}
715
+		// maybe resave the caps
716
+		$updated = $this->updateCapabilitiesMap($update_capabilities_map);
717
+		$this->flushWpUser($updated);
718
+		return $updated;
719
+	}
720
+
721
+
722
+	/**
723
+	 * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from
724
+	 * the roles on that user.
725
+	 *
726
+	 * @param bool $flush Default is to flush the WP_User object.  If false, then this method effectively does nothing.
727
+	 */
728
+	private function flushWpUser($flush = true)
729
+	{
730
+		if ($flush) {
731
+			$user = wp_get_current_user();
732
+			if ($user instanceof WP_User) {
733
+				$user->get_role_caps();
734
+			}
735
+		}
736
+	}
737
+
738
+
739
+	/**
740
+	 * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
741
+	 * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
742
+	 * this is a wrapper for $wp_role->add_cap()
743
+	 *
744
+	 * @see   wp-includes/capabilities.php
745
+	 * @since 4.5.0
746
+	 * @param string|WP_Role $role  A WordPress role the capability is being added to
747
+	 * @param string         $cap   The capability being added to the role
748
+	 * @param bool           $grant Whether to grant access to this cap on this role.
749
+	 * @param bool           $update_capabilities_map
750
+	 * @return bool
751
+	 * @throws \EE_Error
752
+	 */
753
+	public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true)
754
+	{
755
+		// capture incoming value for $role because we may need it to create a new WP_Role
756
+		$orig_role = $role;
757
+		$role = $role instanceof WP_Role ? $role : get_role($role);
758
+		// if the role isn't available then we create it.
759
+		if (! $role instanceof WP_Role) {
760
+			// if a plugin wants to create a specific role name then they should create the role before
761
+			// EE_Capabilities does.  Otherwise this function will create the role name from the slug:
762
+			// - removes any `ee_` namespacing from the start of the slug.
763
+			// - replaces `_` with ` ` (empty space).
764
+			// - sentence case on the resulting string.
765
+			$role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role));
766
+			$role = add_role($orig_role, $role_label);
767
+		}
768
+		if ($role instanceof WP_Role) {
769
+			// don't do anything if the capabilities map can not be initialized
770
+			if (! $this->setupCapabilitiesMap()) {
771
+				return false;
772
+			}
773
+			if (! $this->capHasBeenAddedToRole($role->name, $cap)) {
774
+				$role->add_cap($cap, $grant);
775
+				$this->capabilities_map[ $role->name ][] = $cap;
776
+				$this->updateCapabilitiesMap($update_capabilities_map);
777
+				return true;
778
+			}
779
+		}
780
+		return false;
781
+	}
782
+
783
+
784
+	/**
785
+	 * Functions similarly to add_cap_to_role except removes cap from given role.
786
+	 * Wrapper for $wp_role->remove_cap()
787
+	 *
788
+	 * @see   wp-includes/capabilities.php
789
+	 * @since 4.5.0
790
+	 * @param string|WP_Role $role A WordPress role the capability is being removed from.
791
+	 * @param string         $cap  The capability being removed
792
+	 * @param bool           $update_capabilities_map
793
+	 * @return bool
794
+	 * @throws \EE_Error
795
+	 */
796
+	public function remove_cap_from_role($role, $cap, $update_capabilities_map = true)
797
+	{
798
+		// don't do anything if the capabilities map can not be initialized
799
+		if (! $this->setupCapabilitiesMap()) {
800
+			return false;
801
+		}
802
+
803
+		$role = $role instanceof WP_Role ? $role : get_role($role);
804
+		if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) {
805
+			$role->remove_cap($cap);
806
+			unset($this->capabilities_map[ $role->name ][ $index ]);
807
+			$this->updateCapabilitiesMap($update_capabilities_map);
808
+			return true;
809
+		}
810
+		return false;
811
+	}
812
+
813
+
814
+	/**
815
+	 * @param string $role_name
816
+	 * @param string $cap
817
+	 * @param bool   $get_index
818
+	 * @return bool|mixed
819
+	 */
820
+	private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false)
821
+	{
822
+		if (
823
+			isset($this->capabilities_map[ $role_name ])
824
+			&& ($index = array_search($cap, $this->capabilities_map[ $role_name ], true)) !== false
825
+		) {
826
+			return $get_index ? $index : true;
827
+		}
828
+		return false;
829
+	}
830
+
831
+
832
+	/**
833
+	 * Wrapper for the native WP current_user_can() method.
834
+	 * This is provided as a handy method for a couple things:
835
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
836
+	 * write those filters wherever current_user_can is called).
837
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
838
+	 *
839
+	 * @since 4.5.0
840
+	 *
841
+	 * @param string $cap     The cap being checked.
842
+	 * @param string $context The context where the current_user_can is being called from.
843
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
844
+	 *                        filters.
845
+	 *
846
+	 * @return bool  Whether user can or not.
847
+	 */
848
+	public function current_user_can($cap, $context, $id = 0)
849
+	{
850
+		// apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
851
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
852
+		$filtered_cap = apply_filters(
853
+			'FHEE__EE_Capabilities__current_user_can__cap',
854
+			$filtered_cap,
855
+			$context,
856
+			$cap,
857
+			$id
858
+		);
859
+		return ! empty($id)
860
+			? current_user_can($filtered_cap, $id)
861
+			: current_user_can($filtered_cap);
862
+	}
863
+
864
+
865
+	/**
866
+	 * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
867
+	 *
868
+	 * @param int|WP_User $user    Either the user_id or a WP_User object
869
+	 * @param string      $cap     The capability string being checked
870
+	 * @param string      $context The context where the user_can is being called from (used in filters).
871
+	 * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
872
+	 *                             filters)
873
+	 *
874
+	 * @return bool Whether user can or not.
875
+	 */
876
+	public function user_can($user, $cap, $context, $id = 0)
877
+	{
878
+		// apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
879
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
880
+		$filtered_cap = apply_filters(
881
+			'FHEE__EE_Capabilities__user_can__cap',
882
+			$filtered_cap,
883
+			$context,
884
+			$cap,
885
+			$user,
886
+			$id
887
+		);
888
+		return ! empty($id)
889
+			? user_can($user, $filtered_cap, $id)
890
+			: user_can($user, $filtered_cap);
891
+	}
892
+
893
+
894
+	/**
895
+	 * Wrapper for the native WP current_user_can_for_blog() method.
896
+	 * This is provided as a handy method for a couple things:
897
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
898
+	 * write those filters wherever current_user_can is called).
899
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
900
+	 *
901
+	 * @since 4.5.0
902
+	 *
903
+	 * @param int    $blog_id The blog id that is being checked for.
904
+	 * @param string $cap     The cap being checked.
905
+	 * @param string $context The context where the current_user_can is being called from.
906
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
907
+	 *                        filters.
908
+	 *
909
+	 * @return bool  Whether user can or not.
910
+	 */
911
+	public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
912
+	{
913
+		$user_can = ! empty($id)
914
+			? current_user_can_for_blog($blog_id, $cap, $id)
915
+			: current_user_can($blog_id, $cap);
916
+		// apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
917
+		$user_can = apply_filters(
918
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
919
+			$user_can,
920
+			$blog_id,
921
+			$cap,
922
+			$id
923
+		);
924
+		$user_can = apply_filters(
925
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
926
+			$user_can,
927
+			$context,
928
+			$blog_id,
929
+			$cap,
930
+			$id
931
+		);
932
+		return $user_can;
933
+	}
934
+
935
+
936
+	/**
937
+	 * This helper method just returns an array of registered EE capabilities.
938
+	 *
939
+	 * @since 4.5.0
940
+	 * @param string $role If empty then the entire role/capability map is returned.
941
+	 *                     Otherwise just the capabilities for the given role are returned.
942
+	 * @return array
943
+	 * @throws EE_Error
944
+	 */
945
+	public function get_ee_capabilities($role = 'administrator')
946
+	{
947
+		if (! $this->initialized) {
948
+			$this->init_caps();
949
+		}
950
+		if (empty($role)) {
951
+			return $this->capabilities_map;
952
+		}
953
+		return isset($this->capabilities_map[ $role ])
954
+			? $this->capabilities_map[ $role ]
955
+			: array();
956
+	}
957
+
958
+
959
+	/**
960
+	 * @deprecated 4.9.42
961
+	 * @param bool  $reset      If you need to reset Event Espresso's capabilities,
962
+	 *                          then please use the init_caps() method with the "$reset" parameter set to "true"
963
+	 * @param array $caps_map   Optional.
964
+	 *                          Can be used to send a custom map of roles and capabilities for setting them up.
965
+	 *                          Note that this should ONLY be called on activation hook or some other one-time
966
+	 *                          task otherwise the caps will be added on every request.
967
+	 * @return void
968
+	 * @throws EE_Error
969
+	 */
970
+	public function init_role_caps($reset = false, $caps_map = array())
971
+	{
972
+		// If this method is called directly and reset is set as 'true',
973
+		// then display a doing it wrong notice, because we want resets to go through init_caps()
974
+		// to guarantee that everything is set up correctly.
975
+		// This prevents the capabilities map getting reset incorrectly by direct calls to this method.
976
+		if ($reset) {
977
+			EE_Error::doing_it_wrong(
978
+				__METHOD__,
979
+				sprintf(
980
+					esc_html__(
981
+						'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".',
982
+						'event_espresso'
983
+					),
984
+					'$reset',
985
+					__METHOD__ . '()',
986
+					'EE_Capabilities::init_caps()',
987
+					'true'
988
+				),
989
+				'4.9.42',
990
+				'5.0.0'
991
+			);
992
+		}
993
+		$this->addCaps($caps_map);
994
+	}
995 995
 }
996 996
 
997 997
 
@@ -1008,142 +1008,142 @@  discard block
 block discarded – undo
1008 1008
 abstract class EE_Meta_Capability_Map
1009 1009
 {
1010 1010
 
1011
-    public $meta_cap;
1012
-
1013
-    /**
1014
-     * @var EEM_Base
1015
-     */
1016
-    protected $_model;
1017
-
1018
-    protected $_model_name;
1019
-
1020
-    public $published_cap = '';
1021
-
1022
-    public $others_cap = '';
1023
-
1024
-    public $private_cap = '';
1025
-
1026
-
1027
-    /**
1028
-     * constructor.
1029
-     * Receives the setup arguments for the map.
1030
-     *
1031
-     * @since                        4.5.0
1032
-     *
1033
-     * @param string $meta_cap   What meta capability is this mapping.
1034
-     * @param array  $map_values array {
1035
-     *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
1036
-     *                           capabilities that don't get mapped to.
1037
-     *
1038
-     * @type         $map_values [0] string A string representing the model name. Required.  String's
1039
-     *                               should always be used when Menu Maps are registered via the
1040
-     *                               plugin API as models are not allowed to be instantiated when
1041
-     *                               in maintenance mode 2 (migrations).
1042
-     * @type         $map_values [1] string represents the capability used for published. Optional.
1043
-     * @type         $map_values [2] string represents the capability used for "others". Optional.
1044
-     * @type         $map_values [3] string represents the capability used for private. Optional.
1045
-     *                               }
1046
-     * @throws EE_Error
1047
-     */
1048
-    public function __construct($meta_cap, $map_values)
1049
-    {
1050
-        $this->meta_cap = $meta_cap;
1051
-        // verify there are four args in the $map_values array;
1052
-        if (count($map_values) !== 4) {
1053
-            throw new EE_Error(
1054
-                sprintf(
1055
-                    __(
1056
-                        'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
1057
-                        'event_espresso'
1058
-                    ),
1059
-                    '<br>' . print_r($map_values, true)
1060
-                )
1061
-            );
1062
-        }
1063
-        // set properties
1064
-        $this->_model = null;
1065
-        $this->_model_name = $map_values[0];
1066
-        $this->published_cap = (string) $map_values[1];
1067
-        $this->others_cap = (string) $map_values[2];
1068
-        $this->private_cap = (string) $map_values[3];
1069
-    }
1070
-
1071
-    /**
1072
-     * Makes it so this object stops filtering caps
1073
-     */
1074
-    public function remove_filters()
1075
-    {
1076
-        remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
1077
-    }
1078
-
1079
-
1080
-    /**
1081
-     * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
1082
-     *
1083
-     * @since 4.5.0
1084
-     * @throws EE_Error
1085
-     *
1086
-     * @return void
1087
-     */
1088
-    public function ensure_is_model()
1089
-    {
1090
-        // is it already instantiated?
1091
-        if ($this->_model instanceof EEM_Base) {
1092
-            return;
1093
-        }
1094
-        // ensure model name is string
1095
-        $this->_model_name = (string) $this->_model_name;
1096
-        // error proof if the name has EEM in it
1097
-        $this->_model_name = str_replace('EEM', '', $this->_model_name);
1098
-        $this->_model = EE_Registry::instance()->load_model($this->_model_name);
1099
-        if (! $this->_model instanceof EEM_Base) {
1100
-            throw new EE_Error(
1101
-                sprintf(
1102
-                    __(
1103
-                        'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class.   Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s',
1104
-                        'event_espresso'
1105
-                    ),
1106
-                    get_class($this),
1107
-                    $this->_model
1108
-                )
1109
-            );
1110
-        }
1111
-    }
1112
-
1113
-
1114
-    /**
1115
-     *
1116
-     * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
1117
-     * @since 4.6.x
1118
-     *
1119
-     * @param $caps
1120
-     * @param $cap
1121
-     * @param $user_id
1122
-     * @param $args
1123
-     *
1124
-     * @return array
1125
-     */
1126
-    public function map_meta_caps($caps, $cap, $user_id, $args)
1127
-    {
1128
-        return $this->_map_meta_caps($caps, $cap, $user_id, $args);
1129
-    }
1130
-
1131
-
1132
-    /**
1133
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1134
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1135
-     *
1136
-     * @since 4.5.0
1137
-     * @see   wp-includes/capabilities.php
1138
-     *
1139
-     * @param array  $caps    actual users capabilities
1140
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1141
-     * @param int    $user_id The user id
1142
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1143
-     *
1144
-     * @return array   actual users capabilities
1145
-     */
1146
-    abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
1011
+	public $meta_cap;
1012
+
1013
+	/**
1014
+	 * @var EEM_Base
1015
+	 */
1016
+	protected $_model;
1017
+
1018
+	protected $_model_name;
1019
+
1020
+	public $published_cap = '';
1021
+
1022
+	public $others_cap = '';
1023
+
1024
+	public $private_cap = '';
1025
+
1026
+
1027
+	/**
1028
+	 * constructor.
1029
+	 * Receives the setup arguments for the map.
1030
+	 *
1031
+	 * @since                        4.5.0
1032
+	 *
1033
+	 * @param string $meta_cap   What meta capability is this mapping.
1034
+	 * @param array  $map_values array {
1035
+	 *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
1036
+	 *                           capabilities that don't get mapped to.
1037
+	 *
1038
+	 * @type         $map_values [0] string A string representing the model name. Required.  String's
1039
+	 *                               should always be used when Menu Maps are registered via the
1040
+	 *                               plugin API as models are not allowed to be instantiated when
1041
+	 *                               in maintenance mode 2 (migrations).
1042
+	 * @type         $map_values [1] string represents the capability used for published. Optional.
1043
+	 * @type         $map_values [2] string represents the capability used for "others". Optional.
1044
+	 * @type         $map_values [3] string represents the capability used for private. Optional.
1045
+	 *                               }
1046
+	 * @throws EE_Error
1047
+	 */
1048
+	public function __construct($meta_cap, $map_values)
1049
+	{
1050
+		$this->meta_cap = $meta_cap;
1051
+		// verify there are four args in the $map_values array;
1052
+		if (count($map_values) !== 4) {
1053
+			throw new EE_Error(
1054
+				sprintf(
1055
+					__(
1056
+						'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
1057
+						'event_espresso'
1058
+					),
1059
+					'<br>' . print_r($map_values, true)
1060
+				)
1061
+			);
1062
+		}
1063
+		// set properties
1064
+		$this->_model = null;
1065
+		$this->_model_name = $map_values[0];
1066
+		$this->published_cap = (string) $map_values[1];
1067
+		$this->others_cap = (string) $map_values[2];
1068
+		$this->private_cap = (string) $map_values[3];
1069
+	}
1070
+
1071
+	/**
1072
+	 * Makes it so this object stops filtering caps
1073
+	 */
1074
+	public function remove_filters()
1075
+	{
1076
+		remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
1077
+	}
1078
+
1079
+
1080
+	/**
1081
+	 * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
1082
+	 *
1083
+	 * @since 4.5.0
1084
+	 * @throws EE_Error
1085
+	 *
1086
+	 * @return void
1087
+	 */
1088
+	public function ensure_is_model()
1089
+	{
1090
+		// is it already instantiated?
1091
+		if ($this->_model instanceof EEM_Base) {
1092
+			return;
1093
+		}
1094
+		// ensure model name is string
1095
+		$this->_model_name = (string) $this->_model_name;
1096
+		// error proof if the name has EEM in it
1097
+		$this->_model_name = str_replace('EEM', '', $this->_model_name);
1098
+		$this->_model = EE_Registry::instance()->load_model($this->_model_name);
1099
+		if (! $this->_model instanceof EEM_Base) {
1100
+			throw new EE_Error(
1101
+				sprintf(
1102
+					__(
1103
+						'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class.   Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s',
1104
+						'event_espresso'
1105
+					),
1106
+					get_class($this),
1107
+					$this->_model
1108
+				)
1109
+			);
1110
+		}
1111
+	}
1112
+
1113
+
1114
+	/**
1115
+	 *
1116
+	 * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
1117
+	 * @since 4.6.x
1118
+	 *
1119
+	 * @param $caps
1120
+	 * @param $cap
1121
+	 * @param $user_id
1122
+	 * @param $args
1123
+	 *
1124
+	 * @return array
1125
+	 */
1126
+	public function map_meta_caps($caps, $cap, $user_id, $args)
1127
+	{
1128
+		return $this->_map_meta_caps($caps, $cap, $user_id, $args);
1129
+	}
1130
+
1131
+
1132
+	/**
1133
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1134
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1135
+	 *
1136
+	 * @since 4.5.0
1137
+	 * @see   wp-includes/capabilities.php
1138
+	 *
1139
+	 * @param array  $caps    actual users capabilities
1140
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1141
+	 * @param int    $user_id The user id
1142
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1143
+	 *
1144
+	 * @return array   actual users capabilities
1145
+	 */
1146
+	abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
1147 1147
 }
1148 1148
 
1149 1149
 
@@ -1159,81 +1159,81 @@  discard block
 block discarded – undo
1159 1159
 class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map
1160 1160
 {
1161 1161
 
1162
-    /**
1163
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1164
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1165
-     *
1166
-     * @since 4.5.0
1167
-     * @see   wp-includes/capabilities.php
1168
-     *
1169
-     * @param array  $caps    actual users capabilities
1170
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1171
-     * @param int    $user_id The user id
1172
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1173
-     *
1174
-     * @return array   actual users capabilities
1175
-     */
1176
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1177
-    {
1178
-        // only process if we're checking our mapped_cap
1179
-        if ($cap !== $this->meta_cap) {
1180
-            return $caps;
1181
-        }
1182
-
1183
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1184
-        if (($key = array_search($cap, $caps)) !== false) {
1185
-            unset($caps[ $key ]);
1186
-        }
1187
-
1188
-        // cast $user_id to int for later explicit comparisons
1189
-        $user_id = (int) $user_id;
1190
-
1191
-        /** @var EE_Base_Class $obj */
1192
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1193
-        // if no obj then let's just do cap
1194
-        if (! $obj instanceof EE_Base_Class) {
1195
-            $caps[] = 'do_not_allow';
1196
-            return $caps;
1197
-        }
1198
-        $caps[] = $cap . 's';
1199
-        if ($obj instanceof EE_CPT_Base) {
1200
-            // if the item author is set and the user is the author...
1201
-            if ($obj->wp_user() && $user_id === $obj->wp_user()) {
1202
-                // if obj is published...
1203
-                if ($obj->status() === 'publish') {
1204
-                    $caps[] = $this->published_cap;
1205
-                }
1206
-            } else {
1207
-                // the user is trying to edit someone else's obj
1208
-                if (! empty($this->others_cap)) {
1209
-                    $caps[] = $this->others_cap;
1210
-                }
1211
-                if (! empty($this->published_cap) && $obj->status() === 'publish') {
1212
-                    $caps[] = $this->published_cap;
1213
-                } elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1214
-                    $caps[] = $this->private_cap;
1215
-                }
1216
-            }
1217
-        } else {
1218
-            // not a cpt object so handled differently
1219
-            $has_cap = false;
1220
-            try {
1221
-                $has_cap = method_exists($obj, 'wp_user')
1222
-                           && $obj->wp_user()
1223
-                           && $obj->wp_user() === $user_id;
1224
-            } catch (Exception $e) {
1225
-                if (WP_DEBUG) {
1226
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1227
-                }
1228
-            }
1229
-            if (! $has_cap) {
1230
-                if (! empty($this->others_cap)) {
1231
-                    $caps[] = $this->others_cap;
1232
-                }
1233
-            }
1234
-        }
1235
-        return $caps;
1236
-    }
1162
+	/**
1163
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1164
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1165
+	 *
1166
+	 * @since 4.5.0
1167
+	 * @see   wp-includes/capabilities.php
1168
+	 *
1169
+	 * @param array  $caps    actual users capabilities
1170
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1171
+	 * @param int    $user_id The user id
1172
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1173
+	 *
1174
+	 * @return array   actual users capabilities
1175
+	 */
1176
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1177
+	{
1178
+		// only process if we're checking our mapped_cap
1179
+		if ($cap !== $this->meta_cap) {
1180
+			return $caps;
1181
+		}
1182
+
1183
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1184
+		if (($key = array_search($cap, $caps)) !== false) {
1185
+			unset($caps[ $key ]);
1186
+		}
1187
+
1188
+		// cast $user_id to int for later explicit comparisons
1189
+		$user_id = (int) $user_id;
1190
+
1191
+		/** @var EE_Base_Class $obj */
1192
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1193
+		// if no obj then let's just do cap
1194
+		if (! $obj instanceof EE_Base_Class) {
1195
+			$caps[] = 'do_not_allow';
1196
+			return $caps;
1197
+		}
1198
+		$caps[] = $cap . 's';
1199
+		if ($obj instanceof EE_CPT_Base) {
1200
+			// if the item author is set and the user is the author...
1201
+			if ($obj->wp_user() && $user_id === $obj->wp_user()) {
1202
+				// if obj is published...
1203
+				if ($obj->status() === 'publish') {
1204
+					$caps[] = $this->published_cap;
1205
+				}
1206
+			} else {
1207
+				// the user is trying to edit someone else's obj
1208
+				if (! empty($this->others_cap)) {
1209
+					$caps[] = $this->others_cap;
1210
+				}
1211
+				if (! empty($this->published_cap) && $obj->status() === 'publish') {
1212
+					$caps[] = $this->published_cap;
1213
+				} elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1214
+					$caps[] = $this->private_cap;
1215
+				}
1216
+			}
1217
+		} else {
1218
+			// not a cpt object so handled differently
1219
+			$has_cap = false;
1220
+			try {
1221
+				$has_cap = method_exists($obj, 'wp_user')
1222
+						   && $obj->wp_user()
1223
+						   && $obj->wp_user() === $user_id;
1224
+			} catch (Exception $e) {
1225
+				if (WP_DEBUG) {
1226
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1227
+				}
1228
+			}
1229
+			if (! $has_cap) {
1230
+				if (! empty($this->others_cap)) {
1231
+					$caps[] = $this->others_cap;
1232
+				}
1233
+			}
1234
+		}
1235
+		return $caps;
1236
+	}
1237 1237
 }
1238 1238
 
1239 1239
 
@@ -1250,24 +1250,24 @@  discard block
 block discarded – undo
1250 1250
 class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit
1251 1251
 {
1252 1252
 
1253
-    /**
1254
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1255
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1256
-     *
1257
-     * @since 4.5.0
1258
-     * @see   wp-includes/capabilities.php
1259
-     *
1260
-     * @param array  $caps    actual users capabilities
1261
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1262
-     * @param int    $user_id The user id
1263
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1264
-     *
1265
-     * @return array   actual users capabilities
1266
-     */
1267
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1268
-    {
1269
-        return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1270
-    }
1253
+	/**
1254
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1255
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1256
+	 *
1257
+	 * @since 4.5.0
1258
+	 * @see   wp-includes/capabilities.php
1259
+	 *
1260
+	 * @param array  $caps    actual users capabilities
1261
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1262
+	 * @param int    $user_id The user id
1263
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1264
+	 *
1265
+	 * @return array   actual users capabilities
1266
+	 */
1267
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1268
+	{
1269
+		return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1270
+	}
1271 1271
 }
1272 1272
 
1273 1273
 
@@ -1283,86 +1283,86 @@  discard block
 block discarded – undo
1283 1283
 class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map
1284 1284
 {
1285 1285
 
1286
-    /**
1287
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1288
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1289
-     *
1290
-     * @since 4.5.0
1291
-     * @see   wp-includes/capabilities.php
1292
-     *
1293
-     * @param array  $caps    actual users capabilities
1294
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1295
-     * @param int    $user_id The user id
1296
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1297
-     *
1298
-     * @return array   actual users capabilities
1299
-     */
1300
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1301
-    {
1302
-        // only process if we're checking our mapped cap;
1303
-        if ($cap !== $this->meta_cap) {
1304
-            return $caps;
1305
-        }
1306
-
1307
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1308
-        if (($key = array_search($cap, $caps)) !== false) {
1309
-            unset($caps[ $key ]);
1310
-        }
1311
-
1312
-        // cast $user_id to int for later explicit comparisons
1313
-        $user_id = (int) $user_id;
1314
-
1315
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1316
-        // if no obj then let's just do cap
1317
-        if (! $obj instanceof EE_Base_Class) {
1318
-            $caps[] = 'do_not_allow';
1319
-            return $caps;
1320
-        }
1321
-
1322
-        $caps[] = $cap . 's';
1323
-        if ($obj instanceof EE_CPT_Base) {
1324
-            $status_obj = get_post_status_object($obj->status());
1325
-            if ($status_obj->public) {
1326
-                return $caps;
1327
-            }
1328
-            // if the item author is set and the user is not the author...
1329
-            if ($obj->wp_user() && $obj->wp_user() !== $user_id) {
1330
-                if (! empty($this->others_cap)) {
1331
-                    $caps[] = $this->others_cap;
1332
-                }
1333
-            }
1334
-            // yes this means that if users created the private post, they are able to see it regardless of private cap.
1335
-            if (
1336
-                $status_obj->private
1337
-                && ! empty($this->private_cap)
1338
-                && $obj->wp_user() !== $user_id
1339
-            ) {
1340
-                // the user is trying to view a private object for an object they don't own.
1341
-                $caps[] = $this->private_cap;
1342
-            }
1343
-        } else {
1344
-            // not a cpt object so handled differently
1345
-            $has_cap = false;
1346
-            try {
1347
-                $has_cap = method_exists($obj, 'wp_user')
1348
-                           && $obj->wp_user()
1349
-                           && $obj->wp_user() === $user_id;
1350
-            } catch (Exception $e) {
1351
-                if (WP_DEBUG) {
1352
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1353
-                }
1354
-            }
1355
-            if (! $has_cap) {
1356
-                if (! empty($this->private_cap)) {
1357
-                    $caps[] = $this->private_cap;
1358
-                }
1359
-                if (! empty($this->others_cap)) {
1360
-                    $caps[] = $this->others_cap;
1361
-                }
1362
-            }
1363
-        }
1364
-        return $caps;
1365
-    }
1286
+	/**
1287
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1288
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1289
+	 *
1290
+	 * @since 4.5.0
1291
+	 * @see   wp-includes/capabilities.php
1292
+	 *
1293
+	 * @param array  $caps    actual users capabilities
1294
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1295
+	 * @param int    $user_id The user id
1296
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1297
+	 *
1298
+	 * @return array   actual users capabilities
1299
+	 */
1300
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1301
+	{
1302
+		// only process if we're checking our mapped cap;
1303
+		if ($cap !== $this->meta_cap) {
1304
+			return $caps;
1305
+		}
1306
+
1307
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1308
+		if (($key = array_search($cap, $caps)) !== false) {
1309
+			unset($caps[ $key ]);
1310
+		}
1311
+
1312
+		// cast $user_id to int for later explicit comparisons
1313
+		$user_id = (int) $user_id;
1314
+
1315
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1316
+		// if no obj then let's just do cap
1317
+		if (! $obj instanceof EE_Base_Class) {
1318
+			$caps[] = 'do_not_allow';
1319
+			return $caps;
1320
+		}
1321
+
1322
+		$caps[] = $cap . 's';
1323
+		if ($obj instanceof EE_CPT_Base) {
1324
+			$status_obj = get_post_status_object($obj->status());
1325
+			if ($status_obj->public) {
1326
+				return $caps;
1327
+			}
1328
+			// if the item author is set and the user is not the author...
1329
+			if ($obj->wp_user() && $obj->wp_user() !== $user_id) {
1330
+				if (! empty($this->others_cap)) {
1331
+					$caps[] = $this->others_cap;
1332
+				}
1333
+			}
1334
+			// yes this means that if users created the private post, they are able to see it regardless of private cap.
1335
+			if (
1336
+				$status_obj->private
1337
+				&& ! empty($this->private_cap)
1338
+				&& $obj->wp_user() !== $user_id
1339
+			) {
1340
+				// the user is trying to view a private object for an object they don't own.
1341
+				$caps[] = $this->private_cap;
1342
+			}
1343
+		} else {
1344
+			// not a cpt object so handled differently
1345
+			$has_cap = false;
1346
+			try {
1347
+				$has_cap = method_exists($obj, 'wp_user')
1348
+						   && $obj->wp_user()
1349
+						   && $obj->wp_user() === $user_id;
1350
+			} catch (Exception $e) {
1351
+				if (WP_DEBUG) {
1352
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1353
+				}
1354
+			}
1355
+			if (! $has_cap) {
1356
+				if (! empty($this->private_cap)) {
1357
+					$caps[] = $this->private_cap;
1358
+				}
1359
+				if (! empty($this->others_cap)) {
1360
+					$caps[] = $this->others_cap;
1361
+				}
1362
+			}
1363
+		}
1364
+		return $caps;
1365
+	}
1366 1366
 }
1367 1367
 
1368 1368
 
@@ -1379,56 +1379,56 @@  discard block
 block discarded – undo
1379 1379
 class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map
1380 1380
 {
1381 1381
 
1382
-    /**
1383
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1384
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1385
-     *
1386
-     * @since 4.5.0
1387
-     * @see   wp-includes/capabilities.php
1388
-     *
1389
-     * @param array  $caps    actual users capabilities
1390
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1391
-     * @param int    $user_id The user id
1392
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1393
-     *
1394
-     * @return array   actual users capabilities
1395
-     */
1396
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1397
-    {
1398
-        // only process if we're checking our mapped_cap
1399
-        if ($cap !== $this->meta_cap) {
1400
-            return $caps;
1401
-        }
1402
-
1403
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1404
-        if (($key = array_search($cap, $caps)) !== false) {
1405
-            unset($caps[ $key ]);
1406
-        }
1407
-
1408
-        // cast $user_id to int for later explicit comparisons
1409
-        $user_id = (int) $user_id;
1410
-
1411
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1412
-        // if no obj then let's just do cap
1413
-        if (! $obj instanceof EE_Message_Template_Group) {
1414
-            $caps[] = 'do_not_allow';
1415
-            return $caps;
1416
-        }
1417
-        $caps[] = $cap . 's';
1418
-        $is_global = $obj->is_global();
1419
-        if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1420
-            if ($is_global) {
1421
-                $caps[] = $this->private_cap;
1422
-            }
1423
-        } else {
1424
-            if ($is_global) {
1425
-                $caps[] = $this->private_cap;
1426
-            } else {
1427
-                $caps[] = $this->others_cap;
1428
-            }
1429
-        }
1430
-        return $caps;
1431
-    }
1382
+	/**
1383
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1384
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1385
+	 *
1386
+	 * @since 4.5.0
1387
+	 * @see   wp-includes/capabilities.php
1388
+	 *
1389
+	 * @param array  $caps    actual users capabilities
1390
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1391
+	 * @param int    $user_id The user id
1392
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1393
+	 *
1394
+	 * @return array   actual users capabilities
1395
+	 */
1396
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1397
+	{
1398
+		// only process if we're checking our mapped_cap
1399
+		if ($cap !== $this->meta_cap) {
1400
+			return $caps;
1401
+		}
1402
+
1403
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1404
+		if (($key = array_search($cap, $caps)) !== false) {
1405
+			unset($caps[ $key ]);
1406
+		}
1407
+
1408
+		// cast $user_id to int for later explicit comparisons
1409
+		$user_id = (int) $user_id;
1410
+
1411
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1412
+		// if no obj then let's just do cap
1413
+		if (! $obj instanceof EE_Message_Template_Group) {
1414
+			$caps[] = 'do_not_allow';
1415
+			return $caps;
1416
+		}
1417
+		$caps[] = $cap . 's';
1418
+		$is_global = $obj->is_global();
1419
+		if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1420
+			if ($is_global) {
1421
+				$caps[] = $this->private_cap;
1422
+			}
1423
+		} else {
1424
+			if ($is_global) {
1425
+				$caps[] = $this->private_cap;
1426
+			} else {
1427
+				$caps[] = $this->others_cap;
1428
+			}
1429
+		}
1430
+		return $caps;
1431
+	}
1432 1432
 }
1433 1433
 
1434 1434
 
@@ -1445,40 +1445,40 @@  discard block
 block discarded – undo
1445 1445
 class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map
1446 1446
 {
1447 1447
 
1448
-    /**
1449
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1450
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1451
-     *
1452
-     * @since 4.5.0
1453
-     * @see   wp-includes/capabilities.php
1454
-     * @param array  $caps    actual users capabilities
1455
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1456
-     * @param int    $user_id The user id
1457
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1458
-     * @return array   actual users capabilities
1459
-     */
1460
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1461
-    {
1462
-        // only process if we're checking our mapped_cap
1463
-        if ($cap !== $this->meta_cap) {
1464
-            return $caps;
1465
-        }
1466
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1467
-        if (($key = array_search($cap, $caps)) !== false) {
1468
-            unset($caps[ $key ]);
1469
-        }
1470
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1471
-        // if no obj then let's just do cap
1472
-        if (! $obj instanceof EE_Base_Class) {
1473
-            $caps[] = 'do_not_allow';
1474
-            return $caps;
1475
-        }
1476
-        $caps[] = $cap . 's';
1477
-        $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1478
-        $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1479
-        if ($is_system) {
1480
-            $caps[] = $this->private_cap;
1481
-        }
1482
-        return $caps;
1483
-    }
1448
+	/**
1449
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1450
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1451
+	 *
1452
+	 * @since 4.5.0
1453
+	 * @see   wp-includes/capabilities.php
1454
+	 * @param array  $caps    actual users capabilities
1455
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1456
+	 * @param int    $user_id The user id
1457
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1458
+	 * @return array   actual users capabilities
1459
+	 */
1460
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1461
+	{
1462
+		// only process if we're checking our mapped_cap
1463
+		if ($cap !== $this->meta_cap) {
1464
+			return $caps;
1465
+		}
1466
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1467
+		if (($key = array_search($cap, $caps)) !== false) {
1468
+			unset($caps[ $key ]);
1469
+		}
1470
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1471
+		// if no obj then let's just do cap
1472
+		if (! $obj instanceof EE_Base_Class) {
1473
+			$caps[] = 'do_not_allow';
1474
+			return $caps;
1475
+		}
1476
+		$caps[] = $cap . 's';
1477
+		$is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1478
+		$is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1479
+		if ($is_system) {
1480
+			$caps[] = $this->private_cap;
1481
+		}
1482
+		return $caps;
1483
+	}
1484 1484
 }
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     public static function instance()
81 81
     {
82 82
         // check if instantiated, and if not do so.
83
-        if (! self::$_instance instanceof EE_Capabilities) {
83
+        if ( ! self::$_instance instanceof EE_Capabilities) {
84 84
             self::$_instance = new self();
85 85
         }
86 86
         return self::$_instance;
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
      */
111 111
     public function init_caps($reset = false)
112 112
     {
113
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
113
+        if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
114 114
             return false;
115 115
         }
116 116
         $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN);
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
             $this->_get_default_meta_caps_array()
156 156
         );
157 157
         // add filter for map_meta_caps but only if models can query.
158
-        if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
158
+        if ( ! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
159 159
             add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
160 160
         }
161 161
     }
@@ -314,11 +314,11 @@  discard block
 block discarded – undo
314 314
         if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
315 315
             // loop through our _meta_caps array
316 316
             foreach ($this->_meta_caps as $meta_map) {
317
-                if (! $meta_map instanceof EE_Meta_Capability_Map) {
317
+                if ( ! $meta_map instanceof EE_Meta_Capability_Map) {
318 318
                     continue;
319 319
                 }
320 320
                 // don't load models if there is no object ID in the args
321
-                if (! empty($args[0])) {
321
+                if ( ! empty($args[0])) {
322 322
                     $meta_map->ensure_is_model();
323 323
                 }
324 324
                 $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
     public function addCaps(array $capabilities_to_add)
655 655
     {
656 656
         // don't do anything if the capabilities map can not be initialized
657
-        if (! $this->setupCapabilitiesMap()) {
657
+        if ( ! $this->setupCapabilitiesMap()) {
658 658
             return false;
659 659
         }
660 660
         // and filter the array so others can get in on the fun during resets
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
     public function removeCaps($caps_map)
697 697
     {
698 698
         // don't do anything if the capabilities map can not be initialized
699
-        if (! $this->setupCapabilitiesMap()) {
699
+        if ( ! $this->setupCapabilitiesMap()) {
700 700
             return false;
701 701
         }
702 702
         $update_capabilities_map = false;
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
         $orig_role = $role;
757 757
         $role = $role instanceof WP_Role ? $role : get_role($role);
758 758
         // if the role isn't available then we create it.
759
-        if (! $role instanceof WP_Role) {
759
+        if ( ! $role instanceof WP_Role) {
760 760
             // if a plugin wants to create a specific role name then they should create the role before
761 761
             // EE_Capabilities does.  Otherwise this function will create the role name from the slug:
762 762
             // - removes any `ee_` namespacing from the start of the slug.
@@ -767,12 +767,12 @@  discard block
 block discarded – undo
767 767
         }
768 768
         if ($role instanceof WP_Role) {
769 769
             // don't do anything if the capabilities map can not be initialized
770
-            if (! $this->setupCapabilitiesMap()) {
770
+            if ( ! $this->setupCapabilitiesMap()) {
771 771
                 return false;
772 772
             }
773
-            if (! $this->capHasBeenAddedToRole($role->name, $cap)) {
773
+            if ( ! $this->capHasBeenAddedToRole($role->name, $cap)) {
774 774
                 $role->add_cap($cap, $grant);
775
-                $this->capabilities_map[ $role->name ][] = $cap;
775
+                $this->capabilities_map[$role->name][] = $cap;
776 776
                 $this->updateCapabilitiesMap($update_capabilities_map);
777 777
                 return true;
778 778
             }
@@ -796,14 +796,14 @@  discard block
 block discarded – undo
796 796
     public function remove_cap_from_role($role, $cap, $update_capabilities_map = true)
797 797
     {
798 798
         // don't do anything if the capabilities map can not be initialized
799
-        if (! $this->setupCapabilitiesMap()) {
799
+        if ( ! $this->setupCapabilitiesMap()) {
800 800
             return false;
801 801
         }
802 802
 
803 803
         $role = $role instanceof WP_Role ? $role : get_role($role);
804 804
         if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) {
805 805
             $role->remove_cap($cap);
806
-            unset($this->capabilities_map[ $role->name ][ $index ]);
806
+            unset($this->capabilities_map[$role->name][$index]);
807 807
             $this->updateCapabilitiesMap($update_capabilities_map);
808 808
             return true;
809 809
         }
@@ -820,8 +820,8 @@  discard block
 block discarded – undo
820 820
     private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false)
821 821
     {
822 822
         if (
823
-            isset($this->capabilities_map[ $role_name ])
824
-            && ($index = array_search($cap, $this->capabilities_map[ $role_name ], true)) !== false
823
+            isset($this->capabilities_map[$role_name])
824
+            && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false
825 825
         ) {
826 826
             return $get_index ? $index : true;
827 827
         }
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
     public function current_user_can($cap, $context, $id = 0)
849 849
     {
850 850
         // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
851
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
851
+        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__'.$context, $cap, $id);
852 852
         $filtered_cap = apply_filters(
853 853
             'FHEE__EE_Capabilities__current_user_can__cap',
854 854
             $filtered_cap,
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
     public function user_can($user, $cap, $context, $id = 0)
877 877
     {
878 878
         // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
879
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
879
+        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__'.$context, $cap, $user, $id);
880 880
         $filtered_cap = apply_filters(
881 881
             'FHEE__EE_Capabilities__user_can__cap',
882 882
             $filtered_cap,
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
             : current_user_can($blog_id, $cap);
916 916
         // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
917 917
         $user_can = apply_filters(
918
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
918
+            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__'.$context,
919 919
             $user_can,
920 920
             $blog_id,
921 921
             $cap,
@@ -944,14 +944,14 @@  discard block
 block discarded – undo
944 944
      */
945 945
     public function get_ee_capabilities($role = 'administrator')
946 946
     {
947
-        if (! $this->initialized) {
947
+        if ( ! $this->initialized) {
948 948
             $this->init_caps();
949 949
         }
950 950
         if (empty($role)) {
951 951
             return $this->capabilities_map;
952 952
         }
953
-        return isset($this->capabilities_map[ $role ])
954
-            ? $this->capabilities_map[ $role ]
953
+        return isset($this->capabilities_map[$role])
954
+            ? $this->capabilities_map[$role]
955 955
             : array();
956 956
     }
957 957
 
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
                         'event_espresso'
983 983
                     ),
984 984
                     '$reset',
985
-                    __METHOD__ . '()',
985
+                    __METHOD__.'()',
986 986
                     'EE_Capabilities::init_caps()',
987 987
                     'true'
988 988
                 ),
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
                         'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
1057 1057
                         'event_espresso'
1058 1058
                     ),
1059
-                    '<br>' . print_r($map_values, true)
1059
+                    '<br>'.print_r($map_values, true)
1060 1060
                 )
1061 1061
             );
1062 1062
         }
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
         // error proof if the name has EEM in it
1097 1097
         $this->_model_name = str_replace('EEM', '', $this->_model_name);
1098 1098
         $this->_model = EE_Registry::instance()->load_model($this->_model_name);
1099
-        if (! $this->_model instanceof EEM_Base) {
1099
+        if ( ! $this->_model instanceof EEM_Base) {
1100 1100
             throw new EE_Error(
1101 1101
                 sprintf(
1102 1102
                     __(
@@ -1182,7 +1182,7 @@  discard block
 block discarded – undo
1182 1182
 
1183 1183
         // okay it is a meta cap so let's first remove that cap from the $caps array.
1184 1184
         if (($key = array_search($cap, $caps)) !== false) {
1185
-            unset($caps[ $key ]);
1185
+            unset($caps[$key]);
1186 1186
         }
1187 1187
 
1188 1188
         // cast $user_id to int for later explicit comparisons
@@ -1191,11 +1191,11 @@  discard block
 block discarded – undo
1191 1191
         /** @var EE_Base_Class $obj */
1192 1192
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1193 1193
         // if no obj then let's just do cap
1194
-        if (! $obj instanceof EE_Base_Class) {
1194
+        if ( ! $obj instanceof EE_Base_Class) {
1195 1195
             $caps[] = 'do_not_allow';
1196 1196
             return $caps;
1197 1197
         }
1198
-        $caps[] = $cap . 's';
1198
+        $caps[] = $cap.'s';
1199 1199
         if ($obj instanceof EE_CPT_Base) {
1200 1200
             // if the item author is set and the user is the author...
1201 1201
             if ($obj->wp_user() && $user_id === $obj->wp_user()) {
@@ -1205,12 +1205,12 @@  discard block
 block discarded – undo
1205 1205
                 }
1206 1206
             } else {
1207 1207
                 // the user is trying to edit someone else's obj
1208
-                if (! empty($this->others_cap)) {
1208
+                if ( ! empty($this->others_cap)) {
1209 1209
                     $caps[] = $this->others_cap;
1210 1210
                 }
1211
-                if (! empty($this->published_cap) && $obj->status() === 'publish') {
1211
+                if ( ! empty($this->published_cap) && $obj->status() === 'publish') {
1212 1212
                     $caps[] = $this->published_cap;
1213
-                } elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1213
+                } elseif ( ! empty($this->private_cap) && $obj->status() === 'private') {
1214 1214
                     $caps[] = $this->private_cap;
1215 1215
                 }
1216 1216
             }
@@ -1226,8 +1226,8 @@  discard block
 block discarded – undo
1226 1226
                     EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1227 1227
                 }
1228 1228
             }
1229
-            if (! $has_cap) {
1230
-                if (! empty($this->others_cap)) {
1229
+            if ( ! $has_cap) {
1230
+                if ( ! empty($this->others_cap)) {
1231 1231
                     $caps[] = $this->others_cap;
1232 1232
                 }
1233 1233
             }
@@ -1306,7 +1306,7 @@  discard block
 block discarded – undo
1306 1306
 
1307 1307
         // okay it is a meta cap so let's first remove that cap from the $caps array.
1308 1308
         if (($key = array_search($cap, $caps)) !== false) {
1309
-            unset($caps[ $key ]);
1309
+            unset($caps[$key]);
1310 1310
         }
1311 1311
 
1312 1312
         // cast $user_id to int for later explicit comparisons
@@ -1314,12 +1314,12 @@  discard block
 block discarded – undo
1314 1314
 
1315 1315
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1316 1316
         // if no obj then let's just do cap
1317
-        if (! $obj instanceof EE_Base_Class) {
1317
+        if ( ! $obj instanceof EE_Base_Class) {
1318 1318
             $caps[] = 'do_not_allow';
1319 1319
             return $caps;
1320 1320
         }
1321 1321
 
1322
-        $caps[] = $cap . 's';
1322
+        $caps[] = $cap.'s';
1323 1323
         if ($obj instanceof EE_CPT_Base) {
1324 1324
             $status_obj = get_post_status_object($obj->status());
1325 1325
             if ($status_obj->public) {
@@ -1327,7 +1327,7 @@  discard block
 block discarded – undo
1327 1327
             }
1328 1328
             // if the item author is set and the user is not the author...
1329 1329
             if ($obj->wp_user() && $obj->wp_user() !== $user_id) {
1330
-                if (! empty($this->others_cap)) {
1330
+                if ( ! empty($this->others_cap)) {
1331 1331
                     $caps[] = $this->others_cap;
1332 1332
                 }
1333 1333
             }
@@ -1352,11 +1352,11 @@  discard block
 block discarded – undo
1352 1352
                     EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1353 1353
                 }
1354 1354
             }
1355
-            if (! $has_cap) {
1356
-                if (! empty($this->private_cap)) {
1355
+            if ( ! $has_cap) {
1356
+                if ( ! empty($this->private_cap)) {
1357 1357
                     $caps[] = $this->private_cap;
1358 1358
                 }
1359
-                if (! empty($this->others_cap)) {
1359
+                if ( ! empty($this->others_cap)) {
1360 1360
                     $caps[] = $this->others_cap;
1361 1361
                 }
1362 1362
             }
@@ -1402,7 +1402,7 @@  discard block
 block discarded – undo
1402 1402
 
1403 1403
         // okay it is a meta cap so let's first remove that cap from the $caps array.
1404 1404
         if (($key = array_search($cap, $caps)) !== false) {
1405
-            unset($caps[ $key ]);
1405
+            unset($caps[$key]);
1406 1406
         }
1407 1407
 
1408 1408
         // cast $user_id to int for later explicit comparisons
@@ -1410,11 +1410,11 @@  discard block
 block discarded – undo
1410 1410
 
1411 1411
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1412 1412
         // if no obj then let's just do cap
1413
-        if (! $obj instanceof EE_Message_Template_Group) {
1413
+        if ( ! $obj instanceof EE_Message_Template_Group) {
1414 1414
             $caps[] = 'do_not_allow';
1415 1415
             return $caps;
1416 1416
         }
1417
-        $caps[] = $cap . 's';
1417
+        $caps[] = $cap.'s';
1418 1418
         $is_global = $obj->is_global();
1419 1419
         if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1420 1420
             if ($is_global) {
@@ -1465,15 +1465,15 @@  discard block
 block discarded – undo
1465 1465
         }
1466 1466
         // okay it is a meta cap so let's first remove that cap from the $caps array.
1467 1467
         if (($key = array_search($cap, $caps)) !== false) {
1468
-            unset($caps[ $key ]);
1468
+            unset($caps[$key]);
1469 1469
         }
1470 1470
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1471 1471
         // if no obj then let's just do cap
1472
-        if (! $obj instanceof EE_Base_Class) {
1472
+        if ( ! $obj instanceof EE_Base_Class) {
1473 1473
             $caps[] = 'do_not_allow';
1474 1474
             return $caps;
1475 1475
         }
1476
-        $caps[] = $cap . 's';
1476
+        $caps[] = $cap.'s';
1477 1477
         $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1478 1478
         $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1479 1479
         if ($is_system) {
Please login to merge, or discard this patch.
admin/extend/transactions/Extend_Transactions_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -198,7 +198,7 @@
 block discarded – undo
198 198
      *
199 199
      * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
200 200
      *
201
-     * @return int
201
+     * @return string
202 202
      */
203 203
     private function _revenue_per_event_report($period = '-1 month')
204 204
     {
Please login to merge, or discard this patch.
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -16,239 +16,239 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * This is used to hold the reports template data which is setup early in the request.
21
-     *
22
-     * @type array
23
-     */
24
-    protected $_reports_template_data = array();
25
-
26
-    /**
27
-     * @Constructor
28
-     * @access public
29
-     *
30
-     * @param bool $routing
31
-     *
32
-     * @return \Extend_Transactions_Admin_Page
33
-     */
34
-    public function __construct($routing = true)
35
-    {
36
-        parent::__construct($routing);
37
-        define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/');
38
-        define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/');
39
-        define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/');
40
-    }
41
-
42
-
43
-    /**
44
-     *    _extend_page_config
45
-     *
46
-     * @access protected
47
-     * @return void
48
-     */
49
-    protected function _extend_page_config()
50
-    {
51
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions';
52
-
53
-        $new_page_routes = array(
54
-            'reports' => array(
55
-                'func'       => '_transaction_reports',
56
-                'capability' => 'ee_read_transactions',
57
-            ),
58
-        );
59
-
60
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
61
-
62
-        $new_page_config = array(
63
-            'reports' => array(
64
-                'nav'           => array(
65
-                    'label' => __('Reports', 'event_espresso'),
66
-                    'order' => 20,
67
-                ),
68
-                'help_tabs'     => array(
69
-                    'transactions_reports_help_tab' => array(
70
-                        'title'    => __('Transaction Reports', 'event_espresso'),
71
-                        'filename' => 'transactions_reports',
72
-                    ),
73
-                ),
74
-                /*'help_tour' => array( 'Transaction_Reports_Help_Tour' ),*/
75
-                'require_nonce' => false,
76
-            ),
77
-        );
78
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
79
-    }
80
-
81
-
82
-    /**
83
-     *    load_scripts_styles_reports
84
-     *
85
-     * @access public
86
-     * @return void
87
-     */
88
-    public function load_scripts_styles_reports()
89
-    {
90
-        wp_register_script(
91
-            'ee-txn-reports-js',
92
-            TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js',
93
-            array('google-charts'),
94
-            EVENT_ESPRESSO_VERSION,
95
-            true
96
-        );
97
-        wp_enqueue_script('ee-txn-reports-js');
98
-        $this->_transaction_reports_js_setup();
99
-        EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts();
100
-    }
101
-
102
-
103
-    /**
104
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
105
-     * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method.
106
-     */
107
-    protected function _transaction_reports_js_setup()
108
-    {
109
-        $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report();
110
-        $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report();
111
-    }
112
-
113
-
114
-    /**
115
-     * _transaction_reports
116
-     *    generates Business Reports regarding Transactions
117
-     *
118
-     * @return void
119
-     */
120
-    protected function _transaction_reports()
121
-    {
122
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
123
-        $this->_admin_page_title = __('Transactions', 'event_espresso');
124
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
125
-            $template_path,
126
-            $this->_reports_template_data,
127
-            true
128
-        );
129
-
130
-        // the final template wrapper
131
-        $this->display_admin_page_with_no_sidebar();
132
-    }
133
-
134
-
135
-    /**
136
-     * _revenue_per_day_report
137
-     * generates Business Report showing Total Revenue per Day.
138
-     *
139
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
140
-     *
141
-     * @return string
142
-     */
143
-    private function _revenue_per_day_report($period = '-1 month')
144
-    {
145
-
146
-        $report_ID = 'txn-admin-revenue-per-day-report-dv';
147
-
148
-        $TXN = EEM_Transaction::instance();
149
-
150
-        $results = $TXN->get_revenue_per_day_report($period);
151
-        $results = (array) $results;
152
-        $revenue = array();
153
-        $subtitle = '';
154
-
155
-        if ($results) {
156
-            $revenue[] = array(
157
-                __('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'),
158
-                __('Total Revenue', 'event_espresso'),
159
-            );
160
-            foreach ($results as $result) {
161
-                $revenue[] = array($result->txnDate, (float) $result->revenue);
162
-            }
163
-
164
-            // setup the date range.
165
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
166
-            $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
167
-            $subtitle = sprintf(
168
-                _x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
169
-                $beginning_date->format('Y-m-d'),
170
-                $ending_date->format('Y-m-d')
171
-            );
172
-        }
173
-
174
-        $report_title = esc_html__('Total Revenue per Day', 'event_espresso');
175
-
176
-        $report_params = array(
177
-            'title'     => $report_title,
178
-            'subtitle'  => $subtitle,
179
-            'id'        => $report_ID,
180
-            'revenue'   => $revenue,
181
-            'noResults' => empty($revenue) || count($revenue) === 1,
182
-            'noTxnMsg'  => sprintf(
183
-                __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
184
-                '<h2>' . $report_title . '</h2><p>',
185
-                '</p>'
186
-            ),
187
-        );
188
-        wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params);
189
-
190
-        return $report_ID;
191
-    }
192
-
193
-
194
-    /**
195
-     * _revenue_per_event_report
196
-     * generates Business Report showing total revenue per event.
197
-     *
198
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
199
-     *
200
-     * @return int
201
-     */
202
-    private function _revenue_per_event_report($period = '-1 month')
203
-    {
204
-
205
-        $report_ID = 'txn-admin-revenue-per-event-report-dv';
206
-
207
-        $TXN = EEM_Transaction::instance();
208
-        $results = $TXN->get_revenue_per_event_report($period);
209
-        $results = (array) $results;
210
-        $revenue = array();
211
-        $subtitle = '';
212
-
213
-        if ($results) {
214
-            $revenue[] = array(
215
-                __('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'),
216
-                __('Total Revenue', 'event_espresso'),
217
-            );
218
-            foreach ($results as $result) {
219
-                if ($result->revenue > 1) {
220
-                    $event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8'));
221
-                    $event_name = wp_trim_words($event_name, 5, '...');
222
-                    $revenue[] = array($event_name, (float) $result->revenue);
223
-                }
224
-            }
225
-
226
-            // setup the date range.
227
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
228
-            $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
229
-            $subtitle = sprintf(
230
-                _x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
231
-                $beginning_date->format('Y-m-d'),
232
-                $ending_date->format('Y-m-d')
233
-            );
234
-        }
235
-
236
-        $report_title = esc_html__('Total Revenue per Event', 'event_espresso');
237
-
238
-        $report_params = array(
239
-            'title'     => $report_title,
240
-            'subtitle'  => $subtitle,
241
-            'id'        => $report_ID,
242
-            'revenue'   => $revenue,
243
-            'noResults' => empty($revenue),
244
-            'noTxnMsg'  => sprintf(
245
-                __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
246
-                '<h2>' . $report_title . '</h2><p>',
247
-                '</p>'
248
-            ),
249
-        );
250
-        wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params);
251
-
252
-        return $report_ID;
253
-    }
19
+	/**
20
+	 * This is used to hold the reports template data which is setup early in the request.
21
+	 *
22
+	 * @type array
23
+	 */
24
+	protected $_reports_template_data = array();
25
+
26
+	/**
27
+	 * @Constructor
28
+	 * @access public
29
+	 *
30
+	 * @param bool $routing
31
+	 *
32
+	 * @return \Extend_Transactions_Admin_Page
33
+	 */
34
+	public function __construct($routing = true)
35
+	{
36
+		parent::__construct($routing);
37
+		define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/');
38
+		define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/');
39
+		define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/');
40
+	}
41
+
42
+
43
+	/**
44
+	 *    _extend_page_config
45
+	 *
46
+	 * @access protected
47
+	 * @return void
48
+	 */
49
+	protected function _extend_page_config()
50
+	{
51
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions';
52
+
53
+		$new_page_routes = array(
54
+			'reports' => array(
55
+				'func'       => '_transaction_reports',
56
+				'capability' => 'ee_read_transactions',
57
+			),
58
+		);
59
+
60
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
61
+
62
+		$new_page_config = array(
63
+			'reports' => array(
64
+				'nav'           => array(
65
+					'label' => __('Reports', 'event_espresso'),
66
+					'order' => 20,
67
+				),
68
+				'help_tabs'     => array(
69
+					'transactions_reports_help_tab' => array(
70
+						'title'    => __('Transaction Reports', 'event_espresso'),
71
+						'filename' => 'transactions_reports',
72
+					),
73
+				),
74
+				/*'help_tour' => array( 'Transaction_Reports_Help_Tour' ),*/
75
+				'require_nonce' => false,
76
+			),
77
+		);
78
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
79
+	}
80
+
81
+
82
+	/**
83
+	 *    load_scripts_styles_reports
84
+	 *
85
+	 * @access public
86
+	 * @return void
87
+	 */
88
+	public function load_scripts_styles_reports()
89
+	{
90
+		wp_register_script(
91
+			'ee-txn-reports-js',
92
+			TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js',
93
+			array('google-charts'),
94
+			EVENT_ESPRESSO_VERSION,
95
+			true
96
+		);
97
+		wp_enqueue_script('ee-txn-reports-js');
98
+		$this->_transaction_reports_js_setup();
99
+		EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts();
100
+	}
101
+
102
+
103
+	/**
104
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
105
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method.
106
+	 */
107
+	protected function _transaction_reports_js_setup()
108
+	{
109
+		$this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report();
110
+		$this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report();
111
+	}
112
+
113
+
114
+	/**
115
+	 * _transaction_reports
116
+	 *    generates Business Reports regarding Transactions
117
+	 *
118
+	 * @return void
119
+	 */
120
+	protected function _transaction_reports()
121
+	{
122
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
123
+		$this->_admin_page_title = __('Transactions', 'event_espresso');
124
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
125
+			$template_path,
126
+			$this->_reports_template_data,
127
+			true
128
+		);
129
+
130
+		// the final template wrapper
131
+		$this->display_admin_page_with_no_sidebar();
132
+	}
133
+
134
+
135
+	/**
136
+	 * _revenue_per_day_report
137
+	 * generates Business Report showing Total Revenue per Day.
138
+	 *
139
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
140
+	 *
141
+	 * @return string
142
+	 */
143
+	private function _revenue_per_day_report($period = '-1 month')
144
+	{
145
+
146
+		$report_ID = 'txn-admin-revenue-per-day-report-dv';
147
+
148
+		$TXN = EEM_Transaction::instance();
149
+
150
+		$results = $TXN->get_revenue_per_day_report($period);
151
+		$results = (array) $results;
152
+		$revenue = array();
153
+		$subtitle = '';
154
+
155
+		if ($results) {
156
+			$revenue[] = array(
157
+				__('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'),
158
+				__('Total Revenue', 'event_espresso'),
159
+			);
160
+			foreach ($results as $result) {
161
+				$revenue[] = array($result->txnDate, (float) $result->revenue);
162
+			}
163
+
164
+			// setup the date range.
165
+			$beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
166
+			$ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
167
+			$subtitle = sprintf(
168
+				_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
169
+				$beginning_date->format('Y-m-d'),
170
+				$ending_date->format('Y-m-d')
171
+			);
172
+		}
173
+
174
+		$report_title = esc_html__('Total Revenue per Day', 'event_espresso');
175
+
176
+		$report_params = array(
177
+			'title'     => $report_title,
178
+			'subtitle'  => $subtitle,
179
+			'id'        => $report_ID,
180
+			'revenue'   => $revenue,
181
+			'noResults' => empty($revenue) || count($revenue) === 1,
182
+			'noTxnMsg'  => sprintf(
183
+				__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
184
+				'<h2>' . $report_title . '</h2><p>',
185
+				'</p>'
186
+			),
187
+		);
188
+		wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params);
189
+
190
+		return $report_ID;
191
+	}
192
+
193
+
194
+	/**
195
+	 * _revenue_per_event_report
196
+	 * generates Business Report showing total revenue per event.
197
+	 *
198
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
199
+	 *
200
+	 * @return int
201
+	 */
202
+	private function _revenue_per_event_report($period = '-1 month')
203
+	{
204
+
205
+		$report_ID = 'txn-admin-revenue-per-event-report-dv';
206
+
207
+		$TXN = EEM_Transaction::instance();
208
+		$results = $TXN->get_revenue_per_event_report($period);
209
+		$results = (array) $results;
210
+		$revenue = array();
211
+		$subtitle = '';
212
+
213
+		if ($results) {
214
+			$revenue[] = array(
215
+				__('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'),
216
+				__('Total Revenue', 'event_espresso'),
217
+			);
218
+			foreach ($results as $result) {
219
+				if ($result->revenue > 1) {
220
+					$event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8'));
221
+					$event_name = wp_trim_words($event_name, 5, '...');
222
+					$revenue[] = array($event_name, (float) $result->revenue);
223
+				}
224
+			}
225
+
226
+			// setup the date range.
227
+			$beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
228
+			$ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
229
+			$subtitle = sprintf(
230
+				_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
231
+				$beginning_date->format('Y-m-d'),
232
+				$ending_date->format('Y-m-d')
233
+			);
234
+		}
235
+
236
+		$report_title = esc_html__('Total Revenue per Event', 'event_espresso');
237
+
238
+		$report_params = array(
239
+			'title'     => $report_title,
240
+			'subtitle'  => $subtitle,
241
+			'id'        => $report_ID,
242
+			'revenue'   => $revenue,
243
+			'noResults' => empty($revenue),
244
+			'noTxnMsg'  => sprintf(
245
+				__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
246
+				'<h2>' . $report_title . '</h2><p>',
247
+				'</p>'
248
+			),
249
+		);
250
+		wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params);
251
+
252
+		return $report_ID;
253
+	}
254 254
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
     public function __construct($routing = true)
35 35
     {
36 36
         parent::__construct($routing);
37
-        define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/');
38
-        define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/');
39
-        define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/');
37
+        define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'transactions/templates/');
38
+        define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'transactions/assets/');
39
+        define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'transactions/assets/');
40 40
     }
41 41
 
42 42
 
@@ -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 . 'transactions';
51
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'transactions';
52 52
 
53 53
         $new_page_routes = array(
54 54
             'reports' => array(
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
     {
90 90
         wp_register_script(
91 91
             'ee-txn-reports-js',
92
-            TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js',
92
+            TXN_CAF_ASSETS_URL.'ee-transaction-admin-reports.js',
93 93
             array('google-charts'),
94 94
             EVENT_ESPRESSO_VERSION,
95 95
             true
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
      */
120 120
     protected function _transaction_reports()
121 121
     {
122
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
122
+        $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
123 123
         $this->_admin_page_title = __('Transactions', 'event_espresso');
124 124
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
125 125
             $template_path,
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
             }
163 163
 
164 164
             // setup the date range.
165
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
165
+            $beginning_date = new DateTime('now'.$period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
166 166
             $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
167 167
             $subtitle = sprintf(
168 168
                 _x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
             'noResults' => empty($revenue) || count($revenue) === 1,
182 182
             'noTxnMsg'  => sprintf(
183 183
                 __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
184
-                '<h2>' . $report_title . '</h2><p>',
184
+                '<h2>'.$report_title.'</h2><p>',
185 185
                 '</p>'
186 186
             ),
187 187
         );
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
             }
225 225
 
226 226
             // setup the date range.
227
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
227
+            $beginning_date = new DateTime('now'.$period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
228 228
             $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
229 229
             $subtitle = sprintf(
230 230
                 _x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
             'noResults' => empty($revenue),
244 244
             'noTxnMsg'  => sprintf(
245 245
                 __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
246
-                '<h2>' . $report_title . '</h2><p>',
246
+                '<h2>'.$report_title.'</h2><p>',
247 247
                 '</p>'
248 248
             ),
249 249
         );
Please login to merge, or discard this patch.
caffeinated/EE_Caf_Messages.class.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      *
92 92
      * @param  array $dir_ref original array of paths
93 93
      *
94
-     * @return array           appended paths
94
+     * @return string[]           appended paths
95 95
      */
96 96
     public function messages_autoload_paths($dir_ref)
97 97
     {
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
      * @param EE_Question[]  $questions        An array of questions indexed by answer id.
702 702
      * @param EE_Answer[]    $answers          An array of answer objects
703 703
      * @param string         $template         Template content to be parsed.
704
-     * @param array          $valid_shortcodes Valid shortcodes for the template being parsed.
704
+     * @param string[]          $valid_shortcodes Valid shortcodes for the template being parsed.
705 705
      * @param array          $extra_data       Extra data that might be used when parsing the template.
706 706
      */
707 707
     protected function _parse_question_list_for_primary_or_recipient_registration(
Please login to merge, or discard this patch.
Indentation   +802 added lines, -802 removed lines patch added patch discarded remove patch
@@ -12,806 +12,806 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * constructor.
17
-     */
18
-    public function __construct()
19
-    {
20
-        $this->_caf_hooks();
21
-    }
22
-
23
-
24
-    /**
25
-     * Contains all the hooks filters for setting up caffeinated messages functionality.
26
-     *
27
-     * @since 4.3.2
28
-     *
29
-     * @return void
30
-     */
31
-    private function _caf_hooks()
32
-    {
33
-        add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5);
34
-        add_filter(
35
-            'FHEE__EE_Email_messenger__get_validator_config',
36
-            array($this, 'email_messenger_validator_config'),
37
-            5,
38
-            2
39
-        );
40
-        add_filter(
41
-            'FHEE__EE_Email_messenger__get_template_fields',
42
-            array($this, 'email_messenger_template_fields'),
43
-            5,
44
-            2
45
-        );
46
-        add_filter(
47
-            'FHEE__EE_Html_messenger__get_template_fields',
48
-            array($this, 'html_messenger_template_fields'),
49
-            5,
50
-            2
51
-        );
52
-        add_filter(
53
-            'FHEE__EE_Html_messenger__get_validator_config',
54
-            array($this, 'html_messenger_validator_config'),
55
-            5,
56
-            2
57
-        );
58
-        add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2);
59
-        add_filter(
60
-            'FHEE__EE_Pdf_messenger__get_validator_config',
61
-            array($this, 'pdf_messenger_validator_config'),
62
-            5,
63
-            2
64
-        );
65
-        add_filter(
66
-            'FHEE__EE_Messages_Template_Pack__get_specific_template__contents',
67
-            array($this, 'new_default_templates'),
68
-            5,
69
-            7
70
-        );
71
-        add_filter(
72
-            'FHEE__EE_Messages_Base__get_valid_shortcodes',
73
-            array($this, 'message_types_valid_shortcodes'),
74
-            5,
75
-            2
76
-        );
77
-
78
-        // shortcode parsers
79
-        add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2);
80
-        add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5);
81
-        add_filter(
82
-            'FHEE__EE_Recipient_List_Shortcodes__shortcodes',
83
-            array($this, 'additional_recipient_details_shortcodes'),
84
-            5,
85
-            2
86
-        );
87
-        add_filter(
88
-            'FHEE__EE_Recipient_List_Shortcodes__parser_after',
89
-            array($this, 'additional_recipient_details_parser'),
90
-            5,
91
-            5
92
-        );
93
-        add_filter(
94
-            'FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes',
95
-            array($this, 'additional_primary_registration_details_shortcodes'),
96
-            5,
97
-            2
98
-        );
99
-        add_filter(
100
-            'FHEE__EE_Primary_Registration_List_Shortcodes__parser_after',
101
-            array($this, 'additional_primary_registration_details_parser'),
102
-            5,
103
-            5
104
-        );
105
-
106
-        /**
107
-         * @since 4.2.0
108
-         */
109
-        add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2);
110
-        add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5);
111
-
112
-        /**
113
-         * @since 4.3.0
114
-         */
115
-        // eat our own dog food!
116
-        add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types'));
117
-        add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes'));
118
-        do_action('EE_Brewing_Regular___messages_caf');
119
-    }
120
-
121
-
122
-    /**
123
-     * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the
124
-     * messages system.
125
-     *
126
-     * @param  array $dir_ref original array of paths
127
-     *
128
-     * @return array           appended paths
129
-     */
130
-    public function messages_autoload_paths($dir_ref)
131
-    {
132
-        $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/';
133
-
134
-        return $dir_ref;
135
-    }
136
-
137
-
138
-    public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger)
139
-    {
140
-        $validator_config['attendee_list'] = array(
141
-            'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
142
-            'required'   => array('[ATTENDEE_LIST]'),
143
-        );
144
-        $validator_config['question_list'] = array(
145
-            'shortcodes' => array('question'),
146
-            'required'   => array('[QUESTION_LIST]'),
147
-        );
148
-
149
-        return $validator_config;
150
-    }
151
-
152
-
153
-    public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger)
154
-    {
155
-        $validator_config['attendee_list'] = array(
156
-            'shortcodes' => array('attendee', 'question_list'),
157
-            'required'   => array('[ATTENDEE_LIST]'),
158
-        );
159
-        $validator_config['question_list'] = array(
160
-            'shortcodes' => array('question'),
161
-            'required'   => array('[QUESTION_LIST]'),
162
-        );
163
-
164
-        return $validator_config;
165
-    }
166
-
167
-
168
-    public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger)
169
-    {
170
-        $validator_config['attendee_list'] = array(
171
-            'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
172
-            'required'   => array('[ATTENDEE_LIST]'),
173
-        );
174
-        $validator_config['question_list'] = array(
175
-            'shortcodes' => array('question'),
176
-            'required'   => array('[QUESTION_LIST]'),
177
-        );
178
-
179
-        return $validator_config;
180
-    }
181
-
182
-
183
-    public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger)
184
-    {
185
-        $template_fields['extra']['content']['question_list'] = array(
186
-            'input'               => 'textarea',
187
-            'label'               => '[QUESTION_LIST]',
188
-            'type'                => 'string',
189
-            'required'            => true,
190
-            'validation'          => true,
191
-            'format'              => '%s',
192
-            'css_class'           => 'large-text',
193
-            'rows'                => '5',
194
-            'shortcodes_required' => array('[QUESTION_LIST]'),
195
-        );
196
-
197
-        return $template_fields;
198
-    }
199
-
200
-
201
-    public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger)
202
-    {
203
-        $template_fields['extra']['content']['question_list'] = array(
204
-            'input'               => 'textarea',
205
-            'label'               => '[QUESTION_LIST]',
206
-            'type'                => 'string',
207
-            'required'            => true,
208
-            'validation'          => true,
209
-            'format'              => '%s',
210
-            'css_class'           => 'large-text',
211
-            'rows'                => '5',
212
-            'shortcodes_required' => array('[QUESTION_LIST]'),
213
-        );
214
-
215
-        return $template_fields;
216
-    }
217
-
218
-
219
-    public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger)
220
-    {
221
-        $template_fields['extra']['content']['question_list'] = array(
222
-            'input'               => 'textarea',
223
-            'label'               => '[QUESTION_LIST]',
224
-            'type'                => 'string',
225
-            'required'            => true,
226
-            'validation'          => true,
227
-            'format'              => '%s',
228
-            'css_class'           => 'large-text',
229
-            'rows'                => '5',
230
-            'shortcodes_required' => array('[QUESTION_LIST]'),
231
-        );
232
-
233
-        return $template_fields;
234
-    }
235
-
236
-
237
-    public function new_default_templates(
238
-        $contents,
239
-        $actual_path,
240
-        EE_messenger $messenger,
241
-        EE_message_type $message_type,
242
-        $field,
243
-        $context,
244
-        EE_Messages_Template_Pack $template_pack
245
-    ) {
246
-
247
-        // we're only modifying templates for the default template pack
248
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
249
-            return $contents;
250
-        }
251
-
252
-        // the template file name we're replacing contents for.
253
-        $template_file_prefix = $field . '_' . $context;
254
-        $msg_prefix = $messenger->name . '_' . $message_type->name . '_';
255
-
256
-        $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/';
257
-
258
-        if ($messenger->name == 'email' && $message_type->name == 'registration') {
259
-            switch ($template_file_prefix) {
260
-                case 'question_list_admin':
261
-                case 'question_list_attendee':
262
-                case 'question_list_primary_attendee':
263
-                    $path = $base_path . $msg_prefix . 'question_list.template.php';
264
-                    $contents = EEH_Template::display_template($path, array(), true);
265
-                    break;
266
-
267
-                case 'attendee_list_primary_attendee':
268
-                    $path = $base_path . $msg_prefix . 'attendee_list.template.php';
269
-                    $contents = EEH_Template::display_template($path, array(), true);
270
-                    break;
271
-
272
-                case 'attendee_list_admin':
273
-                    $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php';
274
-                    $contents = EEH_Template::display_template(
275
-                        $path,
276
-                        array(),
277
-                        true
278
-                    );
279
-                    break;
280
-
281
-                case 'attendee_list_attendee':
282
-                    $contents = '';
283
-                    break;
284
-
285
-                case 'event_list_attendee':
286
-                    $path = $base_path . $msg_prefix . 'event_list_attendee.template.php';
287
-                    $contents = EEH_Template::display_template($path, array(), true);
288
-                    break;
289
-            }
290
-        } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') {
291
-            switch ($template_file_prefix) {
292
-                case 'content_attendee':
293
-                    $path = $base_path . $msg_prefix . 'content.template.php';
294
-                    $contents = EEH_Template::display_template($path, array(), true);
295
-                    break;
296
-
297
-                case 'newsletter_content_attendee':
298
-                    $path = $base_path . $msg_prefix . 'newsletter_content.template.php';
299
-                    $contents = EEH_Template::display_template($path, array(), true);
300
-                    break;
301
-
302
-                case 'newsletter_subject_attendee':
303
-                    $path = $base_path . $msg_prefix . 'subject.template.php';
304
-                    $contents = EEH_Template::display_template($path, array(), true);
305
-                    break;
306
-            }
307
-        } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') {
308
-            switch ($template_file_prefix) {
309
-                case 'attendee_list_purchaser':
310
-                    $path = $base_path . $msg_prefix . 'attendee_list.template.php';
311
-                    $contents = EEH_Template::display_template($path, array(), true);
312
-                    break;
313
-            }
314
-        }
315
-
316
-        return $contents;
317
-    }
318
-
319
-
320
-    public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg)
321
-    {
322
-        // make sure question_list and question are ONLY added for the core message types.  Any other message types will have to explicitly set question_list as a valid shortcode.
323
-        $include_with = array(
324
-            'registration',
325
-            'cancelled_registration',
326
-            'declined_registration',
327
-            'not_approved_registration',
328
-            'payment_declined',
329
-            'payment_failed',
330
-            'payment_cancelled',
331
-            'payment',
332
-            'payment_reminder',
333
-            'pending_approval',
334
-            'registration_summary',
335
-            'invoice',
336
-            'receipt',
337
-        );
338
-        if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) {
339
-            $contexts = array_keys($msg->get_contexts());
340
-            foreach ($contexts as $context) {
341
-                $valid_shortcodes[ $context ][] = 'question_list';
342
-                $valid_shortcodes[ $context ][] = 'question';
343
-            }
344
-        }
345
-
346
-        return $valid_shortcodes;
347
-    }
348
-
349
-
350
-    public function additional_attendee_shortcodes($shortcodes, $shortcode_parser)
351
-    {
352
-        $shortcodes['[ANSWER_*]'] = __(
353
-            'This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.',
354
-            'event_espresso'
355
-        );
356
-
357
-        return $shortcodes;
358
-    }
359
-
360
-
361
-    public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
362
-    {
363
-
364
-        if (
365
-            strpos($shortcode, '[ANSWER_*') === false
366
-            || ! isset($extra_data['data']->questions)
367
-            || ! isset($extra_data['data']->registrations)
368
-        ) {
369
-            return $parsed;
370
-        }
371
-
372
-        // let's get the question from the code.
373
-        $shortcode = str_replace('[ANSWER_*', '', $shortcode);
374
-        $shortcode = trim(str_replace(']', '', $shortcode));
375
-
376
-        $registration = $data instanceof EE_Registration ? $data : null;
377
-        $registration = ! $registration instanceof EE_Registration && is_array(
378
-            $extra_data
379
-        ) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration;
380
-
381
-        $aee = $data instanceof EE_Messages_Addressee ? $data : null;
382
-        $aee = ! $aee instanceof EE_Messages_Addressee && is_array(
383
-            $extra_data
384
-        ) && isset($extra_data['data']) ? $extra_data['data'] : $aee;
385
-
386
-        if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) {
387
-            return $parsed;
388
-        }
389
-
390
-        // now let's figure out which question has this text.
391
-        foreach ($aee->questions as $ansid => $question) {
392
-            if (
393
-                $question instanceof EE_Question
394
-                && trim($question->display_text()) == trim($shortcode)
395
-                && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ])
396
-            ) {
397
-                return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty(
398
-                    'ANS_value',
399
-                    'no_wpautop'
400
-                );
401
-            }
402
-        }
403
-
404
-        // nothing!
405
-        return $parsed;
406
-    }
407
-
408
-
409
-    /**
410
-     * Callback for additional shortcodes filter for adding additional datetime shortcodes.
411
-     *
412
-     * @since  4.2
413
-     *
414
-     * @param  array                  $shortcodes         array of shortcodes and
415
-     *                                                    descriptions
416
-     * @param  EE_Datetime_Shortcodes $shortcode_parser   EE_Shortcodes object
417
-     *
418
-     * @return array                                        array of shortcodes and
419
-     *                                                        descriptions
420
-     */
421
-    public function additional_datetime_shortcodes($shortcodes, $shortcode_parser)
422
-    {
423
-        $shortcodes['[DTT_NAME]'] = __(
424
-            'This will be parsed to the Title given for a Datetime',
425
-            'event_espresso'
426
-        );
427
-        $shortcodes['[DTT_DESCRIPTION]'] = __(
428
-            'This will be parsed to the description for a Datetime',
429
-            'event_espresso'
430
-        );
431
-        $shortcodes['[DTT_NAME_OR_DATES]'] = __(
432
-            'When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.',
433
-            'event_espresso'
434
-        );
435
-
436
-        return $shortcodes;
437
-    }
438
-
439
-
440
-    /**
441
-     * Callback for additional shortcodes parser filter used for adding parser for new
442
-     * Datetime shortcodes
443
-     *
444
-     * @since  4.2
445
-     *
446
-     * @param  string                 $parsed     The finished parsed string for the given shortcode.
447
-     * @param  string                 $shortcode  The shortcode being parsed.
448
-     * @param  object                 $data       The incoming data object for the Shortcode Parser.
449
-     * @param  object                 $extra_data The incoming extra date object for the Shortcode
450
-     *                                            Parser.
451
-     * @param  EE_Datetime_Shortcodes $shortcode_parser
452
-     *
453
-     * @return string                   The new parsed string.
454
-     */
455
-    public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
456
-    {
457
-
458
-        if (! $data instanceof EE_Datetime) {
459
-            return ''; // get out because we can only parse with the datetime object.
460
-        }
461
-
462
-        switch ($shortcode) {
463
-            case '[DTT_NAME]':
464
-                return $data->name();
465
-                break;
466
-            case '[DTT_DESCRIPTION]':
467
-                return $data->description();
468
-                break;
469
-            case '[DTT_NAME_OR_DATES]':
470
-                return $data->get_dtt_display_name(true);
471
-                break;
472
-            default:
473
-                return $parsed;
474
-                break;
475
-        }
476
-    }
477
-
478
-
479
-    public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser)
480
-    {
481
-        $shortcodes['[RECIPIENT_QUESTION_LIST]'] = __(
482
-            'This is used to indicate where you want the list of questions and answers to show for the person receiving the message.',
483
-            'event_espresso'
484
-        );
485
-
486
-        return $shortcodes;
487
-    }
488
-
489
-
490
-    /**
491
-     * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter).
492
-     *
493
-     * @param string         $parsed           The original parsed content for the shortcode
494
-     * @param string         $shortcode        The shortcode being parsed
495
-     * @param array          $data             The shortcode parser data array
496
-     * @param array          $extra_data       The shortcode parser extra data array
497
-     * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
498
-     *
499
-     * @return string
500
-     */
501
-    public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
502
-    {
503
-
504
-        if (array($data) && ! isset($data['data'])) {
505
-            return $parsed;
506
-        }
507
-
508
-        $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
509
-        $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
510
-
511
-        if (! $recipient instanceof EE_Messages_Addressee) {
512
-            return $parsed;
513
-        }
514
-
515
-        switch ($shortcode) {
516
-            case '[RECIPIENT_QUESTION_LIST]':
517
-                $att = $recipient->att_obj;
518
-                $registrations_on_attendee = $att instanceof EE_Attendee
519
-                    ? $recipient->attendees[ $att->ID() ]['reg_objs']
520
-                    : array();
521
-                $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee;
522
-                $answers = array();
523
-
524
-                $template = is_array($data['template']) && isset($data['template']['question_list'])
525
-                    ? $data['template']['question_list']
526
-                    : $extra_data['template']['question_list'];
527
-                $valid_shortcodes = array('question');
528
-
529
-                // if the context is main_content then get all answers for all registrations on this attendee
530
-                if ($data['data'] instanceof EE_Messages_Addressee) {
531
-                    foreach ($registrations_on_attendee as $reg) {
532
-                        if ($reg instanceof EE_Registration) {
533
-                            $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
534
-                                ? $recipient->registrations[ $reg->ID() ]['ans_objs']
535
-                                : array();
536
-                            foreach ($anss as $ans) {
537
-                                if ($ans instanceof EE_Answer) {
538
-                                    $answers[ $ans->ID() ] = $ans;
539
-                                }
540
-                            }
541
-                        }
542
-                    }
543
-                }
544
-
545
-                // if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event.
546
-                if ($data['data'] instanceof EE_Event) {
547
-                    $event = $data['data'];
548
-                    foreach ($registrations_on_attendee as $reg) {
549
-                        if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
550
-                            $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
551
-                                ? $recipient->registrations[ $reg->ID() ]['ans_objs']
552
-                                : array();
553
-                            foreach ($anss as $ans) {
554
-                                if ($ans instanceof EE_Answer) {
555
-                                    $answers[ $ans->ID() ] = $ans;
556
-                                }
557
-                            }
558
-                        }
559
-                    }
560
-                }
561
-
562
-                $questions = $questions = isset($recipient->questions) ? $recipient->questions : array();
563
-
564
-                // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
565
-                // object on it.
566
-                if (! isset($extra_data['data'])) {
567
-                    $extra_data['data'] = $recipient;
568
-                }
569
-
570
-                return $this->_parse_question_list_for_primary_or_recipient_registration(
571
-                    $shortcode_parser,
572
-                    $questions,
573
-                    $answers,
574
-                    $template,
575
-                    $valid_shortcodes,
576
-                    $extra_data
577
-                );
578
-                break;
579
-
580
-            default:
581
-                return $parsed;
582
-                break;
583
-        }
584
-    }
585
-
586
-
587
-    public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser)
588
-    {
589
-        $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __(
590
-            'This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field',
591
-            'event_espresso'
592
-        );
593
-
594
-        return $shortcodes;
595
-    }
596
-
597
-
598
-    /**
599
-     * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter).
600
-     *
601
-     * @param string         $parsed           The original parsed content for the shortcode
602
-     * @param string         $shortcode        The shortcode being parsed
603
-     * @param array          $data             The shortcode parser data array
604
-     * @param array          $extra_data       The shortcode parser extra data array
605
-     * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
606
-     *
607
-     * @return string
608
-     */
609
-    public function additional_primary_registration_details_parser(
610
-        $parsed,
611
-        $shortcode,
612
-        $data,
613
-        $extra_data,
614
-        $shortcode_parser
615
-    ) {
616
-        if (array($data) && ! isset($data['data'])) {
617
-            return $parsed;
618
-        }
619
-
620
-        $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
621
-        $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
622
-
623
-        if (! $recipient instanceof EE_Messages_Addressee) {
624
-            return $parsed;
625
-        }
626
-
627
-        switch ($shortcode) {
628
-            case '[PRIMARY_REGISTRANT_QUESTION_LIST]':
629
-                if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) {
630
-                    return '';
631
-                }
632
-                $registration = $recipient->primary_reg_obj;
633
-                $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs'])
634
-                    ? $recipient->registrations[ $registration->ID() ]['ans_objs']
635
-                    : array();
636
-                if (empty($answers)) {
637
-                    return '';
638
-                }
639
-                $template = is_array($data['template']) && isset($data['template']['question_list'])
640
-                    ? $data['template']['question_list']
641
-                    : $extra_data['template']['question_list'];
642
-                $valid_shortcodes = array('question');
643
-                $answers = $recipient->registrations[ $registration->ID() ]['ans_objs'];
644
-                $questions = isset($recipient->questions) ? $recipient->questions : array();
645
-                // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
646
-                // object on it.
647
-                if (! isset($extra_data['data'])) {
648
-                    $extra_data['data'] = $recipient;
649
-                }
650
-                return $this->_parse_question_list_for_primary_or_recipient_registration(
651
-                    $shortcode_parser,
652
-                    $questions,
653
-                    $answers,
654
-                    $template,
655
-                    $valid_shortcodes,
656
-                    $extra_data
657
-                );
658
-                break;
659
-
660
-            default:
661
-                return $parsed;
662
-                break;
663
-        }
664
-    }
665
-
666
-
667
-    /**
668
-     * Takes care of registering the  message types that are only available in caffeinated EE.
669
-     *
670
-     * @since   4.3.2
671
-     *
672
-     * @return  void
673
-     */
674
-    public function register_caf_message_types()
675
-    {
676
-        // register newsletter message type
677
-        $setup_args = array(
678
-            'mtfilename'                                       => 'EE_Newsletter_message_type.class.php',
679
-            'autoloadpaths'                                    => array(
680
-                EE_CAF_LIBRARIES . 'messages/message_type/newsletter/',
681
-            ),
682
-            'messengers_to_activate_with'                      => array('email'),
683
-            'messengers_to_validate_with'                      => array('email'),
684
-            'messengers_supporting_default_template_pack_with' => array('email'),
685
-        );
686
-        EE_Register_Message_Type::register('newsletter', $setup_args);
687
-
688
-        // register payment reminder message type
689
-        $setup_args = array(
690
-            'mtfilename'                                       => 'EE_Payment_Reminder_message_type.class.php',
691
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'),
692
-            'messengers_to_activate_with'                      => array('email'),
693
-            'messengers_to_validate_with'                      => array('email'),
694
-            'messengers_supporting_default_template_pack_with' => array('email'),
695
-        );
696
-        EE_Register_Message_Type::register('payment_reminder', $setup_args);
697
-
698
-        // register payment declined message type
699
-        $setup_args = array(
700
-            'mtfilename'                                       => 'EE_Payment_Declined_message_type.class.php',
701
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'),
702
-            'messengers_to_activate_with'                      => array('email'),
703
-            'messengers_to_validate_with'                      => array('email'),
704
-            'messengers_supporting_default_template_pack_with' => array('email'),
705
-        );
706
-        EE_Register_Message_Type::register('payment_declined', $setup_args);
707
-
708
-        // register registration declined message type
709
-        $setup_args = array(
710
-            'mtfilename'                                       => 'EE_Declined_Registration_message_type.class.php',
711
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'),
712
-            'messengers_to_activate_with'                      => array('email'),
713
-            'messengers_to_validate_with'                      => array('email'),
714
-            'messengers_supporting_default_template_pack_with' => array('email'),
715
-        );
716
-        EE_Register_Message_Type::register('declined_registration', $setup_args);
717
-
718
-        // register registration cancelled message type
719
-        $setup_args = array(
720
-            'mtfilename'                                       => 'EE_Cancelled_Registration_message_type.class.php',
721
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'),
722
-            'messengers_to_activate_with'                      => array('email'),
723
-            'messengers_to_validate_with'                      => array('email'),
724
-            'messengers_supporting_default_template_pack_with' => array('email'),
725
-        );
726
-        EE_Register_Message_Type::register('cancelled_registration', $setup_args);
727
-
728
-
729
-        // register payment failed message type
730
-        $setup_args = array(
731
-            'mtfilename'                                       => 'EE_Payment_Failed_message_type.class.php',
732
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'),
733
-            'messengers_to_activate_with'                      => array('email'),
734
-            'messengers_to_validate_with'                      => array('email'),
735
-            'messengers_supporting_default_template_pack_with' => array('email'),
736
-        );
737
-        EE_Register_Message_Type::register('payment_failed', $setup_args);
738
-
739
-        // register payment declined message type
740
-        $setup_args = array(
741
-            'mtfilename'                                       => 'EE_Payment_Cancelled_message_type.class.php',
742
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'),
743
-            'messengers_to_activate_with'                      => array('email'),
744
-            'messengers_to_validate_with'                      => array('email'),
745
-            'messengers_supporting_default_template_pack_with' => array('email'),
746
-        );
747
-        EE_Register_Message_Type::register('payment_cancelled', $setup_args);
748
-    }
749
-
750
-
751
-    /**
752
-     * Takes care of registering the  shortcode libraries implemented with caffeinated EE and set up related items.
753
-     *
754
-     * @since   4.3.2
755
-     *
756
-     * @return void
757
-     */
758
-    public function register_caf_shortcodes()
759
-    {
760
-        $setup_args = array(
761
-            'autoloadpaths'                 => array(
762
-                EE_CAF_LIBRARIES . 'shortcodes/',
763
-            ),
764
-            'msgr_validator_callback'       => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'),
765
-            'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'),
766
-            'list_type_shortcodes'          => array('[NEWSLETTER_CONTENT]'),
767
-        );
768
-        EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args);
769
-    }
770
-
771
-
772
-    /**
773
-     * Parses a question list shortcode using given data and template
774
-     *
775
-     * @param \EE_Shortcodes $shortcode_parser
776
-     * @param EE_Question[]  $questions        An array of questions indexed by answer id.
777
-     * @param EE_Answer[]    $answers          An array of answer objects
778
-     * @param string         $template         Template content to be parsed.
779
-     * @param array          $valid_shortcodes Valid shortcodes for the template being parsed.
780
-     * @param array          $extra_data       Extra data that might be used when parsing the template.
781
-     */
782
-    protected function _parse_question_list_for_primary_or_recipient_registration(
783
-        $shortcode_parser,
784
-        $questions,
785
-        $answers,
786
-        $template,
787
-        $valid_shortcodes,
788
-        $extra_data
789
-    ) {
790
-        $question_list = '';
791
-        /** @var EEH_Parse_Shortcodes $shortcode_helper */
792
-        $shortcode_helper = $shortcode_parser->get_shortcode_helper();
793
-        foreach ($answers as $answer) {
794
-            if ($answer instanceof EE_Answer) {
795
-                // first see if the question is in our $questions array. If not then try to get from answer object.
796
-                $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null;
797
-                $question = ! $question instanceof EE_Question ? $answer->question() : $question;
798
-                if (
799
-                    ! $question instanceof EE_Question
800
-                    || (
801
-                        $question instanceof EE_Question
802
-                        && $question->admin_only()
803
-                    )
804
-                ) {
805
-                    continue;
806
-                }
807
-                $question_list .= $shortcode_helper->parse_question_list_template(
808
-                    $template,
809
-                    $answer,
810
-                    $valid_shortcodes,
811
-                    $extra_data
812
-                );
813
-            }
814
-        }
815
-        return $question_list;
816
-    }
15
+	/**
16
+	 * constructor.
17
+	 */
18
+	public function __construct()
19
+	{
20
+		$this->_caf_hooks();
21
+	}
22
+
23
+
24
+	/**
25
+	 * Contains all the hooks filters for setting up caffeinated messages functionality.
26
+	 *
27
+	 * @since 4.3.2
28
+	 *
29
+	 * @return void
30
+	 */
31
+	private function _caf_hooks()
32
+	{
33
+		add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5);
34
+		add_filter(
35
+			'FHEE__EE_Email_messenger__get_validator_config',
36
+			array($this, 'email_messenger_validator_config'),
37
+			5,
38
+			2
39
+		);
40
+		add_filter(
41
+			'FHEE__EE_Email_messenger__get_template_fields',
42
+			array($this, 'email_messenger_template_fields'),
43
+			5,
44
+			2
45
+		);
46
+		add_filter(
47
+			'FHEE__EE_Html_messenger__get_template_fields',
48
+			array($this, 'html_messenger_template_fields'),
49
+			5,
50
+			2
51
+		);
52
+		add_filter(
53
+			'FHEE__EE_Html_messenger__get_validator_config',
54
+			array($this, 'html_messenger_validator_config'),
55
+			5,
56
+			2
57
+		);
58
+		add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2);
59
+		add_filter(
60
+			'FHEE__EE_Pdf_messenger__get_validator_config',
61
+			array($this, 'pdf_messenger_validator_config'),
62
+			5,
63
+			2
64
+		);
65
+		add_filter(
66
+			'FHEE__EE_Messages_Template_Pack__get_specific_template__contents',
67
+			array($this, 'new_default_templates'),
68
+			5,
69
+			7
70
+		);
71
+		add_filter(
72
+			'FHEE__EE_Messages_Base__get_valid_shortcodes',
73
+			array($this, 'message_types_valid_shortcodes'),
74
+			5,
75
+			2
76
+		);
77
+
78
+		// shortcode parsers
79
+		add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2);
80
+		add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5);
81
+		add_filter(
82
+			'FHEE__EE_Recipient_List_Shortcodes__shortcodes',
83
+			array($this, 'additional_recipient_details_shortcodes'),
84
+			5,
85
+			2
86
+		);
87
+		add_filter(
88
+			'FHEE__EE_Recipient_List_Shortcodes__parser_after',
89
+			array($this, 'additional_recipient_details_parser'),
90
+			5,
91
+			5
92
+		);
93
+		add_filter(
94
+			'FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes',
95
+			array($this, 'additional_primary_registration_details_shortcodes'),
96
+			5,
97
+			2
98
+		);
99
+		add_filter(
100
+			'FHEE__EE_Primary_Registration_List_Shortcodes__parser_after',
101
+			array($this, 'additional_primary_registration_details_parser'),
102
+			5,
103
+			5
104
+		);
105
+
106
+		/**
107
+		 * @since 4.2.0
108
+		 */
109
+		add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2);
110
+		add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5);
111
+
112
+		/**
113
+		 * @since 4.3.0
114
+		 */
115
+		// eat our own dog food!
116
+		add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types'));
117
+		add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes'));
118
+		do_action('EE_Brewing_Regular___messages_caf');
119
+	}
120
+
121
+
122
+	/**
123
+	 * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the
124
+	 * messages system.
125
+	 *
126
+	 * @param  array $dir_ref original array of paths
127
+	 *
128
+	 * @return array           appended paths
129
+	 */
130
+	public function messages_autoload_paths($dir_ref)
131
+	{
132
+		$dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/';
133
+
134
+		return $dir_ref;
135
+	}
136
+
137
+
138
+	public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger)
139
+	{
140
+		$validator_config['attendee_list'] = array(
141
+			'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
142
+			'required'   => array('[ATTENDEE_LIST]'),
143
+		);
144
+		$validator_config['question_list'] = array(
145
+			'shortcodes' => array('question'),
146
+			'required'   => array('[QUESTION_LIST]'),
147
+		);
148
+
149
+		return $validator_config;
150
+	}
151
+
152
+
153
+	public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger)
154
+	{
155
+		$validator_config['attendee_list'] = array(
156
+			'shortcodes' => array('attendee', 'question_list'),
157
+			'required'   => array('[ATTENDEE_LIST]'),
158
+		);
159
+		$validator_config['question_list'] = array(
160
+			'shortcodes' => array('question'),
161
+			'required'   => array('[QUESTION_LIST]'),
162
+		);
163
+
164
+		return $validator_config;
165
+	}
166
+
167
+
168
+	public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger)
169
+	{
170
+		$validator_config['attendee_list'] = array(
171
+			'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
172
+			'required'   => array('[ATTENDEE_LIST]'),
173
+		);
174
+		$validator_config['question_list'] = array(
175
+			'shortcodes' => array('question'),
176
+			'required'   => array('[QUESTION_LIST]'),
177
+		);
178
+
179
+		return $validator_config;
180
+	}
181
+
182
+
183
+	public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger)
184
+	{
185
+		$template_fields['extra']['content']['question_list'] = array(
186
+			'input'               => 'textarea',
187
+			'label'               => '[QUESTION_LIST]',
188
+			'type'                => 'string',
189
+			'required'            => true,
190
+			'validation'          => true,
191
+			'format'              => '%s',
192
+			'css_class'           => 'large-text',
193
+			'rows'                => '5',
194
+			'shortcodes_required' => array('[QUESTION_LIST]'),
195
+		);
196
+
197
+		return $template_fields;
198
+	}
199
+
200
+
201
+	public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger)
202
+	{
203
+		$template_fields['extra']['content']['question_list'] = array(
204
+			'input'               => 'textarea',
205
+			'label'               => '[QUESTION_LIST]',
206
+			'type'                => 'string',
207
+			'required'            => true,
208
+			'validation'          => true,
209
+			'format'              => '%s',
210
+			'css_class'           => 'large-text',
211
+			'rows'                => '5',
212
+			'shortcodes_required' => array('[QUESTION_LIST]'),
213
+		);
214
+
215
+		return $template_fields;
216
+	}
217
+
218
+
219
+	public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger)
220
+	{
221
+		$template_fields['extra']['content']['question_list'] = array(
222
+			'input'               => 'textarea',
223
+			'label'               => '[QUESTION_LIST]',
224
+			'type'                => 'string',
225
+			'required'            => true,
226
+			'validation'          => true,
227
+			'format'              => '%s',
228
+			'css_class'           => 'large-text',
229
+			'rows'                => '5',
230
+			'shortcodes_required' => array('[QUESTION_LIST]'),
231
+		);
232
+
233
+		return $template_fields;
234
+	}
235
+
236
+
237
+	public function new_default_templates(
238
+		$contents,
239
+		$actual_path,
240
+		EE_messenger $messenger,
241
+		EE_message_type $message_type,
242
+		$field,
243
+		$context,
244
+		EE_Messages_Template_Pack $template_pack
245
+	) {
246
+
247
+		// we're only modifying templates for the default template pack
248
+		if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
249
+			return $contents;
250
+		}
251
+
252
+		// the template file name we're replacing contents for.
253
+		$template_file_prefix = $field . '_' . $context;
254
+		$msg_prefix = $messenger->name . '_' . $message_type->name . '_';
255
+
256
+		$base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/';
257
+
258
+		if ($messenger->name == 'email' && $message_type->name == 'registration') {
259
+			switch ($template_file_prefix) {
260
+				case 'question_list_admin':
261
+				case 'question_list_attendee':
262
+				case 'question_list_primary_attendee':
263
+					$path = $base_path . $msg_prefix . 'question_list.template.php';
264
+					$contents = EEH_Template::display_template($path, array(), true);
265
+					break;
266
+
267
+				case 'attendee_list_primary_attendee':
268
+					$path = $base_path . $msg_prefix . 'attendee_list.template.php';
269
+					$contents = EEH_Template::display_template($path, array(), true);
270
+					break;
271
+
272
+				case 'attendee_list_admin':
273
+					$path = $base_path . $msg_prefix . 'attendee_list_admin.template.php';
274
+					$contents = EEH_Template::display_template(
275
+						$path,
276
+						array(),
277
+						true
278
+					);
279
+					break;
280
+
281
+				case 'attendee_list_attendee':
282
+					$contents = '';
283
+					break;
284
+
285
+				case 'event_list_attendee':
286
+					$path = $base_path . $msg_prefix . 'event_list_attendee.template.php';
287
+					$contents = EEH_Template::display_template($path, array(), true);
288
+					break;
289
+			}
290
+		} elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') {
291
+			switch ($template_file_prefix) {
292
+				case 'content_attendee':
293
+					$path = $base_path . $msg_prefix . 'content.template.php';
294
+					$contents = EEH_Template::display_template($path, array(), true);
295
+					break;
296
+
297
+				case 'newsletter_content_attendee':
298
+					$path = $base_path . $msg_prefix . 'newsletter_content.template.php';
299
+					$contents = EEH_Template::display_template($path, array(), true);
300
+					break;
301
+
302
+				case 'newsletter_subject_attendee':
303
+					$path = $base_path . $msg_prefix . 'subject.template.php';
304
+					$contents = EEH_Template::display_template($path, array(), true);
305
+					break;
306
+			}
307
+		} elseif ($messenger->name == 'html' && $message_type->name == 'receipt') {
308
+			switch ($template_file_prefix) {
309
+				case 'attendee_list_purchaser':
310
+					$path = $base_path . $msg_prefix . 'attendee_list.template.php';
311
+					$contents = EEH_Template::display_template($path, array(), true);
312
+					break;
313
+			}
314
+		}
315
+
316
+		return $contents;
317
+	}
318
+
319
+
320
+	public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg)
321
+	{
322
+		// make sure question_list and question are ONLY added for the core message types.  Any other message types will have to explicitly set question_list as a valid shortcode.
323
+		$include_with = array(
324
+			'registration',
325
+			'cancelled_registration',
326
+			'declined_registration',
327
+			'not_approved_registration',
328
+			'payment_declined',
329
+			'payment_failed',
330
+			'payment_cancelled',
331
+			'payment',
332
+			'payment_reminder',
333
+			'pending_approval',
334
+			'registration_summary',
335
+			'invoice',
336
+			'receipt',
337
+		);
338
+		if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) {
339
+			$contexts = array_keys($msg->get_contexts());
340
+			foreach ($contexts as $context) {
341
+				$valid_shortcodes[ $context ][] = 'question_list';
342
+				$valid_shortcodes[ $context ][] = 'question';
343
+			}
344
+		}
345
+
346
+		return $valid_shortcodes;
347
+	}
348
+
349
+
350
+	public function additional_attendee_shortcodes($shortcodes, $shortcode_parser)
351
+	{
352
+		$shortcodes['[ANSWER_*]'] = __(
353
+			'This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.',
354
+			'event_espresso'
355
+		);
356
+
357
+		return $shortcodes;
358
+	}
359
+
360
+
361
+	public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
362
+	{
363
+
364
+		if (
365
+			strpos($shortcode, '[ANSWER_*') === false
366
+			|| ! isset($extra_data['data']->questions)
367
+			|| ! isset($extra_data['data']->registrations)
368
+		) {
369
+			return $parsed;
370
+		}
371
+
372
+		// let's get the question from the code.
373
+		$shortcode = str_replace('[ANSWER_*', '', $shortcode);
374
+		$shortcode = trim(str_replace(']', '', $shortcode));
375
+
376
+		$registration = $data instanceof EE_Registration ? $data : null;
377
+		$registration = ! $registration instanceof EE_Registration && is_array(
378
+			$extra_data
379
+		) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration;
380
+
381
+		$aee = $data instanceof EE_Messages_Addressee ? $data : null;
382
+		$aee = ! $aee instanceof EE_Messages_Addressee && is_array(
383
+			$extra_data
384
+		) && isset($extra_data['data']) ? $extra_data['data'] : $aee;
385
+
386
+		if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) {
387
+			return $parsed;
388
+		}
389
+
390
+		// now let's figure out which question has this text.
391
+		foreach ($aee->questions as $ansid => $question) {
392
+			if (
393
+				$question instanceof EE_Question
394
+				&& trim($question->display_text()) == trim($shortcode)
395
+				&& isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ])
396
+			) {
397
+				return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty(
398
+					'ANS_value',
399
+					'no_wpautop'
400
+				);
401
+			}
402
+		}
403
+
404
+		// nothing!
405
+		return $parsed;
406
+	}
407
+
408
+
409
+	/**
410
+	 * Callback for additional shortcodes filter for adding additional datetime shortcodes.
411
+	 *
412
+	 * @since  4.2
413
+	 *
414
+	 * @param  array                  $shortcodes         array of shortcodes and
415
+	 *                                                    descriptions
416
+	 * @param  EE_Datetime_Shortcodes $shortcode_parser   EE_Shortcodes object
417
+	 *
418
+	 * @return array                                        array of shortcodes and
419
+	 *                                                        descriptions
420
+	 */
421
+	public function additional_datetime_shortcodes($shortcodes, $shortcode_parser)
422
+	{
423
+		$shortcodes['[DTT_NAME]'] = __(
424
+			'This will be parsed to the Title given for a Datetime',
425
+			'event_espresso'
426
+		);
427
+		$shortcodes['[DTT_DESCRIPTION]'] = __(
428
+			'This will be parsed to the description for a Datetime',
429
+			'event_espresso'
430
+		);
431
+		$shortcodes['[DTT_NAME_OR_DATES]'] = __(
432
+			'When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.',
433
+			'event_espresso'
434
+		);
435
+
436
+		return $shortcodes;
437
+	}
438
+
439
+
440
+	/**
441
+	 * Callback for additional shortcodes parser filter used for adding parser for new
442
+	 * Datetime shortcodes
443
+	 *
444
+	 * @since  4.2
445
+	 *
446
+	 * @param  string                 $parsed     The finished parsed string for the given shortcode.
447
+	 * @param  string                 $shortcode  The shortcode being parsed.
448
+	 * @param  object                 $data       The incoming data object for the Shortcode Parser.
449
+	 * @param  object                 $extra_data The incoming extra date object for the Shortcode
450
+	 *                                            Parser.
451
+	 * @param  EE_Datetime_Shortcodes $shortcode_parser
452
+	 *
453
+	 * @return string                   The new parsed string.
454
+	 */
455
+	public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
456
+	{
457
+
458
+		if (! $data instanceof EE_Datetime) {
459
+			return ''; // get out because we can only parse with the datetime object.
460
+		}
461
+
462
+		switch ($shortcode) {
463
+			case '[DTT_NAME]':
464
+				return $data->name();
465
+				break;
466
+			case '[DTT_DESCRIPTION]':
467
+				return $data->description();
468
+				break;
469
+			case '[DTT_NAME_OR_DATES]':
470
+				return $data->get_dtt_display_name(true);
471
+				break;
472
+			default:
473
+				return $parsed;
474
+				break;
475
+		}
476
+	}
477
+
478
+
479
+	public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser)
480
+	{
481
+		$shortcodes['[RECIPIENT_QUESTION_LIST]'] = __(
482
+			'This is used to indicate where you want the list of questions and answers to show for the person receiving the message.',
483
+			'event_espresso'
484
+		);
485
+
486
+		return $shortcodes;
487
+	}
488
+
489
+
490
+	/**
491
+	 * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter).
492
+	 *
493
+	 * @param string         $parsed           The original parsed content for the shortcode
494
+	 * @param string         $shortcode        The shortcode being parsed
495
+	 * @param array          $data             The shortcode parser data array
496
+	 * @param array          $extra_data       The shortcode parser extra data array
497
+	 * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
498
+	 *
499
+	 * @return string
500
+	 */
501
+	public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
502
+	{
503
+
504
+		if (array($data) && ! isset($data['data'])) {
505
+			return $parsed;
506
+		}
507
+
508
+		$recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
509
+		$recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
510
+
511
+		if (! $recipient instanceof EE_Messages_Addressee) {
512
+			return $parsed;
513
+		}
514
+
515
+		switch ($shortcode) {
516
+			case '[RECIPIENT_QUESTION_LIST]':
517
+				$att = $recipient->att_obj;
518
+				$registrations_on_attendee = $att instanceof EE_Attendee
519
+					? $recipient->attendees[ $att->ID() ]['reg_objs']
520
+					: array();
521
+				$registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee;
522
+				$answers = array();
523
+
524
+				$template = is_array($data['template']) && isset($data['template']['question_list'])
525
+					? $data['template']['question_list']
526
+					: $extra_data['template']['question_list'];
527
+				$valid_shortcodes = array('question');
528
+
529
+				// if the context is main_content then get all answers for all registrations on this attendee
530
+				if ($data['data'] instanceof EE_Messages_Addressee) {
531
+					foreach ($registrations_on_attendee as $reg) {
532
+						if ($reg instanceof EE_Registration) {
533
+							$anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
534
+								? $recipient->registrations[ $reg->ID() ]['ans_objs']
535
+								: array();
536
+							foreach ($anss as $ans) {
537
+								if ($ans instanceof EE_Answer) {
538
+									$answers[ $ans->ID() ] = $ans;
539
+								}
540
+							}
541
+						}
542
+					}
543
+				}
544
+
545
+				// if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event.
546
+				if ($data['data'] instanceof EE_Event) {
547
+					$event = $data['data'];
548
+					foreach ($registrations_on_attendee as $reg) {
549
+						if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
550
+							$anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
551
+								? $recipient->registrations[ $reg->ID() ]['ans_objs']
552
+								: array();
553
+							foreach ($anss as $ans) {
554
+								if ($ans instanceof EE_Answer) {
555
+									$answers[ $ans->ID() ] = $ans;
556
+								}
557
+							}
558
+						}
559
+					}
560
+				}
561
+
562
+				$questions = $questions = isset($recipient->questions) ? $recipient->questions : array();
563
+
564
+				// if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
565
+				// object on it.
566
+				if (! isset($extra_data['data'])) {
567
+					$extra_data['data'] = $recipient;
568
+				}
569
+
570
+				return $this->_parse_question_list_for_primary_or_recipient_registration(
571
+					$shortcode_parser,
572
+					$questions,
573
+					$answers,
574
+					$template,
575
+					$valid_shortcodes,
576
+					$extra_data
577
+				);
578
+				break;
579
+
580
+			default:
581
+				return $parsed;
582
+				break;
583
+		}
584
+	}
585
+
586
+
587
+	public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser)
588
+	{
589
+		$shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __(
590
+			'This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field',
591
+			'event_espresso'
592
+		);
593
+
594
+		return $shortcodes;
595
+	}
596
+
597
+
598
+	/**
599
+	 * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter).
600
+	 *
601
+	 * @param string         $parsed           The original parsed content for the shortcode
602
+	 * @param string         $shortcode        The shortcode being parsed
603
+	 * @param array          $data             The shortcode parser data array
604
+	 * @param array          $extra_data       The shortcode parser extra data array
605
+	 * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
606
+	 *
607
+	 * @return string
608
+	 */
609
+	public function additional_primary_registration_details_parser(
610
+		$parsed,
611
+		$shortcode,
612
+		$data,
613
+		$extra_data,
614
+		$shortcode_parser
615
+	) {
616
+		if (array($data) && ! isset($data['data'])) {
617
+			return $parsed;
618
+		}
619
+
620
+		$recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
621
+		$recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
622
+
623
+		if (! $recipient instanceof EE_Messages_Addressee) {
624
+			return $parsed;
625
+		}
626
+
627
+		switch ($shortcode) {
628
+			case '[PRIMARY_REGISTRANT_QUESTION_LIST]':
629
+				if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) {
630
+					return '';
631
+				}
632
+				$registration = $recipient->primary_reg_obj;
633
+				$answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs'])
634
+					? $recipient->registrations[ $registration->ID() ]['ans_objs']
635
+					: array();
636
+				if (empty($answers)) {
637
+					return '';
638
+				}
639
+				$template = is_array($data['template']) && isset($data['template']['question_list'])
640
+					? $data['template']['question_list']
641
+					: $extra_data['template']['question_list'];
642
+				$valid_shortcodes = array('question');
643
+				$answers = $recipient->registrations[ $registration->ID() ]['ans_objs'];
644
+				$questions = isset($recipient->questions) ? $recipient->questions : array();
645
+				// if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
646
+				// object on it.
647
+				if (! isset($extra_data['data'])) {
648
+					$extra_data['data'] = $recipient;
649
+				}
650
+				return $this->_parse_question_list_for_primary_or_recipient_registration(
651
+					$shortcode_parser,
652
+					$questions,
653
+					$answers,
654
+					$template,
655
+					$valid_shortcodes,
656
+					$extra_data
657
+				);
658
+				break;
659
+
660
+			default:
661
+				return $parsed;
662
+				break;
663
+		}
664
+	}
665
+
666
+
667
+	/**
668
+	 * Takes care of registering the  message types that are only available in caffeinated EE.
669
+	 *
670
+	 * @since   4.3.2
671
+	 *
672
+	 * @return  void
673
+	 */
674
+	public function register_caf_message_types()
675
+	{
676
+		// register newsletter message type
677
+		$setup_args = array(
678
+			'mtfilename'                                       => 'EE_Newsletter_message_type.class.php',
679
+			'autoloadpaths'                                    => array(
680
+				EE_CAF_LIBRARIES . 'messages/message_type/newsletter/',
681
+			),
682
+			'messengers_to_activate_with'                      => array('email'),
683
+			'messengers_to_validate_with'                      => array('email'),
684
+			'messengers_supporting_default_template_pack_with' => array('email'),
685
+		);
686
+		EE_Register_Message_Type::register('newsletter', $setup_args);
687
+
688
+		// register payment reminder message type
689
+		$setup_args = array(
690
+			'mtfilename'                                       => 'EE_Payment_Reminder_message_type.class.php',
691
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'),
692
+			'messengers_to_activate_with'                      => array('email'),
693
+			'messengers_to_validate_with'                      => array('email'),
694
+			'messengers_supporting_default_template_pack_with' => array('email'),
695
+		);
696
+		EE_Register_Message_Type::register('payment_reminder', $setup_args);
697
+
698
+		// register payment declined message type
699
+		$setup_args = array(
700
+			'mtfilename'                                       => 'EE_Payment_Declined_message_type.class.php',
701
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'),
702
+			'messengers_to_activate_with'                      => array('email'),
703
+			'messengers_to_validate_with'                      => array('email'),
704
+			'messengers_supporting_default_template_pack_with' => array('email'),
705
+		);
706
+		EE_Register_Message_Type::register('payment_declined', $setup_args);
707
+
708
+		// register registration declined message type
709
+		$setup_args = array(
710
+			'mtfilename'                                       => 'EE_Declined_Registration_message_type.class.php',
711
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'),
712
+			'messengers_to_activate_with'                      => array('email'),
713
+			'messengers_to_validate_with'                      => array('email'),
714
+			'messengers_supporting_default_template_pack_with' => array('email'),
715
+		);
716
+		EE_Register_Message_Type::register('declined_registration', $setup_args);
717
+
718
+		// register registration cancelled message type
719
+		$setup_args = array(
720
+			'mtfilename'                                       => 'EE_Cancelled_Registration_message_type.class.php',
721
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'),
722
+			'messengers_to_activate_with'                      => array('email'),
723
+			'messengers_to_validate_with'                      => array('email'),
724
+			'messengers_supporting_default_template_pack_with' => array('email'),
725
+		);
726
+		EE_Register_Message_Type::register('cancelled_registration', $setup_args);
727
+
728
+
729
+		// register payment failed message type
730
+		$setup_args = array(
731
+			'mtfilename'                                       => 'EE_Payment_Failed_message_type.class.php',
732
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'),
733
+			'messengers_to_activate_with'                      => array('email'),
734
+			'messengers_to_validate_with'                      => array('email'),
735
+			'messengers_supporting_default_template_pack_with' => array('email'),
736
+		);
737
+		EE_Register_Message_Type::register('payment_failed', $setup_args);
738
+
739
+		// register payment declined message type
740
+		$setup_args = array(
741
+			'mtfilename'                                       => 'EE_Payment_Cancelled_message_type.class.php',
742
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'),
743
+			'messengers_to_activate_with'                      => array('email'),
744
+			'messengers_to_validate_with'                      => array('email'),
745
+			'messengers_supporting_default_template_pack_with' => array('email'),
746
+		);
747
+		EE_Register_Message_Type::register('payment_cancelled', $setup_args);
748
+	}
749
+
750
+
751
+	/**
752
+	 * Takes care of registering the  shortcode libraries implemented with caffeinated EE and set up related items.
753
+	 *
754
+	 * @since   4.3.2
755
+	 *
756
+	 * @return void
757
+	 */
758
+	public function register_caf_shortcodes()
759
+	{
760
+		$setup_args = array(
761
+			'autoloadpaths'                 => array(
762
+				EE_CAF_LIBRARIES . 'shortcodes/',
763
+			),
764
+			'msgr_validator_callback'       => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'),
765
+			'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'),
766
+			'list_type_shortcodes'          => array('[NEWSLETTER_CONTENT]'),
767
+		);
768
+		EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args);
769
+	}
770
+
771
+
772
+	/**
773
+	 * Parses a question list shortcode using given data and template
774
+	 *
775
+	 * @param \EE_Shortcodes $shortcode_parser
776
+	 * @param EE_Question[]  $questions        An array of questions indexed by answer id.
777
+	 * @param EE_Answer[]    $answers          An array of answer objects
778
+	 * @param string         $template         Template content to be parsed.
779
+	 * @param array          $valid_shortcodes Valid shortcodes for the template being parsed.
780
+	 * @param array          $extra_data       Extra data that might be used when parsing the template.
781
+	 */
782
+	protected function _parse_question_list_for_primary_or_recipient_registration(
783
+		$shortcode_parser,
784
+		$questions,
785
+		$answers,
786
+		$template,
787
+		$valid_shortcodes,
788
+		$extra_data
789
+	) {
790
+		$question_list = '';
791
+		/** @var EEH_Parse_Shortcodes $shortcode_helper */
792
+		$shortcode_helper = $shortcode_parser->get_shortcode_helper();
793
+		foreach ($answers as $answer) {
794
+			if ($answer instanceof EE_Answer) {
795
+				// first see if the question is in our $questions array. If not then try to get from answer object.
796
+				$question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null;
797
+				$question = ! $question instanceof EE_Question ? $answer->question() : $question;
798
+				if (
799
+					! $question instanceof EE_Question
800
+					|| (
801
+						$question instanceof EE_Question
802
+						&& $question->admin_only()
803
+					)
804
+				) {
805
+					continue;
806
+				}
807
+				$question_list .= $shortcode_helper->parse_question_list_template(
808
+					$template,
809
+					$answer,
810
+					$valid_shortcodes,
811
+					$extra_data
812
+				);
813
+			}
814
+		}
815
+		return $question_list;
816
+	}
817 817
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      */
130 130
     public function messages_autoload_paths($dir_ref)
131 131
     {
132
-        $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/';
132
+        $dir_ref[] = EE_CAF_LIBRARIES.'shortcodes/';
133 133
 
134 134
         return $dir_ref;
135 135
     }
@@ -245,32 +245,32 @@  discard block
 block discarded – undo
245 245
     ) {
246 246
 
247 247
         // we're only modifying templates for the default template pack
248
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
248
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) {
249 249
             return $contents;
250 250
         }
251 251
 
252 252
         // the template file name we're replacing contents for.
253
-        $template_file_prefix = $field . '_' . $context;
254
-        $msg_prefix = $messenger->name . '_' . $message_type->name . '_';
253
+        $template_file_prefix = $field.'_'.$context;
254
+        $msg_prefix = $messenger->name.'_'.$message_type->name.'_';
255 255
 
256
-        $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/';
256
+        $base_path = EE_CAF_LIBRARIES.'messages/defaults/default/';
257 257
 
258 258
         if ($messenger->name == 'email' && $message_type->name == 'registration') {
259 259
             switch ($template_file_prefix) {
260 260
                 case 'question_list_admin':
261 261
                 case 'question_list_attendee':
262 262
                 case 'question_list_primary_attendee':
263
-                    $path = $base_path . $msg_prefix . 'question_list.template.php';
263
+                    $path = $base_path.$msg_prefix.'question_list.template.php';
264 264
                     $contents = EEH_Template::display_template($path, array(), true);
265 265
                     break;
266 266
 
267 267
                 case 'attendee_list_primary_attendee':
268
-                    $path = $base_path . $msg_prefix . 'attendee_list.template.php';
268
+                    $path = $base_path.$msg_prefix.'attendee_list.template.php';
269 269
                     $contents = EEH_Template::display_template($path, array(), true);
270 270
                     break;
271 271
 
272 272
                 case 'attendee_list_admin':
273
-                    $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php';
273
+                    $path = $base_path.$msg_prefix.'attendee_list_admin.template.php';
274 274
                     $contents = EEH_Template::display_template(
275 275
                         $path,
276 276
                         array(),
@@ -283,31 +283,31 @@  discard block
 block discarded – undo
283 283
                     break;
284 284
 
285 285
                 case 'event_list_attendee':
286
-                    $path = $base_path . $msg_prefix . 'event_list_attendee.template.php';
286
+                    $path = $base_path.$msg_prefix.'event_list_attendee.template.php';
287 287
                     $contents = EEH_Template::display_template($path, array(), true);
288 288
                     break;
289 289
             }
290 290
         } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') {
291 291
             switch ($template_file_prefix) {
292 292
                 case 'content_attendee':
293
-                    $path = $base_path . $msg_prefix . 'content.template.php';
293
+                    $path = $base_path.$msg_prefix.'content.template.php';
294 294
                     $contents = EEH_Template::display_template($path, array(), true);
295 295
                     break;
296 296
 
297 297
                 case 'newsletter_content_attendee':
298
-                    $path = $base_path . $msg_prefix . 'newsletter_content.template.php';
298
+                    $path = $base_path.$msg_prefix.'newsletter_content.template.php';
299 299
                     $contents = EEH_Template::display_template($path, array(), true);
300 300
                     break;
301 301
 
302 302
                 case 'newsletter_subject_attendee':
303
-                    $path = $base_path . $msg_prefix . 'subject.template.php';
303
+                    $path = $base_path.$msg_prefix.'subject.template.php';
304 304
                     $contents = EEH_Template::display_template($path, array(), true);
305 305
                     break;
306 306
             }
307 307
         } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') {
308 308
             switch ($template_file_prefix) {
309 309
                 case 'attendee_list_purchaser':
310
-                    $path = $base_path . $msg_prefix . 'attendee_list.template.php';
310
+                    $path = $base_path.$msg_prefix.'attendee_list.template.php';
311 311
                     $contents = EEH_Template::display_template($path, array(), true);
312 312
                     break;
313 313
             }
@@ -338,8 +338,8 @@  discard block
 block discarded – undo
338 338
         if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) {
339 339
             $contexts = array_keys($msg->get_contexts());
340 340
             foreach ($contexts as $context) {
341
-                $valid_shortcodes[ $context ][] = 'question_list';
342
-                $valid_shortcodes[ $context ][] = 'question';
341
+                $valid_shortcodes[$context][] = 'question_list';
342
+                $valid_shortcodes[$context][] = 'question';
343 343
             }
344 344
         }
345 345
 
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
             $extra_data
384 384
         ) && isset($extra_data['data']) ? $extra_data['data'] : $aee;
385 385
 
386
-        if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) {
386
+        if ( ! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) {
387 387
             return $parsed;
388 388
         }
389 389
 
@@ -392,9 +392,9 @@  discard block
 block discarded – undo
392 392
             if (
393 393
                 $question instanceof EE_Question
394 394
                 && trim($question->display_text()) == trim($shortcode)
395
-                && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ])
395
+                && isset($aee->registrations[$registration->ID()]['ans_objs'][$ansid])
396 396
             ) {
397
-                return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty(
397
+                return $aee->registrations[$registration->ID()]['ans_objs'][$ansid]->get_pretty(
398 398
                     'ANS_value',
399 399
                     'no_wpautop'
400 400
                 );
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
     public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
456 456
     {
457 457
 
458
-        if (! $data instanceof EE_Datetime) {
458
+        if ( ! $data instanceof EE_Datetime) {
459 459
             return ''; // get out because we can only parse with the datetime object.
460 460
         }
461 461
 
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
         $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
509 509
         $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
510 510
 
511
-        if (! $recipient instanceof EE_Messages_Addressee) {
511
+        if ( ! $recipient instanceof EE_Messages_Addressee) {
512 512
             return $parsed;
513 513
         }
514 514
 
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
             case '[RECIPIENT_QUESTION_LIST]':
517 517
                 $att = $recipient->att_obj;
518 518
                 $registrations_on_attendee = $att instanceof EE_Attendee
519
-                    ? $recipient->attendees[ $att->ID() ]['reg_objs']
519
+                    ? $recipient->attendees[$att->ID()]['reg_objs']
520 520
                     : array();
521 521
                 $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee;
522 522
                 $answers = array();
@@ -530,12 +530,12 @@  discard block
 block discarded – undo
530 530
                 if ($data['data'] instanceof EE_Messages_Addressee) {
531 531
                     foreach ($registrations_on_attendee as $reg) {
532 532
                         if ($reg instanceof EE_Registration) {
533
-                            $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
534
-                                ? $recipient->registrations[ $reg->ID() ]['ans_objs']
533
+                            $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs'])
534
+                                ? $recipient->registrations[$reg->ID()]['ans_objs']
535 535
                                 : array();
536 536
                             foreach ($anss as $ans) {
537 537
                                 if ($ans instanceof EE_Answer) {
538
-                                    $answers[ $ans->ID() ] = $ans;
538
+                                    $answers[$ans->ID()] = $ans;
539 539
                                 }
540 540
                             }
541 541
                         }
@@ -547,12 +547,12 @@  discard block
 block discarded – undo
547 547
                     $event = $data['data'];
548 548
                     foreach ($registrations_on_attendee as $reg) {
549 549
                         if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
550
-                            $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
551
-                                ? $recipient->registrations[ $reg->ID() ]['ans_objs']
550
+                            $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs'])
551
+                                ? $recipient->registrations[$reg->ID()]['ans_objs']
552 552
                                 : array();
553 553
                             foreach ($anss as $ans) {
554 554
                                 if ($ans instanceof EE_Answer) {
555
-                                    $answers[ $ans->ID() ] = $ans;
555
+                                    $answers[$ans->ID()] = $ans;
556 556
                                 }
557 557
                             }
558 558
                         }
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 
564 564
                 // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
565 565
                 // object on it.
566
-                if (! isset($extra_data['data'])) {
566
+                if ( ! isset($extra_data['data'])) {
567 567
                     $extra_data['data'] = $recipient;
568 568
                 }
569 569
 
@@ -620,18 +620,18 @@  discard block
 block discarded – undo
620 620
         $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
621 621
         $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
622 622
 
623
-        if (! $recipient instanceof EE_Messages_Addressee) {
623
+        if ( ! $recipient instanceof EE_Messages_Addressee) {
624 624
             return $parsed;
625 625
         }
626 626
 
627 627
         switch ($shortcode) {
628 628
             case '[PRIMARY_REGISTRANT_QUESTION_LIST]':
629
-                if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) {
629
+                if ( ! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) {
630 630
                     return '';
631 631
                 }
632 632
                 $registration = $recipient->primary_reg_obj;
633
-                $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs'])
634
-                    ? $recipient->registrations[ $registration->ID() ]['ans_objs']
633
+                $answers = isset($recipient->registrations[$registration->ID()]['ans_objs'])
634
+                    ? $recipient->registrations[$registration->ID()]['ans_objs']
635 635
                     : array();
636 636
                 if (empty($answers)) {
637 637
                     return '';
@@ -640,11 +640,11 @@  discard block
 block discarded – undo
640 640
                     ? $data['template']['question_list']
641 641
                     : $extra_data['template']['question_list'];
642 642
                 $valid_shortcodes = array('question');
643
-                $answers = $recipient->registrations[ $registration->ID() ]['ans_objs'];
643
+                $answers = $recipient->registrations[$registration->ID()]['ans_objs'];
644 644
                 $questions = isset($recipient->questions) ? $recipient->questions : array();
645 645
                 // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
646 646
                 // object on it.
647
-                if (! isset($extra_data['data'])) {
647
+                if ( ! isset($extra_data['data'])) {
648 648
                     $extra_data['data'] = $recipient;
649 649
                 }
650 650
                 return $this->_parse_question_list_for_primary_or_recipient_registration(
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
         $setup_args = array(
678 678
             'mtfilename'                                       => 'EE_Newsletter_message_type.class.php',
679 679
             'autoloadpaths'                                    => array(
680
-                EE_CAF_LIBRARIES . 'messages/message_type/newsletter/',
680
+                EE_CAF_LIBRARIES.'messages/message_type/newsletter/',
681 681
             ),
682 682
             'messengers_to_activate_with'                      => array('email'),
683 683
             'messengers_to_validate_with'                      => array('email'),
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
         // register payment reminder message type
689 689
         $setup_args = array(
690 690
             'mtfilename'                                       => 'EE_Payment_Reminder_message_type.class.php',
691
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'),
691
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/payment_reminder/'),
692 692
             'messengers_to_activate_with'                      => array('email'),
693 693
             'messengers_to_validate_with'                      => array('email'),
694 694
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
         // register payment declined message type
699 699
         $setup_args = array(
700 700
             'mtfilename'                                       => 'EE_Payment_Declined_message_type.class.php',
701
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'),
701
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/payment_declined/'),
702 702
             'messengers_to_activate_with'                      => array('email'),
703 703
             'messengers_to_validate_with'                      => array('email'),
704 704
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
         // register registration declined message type
709 709
         $setup_args = array(
710 710
             'mtfilename'                                       => 'EE_Declined_Registration_message_type.class.php',
711
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'),
711
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/declined_registration/'),
712 712
             'messengers_to_activate_with'                      => array('email'),
713 713
             'messengers_to_validate_with'                      => array('email'),
714 714
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
         // register registration cancelled message type
719 719
         $setup_args = array(
720 720
             'mtfilename'                                       => 'EE_Cancelled_Registration_message_type.class.php',
721
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'),
721
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/cancelled_registration/'),
722 722
             'messengers_to_activate_with'                      => array('email'),
723 723
             'messengers_to_validate_with'                      => array('email'),
724 724
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
         // register payment failed message type
730 730
         $setup_args = array(
731 731
             'mtfilename'                                       => 'EE_Payment_Failed_message_type.class.php',
732
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'),
732
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/payment_failed/'),
733 733
             'messengers_to_activate_with'                      => array('email'),
734 734
             'messengers_to_validate_with'                      => array('email'),
735 735
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
         // register payment declined message type
740 740
         $setup_args = array(
741 741
             'mtfilename'                                       => 'EE_Payment_Cancelled_message_type.class.php',
742
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'),
742
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/payment_cancelled/'),
743 743
             'messengers_to_activate_with'                      => array('email'),
744 744
             'messengers_to_validate_with'                      => array('email'),
745 745
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
     {
760 760
         $setup_args = array(
761 761
             'autoloadpaths'                 => array(
762
-                EE_CAF_LIBRARIES . 'shortcodes/',
762
+                EE_CAF_LIBRARIES.'shortcodes/',
763 763
             ),
764 764
             'msgr_validator_callback'       => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'),
765 765
             'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'),
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
         foreach ($answers as $answer) {
794 794
             if ($answer instanceof EE_Answer) {
795 795
                 // first see if the question is in our $questions array. If not then try to get from answer object.
796
-                $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null;
796
+                $question = isset($questions[$answer->ID()]) ? $questions[$answer->ID()] : null;
797 797
                 $question = ! $question instanceof EE_Question ? $answer->question() : $question;
798 798
                 if (
799 799
                     ! $question instanceof EE_Question
Please login to merge, or discard this patch.
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
      * _get_transaction_and_cart_for_previous_visit
782 782
      *
783 783
      * @access private
784
-     * @return mixed EE_Transaction|NULL
784
+     * @return EE_Transaction|null EE_Transaction|NULL
785 785
      */
786 786
     private function _get_transaction_and_cart_for_previous_visit()
787 787
     {
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
      *    generates a new EE_Transaction object and adds it to the $_transaction property.
864 864
      *
865 865
      * @access private
866
-     * @return mixed EE_Transaction|NULL
866
+     * @return EE_Transaction|null EE_Transaction|NULL
867 867
      */
868 868
     private function _initialize_transaction()
869 869
     {
Please login to merge, or discard this patch.
Indentation   +1811 added lines, -1811 removed lines patch added patch discarded remove patch
@@ -15,1815 +15,1815 @@
 block discarded – undo
15 15
 class EED_Single_Page_Checkout extends EED_Module
16 16
 {
17 17
 
18
-    /**
19
-     * $_initialized - has the SPCO controller already been initialized ?
20
-     *
21
-     * @access private
22
-     * @var bool $_initialized
23
-     */
24
-    private static $_initialized = false;
25
-
26
-
27
-    /**
28
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
29
-     *
30
-     * @access private
31
-     * @var bool $_valid_checkout
32
-     */
33
-    private static $_checkout_verified = true;
34
-
35
-    /**
36
-     *    $_reg_steps_array - holds initial array of reg steps
37
-     *
38
-     * @access private
39
-     * @var array $_reg_steps_array
40
-     */
41
-    private static $_reg_steps_array = array();
42
-
43
-    /**
44
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
45
-     *
46
-     * @access public
47
-     * @var EE_Checkout $checkout
48
-     */
49
-    public $checkout;
50
-
51
-
52
-    /**
53
-     * @return EED_Module|EED_Single_Page_Checkout
54
-     */
55
-    public static function instance()
56
-    {
57
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
58
-        return parent::get_instance(__CLASS__);
59
-    }
60
-
61
-
62
-    /**
63
-     * @return EE_CART
64
-     */
65
-    public function cart()
66
-    {
67
-        return $this->checkout->cart;
68
-    }
69
-
70
-
71
-    /**
72
-     * @return EE_Transaction
73
-     */
74
-    public function transaction()
75
-    {
76
-        return $this->checkout->transaction;
77
-    }
78
-
79
-
80
-    /**
81
-     *    set_hooks - for hooking into EE Core, other modules, etc
82
-     *
83
-     * @access    public
84
-     * @return    void
85
-     * @throws EE_Error
86
-     */
87
-    public static function set_hooks()
88
-    {
89
-        EED_Single_Page_Checkout::set_definitions();
90
-    }
91
-
92
-
93
-    /**
94
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
95
-     *
96
-     * @access    public
97
-     * @return    void
98
-     * @throws EE_Error
99
-     */
100
-    public static function set_hooks_admin()
101
-    {
102
-        EED_Single_Page_Checkout::set_definitions();
103
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
104
-            return;
105
-        }
106
-        // going to start an output buffer in case anything gets accidentally output
107
-        // that might disrupt our JSON response
108
-        ob_start();
109
-        EED_Single_Page_Checkout::load_request_handler();
110
-        EED_Single_Page_Checkout::load_reg_steps();
111
-        // set ajax hooks
112
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
113
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
114
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
115
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
116
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
117
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
118
-    }
119
-
120
-
121
-    /**
122
-     *    process ajax request
123
-     *
124
-     * @param string $ajax_action
125
-     * @throws EE_Error
126
-     */
127
-    public static function process_ajax_request($ajax_action)
128
-    {
129
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
130
-        EED_Single_Page_Checkout::instance()->_initialize();
131
-    }
132
-
133
-
134
-    /**
135
-     *    ajax display registration step
136
-     *
137
-     * @throws EE_Error
138
-     */
139
-    public static function display_reg_step()
140
-    {
141
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
142
-    }
143
-
144
-
145
-    /**
146
-     *    ajax process registration step
147
-     *
148
-     * @throws EE_Error
149
-     */
150
-    public static function process_reg_step()
151
-    {
152
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
153
-    }
154
-
155
-
156
-    /**
157
-     *    ajax process registration step
158
-     *
159
-     * @throws EE_Error
160
-     */
161
-    public static function update_reg_step()
162
-    {
163
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
164
-    }
165
-
166
-
167
-    /**
168
-     *   update_checkout
169
-     *
170
-     * @access public
171
-     * @return void
172
-     * @throws EE_Error
173
-     */
174
-    public static function update_checkout()
175
-    {
176
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
177
-    }
178
-
179
-
180
-    /**
181
-     *    load_request_handler
182
-     *
183
-     * @access    public
184
-     * @return    void
185
-     */
186
-    public static function load_request_handler()
187
-    {
188
-        // load core Request_Handler class
189
-        if (EE_Registry::instance()->REQ !== null) {
190
-            EE_Registry::instance()->load_core('Request_Handler');
191
-        }
192
-    }
193
-
194
-
195
-    /**
196
-     *    set_definitions
197
-     *
198
-     * @access    public
199
-     * @return    void
200
-     * @throws EE_Error
201
-     */
202
-    public static function set_definitions()
203
-    {
204
-        if (defined('SPCO_BASE_PATH')) {
205
-            return;
206
-        }
207
-        define(
208
-            'SPCO_BASE_PATH',
209
-            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
210
-        );
211
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css/');
212
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img/');
213
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js/');
214
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc/');
215
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps/');
216
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates/');
217
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
218
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
219
-        );
220
-    }
221
-
222
-
223
-    /**
224
-     * load_reg_steps
225
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
226
-     *
227
-     * @access    private
228
-     * @throws EE_Error
229
-     */
230
-    public static function load_reg_steps()
231
-    {
232
-        static $reg_steps_loaded = false;
233
-        if ($reg_steps_loaded) {
234
-            return;
235
-        }
236
-        // filter list of reg_steps
237
-        $reg_steps_to_load = (array) apply_filters(
238
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
239
-            EED_Single_Page_Checkout::get_reg_steps()
240
-        );
241
-        // sort by key (order)
242
-        ksort($reg_steps_to_load);
243
-        // loop through folders
244
-        foreach ($reg_steps_to_load as $order => $reg_step) {
245
-            // we need a
246
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
247
-                // copy over to the reg_steps_array
248
-                EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
249
-                // register custom key route for each reg step
250
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
251
-                EE_Config::register_route(
252
-                    $reg_step['slug'],
253
-                    'EED_Single_Page_Checkout',
254
-                    'run',
255
-                    'step'
256
-                );
257
-                // add AJAX or other hooks
258
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
259
-                    // setup autoloaders if necessary
260
-                    if (! class_exists($reg_step['class_name'])) {
261
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
262
-                            $reg_step['file_path'],
263
-                            true
264
-                        );
265
-                    }
266
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
267
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
268
-                    }
269
-                }
270
-            }
271
-        }
272
-        $reg_steps_loaded = true;
273
-    }
274
-
275
-
276
-    /**
277
-     *    get_reg_steps
278
-     *
279
-     * @access    public
280
-     * @return    array
281
-     */
282
-    public static function get_reg_steps()
283
-    {
284
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
285
-        if (empty($reg_steps)) {
286
-            $reg_steps = array(
287
-                10  => array(
288
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
289
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
290
-                    'slug'       => 'attendee_information',
291
-                    'has_hooks'  => false,
292
-                ),
293
-                30  => array(
294
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
295
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
296
-                    'slug'       => 'payment_options',
297
-                    'has_hooks'  => true,
298
-                ),
299
-                999 => array(
300
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
301
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
302
-                    'slug'       => 'finalize_registration',
303
-                    'has_hooks'  => false,
304
-                ),
305
-            );
306
-        }
307
-        return $reg_steps;
308
-    }
309
-
310
-
311
-    /**
312
-     *    registration_checkout_for_admin
313
-     *
314
-     * @access    public
315
-     * @return    string
316
-     * @throws EE_Error
317
-     */
318
-    public static function registration_checkout_for_admin()
319
-    {
320
-        EED_Single_Page_Checkout::load_request_handler();
321
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
322
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
323
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
324
-        EED_Single_Page_Checkout::instance()->_initialize();
325
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
326
-        return EE_Registry::instance()->REQ->get_output();
327
-    }
328
-
329
-
330
-    /**
331
-     * process_registration_from_admin
332
-     *
333
-     * @access public
334
-     * @return \EE_Transaction
335
-     * @throws EE_Error
336
-     */
337
-    public static function process_registration_from_admin()
338
-    {
339
-        EED_Single_Page_Checkout::load_request_handler();
340
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
341
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
342
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
343
-        EED_Single_Page_Checkout::instance()->_initialize();
344
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
345
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
346
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
347
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
348
-                if ($final_reg_step->process_reg_step()) {
349
-                    $final_reg_step->set_completed();
350
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
351
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
352
-                }
353
-            }
354
-        }
355
-        return null;
356
-    }
357
-
358
-
359
-    /**
360
-     *    run
361
-     *
362
-     * @access    public
363
-     * @param WP_Query $WP_Query
364
-     * @return    void
365
-     * @throws EE_Error
366
-     */
367
-    public function run($WP_Query)
368
-    {
369
-        if (
370
-            $WP_Query instanceof WP_Query
371
-            && $WP_Query->is_main_query()
372
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
373
-            && $this->_is_reg_checkout()
374
-        ) {
375
-            $this->_initialize();
376
-        }
377
-    }
378
-
379
-
380
-    /**
381
-     * determines whether current url matches reg page url
382
-     *
383
-     * @return bool
384
-     */
385
-    protected function _is_reg_checkout()
386
-    {
387
-        // get current permalink for reg page without any extra query args
388
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
389
-        // get request URI for current request, but without the scheme or host
390
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
391
-        $current_request_uri = html_entity_decode($current_request_uri);
392
-        // get array of query args from the current request URI
393
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
394
-        // grab page id if it is set
395
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
396
-        // and remove the page id from the query args (we will re-add it later)
397
-        unset($query_args['page_id']);
398
-        // now strip all query args from current request URI
399
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
400
-        // and re-add the page id if it was set
401
-        if ($page_id) {
402
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
403
-        }
404
-        // remove slashes and ?
405
-        $current_request_uri = trim($current_request_uri, '?/');
406
-        // is current request URI part of the known full reg page URL ?
407
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
408
-    }
409
-
410
-
411
-    /**
412
-     * @param WP_Query $wp_query
413
-     * @return    void
414
-     * @throws EE_Error
415
-     */
416
-    public static function init($wp_query)
417
-    {
418
-        EED_Single_Page_Checkout::instance()->run($wp_query);
419
-    }
420
-
421
-
422
-    /**
423
-     *    _initialize - initial module setup
424
-     *
425
-     * @access    private
426
-     * @throws EE_Error
427
-     * @return    void
428
-     */
429
-    private function _initialize()
430
-    {
431
-        // ensure SPCO doesn't run twice
432
-        if (EED_Single_Page_Checkout::$_initialized) {
433
-            return;
434
-        }
435
-        try {
436
-            EED_Single_Page_Checkout::load_reg_steps();
437
-            $this->_verify_session();
438
-            // setup the EE_Checkout object
439
-            $this->checkout = $this->_initialize_checkout();
440
-            // filter checkout
441
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
442
-            // get the $_GET
443
-            $this->_get_request_vars();
444
-            if ($this->_block_bots()) {
445
-                return;
446
-            }
447
-            // filter continue_reg
448
-            $this->checkout->continue_reg = apply_filters(
449
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
450
-                true,
451
-                $this->checkout
452
-            );
453
-            // load the reg steps array
454
-            if (! $this->_load_and_instantiate_reg_steps()) {
455
-                EED_Single_Page_Checkout::$_initialized = true;
456
-                return;
457
-            }
458
-            // set the current step
459
-            $this->checkout->set_current_step($this->checkout->step);
460
-            // and the next step
461
-            $this->checkout->set_next_step();
462
-            // verify that everything has been setup correctly
463
-            if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
464
-                EED_Single_Page_Checkout::$_initialized = true;
465
-                return;
466
-            }
467
-            // lock the transaction
468
-            $this->checkout->transaction->lock();
469
-            // make sure all of our cached objects are added to their respective model entity mappers
470
-            $this->checkout->refresh_all_entities();
471
-            // set amount owing
472
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
473
-            // initialize each reg step, which gives them the chance to potentially alter the process
474
-            $this->_initialize_reg_steps();
475
-            // DEBUG LOG
476
-            // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
477
-            // get reg form
478
-            if (! $this->_check_form_submission()) {
479
-                EED_Single_Page_Checkout::$_initialized = true;
480
-                return;
481
-            }
482
-            // checkout the action!!!
483
-            $this->_process_form_action();
484
-            // add some style and make it dance
485
-            $this->add_styles_and_scripts($this);
486
-            // kk... SPCO has successfully run
487
-            EED_Single_Page_Checkout::$_initialized = true;
488
-            // set no cache headers and constants
489
-            EE_System::do_not_cache();
490
-            // add anchor
491
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
492
-            // remove transaction lock
493
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
494
-        } catch (Exception $e) {
495
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
496
-        }
497
-    }
498
-
499
-
500
-    /**
501
-     *    _verify_session
502
-     * checks that the session is valid and not expired
503
-     *
504
-     * @access    private
505
-     * @throws EE_Error
506
-     */
507
-    private function _verify_session()
508
-    {
509
-        if (! EE_Registry::instance()->SSN instanceof EE_Session) {
510
-            throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso'));
511
-        }
512
-        $clear_session_requested = filter_var(
513
-            EE_Registry::instance()->REQ->get('clear_session', false),
514
-            FILTER_VALIDATE_BOOLEAN
515
-        );
516
-        // is session still valid ?
517
-        if (
518
-            $clear_session_requested
519
-            || (EE_Registry::instance()->SSN->expired()
520
-                && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
521
-            )
522
-        ) {
523
-            $this->checkout = new EE_Checkout();
524
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
525
-            // EE_Registry::instance()->SSN->reset_cart();
526
-            // EE_Registry::instance()->SSN->reset_checkout();
527
-            // EE_Registry::instance()->SSN->reset_transaction();
528
-            if (! $clear_session_requested) {
529
-                EE_Error::add_attention(
530
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
531
-                    __FILE__,
532
-                    __FUNCTION__,
533
-                    __LINE__
534
-                );
535
-            }
536
-            // EE_Registry::instance()->SSN->reset_expired();
537
-        }
538
-    }
539
-
540
-
541
-    /**
542
-     *    _initialize_checkout
543
-     * loads and instantiates EE_Checkout
544
-     *
545
-     * @access    private
546
-     * @throws EE_Error
547
-     * @return EE_Checkout
548
-     */
549
-    private function _initialize_checkout()
550
-    {
551
-        // look in session for existing checkout
552
-        /** @type EE_Checkout $checkout */
553
-        $checkout = EE_Registry::instance()->SSN->checkout();
554
-        // verify
555
-        if (! $checkout instanceof EE_Checkout) {
556
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
557
-            $checkout = EE_Registry::instance()->load_file(
558
-                SPCO_INC_PATH,
559
-                'EE_Checkout',
560
-                'class',
561
-                array(),
562
-                false
563
-            );
564
-        } else {
565
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
566
-                $this->unlock_transaction();
567
-                wp_safe_redirect($checkout->redirect_url);
568
-                exit();
569
-            }
570
-        }
571
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
572
-        // verify again
573
-        if (! $checkout instanceof EE_Checkout) {
574
-            throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso'));
575
-        }
576
-        // reset anything that needs a clean slate for each request
577
-        $checkout->reset_for_current_request();
578
-        return $checkout;
579
-    }
580
-
581
-
582
-    /**
583
-     *    _get_request_vars
584
-     *
585
-     * @access    private
586
-     * @return    void
587
-     * @throws EE_Error
588
-     */
589
-    private function _get_request_vars()
590
-    {
591
-        // load classes
592
-        EED_Single_Page_Checkout::load_request_handler();
593
-        // make sure this request is marked as belonging to EE
594
-        EE_Registry::instance()->REQ->set_espresso_page(true);
595
-        // which step is being requested ?
596
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
597
-        // which step is being edited ?
598
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
599
-        // and what we're doing on the current step
600
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
601
-        // timestamp
602
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
603
-        // returning to edit ?
604
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
605
-        // add reg url link to registration query params
606
-        if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
607
-            $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
608
-        }
609
-        // or some other kind of revisit ?
610
-        $this->checkout->revisit = filter_var(
611
-            EE_Registry::instance()->REQ->get('revisit', false),
612
-            FILTER_VALIDATE_BOOLEAN
613
-        );
614
-        // and whether or not to generate a reg form for this request
615
-        $this->checkout->generate_reg_form = filter_var(
616
-            EE_Registry::instance()->REQ->get('generate_reg_form', true),
617
-            FILTER_VALIDATE_BOOLEAN
618
-        );
619
-        // and whether or not to process a reg form submission for this request
620
-        $this->checkout->process_form_submission = filter_var(
621
-            EE_Registry::instance()->REQ->get(
622
-                'process_form_submission',
623
-                $this->checkout->action === 'process_reg_step'
624
-            ),
625
-            FILTER_VALIDATE_BOOLEAN
626
-        );
627
-        $this->checkout->process_form_submission = filter_var(
628
-            $this->checkout->action !== 'display_spco_reg_step'
629
-                ? $this->checkout->process_form_submission
630
-                : false,
631
-            FILTER_VALIDATE_BOOLEAN
632
-        );
633
-        // $this->_display_request_vars();
634
-    }
635
-
636
-
637
-    /**
638
-     *  _display_request_vars
639
-     *
640
-     * @access    protected
641
-     * @return    void
642
-     */
643
-    protected function _display_request_vars()
644
-    {
645
-        if (! WP_DEBUG) {
646
-            return;
647
-        }
648
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
649
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
650
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
651
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
652
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
653
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
654
-        EEH_Debug_Tools::printr(
655
-            $this->checkout->generate_reg_form,
656
-            '$this->checkout->generate_reg_form',
657
-            __FILE__,
658
-            __LINE__
659
-        );
660
-        EEH_Debug_Tools::printr(
661
-            $this->checkout->process_form_submission,
662
-            '$this->checkout->process_form_submission',
663
-            __FILE__,
664
-            __LINE__
665
-        );
666
-    }
667
-
668
-
669
-    /**
670
-     * _block_bots
671
-     * checks that the incoming request has either of the following set:
672
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
673
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
674
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
675
-     * then where you coming from man?
676
-     *
677
-     * @return boolean
678
-     */
679
-    private function _block_bots()
680
-    {
681
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
682
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
683
-            return true;
684
-        }
685
-        return false;
686
-    }
687
-
688
-
689
-    /**
690
-     *    _get_first_step
691
-     *  gets slug for first step in $_reg_steps_array
692
-     *
693
-     * @access    private
694
-     * @throws EE_Error
695
-     * @return    string
696
-     */
697
-    private function _get_first_step()
698
-    {
699
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
700
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
701
-    }
702
-
703
-
704
-    /**
705
-     * instantiates each reg step based on the loaded reg_steps array
706
-     *
707
-     * @return    bool
708
-     * @throws EE_Error
709
-     * @throws InvalidArgumentException
710
-     * @throws InvalidDataTypeException
711
-     * @throws InvalidInterfaceException
712
-     */
713
-    private function _load_and_instantiate_reg_steps()
714
-    {
715
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
716
-        // have reg_steps already been instantiated ?
717
-        if (
718
-            empty($this->checkout->reg_steps)
719
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
720
-        ) {
721
-            // if not, then loop through raw reg steps array
722
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
723
-                if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
724
-                    return false;
725
-                }
726
-            }
727
-            if (isset($this->checkout->reg_steps['registration_confirmation'])) {
728
-                // skip the registration_confirmation page ?
729
-                if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
730
-                    // just remove it from the reg steps array
731
-                    $this->checkout->remove_reg_step('registration_confirmation', false);
732
-                } elseif (
733
-                    EE_Registry::instance()->CFG->registration->reg_confirmation_last
734
-                ) {
735
-                    // set the order to something big like 100
736
-                    $this->checkout->set_reg_step_order('registration_confirmation', 100);
737
-                }
738
-            }
739
-            // filter the array for good luck
740
-            $this->checkout->reg_steps = apply_filters(
741
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
742
-                $this->checkout->reg_steps
743
-            );
744
-            // finally re-sort based on the reg step class order properties
745
-            $this->checkout->sort_reg_steps();
746
-        } else {
747
-            foreach ($this->checkout->reg_steps as $reg_step) {
748
-                // set all current step stati to FALSE
749
-                $reg_step->set_is_current_step(false);
750
-            }
751
-        }
752
-        if (empty($this->checkout->reg_steps)) {
753
-            EE_Error::add_error(
754
-                esc_html__('No Reg Steps were loaded..', 'event_espresso'),
755
-                __FILE__,
756
-                __FUNCTION__,
757
-                __LINE__
758
-            );
759
-            return false;
760
-        }
761
-        // make reg step details available to JS
762
-        $this->checkout->set_reg_step_JSON_info();
763
-        return true;
764
-    }
765
-
766
-
767
-    /**
768
-     *     _load_and_instantiate_reg_step
769
-     *
770
-     * @access    private
771
-     * @param array $reg_step
772
-     * @param int   $order
773
-     * @return bool
774
-     */
775
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
776
-    {
777
-        // we need a file_path, class_name, and slug to add a reg step
778
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
779
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
780
-            if (
781
-                $this->checkout->reg_url_link
782
-                && $this->checkout->step !== $reg_step['slug']
783
-                && $reg_step['slug'] !== 'finalize_registration'
784
-                // normally at this point we would NOT load the reg step, but this filter can change that
785
-                && apply_filters(
786
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
787
-                    true,
788
-                    $reg_step,
789
-                    $this->checkout
790
-                )
791
-            ) {
792
-                return true;
793
-            }
794
-            // instantiate step class using file path and class name
795
-            $reg_step_obj = EE_Registry::instance()->load_file(
796
-                $reg_step['file_path'],
797
-                $reg_step['class_name'],
798
-                'class',
799
-                $this->checkout,
800
-                false
801
-            );
802
-            // did we gets the goods ?
803
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
804
-                // set reg step order based on config
805
-                $reg_step_obj->set_order($order);
806
-                // add instantiated reg step object to the master reg steps array
807
-                $this->checkout->add_reg_step($reg_step_obj);
808
-            } else {
809
-                EE_Error::add_error(
810
-                    esc_html__('The current step could not be set.', 'event_espresso'),
811
-                    __FILE__,
812
-                    __FUNCTION__,
813
-                    __LINE__
814
-                );
815
-                return false;
816
-            }
817
-        } else {
818
-            if (WP_DEBUG) {
819
-                EE_Error::add_error(
820
-                    sprintf(
821
-                        esc_html__(
822
-                            'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
823
-                            'event_espresso'
824
-                        ),
825
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
826
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
827
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
828
-                        '<ul>',
829
-                        '<li>',
830
-                        '</li>',
831
-                        '</ul>'
832
-                    ),
833
-                    __FILE__,
834
-                    __FUNCTION__,
835
-                    __LINE__
836
-                );
837
-            }
838
-            return false;
839
-        }
840
-        return true;
841
-    }
842
-
843
-
844
-    /**
845
-     * _verify_transaction_and_get_registrations
846
-     *
847
-     * @access private
848
-     * @return bool
849
-     * @throws InvalidDataTypeException
850
-     * @throws InvalidEntityException
851
-     * @throws EE_Error
852
-     */
853
-    private function _verify_transaction_and_get_registrations()
854
-    {
855
-        // was there already a valid transaction in the checkout from the session ?
856
-        if (! $this->checkout->transaction instanceof EE_Transaction) {
857
-            // get transaction from db or session
858
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
859
-                ? $this->_get_transaction_and_cart_for_previous_visit()
860
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
861
-            if (! $this->checkout->transaction instanceof EE_Transaction) {
862
-                EE_Error::add_error(
863
-                    esc_html__(
864
-                        'Your Registration and Transaction information could not be retrieved from the db.',
865
-                        'event_espresso'
866
-                    ),
867
-                    __FILE__,
868
-                    __FUNCTION__,
869
-                    __LINE__
870
-                );
871
-                $this->checkout->transaction = EE_Transaction::new_instance();
872
-                // add some style and make it dance
873
-                $this->add_styles_and_scripts($this);
874
-                EED_Single_Page_Checkout::$_initialized = true;
875
-                return false;
876
-            }
877
-            // and the registrations for the transaction
878
-            $this->_get_registrations($this->checkout->transaction);
879
-        }
880
-        return true;
881
-    }
882
-
883
-
884
-    /**
885
-     * _get_transaction_and_cart_for_previous_visit
886
-     *
887
-     * @access private
888
-     * @return mixed EE_Transaction|NULL
889
-     */
890
-    private function _get_transaction_and_cart_for_previous_visit()
891
-    {
892
-        /** @var $TXN_model EEM_Transaction */
893
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
894
-        // because the reg_url_link is present in the request,
895
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
896
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
897
-        // verify transaction
898
-        if ($transaction instanceof EE_Transaction) {
899
-            // and get the cart that was used for that transaction
900
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
901
-            return $transaction;
902
-        }
903
-        EE_Error::add_error(
904
-            esc_html__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
905
-            __FILE__,
906
-            __FUNCTION__,
907
-            __LINE__
908
-        );
909
-        return null;
910
-    }
911
-
912
-
913
-    /**
914
-     * _get_cart_for_transaction
915
-     *
916
-     * @access private
917
-     * @param EE_Transaction $transaction
918
-     * @return EE_Cart
919
-     */
920
-    private function _get_cart_for_transaction($transaction)
921
-    {
922
-        return $this->checkout->get_cart_for_transaction($transaction);
923
-    }
924
-
925
-
926
-    /**
927
-     * get_cart_for_transaction
928
-     *
929
-     * @access public
930
-     * @param EE_Transaction $transaction
931
-     * @return EE_Cart
932
-     */
933
-    public function get_cart_for_transaction(EE_Transaction $transaction)
934
-    {
935
-        return $this->checkout->get_cart_for_transaction($transaction);
936
-    }
937
-
938
-
939
-    /**
940
-     * _get_transaction_and_cart_for_current_session
941
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
942
-     *
943
-     * @access private
944
-     * @return EE_Transaction
945
-     * @throws EE_Error
946
-     */
947
-    private function _get_cart_for_current_session_and_setup_new_transaction()
948
-    {
949
-        //  if there's no transaction, then this is the FIRST visit to SPCO
950
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
951
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
952
-        // and then create a new transaction
953
-        $transaction = $this->_initialize_transaction();
954
-        // verify transaction
955
-        if ($transaction instanceof EE_Transaction) {
956
-            // save it so that we have an ID for other objects to use
957
-            $transaction->save();
958
-            // and save TXN data to the cart
959
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
960
-        } else {
961
-            EE_Error::add_error(
962
-                esc_html__('A Valid Transaction could not be initialized.', 'event_espresso'),
963
-                __FILE__,
964
-                __FUNCTION__,
965
-                __LINE__
966
-            );
967
-        }
968
-        return $transaction;
969
-    }
970
-
971
-
972
-    /**
973
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
974
-     *
975
-     * @access private
976
-     * @return mixed EE_Transaction|NULL
977
-     */
978
-    private function _initialize_transaction()
979
-    {
980
-        try {
981
-            // ensure cart totals have been calculated
982
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
983
-            // grab the cart grand total
984
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
985
-            // create new TXN
986
-            $transaction = EE_Transaction::new_instance(
987
-                array(
988
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
989
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
990
-                    'TXN_paid'      => 0,
991
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
992
-                )
993
-            );
994
-            // save it so that we have an ID for other objects to use
995
-            $transaction->save();
996
-            // set cron job for following up on TXNs after their session has expired
997
-            EE_Cron_Tasks::schedule_expired_transaction_check(
998
-                EE_Registry::instance()->SSN->expiration() + 1,
999
-                $transaction->ID()
1000
-            );
1001
-            return $transaction;
1002
-        } catch (Exception $e) {
1003
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1004
-        }
1005
-        return null;
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * _get_registrations
1011
-     *
1012
-     * @access private
1013
-     * @param EE_Transaction $transaction
1014
-     * @return void
1015
-     * @throws InvalidDataTypeException
1016
-     * @throws InvalidEntityException
1017
-     * @throws EE_Error
1018
-     */
1019
-    private function _get_registrations(EE_Transaction $transaction)
1020
-    {
1021
-        // first step: grab the registrants  { : o
1022
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1023
-        $this->checkout->total_ticket_count = count($registrations);
1024
-        // verify registrations have been set
1025
-        if (empty($registrations)) {
1026
-            // if no cached registrations, then check the db
1027
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1028
-            // still nothing ? well as long as this isn't a revisit
1029
-            if (empty($registrations) && ! $this->checkout->revisit) {
1030
-                // generate new registrations from scratch
1031
-                $registrations = $this->_initialize_registrations($transaction);
1032
-            }
1033
-        }
1034
-        // sort by their original registration order
1035
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1036
-        // then loop thru the array
1037
-        foreach ($registrations as $registration) {
1038
-            // verify each registration
1039
-            if ($registration instanceof EE_Registration) {
1040
-                // we display all attendee info for the primary registrant
1041
-                if (
1042
-                    $this->checkout->reg_url_link === $registration->reg_url_link()
1043
-                    && $registration->is_primary_registrant()
1044
-                ) {
1045
-                    $this->checkout->primary_revisit = true;
1046
-                    break;
1047
-                }
1048
-                if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1049
-                    // but hide info if it doesn't belong to you
1050
-                    $transaction->clear_cache('Registration', $registration->ID());
1051
-                    $this->checkout->total_ticket_count--;
1052
-                }
1053
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1054
-            }
1055
-        }
1056
-    }
1057
-
1058
-
1059
-    /**
1060
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1061
-     *
1062
-     * @access private
1063
-     * @param EE_Transaction $transaction
1064
-     * @return    array
1065
-     * @throws InvalidDataTypeException
1066
-     * @throws InvalidEntityException
1067
-     * @throws EE_Error
1068
-     */
1069
-    private function _initialize_registrations(EE_Transaction $transaction)
1070
-    {
1071
-        $att_nmbr = 0;
1072
-        $registrations = array();
1073
-        if ($transaction instanceof EE_Transaction) {
1074
-            /** @type EE_Registration_Processor $registration_processor */
1075
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1076
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1077
-            // now let's add the cart items to the $transaction
1078
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1079
-                // do the following for each ticket of this type they selected
1080
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1081
-                    $att_nmbr++;
1082
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1083
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1084
-                        'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1085
-                        array(
1086
-                            $transaction,
1087
-                            $line_item,
1088
-                            $att_nmbr,
1089
-                            $this->checkout->total_ticket_count,
1090
-                        )
1091
-                    );
1092
-                    // override capabilities for frontend registrations
1093
-                    if (! is_admin()) {
1094
-                        $CreateRegistrationCommand->setCapCheck(
1095
-                            new PublicCapabilities('', 'create_new_registration')
1096
-                        );
1097
-                    }
1098
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1099
-                    if (! $registration instanceof EE_Registration) {
1100
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1101
-                    }
1102
-                    $registrations[ $registration->ID() ] = $registration;
1103
-                }
1104
-            }
1105
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1106
-        }
1107
-        return $registrations;
1108
-    }
1109
-
1110
-
1111
-    /**
1112
-     * sorts registrations by REG_count
1113
-     *
1114
-     * @access public
1115
-     * @param EE_Registration $reg_A
1116
-     * @param EE_Registration $reg_B
1117
-     * @return int
1118
-     */
1119
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1120
-    {
1121
-        // this shouldn't ever happen within the same TXN, but oh well
1122
-        if ($reg_A->count() === $reg_B->count()) {
1123
-            return 0;
1124
-        }
1125
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1126
-    }
1127
-
1128
-
1129
-    /**
1130
-     *    _final_verifications
1131
-     * just makes sure that everything is set up correctly before proceeding
1132
-     *
1133
-     * @access    private
1134
-     * @return    bool
1135
-     * @throws EE_Error
1136
-     */
1137
-    private function _final_verifications()
1138
-    {
1139
-        // filter checkout
1140
-        $this->checkout = apply_filters(
1141
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1142
-            $this->checkout
1143
-        );
1144
-        // verify that current step is still set correctly
1145
-        if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1146
-            EE_Error::add_error(
1147
-                esc_html__(
1148
-                    'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.',
1149
-                    'event_espresso'
1150
-                ),
1151
-                __FILE__,
1152
-                __FUNCTION__,
1153
-                __LINE__
1154
-            );
1155
-            return false;
1156
-        }
1157
-        // if returning to SPCO, then verify that primary registrant is set
1158
-        if (! empty($this->checkout->reg_url_link)) {
1159
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1160
-            if (! $valid_registrant instanceof EE_Registration) {
1161
-                EE_Error::add_error(
1162
-                    esc_html__(
1163
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.',
1164
-                        'event_espresso'
1165
-                    ),
1166
-                    __FILE__,
1167
-                    __FUNCTION__,
1168
-                    __LINE__
1169
-                );
1170
-                return false;
1171
-            }
1172
-            $valid_registrant = null;
1173
-            foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1174
-                if (
1175
-                    $registration instanceof EE_Registration
1176
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1177
-                ) {
1178
-                    $valid_registrant = $registration;
1179
-                }
1180
-            }
1181
-            if (! $valid_registrant instanceof EE_Registration) {
1182
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1183
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1184
-                    // clear the session, mark the checkout as unverified, and try again
1185
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1186
-                    EED_Single_Page_Checkout::$_initialized = false;
1187
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1188
-                    $this->_initialize();
1189
-                    EE_Error::reset_notices();
1190
-                    return false;
1191
-                }
1192
-                EE_Error::add_error(
1193
-                    esc_html__(
1194
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1195
-                        'event_espresso'
1196
-                    ),
1197
-                    __FILE__,
1198
-                    __FUNCTION__,
1199
-                    __LINE__
1200
-                );
1201
-                return false;
1202
-            }
1203
-        }
1204
-        // now that things have been kinda sufficiently verified,
1205
-        // let's add the checkout to the session so that it's available to other systems
1206
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1207
-        return true;
1208
-    }
1209
-
1210
-
1211
-    /**
1212
-     *    _initialize_reg_steps
1213
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1214
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1215
-     *
1216
-     * @access    private
1217
-     * @param bool $reinitializing
1218
-     * @throws EE_Error
1219
-     */
1220
-    private function _initialize_reg_steps($reinitializing = false)
1221
-    {
1222
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1223
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1224
-        foreach ($this->checkout->reg_steps as $reg_step) {
1225
-            if (! $reg_step->initialize_reg_step()) {
1226
-                // if not initialized then maybe this step is being removed...
1227
-                if (! $reinitializing && $reg_step->is_current_step()) {
1228
-                    // if it was the current step, then we need to start over here
1229
-                    $this->_initialize_reg_steps(true);
1230
-                    return;
1231
-                }
1232
-                continue;
1233
-            }
1234
-            // add css and JS for current step
1235
-            $this->add_styles_and_scripts($reg_step);
1236
-            if ($reg_step->is_current_step()) {
1237
-                // the text that appears on the reg step form submit button
1238
-                $reg_step->set_submit_button_text();
1239
-            }
1240
-        }
1241
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1242
-        do_action(
1243
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1244
-            $this->checkout->current_step
1245
-        );
1246
-    }
1247
-
1248
-
1249
-    /**
1250
-     * _check_form_submission
1251
-     *
1252
-     * @access private
1253
-     * @return boolean
1254
-     */
1255
-    private function _check_form_submission()
1256
-    {
1257
-        // does this request require the reg form to be generated ?
1258
-        if ($this->checkout->generate_reg_form) {
1259
-            // ever heard that song by Blue Rodeo ?
1260
-            try {
1261
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1262
-                // if not displaying a form, then check for form submission
1263
-                if (
1264
-                    $this->checkout->process_form_submission
1265
-                    && $this->checkout->current_step->reg_form->was_submitted()
1266
-                ) {
1267
-                    // clear out any old data in case this step is being run again
1268
-                    $this->checkout->current_step->set_valid_data(array());
1269
-                    // capture submitted form data
1270
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1271
-                        apply_filters(
1272
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1273
-                            EE_Registry::instance()->REQ->params(),
1274
-                            $this->checkout
1275
-                        )
1276
-                    );
1277
-                    // validate submitted form data
1278
-                    if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1279
-                        // thou shall not pass !!!
1280
-                        $this->checkout->continue_reg = false;
1281
-                        // any form validation errors?
1282
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1283
-                            EE_Error::add_error(
1284
-                                $this->checkout->current_step->reg_form->submission_error_message(),
1285
-                                __FILE__,
1286
-                                __FUNCTION__,
1287
-                                __LINE__
1288
-                            );
1289
-                        }
1290
-                        // well not really... what will happen is
1291
-                        // we'll just get redirected back to redo the current step
1292
-                        $this->go_to_next_step();
1293
-                        return false;
1294
-                    }
1295
-                }
1296
-            } catch (EE_Error $e) {
1297
-                $e->get_error();
1298
-            }
1299
-        }
1300
-        return true;
1301
-    }
1302
-
1303
-
1304
-    /**
1305
-     * _process_action
1306
-     *
1307
-     * @access private
1308
-     * @return void
1309
-     * @throws EE_Error
1310
-     */
1311
-    private function _process_form_action()
1312
-    {
1313
-        // what cha wanna do?
1314
-        switch ($this->checkout->action) {
1315
-            // AJAX next step reg form
1316
-            case 'display_spco_reg_step':
1317
-                $this->checkout->redirect = false;
1318
-                if (EE_Registry::instance()->REQ->ajax) {
1319
-                    $this->checkout->json_response->set_reg_step_html(
1320
-                        $this->checkout->current_step->display_reg_form()
1321
-                    );
1322
-                }
1323
-                break;
1324
-            default:
1325
-                // meh... do one of those other steps first
1326
-                if (
1327
-                    ! empty($this->checkout->action)
1328
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1329
-                ) {
1330
-                    // dynamically creates hook point like:
1331
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1332
-                    do_action(
1333
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1334
-                        $this->checkout->current_step
1335
-                    );
1336
-                    $process_reg_step = apply_filters(
1337
-                        "AHEE__Single_Page_Checkout__process_reg_step__{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1338
-                        true,
1339
-                        $this->checkout->current_step,
1340
-                        $this
1341
-                    );
1342
-                    // call action on current step
1343
-                    if ($process_reg_step && call_user_func([$this->checkout->current_step, $this->checkout->action])) {
1344
-                        // good registrant, you get to proceed
1345
-                        if (
1346
-                            $this->checkout->current_step->success_message() !== ''
1347
-                            && apply_filters(
1348
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1349
-                                false
1350
-                            )
1351
-                        ) {
1352
-                            EE_Error::add_success(
1353
-                                $this->checkout->current_step->success_message()
1354
-                                . '<br />' . $this->checkout->next_step->_instructions()
1355
-                            );
1356
-                        }
1357
-                        // pack it up, pack it in...
1358
-                        $this->_setup_redirect();
1359
-                    }
1360
-                    // dynamically creates hook point like:
1361
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1362
-                    do_action(
1363
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1364
-                        $this->checkout->current_step
1365
-                    );
1366
-                } else {
1367
-                    EE_Error::add_error(
1368
-                        sprintf(
1369
-                            esc_html__(
1370
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1371
-                                'event_espresso'
1372
-                            ),
1373
-                            $this->checkout->action,
1374
-                            $this->checkout->current_step->name()
1375
-                        ),
1376
-                        __FILE__,
1377
-                        __FUNCTION__,
1378
-                        __LINE__
1379
-                    );
1380
-                }
1381
-            // end default
1382
-        }
1383
-        // store our progress so far
1384
-        $this->checkout->stash_transaction_and_checkout();
1385
-        // advance to the next step! If you pass GO, collect $200
1386
-        $this->go_to_next_step();
1387
-    }
1388
-
1389
-
1390
-    /**
1391
-     * @param EED_Single_Page_Checkout|EE_SPCO_Reg_Step $target
1392
-     * @param object $target an object with the method `translate_js_strings` and `enqueue_styles_and_scripts`.
1393
-     * @return        void
1394
-     */
1395
-    public function add_styles_and_scripts($target)
1396
-    {
1397
-        // i18n
1398
-        $target->translate_js_strings();
1399
-        if ($this->checkout->admin_request) {
1400
-            add_action('admin_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1401
-        } else {
1402
-            add_action('wp_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1403
-        }
1404
-    }
1405
-
1406
-    /**
1407
-     *        translate_js_strings
1408
-     *
1409
-     * @access        public
1410
-     * @return        void
1411
-     */
1412
-    public function translate_js_strings()
1413
-    {
1414
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1415
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1416
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
1417
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1418
-            'event_espresso'
1419
-        );
1420
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = esc_html__(
1421
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1422
-            'event_espresso'
1423
-        );
1424
-        EE_Registry::$i18n_js_strings['validation_error'] = esc_html__(
1425
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1426
-            'event_espresso'
1427
-        );
1428
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
1429
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1430
-            'event_espresso'
1431
-        );
1432
-        EE_Registry::$i18n_js_strings['reg_step_error'] = esc_html__(
1433
-            'This registration step could not be completed. Please refresh the page and try again.',
1434
-            'event_espresso'
1435
-        );
1436
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = esc_html__(
1437
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1438
-            'event_espresso'
1439
-        );
1440
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1441
-            esc_html__(
1442
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1443
-                'event_espresso'
1444
-            ),
1445
-            '<br/>',
1446
-            '<br/>'
1447
-        );
1448
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1449
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1450
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1451
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1452
-        EE_Registry::$i18n_js_strings['timer_years'] = esc_html__('years', 'event_espresso');
1453
-        EE_Registry::$i18n_js_strings['timer_months'] = esc_html__('months', 'event_espresso');
1454
-        EE_Registry::$i18n_js_strings['timer_weeks'] = esc_html__('weeks', 'event_espresso');
1455
-        EE_Registry::$i18n_js_strings['timer_days'] = esc_html__('days', 'event_espresso');
1456
-        EE_Registry::$i18n_js_strings['timer_hours'] = esc_html__('hours', 'event_espresso');
1457
-        EE_Registry::$i18n_js_strings['timer_minutes'] = esc_html__('minutes', 'event_espresso');
1458
-        EE_Registry::$i18n_js_strings['timer_seconds'] = esc_html__('seconds', 'event_espresso');
1459
-        EE_Registry::$i18n_js_strings['timer_year'] = esc_html__('year', 'event_espresso');
1460
-        EE_Registry::$i18n_js_strings['timer_month'] = esc_html__('month', 'event_espresso');
1461
-        EE_Registry::$i18n_js_strings['timer_week'] = esc_html__('week', 'event_espresso');
1462
-        EE_Registry::$i18n_js_strings['timer_day'] = esc_html__('day', 'event_espresso');
1463
-        EE_Registry::$i18n_js_strings['timer_hour'] = esc_html__('hour', 'event_espresso');
1464
-        EE_Registry::$i18n_js_strings['timer_minute'] = esc_html__('minute', 'event_espresso');
1465
-        EE_Registry::$i18n_js_strings['timer_second'] = esc_html__('second', 'event_espresso');
1466
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
1467
-        );
1468
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1469
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1470
-            true
1471
-        );
1472
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1473
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1474
-        );
1475
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1476
-            'M d, Y H:i:s',
1477
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1478
-        );
1479
-    }
1480
-
1481
-
1482
-    /**
1483
-     *    enqueue_styles_and_scripts
1484
-     *
1485
-     * @access        public
1486
-     * @return        void
1487
-     * @throws EE_Error
1488
-     */
1489
-    public function enqueue_styles_and_scripts()
1490
-    {
1491
-        // load css
1492
-        wp_register_style(
1493
-            'single_page_checkout',
1494
-            SPCO_CSS_URL . 'single_page_checkout.css',
1495
-            array('espresso_default'),
1496
-            EVENT_ESPRESSO_VERSION
1497
-        );
1498
-        wp_enqueue_style('single_page_checkout');
1499
-        // load JS
1500
-        wp_register_script(
1501
-            'jquery_plugin',
1502
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1503
-            array('jquery'),
1504
-            '1.0.1',
1505
-            true
1506
-        );
1507
-        wp_register_script(
1508
-            'jquery_countdown',
1509
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1510
-            array('jquery_plugin'),
1511
-            '2.1.0',
1512
-            true
1513
-        );
1514
-        wp_register_script(
1515
-            'single_page_checkout',
1516
-            SPCO_JS_URL . 'single_page_checkout.js',
1517
-            array('espresso_core', 'underscore', 'ee_form_section_validation'),
1518
-            EVENT_ESPRESSO_VERSION,
1519
-            true
1520
-        );
1521
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1522
-            $this->checkout->registration_form->enqueue_js();
1523
-        }
1524
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1525
-            $this->checkout->current_step->reg_form->enqueue_js();
1526
-        }
1527
-        wp_enqueue_script('single_page_checkout');
1528
-        if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) {
1529
-            wp_enqueue_script('jquery_countdown');
1530
-        }
1531
-        /**
1532
-         * global action hook for enqueueing styles and scripts with
1533
-         * spco calls.
1534
-         */
1535
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1536
-        /**
1537
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1538
-         * The hook will end up being something like:
1539
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1540
-         */
1541
-        do_action(
1542
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1543
-            $this
1544
-        );
1545
-    }
1546
-
1547
-
1548
-    /**
1549
-     *    display the Registration Single Page Checkout Form
1550
-     *
1551
-     * @access    private
1552
-     * @return    void
1553
-     * @throws EE_Error
1554
-     */
1555
-    private function _display_spco_reg_form()
1556
-    {
1557
-        // if registering via the admin, just display the reg form for the current step
1558
-        if ($this->checkout->admin_request) {
1559
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1560
-        } else {
1561
-            // add powered by EE msg
1562
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1563
-            $empty_cart = count($this->checkout->transaction
1564
-                                    ->registrations($this->checkout->reg_cache_where_params)) < 1;
1565
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1566
-            $cookies_not_set_msg = '';
1567
-            if ($empty_cart) {
1568
-                $cookies_not_set_msg = apply_filters(
1569
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1570
-                    sprintf(
1571
-                        esc_html__(
1572
-                            '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1573
-                            'event_espresso'
1574
-                        ),
1575
-                        '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1576
-                        '</div>',
1577
-                        '<h6 class="important-notice">',
1578
-                        '</h6>',
1579
-                        '<p>',
1580
-                        '</p>',
1581
-                        '<br />',
1582
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank" rel="noopener noreferrer">',
1583
-                        '</a>'
1584
-                    )
1585
-                );
1586
-            }
1587
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1588
-                array(
1589
-                    'name'            => 'single-page-checkout',
1590
-                    'html_id'         => 'ee-single-page-checkout-dv',
1591
-                    'layout_strategy' =>
1592
-                        new EE_Template_Layout(
1593
-                            array(
1594
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1595
-                                'template_args'        => array(
1596
-                                    'empty_cart'              => $empty_cart,
1597
-                                    'revisit'                 => $this->checkout->revisit,
1598
-                                    'reg_steps'               => $this->checkout->reg_steps,
1599
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1600
-                                        ? $this->checkout->next_step->slug()
1601
-                                        : '',
1602
-                                    'empty_msg'               => apply_filters(
1603
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1604
-                                        sprintf(
1605
-                                            esc_html__(
1606
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1607
-                                                'event_espresso'
1608
-                                            ),
1609
-                                            '<a href="'
1610
-                                            . get_post_type_archive_link('espresso_events')
1611
-                                            . '" title="',
1612
-                                            '">',
1613
-                                            '</a>'
1614
-                                        )
1615
-                                    ),
1616
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1617
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1618
-                                    'session_expiration'      => gmdate(
1619
-                                        'M d, Y H:i:s',
1620
-                                        EE_Registry::instance()->SSN->expiration()
1621
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1622
-                                    ),
1623
-                                ),
1624
-                            )
1625
-                        ),
1626
-                )
1627
-            );
1628
-            // load template and add to output sent that gets filtered into the_content()
1629
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1630
-        }
1631
-    }
1632
-
1633
-
1634
-    /**
1635
-     *    add_extra_finalize_registration_inputs
1636
-     *
1637
-     * @access    public
1638
-     * @param $next_step
1639
-     * @internal  param string $label
1640
-     * @return void
1641
-     */
1642
-    public function add_extra_finalize_registration_inputs($next_step)
1643
-    {
1644
-        if ($next_step === 'finalize_registration') {
1645
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1646
-        }
1647
-    }
1648
-
1649
-
1650
-    /**
1651
-     *    display_registration_footer
1652
-     *
1653
-     * @access    public
1654
-     * @return    string
1655
-     */
1656
-    public static function display_registration_footer()
1657
-    {
1658
-        if (
1659
-            apply_filters(
1660
-                'FHEE__EE_Front__Controller__show_reg_footer',
1661
-                EE_Registry::instance()->CFG->admin->show_reg_footer
1662
-            )
1663
-        ) {
1664
-            add_filter(
1665
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1666
-                function ($url) {
1667
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1668
-                }
1669
-            );
1670
-            echo apply_filters(
1671
-                'FHEE__EE_Front_Controller__display_registration_footer',
1672
-                \EEH_Template::powered_by_event_espresso(
1673
-                    '',
1674
-                    'espresso-registration-footer-dv',
1675
-                    array('utm_content' => 'registration_checkout')
1676
-                )
1677
-            );
1678
-        }
1679
-        return '';
1680
-    }
1681
-
1682
-
1683
-    /**
1684
-     *    unlock_transaction
1685
-     *
1686
-     * @access    public
1687
-     * @return    void
1688
-     * @throws EE_Error
1689
-     */
1690
-    public function unlock_transaction()
1691
-    {
1692
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1693
-            $this->checkout->transaction->unlock();
1694
-        }
1695
-    }
1696
-
1697
-
1698
-    /**
1699
-     *        _setup_redirect
1700
-     *
1701
-     * @access    private
1702
-     * @return void
1703
-     */
1704
-    private function _setup_redirect()
1705
-    {
1706
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1707
-            $this->checkout->redirect = true;
1708
-            if (empty($this->checkout->redirect_url)) {
1709
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1710
-            }
1711
-            $this->checkout->redirect_url = apply_filters(
1712
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1713
-                $this->checkout->redirect_url,
1714
-                $this->checkout
1715
-            );
1716
-        }
1717
-    }
1718
-
1719
-
1720
-    /**
1721
-     *   handle ajax message responses and redirects
1722
-     *
1723
-     * @access public
1724
-     * @return void
1725
-     * @throws EE_Error
1726
-     */
1727
-    public function go_to_next_step()
1728
-    {
1729
-        if (EE_Registry::instance()->REQ->ajax) {
1730
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1731
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1732
-        }
1733
-        $this->unlock_transaction();
1734
-        // just return for these conditions
1735
-        if (
1736
-            $this->checkout->admin_request
1737
-            || $this->checkout->action === 'redirect_form'
1738
-            || $this->checkout->action === 'update_checkout'
1739
-        ) {
1740
-            return;
1741
-        }
1742
-        // AJAX response
1743
-        $this->_handle_json_response();
1744
-        // redirect to next step or the Thank You page
1745
-        $this->_handle_html_redirects();
1746
-        // hmmm... must be something wrong, so let's just display the form again !
1747
-        $this->_display_spco_reg_form();
1748
-    }
1749
-
1750
-
1751
-    /**
1752
-     *   _handle_json_response
1753
-     *
1754
-     * @access protected
1755
-     * @return void
1756
-     */
1757
-    protected function _handle_json_response()
1758
-    {
1759
-        // if this is an ajax request
1760
-        if (EE_Registry::instance()->REQ->ajax) {
1761
-            $this->checkout->json_response->set_registration_time_limit(
1762
-                $this->checkout->get_registration_time_limit()
1763
-            );
1764
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1765
-            // just send the ajax (
1766
-            $json_response = apply_filters(
1767
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1768
-                $this->checkout->json_response
1769
-            );
1770
-            echo $json_response;
1771
-            exit();
1772
-        }
1773
-    }
1774
-
1775
-
1776
-    /**
1777
-     *   _handle_redirects
1778
-     *
1779
-     * @access protected
1780
-     * @return void
1781
-     */
1782
-    protected function _handle_html_redirects()
1783
-    {
1784
-        // going somewhere ?
1785
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1786
-            // store notices in a transient
1787
-            EE_Error::get_notices(false, true, true);
1788
-            wp_safe_redirect($this->checkout->redirect_url);
1789
-            exit();
1790
-        }
1791
-    }
1792
-
1793
-
1794
-    /**
1795
-     *   set_checkout_anchor
1796
-     *
1797
-     * @access public
1798
-     * @return void
1799
-     */
1800
-    public function set_checkout_anchor()
1801
-    {
1802
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1803
-    }
1804
-
1805
-    /**
1806
-     *    getRegistrationExpirationNotice
1807
-     *
1808
-     * @since     4.9.59.p
1809
-     * @access    public
1810
-     * @return    string
1811
-     */
1812
-    public static function getRegistrationExpirationNotice()
1813
-    {
1814
-        return sprintf(
1815
-            esc_html__(
1816
-                '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1817
-                'event_espresso'
1818
-            ),
1819
-            '<h4 class="important-notice">',
1820
-            '</h4>',
1821
-            '<br />',
1822
-            '<p>',
1823
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1824
-            '">',
1825
-            '</a>',
1826
-            '</p>'
1827
-        );
1828
-    }
18
+	/**
19
+	 * $_initialized - has the SPCO controller already been initialized ?
20
+	 *
21
+	 * @access private
22
+	 * @var bool $_initialized
23
+	 */
24
+	private static $_initialized = false;
25
+
26
+
27
+	/**
28
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
29
+	 *
30
+	 * @access private
31
+	 * @var bool $_valid_checkout
32
+	 */
33
+	private static $_checkout_verified = true;
34
+
35
+	/**
36
+	 *    $_reg_steps_array - holds initial array of reg steps
37
+	 *
38
+	 * @access private
39
+	 * @var array $_reg_steps_array
40
+	 */
41
+	private static $_reg_steps_array = array();
42
+
43
+	/**
44
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
45
+	 *
46
+	 * @access public
47
+	 * @var EE_Checkout $checkout
48
+	 */
49
+	public $checkout;
50
+
51
+
52
+	/**
53
+	 * @return EED_Module|EED_Single_Page_Checkout
54
+	 */
55
+	public static function instance()
56
+	{
57
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
58
+		return parent::get_instance(__CLASS__);
59
+	}
60
+
61
+
62
+	/**
63
+	 * @return EE_CART
64
+	 */
65
+	public function cart()
66
+	{
67
+		return $this->checkout->cart;
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return EE_Transaction
73
+	 */
74
+	public function transaction()
75
+	{
76
+		return $this->checkout->transaction;
77
+	}
78
+
79
+
80
+	/**
81
+	 *    set_hooks - for hooking into EE Core, other modules, etc
82
+	 *
83
+	 * @access    public
84
+	 * @return    void
85
+	 * @throws EE_Error
86
+	 */
87
+	public static function set_hooks()
88
+	{
89
+		EED_Single_Page_Checkout::set_definitions();
90
+	}
91
+
92
+
93
+	/**
94
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
95
+	 *
96
+	 * @access    public
97
+	 * @return    void
98
+	 * @throws EE_Error
99
+	 */
100
+	public static function set_hooks_admin()
101
+	{
102
+		EED_Single_Page_Checkout::set_definitions();
103
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
104
+			return;
105
+		}
106
+		// going to start an output buffer in case anything gets accidentally output
107
+		// that might disrupt our JSON response
108
+		ob_start();
109
+		EED_Single_Page_Checkout::load_request_handler();
110
+		EED_Single_Page_Checkout::load_reg_steps();
111
+		// set ajax hooks
112
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
113
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
114
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
115
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
116
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
117
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
118
+	}
119
+
120
+
121
+	/**
122
+	 *    process ajax request
123
+	 *
124
+	 * @param string $ajax_action
125
+	 * @throws EE_Error
126
+	 */
127
+	public static function process_ajax_request($ajax_action)
128
+	{
129
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
130
+		EED_Single_Page_Checkout::instance()->_initialize();
131
+	}
132
+
133
+
134
+	/**
135
+	 *    ajax display registration step
136
+	 *
137
+	 * @throws EE_Error
138
+	 */
139
+	public static function display_reg_step()
140
+	{
141
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
142
+	}
143
+
144
+
145
+	/**
146
+	 *    ajax process registration step
147
+	 *
148
+	 * @throws EE_Error
149
+	 */
150
+	public static function process_reg_step()
151
+	{
152
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
153
+	}
154
+
155
+
156
+	/**
157
+	 *    ajax process registration step
158
+	 *
159
+	 * @throws EE_Error
160
+	 */
161
+	public static function update_reg_step()
162
+	{
163
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
164
+	}
165
+
166
+
167
+	/**
168
+	 *   update_checkout
169
+	 *
170
+	 * @access public
171
+	 * @return void
172
+	 * @throws EE_Error
173
+	 */
174
+	public static function update_checkout()
175
+	{
176
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
177
+	}
178
+
179
+
180
+	/**
181
+	 *    load_request_handler
182
+	 *
183
+	 * @access    public
184
+	 * @return    void
185
+	 */
186
+	public static function load_request_handler()
187
+	{
188
+		// load core Request_Handler class
189
+		if (EE_Registry::instance()->REQ !== null) {
190
+			EE_Registry::instance()->load_core('Request_Handler');
191
+		}
192
+	}
193
+
194
+
195
+	/**
196
+	 *    set_definitions
197
+	 *
198
+	 * @access    public
199
+	 * @return    void
200
+	 * @throws EE_Error
201
+	 */
202
+	public static function set_definitions()
203
+	{
204
+		if (defined('SPCO_BASE_PATH')) {
205
+			return;
206
+		}
207
+		define(
208
+			'SPCO_BASE_PATH',
209
+			rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
210
+		);
211
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css/');
212
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img/');
213
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js/');
214
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc/');
215
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps/');
216
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates/');
217
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
218
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
219
+		);
220
+	}
221
+
222
+
223
+	/**
224
+	 * load_reg_steps
225
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
226
+	 *
227
+	 * @access    private
228
+	 * @throws EE_Error
229
+	 */
230
+	public static function load_reg_steps()
231
+	{
232
+		static $reg_steps_loaded = false;
233
+		if ($reg_steps_loaded) {
234
+			return;
235
+		}
236
+		// filter list of reg_steps
237
+		$reg_steps_to_load = (array) apply_filters(
238
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
239
+			EED_Single_Page_Checkout::get_reg_steps()
240
+		);
241
+		// sort by key (order)
242
+		ksort($reg_steps_to_load);
243
+		// loop through folders
244
+		foreach ($reg_steps_to_load as $order => $reg_step) {
245
+			// we need a
246
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
247
+				// copy over to the reg_steps_array
248
+				EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
249
+				// register custom key route for each reg step
250
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
251
+				EE_Config::register_route(
252
+					$reg_step['slug'],
253
+					'EED_Single_Page_Checkout',
254
+					'run',
255
+					'step'
256
+				);
257
+				// add AJAX or other hooks
258
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
259
+					// setup autoloaders if necessary
260
+					if (! class_exists($reg_step['class_name'])) {
261
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
262
+							$reg_step['file_path'],
263
+							true
264
+						);
265
+					}
266
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
267
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
268
+					}
269
+				}
270
+			}
271
+		}
272
+		$reg_steps_loaded = true;
273
+	}
274
+
275
+
276
+	/**
277
+	 *    get_reg_steps
278
+	 *
279
+	 * @access    public
280
+	 * @return    array
281
+	 */
282
+	public static function get_reg_steps()
283
+	{
284
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
285
+		if (empty($reg_steps)) {
286
+			$reg_steps = array(
287
+				10  => array(
288
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
289
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
290
+					'slug'       => 'attendee_information',
291
+					'has_hooks'  => false,
292
+				),
293
+				30  => array(
294
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
295
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
296
+					'slug'       => 'payment_options',
297
+					'has_hooks'  => true,
298
+				),
299
+				999 => array(
300
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
301
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
302
+					'slug'       => 'finalize_registration',
303
+					'has_hooks'  => false,
304
+				),
305
+			);
306
+		}
307
+		return $reg_steps;
308
+	}
309
+
310
+
311
+	/**
312
+	 *    registration_checkout_for_admin
313
+	 *
314
+	 * @access    public
315
+	 * @return    string
316
+	 * @throws EE_Error
317
+	 */
318
+	public static function registration_checkout_for_admin()
319
+	{
320
+		EED_Single_Page_Checkout::load_request_handler();
321
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
322
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
323
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
324
+		EED_Single_Page_Checkout::instance()->_initialize();
325
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
326
+		return EE_Registry::instance()->REQ->get_output();
327
+	}
328
+
329
+
330
+	/**
331
+	 * process_registration_from_admin
332
+	 *
333
+	 * @access public
334
+	 * @return \EE_Transaction
335
+	 * @throws EE_Error
336
+	 */
337
+	public static function process_registration_from_admin()
338
+	{
339
+		EED_Single_Page_Checkout::load_request_handler();
340
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
341
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
342
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
343
+		EED_Single_Page_Checkout::instance()->_initialize();
344
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
345
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
346
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
347
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
348
+				if ($final_reg_step->process_reg_step()) {
349
+					$final_reg_step->set_completed();
350
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
351
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
352
+				}
353
+			}
354
+		}
355
+		return null;
356
+	}
357
+
358
+
359
+	/**
360
+	 *    run
361
+	 *
362
+	 * @access    public
363
+	 * @param WP_Query $WP_Query
364
+	 * @return    void
365
+	 * @throws EE_Error
366
+	 */
367
+	public function run($WP_Query)
368
+	{
369
+		if (
370
+			$WP_Query instanceof WP_Query
371
+			&& $WP_Query->is_main_query()
372
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
373
+			&& $this->_is_reg_checkout()
374
+		) {
375
+			$this->_initialize();
376
+		}
377
+	}
378
+
379
+
380
+	/**
381
+	 * determines whether current url matches reg page url
382
+	 *
383
+	 * @return bool
384
+	 */
385
+	protected function _is_reg_checkout()
386
+	{
387
+		// get current permalink for reg page without any extra query args
388
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
389
+		// get request URI for current request, but without the scheme or host
390
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
391
+		$current_request_uri = html_entity_decode($current_request_uri);
392
+		// get array of query args from the current request URI
393
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
394
+		// grab page id if it is set
395
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
396
+		// and remove the page id from the query args (we will re-add it later)
397
+		unset($query_args['page_id']);
398
+		// now strip all query args from current request URI
399
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
400
+		// and re-add the page id if it was set
401
+		if ($page_id) {
402
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
403
+		}
404
+		// remove slashes and ?
405
+		$current_request_uri = trim($current_request_uri, '?/');
406
+		// is current request URI part of the known full reg page URL ?
407
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
408
+	}
409
+
410
+
411
+	/**
412
+	 * @param WP_Query $wp_query
413
+	 * @return    void
414
+	 * @throws EE_Error
415
+	 */
416
+	public static function init($wp_query)
417
+	{
418
+		EED_Single_Page_Checkout::instance()->run($wp_query);
419
+	}
420
+
421
+
422
+	/**
423
+	 *    _initialize - initial module setup
424
+	 *
425
+	 * @access    private
426
+	 * @throws EE_Error
427
+	 * @return    void
428
+	 */
429
+	private function _initialize()
430
+	{
431
+		// ensure SPCO doesn't run twice
432
+		if (EED_Single_Page_Checkout::$_initialized) {
433
+			return;
434
+		}
435
+		try {
436
+			EED_Single_Page_Checkout::load_reg_steps();
437
+			$this->_verify_session();
438
+			// setup the EE_Checkout object
439
+			$this->checkout = $this->_initialize_checkout();
440
+			// filter checkout
441
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
442
+			// get the $_GET
443
+			$this->_get_request_vars();
444
+			if ($this->_block_bots()) {
445
+				return;
446
+			}
447
+			// filter continue_reg
448
+			$this->checkout->continue_reg = apply_filters(
449
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
450
+				true,
451
+				$this->checkout
452
+			);
453
+			// load the reg steps array
454
+			if (! $this->_load_and_instantiate_reg_steps()) {
455
+				EED_Single_Page_Checkout::$_initialized = true;
456
+				return;
457
+			}
458
+			// set the current step
459
+			$this->checkout->set_current_step($this->checkout->step);
460
+			// and the next step
461
+			$this->checkout->set_next_step();
462
+			// verify that everything has been setup correctly
463
+			if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
464
+				EED_Single_Page_Checkout::$_initialized = true;
465
+				return;
466
+			}
467
+			// lock the transaction
468
+			$this->checkout->transaction->lock();
469
+			// make sure all of our cached objects are added to their respective model entity mappers
470
+			$this->checkout->refresh_all_entities();
471
+			// set amount owing
472
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
473
+			// initialize each reg step, which gives them the chance to potentially alter the process
474
+			$this->_initialize_reg_steps();
475
+			// DEBUG LOG
476
+			// $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
477
+			// get reg form
478
+			if (! $this->_check_form_submission()) {
479
+				EED_Single_Page_Checkout::$_initialized = true;
480
+				return;
481
+			}
482
+			// checkout the action!!!
483
+			$this->_process_form_action();
484
+			// add some style and make it dance
485
+			$this->add_styles_and_scripts($this);
486
+			// kk... SPCO has successfully run
487
+			EED_Single_Page_Checkout::$_initialized = true;
488
+			// set no cache headers and constants
489
+			EE_System::do_not_cache();
490
+			// add anchor
491
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
492
+			// remove transaction lock
493
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
494
+		} catch (Exception $e) {
495
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
496
+		}
497
+	}
498
+
499
+
500
+	/**
501
+	 *    _verify_session
502
+	 * checks that the session is valid and not expired
503
+	 *
504
+	 * @access    private
505
+	 * @throws EE_Error
506
+	 */
507
+	private function _verify_session()
508
+	{
509
+		if (! EE_Registry::instance()->SSN instanceof EE_Session) {
510
+			throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso'));
511
+		}
512
+		$clear_session_requested = filter_var(
513
+			EE_Registry::instance()->REQ->get('clear_session', false),
514
+			FILTER_VALIDATE_BOOLEAN
515
+		);
516
+		// is session still valid ?
517
+		if (
518
+			$clear_session_requested
519
+			|| (EE_Registry::instance()->SSN->expired()
520
+				&& EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
521
+			)
522
+		) {
523
+			$this->checkout = new EE_Checkout();
524
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
525
+			// EE_Registry::instance()->SSN->reset_cart();
526
+			// EE_Registry::instance()->SSN->reset_checkout();
527
+			// EE_Registry::instance()->SSN->reset_transaction();
528
+			if (! $clear_session_requested) {
529
+				EE_Error::add_attention(
530
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
531
+					__FILE__,
532
+					__FUNCTION__,
533
+					__LINE__
534
+				);
535
+			}
536
+			// EE_Registry::instance()->SSN->reset_expired();
537
+		}
538
+	}
539
+
540
+
541
+	/**
542
+	 *    _initialize_checkout
543
+	 * loads and instantiates EE_Checkout
544
+	 *
545
+	 * @access    private
546
+	 * @throws EE_Error
547
+	 * @return EE_Checkout
548
+	 */
549
+	private function _initialize_checkout()
550
+	{
551
+		// look in session for existing checkout
552
+		/** @type EE_Checkout $checkout */
553
+		$checkout = EE_Registry::instance()->SSN->checkout();
554
+		// verify
555
+		if (! $checkout instanceof EE_Checkout) {
556
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
557
+			$checkout = EE_Registry::instance()->load_file(
558
+				SPCO_INC_PATH,
559
+				'EE_Checkout',
560
+				'class',
561
+				array(),
562
+				false
563
+			);
564
+		} else {
565
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
566
+				$this->unlock_transaction();
567
+				wp_safe_redirect($checkout->redirect_url);
568
+				exit();
569
+			}
570
+		}
571
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
572
+		// verify again
573
+		if (! $checkout instanceof EE_Checkout) {
574
+			throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso'));
575
+		}
576
+		// reset anything that needs a clean slate for each request
577
+		$checkout->reset_for_current_request();
578
+		return $checkout;
579
+	}
580
+
581
+
582
+	/**
583
+	 *    _get_request_vars
584
+	 *
585
+	 * @access    private
586
+	 * @return    void
587
+	 * @throws EE_Error
588
+	 */
589
+	private function _get_request_vars()
590
+	{
591
+		// load classes
592
+		EED_Single_Page_Checkout::load_request_handler();
593
+		// make sure this request is marked as belonging to EE
594
+		EE_Registry::instance()->REQ->set_espresso_page(true);
595
+		// which step is being requested ?
596
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
597
+		// which step is being edited ?
598
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
599
+		// and what we're doing on the current step
600
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
601
+		// timestamp
602
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
603
+		// returning to edit ?
604
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
605
+		// add reg url link to registration query params
606
+		if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
607
+			$this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
608
+		}
609
+		// or some other kind of revisit ?
610
+		$this->checkout->revisit = filter_var(
611
+			EE_Registry::instance()->REQ->get('revisit', false),
612
+			FILTER_VALIDATE_BOOLEAN
613
+		);
614
+		// and whether or not to generate a reg form for this request
615
+		$this->checkout->generate_reg_form = filter_var(
616
+			EE_Registry::instance()->REQ->get('generate_reg_form', true),
617
+			FILTER_VALIDATE_BOOLEAN
618
+		);
619
+		// and whether or not to process a reg form submission for this request
620
+		$this->checkout->process_form_submission = filter_var(
621
+			EE_Registry::instance()->REQ->get(
622
+				'process_form_submission',
623
+				$this->checkout->action === 'process_reg_step'
624
+			),
625
+			FILTER_VALIDATE_BOOLEAN
626
+		);
627
+		$this->checkout->process_form_submission = filter_var(
628
+			$this->checkout->action !== 'display_spco_reg_step'
629
+				? $this->checkout->process_form_submission
630
+				: false,
631
+			FILTER_VALIDATE_BOOLEAN
632
+		);
633
+		// $this->_display_request_vars();
634
+	}
635
+
636
+
637
+	/**
638
+	 *  _display_request_vars
639
+	 *
640
+	 * @access    protected
641
+	 * @return    void
642
+	 */
643
+	protected function _display_request_vars()
644
+	{
645
+		if (! WP_DEBUG) {
646
+			return;
647
+		}
648
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
649
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
650
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
651
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
652
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
653
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
654
+		EEH_Debug_Tools::printr(
655
+			$this->checkout->generate_reg_form,
656
+			'$this->checkout->generate_reg_form',
657
+			__FILE__,
658
+			__LINE__
659
+		);
660
+		EEH_Debug_Tools::printr(
661
+			$this->checkout->process_form_submission,
662
+			'$this->checkout->process_form_submission',
663
+			__FILE__,
664
+			__LINE__
665
+		);
666
+	}
667
+
668
+
669
+	/**
670
+	 * _block_bots
671
+	 * checks that the incoming request has either of the following set:
672
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
673
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
674
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
675
+	 * then where you coming from man?
676
+	 *
677
+	 * @return boolean
678
+	 */
679
+	private function _block_bots()
680
+	{
681
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
682
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
683
+			return true;
684
+		}
685
+		return false;
686
+	}
687
+
688
+
689
+	/**
690
+	 *    _get_first_step
691
+	 *  gets slug for first step in $_reg_steps_array
692
+	 *
693
+	 * @access    private
694
+	 * @throws EE_Error
695
+	 * @return    string
696
+	 */
697
+	private function _get_first_step()
698
+	{
699
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
700
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
701
+	}
702
+
703
+
704
+	/**
705
+	 * instantiates each reg step based on the loaded reg_steps array
706
+	 *
707
+	 * @return    bool
708
+	 * @throws EE_Error
709
+	 * @throws InvalidArgumentException
710
+	 * @throws InvalidDataTypeException
711
+	 * @throws InvalidInterfaceException
712
+	 */
713
+	private function _load_and_instantiate_reg_steps()
714
+	{
715
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
716
+		// have reg_steps already been instantiated ?
717
+		if (
718
+			empty($this->checkout->reg_steps)
719
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
720
+		) {
721
+			// if not, then loop through raw reg steps array
722
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
723
+				if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
724
+					return false;
725
+				}
726
+			}
727
+			if (isset($this->checkout->reg_steps['registration_confirmation'])) {
728
+				// skip the registration_confirmation page ?
729
+				if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
730
+					// just remove it from the reg steps array
731
+					$this->checkout->remove_reg_step('registration_confirmation', false);
732
+				} elseif (
733
+					EE_Registry::instance()->CFG->registration->reg_confirmation_last
734
+				) {
735
+					// set the order to something big like 100
736
+					$this->checkout->set_reg_step_order('registration_confirmation', 100);
737
+				}
738
+			}
739
+			// filter the array for good luck
740
+			$this->checkout->reg_steps = apply_filters(
741
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
742
+				$this->checkout->reg_steps
743
+			);
744
+			// finally re-sort based on the reg step class order properties
745
+			$this->checkout->sort_reg_steps();
746
+		} else {
747
+			foreach ($this->checkout->reg_steps as $reg_step) {
748
+				// set all current step stati to FALSE
749
+				$reg_step->set_is_current_step(false);
750
+			}
751
+		}
752
+		if (empty($this->checkout->reg_steps)) {
753
+			EE_Error::add_error(
754
+				esc_html__('No Reg Steps were loaded..', 'event_espresso'),
755
+				__FILE__,
756
+				__FUNCTION__,
757
+				__LINE__
758
+			);
759
+			return false;
760
+		}
761
+		// make reg step details available to JS
762
+		$this->checkout->set_reg_step_JSON_info();
763
+		return true;
764
+	}
765
+
766
+
767
+	/**
768
+	 *     _load_and_instantiate_reg_step
769
+	 *
770
+	 * @access    private
771
+	 * @param array $reg_step
772
+	 * @param int   $order
773
+	 * @return bool
774
+	 */
775
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
776
+	{
777
+		// we need a file_path, class_name, and slug to add a reg step
778
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
779
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
780
+			if (
781
+				$this->checkout->reg_url_link
782
+				&& $this->checkout->step !== $reg_step['slug']
783
+				&& $reg_step['slug'] !== 'finalize_registration'
784
+				// normally at this point we would NOT load the reg step, but this filter can change that
785
+				&& apply_filters(
786
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
787
+					true,
788
+					$reg_step,
789
+					$this->checkout
790
+				)
791
+			) {
792
+				return true;
793
+			}
794
+			// instantiate step class using file path and class name
795
+			$reg_step_obj = EE_Registry::instance()->load_file(
796
+				$reg_step['file_path'],
797
+				$reg_step['class_name'],
798
+				'class',
799
+				$this->checkout,
800
+				false
801
+			);
802
+			// did we gets the goods ?
803
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
804
+				// set reg step order based on config
805
+				$reg_step_obj->set_order($order);
806
+				// add instantiated reg step object to the master reg steps array
807
+				$this->checkout->add_reg_step($reg_step_obj);
808
+			} else {
809
+				EE_Error::add_error(
810
+					esc_html__('The current step could not be set.', 'event_espresso'),
811
+					__FILE__,
812
+					__FUNCTION__,
813
+					__LINE__
814
+				);
815
+				return false;
816
+			}
817
+		} else {
818
+			if (WP_DEBUG) {
819
+				EE_Error::add_error(
820
+					sprintf(
821
+						esc_html__(
822
+							'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
823
+							'event_espresso'
824
+						),
825
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
826
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
827
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
828
+						'<ul>',
829
+						'<li>',
830
+						'</li>',
831
+						'</ul>'
832
+					),
833
+					__FILE__,
834
+					__FUNCTION__,
835
+					__LINE__
836
+				);
837
+			}
838
+			return false;
839
+		}
840
+		return true;
841
+	}
842
+
843
+
844
+	/**
845
+	 * _verify_transaction_and_get_registrations
846
+	 *
847
+	 * @access private
848
+	 * @return bool
849
+	 * @throws InvalidDataTypeException
850
+	 * @throws InvalidEntityException
851
+	 * @throws EE_Error
852
+	 */
853
+	private function _verify_transaction_and_get_registrations()
854
+	{
855
+		// was there already a valid transaction in the checkout from the session ?
856
+		if (! $this->checkout->transaction instanceof EE_Transaction) {
857
+			// get transaction from db or session
858
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
859
+				? $this->_get_transaction_and_cart_for_previous_visit()
860
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
861
+			if (! $this->checkout->transaction instanceof EE_Transaction) {
862
+				EE_Error::add_error(
863
+					esc_html__(
864
+						'Your Registration and Transaction information could not be retrieved from the db.',
865
+						'event_espresso'
866
+					),
867
+					__FILE__,
868
+					__FUNCTION__,
869
+					__LINE__
870
+				);
871
+				$this->checkout->transaction = EE_Transaction::new_instance();
872
+				// add some style and make it dance
873
+				$this->add_styles_and_scripts($this);
874
+				EED_Single_Page_Checkout::$_initialized = true;
875
+				return false;
876
+			}
877
+			// and the registrations for the transaction
878
+			$this->_get_registrations($this->checkout->transaction);
879
+		}
880
+		return true;
881
+	}
882
+
883
+
884
+	/**
885
+	 * _get_transaction_and_cart_for_previous_visit
886
+	 *
887
+	 * @access private
888
+	 * @return mixed EE_Transaction|NULL
889
+	 */
890
+	private function _get_transaction_and_cart_for_previous_visit()
891
+	{
892
+		/** @var $TXN_model EEM_Transaction */
893
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
894
+		// because the reg_url_link is present in the request,
895
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
896
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
897
+		// verify transaction
898
+		if ($transaction instanceof EE_Transaction) {
899
+			// and get the cart that was used for that transaction
900
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
901
+			return $transaction;
902
+		}
903
+		EE_Error::add_error(
904
+			esc_html__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
905
+			__FILE__,
906
+			__FUNCTION__,
907
+			__LINE__
908
+		);
909
+		return null;
910
+	}
911
+
912
+
913
+	/**
914
+	 * _get_cart_for_transaction
915
+	 *
916
+	 * @access private
917
+	 * @param EE_Transaction $transaction
918
+	 * @return EE_Cart
919
+	 */
920
+	private function _get_cart_for_transaction($transaction)
921
+	{
922
+		return $this->checkout->get_cart_for_transaction($transaction);
923
+	}
924
+
925
+
926
+	/**
927
+	 * get_cart_for_transaction
928
+	 *
929
+	 * @access public
930
+	 * @param EE_Transaction $transaction
931
+	 * @return EE_Cart
932
+	 */
933
+	public function get_cart_for_transaction(EE_Transaction $transaction)
934
+	{
935
+		return $this->checkout->get_cart_for_transaction($transaction);
936
+	}
937
+
938
+
939
+	/**
940
+	 * _get_transaction_and_cart_for_current_session
941
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
942
+	 *
943
+	 * @access private
944
+	 * @return EE_Transaction
945
+	 * @throws EE_Error
946
+	 */
947
+	private function _get_cart_for_current_session_and_setup_new_transaction()
948
+	{
949
+		//  if there's no transaction, then this is the FIRST visit to SPCO
950
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
951
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
952
+		// and then create a new transaction
953
+		$transaction = $this->_initialize_transaction();
954
+		// verify transaction
955
+		if ($transaction instanceof EE_Transaction) {
956
+			// save it so that we have an ID for other objects to use
957
+			$transaction->save();
958
+			// and save TXN data to the cart
959
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
960
+		} else {
961
+			EE_Error::add_error(
962
+				esc_html__('A Valid Transaction could not be initialized.', 'event_espresso'),
963
+				__FILE__,
964
+				__FUNCTION__,
965
+				__LINE__
966
+			);
967
+		}
968
+		return $transaction;
969
+	}
970
+
971
+
972
+	/**
973
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
974
+	 *
975
+	 * @access private
976
+	 * @return mixed EE_Transaction|NULL
977
+	 */
978
+	private function _initialize_transaction()
979
+	{
980
+		try {
981
+			// ensure cart totals have been calculated
982
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
983
+			// grab the cart grand total
984
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
985
+			// create new TXN
986
+			$transaction = EE_Transaction::new_instance(
987
+				array(
988
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
989
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
990
+					'TXN_paid'      => 0,
991
+					'STS_ID'        => EEM_Transaction::failed_status_code,
992
+				)
993
+			);
994
+			// save it so that we have an ID for other objects to use
995
+			$transaction->save();
996
+			// set cron job for following up on TXNs after their session has expired
997
+			EE_Cron_Tasks::schedule_expired_transaction_check(
998
+				EE_Registry::instance()->SSN->expiration() + 1,
999
+				$transaction->ID()
1000
+			);
1001
+			return $transaction;
1002
+		} catch (Exception $e) {
1003
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1004
+		}
1005
+		return null;
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * _get_registrations
1011
+	 *
1012
+	 * @access private
1013
+	 * @param EE_Transaction $transaction
1014
+	 * @return void
1015
+	 * @throws InvalidDataTypeException
1016
+	 * @throws InvalidEntityException
1017
+	 * @throws EE_Error
1018
+	 */
1019
+	private function _get_registrations(EE_Transaction $transaction)
1020
+	{
1021
+		// first step: grab the registrants  { : o
1022
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1023
+		$this->checkout->total_ticket_count = count($registrations);
1024
+		// verify registrations have been set
1025
+		if (empty($registrations)) {
1026
+			// if no cached registrations, then check the db
1027
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1028
+			// still nothing ? well as long as this isn't a revisit
1029
+			if (empty($registrations) && ! $this->checkout->revisit) {
1030
+				// generate new registrations from scratch
1031
+				$registrations = $this->_initialize_registrations($transaction);
1032
+			}
1033
+		}
1034
+		// sort by their original registration order
1035
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1036
+		// then loop thru the array
1037
+		foreach ($registrations as $registration) {
1038
+			// verify each registration
1039
+			if ($registration instanceof EE_Registration) {
1040
+				// we display all attendee info for the primary registrant
1041
+				if (
1042
+					$this->checkout->reg_url_link === $registration->reg_url_link()
1043
+					&& $registration->is_primary_registrant()
1044
+				) {
1045
+					$this->checkout->primary_revisit = true;
1046
+					break;
1047
+				}
1048
+				if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1049
+					// but hide info if it doesn't belong to you
1050
+					$transaction->clear_cache('Registration', $registration->ID());
1051
+					$this->checkout->total_ticket_count--;
1052
+				}
1053
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1054
+			}
1055
+		}
1056
+	}
1057
+
1058
+
1059
+	/**
1060
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1061
+	 *
1062
+	 * @access private
1063
+	 * @param EE_Transaction $transaction
1064
+	 * @return    array
1065
+	 * @throws InvalidDataTypeException
1066
+	 * @throws InvalidEntityException
1067
+	 * @throws EE_Error
1068
+	 */
1069
+	private function _initialize_registrations(EE_Transaction $transaction)
1070
+	{
1071
+		$att_nmbr = 0;
1072
+		$registrations = array();
1073
+		if ($transaction instanceof EE_Transaction) {
1074
+			/** @type EE_Registration_Processor $registration_processor */
1075
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1076
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1077
+			// now let's add the cart items to the $transaction
1078
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1079
+				// do the following for each ticket of this type they selected
1080
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1081
+					$att_nmbr++;
1082
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1083
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1084
+						'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1085
+						array(
1086
+							$transaction,
1087
+							$line_item,
1088
+							$att_nmbr,
1089
+							$this->checkout->total_ticket_count,
1090
+						)
1091
+					);
1092
+					// override capabilities for frontend registrations
1093
+					if (! is_admin()) {
1094
+						$CreateRegistrationCommand->setCapCheck(
1095
+							new PublicCapabilities('', 'create_new_registration')
1096
+						);
1097
+					}
1098
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1099
+					if (! $registration instanceof EE_Registration) {
1100
+						throw new InvalidEntityException($registration, 'EE_Registration');
1101
+					}
1102
+					$registrations[ $registration->ID() ] = $registration;
1103
+				}
1104
+			}
1105
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1106
+		}
1107
+		return $registrations;
1108
+	}
1109
+
1110
+
1111
+	/**
1112
+	 * sorts registrations by REG_count
1113
+	 *
1114
+	 * @access public
1115
+	 * @param EE_Registration $reg_A
1116
+	 * @param EE_Registration $reg_B
1117
+	 * @return int
1118
+	 */
1119
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1120
+	{
1121
+		// this shouldn't ever happen within the same TXN, but oh well
1122
+		if ($reg_A->count() === $reg_B->count()) {
1123
+			return 0;
1124
+		}
1125
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1126
+	}
1127
+
1128
+
1129
+	/**
1130
+	 *    _final_verifications
1131
+	 * just makes sure that everything is set up correctly before proceeding
1132
+	 *
1133
+	 * @access    private
1134
+	 * @return    bool
1135
+	 * @throws EE_Error
1136
+	 */
1137
+	private function _final_verifications()
1138
+	{
1139
+		// filter checkout
1140
+		$this->checkout = apply_filters(
1141
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1142
+			$this->checkout
1143
+		);
1144
+		// verify that current step is still set correctly
1145
+		if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1146
+			EE_Error::add_error(
1147
+				esc_html__(
1148
+					'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.',
1149
+					'event_espresso'
1150
+				),
1151
+				__FILE__,
1152
+				__FUNCTION__,
1153
+				__LINE__
1154
+			);
1155
+			return false;
1156
+		}
1157
+		// if returning to SPCO, then verify that primary registrant is set
1158
+		if (! empty($this->checkout->reg_url_link)) {
1159
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1160
+			if (! $valid_registrant instanceof EE_Registration) {
1161
+				EE_Error::add_error(
1162
+					esc_html__(
1163
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.',
1164
+						'event_espresso'
1165
+					),
1166
+					__FILE__,
1167
+					__FUNCTION__,
1168
+					__LINE__
1169
+				);
1170
+				return false;
1171
+			}
1172
+			$valid_registrant = null;
1173
+			foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1174
+				if (
1175
+					$registration instanceof EE_Registration
1176
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1177
+				) {
1178
+					$valid_registrant = $registration;
1179
+				}
1180
+			}
1181
+			if (! $valid_registrant instanceof EE_Registration) {
1182
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1183
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1184
+					// clear the session, mark the checkout as unverified, and try again
1185
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1186
+					EED_Single_Page_Checkout::$_initialized = false;
1187
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1188
+					$this->_initialize();
1189
+					EE_Error::reset_notices();
1190
+					return false;
1191
+				}
1192
+				EE_Error::add_error(
1193
+					esc_html__(
1194
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1195
+						'event_espresso'
1196
+					),
1197
+					__FILE__,
1198
+					__FUNCTION__,
1199
+					__LINE__
1200
+				);
1201
+				return false;
1202
+			}
1203
+		}
1204
+		// now that things have been kinda sufficiently verified,
1205
+		// let's add the checkout to the session so that it's available to other systems
1206
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1207
+		return true;
1208
+	}
1209
+
1210
+
1211
+	/**
1212
+	 *    _initialize_reg_steps
1213
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1214
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1215
+	 *
1216
+	 * @access    private
1217
+	 * @param bool $reinitializing
1218
+	 * @throws EE_Error
1219
+	 */
1220
+	private function _initialize_reg_steps($reinitializing = false)
1221
+	{
1222
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1223
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1224
+		foreach ($this->checkout->reg_steps as $reg_step) {
1225
+			if (! $reg_step->initialize_reg_step()) {
1226
+				// if not initialized then maybe this step is being removed...
1227
+				if (! $reinitializing && $reg_step->is_current_step()) {
1228
+					// if it was the current step, then we need to start over here
1229
+					$this->_initialize_reg_steps(true);
1230
+					return;
1231
+				}
1232
+				continue;
1233
+			}
1234
+			// add css and JS for current step
1235
+			$this->add_styles_and_scripts($reg_step);
1236
+			if ($reg_step->is_current_step()) {
1237
+				// the text that appears on the reg step form submit button
1238
+				$reg_step->set_submit_button_text();
1239
+			}
1240
+		}
1241
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1242
+		do_action(
1243
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1244
+			$this->checkout->current_step
1245
+		);
1246
+	}
1247
+
1248
+
1249
+	/**
1250
+	 * _check_form_submission
1251
+	 *
1252
+	 * @access private
1253
+	 * @return boolean
1254
+	 */
1255
+	private function _check_form_submission()
1256
+	{
1257
+		// does this request require the reg form to be generated ?
1258
+		if ($this->checkout->generate_reg_form) {
1259
+			// ever heard that song by Blue Rodeo ?
1260
+			try {
1261
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1262
+				// if not displaying a form, then check for form submission
1263
+				if (
1264
+					$this->checkout->process_form_submission
1265
+					&& $this->checkout->current_step->reg_form->was_submitted()
1266
+				) {
1267
+					// clear out any old data in case this step is being run again
1268
+					$this->checkout->current_step->set_valid_data(array());
1269
+					// capture submitted form data
1270
+					$this->checkout->current_step->reg_form->receive_form_submission(
1271
+						apply_filters(
1272
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1273
+							EE_Registry::instance()->REQ->params(),
1274
+							$this->checkout
1275
+						)
1276
+					);
1277
+					// validate submitted form data
1278
+					if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1279
+						// thou shall not pass !!!
1280
+						$this->checkout->continue_reg = false;
1281
+						// any form validation errors?
1282
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1283
+							EE_Error::add_error(
1284
+								$this->checkout->current_step->reg_form->submission_error_message(),
1285
+								__FILE__,
1286
+								__FUNCTION__,
1287
+								__LINE__
1288
+							);
1289
+						}
1290
+						// well not really... what will happen is
1291
+						// we'll just get redirected back to redo the current step
1292
+						$this->go_to_next_step();
1293
+						return false;
1294
+					}
1295
+				}
1296
+			} catch (EE_Error $e) {
1297
+				$e->get_error();
1298
+			}
1299
+		}
1300
+		return true;
1301
+	}
1302
+
1303
+
1304
+	/**
1305
+	 * _process_action
1306
+	 *
1307
+	 * @access private
1308
+	 * @return void
1309
+	 * @throws EE_Error
1310
+	 */
1311
+	private function _process_form_action()
1312
+	{
1313
+		// what cha wanna do?
1314
+		switch ($this->checkout->action) {
1315
+			// AJAX next step reg form
1316
+			case 'display_spco_reg_step':
1317
+				$this->checkout->redirect = false;
1318
+				if (EE_Registry::instance()->REQ->ajax) {
1319
+					$this->checkout->json_response->set_reg_step_html(
1320
+						$this->checkout->current_step->display_reg_form()
1321
+					);
1322
+				}
1323
+				break;
1324
+			default:
1325
+				// meh... do one of those other steps first
1326
+				if (
1327
+					! empty($this->checkout->action)
1328
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1329
+				) {
1330
+					// dynamically creates hook point like:
1331
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1332
+					do_action(
1333
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1334
+						$this->checkout->current_step
1335
+					);
1336
+					$process_reg_step = apply_filters(
1337
+						"AHEE__Single_Page_Checkout__process_reg_step__{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1338
+						true,
1339
+						$this->checkout->current_step,
1340
+						$this
1341
+					);
1342
+					// call action on current step
1343
+					if ($process_reg_step && call_user_func([$this->checkout->current_step, $this->checkout->action])) {
1344
+						// good registrant, you get to proceed
1345
+						if (
1346
+							$this->checkout->current_step->success_message() !== ''
1347
+							&& apply_filters(
1348
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1349
+								false
1350
+							)
1351
+						) {
1352
+							EE_Error::add_success(
1353
+								$this->checkout->current_step->success_message()
1354
+								. '<br />' . $this->checkout->next_step->_instructions()
1355
+							);
1356
+						}
1357
+						// pack it up, pack it in...
1358
+						$this->_setup_redirect();
1359
+					}
1360
+					// dynamically creates hook point like:
1361
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1362
+					do_action(
1363
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1364
+						$this->checkout->current_step
1365
+					);
1366
+				} else {
1367
+					EE_Error::add_error(
1368
+						sprintf(
1369
+							esc_html__(
1370
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1371
+								'event_espresso'
1372
+							),
1373
+							$this->checkout->action,
1374
+							$this->checkout->current_step->name()
1375
+						),
1376
+						__FILE__,
1377
+						__FUNCTION__,
1378
+						__LINE__
1379
+					);
1380
+				}
1381
+			// end default
1382
+		}
1383
+		// store our progress so far
1384
+		$this->checkout->stash_transaction_and_checkout();
1385
+		// advance to the next step! If you pass GO, collect $200
1386
+		$this->go_to_next_step();
1387
+	}
1388
+
1389
+
1390
+	/**
1391
+	 * @param EED_Single_Page_Checkout|EE_SPCO_Reg_Step $target
1392
+	 * @param object $target an object with the method `translate_js_strings` and `enqueue_styles_and_scripts`.
1393
+	 * @return        void
1394
+	 */
1395
+	public function add_styles_and_scripts($target)
1396
+	{
1397
+		// i18n
1398
+		$target->translate_js_strings();
1399
+		if ($this->checkout->admin_request) {
1400
+			add_action('admin_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1401
+		} else {
1402
+			add_action('wp_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1403
+		}
1404
+	}
1405
+
1406
+	/**
1407
+	 *        translate_js_strings
1408
+	 *
1409
+	 * @access        public
1410
+	 * @return        void
1411
+	 */
1412
+	public function translate_js_strings()
1413
+	{
1414
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1415
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1416
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
1417
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1418
+			'event_espresso'
1419
+		);
1420
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = esc_html__(
1421
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1422
+			'event_espresso'
1423
+		);
1424
+		EE_Registry::$i18n_js_strings['validation_error'] = esc_html__(
1425
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1426
+			'event_espresso'
1427
+		);
1428
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
1429
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1430
+			'event_espresso'
1431
+		);
1432
+		EE_Registry::$i18n_js_strings['reg_step_error'] = esc_html__(
1433
+			'This registration step could not be completed. Please refresh the page and try again.',
1434
+			'event_espresso'
1435
+		);
1436
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = esc_html__(
1437
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1438
+			'event_espresso'
1439
+		);
1440
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1441
+			esc_html__(
1442
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1443
+				'event_espresso'
1444
+			),
1445
+			'<br/>',
1446
+			'<br/>'
1447
+		);
1448
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1449
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1450
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1451
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1452
+		EE_Registry::$i18n_js_strings['timer_years'] = esc_html__('years', 'event_espresso');
1453
+		EE_Registry::$i18n_js_strings['timer_months'] = esc_html__('months', 'event_espresso');
1454
+		EE_Registry::$i18n_js_strings['timer_weeks'] = esc_html__('weeks', 'event_espresso');
1455
+		EE_Registry::$i18n_js_strings['timer_days'] = esc_html__('days', 'event_espresso');
1456
+		EE_Registry::$i18n_js_strings['timer_hours'] = esc_html__('hours', 'event_espresso');
1457
+		EE_Registry::$i18n_js_strings['timer_minutes'] = esc_html__('minutes', 'event_espresso');
1458
+		EE_Registry::$i18n_js_strings['timer_seconds'] = esc_html__('seconds', 'event_espresso');
1459
+		EE_Registry::$i18n_js_strings['timer_year'] = esc_html__('year', 'event_espresso');
1460
+		EE_Registry::$i18n_js_strings['timer_month'] = esc_html__('month', 'event_espresso');
1461
+		EE_Registry::$i18n_js_strings['timer_week'] = esc_html__('week', 'event_espresso');
1462
+		EE_Registry::$i18n_js_strings['timer_day'] = esc_html__('day', 'event_espresso');
1463
+		EE_Registry::$i18n_js_strings['timer_hour'] = esc_html__('hour', 'event_espresso');
1464
+		EE_Registry::$i18n_js_strings['timer_minute'] = esc_html__('minute', 'event_espresso');
1465
+		EE_Registry::$i18n_js_strings['timer_second'] = esc_html__('second', 'event_espresso');
1466
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
1467
+		);
1468
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1469
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1470
+			true
1471
+		);
1472
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1473
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1474
+		);
1475
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1476
+			'M d, Y H:i:s',
1477
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1478
+		);
1479
+	}
1480
+
1481
+
1482
+	/**
1483
+	 *    enqueue_styles_and_scripts
1484
+	 *
1485
+	 * @access        public
1486
+	 * @return        void
1487
+	 * @throws EE_Error
1488
+	 */
1489
+	public function enqueue_styles_and_scripts()
1490
+	{
1491
+		// load css
1492
+		wp_register_style(
1493
+			'single_page_checkout',
1494
+			SPCO_CSS_URL . 'single_page_checkout.css',
1495
+			array('espresso_default'),
1496
+			EVENT_ESPRESSO_VERSION
1497
+		);
1498
+		wp_enqueue_style('single_page_checkout');
1499
+		// load JS
1500
+		wp_register_script(
1501
+			'jquery_plugin',
1502
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1503
+			array('jquery'),
1504
+			'1.0.1',
1505
+			true
1506
+		);
1507
+		wp_register_script(
1508
+			'jquery_countdown',
1509
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1510
+			array('jquery_plugin'),
1511
+			'2.1.0',
1512
+			true
1513
+		);
1514
+		wp_register_script(
1515
+			'single_page_checkout',
1516
+			SPCO_JS_URL . 'single_page_checkout.js',
1517
+			array('espresso_core', 'underscore', 'ee_form_section_validation'),
1518
+			EVENT_ESPRESSO_VERSION,
1519
+			true
1520
+		);
1521
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1522
+			$this->checkout->registration_form->enqueue_js();
1523
+		}
1524
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1525
+			$this->checkout->current_step->reg_form->enqueue_js();
1526
+		}
1527
+		wp_enqueue_script('single_page_checkout');
1528
+		if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) {
1529
+			wp_enqueue_script('jquery_countdown');
1530
+		}
1531
+		/**
1532
+		 * global action hook for enqueueing styles and scripts with
1533
+		 * spco calls.
1534
+		 */
1535
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1536
+		/**
1537
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1538
+		 * The hook will end up being something like:
1539
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1540
+		 */
1541
+		do_action(
1542
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1543
+			$this
1544
+		);
1545
+	}
1546
+
1547
+
1548
+	/**
1549
+	 *    display the Registration Single Page Checkout Form
1550
+	 *
1551
+	 * @access    private
1552
+	 * @return    void
1553
+	 * @throws EE_Error
1554
+	 */
1555
+	private function _display_spco_reg_form()
1556
+	{
1557
+		// if registering via the admin, just display the reg form for the current step
1558
+		if ($this->checkout->admin_request) {
1559
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1560
+		} else {
1561
+			// add powered by EE msg
1562
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1563
+			$empty_cart = count($this->checkout->transaction
1564
+									->registrations($this->checkout->reg_cache_where_params)) < 1;
1565
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1566
+			$cookies_not_set_msg = '';
1567
+			if ($empty_cart) {
1568
+				$cookies_not_set_msg = apply_filters(
1569
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1570
+					sprintf(
1571
+						esc_html__(
1572
+							'%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1573
+							'event_espresso'
1574
+						),
1575
+						'<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1576
+						'</div>',
1577
+						'<h6 class="important-notice">',
1578
+						'</h6>',
1579
+						'<p>',
1580
+						'</p>',
1581
+						'<br />',
1582
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank" rel="noopener noreferrer">',
1583
+						'</a>'
1584
+					)
1585
+				);
1586
+			}
1587
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1588
+				array(
1589
+					'name'            => 'single-page-checkout',
1590
+					'html_id'         => 'ee-single-page-checkout-dv',
1591
+					'layout_strategy' =>
1592
+						new EE_Template_Layout(
1593
+							array(
1594
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1595
+								'template_args'        => array(
1596
+									'empty_cart'              => $empty_cart,
1597
+									'revisit'                 => $this->checkout->revisit,
1598
+									'reg_steps'               => $this->checkout->reg_steps,
1599
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1600
+										? $this->checkout->next_step->slug()
1601
+										: '',
1602
+									'empty_msg'               => apply_filters(
1603
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1604
+										sprintf(
1605
+											esc_html__(
1606
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1607
+												'event_espresso'
1608
+											),
1609
+											'<a href="'
1610
+											. get_post_type_archive_link('espresso_events')
1611
+											. '" title="',
1612
+											'">',
1613
+											'</a>'
1614
+										)
1615
+									),
1616
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1617
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1618
+									'session_expiration'      => gmdate(
1619
+										'M d, Y H:i:s',
1620
+										EE_Registry::instance()->SSN->expiration()
1621
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1622
+									),
1623
+								),
1624
+							)
1625
+						),
1626
+				)
1627
+			);
1628
+			// load template and add to output sent that gets filtered into the_content()
1629
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1630
+		}
1631
+	}
1632
+
1633
+
1634
+	/**
1635
+	 *    add_extra_finalize_registration_inputs
1636
+	 *
1637
+	 * @access    public
1638
+	 * @param $next_step
1639
+	 * @internal  param string $label
1640
+	 * @return void
1641
+	 */
1642
+	public function add_extra_finalize_registration_inputs($next_step)
1643
+	{
1644
+		if ($next_step === 'finalize_registration') {
1645
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1646
+		}
1647
+	}
1648
+
1649
+
1650
+	/**
1651
+	 *    display_registration_footer
1652
+	 *
1653
+	 * @access    public
1654
+	 * @return    string
1655
+	 */
1656
+	public static function display_registration_footer()
1657
+	{
1658
+		if (
1659
+			apply_filters(
1660
+				'FHEE__EE_Front__Controller__show_reg_footer',
1661
+				EE_Registry::instance()->CFG->admin->show_reg_footer
1662
+			)
1663
+		) {
1664
+			add_filter(
1665
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1666
+				function ($url) {
1667
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1668
+				}
1669
+			);
1670
+			echo apply_filters(
1671
+				'FHEE__EE_Front_Controller__display_registration_footer',
1672
+				\EEH_Template::powered_by_event_espresso(
1673
+					'',
1674
+					'espresso-registration-footer-dv',
1675
+					array('utm_content' => 'registration_checkout')
1676
+				)
1677
+			);
1678
+		}
1679
+		return '';
1680
+	}
1681
+
1682
+
1683
+	/**
1684
+	 *    unlock_transaction
1685
+	 *
1686
+	 * @access    public
1687
+	 * @return    void
1688
+	 * @throws EE_Error
1689
+	 */
1690
+	public function unlock_transaction()
1691
+	{
1692
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1693
+			$this->checkout->transaction->unlock();
1694
+		}
1695
+	}
1696
+
1697
+
1698
+	/**
1699
+	 *        _setup_redirect
1700
+	 *
1701
+	 * @access    private
1702
+	 * @return void
1703
+	 */
1704
+	private function _setup_redirect()
1705
+	{
1706
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1707
+			$this->checkout->redirect = true;
1708
+			if (empty($this->checkout->redirect_url)) {
1709
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1710
+			}
1711
+			$this->checkout->redirect_url = apply_filters(
1712
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1713
+				$this->checkout->redirect_url,
1714
+				$this->checkout
1715
+			);
1716
+		}
1717
+	}
1718
+
1719
+
1720
+	/**
1721
+	 *   handle ajax message responses and redirects
1722
+	 *
1723
+	 * @access public
1724
+	 * @return void
1725
+	 * @throws EE_Error
1726
+	 */
1727
+	public function go_to_next_step()
1728
+	{
1729
+		if (EE_Registry::instance()->REQ->ajax) {
1730
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1731
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1732
+		}
1733
+		$this->unlock_transaction();
1734
+		// just return for these conditions
1735
+		if (
1736
+			$this->checkout->admin_request
1737
+			|| $this->checkout->action === 'redirect_form'
1738
+			|| $this->checkout->action === 'update_checkout'
1739
+		) {
1740
+			return;
1741
+		}
1742
+		// AJAX response
1743
+		$this->_handle_json_response();
1744
+		// redirect to next step or the Thank You page
1745
+		$this->_handle_html_redirects();
1746
+		// hmmm... must be something wrong, so let's just display the form again !
1747
+		$this->_display_spco_reg_form();
1748
+	}
1749
+
1750
+
1751
+	/**
1752
+	 *   _handle_json_response
1753
+	 *
1754
+	 * @access protected
1755
+	 * @return void
1756
+	 */
1757
+	protected function _handle_json_response()
1758
+	{
1759
+		// if this is an ajax request
1760
+		if (EE_Registry::instance()->REQ->ajax) {
1761
+			$this->checkout->json_response->set_registration_time_limit(
1762
+				$this->checkout->get_registration_time_limit()
1763
+			);
1764
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1765
+			// just send the ajax (
1766
+			$json_response = apply_filters(
1767
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1768
+				$this->checkout->json_response
1769
+			);
1770
+			echo $json_response;
1771
+			exit();
1772
+		}
1773
+	}
1774
+
1775
+
1776
+	/**
1777
+	 *   _handle_redirects
1778
+	 *
1779
+	 * @access protected
1780
+	 * @return void
1781
+	 */
1782
+	protected function _handle_html_redirects()
1783
+	{
1784
+		// going somewhere ?
1785
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1786
+			// store notices in a transient
1787
+			EE_Error::get_notices(false, true, true);
1788
+			wp_safe_redirect($this->checkout->redirect_url);
1789
+			exit();
1790
+		}
1791
+	}
1792
+
1793
+
1794
+	/**
1795
+	 *   set_checkout_anchor
1796
+	 *
1797
+	 * @access public
1798
+	 * @return void
1799
+	 */
1800
+	public function set_checkout_anchor()
1801
+	{
1802
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1803
+	}
1804
+
1805
+	/**
1806
+	 *    getRegistrationExpirationNotice
1807
+	 *
1808
+	 * @since     4.9.59.p
1809
+	 * @access    public
1810
+	 * @return    string
1811
+	 */
1812
+	public static function getRegistrationExpirationNotice()
1813
+	{
1814
+		return sprintf(
1815
+			esc_html__(
1816
+				'%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1817
+				'event_espresso'
1818
+			),
1819
+			'<h4 class="important-notice">',
1820
+			'</h4>',
1821
+			'<br />',
1822
+			'<p>',
1823
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1824
+			'">',
1825
+			'</a>',
1826
+			'</p>'
1827
+		);
1828
+	}
1829 1829
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
     public static function set_hooks_admin()
101 101
     {
102 102
         EED_Single_Page_Checkout::set_definitions();
103
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
103
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
104 104
             return;
105 105
         }
106 106
         // going to start an output buffer in case anything gets accidentally output
@@ -206,14 +206,14 @@  discard block
 block discarded – undo
206 206
         }
207 207
         define(
208 208
             'SPCO_BASE_PATH',
209
-            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
209
+            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/').'/'
210 210
         );
211
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css/');
212
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img/');
213
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js/');
214
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc/');
215
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps/');
216
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates/');
211
+        define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css/');
212
+        define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img/');
213
+        define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js/');
214
+        define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc/');
215
+        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps/');
216
+        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates/');
217 217
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
218 218
         EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
219 219
         );
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
             // we need a
246 246
             if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
247 247
                 // copy over to the reg_steps_array
248
-                EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
248
+                EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
249 249
                 // register custom key route for each reg step
250 250
                 // ie: step=>"slug" - this is the entire reason we load the reg steps array now
251 251
                 EE_Config::register_route(
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
                 // add AJAX or other hooks
258 258
                 if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
259 259
                     // setup autoloaders if necessary
260
-                    if (! class_exists($reg_step['class_name'])) {
260
+                    if ( ! class_exists($reg_step['class_name'])) {
261 261
                         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
262 262
                             $reg_step['file_path'],
263 263
                             true
@@ -285,19 +285,19 @@  discard block
 block discarded – undo
285 285
         if (empty($reg_steps)) {
286 286
             $reg_steps = array(
287 287
                 10  => array(
288
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
288
+                    'file_path'  => SPCO_REG_STEPS_PATH.'attendee_information',
289 289
                     'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
290 290
                     'slug'       => 'attendee_information',
291 291
                     'has_hooks'  => false,
292 292
                 ),
293 293
                 30  => array(
294
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
294
+                    'file_path'  => SPCO_REG_STEPS_PATH.'payment_options',
295 295
                     'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
296 296
                     'slug'       => 'payment_options',
297 297
                     'has_hooks'  => true,
298 298
                 ),
299 299
                 999 => array(
300
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
300
+                    'file_path'  => SPCO_REG_STEPS_PATH.'finalize_registration',
301 301
                     'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
302 302
                     'slug'       => 'finalize_registration',
303 303
                     'has_hooks'  => false,
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
                 $this->checkout
452 452
             );
453 453
             // load the reg steps array
454
-            if (! $this->_load_and_instantiate_reg_steps()) {
454
+            if ( ! $this->_load_and_instantiate_reg_steps()) {
455 455
                 EED_Single_Page_Checkout::$_initialized = true;
456 456
                 return;
457 457
             }
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
             // and the next step
461 461
             $this->checkout->set_next_step();
462 462
             // verify that everything has been setup correctly
463
-            if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
463
+            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
464 464
                 EED_Single_Page_Checkout::$_initialized = true;
465 465
                 return;
466 466
             }
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
             // DEBUG LOG
476 476
             // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
477 477
             // get reg form
478
-            if (! $this->_check_form_submission()) {
478
+            if ( ! $this->_check_form_submission()) {
479 479
                 EED_Single_Page_Checkout::$_initialized = true;
480 480
                 return;
481 481
             }
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
      */
507 507
     private function _verify_session()
508 508
     {
509
-        if (! EE_Registry::instance()->SSN instanceof EE_Session) {
509
+        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
510 510
             throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso'));
511 511
         }
512 512
         $clear_session_requested = filter_var(
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
             // EE_Registry::instance()->SSN->reset_cart();
526 526
             // EE_Registry::instance()->SSN->reset_checkout();
527 527
             // EE_Registry::instance()->SSN->reset_transaction();
528
-            if (! $clear_session_requested) {
528
+            if ( ! $clear_session_requested) {
529 529
                 EE_Error::add_attention(
530 530
                     EE_Registry::$i18n_js_strings['registration_expiration_notice'],
531 531
                     __FILE__,
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
         /** @type EE_Checkout $checkout */
553 553
         $checkout = EE_Registry::instance()->SSN->checkout();
554 554
         // verify
555
-        if (! $checkout instanceof EE_Checkout) {
555
+        if ( ! $checkout instanceof EE_Checkout) {
556 556
             // instantiate EE_Checkout object for handling the properties of the current checkout process
557 557
             $checkout = EE_Registry::instance()->load_file(
558 558
                 SPCO_INC_PATH,
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
         }
571 571
         $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
572 572
         // verify again
573
-        if (! $checkout instanceof EE_Checkout) {
573
+        if ( ! $checkout instanceof EE_Checkout) {
574 574
             throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso'));
575 575
         }
576 576
         // reset anything that needs a clean slate for each request
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
      */
643 643
     protected function _display_request_vars()
644 644
     {
645
-        if (! WP_DEBUG) {
645
+        if ( ! WP_DEBUG) {
646 646
             return;
647 647
         }
648 648
         EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
         ) {
721 721
             // if not, then loop through raw reg steps array
722 722
             foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
723
-                if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
723
+                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
724 724
                     return false;
725 725
                 }
726 726
             }
@@ -853,12 +853,12 @@  discard block
 block discarded – undo
853 853
     private function _verify_transaction_and_get_registrations()
854 854
     {
855 855
         // was there already a valid transaction in the checkout from the session ?
856
-        if (! $this->checkout->transaction instanceof EE_Transaction) {
856
+        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
857 857
             // get transaction from db or session
858 858
             $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
859 859
                 ? $this->_get_transaction_and_cart_for_previous_visit()
860 860
                 : $this->_get_cart_for_current_session_and_setup_new_transaction();
861
-            if (! $this->checkout->transaction instanceof EE_Transaction) {
861
+            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
862 862
                 EE_Error::add_error(
863 863
                     esc_html__(
864 864
                         'Your Registration and Transaction information could not be retrieved from the db.',
@@ -1090,16 +1090,16 @@  discard block
 block discarded – undo
1090 1090
                         )
1091 1091
                     );
1092 1092
                     // override capabilities for frontend registrations
1093
-                    if (! is_admin()) {
1093
+                    if ( ! is_admin()) {
1094 1094
                         $CreateRegistrationCommand->setCapCheck(
1095 1095
                             new PublicCapabilities('', 'create_new_registration')
1096 1096
                         );
1097 1097
                     }
1098 1098
                     $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1099
-                    if (! $registration instanceof EE_Registration) {
1099
+                    if ( ! $registration instanceof EE_Registration) {
1100 1100
                         throw new InvalidEntityException($registration, 'EE_Registration');
1101 1101
                     }
1102
-                    $registrations[ $registration->ID() ] = $registration;
1102
+                    $registrations[$registration->ID()] = $registration;
1103 1103
                 }
1104 1104
             }
1105 1105
             $registration_processor->fix_reg_final_price_rounding_issue($transaction);
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
             $this->checkout
1143 1143
         );
1144 1144
         // verify that current step is still set correctly
1145
-        if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1145
+        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1146 1146
             EE_Error::add_error(
1147 1147
                 esc_html__(
1148 1148
                     'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.',
@@ -1155,9 +1155,9 @@  discard block
 block discarded – undo
1155 1155
             return false;
1156 1156
         }
1157 1157
         // if returning to SPCO, then verify that primary registrant is set
1158
-        if (! empty($this->checkout->reg_url_link)) {
1158
+        if ( ! empty($this->checkout->reg_url_link)) {
1159 1159
             $valid_registrant = $this->checkout->transaction->primary_registration();
1160
-            if (! $valid_registrant instanceof EE_Registration) {
1160
+            if ( ! $valid_registrant instanceof EE_Registration) {
1161 1161
                 EE_Error::add_error(
1162 1162
                     esc_html__(
1163 1163
                         'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.',
@@ -1178,7 +1178,7 @@  discard block
 block discarded – undo
1178 1178
                     $valid_registrant = $registration;
1179 1179
                 }
1180 1180
             }
1181
-            if (! $valid_registrant instanceof EE_Registration) {
1181
+            if ( ! $valid_registrant instanceof EE_Registration) {
1182 1182
                 // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1183 1183
                 if (EED_Single_Page_Checkout::$_checkout_verified) {
1184 1184
                     // clear the session, mark the checkout as unverified, and try again
@@ -1222,9 +1222,9 @@  discard block
 block discarded – undo
1222 1222
         $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1223 1223
         // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1224 1224
         foreach ($this->checkout->reg_steps as $reg_step) {
1225
-            if (! $reg_step->initialize_reg_step()) {
1225
+            if ( ! $reg_step->initialize_reg_step()) {
1226 1226
                 // if not initialized then maybe this step is being removed...
1227
-                if (! $reinitializing && $reg_step->is_current_step()) {
1227
+                if ( ! $reinitializing && $reg_step->is_current_step()) {
1228 1228
                     // if it was the current step, then we need to start over here
1229 1229
                     $this->_initialize_reg_steps(true);
1230 1230
                     return;
@@ -1275,7 +1275,7 @@  discard block
 block discarded – undo
1275 1275
                         )
1276 1276
                     );
1277 1277
                     // validate submitted form data
1278
-                    if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1278
+                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1279 1279
                         // thou shall not pass !!!
1280 1280
                         $this->checkout->continue_reg = false;
1281 1281
                         // any form validation errors?
@@ -1351,7 +1351,7 @@  discard block
 block discarded – undo
1351 1351
                         ) {
1352 1352
                             EE_Error::add_success(
1353 1353
                                 $this->checkout->current_step->success_message()
1354
-                                . '<br />' . $this->checkout->next_step->_instructions()
1354
+                                . '<br />'.$this->checkout->next_step->_instructions()
1355 1355
                             );
1356 1356
                         }
1357 1357
                         // pack it up, pack it in...
@@ -1491,7 +1491,7 @@  discard block
 block discarded – undo
1491 1491
         // load css
1492 1492
         wp_register_style(
1493 1493
             'single_page_checkout',
1494
-            SPCO_CSS_URL . 'single_page_checkout.css',
1494
+            SPCO_CSS_URL.'single_page_checkout.css',
1495 1495
             array('espresso_default'),
1496 1496
             EVENT_ESPRESSO_VERSION
1497 1497
         );
@@ -1499,21 +1499,21 @@  discard block
 block discarded – undo
1499 1499
         // load JS
1500 1500
         wp_register_script(
1501 1501
             'jquery_plugin',
1502
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1502
+            EE_THIRD_PARTY_URL.'jquery	.plugin.min.js',
1503 1503
             array('jquery'),
1504 1504
             '1.0.1',
1505 1505
             true
1506 1506
         );
1507 1507
         wp_register_script(
1508 1508
             'jquery_countdown',
1509
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1509
+            EE_THIRD_PARTY_URL.'jquery	.countdown.min.js',
1510 1510
             array('jquery_plugin'),
1511 1511
             '2.1.0',
1512 1512
             true
1513 1513
         );
1514 1514
         wp_register_script(
1515 1515
             'single_page_checkout',
1516
-            SPCO_JS_URL . 'single_page_checkout.js',
1516
+            SPCO_JS_URL.'single_page_checkout.js',
1517 1517
             array('espresso_core', 'underscore', 'ee_form_section_validation'),
1518 1518
             EVENT_ESPRESSO_VERSION,
1519 1519
             true
@@ -1539,7 +1539,7 @@  discard block
 block discarded – undo
1539 1539
          *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1540 1540
          */
1541 1541
         do_action(
1542
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1542
+            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(),
1543 1543
             $this
1544 1544
         );
1545 1545
     }
@@ -1591,7 +1591,7 @@  discard block
 block discarded – undo
1591 1591
                     'layout_strategy' =>
1592 1592
                         new EE_Template_Layout(
1593 1593
                             array(
1594
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1594
+                                'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php',
1595 1595
                                 'template_args'        => array(
1596 1596
                                     'empty_cart'              => $empty_cart,
1597 1597
                                     'revisit'                 => $this->checkout->revisit,
@@ -1663,7 +1663,7 @@  discard block
 block discarded – undo
1663 1663
         ) {
1664 1664
             add_filter(
1665 1665
                 'FHEE__EEH_Template__powered_by_event_espresso__url',
1666
-                function ($url) {
1666
+                function($url) {
1667 1667
                     return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1668 1668
                 }
1669 1669
             );
@@ -1820,7 +1820,7 @@  discard block
 block discarded – undo
1820 1820
             '</h4>',
1821 1821
             '<br />',
1822 1822
             '<p>',
1823
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1823
+            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1824 1824
             '">',
1825 1825
             '</a>',
1826 1826
             '</p>'
Please login to merge, or discard this patch.
core/EE_Cart.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
      * @access  public
261 261
      * @param EE_Ticket $ticket
262 262
      * @param int       $qty
263
-     * @return TRUE on success, FALSE on fail
263
+     * @return boolean on success, FALSE on fail
264 264
      * @throws \EE_Error
265 265
      */
266 266
     public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
      * @save   cart to session
386 386
      * @access public
387 387
      * @param bool $apply_taxes
388
-     * @return TRUE on success, FALSE on fail
388
+     * @return boolean on success, FALSE on fail
389 389
      * @throws \EE_Error
390 390
      */
391 391
     public function save_cart($apply_taxes = true)
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 
420 420
 
421 421
     /**
422
-     * @return array
422
+     * @return string[]
423 423
      */
424 424
     public function __sleep()
425 425
     {
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
             self::$_instance = new self($grand_total, $session);
66 66
         }
67 67
         // or maybe retrieve an existing one ?
68
-        if (! self::$_instance instanceof EE_Cart) {
68
+        if ( ! self::$_instance instanceof EE_Cart) {
69 69
             // try getting the cart out of the session
70 70
             $saved_cart = $session instanceof EE_Session ? $session->cart() : null;
71 71
             self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
72 72
             unset($saved_cart);
73 73
         }
74 74
         // verify that cart is ok and grand total line item exists
75
-        if (! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
75
+        if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
76 76
             self::$_instance = new self($grand_total, $session);
77 77
         }
78 78
         self::$_instance->get_grand_total();
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      */
125 125
     public function session()
126 126
     {
127
-        if (! $this->_session instanceof EE_Session) {
127
+        if ( ! $this->_session instanceof EE_Session) {
128 128
             $this->set_session();
129 129
         }
130 130
         return $this->_session;
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 
393 393
     public function __wakeup()
394 394
     {
395
-        if (! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
395
+        if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
396 396
             // $this->_grand_total is actually just an ID, so use it to get the object from the db
397 397
             $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
398 398
         }
Please login to merge, or discard this patch.
Indentation   +393 added lines, -393 removed lines patch added patch discarded remove patch
@@ -17,397 +17,397 @@
 block discarded – undo
17 17
 class EE_Cart implements ResettableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * instance of the EE_Cart object
22
-     *
23
-     * @access    private
24
-     * @var EE_Cart $_instance
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * instance of the EE_Session object
30
-     *
31
-     * @access    protected
32
-     * @var EE_Session $_session
33
-     */
34
-    protected $_session;
35
-
36
-    /**
37
-     * The total Line item which comprises all the children line-item subtotals,
38
-     * which in turn each have their line items.
39
-     * Typically, the line item structure will look like:
40
-     * grand total
41
-     * -tickets-sub-total
42
-     * --ticket1
43
-     * --ticket2
44
-     * --...
45
-     * -taxes-sub-total
46
-     * --tax1
47
-     * --tax2
48
-     *
49
-     * @var EE_Line_Item
50
-     */
51
-    private $_grand_total;
52
-
53
-
54
-    /**
55
-     * @singleton method used to instantiate class object
56
-     * @access    public
57
-     * @param EE_Line_Item $grand_total
58
-     * @param EE_Session   $session
59
-     * @return \EE_Cart
60
-     * @throws \EE_Error
61
-     */
62
-    public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
63
-    {
64
-        if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
65
-            self::$_instance = new self($grand_total, $session);
66
-        }
67
-        // or maybe retrieve an existing one ?
68
-        if (! self::$_instance instanceof EE_Cart) {
69
-            // try getting the cart out of the session
70
-            $saved_cart = $session instanceof EE_Session ? $session->cart() : null;
71
-            self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
72
-            unset($saved_cart);
73
-        }
74
-        // verify that cart is ok and grand total line item exists
75
-        if (! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
76
-            self::$_instance = new self($grand_total, $session);
77
-        }
78
-        self::$_instance->get_grand_total();
79
-        // once everything is all said and done, save the cart to the EE_Session
80
-        add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
81
-        return self::$_instance;
82
-    }
83
-
84
-
85
-    /**
86
-     * private constructor to prevent direct creation
87
-     *
88
-     * @Constructor
89
-     * @access private
90
-     * @param EE_Line_Item $grand_total
91
-     * @param EE_Session   $session
92
-     */
93
-    private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
94
-    {
95
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
96
-        $this->set_session($session);
97
-        if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
98
-            $this->set_grand_total_line_item($grand_total);
99
-        }
100
-    }
101
-
102
-
103
-    /**
104
-     * Resets the cart completely (whereas empty_cart
105
-     *
106
-     * @param EE_Line_Item $grand_total
107
-     * @param EE_Session   $session
108
-     * @return EE_Cart
109
-     * @throws \EE_Error
110
-     */
111
-    public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
112
-    {
113
-        remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
114
-        if ($session instanceof EE_Session) {
115
-            $session->reset_cart();
116
-        }
117
-        self::$_instance = null;
118
-        return self::instance($grand_total, $session);
119
-    }
120
-
121
-
122
-    /**
123
-     * @return \EE_Session
124
-     */
125
-    public function session()
126
-    {
127
-        if (! $this->_session instanceof EE_Session) {
128
-            $this->set_session();
129
-        }
130
-        return $this->_session;
131
-    }
132
-
133
-
134
-    /**
135
-     * @param EE_Session $session
136
-     */
137
-    public function set_session(EE_Session $session = null)
138
-    {
139
-        $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
140
-    }
141
-
142
-
143
-    /**
144
-     * Sets the cart to match the line item. Especially handy for loading an old cart where you
145
-     *  know the grand total line item on it
146
-     *
147
-     * @param EE_Line_Item $line_item
148
-     */
149
-    public function set_grand_total_line_item(EE_Line_Item $line_item)
150
-    {
151
-        $this->_grand_total = $line_item;
152
-    }
153
-
154
-
155
-    /**
156
-     * get_cart_from_reg_url_link
157
-     *
158
-     * @access public
159
-     * @param EE_Transaction $transaction
160
-     * @param EE_Session     $session
161
-     * @return \EE_Cart
162
-     * @throws \EE_Error
163
-     */
164
-    public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
165
-    {
166
-        $grand_total = $transaction->total_line_item();
167
-        $grand_total->get_items();
168
-        $grand_total->tax_descendants();
169
-        return EE_Cart::instance($grand_total, $session);
170
-    }
171
-
172
-
173
-    /**
174
-     * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
175
-     *
176
-     * @return EE_Line_Item
177
-     * @throws \EE_Error
178
-     */
179
-    private function _create_grand_total()
180
-    {
181
-        $this->_grand_total = EEH_Line_Item::create_total_line_item();
182
-        return $this->_grand_total;
183
-    }
184
-
185
-
186
-    /**
187
-     * Gets all the line items of object type Ticket
188
-     *
189
-     * @access public
190
-     * @return \EE_Line_Item[]
191
-     */
192
-    public function get_tickets()
193
-    {
194
-        if ($this->_grand_total === null) {
195
-            return array();
196
-        }
197
-        return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
198
-    }
199
-
200
-
201
-    /**
202
-     * returns the total quantity of tickets in the cart
203
-     *
204
-     * @access public
205
-     * @return int
206
-     * @throws \EE_Error
207
-     */
208
-    public function all_ticket_quantity_count()
209
-    {
210
-        $tickets = $this->get_tickets();
211
-        if (empty($tickets)) {
212
-            return 0;
213
-        }
214
-        $count = 0;
215
-        foreach ($tickets as $ticket) {
216
-            $count += $ticket->get('LIN_quantity');
217
-        }
218
-        return $count;
219
-    }
220
-
221
-
222
-    /**
223
-     * Gets all the tax line items
224
-     *
225
-     * @return \EE_Line_Item[]
226
-     * @throws \EE_Error
227
-     */
228
-    public function get_taxes()
229
-    {
230
-        return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
231
-    }
232
-
233
-
234
-    /**
235
-     * Gets the total line item (which is a parent of all other line items) on this cart
236
-     *
237
-     * @return EE_Line_Item
238
-     * @throws \EE_Error
239
-     */
240
-    public function get_grand_total()
241
-    {
242
-        return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
243
-    }
244
-
245
-
246
-    /**
247
-     * @process items for adding to cart
248
-     * @access  public
249
-     * @param EE_Ticket $ticket
250
-     * @param int       $qty
251
-     * @return TRUE on success, FALSE on fail
252
-     * @throws \EE_Error
253
-     */
254
-    public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
255
-    {
256
-        EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
257
-        return $this->save_cart() ? true : false;
258
-    }
259
-
260
-
261
-    /**
262
-     * get_cart_total_before_tax
263
-     *
264
-     * @access public
265
-     * @return float
266
-     * @throws \EE_Error
267
-     */
268
-    public function get_cart_total_before_tax()
269
-    {
270
-        return $this->get_grand_total()->recalculate_pre_tax_total();
271
-    }
272
-
273
-
274
-    /**
275
-     * gets the total amount of tax paid for items in this cart
276
-     *
277
-     * @access public
278
-     * @return float
279
-     * @throws \EE_Error
280
-     */
281
-    public function get_applied_taxes()
282
-    {
283
-        return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
284
-    }
285
-
286
-
287
-    /**
288
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
289
-     *
290
-     * @access public
291
-     * @return float
292
-     * @throws \EE_Error
293
-     */
294
-    public function get_cart_grand_total()
295
-    {
296
-        EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
297
-        return $this->get_grand_total()->total();
298
-    }
299
-
300
-
301
-    /**
302
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
303
-     *
304
-     * @access public
305
-     * @return float
306
-     * @throws \EE_Error
307
-     */
308
-    public function recalculate_all_cart_totals()
309
-    {
310
-        $pre_tax_total = $this->get_cart_total_before_tax();
311
-        $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
312
-        $this->_grand_total->set_total($pre_tax_total + $taxes_total);
313
-        $this->_grand_total->save_this_and_descendants_to_txn();
314
-        return $this->get_grand_total()->total();
315
-    }
316
-
317
-
318
-    /**
319
-     * deletes an item from the cart
320
-     *
321
-     * @access public
322
-     * @param array|bool|string $line_item_codes
323
-     * @return int on success, FALSE on fail
324
-     * @throws \EE_Error
325
-     */
326
-    public function delete_items($line_item_codes = false)
327
-    {
328
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
329
-        return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
330
-    }
331
-
332
-
333
-    /**
334
-     * @remove ALL items from cart and zero ALL totals
335
-     * @access public
336
-     * @return bool
337
-     * @throws \EE_Error
338
-     */
339
-    public function empty_cart()
340
-    {
341
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
342
-        $this->_grand_total = $this->_create_grand_total();
343
-        return $this->save_cart(true);
344
-    }
345
-
346
-
347
-    /**
348
-     * @remove ALL items from cart and delete total as well
349
-     * @access public
350
-     * @return bool
351
-     * @throws \EE_Error
352
-     */
353
-    public function delete_cart()
354
-    {
355
-        if ($this->_grand_total instanceof EE_Line_Item) {
356
-            $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
357
-            if ($deleted) {
358
-                $deleted += $this->_grand_total->delete();
359
-                $this->_grand_total = null;
360
-                return true;
361
-            }
362
-        }
363
-        return false;
364
-    }
365
-
366
-
367
-    /**
368
-     * @save   cart to session
369
-     * @access public
370
-     * @param bool $apply_taxes
371
-     * @return TRUE on success, FALSE on fail
372
-     * @throws \EE_Error
373
-     */
374
-    public function save_cart($apply_taxes = true)
375
-    {
376
-        if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
377
-            EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
378
-            // make sure we don't cache the transaction because it can get stale
379
-            if (
380
-                $this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
381
-                && $this->_grand_total->get_one_from_cache('Transaction')->ID()
382
-            ) {
383
-                $this->_grand_total->clear_cache('Transaction', null, true);
384
-            }
385
-        }
386
-        if ($this->session() instanceof EE_Session) {
387
-            return $this->session()->set_cart($this);
388
-        } else {
389
-            return false;
390
-        }
391
-    }
392
-
393
-
394
-    public function __wakeup()
395
-    {
396
-        if (! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
397
-            // $this->_grand_total is actually just an ID, so use it to get the object from the db
398
-            $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
399
-        }
400
-    }
401
-
402
-
403
-    /**
404
-     * @return array
405
-     */
406
-    public function __sleep()
407
-    {
408
-        if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
409
-            $this->_grand_total = $this->_grand_total->ID();
410
-        }
411
-        return array('_grand_total');
412
-    }
20
+	/**
21
+	 * instance of the EE_Cart object
22
+	 *
23
+	 * @access    private
24
+	 * @var EE_Cart $_instance
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * instance of the EE_Session object
30
+	 *
31
+	 * @access    protected
32
+	 * @var EE_Session $_session
33
+	 */
34
+	protected $_session;
35
+
36
+	/**
37
+	 * The total Line item which comprises all the children line-item subtotals,
38
+	 * which in turn each have their line items.
39
+	 * Typically, the line item structure will look like:
40
+	 * grand total
41
+	 * -tickets-sub-total
42
+	 * --ticket1
43
+	 * --ticket2
44
+	 * --...
45
+	 * -taxes-sub-total
46
+	 * --tax1
47
+	 * --tax2
48
+	 *
49
+	 * @var EE_Line_Item
50
+	 */
51
+	private $_grand_total;
52
+
53
+
54
+	/**
55
+	 * @singleton method used to instantiate class object
56
+	 * @access    public
57
+	 * @param EE_Line_Item $grand_total
58
+	 * @param EE_Session   $session
59
+	 * @return \EE_Cart
60
+	 * @throws \EE_Error
61
+	 */
62
+	public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
63
+	{
64
+		if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
65
+			self::$_instance = new self($grand_total, $session);
66
+		}
67
+		// or maybe retrieve an existing one ?
68
+		if (! self::$_instance instanceof EE_Cart) {
69
+			// try getting the cart out of the session
70
+			$saved_cart = $session instanceof EE_Session ? $session->cart() : null;
71
+			self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
72
+			unset($saved_cart);
73
+		}
74
+		// verify that cart is ok and grand total line item exists
75
+		if (! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
76
+			self::$_instance = new self($grand_total, $session);
77
+		}
78
+		self::$_instance->get_grand_total();
79
+		// once everything is all said and done, save the cart to the EE_Session
80
+		add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
81
+		return self::$_instance;
82
+	}
83
+
84
+
85
+	/**
86
+	 * private constructor to prevent direct creation
87
+	 *
88
+	 * @Constructor
89
+	 * @access private
90
+	 * @param EE_Line_Item $grand_total
91
+	 * @param EE_Session   $session
92
+	 */
93
+	private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
94
+	{
95
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
96
+		$this->set_session($session);
97
+		if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
98
+			$this->set_grand_total_line_item($grand_total);
99
+		}
100
+	}
101
+
102
+
103
+	/**
104
+	 * Resets the cart completely (whereas empty_cart
105
+	 *
106
+	 * @param EE_Line_Item $grand_total
107
+	 * @param EE_Session   $session
108
+	 * @return EE_Cart
109
+	 * @throws \EE_Error
110
+	 */
111
+	public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
112
+	{
113
+		remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
114
+		if ($session instanceof EE_Session) {
115
+			$session->reset_cart();
116
+		}
117
+		self::$_instance = null;
118
+		return self::instance($grand_total, $session);
119
+	}
120
+
121
+
122
+	/**
123
+	 * @return \EE_Session
124
+	 */
125
+	public function session()
126
+	{
127
+		if (! $this->_session instanceof EE_Session) {
128
+			$this->set_session();
129
+		}
130
+		return $this->_session;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @param EE_Session $session
136
+	 */
137
+	public function set_session(EE_Session $session = null)
138
+	{
139
+		$this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
140
+	}
141
+
142
+
143
+	/**
144
+	 * Sets the cart to match the line item. Especially handy for loading an old cart where you
145
+	 *  know the grand total line item on it
146
+	 *
147
+	 * @param EE_Line_Item $line_item
148
+	 */
149
+	public function set_grand_total_line_item(EE_Line_Item $line_item)
150
+	{
151
+		$this->_grand_total = $line_item;
152
+	}
153
+
154
+
155
+	/**
156
+	 * get_cart_from_reg_url_link
157
+	 *
158
+	 * @access public
159
+	 * @param EE_Transaction $transaction
160
+	 * @param EE_Session     $session
161
+	 * @return \EE_Cart
162
+	 * @throws \EE_Error
163
+	 */
164
+	public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
165
+	{
166
+		$grand_total = $transaction->total_line_item();
167
+		$grand_total->get_items();
168
+		$grand_total->tax_descendants();
169
+		return EE_Cart::instance($grand_total, $session);
170
+	}
171
+
172
+
173
+	/**
174
+	 * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
175
+	 *
176
+	 * @return EE_Line_Item
177
+	 * @throws \EE_Error
178
+	 */
179
+	private function _create_grand_total()
180
+	{
181
+		$this->_grand_total = EEH_Line_Item::create_total_line_item();
182
+		return $this->_grand_total;
183
+	}
184
+
185
+
186
+	/**
187
+	 * Gets all the line items of object type Ticket
188
+	 *
189
+	 * @access public
190
+	 * @return \EE_Line_Item[]
191
+	 */
192
+	public function get_tickets()
193
+	{
194
+		if ($this->_grand_total === null) {
195
+			return array();
196
+		}
197
+		return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
198
+	}
199
+
200
+
201
+	/**
202
+	 * returns the total quantity of tickets in the cart
203
+	 *
204
+	 * @access public
205
+	 * @return int
206
+	 * @throws \EE_Error
207
+	 */
208
+	public function all_ticket_quantity_count()
209
+	{
210
+		$tickets = $this->get_tickets();
211
+		if (empty($tickets)) {
212
+			return 0;
213
+		}
214
+		$count = 0;
215
+		foreach ($tickets as $ticket) {
216
+			$count += $ticket->get('LIN_quantity');
217
+		}
218
+		return $count;
219
+	}
220
+
221
+
222
+	/**
223
+	 * Gets all the tax line items
224
+	 *
225
+	 * @return \EE_Line_Item[]
226
+	 * @throws \EE_Error
227
+	 */
228
+	public function get_taxes()
229
+	{
230
+		return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
231
+	}
232
+
233
+
234
+	/**
235
+	 * Gets the total line item (which is a parent of all other line items) on this cart
236
+	 *
237
+	 * @return EE_Line_Item
238
+	 * @throws \EE_Error
239
+	 */
240
+	public function get_grand_total()
241
+	{
242
+		return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
243
+	}
244
+
245
+
246
+	/**
247
+	 * @process items for adding to cart
248
+	 * @access  public
249
+	 * @param EE_Ticket $ticket
250
+	 * @param int       $qty
251
+	 * @return TRUE on success, FALSE on fail
252
+	 * @throws \EE_Error
253
+	 */
254
+	public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
255
+	{
256
+		EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
257
+		return $this->save_cart() ? true : false;
258
+	}
259
+
260
+
261
+	/**
262
+	 * get_cart_total_before_tax
263
+	 *
264
+	 * @access public
265
+	 * @return float
266
+	 * @throws \EE_Error
267
+	 */
268
+	public function get_cart_total_before_tax()
269
+	{
270
+		return $this->get_grand_total()->recalculate_pre_tax_total();
271
+	}
272
+
273
+
274
+	/**
275
+	 * gets the total amount of tax paid for items in this cart
276
+	 *
277
+	 * @access public
278
+	 * @return float
279
+	 * @throws \EE_Error
280
+	 */
281
+	public function get_applied_taxes()
282
+	{
283
+		return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
284
+	}
285
+
286
+
287
+	/**
288
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
289
+	 *
290
+	 * @access public
291
+	 * @return float
292
+	 * @throws \EE_Error
293
+	 */
294
+	public function get_cart_grand_total()
295
+	{
296
+		EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
297
+		return $this->get_grand_total()->total();
298
+	}
299
+
300
+
301
+	/**
302
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
303
+	 *
304
+	 * @access public
305
+	 * @return float
306
+	 * @throws \EE_Error
307
+	 */
308
+	public function recalculate_all_cart_totals()
309
+	{
310
+		$pre_tax_total = $this->get_cart_total_before_tax();
311
+		$taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
312
+		$this->_grand_total->set_total($pre_tax_total + $taxes_total);
313
+		$this->_grand_total->save_this_and_descendants_to_txn();
314
+		return $this->get_grand_total()->total();
315
+	}
316
+
317
+
318
+	/**
319
+	 * deletes an item from the cart
320
+	 *
321
+	 * @access public
322
+	 * @param array|bool|string $line_item_codes
323
+	 * @return int on success, FALSE on fail
324
+	 * @throws \EE_Error
325
+	 */
326
+	public function delete_items($line_item_codes = false)
327
+	{
328
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
329
+		return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
330
+	}
331
+
332
+
333
+	/**
334
+	 * @remove ALL items from cart and zero ALL totals
335
+	 * @access public
336
+	 * @return bool
337
+	 * @throws \EE_Error
338
+	 */
339
+	public function empty_cart()
340
+	{
341
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
342
+		$this->_grand_total = $this->_create_grand_total();
343
+		return $this->save_cart(true);
344
+	}
345
+
346
+
347
+	/**
348
+	 * @remove ALL items from cart and delete total as well
349
+	 * @access public
350
+	 * @return bool
351
+	 * @throws \EE_Error
352
+	 */
353
+	public function delete_cart()
354
+	{
355
+		if ($this->_grand_total instanceof EE_Line_Item) {
356
+			$deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
357
+			if ($deleted) {
358
+				$deleted += $this->_grand_total->delete();
359
+				$this->_grand_total = null;
360
+				return true;
361
+			}
362
+		}
363
+		return false;
364
+	}
365
+
366
+
367
+	/**
368
+	 * @save   cart to session
369
+	 * @access public
370
+	 * @param bool $apply_taxes
371
+	 * @return TRUE on success, FALSE on fail
372
+	 * @throws \EE_Error
373
+	 */
374
+	public function save_cart($apply_taxes = true)
375
+	{
376
+		if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
377
+			EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
378
+			// make sure we don't cache the transaction because it can get stale
379
+			if (
380
+				$this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
381
+				&& $this->_grand_total->get_one_from_cache('Transaction')->ID()
382
+			) {
383
+				$this->_grand_total->clear_cache('Transaction', null, true);
384
+			}
385
+		}
386
+		if ($this->session() instanceof EE_Session) {
387
+			return $this->session()->set_cart($this);
388
+		} else {
389
+			return false;
390
+		}
391
+	}
392
+
393
+
394
+	public function __wakeup()
395
+	{
396
+		if (! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
397
+			// $this->_grand_total is actually just an ID, so use it to get the object from the db
398
+			$this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
399
+		}
400
+	}
401
+
402
+
403
+	/**
404
+	 * @return array
405
+	 */
406
+	public function __sleep()
407
+	{
408
+		if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
409
+			$this->_grand_total = $this->_grand_total->ID();
410
+		}
411
+		return array('_grand_total');
412
+	}
413 413
 }
Please login to merge, or discard this patch.