Completed
Branch FET-10486-add-timestamp-checki... (611b15)
by
unknown
136:24 queued 121:17
created
modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php 2 patches
Indentation   +616 added lines, -616 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -16,659 +16,659 @@  discard block
 block discarded – undo
16 16
 abstract class EE_SPCO_Reg_Step
17 17
 {
18 18
 
19
-    /**
20
-     *    $_completed - TRUE if this step has fully completed it's duties
21
-     *
22
-     * @access protected
23
-     * @type bool $_completed
24
-     */
25
-    protected $_completed = false;
26
-
27
-    /**
28
-     *    $_is_current_step - TRUE if this is the current step
29
-     *
30
-     * @access protected
31
-     * @type bool $_is_current_step
32
-     */
33
-    protected $_is_current_step = false;
34
-
35
-    /**
36
-     *    $_order - when the reg step should be run relative to other steps
37
-     *
38
-     * @access protected
39
-     * @type int $_template
40
-     */
41
-    protected $_order = 0;
42
-
43
-    /**
44
-     *    $_slug - URL param for this step
45
-     *
46
-     * @access protected
47
-     * @type string $_slug
48
-     */
49
-    protected $_slug;
50
-
51
-    /**
52
-     *    $_name - Step Name - translatable string
53
-     *
54
-     * @access protected
55
-     * @type string $_slug
56
-     */
57
-    protected $_name;
58
-
59
-    /**
60
-     *    $_submit_button_text - translatable string that appears on this step's submit button
61
-     *
62
-     * @access protected
63
-     * @type string $_slug
64
-     */
65
-    protected $_submit_button_text;
66
-
67
-    /**
68
-     *    $_template - template name
69
-     *
70
-     * @access protected
71
-     * @type string $_template
72
-     */
73
-    protected $_template;
74
-
75
-    /**
76
-     *    $_reg_form_name - the form input name and id attribute
77
-     *
78
-     * @access protected
79
-     * @var string $_reg_form_name
80
-     */
81
-    protected $_reg_form_name;
82
-
83
-    /**
84
-     *    $_success_message - text to display upon successful form submission
85
-     *
86
-     * @access private
87
-     * @var string $_success_message
88
-     */
89
-    protected $_success_message;
90
-
91
-    /**
92
-     *    $_instructions - a brief description of how to complete the reg step. Usually displayed in conjunction with
93
-     *    the previous step's success message.
94
-     *
95
-     * @access private
96
-     * @var string $_instructions
97
-     */
98
-    protected $_instructions;
99
-
100
-    /**
101
-     *    $_valid_data - the normalized and validated data for this step
102
-     *
103
-     * @access public
104
-     * @var array $_valid_data
105
-     */
106
-    protected $_valid_data = array();
107
-
108
-    /**
109
-     *    $reg_form - the registration form for this step
110
-     *
111
-     * @access public
112
-     * @var EE_Form_Section_Proper $reg_form
113
-     */
114
-    public $reg_form;
115
-
116
-    /**
117
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
118
-     *
119
-     * @access public
120
-     * @var EE_Checkout $checkout
121
-     */
122
-    public $checkout;
123
-
124
-
125
-
126
-    /**
127
-     * @return void
128
-     */
129
-    abstract public function translate_js_strings();
130
-
131
-
19
+	/**
20
+	 *    $_completed - TRUE if this step has fully completed it's duties
21
+	 *
22
+	 * @access protected
23
+	 * @type bool $_completed
24
+	 */
25
+	protected $_completed = false;
26
+
27
+	/**
28
+	 *    $_is_current_step - TRUE if this is the current step
29
+	 *
30
+	 * @access protected
31
+	 * @type bool $_is_current_step
32
+	 */
33
+	protected $_is_current_step = false;
34
+
35
+	/**
36
+	 *    $_order - when the reg step should be run relative to other steps
37
+	 *
38
+	 * @access protected
39
+	 * @type int $_template
40
+	 */
41
+	protected $_order = 0;
42
+
43
+	/**
44
+	 *    $_slug - URL param for this step
45
+	 *
46
+	 * @access protected
47
+	 * @type string $_slug
48
+	 */
49
+	protected $_slug;
50
+
51
+	/**
52
+	 *    $_name - Step Name - translatable string
53
+	 *
54
+	 * @access protected
55
+	 * @type string $_slug
56
+	 */
57
+	protected $_name;
58
+
59
+	/**
60
+	 *    $_submit_button_text - translatable string that appears on this step's submit button
61
+	 *
62
+	 * @access protected
63
+	 * @type string $_slug
64
+	 */
65
+	protected $_submit_button_text;
66
+
67
+	/**
68
+	 *    $_template - template name
69
+	 *
70
+	 * @access protected
71
+	 * @type string $_template
72
+	 */
73
+	protected $_template;
74
+
75
+	/**
76
+	 *    $_reg_form_name - the form input name and id attribute
77
+	 *
78
+	 * @access protected
79
+	 * @var string $_reg_form_name
80
+	 */
81
+	protected $_reg_form_name;
82
+
83
+	/**
84
+	 *    $_success_message - text to display upon successful form submission
85
+	 *
86
+	 * @access private
87
+	 * @var string $_success_message
88
+	 */
89
+	protected $_success_message;
90
+
91
+	/**
92
+	 *    $_instructions - a brief description of how to complete the reg step. Usually displayed in conjunction with
93
+	 *    the previous step's success message.
94
+	 *
95
+	 * @access private
96
+	 * @var string $_instructions
97
+	 */
98
+	protected $_instructions;
99
+
100
+	/**
101
+	 *    $_valid_data - the normalized and validated data for this step
102
+	 *
103
+	 * @access public
104
+	 * @var array $_valid_data
105
+	 */
106
+	protected $_valid_data = array();
107
+
108
+	/**
109
+	 *    $reg_form - the registration form for this step
110
+	 *
111
+	 * @access public
112
+	 * @var EE_Form_Section_Proper $reg_form
113
+	 */
114
+	public $reg_form;
115
+
116
+	/**
117
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
118
+	 *
119
+	 * @access public
120
+	 * @var EE_Checkout $checkout
121
+	 */
122
+	public $checkout;
123
+
124
+
125
+
126
+	/**
127
+	 * @return void
128
+	 */
129
+	abstract public function translate_js_strings();
130
+
131
+
132 132
 
133
-    /**
134
-     * @return void
135
-     */
136
-    abstract public function enqueue_styles_and_scripts();
137
-
138
-
139
-
140
-    /**
141
-     * @return boolean
142
-     */
143
-    abstract public function initialize_reg_step();
144
-
145
-
146
-
147
-    /**
148
-     * @return string
149
-     */
150
-    abstract public function generate_reg_form();
151
-
152
-
153
-
154
-    /**
155
-     * @return boolean
156
-     */
157
-    abstract public function process_reg_step();
158
-
159
-
160
-
161
-    /**
162
-     * @return boolean
163
-     */
164
-    abstract public function update_reg_step();
165
-
166
-
167
-
168
-    /**
169
-     * @return boolean
170
-     */
171
-    public function completed()
172
-    {
173
-        return $this->_completed;
174
-    }
133
+	/**
134
+	 * @return void
135
+	 */
136
+	abstract public function enqueue_styles_and_scripts();
137
+
138
+
139
+
140
+	/**
141
+	 * @return boolean
142
+	 */
143
+	abstract public function initialize_reg_step();
144
+
145
+
146
+
147
+	/**
148
+	 * @return string
149
+	 */
150
+	abstract public function generate_reg_form();
151
+
152
+
153
+
154
+	/**
155
+	 * @return boolean
156
+	 */
157
+	abstract public function process_reg_step();
158
+
159
+
160
+
161
+	/**
162
+	 * @return boolean
163
+	 */
164
+	abstract public function update_reg_step();
165
+
166
+
167
+
168
+	/**
169
+	 * @return boolean
170
+	 */
171
+	public function completed()
172
+	{
173
+		return $this->_completed;
174
+	}
175 175
 
176 176
 
177 177
 
178
-    /**
179
-     * set_completed - toggles $_completed to TRUE
180
-     */
181
-    public function set_completed()
182
-    {
183
-        // DEBUG LOG
184
-        //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
185
-        $this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this);
186
-    }
178
+	/**
179
+	 * set_completed - toggles $_completed to TRUE
180
+	 */
181
+	public function set_completed()
182
+	{
183
+		// DEBUG LOG
184
+		//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
185
+		$this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this);
186
+	}
187 187
 
188 188
 
189 189
 
190
-    /**
191
-     * set_completed - toggles $_completed to FALSE
192
-     */
193
-    public function set_not_completed()
194
-    {
195
-        $this->_completed = false;
196
-    }
190
+	/**
191
+	 * set_completed - toggles $_completed to FALSE
192
+	 */
193
+	public function set_not_completed()
194
+	{
195
+		$this->_completed = false;
196
+	}
197 197
 
198 198
 
199 199
 
200
-    /**
201
-     * @return string
202
-     */
203
-    public function name()
204
-    {
205
-        return $this->_name;
206
-    }
200
+	/**
201
+	 * @return string
202
+	 */
203
+	public function name()
204
+	{
205
+		return $this->_name;
206
+	}
207 207
 
208 208
 
209 209
 
210
-    /**
211
-     * @return string
212
-     */
213
-    public function slug()
214
-    {
215
-        return $this->_slug;
216
-    }
210
+	/**
211
+	 * @return string
212
+	 */
213
+	public function slug()
214
+	{
215
+		return $this->_slug;
216
+	}
217 217
 
218 218
 
219 219
 
220
-    /**
221
-     * submit_button_text
222
-     * the text that appears on the reg step form submit button
223
-     *
224
-     * @return string
225
-     */
226
-    public function submit_button_text()
227
-    {
228
-        return $this->_submit_button_text;
229
-    }
220
+	/**
221
+	 * submit_button_text
222
+	 * the text that appears on the reg step form submit button
223
+	 *
224
+	 * @return string
225
+	 */
226
+	public function submit_button_text()
227
+	{
228
+		return $this->_submit_button_text;
229
+	}
230 230
 
231 231
 
232 232
 
233
-    /**
234
-     * set_submit_button_text
235
-     * sets the text that appears on the reg step form submit button
236
-     *
237
-     * @param string $submit_button_text
238
-     */
239
-    public function set_submit_button_text($submit_button_text = '')
240
-    {
241
-        if (! empty($submit_button_text)) {
242
-            $this->_submit_button_text = $submit_button_text;
243
-        } else if ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
244
-            if ($this->checkout->revisit) {
245
-                $this->_submit_button_text = sprintf(__('Update %s', 'event_espresso'),
246
-                    $this->checkout->current_step->name());
247
-            } else {
248
-                $this->_submit_button_text = sprintf(__('Proceed to %s', 'event_espresso'),
249
-                    $this->checkout->next_step->name());
250
-            }
251
-        }
252
-        // filters the submit button text
253
-        $this->_submit_button_text = apply_filters(
254
-            'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
255
-            $this->_submit_button_text,
256
-            $this->checkout
257
-        );
258
-    }
233
+	/**
234
+	 * set_submit_button_text
235
+	 * sets the text that appears on the reg step form submit button
236
+	 *
237
+	 * @param string $submit_button_text
238
+	 */
239
+	public function set_submit_button_text($submit_button_text = '')
240
+	{
241
+		if (! empty($submit_button_text)) {
242
+			$this->_submit_button_text = $submit_button_text;
243
+		} else if ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
244
+			if ($this->checkout->revisit) {
245
+				$this->_submit_button_text = sprintf(__('Update %s', 'event_espresso'),
246
+					$this->checkout->current_step->name());
247
+			} else {
248
+				$this->_submit_button_text = sprintf(__('Proceed to %s', 'event_espresso'),
249
+					$this->checkout->next_step->name());
250
+			}
251
+		}
252
+		// filters the submit button text
253
+		$this->_submit_button_text = apply_filters(
254
+			'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
255
+			$this->_submit_button_text,
256
+			$this->checkout
257
+		);
258
+	}
259 259
 
260 260
 
261 261
 
262
-    /**
263
-     * @param boolean $is_current_step
264
-     */
265
-    public function set_is_current_step($is_current_step)
266
-    {
267
-        $this->_is_current_step = $is_current_step;
268
-    }
262
+	/**
263
+	 * @param boolean $is_current_step
264
+	 */
265
+	public function set_is_current_step($is_current_step)
266
+	{
267
+		$this->_is_current_step = $is_current_step;
268
+	}
269 269
 
270 270
 
271 271
 
272
-    /**
273
-     * @return boolean
274
-     */
275
-    public function is_current_step()
276
-    {
277
-        return $this->_is_current_step;
278
-    }
272
+	/**
273
+	 * @return boolean
274
+	 */
275
+	public function is_current_step()
276
+	{
277
+		return $this->_is_current_step;
278
+	}
279 279
 
280 280
 
281 281
 
282
-    /**
283
-     * @return boolean
284
-     */
285
-    public function is_final_step()
286
-    {
287
-        return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration ? true : false;
288
-    }
282
+	/**
283
+	 * @return boolean
284
+	 */
285
+	public function is_final_step()
286
+	{
287
+		return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration ? true : false;
288
+	}
289 289
 
290 290
 
291 291
 
292
-    /**
293
-     * @param int $order
294
-     */
295
-    public function set_order($order)
296
-    {
297
-        $this->_order = $order;
298
-    }
299
-
300
-
292
+	/**
293
+	 * @param int $order
294
+	 */
295
+	public function set_order($order)
296
+	{
297
+		$this->_order = $order;
298
+	}
299
+
300
+
301 301
 
302
-    /**
303
-     * @return int
304
-     */
305
-    public function order()
306
-    {
307
-        return $this->_order;
308
-    }
309
-
310
-
311
-
312
-    /**
313
-     * @return string
314
-     */
315
-    public function template()
316
-    {
317
-        return $this->_template;
318
-    }
319
-
320
-
321
-
322
-    /**
323
-     * @return string
324
-     */
325
-    public function success_message()
326
-    {
327
-        return $this->_success_message;
328
-    }
302
+	/**
303
+	 * @return int
304
+	 */
305
+	public function order()
306
+	{
307
+		return $this->_order;
308
+	}
309
+
310
+
311
+
312
+	/**
313
+	 * @return string
314
+	 */
315
+	public function template()
316
+	{
317
+		return $this->_template;
318
+	}
319
+
320
+
321
+
322
+	/**
323
+	 * @return string
324
+	 */
325
+	public function success_message()
326
+	{
327
+		return $this->_success_message;
328
+	}
329 329
 
330 330
 
331 331
 
332
-    /**
333
-     * _set_success_message
334
-     *
335
-     * @param string $success_message
336
-     */
337
-    protected function _set_success_message($success_message)
338
-    {
339
-        $this->_success_message = $success_message;
340
-    }
341
-
342
-
343
-
344
-    /**
345
-     * _reset_success_message
346
-     *
347
-     * @return void
348
-     */
349
-    protected function _reset_success_message()
350
-    {
351
-        $this->_success_message = '';
352
-    }
332
+	/**
333
+	 * _set_success_message
334
+	 *
335
+	 * @param string $success_message
336
+	 */
337
+	protected function _set_success_message($success_message)
338
+	{
339
+		$this->_success_message = $success_message;
340
+	}
341
+
342
+
343
+
344
+	/**
345
+	 * _reset_success_message
346
+	 *
347
+	 * @return void
348
+	 */
349
+	protected function _reset_success_message()
350
+	{
351
+		$this->_success_message = '';
352
+	}
353 353
 
354 354
 
355 355
 
356
-    /**
357
-     * @return string
358
-     */
359
-    public function _instructions()
360
-    {
361
-        return $this->_instructions;
362
-    }
363
-
364
-
365
-
366
-    /**
367
-     * @param string $instructions
368
-     */
369
-    public function set_instructions($instructions)
370
-    {
371
-        $this->_instructions = apply_filters(
372
-            'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions',
373
-            $instructions,
374
-            $this
375
-        );
376
-    }
377
-
378
-
379
-
380
-    /**
381
-     * @param array $valid_data
382
-     */
383
-    public function set_valid_data($valid_data)
384
-    {
385
-        $this->_valid_data = $valid_data;
386
-    }
387
-
388
-
389
-
390
-    /**
391
-     * @return array
392
-     */
393
-    public function valid_data()
394
-    {
395
-        if (empty($this->_valid_data)) {
396
-            $this->_valid_data = $this->reg_form->valid_data();
397
-        }
398
-        return $this->_valid_data;
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * @return string
405
-     */
406
-    public function reg_form_name()
407
-    {
408
-        if (empty($this->_reg_form_name)) {
409
-            $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form');
410
-        }
411
-        return $this->_reg_form_name;
412
-    }
413
-
414
-
415
-
416
-    /**
417
-     * @param string $reg_form_name
418
-     */
419
-    protected function set_reg_form_name($reg_form_name)
420
-    {
421
-        $this->_reg_form_name = $reg_form_name;
422
-    }
423
-
424
-
425
-
426
-    /**
427
-     * reg_step_url
428
-     *
429
-     * @param string $action
430
-     * @return string
431
-     */
432
-    public function reg_step_url($action = '')
433
-    {
434
-        $query_args = array('step' => $this->slug());
435
-        if (! empty($action)) {
436
-            $query_args['action'] = $action;
437
-        }
438
-        // final step has no display
439
-        if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') {
440
-            $query_args['action'] = 'process_reg_step';
441
-        }
442
-        if ($this->checkout->revisit) {
443
-            $query_args['revisit'] = true;
444
-        }
445
-        if ($this->checkout->reg_url_link) {
446
-            $query_args['e_reg_url_link'] = $this->checkout->reg_url_link;
447
-        }
448
-        return add_query_arg($query_args, $this->checkout->reg_page_base_url);
449
-    }
450
-
451
-
452
-
453
-    /**
454
-     * creates the default hidden inputs section
455
-     *
456
-     * @return EE_Form_Section_Proper
457
-     * @throws \EE_Error
458
-     */
459
-    public function reg_step_hidden_inputs()
460
-    {
461
-        // hidden inputs for admin registrations
462
-        if ($this->checkout->admin_request) {
463
-            return new EE_Form_Section_Proper(
464
-                array(
465
-                    'layout_strategy' => new EE_Div_Per_Section_Layout(),
466
-                    'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
467
-                    'subsections'     => array(
468
-                        'next_step' => new EE_Fixed_Hidden_Input(
469
-                            array(
470
-                                'html_name' => 'next_step',
471
-                                'html_id'   => 'spco-' . $this->slug() . '-next-step',
472
-                                'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
473
-                                    ? $this->checkout->next_step->slug() : '',
474
-                            )
475
-                        ),
476
-                    ),
477
-                )
478
-            );
479
-        } else {
480
-            $default_form_action = apply_filters(
481
-                'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action',
482
-                empty($this->checkout->reg_url_link)
483
-                    ? 'process_reg_step'
484
-                    : 'update_reg_step',
485
-                $this
486
-            );
487
-            // hidden inputs for frontend registrations
488
-            return new EE_Form_Section_Proper(
489
-                array(
490
-                    'layout_strategy' => new EE_Div_Per_Section_Layout(),
491
-                    'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
492
-                    'subsections'     => array(
493
-                        'action'         => new EE_Fixed_Hidden_Input(
494
-                            array(
495
-                                'html_name' => 'action',
496
-                                'html_id'   => 'spco-' . $this->slug() . '-action',
497
-                                'default'   => $default_form_action,
498
-                            )
499
-                        ),
500
-                        'next_step'      => new EE_Fixed_Hidden_Input(
501
-                            array(
502
-                                'html_name' => 'next_step',
503
-                                'html_id'   => 'spco-' . $this->slug() . '-next-step',
504
-                                'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
505
-                                    ? $this->checkout->next_step->slug() : '',
506
-                            )
507
-                        ),
508
-                        'e_reg_url_link' => new EE_Fixed_Hidden_Input(
509
-                            array(
510
-                                'html_name' => 'e_reg_url_link',
511
-                                'html_id'   => 'spco-reg_url_link',
512
-                                'default'   => $this->checkout->reg_url_link,
513
-                            )
514
-                        ),
515
-                        'revisit'        => new EE_Fixed_Hidden_Input(
516
-                            array(
517
-                                'html_name' => 'revisit',
518
-                                'html_id'   => 'spco-revisit',
519
-                                'default'   => $this->checkout->revisit,
520
-                            )
521
-                        ),
522
-                    ),
523
-                )
524
-            );
525
-        }
526
-    }
527
-
528
-
529
-
530
-    /**
531
-     * generate_reg_form_for_actions
532
-     *
533
-     * @param array $actions
534
-     * @return void
535
-     */
536
-    public function generate_reg_form_for_actions($actions = array())
537
-    {
538
-        $actions = array_merge(
539
-            array(
540
-                'generate_reg_form',
541
-                'display_spco_reg_step',
542
-                'process_reg_step',
543
-                'update_reg_step',
544
-            ), $actions
545
-        );
546
-        $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true) ? true : false;
547
-    }
548
-
549
-
550
-
551
-    /**
552
-     * @return string
553
-     * @throws \EE_Error
554
-     */
555
-    public function display_reg_form()
556
-    {
557
-        $html = '';
558
-        if ($this->reg_form instanceof EE_Form_Section_Proper) {
559
-            $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : '';
560
-            if (EE_Registry::instance()->REQ->ajax) {
561
-                $this->reg_form->localize_validation_rules();
562
-                $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
563
-            }
564
-            $html .= $this->reg_form->get_html();
565
-            $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : '';
566
-            $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : '';
567
-        }
568
-        return $html;
569
-    }
570
-
571
-
572
-
573
-    /**
574
-     * div_class - returns nothing for current step, but a css class of "hidden" for others
575
-     *
576
-     * @return string
577
-     * @throws \EE_Error
578
-     */
579
-    public function reg_step_submit_button()
580
-    {
581
-        if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
582
-            return '';
583
-        }
584
-        ob_start();
585
-        do_action('AHEE__before_spco_whats_next_buttons', $this->slug(), $this->checkout->next_step->slug(),
586
-            $this->checkout);
587
-        $html = ob_get_clean();
588
-        // generate submit button
589
-        $sbmt_btn = new EE_Submit_Input(array(
590
-            'html_name'             => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
591
-            'html_id'               => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
592
-            'html_class'            => 'spco-next-step-btn',
593
-            'other_html_attributes' => ' rel="' . $this->slug() . '"',
594
-            'default'               => $this->submit_button_text(),
595
-        ));
596
-        $sbmt_btn->set_button_css_attributes(true, 'large');
597
-        $sbmt_btn_html = $sbmt_btn->get_html_for_input();
598
-        $html .= EEH_HTML::div(
599
-            apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this),
600
-            'spco-' . $this->slug() . '-whats-next-buttons-dv',
601
-            'spco-whats-next-buttons'
602
-        );
603
-        return $html;
604
-    }
605
-
606
-
607
-
608
-    /**
609
-     * div_class - returns nothing for current step, but a css class of "hidden" for others
610
-     *
611
-     * @return string
612
-     */
613
-    public function div_class()
614
-    {
615
-        return $this->is_current_step() ? '' : ' hidden';
616
-    }
617
-
618
-
619
-
620
-    /**
621
-     * div_class - returns  a css class of "hidden" for current step, but nothing for others
622
-     *
623
-     * @return string
624
-     */
625
-    public function edit_lnk_url()
626
-    {
627
-        return add_query_arg(array('step' => $this->slug()), $this->checkout->reg_page_base_url);
628
-    }
629
-
630
-
631
-
632
-    /**
633
-     * div_class - returns  a css class of "hidden" for current step, but nothing for others
634
-     *
635
-     * @return string
636
-     */
637
-    public function edit_link_class()
638
-    {
639
-        return $this->is_current_step() ? ' hidden' : '';
640
-    }
641
-
642
-
643
-
644
-    /**
645
-     * update_checkout with changes that have been made to the cart
646
-     *
647
-     * @return void
648
-     * @throws \EE_Error
649
-     */
650
-    public function update_checkout()
651
-    {
652
-        // grab the cart grand total and reset TXN total
653
-        $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total());
654
-        $this->checkout->stash_transaction_and_checkout();
655
-    }
656
-
657
-
658
-
659
-    /**
660
-     *    __sleep
661
-     * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
662
-     * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
663
-     * reg form, because if needed, it will be regenerated anyways
664
-     *
665
-     * @return array
666
-     */
667
-    public function __sleep()
668
-    {
669
-        // remove the reg form and the checkout
670
-        return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout'));
671
-    }
356
+	/**
357
+	 * @return string
358
+	 */
359
+	public function _instructions()
360
+	{
361
+		return $this->_instructions;
362
+	}
363
+
364
+
365
+
366
+	/**
367
+	 * @param string $instructions
368
+	 */
369
+	public function set_instructions($instructions)
370
+	{
371
+		$this->_instructions = apply_filters(
372
+			'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions',
373
+			$instructions,
374
+			$this
375
+		);
376
+	}
377
+
378
+
379
+
380
+	/**
381
+	 * @param array $valid_data
382
+	 */
383
+	public function set_valid_data($valid_data)
384
+	{
385
+		$this->_valid_data = $valid_data;
386
+	}
387
+
388
+
389
+
390
+	/**
391
+	 * @return array
392
+	 */
393
+	public function valid_data()
394
+	{
395
+		if (empty($this->_valid_data)) {
396
+			$this->_valid_data = $this->reg_form->valid_data();
397
+		}
398
+		return $this->_valid_data;
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * @return string
405
+	 */
406
+	public function reg_form_name()
407
+	{
408
+		if (empty($this->_reg_form_name)) {
409
+			$this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form');
410
+		}
411
+		return $this->_reg_form_name;
412
+	}
413
+
414
+
415
+
416
+	/**
417
+	 * @param string $reg_form_name
418
+	 */
419
+	protected function set_reg_form_name($reg_form_name)
420
+	{
421
+		$this->_reg_form_name = $reg_form_name;
422
+	}
423
+
424
+
425
+
426
+	/**
427
+	 * reg_step_url
428
+	 *
429
+	 * @param string $action
430
+	 * @return string
431
+	 */
432
+	public function reg_step_url($action = '')
433
+	{
434
+		$query_args = array('step' => $this->slug());
435
+		if (! empty($action)) {
436
+			$query_args['action'] = $action;
437
+		}
438
+		// final step has no display
439
+		if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') {
440
+			$query_args['action'] = 'process_reg_step';
441
+		}
442
+		if ($this->checkout->revisit) {
443
+			$query_args['revisit'] = true;
444
+		}
445
+		if ($this->checkout->reg_url_link) {
446
+			$query_args['e_reg_url_link'] = $this->checkout->reg_url_link;
447
+		}
448
+		return add_query_arg($query_args, $this->checkout->reg_page_base_url);
449
+	}
450
+
451
+
452
+
453
+	/**
454
+	 * creates the default hidden inputs section
455
+	 *
456
+	 * @return EE_Form_Section_Proper
457
+	 * @throws \EE_Error
458
+	 */
459
+	public function reg_step_hidden_inputs()
460
+	{
461
+		// hidden inputs for admin registrations
462
+		if ($this->checkout->admin_request) {
463
+			return new EE_Form_Section_Proper(
464
+				array(
465
+					'layout_strategy' => new EE_Div_Per_Section_Layout(),
466
+					'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
467
+					'subsections'     => array(
468
+						'next_step' => new EE_Fixed_Hidden_Input(
469
+							array(
470
+								'html_name' => 'next_step',
471
+								'html_id'   => 'spco-' . $this->slug() . '-next-step',
472
+								'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
473
+									? $this->checkout->next_step->slug() : '',
474
+							)
475
+						),
476
+					),
477
+				)
478
+			);
479
+		} else {
480
+			$default_form_action = apply_filters(
481
+				'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action',
482
+				empty($this->checkout->reg_url_link)
483
+					? 'process_reg_step'
484
+					: 'update_reg_step',
485
+				$this
486
+			);
487
+			// hidden inputs for frontend registrations
488
+			return new EE_Form_Section_Proper(
489
+				array(
490
+					'layout_strategy' => new EE_Div_Per_Section_Layout(),
491
+					'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
492
+					'subsections'     => array(
493
+						'action'         => new EE_Fixed_Hidden_Input(
494
+							array(
495
+								'html_name' => 'action',
496
+								'html_id'   => 'spco-' . $this->slug() . '-action',
497
+								'default'   => $default_form_action,
498
+							)
499
+						),
500
+						'next_step'      => new EE_Fixed_Hidden_Input(
501
+							array(
502
+								'html_name' => 'next_step',
503
+								'html_id'   => 'spco-' . $this->slug() . '-next-step',
504
+								'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
505
+									? $this->checkout->next_step->slug() : '',
506
+							)
507
+						),
508
+						'e_reg_url_link' => new EE_Fixed_Hidden_Input(
509
+							array(
510
+								'html_name' => 'e_reg_url_link',
511
+								'html_id'   => 'spco-reg_url_link',
512
+								'default'   => $this->checkout->reg_url_link,
513
+							)
514
+						),
515
+						'revisit'        => new EE_Fixed_Hidden_Input(
516
+							array(
517
+								'html_name' => 'revisit',
518
+								'html_id'   => 'spco-revisit',
519
+								'default'   => $this->checkout->revisit,
520
+							)
521
+						),
522
+					),
523
+				)
524
+			);
525
+		}
526
+	}
527
+
528
+
529
+
530
+	/**
531
+	 * generate_reg_form_for_actions
532
+	 *
533
+	 * @param array $actions
534
+	 * @return void
535
+	 */
536
+	public function generate_reg_form_for_actions($actions = array())
537
+	{
538
+		$actions = array_merge(
539
+			array(
540
+				'generate_reg_form',
541
+				'display_spco_reg_step',
542
+				'process_reg_step',
543
+				'update_reg_step',
544
+			), $actions
545
+		);
546
+		$this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true) ? true : false;
547
+	}
548
+
549
+
550
+
551
+	/**
552
+	 * @return string
553
+	 * @throws \EE_Error
554
+	 */
555
+	public function display_reg_form()
556
+	{
557
+		$html = '';
558
+		if ($this->reg_form instanceof EE_Form_Section_Proper) {
559
+			$html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : '';
560
+			if (EE_Registry::instance()->REQ->ajax) {
561
+				$this->reg_form->localize_validation_rules();
562
+				$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
563
+			}
564
+			$html .= $this->reg_form->get_html();
565
+			$html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : '';
566
+			$html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : '';
567
+		}
568
+		return $html;
569
+	}
570
+
571
+
572
+
573
+	/**
574
+	 * div_class - returns nothing for current step, but a css class of "hidden" for others
575
+	 *
576
+	 * @return string
577
+	 * @throws \EE_Error
578
+	 */
579
+	public function reg_step_submit_button()
580
+	{
581
+		if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
582
+			return '';
583
+		}
584
+		ob_start();
585
+		do_action('AHEE__before_spco_whats_next_buttons', $this->slug(), $this->checkout->next_step->slug(),
586
+			$this->checkout);
587
+		$html = ob_get_clean();
588
+		// generate submit button
589
+		$sbmt_btn = new EE_Submit_Input(array(
590
+			'html_name'             => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
591
+			'html_id'               => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
592
+			'html_class'            => 'spco-next-step-btn',
593
+			'other_html_attributes' => ' rel="' . $this->slug() . '"',
594
+			'default'               => $this->submit_button_text(),
595
+		));
596
+		$sbmt_btn->set_button_css_attributes(true, 'large');
597
+		$sbmt_btn_html = $sbmt_btn->get_html_for_input();
598
+		$html .= EEH_HTML::div(
599
+			apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this),
600
+			'spco-' . $this->slug() . '-whats-next-buttons-dv',
601
+			'spco-whats-next-buttons'
602
+		);
603
+		return $html;
604
+	}
605
+
606
+
607
+
608
+	/**
609
+	 * div_class - returns nothing for current step, but a css class of "hidden" for others
610
+	 *
611
+	 * @return string
612
+	 */
613
+	public function div_class()
614
+	{
615
+		return $this->is_current_step() ? '' : ' hidden';
616
+	}
617
+
618
+
619
+
620
+	/**
621
+	 * div_class - returns  a css class of "hidden" for current step, but nothing for others
622
+	 *
623
+	 * @return string
624
+	 */
625
+	public function edit_lnk_url()
626
+	{
627
+		return add_query_arg(array('step' => $this->slug()), $this->checkout->reg_page_base_url);
628
+	}
629
+
630
+
631
+
632
+	/**
633
+	 * div_class - returns  a css class of "hidden" for current step, but nothing for others
634
+	 *
635
+	 * @return string
636
+	 */
637
+	public function edit_link_class()
638
+	{
639
+		return $this->is_current_step() ? ' hidden' : '';
640
+	}
641
+
642
+
643
+
644
+	/**
645
+	 * update_checkout with changes that have been made to the cart
646
+	 *
647
+	 * @return void
648
+	 * @throws \EE_Error
649
+	 */
650
+	public function update_checkout()
651
+	{
652
+		// grab the cart grand total and reset TXN total
653
+		$this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total());
654
+		$this->checkout->stash_transaction_and_checkout();
655
+	}
656
+
657
+
658
+
659
+	/**
660
+	 *    __sleep
661
+	 * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
662
+	 * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
663
+	 * reg form, because if needed, it will be regenerated anyways
664
+	 *
665
+	 * @return array
666
+	 */
667
+	public function __sleep()
668
+	{
669
+		// remove the reg form and the checkout
670
+		return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout'));
671
+	}
672 672
 
673 673
 
674 674
 
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
      */
239 239
     public function set_submit_button_text($submit_button_text = '')
240 240
     {
241
-        if (! empty($submit_button_text)) {
241
+        if ( ! empty($submit_button_text)) {
242 242
             $this->_submit_button_text = $submit_button_text;
243 243
         } else if ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
244 244
             if ($this->checkout->revisit) {
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
     public function reg_form_name()
407 407
     {
408 408
         if (empty($this->_reg_form_name)) {
409
-            $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form');
409
+            $this->set_reg_form_name('ee-spco-'.$this->slug().'-reg-step-form');
410 410
         }
411 411
         return $this->_reg_form_name;
412 412
     }
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
     public function reg_step_url($action = '')
433 433
     {
434 434
         $query_args = array('step' => $this->slug());
435
-        if (! empty($action)) {
435
+        if ( ! empty($action)) {
436 436
             $query_args['action'] = $action;
437 437
         }
438 438
         // final step has no display
@@ -463,12 +463,12 @@  discard block
 block discarded – undo
463 463
             return new EE_Form_Section_Proper(
464 464
                 array(
465 465
                     'layout_strategy' => new EE_Div_Per_Section_Layout(),
466
-                    'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
466
+                    'html_id'         => 'ee-'.$this->slug().'-hidden-inputs',
467 467
                     'subsections'     => array(
468 468
                         'next_step' => new EE_Fixed_Hidden_Input(
469 469
                             array(
470 470
                                 'html_name' => 'next_step',
471
-                                'html_id'   => 'spco-' . $this->slug() . '-next-step',
471
+                                'html_id'   => 'spco-'.$this->slug().'-next-step',
472 472
                                 'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
473 473
                                     ? $this->checkout->next_step->slug() : '',
474 474
                             )
@@ -488,19 +488,19 @@  discard block
 block discarded – undo
488 488
             return new EE_Form_Section_Proper(
489 489
                 array(
490 490
                     'layout_strategy' => new EE_Div_Per_Section_Layout(),
491
-                    'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
491
+                    'html_id'         => 'ee-'.$this->slug().'-hidden-inputs',
492 492
                     'subsections'     => array(
493 493
                         'action'         => new EE_Fixed_Hidden_Input(
494 494
                             array(
495 495
                                 'html_name' => 'action',
496
-                                'html_id'   => 'spco-' . $this->slug() . '-action',
496
+                                'html_id'   => 'spco-'.$this->slug().'-action',
497 497
                                 'default'   => $default_form_action,
498 498
                             )
499 499
                         ),
500 500
                         'next_step'      => new EE_Fixed_Hidden_Input(
501 501
                             array(
502 502
                                 'html_name' => 'next_step',
503
-                                'html_id'   => 'spco-' . $this->slug() . '-next-step',
503
+                                'html_id'   => 'spco-'.$this->slug().'-next-step',
504 504
                                 'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
505 505
                                     ? $this->checkout->next_step->slug() : '',
506 506
                             )
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
      */
579 579
     public function reg_step_submit_button()
580 580
     {
581
-        if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
581
+        if ( ! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
582 582
             return '';
583 583
         }
584 584
         ob_start();
@@ -587,17 +587,17 @@  discard block
 block discarded – undo
587 587
         $html = ob_get_clean();
588 588
         // generate submit button
589 589
         $sbmt_btn = new EE_Submit_Input(array(
590
-            'html_name'             => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
591
-            'html_id'               => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
590
+            'html_name'             => 'spco-go-to-step-'.$this->checkout->next_step->slug(),
591
+            'html_id'               => 'spco-go-to-step-'.$this->checkout->next_step->slug(),
592 592
             'html_class'            => 'spco-next-step-btn',
593
-            'other_html_attributes' => ' rel="' . $this->slug() . '"',
593
+            'other_html_attributes' => ' rel="'.$this->slug().'"',
594 594
             'default'               => $this->submit_button_text(),
595 595
         ));
596 596
         $sbmt_btn->set_button_css_attributes(true, 'large');
597 597
         $sbmt_btn_html = $sbmt_btn->get_html_for_input();
598 598
         $html .= EEH_HTML::div(
599 599
             apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this),
600
-            'spco-' . $this->slug() . '-whats-next-buttons-dv',
600
+            'spco-'.$this->slug().'-whats-next-buttons-dv',
601 601
             'spco-whats-next-buttons'
602 602
         );
603 603
         return $html;
Please login to merge, or discard this patch.
reg_steps/payment_options/EE_SPCO_Reg_Step_Payment_Options.class.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -286,41 +286,41 @@  discard block
 block discarded – undo
286 286
 			$this->checkout->revisit
287 287
 		);
288 288
 		foreach ( $registrations as $REG_ID => $registration ) {
289
-            /** @var $registration EE_Registration */
290
-            // has this registration lost it's space ?
289
+			/** @var $registration EE_Registration */
290
+			// has this registration lost it's space ?
291 291
 			if ( isset( $ejected_registrations[ $REG_ID ] ) ) {
292 292
 				$insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event();
293 293
 				continue;
294 294
 			}
295
-            // event requires admin approval
296
-            if ($registration->status_ID() === EEM_Registration::status_id_not_approved) {
297
-                // add event to list of events with pre-approval reg status
298
-                $registrations_requiring_pre_approval[$REG_ID] = $registration;
299
-                do_action(
300
-                    'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval',
301
-                    $registration->event(),
302
-                    $this
303
-                );
304
-                continue;
305
-            }
306
-            if (
295
+			// event requires admin approval
296
+			if ($registration->status_ID() === EEM_Registration::status_id_not_approved) {
297
+				// add event to list of events with pre-approval reg status
298
+				$registrations_requiring_pre_approval[$REG_ID] = $registration;
299
+				do_action(
300
+					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval',
301
+					$registration->event(),
302
+					$this
303
+				);
304
+				continue;
305
+			}
306
+			if (
307 307
 				// returning registrant
308 308
 				$this->checkout->revisit
309 309
 				// anything other than Approved
310 310
 				&& $registration->status_ID() !== EEM_Registration::status_id_approved
311
-                && (
312
-                    $registration->event()->is_sold_out()
313
-                    || $registration->event()->is_sold_out( true )
314
-                )
315
-            ) {
316
-                // add event to list of events that are sold out
317
-                $sold_out_events[ $registration->event()->ID() ] = $registration->event();
318
-                do_action(
319
-                    'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
320
-                    $registration->event(),
321
-                    $this
322
-                );
323
-                continue;
311
+				&& (
312
+					$registration->event()->is_sold_out()
313
+					|| $registration->event()->is_sold_out( true )
314
+				)
315
+			) {
316
+				// add event to list of events that are sold out
317
+				$sold_out_events[ $registration->event()->ID() ] = $registration->event();
318
+				do_action(
319
+					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
320
+					$registration->event(),
321
+					$this
322
+				);
323
+				continue;
324 324
 			}
325 325
 			// are they allowed to pay now and is there monies owing?
326 326
 			if ( $registration->owes_monies_and_can_pay() ) {
@@ -428,11 +428,11 @@  discard block
 block discarded – undo
428 428
 			new EE_Billable_Line_Item_Filter(
429 429
 				EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations(
430 430
 					EE_Registry::instance()->SSN->checkout()->transaction->registrations(
431
-                        EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
432
-                    )
431
+						EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
432
+					)
433 433
 				)
434 434
 			)
435
-        );
435
+		);
436 436
 		$line_item_filter_collection->add( new EE_Non_Zero_Line_Item_Filter() );
437 437
 		return $line_item_filter_collection;
438 438
 	}
@@ -481,46 +481,46 @@  discard block
 block discarded – undo
481 481
 	 * @throws \EE_Error
482 482
 	 */
483 483
 	public static function find_registrations_that_lost_their_space( array $registrations, $revisit = false ) {
484
-        // registrations per event
484
+		// registrations per event
485 485
 		$event_reg_count = array();
486 486
 		// spaces left per event
487 487
 		$event_spaces_remaining = array();
488
-        // tickets left sorted by ID
489
-        $tickets_remaining = array();
490
-        // registrations that have lost their space
488
+		// tickets left sorted by ID
489
+		$tickets_remaining = array();
490
+		// registrations that have lost their space
491 491
 		$ejected_registrations = array();
492 492
 		foreach ( $registrations as $REG_ID => $registration ) {
493
-            if (
494
-                $registration->status_ID() === EEM_Registration::status_id_approved
495
-                || apply_filters(
496
-                    'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment',
497
-                    false,
498
-                    $registration,
499
-                    $revisit
500
-                )
501
-            ) {
502
-                continue;
493
+			if (
494
+				$registration->status_ID() === EEM_Registration::status_id_approved
495
+				|| apply_filters(
496
+					'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment',
497
+					false,
498
+					$registration,
499
+					$revisit
500
+				)
501
+			) {
502
+				continue;
503 503
 			}
504 504
 			$EVT_ID = $registration->event_ID();
505
-            $ticket = $registration->ticket();
506
-            if ( ! isset($tickets_remaining[$ticket->ID()])) {
507
-                $tickets_remaining[$ticket->ID()] = $ticket->remaining();
508
-            }
509
-            if ($tickets_remaining[$ticket->ID()] > 0) {
510
-                if ( ! isset($event_reg_count[$EVT_ID])) {
511
-                    $event_reg_count[$EVT_ID] = 0;
512
-                }
513
-                $event_reg_count[$EVT_ID]++;
514
-                if ( ! isset($event_spaces_remaining[$EVT_ID])) {
515
-                    $event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale();
516
-                }
517
-            }
505
+			$ticket = $registration->ticket();
506
+			if ( ! isset($tickets_remaining[$ticket->ID()])) {
507
+				$tickets_remaining[$ticket->ID()] = $ticket->remaining();
508
+			}
509
+			if ($tickets_remaining[$ticket->ID()] > 0) {
510
+				if ( ! isset($event_reg_count[$EVT_ID])) {
511
+					$event_reg_count[$EVT_ID] = 0;
512
+				}
513
+				$event_reg_count[$EVT_ID]++;
514
+				if ( ! isset($event_spaces_remaining[$EVT_ID])) {
515
+					$event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale();
516
+				}
517
+			}
518 518
 			if (
519 519
 				$revisit
520 520
 				&& (
521
-                    $tickets_remaining[$ticket->ID()] === 0
522
-				    || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ]
523
-                )
521
+					$tickets_remaining[$ticket->ID()] === 0
522
+					|| $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ]
523
+				)
524 524
 			) {
525 525
 				$ejected_registrations[ $REG_ID ] = $registration->event();
526 526
 				if ( $registration->status_ID() !== EEM_Registration::status_id_wait_list ) {
@@ -589,9 +589,9 @@  discard block
 block discarded – undo
589 589
 				'layout_strategy'		=> new EE_Template_Layout(
590 590
 					array(
591 591
 						'layout_template_file' => SPCO_REG_STEPS_PATH
592
-						                          . $this->_slug
593
-						                          . DS
594
-						                          . 'sold_out_events.template.php',
592
+												  . $this->_slug
593
+												  . DS
594
+												  . 'sold_out_events.template.php',
595 595
 						'template_args'        => apply_filters(
596 596
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
597 597
 							array(
@@ -644,9 +644,9 @@  discard block
 block discarded – undo
644 644
 				'layout_strategy' => new EE_Template_Layout(
645 645
 					array(
646 646
 						'layout_template_file' => SPCO_REG_STEPS_PATH
647
-						                          . $this->_slug
648
-						                          . DS
649
-						                          . 'sold_out_events.template.php',
647
+												  . $this->_slug
648
+												  . DS
649
+												  . 'sold_out_events.template.php',
650 650
 						'template_args'        => apply_filters(
651 651
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args',
652 652
 							array(
@@ -694,9 +694,9 @@  discard block
 block discarded – undo
694 694
 				'layout_strategy'		=> new EE_Template_Layout(
695 695
 					array(
696 696
 						'layout_template_file' => SPCO_REG_STEPS_PATH
697
-						                          . $this->_slug
698
-						                          . DS
699
-						                          . 'events_requiring_pre_approval.template.php', // layout_template
697
+												  . $this->_slug
698
+												  . DS
699
+												  . 'events_requiring_pre_approval.template.php', // layout_template
700 700
 						'template_args'        => apply_filters(
701 701
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
702 702
 							array(
@@ -734,9 +734,9 @@  discard block
 block discarded – undo
734 734
 				'layout_strategy' 	=> new EE_Template_Layout(
735 735
 					array(
736 736
 						'layout_template_file' => SPCO_REG_STEPS_PATH
737
-						                          . $this->_slug
738
-						                          . DS
739
-						                          . 'no_payment_required.template.php', // layout_template
737
+												  . $this->_slug
738
+												  . DS
739
+												  . 'no_payment_required.template.php', // layout_template
740 740
 						'template_args'        => apply_filters(
741 741
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args',
742 742
 							array(
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
 					$available_payment_method_options[ $payment_method->slug() ] = $payment_method_button;
965 965
 				}
966 966
 				$payment_methods_billing_info[ $payment_method->slug()
967
-				                               . '-info' ] = $this->_payment_method_billing_info(
967
+											   . '-info' ] = $this->_payment_method_billing_info(
968 968
 					$payment_method
969 969
 				);
970 970
 			}
@@ -1152,7 +1152,7 @@  discard block
 block discarded – undo
1152 1152
 		// fill form with attendee info if applicable
1153 1153
 		if (
1154 1154
 			$payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form
1155
-		    && $this->checkout->transaction_has_primary_registrant()
1155
+			&& $this->checkout->transaction_has_primary_registrant()
1156 1156
 		) {
1157 1157
 			$payment_method_billing_form->populate_from_attendee(
1158 1158
 				$this->checkout->transaction->primary_registration()->attendee()
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
 		// and debug content
1162 1162
 		if (
1163 1163
 			$payment_method_billing_form instanceof EE_Billing_Info_Form
1164
-		    && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1164
+			&& $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1165 1165
 		) {
1166 1166
 			$payment_method_billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1167 1167
 				$payment_method_billing_form
@@ -1336,7 +1336,7 @@  discard block
 block discarded – undo
1336 1336
 		}
1337 1337
 		// and debug content
1338 1338
 		if ( $this->checkout->billing_form instanceof EE_Billing_Info_Form
1339
-		     && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1339
+			 && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1340 1340
 		) {
1341 1341
 			$this->checkout->billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1342 1342
 				$this->checkout->billing_form
@@ -1506,8 +1506,8 @@  discard block
 block discarded – undo
1506 1506
 		}
1507 1507
 		// does this attendee already exist in the db ? we're searching using a combination of first name, last name, AND email address
1508 1508
 		if ( ! empty( $attendee_data['ATT_fname'] )
1509
-		     && ! empty( $attendee_data['ATT_lname'] )
1510
-		     && ! empty( $attendee_data['ATT_email'] )
1509
+			 && ! empty( $attendee_data['ATT_lname'] )
1510
+			 && ! empty( $attendee_data['ATT_email'] )
1511 1511
 		) {
1512 1512
 			$existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee(
1513 1513
 				array(
@@ -1754,7 +1754,7 @@  discard block
 block discarded – undo
1754 1754
 			$payment_status = $payment->status();
1755 1755
 			if (
1756 1756
 				$payment_status === EEM_Payment::status_id_approved
1757
-			    || $payment_status === EEM_Payment::status_id_pending
1757
+				|| $payment_status === EEM_Payment::status_id_pending
1758 1758
 			) {
1759 1759
 				return true;
1760 1760
 			} else {
@@ -1980,8 +1980,8 @@  discard block
 block discarded – undo
1980 1980
 			return false;
1981 1981
 		}
1982 1982
 		if ( ! $primary_registration->_add_relation_to( $this->checkout->primary_attendee_obj, 'Attendee' )
1983
-		       instanceof
1984
-		       EE_Attendee
1983
+			   instanceof
1984
+			   EE_Attendee
1985 1985
 		) {
1986 1986
 			EE_Error::add_error(
1987 1987
 				sprintf(
@@ -2699,19 +2699,19 @@  discard block
 block discarded – undo
2699 2699
 
2700 2700
 
2701 2701
 
2702
-    /**
2703
-     *    __sleep
2704
-     * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization
2705
-     * EE_Checkout will handle the reimplementation of itself upon waking,
2706
-     * but we won't bother with the reg form, because if needed, it will be regenerated anyways
2707
-     *
2708
-     * @return array
2709
-     */
2710
-    public function __sleep()
2711
-    {
2712
-        // remove the reg form and the checkout
2713
-        return array_diff( array_keys( get_object_vars( $this ) ), array( 'reg_form', 'checkout', 'line_item_display' ) );
2714
-    }
2702
+	/**
2703
+	 *    __sleep
2704
+	 * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization
2705
+	 * EE_Checkout will handle the reimplementation of itself upon waking,
2706
+	 * but we won't bother with the reg form, because if needed, it will be regenerated anyways
2707
+	 *
2708
+	 * @return array
2709
+	 */
2710
+	public function __sleep()
2711
+	{
2712
+		// remove the reg form and the checkout
2713
+		return array_diff( array_keys( get_object_vars( $this ) ), array( 'reg_form', 'checkout', 'line_item_display' ) );
2714
+	}
2715 2715
 
2716 2716
 
2717 2717
 
Please login to merge, or discard this patch.
Spacing   +362 added lines, -362 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -38,32 +38,32 @@  discard block
 block discarded – undo
38 38
 	public static function set_hooks() {
39 39
 		add_filter(
40 40
 			'FHEE__SPCO__EE_Line_Item_Filter_Collection',
41
-			array( 'EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters' )
41
+			array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters')
42 42
 		);
43 43
 		add_action(
44 44
 			'wp_ajax_switch_spco_billing_form',
45
-			array( 'EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form' )
45
+			array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form')
46 46
 		);
47 47
 		add_action(
48 48
 			'wp_ajax_nopriv_switch_spco_billing_form',
49
-			array( 'EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form' )
49
+			array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form')
50 50
 		);
51
-		add_action( 'wp_ajax_save_payer_details', array( 'EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details' ) );
51
+		add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details'));
52 52
 		add_action(
53 53
 			'wp_ajax_nopriv_save_payer_details',
54
-			array( 'EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details' )
54
+			array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')
55 55
 		);
56 56
 		add_action(
57 57
 			'wp_ajax_get_transaction_details_for_gateways',
58
-			array( 'EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details' )
58
+			array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details')
59 59
 		);
60 60
 		add_action(
61 61
 			'wp_ajax_nopriv_get_transaction_details_for_gateways',
62
-			array( 'EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details' )
62
+			array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details')
63 63
 		);
64 64
 		add_filter(
65 65
 			'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
66
-			array( 'EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method' ),
66
+			array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'),
67 67
 			10,
68 68
 			1
69 69
 		);
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	 * @throws \EE_Error
78 78
 	 */
79 79
 	public static function switch_spco_billing_form() {
80
-		EED_Single_Page_Checkout::process_ajax_request( 'switch_payment_method' );
80
+		EED_Single_Page_Checkout::process_ajax_request('switch_payment_method');
81 81
 	}
82 82
 
83 83
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 * @throws \EE_Error
89 89
 	 */
90 90
 	public static function save_payer_details() {
91
-		EED_Single_Page_Checkout::process_ajax_request( 'save_payer_details_via_ajax' );
91
+		EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax');
92 92
 	}
93 93
 
94 94
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 * @throws \EE_Error
100 100
 	 */
101 101
 	public static function get_transaction_details() {
102
-		EED_Single_Page_Checkout::process_ajax_request( 'get_transaction_details_for_gateways' );
102
+		EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways');
103 103
 	}
104 104
 
105 105
 
@@ -126,10 +126,10 @@  discard block
 block discarded – undo
126 126
 	 * @access    public
127 127
 	 * @param    EE_Checkout $checkout
128 128
 	 */
129
-	public function __construct( EE_Checkout $checkout ) {
129
+	public function __construct(EE_Checkout $checkout) {
130 130
 		$this->_slug = 'payment_options';
131
-		$this->_name = __( 'Payment Options', 'event_espresso' );
132
-		$this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php';
131
+		$this->_name = __('Payment Options', 'event_espresso');
132
+		$this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'payment_options_main.template.php';
133 133
 		$this->checkout = $checkout;
134 134
 		$this->_reset_success_message();
135 135
 		$this->set_instructions(
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	/**
155 155
 	 * @param null $line_item_display
156 156
 	 */
157
-	public function set_line_item_display( $line_item_display ) {
157
+	public function set_line_item_display($line_item_display) {
158 158
 		$this->line_item_display = $line_item_display;
159 159
 	}
160 160
 
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
 	/**
173 173
 	 * @param boolean $handle_IPN_in_this_request
174 174
 	 */
175
-	public function set_handle_IPN_in_this_request( $handle_IPN_in_this_request ) {
176
-		$this->handle_IPN_in_this_request = filter_var( $handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN );
175
+	public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) {
176
+		$this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN);
177 177
 	}
178 178
 
179 179
 
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
 	public function enqueue_styles_and_scripts() {
209 209
 		$transaction = $this->checkout->transaction;
210 210
 		//if the transaction isn't set or nothing is owed on it, don't enqueue any JS
211
-		if( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats( $transaction->remaining(), 0 ) ) {
211
+		if ( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) {
212 212
 			return;
213 213
 		}
214
-		foreach( EEM_Payment_Method::instance()->get_all_for_transaction( $transaction, EEM_Payment_Method::scope_cart ) as $payment_method ) {
214
+		foreach (EEM_Payment_Method::instance()->get_all_for_transaction($transaction, EEM_Payment_Method::scope_cart) as $payment_method) {
215 215
 			$type_obj = $payment_method->type_obj();
216
-			if( $type_obj instanceof EE_PMT_Base ) {
217
-				$billing_form = $type_obj->generate_new_billing_form( $transaction );
218
-				if( $billing_form instanceof EE_Form_Section_Proper ) {
216
+			if ($type_obj instanceof EE_PMT_Base) {
217
+				$billing_form = $type_obj->generate_new_billing_form($transaction);
218
+				if ($billing_form instanceof EE_Form_Section_Proper) {
219 219
 					$billing_form->enqueue_js();
220 220
 				}
221 221
 			}
@@ -240,20 +240,20 @@  discard block
 block discarded – undo
240 240
 			// 	$ 0.00 transactions (no payment required)
241 241
 			! $this->checkout->payment_required()
242 242
 			// but do NOT remove if current action being called belongs to this reg step
243
-			&& ! is_callable( array( $this, $this->checkout->action ) )
243
+			&& ! is_callable(array($this, $this->checkout->action))
244 244
 			&& ! $this->completed()
245 245
 		) {
246 246
 			// and if so, then we no longer need the Payment Options step
247
-			if ( $this->is_current_step() ) {
247
+			if ($this->is_current_step()) {
248 248
 				$this->checkout->generate_reg_form = false;
249 249
 			}
250
-			$this->checkout->remove_reg_step( $this->_slug );
250
+			$this->checkout->remove_reg_step($this->_slug);
251 251
 			// DEBUG LOG
252 252
 			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
253 253
 			return false;
254 254
 		}
255 255
 		// load EEM_Payment_Method
256
-		EE_Registry::instance()->load_model( 'Payment_Method' );
256
+		EE_Registry::instance()->load_model('Payment_Method');
257 257
 		// get all active payment methods
258 258
 		$this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
259 259
 			$this->checkout->transaction,
@@ -280,16 +280,16 @@  discard block
 block discarded – undo
280 280
 		$insufficient_spaces_available = array();
281 281
 		$no_payment_required = true;
282 282
 		// loop thru registrations to gather info
283
-		$registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params );
283
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
284 284
 		$ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
285 285
 			$registrations,
286 286
 			$this->checkout->revisit
287 287
 		);
288
-		foreach ( $registrations as $REG_ID => $registration ) {
288
+		foreach ($registrations as $REG_ID => $registration) {
289 289
             /** @var $registration EE_Registration */
290 290
             // has this registration lost it's space ?
291
-			if ( isset( $ejected_registrations[ $REG_ID ] ) ) {
292
-				$insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event();
291
+			if (isset($ejected_registrations[$REG_ID])) {
292
+				$insufficient_spaces_available[$registration->event()->ID()] = $registration->event();
293 293
 				continue;
294 294
 			}
295 295
             // event requires admin approval
@@ -310,11 +310,11 @@  discard block
 block discarded – undo
310 310
 				&& $registration->status_ID() !== EEM_Registration::status_id_approved
311 311
                 && (
312 312
                     $registration->event()->is_sold_out()
313
-                    || $registration->event()->is_sold_out( true )
313
+                    || $registration->event()->is_sold_out(true)
314 314
                 )
315 315
             ) {
316 316
                 // add event to list of events that are sold out
317
-                $sold_out_events[ $registration->event()->ID() ] = $registration->event();
317
+                $sold_out_events[$registration->event()->ID()] = $registration->event();
318 318
                 do_action(
319 319
                     'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
320 320
                     $registration->event(),
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
                 continue;
324 324
 			}
325 325
 			// are they allowed to pay now and is there monies owing?
326
-			if ( $registration->owes_monies_and_can_pay() ) {
327
-				$registrations_requiring_payment[ $REG_ID ] = $registration;
326
+			if ($registration->owes_monies_and_can_pay()) {
327
+				$registrations_requiring_payment[$REG_ID] = $registration;
328 328
 				do_action(
329 329
 					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment',
330 330
 					$registration->event(),
@@ -335,29 +335,29 @@  discard block
 block discarded – undo
335 335
 				&& $registration->status_ID() !== EEM_Registration::status_id_not_approved
336 336
 				&& $registration->ticket()->is_free()
337 337
 			) {
338
-				$registrations_for_free_events[ $registration->event()->ID() ] = $registration;
338
+				$registrations_for_free_events[$registration->event()->ID()] = $registration;
339 339
 			}
340 340
 		}
341 341
 		$subsections = array();
342 342
 		// now decide which template to load
343
-		if ( ! empty( $sold_out_events ) ) {
344
-			$subsections['sold_out_events'] = $this->_sold_out_events( $sold_out_events );
343
+		if ( ! empty($sold_out_events)) {
344
+			$subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events);
345 345
 		}
346
-		if ( ! empty( $insufficient_spaces_available ) ) {
346
+		if ( ! empty($insufficient_spaces_available)) {
347 347
 			$subsections['insufficient_space'] = $this->_insufficient_spaces_available(
348 348
 				$insufficient_spaces_available
349 349
 			);
350 350
 		}
351
-		if ( ! empty( $registrations_requiring_pre_approval ) ) {
351
+		if ( ! empty($registrations_requiring_pre_approval)) {
352 352
 			$subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval(
353 353
 				$registrations_requiring_pre_approval
354 354
 			);
355 355
 		}
356
-		if ( ! empty( $registrations_for_free_events ) ) {
357
-			$subsections['no_payment_required'] = $this->_no_payment_required( $registrations_for_free_events );
356
+		if ( ! empty($registrations_for_free_events)) {
357
+			$subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events);
358 358
 		}
359
-		if ( ! empty( $registrations_requiring_payment ) ) {
360
-			if ( $this->checkout->amount_owing > 0 ) {
359
+		if ( ! empty($registrations_requiring_payment)) {
360
+			if ($this->checkout->amount_owing > 0) {
361 361
 				// autoload Line_Item_Display classes
362 362
 				EEH_Autoloader::register_line_item_filter_autoloaders();
363 363
 				$line_item_filter_processor = new EE_Line_Item_Filter_Processor(
@@ -370,15 +370,15 @@  discard block
 block discarded – undo
370 370
 				/** @var EE_Line_Item $filtered_line_item_tree */
371 371
 				$filtered_line_item_tree = $line_item_filter_processor->process();
372 372
 				EEH_Autoloader::register_line_item_display_autoloaders();
373
-				$this->set_line_item_display( new EE_Line_Item_Display( 'spco' ) );
373
+				$this->set_line_item_display(new EE_Line_Item_Display('spco'));
374 374
 				$subsections['payment_options'] = $this->_display_payment_options(
375 375
 					$this->line_item_display->display_line_item(
376 376
 						$filtered_line_item_tree,
377
-						array( 'registrations' => $registrations )
377
+						array('registrations' => $registrations)
378 378
 					)
379 379
 				);
380 380
 				$this->checkout->amount_owing = $filtered_line_item_tree->total();
381
-				$this->_apply_registration_payments_to_amount_owing( $registrations );
381
+				$this->_apply_registration_payments_to_amount_owing($registrations);
382 382
 			}
383 383
 			$no_payment_required = false;
384 384
 		} else {
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 		$this->_save_selected_method_of_payment();
388 388
 
389 389
 		$subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs();
390
-		$subsections['extra_hidden_inputs' ] = $this->_extra_hidden_inputs( $no_payment_required );
390
+		$subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required);
391 391
 
392 392
 		return new EE_Form_Section_Proper(
393 393
 			array(
@@ -414,14 +414,14 @@  discard block
 block discarded – undo
414 414
 	 * @return \EE_Line_Item_Filter_Collection
415 415
 	 * @throws \EE_Error
416 416
 	 */
417
-	public static function add_spco_line_item_filters( EE_Line_Item_Filter_Collection $line_item_filter_collection ) {
418
-		if ( ! EE_Registry::instance()->SSN instanceof EE_Session ) {
417
+	public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) {
418
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
419 419
 			return $line_item_filter_collection;
420 420
 		}
421
-		if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout ) {
421
+		if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) {
422 422
 			return $line_item_filter_collection;
423 423
 		}
424
-		if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction ) {
424
+		if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) {
425 425
 			return $line_item_filter_collection;
426 426
 		}
427 427
 		$line_item_filter_collection->add(
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 				)
434 434
 			)
435 435
         );
436
-		$line_item_filter_collection->add( new EE_Non_Zero_Line_Item_Filter() );
436
+		$line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter());
437 437
 		return $line_item_filter_collection;
438 438
 	}
439 439
 
@@ -449,15 +449,15 @@  discard block
 block discarded – undo
449 449
 	 * @return \EE_Registration[]
450 450
 	 * @throws \EE_Error
451 451
 	 */
452
-	public static function remove_ejected_registrations( array $registrations ) {
452
+	public static function remove_ejected_registrations(array $registrations) {
453 453
 		$ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
454 454
 			$registrations,
455 455
 			EE_Registry::instance()->SSN->checkout()->revisit
456 456
 		);
457
-		foreach ( $registrations as $REG_ID => $registration ) {
457
+		foreach ($registrations as $REG_ID => $registration) {
458 458
 			// has this registration lost it's space ?
459
-			if ( isset( $ejected_registrations[ $REG_ID ] ) ) {
460
-				unset( $registrations[ $REG_ID ] );
459
+			if (isset($ejected_registrations[$REG_ID])) {
460
+				unset($registrations[$REG_ID]);
461 461
 				continue;
462 462
 			}
463 463
 		}
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	 * @return array
481 481
 	 * @throws \EE_Error
482 482
 	 */
483
-	public static function find_registrations_that_lost_their_space( array $registrations, $revisit = false ) {
483
+	public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) {
484 484
         // registrations per event
485 485
 		$event_reg_count = array();
486 486
 		// spaces left per event
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         $tickets_remaining = array();
490 490
         // registrations that have lost their space
491 491
 		$ejected_registrations = array();
492
-		foreach ( $registrations as $REG_ID => $registration ) {
492
+		foreach ($registrations as $REG_ID => $registration) {
493 493
             if (
494 494
                 $registration->status_ID() === EEM_Registration::status_id_approved
495 495
                 || apply_filters(
@@ -519,13 +519,13 @@  discard block
 block discarded – undo
519 519
 				$revisit
520 520
 				&& (
521 521
                     $tickets_remaining[$ticket->ID()] === 0
522
-				    || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ]
522
+				    || $event_reg_count[$EVT_ID] > $event_spaces_remaining[$EVT_ID]
523 523
                 )
524 524
 			) {
525
-				$ejected_registrations[ $REG_ID ] = $registration->event();
526
-				if ( $registration->status_ID() !== EEM_Registration::status_id_wait_list ) {
525
+				$ejected_registrations[$REG_ID] = $registration->event();
526
+				if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) {
527 527
 					/** @type EE_Registration_Processor $registration_processor */
528
-					$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
528
+					$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
529 529
 					// at this point, we should have enough details about the registrant to consider the registration NOT incomplete
530 530
 					$registration_processor->manually_update_registration_status(
531 531
 						$registration,
@@ -560,8 +560,8 @@  discard block
 block discarded – undo
560 560
 	 * @return void
561 561
 	 */
562 562
 	protected function _hide_reg_step_submit_button_if_revisit() {
563
-		if ( $this->checkout->revisit ) {
564
-			add_filter( 'FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string' );
563
+		if ($this->checkout->revisit) {
564
+			add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string');
565 565
 		}
566 566
 	}
567 567
 
@@ -575,13 +575,13 @@  discard block
 block discarded – undo
575 575
 	 * @return \EE_Form_Section_Proper
576 576
 	 * @throws \EE_Error
577 577
 	 */
578
-	private function _sold_out_events( $sold_out_events_array = array() ) {
578
+	private function _sold_out_events($sold_out_events_array = array()) {
579 579
 		// set some defaults
580 580
 		$this->checkout->selected_method_of_payment = 'events_sold_out';
581 581
 		$sold_out_events = '';
582
-		foreach ( $sold_out_events_array as $sold_out_event ) {
582
+		foreach ($sold_out_events_array as $sold_out_event) {
583 583
 			$sold_out_events .= EEH_HTML::li(
584
-				EEH_HTML::span( '  ' .$sold_out_event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text' )
584
+				EEH_HTML::span('  '.$sold_out_event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text')
585 585
 			);
586 586
 		}
587 587
 		return new EE_Form_Section_Proper(
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 								'sold_out_events_msg' => apply_filters(
600 600
 									'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg',
601 601
 									sprintf(
602
-										__( 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', 'event_espresso' ),
602
+										__('It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', 'event_espresso'),
603 603
 										'<strong>',
604 604
 										'</strong>',
605 605
 										'<br />'
@@ -624,14 +624,14 @@  discard block
 block discarded – undo
624 624
 	 * @return \EE_Form_Section_Proper
625 625
 	 * @throws \EE_Error
626 626
 	 */
627
-	private function _insufficient_spaces_available( $insufficient_spaces_events_array = array() ) {
627
+	private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) {
628 628
 		// set some defaults
629 629
 		$this->checkout->selected_method_of_payment = 'invoice';
630 630
 		$insufficient_space_events = '';
631
-		foreach ( $insufficient_spaces_events_array as $event ) {
632
-			if ( $event instanceof EE_Event ) {
631
+		foreach ($insufficient_spaces_events_array as $event) {
632
+			if ($event instanceof EE_Event) {
633 633
 				$insufficient_space_events .= EEH_HTML::li(
634
-					EEH_HTML::span( ' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text' )
634
+					EEH_HTML::span(' '.$event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text')
635 635
 				);
636 636
 			}
637 637
 		}
@@ -675,17 +675,17 @@  discard block
 block discarded – undo
675 675
 	 * @return \EE_Form_Section_Proper
676 676
 	 * @throws \EE_Error
677 677
 	 */
678
-	private function _registrations_requiring_pre_approval( $registrations_requiring_pre_approval = array() ) {
678
+	private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) {
679 679
 		$events_requiring_pre_approval = '';
680
-		foreach ( $registrations_requiring_pre_approval as $registration ) {
681
-			if ( $registration instanceof EE_Registration && $registration->event() instanceof EE_Event ) {
682
-				$events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li(
680
+		foreach ($registrations_requiring_pre_approval as $registration) {
681
+			if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) {
682
+				$events_requiring_pre_approval[$registration->event()->ID()] = EEH_HTML::li(
683 683
 					EEH_HTML::span(
684 684
 						'',
685 685
 						'',
686 686
 						'dashicons dashicons-marker ee-icon-size-16 orange-text'
687 687
 					)
688
-					. EEH_HTML::span( $registration->event()->name(), '', 'orange-text' )
688
+					. EEH_HTML::span($registration->event()->name(), '', 'orange-text')
689 689
 				);
690 690
 			}
691 691
 		}
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
 						'template_args'        => apply_filters(
701 701
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
702 702
 							array(
703
-								'events_requiring_pre_approval'     => implode( '', $events_requiring_pre_approval ),
703
+								'events_requiring_pre_approval'     => implode('', $events_requiring_pre_approval),
704 704
 								'events_requiring_pre_approval_msg' => apply_filters(
705 705
 									'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg',
706 706
 									__(
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 	 * @return \EE_Form_Section_Proper
726 726
 	 * @throws \EE_Error
727 727
 	 */
728
-	private function _no_payment_required( $registrations_for_free_events = array() ) {
728
+	private function _no_payment_required($registrations_for_free_events = array()) {
729 729
 		// set some defaults
730 730
 		$this->checkout->selected_method_of_payment = 'no_payment_required';
731 731
 		// generate no_payment_required form
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
 								'ticket_count'                  => array(),
746 746
 								'registrations_for_free_events' => $registrations_for_free_events,
747 747
 								'no_payment_required_msg'       => EEH_HTML::p(
748
-									__( 'This is a free event, so no billing will occur.', 'event_espresso' )
748
+									__('This is a free event, so no billing will occur.', 'event_espresso')
749 749
 								)
750 750
 							)
751 751
 						),
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
 	 * @return \EE_Form_Section_Proper
765 765
 	 * @throws \EE_Error
766 766
 	 */
767
-	private function _display_payment_options( $transaction_details = '' ) {
767
+	private function _display_payment_options($transaction_details = '') {
768 768
 		// has method_of_payment been set by no-js user?
769 769
 		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment();
770 770
 		// build payment options form
@@ -776,14 +776,14 @@  discard block
 block discarded – undo
776 776
 						'before_payment_options' => apply_filters(
777 777
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options',
778 778
 							new EE_Form_Section_Proper(
779
-								array( 'layout_strategy' => new EE_Div_Per_Section_Layout() )
779
+								array('layout_strategy' => new EE_Div_Per_Section_Layout())
780 780
 							)
781 781
 						),
782 782
 						'payment_options'        => $this->_setup_payment_options(),
783 783
 						'after_payment_options'  => apply_filters(
784 784
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options',
785 785
 							new EE_Form_Section_Proper(
786
-								array( 'layout_strategy' => new EE_Div_Per_Section_Layout() )
786
+								array('layout_strategy' => new EE_Div_Per_Section_Layout())
787 787
 							)
788 788
 						),
789 789
 					),
@@ -814,10 +814,10 @@  discard block
 block discarded – undo
814 814
 	 * @return \EE_Form_Section_Proper
815 815
 	 * @throws \EE_Error
816 816
 	 */
817
-	private function _extra_hidden_inputs( $no_payment_required = true ) {
817
+	private function _extra_hidden_inputs($no_payment_required = true) {
818 818
 		return new EE_Form_Section_Proper(
819 819
 			array(
820
-				'html_id'         => 'ee-' . $this->slug() . '-extra-hidden-inputs',
820
+				'html_id'         => 'ee-'.$this->slug().'-extra-hidden-inputs',
821 821
 				'layout_strategy' => new EE_Div_Per_Section_Layout(),
822 822
 				'subsections'     => array(
823 823
 					'spco_no_payment_required' => new EE_Hidden_Input(
@@ -849,16 +849,16 @@  discard block
 block discarded – undo
849 849
 	 * @access protected
850 850
 	 * @param array $registrations
851 851
 	 */
852
-	protected function _apply_registration_payments_to_amount_owing( array $registrations ) {
852
+	protected function _apply_registration_payments_to_amount_owing(array $registrations) {
853 853
 		$payments = array();
854
-		foreach ( $registrations as $registration ) {
855
-			if ( $registration instanceof EE_Registration && $registration->owes_monies_and_can_pay() ) {
854
+		foreach ($registrations as $registration) {
855
+			if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
856 856
 				$payments += $registration->registration_payments();
857 857
 			}
858 858
 		}
859
-		if ( ! empty( $payments ) ) {
860
-			foreach ( $payments as $payment ) {
861
-				if ( $payment instanceof EE_Registration_Payment ) {
859
+		if ( ! empty($payments)) {
860
+			foreach ($payments as $payment) {
861
+				if ($payment instanceof EE_Registration_Payment) {
862 862
 					$this->checkout->amount_owing -= $payment->amount();
863 863
 				}
864 864
 			}
@@ -874,11 +874,11 @@  discard block
 block discarded – undo
874 874
 	 * @param    bool $force_reset
875 875
 	 * @return    void
876 876
 	 */
877
-	private function _reset_selected_method_of_payment( $force_reset = false ) {
877
+	private function _reset_selected_method_of_payment($force_reset = false) {
878 878
 		$reset_payment_method = $force_reset
879 879
 			? true
880
-			: sanitize_text_field( EE_Registry::instance()->REQ->get( 'reset_payment_method', false ) );
881
-		if ( $reset_payment_method ) {
880
+			: sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false));
881
+		if ($reset_payment_method) {
882 882
 			$this->checkout->selected_method_of_payment = null;
883 883
 			$this->checkout->payment_method = null;
884 884
 			$this->checkout->billing_form = null;
@@ -897,12 +897,12 @@  discard block
 block discarded – undo
897 897
 	 * @param string $selected_method_of_payment
898 898
 	 * @return  void
899 899
 	 */
900
-	private function _save_selected_method_of_payment( $selected_method_of_payment = '' ) {
901
-		$selected_method_of_payment = ! empty( $selected_method_of_payment )
900
+	private function _save_selected_method_of_payment($selected_method_of_payment = '') {
901
+		$selected_method_of_payment = ! empty($selected_method_of_payment)
902 902
 			? $selected_method_of_payment
903 903
 			: $this->checkout->selected_method_of_payment;
904 904
 		EE_Registry::instance()->SSN->set_session_data(
905
-			array( 'selected_method_of_payment' => $selected_method_of_payment )
905
+			array('selected_method_of_payment' => $selected_method_of_payment)
906 906
 		);
907 907
 	}
908 908
 
@@ -918,19 +918,19 @@  discard block
 block discarded – undo
918 918
 		// load payment method classes
919 919
 		$this->checkout->available_payment_methods = $this->_get_available_payment_methods();
920 920
 		// switch up header depending on number of available payment methods
921
-		$payment_method_header = count( $this->checkout->available_payment_methods ) > 1
921
+		$payment_method_header = count($this->checkout->available_payment_methods) > 1
922 922
 			? apply_filters(
923 923
 				'FHEE__registration_page_payment_options__method_of_payment_hdr',
924
-				__( 'Please Select Your Method of Payment', 'event_espresso' )
924
+				__('Please Select Your Method of Payment', 'event_espresso')
925 925
 			)
926 926
 			: apply_filters(
927 927
 				'FHEE__registration_page_payment_options__method_of_payment_hdr',
928
-				__( 'Method of Payment', 'event_espresso' )
928
+				__('Method of Payment', 'event_espresso')
929 929
 			);
930 930
 		$available_payment_methods = array(
931 931
 			// display the "Payment Method" header
932 932
 			'payment_method_header' => new EE_Form_Section_HTML(
933
-				EEH_HTML::h4( $payment_method_header, 'method-of-payment-hdr' )
933
+				EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr')
934 934
 			)
935 935
 		);
936 936
 		// the list of actual payment methods ( invoice, paypal, etc ) in a  ( slug => HTML )  format
@@ -939,32 +939,32 @@  discard block
 block discarded – undo
939 939
 		// additional instructions to be displayed and hidden below payment methods (adding a clearing div to start)
940 940
 		$payment_methods_billing_info = array(
941 941
 			new EE_Form_Section_HTML(
942
-				EEH_HTML::div( '<br />', '', '', 'clear:both;' )
942
+				EEH_HTML::div('<br />', '', '', 'clear:both;')
943 943
 			)
944 944
 		);
945 945
 		// loop through payment methods
946
-		foreach ( $this->checkout->available_payment_methods as $payment_method ) {
947
-			if ( $payment_method instanceof EE_Payment_Method ) {
946
+		foreach ($this->checkout->available_payment_methods as $payment_method) {
947
+			if ($payment_method instanceof EE_Payment_Method) {
948 948
 				$payment_method_button = EEH_HTML::img(
949 949
 					$payment_method->button_url(),
950 950
 					$payment_method->name(),
951
-					'spco-payment-method-' . $payment_method->slug() . '-btn-img',
951
+					'spco-payment-method-'.$payment_method->slug().'-btn-img',
952 952
 					'spco-payment-method-btn-img'
953 953
 				);
954 954
 				// check if any payment methods are set as default
955 955
 				// if payment method is already selected OR nothing is selected and this payment method should be open_by_default
956 956
 				if (
957
-					( $this->checkout->selected_method_of_payment === $payment_method->slug() )
958
-					|| ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default() )
957
+					($this->checkout->selected_method_of_payment === $payment_method->slug())
958
+					|| ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default())
959 959
 				) {
960 960
 					$this->checkout->selected_method_of_payment = $payment_method->slug();
961 961
 					$this->_save_selected_method_of_payment();
962
-					$default_payment_method_option[ $payment_method->slug() ] = $payment_method_button;
962
+					$default_payment_method_option[$payment_method->slug()] = $payment_method_button;
963 963
 				} else {
964
-					$available_payment_method_options[ $payment_method->slug() ] = $payment_method_button;
964
+					$available_payment_method_options[$payment_method->slug()] = $payment_method_button;
965 965
 				}
966
-				$payment_methods_billing_info[ $payment_method->slug()
967
-				                               . '-info' ] = $this->_payment_method_billing_info(
966
+				$payment_methods_billing_info[$payment_method->slug()
967
+				                               . '-info'] = $this->_payment_method_billing_info(
968 968
 					$payment_method
969 969
 				);
970 970
 			}
@@ -994,12 +994,12 @@  discard block
 block discarded – undo
994 994
 	 * @return EE_Payment_Method[]
995 995
 	 */
996 996
 	protected function _get_available_payment_methods() {
997
-		if ( ! empty( $this->checkout->available_payment_methods ) ) {
997
+		if ( ! empty($this->checkout->available_payment_methods)) {
998 998
 			return $this->checkout->available_payment_methods;
999 999
 		}
1000 1000
 		$available_payment_methods = array();
1001 1001
 		// load EEM_Payment_Method
1002
-		EE_Registry::instance()->load_model( 'Payment_Method' );
1002
+		EE_Registry::instance()->load_model('Payment_Method');
1003 1003
 		/** @type EEM_Payment_Method $EEM_Payment_Method */
1004 1004
 		$EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method;
1005 1005
 		// get all active payment methods
@@ -1007,9 +1007,9 @@  discard block
 block discarded – undo
1007 1007
 			$this->checkout->transaction,
1008 1008
 			EEM_Payment_Method::scope_cart
1009 1009
 		);
1010
-		foreach ( $payment_methods as $payment_method ) {
1011
-			if ( $payment_method instanceof EE_Payment_Method ) {
1012
-				$available_payment_methods[ $payment_method->slug() ] = $payment_method;
1010
+		foreach ($payment_methods as $payment_method) {
1011
+			if ($payment_method instanceof EE_Payment_Method) {
1012
+				$available_payment_methods[$payment_method->slug()] = $payment_method;
1013 1013
 			}
1014 1014
 		}
1015 1015
 		return $available_payment_methods;
@@ -1024,14 +1024,14 @@  discard block
 block discarded – undo
1024 1024
 	 * @param    array $available_payment_method_options
1025 1025
 	 * @return    \EE_Form_Section_Proper
1026 1026
 	 */
1027
-	private function _available_payment_method_inputs( $available_payment_method_options = array() ) {
1027
+	private function _available_payment_method_inputs($available_payment_method_options = array()) {
1028 1028
 		// generate inputs
1029 1029
 		return new EE_Form_Section_Proper(
1030 1030
 			array(
1031 1031
 				'html_id'         => 'ee-available-payment-method-inputs',
1032 1032
 				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1033 1033
 				'subsections'     => array(
1034
-					'' => new EE_Radio_Button_Input (
1034
+					'' => new EE_Radio_Button_Input(
1035 1035
 						$available_payment_method_options,
1036 1036
 						array(
1037 1037
 							'html_name'          => 'selected_method_of_payment',
@@ -1056,28 +1056,28 @@  discard block
 block discarded – undo
1056 1056
 	 * @return    \EE_Form_Section_Proper
1057 1057
 	 * @throws \EE_Error
1058 1058
 	 */
1059
-	private function _payment_method_billing_info( EE_Payment_Method $payment_method ) {
1059
+	private function _payment_method_billing_info(EE_Payment_Method $payment_method) {
1060 1060
 		$currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug()
1061 1061
 			? true
1062 1062
 			: false;
1063 1063
 		// generate the billing form for payment method
1064 1064
 		$billing_form = $currently_selected
1065
-			? $this->_get_billing_form_for_payment_method( $payment_method )
1065
+			? $this->_get_billing_form_for_payment_method($payment_method)
1066 1066
 			: new EE_Form_Section_HTML();
1067 1067
 		$this->checkout->billing_form = $currently_selected
1068 1068
 			? $billing_form
1069 1069
 			: $this->checkout->billing_form;
1070 1070
 		// it's all in the details
1071 1071
 		$info_html = EEH_HTML::h3(
1072
-			__( 'Important information regarding your payment', 'event_espresso' ),
1072
+			__('Important information regarding your payment', 'event_espresso'),
1073 1073
 			'',
1074 1074
 			'spco-payment-method-hdr'
1075 1075
 		);
1076 1076
 		// add some info regarding the step, either from what's saved in the admin,
1077 1077
 		// or a default string depending on whether the PM has a billing form or not
1078
-		if ( $payment_method->description() ) {
1078
+		if ($payment_method->description()) {
1079 1079
 			$payment_method_info = $payment_method->description();
1080
-		} elseif ( $billing_form instanceof EE_Billing_Info_Form ) {
1080
+		} elseif ($billing_form instanceof EE_Billing_Info_Form) {
1081 1081
 			$payment_method_info = sprintf(
1082 1082
 				__(
1083 1083
 					'Please provide the following billing information, then click the "%1$s" button below in order to proceed.',
@@ -1087,7 +1087,7 @@  discard block
 block discarded – undo
1087 1087
 			);
1088 1088
 		} else {
1089 1089
 			$payment_method_info = sprintf(
1090
-				__( 'Please click the "%1$s" button below in order to proceed.', 'event_espresso' ),
1090
+				__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'),
1091 1091
 				$this->submit_button_text()
1092 1092
 			);
1093 1093
 		}
@@ -1101,13 +1101,13 @@  discard block
 block discarded – undo
1101 1101
 		);
1102 1102
 		return new EE_Form_Section_Proper(
1103 1103
 			array(
1104
-				'html_id'         => 'spco-payment-method-info-' . $payment_method->slug(),
1104
+				'html_id'         => 'spco-payment-method-info-'.$payment_method->slug(),
1105 1105
 				'html_class'      => 'spco-payment-method-info-dv',
1106 1106
 				// only display the selected or default PM
1107 1107
 				'html_style'      => $currently_selected ? '' : 'display:none;',
1108 1108
 				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1109 1109
 				'subsections'     => array(
1110
-					'info'         => new EE_Form_Section_HTML( $info_html ),
1110
+					'info'         => new EE_Form_Section_HTML($info_html),
1111 1111
 					'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML()
1112 1112
 				)
1113 1113
 			)
@@ -1125,15 +1125,15 @@  discard block
 block discarded – undo
1125 1125
 	 */
1126 1126
 	public function get_billing_form_html_for_payment_method() {
1127 1127
 		// how have they chosen to pay?
1128
-		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( true );
1128
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1129 1129
 		$this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment();
1130
-		if ( ! $this->checkout->payment_method instanceof EE_Payment_Method ) {
1130
+		if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) {
1131 1131
 			return false;
1132 1132
 		}
1133
-		if ( apply_filters(
1133
+		if (apply_filters(
1134 1134
 			'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1135 1135
 			false
1136
-		) ) {
1136
+		)) {
1137 1137
 			EE_Error::add_success(
1138 1138
 				apply_filters(
1139 1139
 					'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
@@ -1148,7 +1148,7 @@  discard block
 block discarded – undo
1148 1148
 			);
1149 1149
 		}
1150 1150
 		// now generate billing form for selected method of payment
1151
-		$payment_method_billing_form = $this->_get_billing_form_for_payment_method( $this->checkout->payment_method );
1151
+		$payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method);
1152 1152
 		// fill form with attendee info if applicable
1153 1153
 		if (
1154 1154
 			$payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form
@@ -1170,10 +1170,10 @@  discard block
 block discarded – undo
1170 1170
 		$billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper
1171 1171
 			? $payment_method_billing_form->get_html()
1172 1172
 			: '';
1173
-		$this->checkout->json_response->set_return_data( array( 'payment_method_info' => $billing_info ) );
1173
+		$this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info));
1174 1174
 		// localize validation rules for main form
1175 1175
 		$this->checkout->current_step->reg_form->localize_validation_rules();
1176
-		$this->checkout->json_response->add_validation_rules( EE_Form_Section_Proper::js_localization() );
1176
+		$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1177 1177
 		return true;
1178 1178
 	}
1179 1179
 
@@ -1187,18 +1187,18 @@  discard block
 block discarded – undo
1187 1187
 	 * @return \EE_Billing_Info_Form|\EE_Form_Section_HTML
1188 1188
 	 * @throws \EE_Error
1189 1189
 	 */
1190
-	private function _get_billing_form_for_payment_method( EE_Payment_Method $payment_method ) {
1190
+	private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) {
1191 1191
 		$billing_form = $payment_method->type_obj()->billing_form(
1192 1192
 			$this->checkout->transaction,
1193
-			array( 'amount_owing' => $this->checkout->amount_owing )
1193
+			array('amount_owing' => $this->checkout->amount_owing)
1194 1194
 		);
1195
-		if ( $billing_form instanceof EE_Billing_Info_Form ) {
1195
+		if ($billing_form instanceof EE_Billing_Info_Form) {
1196 1196
 			if (
1197 1197
 				apply_filters(
1198 1198
 					'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1199 1199
 					false
1200 1200
 				)
1201
-				&& EE_Registry::instance()->REQ->is_set( 'payment_method' )
1201
+				&& EE_Registry::instance()->REQ->is_set('payment_method')
1202 1202
 			) {
1203 1203
 				EE_Error::add_success(
1204 1204
 					apply_filters(
@@ -1240,15 +1240,15 @@  discard block
 block discarded – undo
1240 1240
 		$request_param = 'selected_method_of_payment'
1241 1241
 	) {
1242 1242
 		// is selected_method_of_payment set in the request ?
1243
-		$selected_method_of_payment = EE_Registry::instance()->REQ->get( $request_param, false );
1244
-		if ( $selected_method_of_payment ) {
1243
+		$selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false);
1244
+		if ($selected_method_of_payment) {
1245 1245
 			// sanitize it
1246
-			$selected_method_of_payment = is_array( $selected_method_of_payment )
1247
-				? array_shift( $selected_method_of_payment )
1246
+			$selected_method_of_payment = is_array($selected_method_of_payment)
1247
+				? array_shift($selected_method_of_payment)
1248 1248
 				: $selected_method_of_payment;
1249
-			$selected_method_of_payment = sanitize_text_field( $selected_method_of_payment );
1249
+			$selected_method_of_payment = sanitize_text_field($selected_method_of_payment);
1250 1250
 			// store it in the session so that it's available for all subsequent requests including AJAX
1251
-			$this->_save_selected_method_of_payment( $selected_method_of_payment );
1251
+			$this->_save_selected_method_of_payment($selected_method_of_payment);
1252 1252
 		} else {
1253 1253
 			// or is is set in the session ?
1254 1254
 			$selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data(
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
 			);
1257 1257
 		}
1258 1258
 		// do ya really really gotta have it?
1259
-		if ( empty( $selected_method_of_payment ) && $required ) {
1259
+		if (empty($selected_method_of_payment) && $required) {
1260 1260
 			EE_Error::add_error(
1261 1261
 				sprintf(
1262 1262
 					__(
@@ -1265,7 +1265,7 @@  discard block
 block discarded – undo
1265 1265
 					),
1266 1266
 					'<br/>',
1267 1267
 					'<br/>',
1268
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1268
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
1269 1269
 				),
1270 1270
 				__FILE__,
1271 1271
 				__FUNCTION__,
@@ -1292,13 +1292,13 @@  discard block
 block discarded – undo
1292 1292
 	 * @throws \EE_Error
1293 1293
 	 */
1294 1294
 	public function switch_payment_method() {
1295
-		if ( ! $this->_verify_payment_method_is_set() ) {
1295
+		if ( ! $this->_verify_payment_method_is_set()) {
1296 1296
 			return false;
1297 1297
 		}
1298
-		if ( apply_filters(
1298
+		if (apply_filters(
1299 1299
 			'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1300 1300
 			false
1301
-		) ) {
1301
+		)) {
1302 1302
 			EE_Error::add_success(
1303 1303
 				apply_filters(
1304 1304
 					'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
@@ -1313,7 +1313,7 @@  discard block
 block discarded – undo
1313 1313
 			);
1314 1314
 		}
1315 1315
 		// generate billing form for selected method of payment if it hasn't been done already
1316
-		if ( $this->checkout->payment_method->type_obj()->has_billing_form() ) {
1316
+		if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1317 1317
 			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1318 1318
 				$this->checkout->payment_method
1319 1319
 			);
@@ -1335,7 +1335,7 @@  discard block
 block discarded – undo
1335 1335
 			);
1336 1336
 		}
1337 1337
 		// and debug content
1338
-		if ( $this->checkout->billing_form instanceof EE_Billing_Info_Form
1338
+		if ($this->checkout->billing_form instanceof EE_Billing_Info_Form
1339 1339
 		     && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1340 1340
 		) {
1341 1341
 			$this->checkout->billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
@@ -1343,15 +1343,15 @@  discard block
 block discarded – undo
1343 1343
 			);
1344 1344
 		}
1345 1345
 		// get html and validation rules for form
1346
-		if ( $this->checkout->billing_form instanceof EE_Form_Section_Proper ) {
1346
+		if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) {
1347 1347
 			$this->checkout->json_response->set_return_data(
1348
-				array( 'payment_method_info' => $this->checkout->billing_form->get_html() )
1348
+				array('payment_method_info' => $this->checkout->billing_form->get_html())
1349 1349
 			);
1350 1350
 			// localize validation rules for main form
1351
-			$this->checkout->billing_form->localize_validation_rules( true );
1352
-			$this->checkout->json_response->add_validation_rules( EE_Form_Section_Proper::js_localization() );
1351
+			$this->checkout->billing_form->localize_validation_rules(true);
1352
+			$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1353 1353
 		} else {
1354
-			$this->checkout->json_response->set_return_data( array( 'payment_method_info' => '' ) );
1354
+			$this->checkout->json_response->set_return_data(array('payment_method_info' => ''));
1355 1355
 		}
1356 1356
 		//prevents advancement to next step
1357 1357
 		$this->checkout->continue_reg = false;
@@ -1368,18 +1368,18 @@  discard block
 block discarded – undo
1368 1368
 	 */
1369 1369
 	protected function _verify_payment_method_is_set() {
1370 1370
 		// generate billing form for selected method of payment if it hasn't been done already
1371
-		if ( empty( $this->checkout->selected_method_of_payment ) ) {
1371
+		if (empty($this->checkout->selected_method_of_payment)) {
1372 1372
 			// how have they chosen to pay?
1373
-			$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( true );
1373
+			$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1374 1374
 		} else {
1375 1375
 			// choose your own adventure based on method_of_payment
1376
-			switch ( $this->checkout->selected_method_of_payment ) {
1376
+			switch ($this->checkout->selected_method_of_payment) {
1377 1377
 				case 'events_sold_out' :
1378 1378
 					EE_Error::add_attention(
1379 1379
 						apply_filters(
1380 1380
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg',
1381
-							__( 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.',
1382
-								'event_espresso' )
1381
+							__('It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.',
1382
+								'event_espresso')
1383 1383
 						),
1384 1384
 						__FILE__, __FUNCTION__, __LINE__
1385 1385
 					);
@@ -1389,7 +1389,7 @@  discard block
 block discarded – undo
1389 1389
 					EE_Error::add_attention(
1390 1390
 						apply_filters(
1391 1391
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg',
1392
-							__( 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', 'event_espresso' )
1392
+							__('It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', 'event_espresso')
1393 1393
 						),
1394 1394
 						__FILE__, __FUNCTION__, __LINE__
1395 1395
 					);
@@ -1399,7 +1399,7 @@  discard block
 block discarded – undo
1399 1399
 					EE_Error::add_attention(
1400 1400
 						apply_filters(
1401 1401
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg',
1402
-							__( 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', 'event_espresso' )
1402
+							__('It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', 'event_espresso')
1403 1403
 						),
1404 1404
 						__FILE__, __FUNCTION__, __LINE__
1405 1405
 					);
@@ -1409,7 +1409,7 @@  discard block
 block discarded – undo
1409 1409
 			}
1410 1410
 		}
1411 1411
 		// verify payment method
1412
-		if ( ! $this->checkout->payment_method instanceof EE_Payment_Method ) {
1412
+		if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) {
1413 1413
 			// get payment method for selected method of payment
1414 1414
 			$this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment();
1415 1415
 		}
@@ -1428,25 +1428,25 @@  discard block
 block discarded – undo
1428 1428
 	 * @throws \EE_Error
1429 1429
 	 */
1430 1430
 	public function save_payer_details_via_ajax() {
1431
-		if ( ! $this->_verify_payment_method_is_set() ) {
1431
+		if ( ! $this->_verify_payment_method_is_set()) {
1432 1432
 			return;
1433 1433
 		}
1434 1434
 		// generate billing form for selected method of payment if it hasn't been done already
1435
-		if ( $this->checkout->payment_method->type_obj()->has_billing_form() ) {
1435
+		if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1436 1436
 			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1437 1437
 				$this->checkout->payment_method
1438 1438
 			);
1439 1439
 		}
1440 1440
 		// generate primary attendee from payer info if applicable
1441
-		if ( ! $this->checkout->transaction_has_primary_registrant() ) {
1441
+		if ( ! $this->checkout->transaction_has_primary_registrant()) {
1442 1442
 			$attendee = $this->_create_attendee_from_request_data();
1443
-			if ( $attendee instanceof EE_Attendee ) {
1444
-				foreach ( $this->checkout->transaction->registrations() as $registration ) {
1445
-					if ( $registration->is_primary_registrant() ) {
1443
+			if ($attendee instanceof EE_Attendee) {
1444
+				foreach ($this->checkout->transaction->registrations() as $registration) {
1445
+					if ($registration->is_primary_registrant()) {
1446 1446
 						$this->checkout->primary_attendee_obj = $attendee;
1447
-						$registration->_add_relation_to( $attendee, 'Attendee' );
1448
-						$registration->set_attendee_id( $attendee->ID() );
1449
-						$registration->update_cache_after_object_save( 'Attendee', $attendee );
1447
+						$registration->_add_relation_to($attendee, 'Attendee');
1448
+						$registration->set_attendee_id($attendee->ID());
1449
+						$registration->update_cache_after_object_save('Attendee', $attendee);
1450 1450
 					}
1451 1451
 				}
1452 1452
 			}
@@ -1464,50 +1464,50 @@  discard block
 block discarded – undo
1464 1464
 	 */
1465 1465
 	protected function _create_attendee_from_request_data() {
1466 1466
 		// get State ID
1467
-		$STA_ID = ! empty( $_REQUEST['state'] ) ? sanitize_text_field( $_REQUEST['state'] ) : '';
1468
-		if ( ! empty( $STA_ID ) ) {
1467
+		$STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : '';
1468
+		if ( ! empty($STA_ID)) {
1469 1469
 			// can we get state object from name ?
1470
-			EE_Registry::instance()->load_model( 'State' );
1471
-			$state = EEM_State::instance()->get_col( array( array( 'STA_name' => $STA_ID ), 'limit' => 1 ), 'STA_ID' );
1472
-			$STA_ID = is_array( $state ) && ! empty( $state ) ? reset( $state ) : $STA_ID;
1470
+			EE_Registry::instance()->load_model('State');
1471
+			$state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID');
1472
+			$STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID;
1473 1473
 		}
1474 1474
 		// get Country ISO
1475
-		$CNT_ISO = ! empty( $_REQUEST['country'] ) ? sanitize_text_field( $_REQUEST['country'] ) : '';
1476
-		if ( ! empty( $CNT_ISO ) ) {
1475
+		$CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : '';
1476
+		if ( ! empty($CNT_ISO)) {
1477 1477
 			// can we get country object from name ?
1478
-			EE_Registry::instance()->load_model( 'Country' );
1478
+			EE_Registry::instance()->load_model('Country');
1479 1479
 			$country = EEM_Country::instance()->get_col(
1480
-				array( array( 'CNT_name' => $CNT_ISO ), 'limit' => 1 ),
1480
+				array(array('CNT_name' => $CNT_ISO), 'limit' => 1),
1481 1481
 				'CNT_ISO'
1482 1482
 			);
1483
-			$CNT_ISO = is_array( $country ) && ! empty( $country ) ? reset( $country ) : $CNT_ISO;
1483
+			$CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO;
1484 1484
 		}
1485 1485
 		// grab attendee data
1486 1486
 		$attendee_data = array(
1487
-			'ATT_fname'    => ! empty( $_REQUEST['first_name'] ) ? sanitize_text_field( $_REQUEST['first_name'] ) : '',
1488
-			'ATT_lname'    => ! empty( $_REQUEST['last_name'] ) ? sanitize_text_field( $_REQUEST['last_name'] ) : '',
1489
-			'ATT_email'    => ! empty( $_REQUEST['email'] ) ? sanitize_email( $_REQUEST['email'] ) : '',
1490
-			'ATT_address'  => ! empty( $_REQUEST['address'] ) ? sanitize_text_field( $_REQUEST['address'] ) : '',
1491
-			'ATT_address2' => ! empty( $_REQUEST['address2'] ) ? sanitize_text_field( $_REQUEST['address2'] ) : '',
1492
-			'ATT_city'     => ! empty( $_REQUEST['city'] ) ? sanitize_text_field( $_REQUEST['city'] ) : '',
1487
+			'ATT_fname'    => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '',
1488
+			'ATT_lname'    => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '',
1489
+			'ATT_email'    => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '',
1490
+			'ATT_address'  => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '',
1491
+			'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '',
1492
+			'ATT_city'     => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '',
1493 1493
 			'STA_ID'       => $STA_ID,
1494 1494
 			'CNT_ISO'      => $CNT_ISO,
1495
-			'ATT_zip'      => ! empty( $_REQUEST['zip'] ) ? sanitize_text_field( $_REQUEST['zip'] ) : '',
1496
-			'ATT_phone'    => ! empty( $_REQUEST['phone'] ) ? sanitize_text_field( $_REQUEST['phone'] ) : '',
1495
+			'ATT_zip'      => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '',
1496
+			'ATT_phone'    => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '',
1497 1497
 		);
1498 1498
 		// validate the email address since it is the most important piece of info
1499
-		if ( empty( $attendee_data['ATT_email'] ) || $attendee_data['ATT_email'] !== $_REQUEST['email'] ) {
1499
+		if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) {
1500 1500
 			EE_Error::add_error(
1501
-				__( 'An invalid email address was submitted.', 'event_espresso' ),
1501
+				__('An invalid email address was submitted.', 'event_espresso'),
1502 1502
 				__FILE__,
1503 1503
 				__FUNCTION__,
1504 1504
 				__LINE__
1505 1505
 			);
1506 1506
 		}
1507 1507
 		// does this attendee already exist in the db ? we're searching using a combination of first name, last name, AND email address
1508
-		if ( ! empty( $attendee_data['ATT_fname'] )
1509
-		     && ! empty( $attendee_data['ATT_lname'] )
1510
-		     && ! empty( $attendee_data['ATT_email'] )
1508
+		if ( ! empty($attendee_data['ATT_fname'])
1509
+		     && ! empty($attendee_data['ATT_lname'])
1510
+		     && ! empty($attendee_data['ATT_email'])
1511 1511
 		) {
1512 1512
 			$existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee(
1513 1513
 				array(
@@ -1516,19 +1516,19 @@  discard block
 block discarded – undo
1516 1516
 					'ATT_email' => $attendee_data['ATT_email']
1517 1517
 				)
1518 1518
 			);
1519
-			if ( $existing_attendee instanceof EE_Attendee ) {
1519
+			if ($existing_attendee instanceof EE_Attendee) {
1520 1520
 				return $existing_attendee;
1521 1521
 			}
1522 1522
 		}
1523 1523
 		// no existing attendee? kk let's create a new one
1524 1524
 		// kinda lame, but we need a first and last name to create an attendee, so use the email address if those don't exist
1525
-		$attendee_data['ATT_fname'] = ! empty( $attendee_data['ATT_fname'] )
1525
+		$attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname'])
1526 1526
 			? $attendee_data['ATT_fname']
1527 1527
 			: $attendee_data['ATT_email'];
1528
-		$attendee_data['ATT_lname'] = ! empty( $attendee_data['ATT_lname'] )
1528
+		$attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname'])
1529 1529
 			? $attendee_data['ATT_lname']
1530 1530
 			: $attendee_data['ATT_email'];
1531
-		return EE_Attendee::new_instance( $attendee_data );
1531
+		return EE_Attendee::new_instance($attendee_data);
1532 1532
 	}
1533 1533
 
1534 1534
 
@@ -1546,26 +1546,26 @@  discard block
 block discarded – undo
1546 1546
 		// how have they chosen to pay?
1547 1547
 		$this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free()
1548 1548
 			? 'no_payment_required'
1549
-			: $this->_get_selected_method_of_payment( true );
1549
+			: $this->_get_selected_method_of_payment(true);
1550 1550
 		// choose your own adventure based on method_of_payment
1551
-		switch ( $this->checkout->selected_method_of_payment ) {
1551
+		switch ($this->checkout->selected_method_of_payment) {
1552 1552
 
1553 1553
 			case 'events_sold_out' :
1554 1554
 				$this->checkout->redirect = true;
1555 1555
 				$this->checkout->redirect_url = $this->checkout->cancel_page_url;
1556
-				$this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url );
1556
+				$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1557 1557
 				// mark this reg step as completed
1558 1558
 				$this->set_completed();
1559 1559
 				return false;
1560 1560
 				break;
1561 1561
 
1562 1562
 			case 'payments_closed' :
1563
-				if ( apply_filters(
1563
+				if (apply_filters(
1564 1564
 					'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success',
1565 1565
 					false
1566
-				) ) {
1566
+				)) {
1567 1567
 					EE_Error::add_success(
1568
-						__( 'no payment required at this time.', 'event_espresso' ),
1568
+						__('no payment required at this time.', 'event_espresso'),
1569 1569
 						__FILE__,
1570 1570
 						__FUNCTION__,
1571 1571
 						__LINE__
@@ -1577,12 +1577,12 @@  discard block
 block discarded – undo
1577 1577
 				break;
1578 1578
 
1579 1579
 			case 'no_payment_required' :
1580
-				if ( apply_filters(
1580
+				if (apply_filters(
1581 1581
 					'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success',
1582 1582
 					false
1583
-				) ) {
1583
+				)) {
1584 1584
 					EE_Error::add_success(
1585
-						__( 'no payment required.', 'event_espresso' ),
1585
+						__('no payment required.', 'event_espresso'),
1586 1586
 						__FILE__,
1587 1587
 						__FUNCTION__,
1588 1588
 						__LINE__
@@ -1602,15 +1602,15 @@  discard block
 block discarded – undo
1602 1602
 					EE_Registry::instance()->SSN->checkout()->revisit
1603 1603
 				);
1604 1604
 				// calculate difference between the two arrays
1605
-				$registrations = array_diff( $registrations, $ejected_registrations );
1606
-				if ( empty( $registrations ) ) {
1605
+				$registrations = array_diff($registrations, $ejected_registrations);
1606
+				if (empty($registrations)) {
1607 1607
 					$this->_redirect_because_event_sold_out();
1608 1608
 					return false;
1609 1609
 				}
1610 1610
 				$payment_successful = $this->_process_payment();
1611
-				if ( $payment_successful ) {
1611
+				if ($payment_successful) {
1612 1612
 					$this->checkout->continue_reg = true;
1613
-					$this->_maybe_set_completed( $this->checkout->payment_method );
1613
+					$this->_maybe_set_completed($this->checkout->payment_method);
1614 1614
 				} else {
1615 1615
 					$this->checkout->continue_reg = false;
1616 1616
 				}
@@ -1631,10 +1631,10 @@  discard block
 block discarded – undo
1631 1631
 		$this->checkout->continue_reg = false;
1632 1632
 		// set redirect URL
1633 1633
 		$this->checkout->redirect_url = add_query_arg(
1634
-			array( 'e_reg_url_link' => $this->checkout->reg_url_link ),
1634
+			array('e_reg_url_link' => $this->checkout->reg_url_link),
1635 1635
 			$this->checkout->current_step->reg_step_url()
1636 1636
 		);
1637
-		$this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url );
1637
+		$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1638 1638
 	}
1639 1639
 
1640 1640
 
@@ -1647,8 +1647,8 @@  discard block
 block discarded – undo
1647 1647
 	 * @return void
1648 1648
 	 * @throws \EE_Error
1649 1649
 	 */
1650
-	protected function _maybe_set_completed( EE_Payment_Method $payment_method ) {
1651
-		switch ( $payment_method->type_obj()->payment_occurs() ) {
1650
+	protected function _maybe_set_completed(EE_Payment_Method $payment_method) {
1651
+		switch ($payment_method->type_obj()->payment_occurs()) {
1652 1652
 			case EE_PMT_Base::offsite :
1653 1653
 				break;
1654 1654
 			case EE_PMT_Base::onsite :
@@ -1671,7 +1671,7 @@  discard block
 block discarded – undo
1671 1671
 	public function update_reg_step() {
1672 1672
 		$success = true;
1673 1673
 		// if payment required
1674
-		if ( $this->checkout->transaction->total() > 0 ) {
1674
+		if ($this->checkout->transaction->total() > 0) {
1675 1675
 			do_action(
1676 1676
 				'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway',
1677 1677
 				$this->checkout->transaction
@@ -1679,13 +1679,13 @@  discard block
 block discarded – undo
1679 1679
 			// attempt payment via payment method
1680 1680
 			$success = $this->process_reg_step();
1681 1681
 		}
1682
-		if ( $success && ! $this->checkout->redirect ) {
1682
+		if ($success && ! $this->checkout->redirect) {
1683 1683
 			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn(
1684 1684
 				$this->checkout->transaction->ID()
1685 1685
 			);
1686 1686
 			// set return URL
1687 1687
 			$this->checkout->redirect_url = add_query_arg(
1688
-				array( 'e_reg_url_link' => $this->checkout->reg_url_link ),
1688
+				array('e_reg_url_link' => $this->checkout->reg_url_link),
1689 1689
 				$this->checkout->thank_you_page_url
1690 1690
 			);
1691 1691
 		}
@@ -1703,36 +1703,36 @@  discard block
 block discarded – undo
1703 1703
 	 */
1704 1704
 	private function _process_payment() {
1705 1705
 		// basically confirm that the event hasn't sold out since they hit the page
1706
-		if ( ! $this->_last_second_ticket_verifications() ) {
1706
+		if ( ! $this->_last_second_ticket_verifications()) {
1707 1707
 			return false;
1708 1708
 		}
1709 1709
 		// ya gotta make a choice man
1710
-		if ( empty( $this->checkout->selected_method_of_payment ) ) {
1710
+		if (empty($this->checkout->selected_method_of_payment)) {
1711 1711
 			$this->checkout->json_response->set_plz_select_method_of_payment(
1712
-				__( 'Please select a method of payment before proceeding.', 'event_espresso' )
1712
+				__('Please select a method of payment before proceeding.', 'event_espresso')
1713 1713
 			);
1714 1714
 			return false;
1715 1715
 		}
1716 1716
 		// get EE_Payment_Method object
1717
-		if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() ) {
1717
+		if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
1718 1718
 			return false;
1719 1719
 		}
1720 1720
 		// setup billing form
1721
-		if ( $this->checkout->payment_method->is_on_site() ) {
1721
+		if ($this->checkout->payment_method->is_on_site()) {
1722 1722
 			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1723 1723
 				$this->checkout->payment_method
1724 1724
 			);
1725 1725
 			// bad billing form ?
1726
-			if ( ! $this->_billing_form_is_valid() ) {
1726
+			if ( ! $this->_billing_form_is_valid()) {
1727 1727
 				return false;
1728 1728
 			}
1729 1729
 		}
1730 1730
 		// ensure primary registrant has been fully processed
1731
-		if ( ! $this->_setup_primary_registrant_prior_to_payment() ) {
1731
+		if ( ! $this->_setup_primary_registrant_prior_to_payment()) {
1732 1732
 			return false;
1733 1733
 		}
1734 1734
 		// if session is close to expiring (under 10 minutes by default)
1735
-		if ( ( time() - EE_Registry::instance()->SSN->expiration() ) < EE_Registry::instance()->SSN->extension() ) {
1735
+		if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) {
1736 1736
 			// add some time to session expiration so that payment can be completed
1737 1737
 			EE_Registry::instance()->SSN->extend_expiration();
1738 1738
 		}
@@ -1741,12 +1741,12 @@  discard block
 block discarded – undo
1741 1741
 		// in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations for events with a default reg status of Approved
1742 1742
 		//$transaction_processor->toggle_registration_statuses_for_default_approved_events( $this->checkout->transaction, $this->checkout->reg_cache_where_params );
1743 1743
 		// attempt payment
1744
-		$payment = $this->_attempt_payment( $this->checkout->payment_method );
1744
+		$payment = $this->_attempt_payment($this->checkout->payment_method);
1745 1745
 		// process results
1746
-		$payment = $this->_validate_payment( $payment );
1747
-		$payment = $this->_post_payment_processing( $payment );
1746
+		$payment = $this->_validate_payment($payment);
1747
+		$payment = $this->_post_payment_processing($payment);
1748 1748
 		// verify payment
1749
-		if ( $payment instanceof EE_Payment ) {
1749
+		if ($payment instanceof EE_Payment) {
1750 1750
 			// store that for later
1751 1751
 			$this->checkout->payment = $payment;
1752 1752
 			// we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned
@@ -1760,7 +1760,7 @@  discard block
 block discarded – undo
1760 1760
 			} else {
1761 1761
 				return false;
1762 1762
 			}
1763
-		} else if ( $payment === true ) {
1763
+		} else if ($payment === true) {
1764 1764
 			// please note that offline payment methods will NOT make a payment,
1765 1765
 			// but instead just mark themselves as the PMD_ID on the transaction, and return true
1766 1766
 			$this->checkout->payment = $payment;
@@ -1780,22 +1780,22 @@  discard block
 block discarded – undo
1780 1780
 	 */
1781 1781
 	protected function _last_second_ticket_verifications() {
1782 1782
 		// don't bother re-validating if not a return visit
1783
-		if ( ! $this->checkout->revisit ) {
1783
+		if ( ! $this->checkout->revisit) {
1784 1784
 			return true;
1785 1785
 		}
1786 1786
 		$registrations = $this->checkout->transaction->registrations();
1787
-		if ( empty( $registrations ) ) {
1787
+		if (empty($registrations)) {
1788 1788
 			return false;
1789 1789
 		}
1790
-		foreach ( $registrations as $registration ) {
1791
-			if ( $registration instanceof EE_Registration ) {
1790
+		foreach ($registrations as $registration) {
1791
+			if ($registration instanceof EE_Registration) {
1792 1792
 				$event = $registration->event_obj();
1793
-				if ( $event instanceof EE_Event && $event->is_sold_out( true ) ) {
1793
+				if ($event instanceof EE_Event && $event->is_sold_out(true)) {
1794 1794
 					EE_Error::add_error(
1795 1795
 						apply_filters(
1796 1796
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg',
1797 1797
 							sprintf(
1798
-								__( 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', 'event_espresso' ),
1798
+								__('It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', 'event_espresso'),
1799 1799
 								$event->name()
1800 1800
 							)
1801 1801
 						),
@@ -1825,7 +1825,7 @@  discard block
 block discarded – undo
1825 1825
 		);
1826 1826
 		$html = $payment_method_billing_info->get_html();
1827 1827
 		$html .= $this->checkout->redirect_form;
1828
-		EE_Registry::instance()->REQ->add_output( $html );
1828
+		EE_Registry::instance()->REQ->add_output($html);
1829 1829
 		return true;
1830 1830
 	}
1831 1831
 
@@ -1839,28 +1839,28 @@  discard block
 block discarded – undo
1839 1839
 	 * @throws \EE_Error
1840 1840
 	 */
1841 1841
 	private function _billing_form_is_valid() {
1842
-		if ( ! $this->checkout->payment_method->type_obj()->has_billing_form() ) {
1842
+		if ( ! $this->checkout->payment_method->type_obj()->has_billing_form()) {
1843 1843
 			return true;
1844 1844
 		}
1845
-		if ( $this->checkout->billing_form instanceof EE_Billing_Info_Form ) {
1846
-			if ( $this->checkout->billing_form->was_submitted() ) {
1845
+		if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) {
1846
+			if ($this->checkout->billing_form->was_submitted()) {
1847 1847
 				$this->checkout->billing_form->receive_form_submission();
1848
-				if ( $this->checkout->billing_form->is_valid() ) {
1848
+				if ($this->checkout->billing_form->is_valid()) {
1849 1849
 					return true;
1850 1850
 				}
1851 1851
 				$validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated();
1852 1852
 				$error_strings = array();
1853
-				foreach ( $validation_errors as $validation_error ) {
1854
-					if ( $validation_error instanceof EE_Validation_Error ) {
1853
+				foreach ($validation_errors as $validation_error) {
1854
+					if ($validation_error instanceof EE_Validation_Error) {
1855 1855
 						$form_section = $validation_error->get_form_section();
1856
-						if ( $form_section instanceof EE_Form_Input_Base ) {
1856
+						if ($form_section instanceof EE_Form_Input_Base) {
1857 1857
 							$label = $form_section->html_label_text();
1858
-						} elseif ( $form_section instanceof EE_Form_Section_Base ) {
1858
+						} elseif ($form_section instanceof EE_Form_Section_Base) {
1859 1859
 							$label = $form_section->name();
1860 1860
 						} else {
1861
-							$label = __( 'Validation Error', 'event_espresso' );
1861
+							$label = __('Validation Error', 'event_espresso');
1862 1862
 						}
1863
-						$error_strings[] = sprintf( '%1$s: %2$s', $label, $validation_error->getMessage() );
1863
+						$error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage());
1864 1864
 					}
1865 1865
 				}
1866 1866
 				EE_Error::add_error(
@@ -1870,7 +1870,7 @@  discard block
 block discarded – undo
1870 1870
 							'event_espresso'
1871 1871
 						),
1872 1872
 						'<br/>',
1873
-						implode( '<br/>', $error_strings )
1873
+						implode('<br/>', $error_strings)
1874 1874
 					),
1875 1875
 					__FILE__,
1876 1876
 					__FUNCTION__,
@@ -1889,7 +1889,7 @@  discard block
 block discarded – undo
1889 1889
 			}
1890 1890
 		} else {
1891 1891
 			EE_Error::add_error(
1892
-				__( 'The submitted billing form is invalid possibly due to a technical reason.', 'event_espresso' ),
1892
+				__('The submitted billing form is invalid possibly due to a technical reason.', 'event_espresso'),
1893 1893
 				__FILE__,
1894 1894
 				__FUNCTION__,
1895 1895
 				__LINE__
@@ -1928,7 +1928,7 @@  discard block
 block discarded – undo
1928 1928
 		// save the TXN ( which clears cached copy of primary_registration)
1929 1929
 		$this->checkout->transaction->save();
1930 1930
 		// grab TXN ID and save it to the primary_registration
1931
-		$primary_registration->set_transaction_id( $this->checkout->transaction->ID() );
1931
+		$primary_registration->set_transaction_id($this->checkout->transaction->ID());
1932 1932
 		// save what we have so far
1933 1933
 		$primary_registration->save();
1934 1934
 		return true;
@@ -1946,7 +1946,7 @@  discard block
 block discarded – undo
1946 1946
 	private function _capture_primary_registration_data_from_billing_form() {
1947 1947
 		// convert billing form data into an attendee
1948 1948
 		$this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data();
1949
-		if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee ) {
1949
+		if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee) {
1950 1950
 			EE_Error::add_error(
1951 1951
 				sprintf(
1952 1952
 					__(
@@ -1954,7 +1954,7 @@  discard block
 block discarded – undo
1954 1954
 						'event_espresso'
1955 1955
 					),
1956 1956
 					'<br/>',
1957
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1957
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
1958 1958
 				),
1959 1959
 				__FILE__,
1960 1960
 				__FUNCTION__,
@@ -1963,7 +1963,7 @@  discard block
 block discarded – undo
1963 1963
 			return false;
1964 1964
 		}
1965 1965
 		$primary_registration = $this->checkout->transaction->primary_registration();
1966
-		if ( ! $primary_registration instanceof EE_Registration ) {
1966
+		if ( ! $primary_registration instanceof EE_Registration) {
1967 1967
 			EE_Error::add_error(
1968 1968
 				sprintf(
1969 1969
 					__(
@@ -1971,7 +1971,7 @@  discard block
 block discarded – undo
1971 1971
 						'event_espresso'
1972 1972
 					),
1973 1973
 					'<br/>',
1974
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1974
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
1975 1975
 				),
1976 1976
 				__FILE__,
1977 1977
 				__FUNCTION__,
@@ -1979,7 +1979,7 @@  discard block
 block discarded – undo
1979 1979
 			);
1980 1980
 			return false;
1981 1981
 		}
1982
-		if ( ! $primary_registration->_add_relation_to( $this->checkout->primary_attendee_obj, 'Attendee' )
1982
+		if ( ! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee')
1983 1983
 		       instanceof
1984 1984
 		       EE_Attendee
1985 1985
 		) {
@@ -1990,7 +1990,7 @@  discard block
 block discarded – undo
1990 1990
 						'event_espresso'
1991 1991
 					),
1992 1992
 					'<br/>',
1993
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1993
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
1994 1994
 				),
1995 1995
 				__FILE__,
1996 1996
 				__FUNCTION__,
@@ -1999,9 +1999,9 @@  discard block
 block discarded – undo
1999 1999
 			return false;
2000 2000
 		}
2001 2001
 		/** @type EE_Registration_Processor $registration_processor */
2002
-		$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
2002
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
2003 2003
 		// at this point, we should have enough details about the registrant to consider the registration NOT incomplete
2004
-		$registration_processor->toggle_incomplete_registration_status_to_default( $primary_registration );
2004
+		$registration_processor->toggle_incomplete_registration_status_to_default($primary_registration);
2005 2005
 		return true;
2006 2006
 	}
2007 2007
 
@@ -2016,22 +2016,22 @@  discard block
 block discarded – undo
2016 2016
 	 * @throws \EE_Error
2017 2017
 	 */
2018 2018
 	private function _get_payment_method_for_selected_method_of_payment() {
2019
-		if ( $this->checkout->selected_method_of_payment === 'events_sold_out' ) {
2019
+		if ($this->checkout->selected_method_of_payment === 'events_sold_out') {
2020 2020
 			$this->_redirect_because_event_sold_out();
2021 2021
 			return null;
2022 2022
 		}
2023 2023
 		// get EE_Payment_Method object
2024
-		if ( isset( $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ] ) ) {
2025
-			$payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ];
2024
+		if (isset($this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment])) {
2025
+			$payment_method = $this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment];
2026 2026
 		} else {
2027 2027
 			// load EEM_Payment_Method
2028
-			EE_Registry::instance()->load_model( 'Payment_Method' );
2028
+			EE_Registry::instance()->load_model('Payment_Method');
2029 2029
 			/** @type EEM_Payment_Method $EEM_Payment_Method */
2030 2030
 			$EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method;
2031
-			$payment_method = $EEM_Payment_Method->get_one_by_slug( $this->checkout->selected_method_of_payment );
2031
+			$payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment);
2032 2032
 		}
2033 2033
 		// verify $payment_method
2034
-		if ( ! $payment_method instanceof EE_Payment_Method ) {
2034
+		if ( ! $payment_method instanceof EE_Payment_Method) {
2035 2035
 			// not a payment
2036 2036
 			EE_Error::add_error(
2037 2037
 				sprintf(
@@ -2040,7 +2040,7 @@  discard block
 block discarded – undo
2040 2040
 						'event_espresso'
2041 2041
 					),
2042 2042
 					'<br/>',
2043
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
2043
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2044 2044
 				),
2045 2045
 				__FILE__,
2046 2046
 				__FUNCTION__,
@@ -2049,7 +2049,7 @@  discard block
 block discarded – undo
2049 2049
 			return null;
2050 2050
 		}
2051 2051
 		// and verify it has a valid Payment_Method Type object
2052
-		if ( ! $payment_method->type_obj() instanceof EE_PMT_Base ) {
2052
+		if ( ! $payment_method->type_obj() instanceof EE_PMT_Base) {
2053 2053
 			// not a payment
2054 2054
 			EE_Error::add_error(
2055 2055
 				sprintf(
@@ -2058,7 +2058,7 @@  discard block
 block discarded – undo
2058 2058
 						'event_espresso'
2059 2059
 					),
2060 2060
 					'<br/>',
2061
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
2061
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2062 2062
 				),
2063 2063
 				__FILE__,
2064 2064
 				__FUNCTION__,
@@ -2079,29 +2079,29 @@  discard block
 block discarded – undo
2079 2079
 	 * @return    mixed    EE_Payment | boolean
2080 2080
 	 * @throws \EE_Error
2081 2081
 	 */
2082
-	private function _attempt_payment( EE_Payment_Method $payment_method ) {
2082
+	private function _attempt_payment(EE_Payment_Method $payment_method) {
2083 2083
 		$payment = null;
2084 2084
 		$this->checkout->transaction->save();
2085
-		$payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' );
2086
-		if ( ! $payment_processor instanceof EE_Payment_Processor ) {
2085
+		$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2086
+		if ( ! $payment_processor instanceof EE_Payment_Processor) {
2087 2087
 			return false;
2088 2088
 		}
2089 2089
 		try {
2090
-			$payment_processor->set_revisit( $this->checkout->revisit );
2090
+			$payment_processor->set_revisit($this->checkout->revisit);
2091 2091
 			// generate payment object
2092 2092
 			$payment = $payment_processor->process_payment(
2093 2093
 				$payment_method,
2094 2094
 				$this->checkout->transaction,
2095 2095
 				$this->checkout->amount_owing,
2096 2096
 				$this->checkout->billing_form,
2097
-				$this->_get_return_url( $payment_method ),
2097
+				$this->_get_return_url($payment_method),
2098 2098
 				'CART',
2099 2099
 				$this->checkout->admin_request,
2100 2100
 				true,
2101 2101
 				$this->reg_step_url()
2102 2102
 			);
2103
-		} catch ( Exception $e ) {
2104
-			$this->_handle_payment_processor_exception( $e );
2103
+		} catch (Exception $e) {
2104
+			$this->_handle_payment_processor_exception($e);
2105 2105
 		}
2106 2106
 		return $payment;
2107 2107
 	}
@@ -2116,7 +2116,7 @@  discard block
 block discarded – undo
2116 2116
 	 * @return void
2117 2117
 	 * @throws \EE_Error
2118 2118
 	 */
2119
-	protected function _handle_payment_processor_exception( Exception $e ) {
2119
+	protected function _handle_payment_processor_exception(Exception $e) {
2120 2120
 		EE_Error::add_error(
2121 2121
 			sprintf(
2122 2122
 				__(
@@ -2124,7 +2124,7 @@  discard block
 block discarded – undo
2124 2124
 					'event_espresso'
2125 2125
 				),
2126 2126
 				'<br/>',
2127
-				EE_Registry::instance()->CFG->organization->get_pretty( 'email' ),
2127
+				EE_Registry::instance()->CFG->organization->get_pretty('email'),
2128 2128
 				$e->getMessage(),
2129 2129
 				$e->getFile(),
2130 2130
 				$e->getLine()
@@ -2145,9 +2145,9 @@  discard block
 block discarded – undo
2145 2145
 	 * @return string
2146 2146
 	 * @throws \EE_Error
2147 2147
 	 */
2148
-	protected function _get_return_url( EE_Payment_Method $payment_method ) {
2148
+	protected function _get_return_url(EE_Payment_Method $payment_method) {
2149 2149
 		$return_url = '';
2150
-		switch ( $payment_method->type_obj()->payment_occurs() ) {
2150
+		switch ($payment_method->type_obj()->payment_occurs()) {
2151 2151
 			case EE_PMT_Base::offsite :
2152 2152
 				$return_url = add_query_arg(
2153 2153
 					array(
@@ -2176,12 +2176,12 @@  discard block
 block discarded – undo
2176 2176
 	 * @return EE_Payment | FALSE
2177 2177
 	 * @throws \EE_Error
2178 2178
 	 */
2179
-	private function _validate_payment( $payment = null ) {
2180
-		if ( $this->checkout->payment_method->is_off_line() ) {
2179
+	private function _validate_payment($payment = null) {
2180
+		if ($this->checkout->payment_method->is_off_line()) {
2181 2181
 			return true;
2182 2182
 		}
2183 2183
 		// verify payment object
2184
-		if ( ! $payment instanceof EE_Payment ) {
2184
+		if ( ! $payment instanceof EE_Payment) {
2185 2185
 			// not a payment
2186 2186
 			EE_Error::add_error(
2187 2187
 				sprintf(
@@ -2190,7 +2190,7 @@  discard block
 block discarded – undo
2190 2190
 						'event_espresso'
2191 2191
 					),
2192 2192
 					'<br/>',
2193
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
2193
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2194 2194
 				),
2195 2195
 				__FILE__,
2196 2196
 				__FUNCTION__,
@@ -2211,27 +2211,27 @@  discard block
 block discarded – undo
2211 2211
 	 * @return bool
2212 2212
 	 * @throws \EE_Error
2213 2213
 	 */
2214
-	private function _post_payment_processing( $payment = null ) {
2214
+	private function _post_payment_processing($payment = null) {
2215 2215
 		// Off-Line payment?
2216
-		if ( $payment === true ) {
2216
+		if ($payment === true) {
2217 2217
 			//$this->_setup_redirect_for_next_step();
2218 2218
 			return true;
2219 2219
 		// On-Site payment?
2220
-		} else if ( $this->checkout->payment_method->is_on_site() ) {
2221
-			if ( ! $this->_process_payment_status( $payment, EE_PMT_Base::onsite ) ) {
2220
+		} else if ($this->checkout->payment_method->is_on_site()) {
2221
+			if ( ! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) {
2222 2222
 				//$this->_setup_redirect_for_next_step();
2223 2223
 				$this->checkout->continue_reg = false;
2224 2224
 			}
2225 2225
 		// Off-Site payment?
2226
-		} else if ( $this->checkout->payment_method->is_off_site() ) {
2226
+		} else if ($this->checkout->payment_method->is_off_site()) {
2227 2227
 			// if a payment object was made and it specifies a redirect url, then we'll setup that redirect info
2228
-			if ( $payment instanceof EE_Payment && $payment->redirect_url() ) {
2229
-				do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()' );
2228
+			if ($payment instanceof EE_Payment && $payment->redirect_url()) {
2229
+				do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()');
2230 2230
 				$this->checkout->redirect = true;
2231 2231
 				$this->checkout->redirect_form = $payment->redirect_form();
2232
-				$this->checkout->redirect_url = $this->reg_step_url( 'redirect_form' );
2232
+				$this->checkout->redirect_url = $this->reg_step_url('redirect_form');
2233 2233
 				// set JSON response
2234
-				$this->checkout->json_response->set_redirect_form( $this->checkout->redirect_form );
2234
+				$this->checkout->json_response->set_redirect_form($this->checkout->redirect_form);
2235 2235
 				// set cron job for finalizing the TXN
2236 2236
 				// in case the user does not return from the off-site gateway
2237 2237
 				EE_Cron_Tasks::schedule_finalize_abandoned_transactions_check(
@@ -2239,7 +2239,7 @@  discard block
 block discarded – undo
2239 2239
 					$this->checkout->transaction->ID()
2240 2240
 				);
2241 2241
 				// and lastly, let's bump the payment status to pending
2242
-				$payment->set_status( EEM_Payment::status_id_pending );
2242
+				$payment->set_status(EEM_Payment::status_id_pending);
2243 2243
 				$payment->save();
2244 2244
 			} else {
2245 2245
 				// not a payment
@@ -2251,7 +2251,7 @@  discard block
 block discarded – undo
2251 2251
 							'event_espresso'
2252 2252
 						),
2253 2253
 						'<br/>',
2254
-						EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
2254
+						EE_Registry::instance()->CFG->organization->get_pretty('email')
2255 2255
 					),
2256 2256
 					__FILE__,
2257 2257
 					__FUNCTION__,
@@ -2289,21 +2289,21 @@  discard block
 block discarded – undo
2289 2289
 	 * @return bool
2290 2290
 	 * @throws \EE_Error
2291 2291
 	 */
2292
-	private function _process_payment_status( $payment, $payment_occurs = EE_PMT_Base::offline ) {
2292
+	private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) {
2293 2293
 		// off-line payment? carry on
2294
-		if ( $payment_occurs === EE_PMT_Base::offline ) {
2294
+		if ($payment_occurs === EE_PMT_Base::offline) {
2295 2295
 			return true;
2296 2296
 		}
2297 2297
 		// verify payment validity
2298
-		if ( $payment instanceof EE_Payment ) {
2299
-			do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()' );
2298
+		if ($payment instanceof EE_Payment) {
2299
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()');
2300 2300
 			$msg = $payment->gateway_response();
2301 2301
 			// check results
2302
-			switch ( $payment->status() ) {
2302
+			switch ($payment->status()) {
2303 2303
 				// good payment
2304 2304
 				case EEM_Payment::status_id_approved :
2305 2305
 					EE_Error::add_success(
2306
-						__( 'Your payment was processed successfully.', 'event_espresso' ),
2306
+						__('Your payment was processed successfully.', 'event_espresso'),
2307 2307
 						__FILE__,
2308 2308
 						__FUNCTION__,
2309 2309
 						__LINE__
@@ -2312,45 +2312,45 @@  discard block
 block discarded – undo
2312 2312
 					break;
2313 2313
 				// slow payment
2314 2314
 				case EEM_Payment::status_id_pending :
2315
-					if ( empty( $msg ) ) {
2315
+					if (empty($msg)) {
2316 2316
 						$msg = __(
2317 2317
 							'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.',
2318 2318
 							'event_espresso'
2319 2319
 						);
2320 2320
 					}
2321
-					EE_Error::add_success( $msg, __FILE__, __FUNCTION__, __LINE__ );
2321
+					EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__);
2322 2322
 					return true;
2323 2323
 					break;
2324 2324
 				// don't wanna payment
2325 2325
 				case EEM_Payment::status_id_cancelled :
2326
-					if ( empty( $msg ) ) {
2326
+					if (empty($msg)) {
2327 2327
 						$msg = _n(
2328 2328
 							'Payment cancelled. Please try again.',
2329 2329
 							'Payment cancelled. Please try again or select another method of payment.',
2330
-							count( $this->checkout->available_payment_methods ),
2330
+							count($this->checkout->available_payment_methods),
2331 2331
 							'event_espresso'
2332 2332
 						);
2333 2333
 					}
2334
-					EE_Error::add_attention( $msg, __FILE__, __FUNCTION__, __LINE__ );
2334
+					EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2335 2335
 					return false;
2336 2336
 					break;
2337 2337
 				// not enough payment
2338 2338
 				case EEM_Payment::status_id_declined :
2339
-					if ( empty( $msg ) ) {
2339
+					if (empty($msg)) {
2340 2340
 						$msg = _n(
2341 2341
 							'We\'re sorry but your payment was declined. Please try again.',
2342 2342
 							'We\'re sorry but your payment was declined. Please try again or select another method of payment.',
2343
-							count( $this->checkout->available_payment_methods ),
2343
+							count($this->checkout->available_payment_methods),
2344 2344
 							'event_espresso'
2345 2345
 						);
2346 2346
 					}
2347
-					EE_Error::add_attention( $msg, __FILE__, __FUNCTION__, __LINE__ );
2347
+					EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2348 2348
 					return false;
2349 2349
 					break;
2350 2350
 				// bad payment
2351 2351
 				case EEM_Payment::status_id_failed :
2352
-					if ( ! empty( $msg ) ) {
2353
-						EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
2352
+					if ( ! empty($msg)) {
2353
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2354 2354
 						return false;
2355 2355
 					}
2356 2356
 					// default to error below
@@ -2359,7 +2359,7 @@  discard block
 block discarded – undo
2359 2359
 		}
2360 2360
 		// off-site payment gateway responses are too unreliable, so let's just assume that
2361 2361
 		// the payment processing is just running slower than the registrant's request
2362
-		if ( $payment_occurs === EE_PMT_Base::offsite ) {
2362
+		if ($payment_occurs === EE_PMT_Base::offsite) {
2363 2363
 			return true;
2364 2364
 		}
2365 2365
 		EE_Error::add_error(
@@ -2369,7 +2369,7 @@  discard block
 block discarded – undo
2369 2369
 					'event_espresso'
2370 2370
 				),
2371 2371
 				'<br/>',
2372
-				EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
2372
+				EE_Registry::instance()->CFG->organization->get_pretty('email')
2373 2373
 			),
2374 2374
 			__FILE__,
2375 2375
 			__FUNCTION__,
@@ -2402,13 +2402,13 @@  discard block
 block discarded – undo
2402 2402
 	public function process_gateway_response() {
2403 2403
 		$payment = null;
2404 2404
 		// how have they chosen to pay?
2405
-		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( true );
2405
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
2406 2406
 		// get EE_Payment_Method object
2407
-		if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() ) {
2407
+		if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
2408 2408
 			$this->checkout->continue_reg = false;
2409 2409
 			return false;
2410 2410
 		}
2411
-		if ( ! $this->checkout->payment_method->is_off_site() ) {
2411
+		if ( ! $this->checkout->payment_method->is_off_site()) {
2412 2412
 			return false;
2413 2413
 		}
2414 2414
 		$this->_validate_offsite_return();
@@ -2422,23 +2422,23 @@  discard block
 block discarded – undo
2422 2422
 		//	true
2423 2423
 		//);
2424 2424
 		// verify TXN
2425
-		if ( $this->checkout->transaction instanceof EE_Transaction ) {
2425
+		if ($this->checkout->transaction instanceof EE_Transaction) {
2426 2426
 			$gateway = $this->checkout->payment_method->type_obj()->get_gateway();
2427
-			if ( ! $gateway instanceof EE_Offsite_Gateway ) {
2427
+			if ( ! $gateway instanceof EE_Offsite_Gateway) {
2428 2428
 				$this->checkout->continue_reg = false;
2429 2429
 				return false;
2430 2430
 			}
2431
-			$payment = $this->_process_off_site_payment( $gateway );
2432
-			$payment = $this->_process_cancelled_payments( $payment );
2433
-			$payment = $this->_validate_payment( $payment );
2431
+			$payment = $this->_process_off_site_payment($gateway);
2432
+			$payment = $this->_process_cancelled_payments($payment);
2433
+			$payment = $this->_validate_payment($payment);
2434 2434
 			// if payment was not declined by the payment gateway or cancelled by the registrant
2435
-			if ( $this->_process_payment_status( $payment, EE_PMT_Base::offsite ) ) {
2435
+			if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) {
2436 2436
 				//$this->_setup_redirect_for_next_step();
2437 2437
 				// store that for later
2438 2438
 				$this->checkout->payment = $payment;
2439 2439
 				// mark this reg step as completed, as long as gateway doesn't use a separate IPN request,
2440 2440
 				// because we will complete this step during the IPN processing then
2441
-				if ( $gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request() ) {
2441
+				if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) {
2442 2442
 					$this->set_completed();
2443 2443
 				}
2444 2444
 				return true;
@@ -2462,21 +2462,21 @@  discard block
 block discarded – undo
2462 2462
 	 * @throws \EE_Error
2463 2463
 	 */
2464 2464
 	private function _validate_offsite_return() {
2465
-		$TXN_ID = (int)EE_Registry::instance()->REQ->get( 'spco_txn', 0 );
2466
-		if ( $TXN_ID !== $this->checkout->transaction->ID() ) {
2465
+		$TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0);
2466
+		if ($TXN_ID !== $this->checkout->transaction->ID()) {
2467 2467
 			// Houston... we might have a problem
2468 2468
 			$invalid_TXN = false;
2469 2469
 			// first gather some info
2470
-			$valid_TXN = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID );
2470
+			$valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2471 2471
 			$primary_registrant = $valid_TXN instanceof EE_Transaction
2472 2472
 				? $valid_TXN->primary_registration()
2473 2473
 				: null;
2474 2474
 			// let's start by retrieving the cart for this TXN
2475
-			$cart = $this->checkout->get_cart_for_transaction( $this->checkout->transaction );
2476
-			if ( $cart instanceof EE_Cart ) {
2475
+			$cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction);
2476
+			if ($cart instanceof EE_Cart) {
2477 2477
 				// verify that the current cart has tickets
2478 2478
 				$tickets = $cart->get_tickets();
2479
-				if ( empty( $tickets ) ) {
2479
+				if (empty($tickets)) {
2480 2480
 					$invalid_TXN = true;
2481 2481
 				}
2482 2482
 			} else {
@@ -2486,35 +2486,35 @@  discard block
 block discarded – undo
2486 2486
 				? $primary_registrant->session_ID()
2487 2487
 				: null;
2488 2488
 			// validate current Session ID and compare against valid TXN session ID
2489
-			if ( EE_Session::instance()->id() === null ) {
2489
+			if (EE_Session::instance()->id() === null) {
2490 2490
 				$invalid_TXN = true;
2491
-			} else if ( EE_Session::instance()->id() === $valid_TXN_SID ) {
2491
+			} else if (EE_Session::instance()->id() === $valid_TXN_SID) {
2492 2492
 				// WARNING !!!
2493 2493
 				// this could be PayPal sending back duplicate requests (ya they do that)
2494 2494
 				// or it **could** mean someone is simply registering AGAIN after having just done so
2495 2495
 				// so now we need to determine if this current TXN looks valid or not
2496 2496
 				// has this step even been started ?
2497
-				if ( $this->checkout->transaction->reg_step_completed( $this->slug() === false )
2497
+				if ($this->checkout->transaction->reg_step_completed($this->slug() === false)
2498 2498
 				) {
2499 2499
 					// really? you're half way through this reg step, but you never started it ?
2500 2500
 					$invalid_TXN = true;
2501 2501
 				}
2502 2502
 			}
2503
-			if ( $invalid_TXN ) {
2503
+			if ($invalid_TXN) {
2504 2504
 				// is the valid TXN completed ?
2505
-				if ( $valid_TXN instanceof EE_Transaction ) {
2505
+				if ($valid_TXN instanceof EE_Transaction) {
2506 2506
 					// has this step even been started ?
2507
-					$reg_step_completed = $valid_TXN->reg_step_completed( $this->slug() );
2508
-					if ( $reg_step_completed !== false && $reg_step_completed !== true ) {
2507
+					$reg_step_completed = $valid_TXN->reg_step_completed($this->slug());
2508
+					if ($reg_step_completed !== false && $reg_step_completed !== true) {
2509 2509
 						// so it **looks** like this is a double request from PayPal
2510 2510
 						// so let's try to pick up where we left off
2511 2511
 						$this->checkout->transaction = $valid_TXN;
2512
-						$this->checkout->refresh_all_entities( true );
2512
+						$this->checkout->refresh_all_entities(true);
2513 2513
 						return;
2514 2514
 					}
2515 2515
 				}
2516 2516
 				// you appear to be lost?
2517
-				$this->_redirect_wayward_request( $primary_registrant );
2517
+				$this->_redirect_wayward_request($primary_registrant);
2518 2518
 			}
2519 2519
 		}
2520 2520
 	}
@@ -2529,14 +2529,14 @@  discard block
 block discarded – undo
2529 2529
 	 * @return bool
2530 2530
 	 * @throws \EE_Error
2531 2531
 	 */
2532
-	private function _redirect_wayward_request( EE_Registration $primary_registrant ) {
2533
-		if ( ! $primary_registrant instanceof EE_Registration ) {
2532
+	private function _redirect_wayward_request(EE_Registration $primary_registrant) {
2533
+		if ( ! $primary_registrant instanceof EE_Registration) {
2534 2534
 			// try redirecting based on the current TXN
2535 2535
 			$primary_registrant = $this->checkout->transaction instanceof EE_Transaction
2536 2536
 				? $this->checkout->transaction->primary_registration()
2537 2537
 				: null;
2538 2538
 		}
2539
-		if ( ! $primary_registrant instanceof EE_Registration ) {
2539
+		if ( ! $primary_registrant instanceof EE_Registration) {
2540 2540
 			EE_Error::add_error(
2541 2541
 				sprintf(
2542 2542
 					__(
@@ -2544,7 +2544,7 @@  discard block
 block discarded – undo
2544 2544
 						'event_espresso'
2545 2545
 					),
2546 2546
 					'<br/>',
2547
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
2547
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2548 2548
 				),
2549 2549
 				__FILE__,
2550 2550
 				__FUNCTION__,
@@ -2575,17 +2575,17 @@  discard block
 block discarded – undo
2575 2575
 	 * @return \EE_Payment
2576 2576
 	 * @throws \EE_Error
2577 2577
 	 */
2578
-	private function _process_off_site_payment( EE_Offsite_Gateway $gateway ) {
2578
+	private function _process_off_site_payment(EE_Offsite_Gateway $gateway) {
2579 2579
 		try {
2580 2580
 			$request_data = \EE_Registry::instance()->REQ->params();
2581 2581
 			// if gateway uses_separate_IPN_request, then we don't have to process the IPN manually
2582 2582
 			$this->set_handle_IPN_in_this_request(
2583
-				$gateway->handle_IPN_in_this_request( $request_data, false )
2583
+				$gateway->handle_IPN_in_this_request($request_data, false)
2584 2584
 			);
2585
-			if ( $this->handle_IPN_in_this_request() ) {
2585
+			if ($this->handle_IPN_in_this_request()) {
2586 2586
 				// get payment details and process results
2587 2587
 				/** @type EE_Payment_Processor $payment_processor */
2588
-				$payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' );
2588
+				$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2589 2589
 				$payment = $payment_processor->process_ipn(
2590 2590
 					$request_data,
2591 2591
 					$this->checkout->transaction,
@@ -2598,14 +2598,14 @@  discard block
 block discarded – undo
2598 2598
 				$payment = $this->checkout->transaction->last_payment();
2599 2599
 				//$payment_source = 'last_payment';
2600 2600
 			}
2601
-		} catch ( Exception $e ) {
2601
+		} catch (Exception $e) {
2602 2602
 			// let's just eat the exception and try to move on using any previously set payment info
2603 2603
 			$payment = $this->checkout->transaction->last_payment();
2604 2604
 			//$payment_source = 'last_payment after Exception';
2605 2605
 			// but if we STILL don't have a payment object
2606
-			if ( ! $payment instanceof EE_Payment ) {
2606
+			if ( ! $payment instanceof EE_Payment) {
2607 2607
 				// then we'll object ! ( not object like a thing... but object like what a lawyer says ! )
2608
-				$this->_handle_payment_processor_exception( $e );
2608
+				$this->_handle_payment_processor_exception($e);
2609 2609
 			}
2610 2610
 		}
2611 2611
 		// DEBUG LOG
@@ -2630,13 +2630,13 @@  discard block
 block discarded – undo
2630 2630
 	 * @return EE_Payment | FALSE
2631 2631
 	 * @throws \EE_Error
2632 2632
 	 */
2633
-	private function _process_cancelled_payments( $payment = null ) {
2633
+	private function _process_cancelled_payments($payment = null) {
2634 2634
 		if (
2635 2635
 			$payment instanceof EE_Payment
2636
-			&& isset( $_REQUEST['ee_cancel_payment'] )
2636
+			&& isset($_REQUEST['ee_cancel_payment'])
2637 2637
 			&& $payment->status() === EEM_Payment::status_id_failed
2638 2638
 		) {
2639
-			$payment->set_status( EEM_Payment::status_id_cancelled );
2639
+			$payment->set_status(EEM_Payment::status_id_cancelled);
2640 2640
 		}
2641 2641
 		return $payment;
2642 2642
 	}
@@ -2653,14 +2653,14 @@  discard block
 block discarded – undo
2653 2653
 	public function get_transaction_details_for_gateways() {
2654 2654
 		$txn_details = array();
2655 2655
 		// ya gotta make a choice man
2656
-		if ( empty( $this->checkout->selected_method_of_payment ) ) {
2656
+		if (empty($this->checkout->selected_method_of_payment)) {
2657 2657
 			$txn_details = array(
2658
-				'error' => __( 'Please select a method of payment before proceeding.', 'event_espresso' )
2658
+				'error' => __('Please select a method of payment before proceeding.', 'event_espresso')
2659 2659
 			);
2660 2660
 		}
2661 2661
 		// get EE_Payment_Method object
2662 2662
 		if (
2663
-			empty( $txn_details )
2663
+			empty($txn_details)
2664 2664
 			&&
2665 2665
 			! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()
2666 2666
 		) {
@@ -2672,8 +2672,8 @@  discard block
 block discarded – undo
2672 2672
 				)
2673 2673
 			);
2674 2674
 		}
2675
-		if ( empty( $txn_details ) && $this->checkout->transaction instanceof EE_Transaction ) {
2676
-			$return_url = $this->_get_return_url( $this->checkout->payment_method );
2675
+		if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) {
2676
+			$return_url = $this->_get_return_url($this->checkout->payment_method);
2677 2677
 			$txn_details = array(
2678 2678
 				'TXN_ID'         => $this->checkout->transaction->ID(),
2679 2679
 				'TXN_timestamp'  => $this->checkout->transaction->datetime(),
@@ -2684,7 +2684,7 @@  discard block
 block discarded – undo
2684 2684
 				'PMD_ID'         => $this->checkout->transaction->payment_method_ID(),
2685 2685
 				'payment_amount' => $this->checkout->amount_owing,
2686 2686
 				'return_url'     => $return_url,
2687
-				'cancel_url'     => add_query_arg( array( 'ee_cancel_payment' => true ), $return_url ),
2687
+				'cancel_url'     => add_query_arg(array('ee_cancel_payment' => true), $return_url),
2688 2688
 				'notify_url'     => EE_Config::instance()->core->txn_page_url(
2689 2689
 					array(
2690 2690
 						'e_reg_url_link'    => $this->checkout->transaction->primary_registration()->reg_url_link(),
@@ -2693,7 +2693,7 @@  discard block
 block discarded – undo
2693 2693
 				)
2694 2694
 			);
2695 2695
 		}
2696
-		echo wp_json_encode( $txn_details );
2696
+		echo wp_json_encode($txn_details);
2697 2697
 		exit();
2698 2698
 	}
2699 2699
 
@@ -2710,7 +2710,7 @@  discard block
 block discarded – undo
2710 2710
     public function __sleep()
2711 2711
     {
2712 2712
         // remove the reg form and the checkout
2713
-        return array_diff( array_keys( get_object_vars( $this ) ), array( 'reg_form', 'checkout', 'line_item_display' ) );
2713
+        return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display'));
2714 2714
     }
2715 2715
 
2716 2716
 
Please login to merge, or discard this patch.
core/libraries/rest_api/changes/Changes_In_4_8_34.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,6 @@
 block discarded – undo
32 32
      * Removes the checkin and checkout endpoints from the index for requests
33 33
      * to api versions lowers than 4.8.33
34 34
      *
35
-     * @param array                                                  $routes_on_this_version
36 35
      * @param EventEspresso\core\libraries\rest_api\controllers\Base $controller
37 36
      * @return array like $routes_on_this_version
38 37
      */
Please login to merge, or discard this patch.
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -12,39 +12,39 @@
 block discarded – undo
12 12
 class Changes_In_4_8_34 extends Changes_In_Base
13 13
 {
14 14
 
15
-    /**
16
-     * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
17
-     */
18
-    public function set_hooks()
19
-    {
20
-        //set a hook to remove the checkout/checkout endpoints if the request 
21
-        //is for lower than 4.8.33
22
-        add_filter(
23
-            'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
24
-            array($this, 'remove_response_headers'),
25
-            10,
26
-            3
27
-        );
28
-    }
29
-
30
-
31
-
32
-    /**
33
-     * Removes the checkin and checkout endpoints from the index for requests
34
-     * to api versions lowers than 4.8.33
35
-     *
36
-     * @param array                                                  $routes_on_this_version
37
-     * @param EventEspresso\core\libraries\rest_api\controllers\Base $controller
38
-     * @return array like $routes_on_this_version
39
-     */
40
-    public function remove_response_headers($response_headers, $controller, $requested_version)
41
-    {
42
-        if ($controller instanceof Base
43
-            && $this->applies_to_version($requested_version)
44
-        ) {
45
-            return array();
46
-        }
47
-        return $response_headers;
48
-    }
15
+	/**
16
+	 * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
17
+	 */
18
+	public function set_hooks()
19
+	{
20
+		//set a hook to remove the checkout/checkout endpoints if the request 
21
+		//is for lower than 4.8.33
22
+		add_filter(
23
+			'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
24
+			array($this, 'remove_response_headers'),
25
+			10,
26
+			3
27
+		);
28
+	}
29
+
30
+
31
+
32
+	/**
33
+	 * Removes the checkin and checkout endpoints from the index for requests
34
+	 * to api versions lowers than 4.8.33
35
+	 *
36
+	 * @param array                                                  $routes_on_this_version
37
+	 * @param EventEspresso\core\libraries\rest_api\controllers\Base $controller
38
+	 * @return array like $routes_on_this_version
39
+	 */
40
+	public function remove_response_headers($response_headers, $controller, $requested_version)
41
+	{
42
+		if ($controller instanceof Base
43
+			&& $this->applies_to_version($requested_version)
44
+		) {
45
+			return array();
46
+		}
47
+		return $response_headers;
48
+	}
49 49
 }
50 50
 
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/Base.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -314,7 +314,7 @@
 block discarded – undo
314 314
      *
315 315
      * @param string $route
316 316
      * @param string $regex
317
-     * @param array  $match_keys EXCLUDING matching the entire regex
317
+     * @param string[]  $match_keys EXCLUDING matching the entire regex
318 318
      * @return array where  $match_keys are the keys (the first value of $match_keys
319 319
      *                           becomes the first key of the return value, etc. Eg passing in $match_keys of
320 320
      *                           array( 'model', 'id' ), will, if the regex is successful, will return
Please login to merge, or discard this patch.
Indentation   +304 added lines, -304 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\libraries\rest_api\Rest_Exception;
5 5
 
6 6
 if (! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -20,309 +20,309 @@  discard block
 block discarded – undo
20 20
 class Base
21 21
 {
22 22
 
23
-    const header_prefix_for_ee = 'X-EE-';
24
-
25
-    const header_prefix_for_wp = 'X-WP-';
26
-
27
-    /**
28
-     * Contains debug info we'll send back in the response headers
29
-     *
30
-     * @var array
31
-     */
32
-    protected $_debug_info = array();
33
-
34
-    /**
35
-     * Indicates whether or not the API is in debug mode
36
-     *
37
-     * @var boolean
38
-     */
39
-    protected $_debug_mode = false;
40
-
41
-    /**
42
-     * Indicates the version that was requested
43
-     *
44
-     * @var string
45
-     */
46
-    protected $_requested_version;
47
-
48
-    /**
49
-     * flat array of headers to send in the response
50
-     *
51
-     * @var array
52
-     */
53
-    protected $_response_headers = array();
54
-
55
-
56
-
57
-    public function __construct()
58
-    {
59
-        $this->_debug_mode = defined('EE_REST_API_DEBUG_MODE') ? EE_REST_API_DEBUG_MODE : false;
60
-    }
61
-
62
-
63
-
64
-    /**
65
-     * Sets the version the user requested
66
-     *
67
-     * @param string $version eg '4.8'
68
-     */
69
-    public function set_requested_version($version)
70
-    {
71
-        $this->_requested_version = $version;
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * Sets some debug info that we'll send back in headers
78
-     *
79
-     * @param string       $key
80
-     * @param string|array $info
81
-     */
82
-    protected function _set_debug_info($key, $info)
83
-    {
84
-        $this->_debug_info[$key] = $info;
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     * Sets headers for the response
91
-     *
92
-     * @param string       $header_key    , excluding the "X-EE-" part
93
-     * @param array|string $value         if an array, multiple headers will be added, one
94
-     *                                    for each key in the array
95
-     * @param boolean      $use_ee_prefix whether to use the EE prefix on the header, or fallback to
96
-     *                                    the standard WP one
97
-     */
98
-    protected function _set_response_header($header_key, $value, $use_ee_prefix = true)
99
-    {
100
-        if (is_array($value)) {
101
-            foreach ($value as $value_key => $value_value) {
102
-                $this->_set_response_header($header_key . '[' . $value_key . ']', $value_value);
103
-            }
104
-        } else {
105
-            $prefix = $use_ee_prefix ? Base::header_prefix_for_ee : Base::header_prefix_for_wp;
106
-            $this->_response_headers[$prefix . $header_key] = $value;
107
-        }
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * Returns a flat array of headers to be added to the response
114
-     *
115
-     * @return array
116
-     */
117
-    protected function _get_response_headers()
118
-    {
119
-        return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
120
-            $this->_response_headers,
121
-            $this,
122
-            $this->_requested_version
123
-        );
124
-    }
125
-
126
-
127
-
128
-    /**
129
-     * Adds error notices from EE_Error onto the provided \WP_Error
130
-     *
131
-     * @param \WP_Error $wp_error_response
132
-     * @return \WP_Error
133
-     */
134
-    protected function _add_ee_errors_to_response(\WP_Error $wp_error_response)
135
-    {
136
-        $notices_during_checkin = \EE_Error::get_raw_notices();
137
-        if (! empty($notices_during_checkin['errors'])) {
138
-            foreach ($notices_during_checkin['errors'] as $error_code => $error_message) {
139
-                $wp_error_response->add(
140
-                    sanitize_key($error_code),
141
-                    strip_tags($error_message));
142
-            }
143
-        }
144
-        return $wp_error_response;
145
-    }
146
-
147
-
148
-
149
-    /**
150
-     * Sends a response, but also makes sure to attach headers that
151
-     * are handy for debugging.
152
-     * Specifically, we assume folks will want to know what exactly was the DB query that got run,
153
-     * what exactly was the Models query that got run, what capabilities came into play, what fields were omitted from
154
-     * the response, others?
155
-     *
156
-     * @param array|\WP_Error|\Exception $response
157
-     * @return \WP_REST_Response
158
-     */
159
-    public function send_response($response)
160
-    {
161
-        if ($response instanceof Rest_Exception) {
162
-            $response = new \WP_Error($response->get_string_code(), $response->getMessage(), $response->get_data());
163
-        }
164
-        if ($response instanceof \Exception) {
165
-            $code = $response->getCode() ? $response->getCode() : 'error_occurred';
166
-            $response = new \WP_Error($code, $response->getMessage());
167
-        }
168
-        if ($response instanceof \WP_Error) {
169
-            $response = $this->_add_ee_errors_to_response($response);
170
-            $rest_response = $this->_create_rest_response_from_wp_error($response);
171
-        } else {
172
-            $rest_response = new \WP_REST_Response($response, 200);
173
-        }
174
-        $headers = array();
175
-        if ($this->_debug_mode && is_array($this->_debug_info)) {
176
-            foreach ($this->_debug_info as $debug_key => $debug_info) {
177
-                if (is_array($debug_info)) {
178
-                    $debug_info = wp_json_encode($debug_info);
179
-                }
180
-                $headers['X-EE4-Debug-' . ucwords($debug_key)] = $debug_info;
181
-            }
182
-        }
183
-        $headers = array_merge(
184
-            $headers,
185
-            $this->_get_response_headers(),
186
-            $this->_get_headers_from_ee_notices()
187
-        );
188
-        $rest_response->set_headers($headers);
189
-        return $rest_response;
190
-    }
191
-
192
-
193
-
194
-    /**
195
-     * Converts the \WP_Error into `WP_REST_Response.
196
-     * Mostly this is just a copy-and-paste from \WP_REST_Server::error_to_response
197
-     * (which is protected)
198
-     *
199
-     * @param \WP_Error $wp_error
200
-     * @return \WP_REST_Response
201
-     */
202
-    protected function _create_rest_response_from_wp_error(\WP_Error $wp_error)
203
-    {
204
-        $error_data = $wp_error->get_error_data();
205
-        if (is_array($error_data) && isset($error_data['status'])) {
206
-            $status = $error_data['status'];
207
-        } else {
208
-            $status = 500;
209
-        }
210
-        $errors = array();
211
-        foreach ((array)$wp_error->errors as $code => $messages) {
212
-            foreach ((array)$messages as $message) {
213
-                $errors[] = array(
214
-                    'code'    => $code,
215
-                    'message' => $message,
216
-                    'data'    => $wp_error->get_error_data($code),
217
-                );
218
-            }
219
-        }
220
-        $data = isset($errors[0]) ? $errors[0] : array();
221
-        if (count($errors) > 1) {
222
-            // Remove the primary error.
223
-            array_shift($errors);
224
-            $data['additional_errors'] = $errors;
225
-        }
226
-        return new \WP_REST_Response($data, $status);
227
-    }
228
-
229
-
230
-
231
-    /**
232
-     * Array of headers derived from EE success, attention, and error messages
233
-     *
234
-     * @return array
235
-     */
236
-    protected function _get_headers_from_ee_notices()
237
-    {
238
-        $headers = array();
239
-        $notices = \EE_Error::get_raw_notices();
240
-        foreach ($notices as $notice_type => $sub_notices) {
241
-            if (! is_array($sub_notices)) {
242
-                continue;
243
-            }
244
-            foreach ($sub_notices as $notice_code => $sub_notice) {
245
-                $headers['X-EE4-Notices-'
246
-                         . \EEH_Inflector::humanize($notice_type)
247
-                         . '['
248
-                         . $notice_code
249
-                         . ']'] = strip_tags($sub_notice);
250
-            }
251
-        }
252
-        return apply_filters(
253
-            'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return',
254
-            $headers,
255
-            $this->_requested_version,
256
-            $notices
257
-        );
258
-    }
259
-
260
-
261
-
262
-    /**
263
-     * Finds which version of the API was requested given the route, and returns it.
264
-     * eg in a request to "mysite.com/wp-json/ee/v4.8.29/events/123" this would return
265
-     * "4.8.29"
266
-     *
267
-     * @param string $route
268
-     * @return string
269
-     */
270
-    public function get_requested_version($route = null)
271
-    {
272
-        $matches = $this->parse_route(
273
-            $route,
274
-            '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '~',
275
-            array('version')
276
-        );
277
-        if (isset($matches['version'])) {
278
-            return $matches['version'];
279
-        } else {
280
-            return \EED_Core_Rest_Api::latest_rest_api_version();
281
-        }
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * Applies the regex to the route, then creates an array using the values of
288
-     * $match_keys as keys (but ignores the full pattern match). Returns the array of matches.
289
-     * For example, if you call
290
-     * parse_route( '/ee/v4.8/events', '~\/ee\/v([^/]*)\/(.*)~', array( 'version', 'model' ) )
291
-     * it will return array( 'version' => '4.8', 'model' => 'events' )
292
-     *
293
-     * @param string $route
294
-     * @param string $regex
295
-     * @param array  $match_keys EXCLUDING matching the entire regex
296
-     * @return array where  $match_keys are the keys (the first value of $match_keys
297
-     *                           becomes the first key of the return value, etc. Eg passing in $match_keys of
298
-     *                           array( 'model', 'id' ), will, if the regex is successful, will return
299
-     *                           array( 'model' => 'foo', 'id' => 'bar' )
300
-     * @throws \EE_Error if it couldn't be parsed
301
-     */
302
-    public function parse_route($route, $regex, $match_keys)
303
-    {
304
-        $indexed_matches = array();
305
-        $success = preg_match($regex, $route, $matches);
306
-        if (
307
-        is_array($matches)
308
-        ) {
309
-            //skip the overall regex match. Who cares
310
-            for ($i = 1; $i <= count($match_keys); $i++) {
311
-                if (! isset($matches[$i])) {
312
-                    $success = false;
313
-                } else {
314
-                    $indexed_matches[$match_keys[$i - 1]] = $matches[$i];
315
-                }
316
-            }
317
-        }
318
-        if (! $success) {
319
-            throw new \EE_Error(
320
-                __('We could not parse the URL. Please contact Event Espresso Support', 'event_espresso'),
321
-                'endpoint_parsing_error'
322
-            );
323
-        }
324
-        return $indexed_matches;
325
-    }
23
+	const header_prefix_for_ee = 'X-EE-';
24
+
25
+	const header_prefix_for_wp = 'X-WP-';
26
+
27
+	/**
28
+	 * Contains debug info we'll send back in the response headers
29
+	 *
30
+	 * @var array
31
+	 */
32
+	protected $_debug_info = array();
33
+
34
+	/**
35
+	 * Indicates whether or not the API is in debug mode
36
+	 *
37
+	 * @var boolean
38
+	 */
39
+	protected $_debug_mode = false;
40
+
41
+	/**
42
+	 * Indicates the version that was requested
43
+	 *
44
+	 * @var string
45
+	 */
46
+	protected $_requested_version;
47
+
48
+	/**
49
+	 * flat array of headers to send in the response
50
+	 *
51
+	 * @var array
52
+	 */
53
+	protected $_response_headers = array();
54
+
55
+
56
+
57
+	public function __construct()
58
+	{
59
+		$this->_debug_mode = defined('EE_REST_API_DEBUG_MODE') ? EE_REST_API_DEBUG_MODE : false;
60
+	}
61
+
62
+
63
+
64
+	/**
65
+	 * Sets the version the user requested
66
+	 *
67
+	 * @param string $version eg '4.8'
68
+	 */
69
+	public function set_requested_version($version)
70
+	{
71
+		$this->_requested_version = $version;
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * Sets some debug info that we'll send back in headers
78
+	 *
79
+	 * @param string       $key
80
+	 * @param string|array $info
81
+	 */
82
+	protected function _set_debug_info($key, $info)
83
+	{
84
+		$this->_debug_info[$key] = $info;
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 * Sets headers for the response
91
+	 *
92
+	 * @param string       $header_key    , excluding the "X-EE-" part
93
+	 * @param array|string $value         if an array, multiple headers will be added, one
94
+	 *                                    for each key in the array
95
+	 * @param boolean      $use_ee_prefix whether to use the EE prefix on the header, or fallback to
96
+	 *                                    the standard WP one
97
+	 */
98
+	protected function _set_response_header($header_key, $value, $use_ee_prefix = true)
99
+	{
100
+		if (is_array($value)) {
101
+			foreach ($value as $value_key => $value_value) {
102
+				$this->_set_response_header($header_key . '[' . $value_key . ']', $value_value);
103
+			}
104
+		} else {
105
+			$prefix = $use_ee_prefix ? Base::header_prefix_for_ee : Base::header_prefix_for_wp;
106
+			$this->_response_headers[$prefix . $header_key] = $value;
107
+		}
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * Returns a flat array of headers to be added to the response
114
+	 *
115
+	 * @return array
116
+	 */
117
+	protected function _get_response_headers()
118
+	{
119
+		return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
120
+			$this->_response_headers,
121
+			$this,
122
+			$this->_requested_version
123
+		);
124
+	}
125
+
126
+
127
+
128
+	/**
129
+	 * Adds error notices from EE_Error onto the provided \WP_Error
130
+	 *
131
+	 * @param \WP_Error $wp_error_response
132
+	 * @return \WP_Error
133
+	 */
134
+	protected function _add_ee_errors_to_response(\WP_Error $wp_error_response)
135
+	{
136
+		$notices_during_checkin = \EE_Error::get_raw_notices();
137
+		if (! empty($notices_during_checkin['errors'])) {
138
+			foreach ($notices_during_checkin['errors'] as $error_code => $error_message) {
139
+				$wp_error_response->add(
140
+					sanitize_key($error_code),
141
+					strip_tags($error_message));
142
+			}
143
+		}
144
+		return $wp_error_response;
145
+	}
146
+
147
+
148
+
149
+	/**
150
+	 * Sends a response, but also makes sure to attach headers that
151
+	 * are handy for debugging.
152
+	 * Specifically, we assume folks will want to know what exactly was the DB query that got run,
153
+	 * what exactly was the Models query that got run, what capabilities came into play, what fields were omitted from
154
+	 * the response, others?
155
+	 *
156
+	 * @param array|\WP_Error|\Exception $response
157
+	 * @return \WP_REST_Response
158
+	 */
159
+	public function send_response($response)
160
+	{
161
+		if ($response instanceof Rest_Exception) {
162
+			$response = new \WP_Error($response->get_string_code(), $response->getMessage(), $response->get_data());
163
+		}
164
+		if ($response instanceof \Exception) {
165
+			$code = $response->getCode() ? $response->getCode() : 'error_occurred';
166
+			$response = new \WP_Error($code, $response->getMessage());
167
+		}
168
+		if ($response instanceof \WP_Error) {
169
+			$response = $this->_add_ee_errors_to_response($response);
170
+			$rest_response = $this->_create_rest_response_from_wp_error($response);
171
+		} else {
172
+			$rest_response = new \WP_REST_Response($response, 200);
173
+		}
174
+		$headers = array();
175
+		if ($this->_debug_mode && is_array($this->_debug_info)) {
176
+			foreach ($this->_debug_info as $debug_key => $debug_info) {
177
+				if (is_array($debug_info)) {
178
+					$debug_info = wp_json_encode($debug_info);
179
+				}
180
+				$headers['X-EE4-Debug-' . ucwords($debug_key)] = $debug_info;
181
+			}
182
+		}
183
+		$headers = array_merge(
184
+			$headers,
185
+			$this->_get_response_headers(),
186
+			$this->_get_headers_from_ee_notices()
187
+		);
188
+		$rest_response->set_headers($headers);
189
+		return $rest_response;
190
+	}
191
+
192
+
193
+
194
+	/**
195
+	 * Converts the \WP_Error into `WP_REST_Response.
196
+	 * Mostly this is just a copy-and-paste from \WP_REST_Server::error_to_response
197
+	 * (which is protected)
198
+	 *
199
+	 * @param \WP_Error $wp_error
200
+	 * @return \WP_REST_Response
201
+	 */
202
+	protected function _create_rest_response_from_wp_error(\WP_Error $wp_error)
203
+	{
204
+		$error_data = $wp_error->get_error_data();
205
+		if (is_array($error_data) && isset($error_data['status'])) {
206
+			$status = $error_data['status'];
207
+		} else {
208
+			$status = 500;
209
+		}
210
+		$errors = array();
211
+		foreach ((array)$wp_error->errors as $code => $messages) {
212
+			foreach ((array)$messages as $message) {
213
+				$errors[] = array(
214
+					'code'    => $code,
215
+					'message' => $message,
216
+					'data'    => $wp_error->get_error_data($code),
217
+				);
218
+			}
219
+		}
220
+		$data = isset($errors[0]) ? $errors[0] : array();
221
+		if (count($errors) > 1) {
222
+			// Remove the primary error.
223
+			array_shift($errors);
224
+			$data['additional_errors'] = $errors;
225
+		}
226
+		return new \WP_REST_Response($data, $status);
227
+	}
228
+
229
+
230
+
231
+	/**
232
+	 * Array of headers derived from EE success, attention, and error messages
233
+	 *
234
+	 * @return array
235
+	 */
236
+	protected function _get_headers_from_ee_notices()
237
+	{
238
+		$headers = array();
239
+		$notices = \EE_Error::get_raw_notices();
240
+		foreach ($notices as $notice_type => $sub_notices) {
241
+			if (! is_array($sub_notices)) {
242
+				continue;
243
+			}
244
+			foreach ($sub_notices as $notice_code => $sub_notice) {
245
+				$headers['X-EE4-Notices-'
246
+						 . \EEH_Inflector::humanize($notice_type)
247
+						 . '['
248
+						 . $notice_code
249
+						 . ']'] = strip_tags($sub_notice);
250
+			}
251
+		}
252
+		return apply_filters(
253
+			'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return',
254
+			$headers,
255
+			$this->_requested_version,
256
+			$notices
257
+		);
258
+	}
259
+
260
+
261
+
262
+	/**
263
+	 * Finds which version of the API was requested given the route, and returns it.
264
+	 * eg in a request to "mysite.com/wp-json/ee/v4.8.29/events/123" this would return
265
+	 * "4.8.29"
266
+	 *
267
+	 * @param string $route
268
+	 * @return string
269
+	 */
270
+	public function get_requested_version($route = null)
271
+	{
272
+		$matches = $this->parse_route(
273
+			$route,
274
+			'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '~',
275
+			array('version')
276
+		);
277
+		if (isset($matches['version'])) {
278
+			return $matches['version'];
279
+		} else {
280
+			return \EED_Core_Rest_Api::latest_rest_api_version();
281
+		}
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * Applies the regex to the route, then creates an array using the values of
288
+	 * $match_keys as keys (but ignores the full pattern match). Returns the array of matches.
289
+	 * For example, if you call
290
+	 * parse_route( '/ee/v4.8/events', '~\/ee\/v([^/]*)\/(.*)~', array( 'version', 'model' ) )
291
+	 * it will return array( 'version' => '4.8', 'model' => 'events' )
292
+	 *
293
+	 * @param string $route
294
+	 * @param string $regex
295
+	 * @param array  $match_keys EXCLUDING matching the entire regex
296
+	 * @return array where  $match_keys are the keys (the first value of $match_keys
297
+	 *                           becomes the first key of the return value, etc. Eg passing in $match_keys of
298
+	 *                           array( 'model', 'id' ), will, if the regex is successful, will return
299
+	 *                           array( 'model' => 'foo', 'id' => 'bar' )
300
+	 * @throws \EE_Error if it couldn't be parsed
301
+	 */
302
+	public function parse_route($route, $regex, $match_keys)
303
+	{
304
+		$indexed_matches = array();
305
+		$success = preg_match($regex, $route, $matches);
306
+		if (
307
+		is_array($matches)
308
+		) {
309
+			//skip the overall regex match. Who cares
310
+			for ($i = 1; $i <= count($match_keys); $i++) {
311
+				if (! isset($matches[$i])) {
312
+					$success = false;
313
+				} else {
314
+					$indexed_matches[$match_keys[$i - 1]] = $matches[$i];
315
+				}
316
+			}
317
+		}
318
+		if (! $success) {
319
+			throw new \EE_Error(
320
+				__('We could not parse the URL. Please contact Event Espresso Support', 'event_espresso'),
321
+				'endpoint_parsing_error'
322
+			);
323
+		}
324
+		return $indexed_matches;
325
+	}
326 326
 }
327 327
 
328 328
 // End of file Base.php
329 329
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 
4 4
 use EventEspresso\core\libraries\rest_api\Rest_Exception;
5 5
 
6
-if (! defined('EVENT_ESPRESSO_VERSION')) {
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7 7
     exit('No direct script access allowed');
8 8
 }
9 9
 
@@ -99,11 +99,11 @@  discard block
 block discarded – undo
99 99
     {
100 100
         if (is_array($value)) {
101 101
             foreach ($value as $value_key => $value_value) {
102
-                $this->_set_response_header($header_key . '[' . $value_key . ']', $value_value);
102
+                $this->_set_response_header($header_key.'['.$value_key.']', $value_value);
103 103
             }
104 104
         } else {
105 105
             $prefix = $use_ee_prefix ? Base::header_prefix_for_ee : Base::header_prefix_for_wp;
106
-            $this->_response_headers[$prefix . $header_key] = $value;
106
+            $this->_response_headers[$prefix.$header_key] = $value;
107 107
         }
108 108
     }
109 109
 
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
     protected function _add_ee_errors_to_response(\WP_Error $wp_error_response)
135 135
     {
136 136
         $notices_during_checkin = \EE_Error::get_raw_notices();
137
-        if (! empty($notices_during_checkin['errors'])) {
137
+        if ( ! empty($notices_during_checkin['errors'])) {
138 138
             foreach ($notices_during_checkin['errors'] as $error_code => $error_message) {
139 139
                 $wp_error_response->add(
140 140
                     sanitize_key($error_code),
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
                 if (is_array($debug_info)) {
178 178
                     $debug_info = wp_json_encode($debug_info);
179 179
                 }
180
-                $headers['X-EE4-Debug-' . ucwords($debug_key)] = $debug_info;
180
+                $headers['X-EE4-Debug-'.ucwords($debug_key)] = $debug_info;
181 181
             }
182 182
         }
183 183
         $headers = array_merge(
@@ -208,8 +208,8 @@  discard block
 block discarded – undo
208 208
             $status = 500;
209 209
         }
210 210
         $errors = array();
211
-        foreach ((array)$wp_error->errors as $code => $messages) {
212
-            foreach ((array)$messages as $message) {
211
+        foreach ((array) $wp_error->errors as $code => $messages) {
212
+            foreach ((array) $messages as $message) {
213 213
                 $errors[] = array(
214 214
                     'code'    => $code,
215 215
                     'message' => $message,
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
         $headers = array();
239 239
         $notices = \EE_Error::get_raw_notices();
240 240
         foreach ($notices as $notice_type => $sub_notices) {
241
-            if (! is_array($sub_notices)) {
241
+            if ( ! is_array($sub_notices)) {
242 242
                 continue;
243 243
             }
244 244
             foreach ($sub_notices as $notice_code => $sub_notice) {
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
     {
272 272
         $matches = $this->parse_route(
273 273
             $route,
274
-            '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '~',
274
+            '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'~',
275 275
             array('version')
276 276
         );
277 277
         if (isset($matches['version'])) {
@@ -308,14 +308,14 @@  discard block
 block discarded – undo
308 308
         ) {
309 309
             //skip the overall regex match. Who cares
310 310
             for ($i = 1; $i <= count($match_keys); $i++) {
311
-                if (! isset($matches[$i])) {
311
+                if ( ! isset($matches[$i])) {
312 312
                     $success = false;
313 313
                 } else {
314 314
                     $indexed_matches[$match_keys[$i - 1]] = $matches[$i];
315 315
                 }
316 316
             }
317 317
         }
318
-        if (! $success) {
318
+        if ( ! $success) {
319 319
             throw new \EE_Error(
320 320
                 __('We could not parse the URL. Please contact Event Espresso Support', 'event_espresso'),
321 321
                 'endpoint_parsing_error'
Please login to merge, or discard this patch.
core/libraries/rest_api/Model_Version_Info.php 2 patches
Indentation   +457 added lines, -457 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 namespace EventEspresso\core\libraries\rest_api;
3 3
 
4 4
 if (! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -24,462 +24,462 @@  discard block
 block discarded – undo
24 24
 class Model_Version_Info
25 25
 {
26 26
 
27
-    /**
28
-     * Constant used in the $_model_changes array to indicate that a model
29
-     * was completely new in this version
30
-     */
31
-    const model_added = 'model_added_in_this_version';
32
-
33
-    /**
34
-     * Top-level keys are versions (major and minor version numbers, eg "4.6")
35
-     * next-level keys are model names (eg "Event") that underwent some change in that version
36
-     * and the value is either Model_Version_Info::model_added (indicating the model is completely NEW in this version),
37
-     * or it's an array where the values are model field names,
38
-     * or API resource properties (ie, non-model fields that appear in REST API results)
39
-     * If a version is missing then we don't know anything about what changes it introduced from the previous version
40
-     *
41
-     * @var array
42
-     */
43
-    protected $_model_changes = array();
44
-
45
-    /**
46
-     * top-level keys are version numbers,
47
-     * next-level keys are model CLASSNAMES (even parent classnames),
48
-     * and next-level keys are extra resource properties to attach to those models' resources,
49
-     * and next-level key-value pairs, where the keys are:
50
-     * 'raw', 'type', 'nullable', 'table_alias', 'table_column',  'always_available'
51
-     *
52
-     * @var array
53
-     */
54
-    protected $_resource_changes = array();
55
-
56
-    /**
57
-     * @var string indicating what version of the API was requested
58
-     * (eg although core might be at version 4.8.11, they may have sent a request
59
-     * for 4.6)
60
-     */
61
-    protected $_requested_version = null;
62
-
63
-    /**
64
-     * Keys are model names, values are their classnames.
65
-     * We cache this so we only need to calculate this once per request
66
-     *
67
-     * @var array
68
-     */
69
-    protected $_cached_models_for_requested_version = null;
70
-
71
-    /**
72
-     * @var array
73
-     */
74
-    protected $_cached_model_changes_between_requested_version_and_current = null;
75
-
76
-    /**
77
-     * @var array
78
-     */
79
-    protected $_cached_resource_changes_between_requested_version_and_current = null;
80
-
81
-    /**
82
-     * 2d array where top-level keys are model names, 2nd-level keys are field names
83
-     * and values are the actual field objects
84
-     *
85
-     * @var array
86
-     */
87
-    protected $_cached_fields_on_models = array();
88
-
89
-
90
-
91
-    /**
92
-     * Model_Version_Info constructor.
93
-     *
94
-     * @param string $requested_version
95
-     */
96
-    public function __construct($requested_version)
97
-    {
98
-        $this->_requested_version = $requested_version;
99
-        $this->_model_changes = array(
100
-            '4.8.29' => array(
101
-                //first version where the REST API is in EE core, so no need
102
-                //to specify how its different from the previous
103
-            ),
104
-        );
105
-        //setup data for "extra" fields added onto resources which don't actually exist on models
106
-        $this->_resource_changes = apply_filters(
107
-            'FHEE__Model_Version_Info___construct__extra_resource_properties_for_models',
108
-            array()
109
-        );
110
-        $defaults = array(
111
-            'raw'              => false,
112
-            'type'             => 'N/A',
113
-            'nullable'         => true,
114
-            'table_alias'      => 'N/A',
115
-            'table_column'     => 'N/A',
116
-            'always_available' => true,
117
-        );
118
-        foreach ($this->_resource_changes as $version => $model_classnames) {
119
-            foreach ($model_classnames as $model_classname => $extra_fields) {
120
-                foreach ($extra_fields as $fieldname => $field_data) {
121
-                    $this->_resource_changes[$model_classname][$fieldname]['name'] = $fieldname;
122
-                    foreach ($defaults as $attribute => $default_value) {
123
-                        if (! isset($this->_resource_changes[$model_classname][$fieldname][$attribute])) {
124
-                            $this->_resource_changes[$model_classname][$fieldname][$attribute] = $default_value;
125
-                        }
126
-                    }
127
-                }
128
-            }
129
-        }
130
-    }
131
-
132
-
133
-
134
-    /**
135
-     * Returns a slice of Model_Version_Info::model_changes()'s array
136
-     * indicating exactly what changes happened between the current core version,
137
-     * and the version requested
138
-     *
139
-     * @return array
140
-     */
141
-    public function model_changes_between_requested_version_and_current()
142
-    {
143
-        if ($this->_cached_model_changes_between_requested_version_and_current === null) {
144
-            $model_changes = array();
145
-            foreach ($this->model_changes() as $version => $models_changed_in_version) {
146
-                if ($version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version()) {
147
-                    $model_changes[$version] = $models_changed_in_version;
148
-                }
149
-            }
150
-            $this->_cached_model_changes_between_requested_version_and_current = $model_changes;
151
-        }
152
-        return $this->_cached_model_changes_between_requested_version_and_current;
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * Returns a slice of Model_Version_Info::model_changes()'s array
159
-     * indicating exactly what changes happened between the current core version,
160
-     * and the version requested
161
-     *
162
-     * @return array
163
-     */
164
-    public function resource_changes_between_requested_version_and_current()
165
-    {
166
-        if ($this->_cached_resource_changes_between_requested_version_and_current === null) {
167
-            $resource_changes = array();
168
-            foreach ($this->resource_changes() as $version => $model_classnames) {
169
-                if ($version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version()) {
170
-                    $resource_changes[$version] = $model_classnames;
171
-                }
172
-            }
173
-            $this->_cached_resource_changes_between_requested_version_and_current = $resource_changes;
174
-        }
175
-        return $this->_cached_resource_changes_between_requested_version_and_current;
176
-    }
177
-
178
-
179
-
180
-    /**
181
-     * If a request was sent to 'wp-json/ee/v4.7/events' this would be '4.7'
182
-     *
183
-     * @return string like '4.6'
184
-     */
185
-    public function requested_version()
186
-    {
187
-        return $this->_requested_version;
188
-    }
189
-
190
-
191
-
192
-    /**
193
-     * Returns an array describing how the models have changed in each version of core
194
-     * that supports the API (starting at 4.6)
195
-     * Top-level keys are versions (major and minor version numbers, eg "4.6")
196
-     * next-level keys are model names (eg "Event") that underwent some change in that version
197
-     * and the value is either NULL (indicating the model is completely NEW in this version),
198
-     * or it's an array where fields are value names.
199
-     * If a version is missing then we don't know anything about what changes it introduced from the previous version
200
-     *
201
-     * @return array
202
-     */
203
-    public function model_changes()
204
-    {
205
-        return $this->_model_changes;
206
-    }
207
-
208
-
209
-
210
-    /**
211
-     * Takes into account the requested version, and the current version, and
212
-     * what changed between the two, and tries to return.
213
-     * Analogous to EE_Registry::instance()->non_abstract_db_models
214
-     *
215
-     * @return array keys are model names, values are their classname
216
-     */
217
-    public function models_for_requested_version()
218
-    {
219
-        if ($this->_cached_models_for_requested_version === null) {
220
-            $all_models_in_current_version = \EE_Registry::instance()->non_abstract_db_models;
221
-            foreach ($this->model_changes_between_requested_version_and_current() as $version => $models_changed) {
222
-                foreach ($models_changed as $model_name => $new_indicator_or_fields_added) {
223
-                    if ($new_indicator_or_fields_added === Model_Version_Info::model_added) {
224
-                        unset($all_models_in_current_version[$model_name]);
225
-                    }
226
-                }
227
-            }
228
-            $this->_cached_models_for_requested_version = apply_filters(
229
-                'FHEE__EventEspresso_core_libraries_rest_api__models_for_requested_version',
230
-                $all_models_in_current_version,
231
-                $this
232
-            );
233
-        }
234
-        return $this->_cached_models_for_requested_version;
235
-    }
236
-
237
-
238
-
239
-    /**
240
-     * Determines if this is a valid model name in the requested version.
241
-     * Similar to EE_Registry::instance()->is_model_name(), but takes the requested
242
-     * version's models into account
243
-     *
244
-     * @param string $model_name eg 'Event'
245
-     * @return boolean
246
-     */
247
-    public function is_model_name_in_this_version($model_name)
248
-    {
249
-        $model_names = $this->models_for_requested_version();
250
-        if (isset($model_names[$model_name])) {
251
-            return true;
252
-        } else {
253
-            return false;
254
-        }
255
-    }
256
-
257
-
258
-
259
-    /**
260
-     * Wrapper for EE_Registry::instance()->load_model(), but takes the requested
261
-     * version's models into account
262
-     *
263
-     * @param string $model_name
264
-     * @return \EEM_Base
265
-     * @throws \EE_Error
266
-     */
267
-    public function load_model($model_name)
268
-    {
269
-        if ($this->is_model_name_in_this_version($model_name)) {
270
-            return \EE_Registry::instance()->load_model($model_name);
271
-        } else {
272
-            throw new \EE_Error(
273
-                sprintf(
274
-                    __(
275
-                        'Cannot load model "%1$s" because it does not exist in version %2$s of Event Espresso',
276
-                        'event_espresso'
277
-                    ),
278
-                    $model_name,
279
-                    $this->requested_version()
280
-                )
281
-            );
282
-        }
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * Gets all the fields that should exist on this model right now
289
-     *
290
-     * @param \EEM_Base $model
291
-     * @return array|\EE_Model_Field_Base[]
292
-     */
293
-    public function fields_on_model_in_this_version($model)
294
-    {
295
-        if (! isset($this->_cached_fields_on_models[$model->get_this_model_name()])) {
296
-            //get all model changes between the requested version and current core version
297
-            $changes = $this->model_changes_between_requested_version_and_current();
298
-            //fetch all fields currently on this model
299
-            $current_fields = $model->field_settings();
300
-            //remove all fields that have been added since
301
-            foreach ($changes as $version => $changes_in_version) {
302
-                if (
303
-                    isset($changes_in_version[$model->get_this_model_name()])
304
-                    && $changes_in_version[$model->get_this_model_name()] !== Model_Version_Info::model_added
305
-                ) {
306
-                    $current_fields = array_diff_key(
307
-                        $current_fields,
308
-                        array_flip($changes_in_version[$model->get_this_model_name()])
309
-                    );
310
-                }
311
-            }
312
-            $this->_cached_fields_on_models = $current_fields;
313
-        }
314
-        return $this->_cached_fields_on_models;
315
-    }
316
-
317
-
318
-
319
-    /**
320
-     * Determines if $object is of one of the classes of $classes. Similar to
321
-     * in_array(), except this checks if $object is a subclass of the classnames provided
322
-     * in $classnames
323
-     *
324
-     * @param object $object
325
-     * @param array  $classnames
326
-     * @return boolean
327
-     */
328
-    public function is_subclass_of_one($object, $classnames)
329
-    {
330
-        foreach ($classnames as $classname) {
331
-            if (is_a($object, $classname)) {
332
-                return true;
333
-            }
334
-        }
335
-        return false;
336
-    }
337
-
338
-
339
-
340
-    /**
341
-     * Returns the list of model field classes that that the API basically ignores
342
-     *
343
-     * @return array
344
-     */
345
-    public function fields_ignored()
346
-    {
347
-        return apply_filters(
348
-            'FHEE__Controller_Model_Read_fields_ignored',
349
-            array('EE_Foreign_Key_Field_Base', 'EE_Any_Foreign_Model_Name_Field')
350
-        );
351
-    }
352
-
353
-
354
-
355
-    /**
356
-     * If this field one that should be ignored by the API?
357
-     *
358
-     * @param EE_Model_Field_Base
359
-     * @return boolean
360
-     */
361
-    public function field_is_ignored($field_obj)
362
-    {
363
-        return $this->is_subclass_of_one($field_obj, $this->fields_ignored());
364
-    }
365
-
366
-
367
-
368
-    /**
369
-     * Returns the list of model field classes that have a "raw" and non-raw formats.
370
-     * Normally the "raw" versions are only accessible to those who can edit them.
371
-     *
372
-     * @return array an array of EE_Model_Field_Base child classnames
373
-     */
374
-    public function fields_that_have_rendered_format()
375
-    {
376
-        return apply_filters(
377
-            'FHEE__Controller_Model_Read__fields_raw',
378
-            array('EE_Post_Content_Field', 'EE_Full_HTML_Field')
379
-        );
380
-    }
381
-
382
-
383
-
384
-    /**
385
-     * If this field one that has a raw format
386
-     *
387
-     * @param EE_Model_Field_Base
388
-     * @return boolean
389
-     */
390
-    public function field_has_rendered_format($field_obj)
391
-    {
392
-        return $this->is_subclass_of_one($field_obj, $this->fields_that_have_rendered_format());
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     * Returns the list of model field classes that have a "_pretty" and non-pretty versions.
399
-     * The pretty version of the field is NOT queryable or editable, but requires no extra permissions
400
-     * to view
401
-     *
402
-     * @return array an array of EE_Model_Field_Base child classnames
403
-     */
404
-    public function fields_that_have_pretty_format()
405
-    {
406
-        return apply_filters(
407
-            'FHEE__Controller_Model_Read__fields_pretty',
408
-            array('EE_Enum_Integer_Field', 'EE_Enum_Text_Field', 'EE_Money_Field')
409
-        );
410
-    }
411
-
412
-
413
-
414
-    /**
415
-     * If this field one that has a pretty equivalent
416
-     *
417
-     * @param EE_Model_Field_Base
418
-     * @return boolean
419
-     */
420
-    public function field_has_pretty_format($field_obj)
421
-    {
422
-        return $this->is_subclass_of_one($field_obj, $this->fields_that_have_pretty_format());
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * Returns an array describing what extra API resource properties have been added through the versions
429
-     *
430
-     * @return array @see $this->_extra_resource_properties_for_models
431
-     */
432
-    public function resource_changes()
433
-    {
434
-        return $this->_resource_changes;
435
-    }
436
-
437
-
438
-
439
-    /**
440
-     * Returns an array where keys are extra resource properties in this version of the API,
441
-     * and values are key-value pairs describing the new properties. @see Model_Version::_resource_changes
442
-     *
443
-     * @param \EEM_Base $model
444
-     * @return array
445
-     */
446
-    public function extra_resource_properties_for_model($model)
447
-    {
448
-        $extra_properties = array();
449
-        foreach ($this->resource_changes_between_requested_version_and_current() as $version => $model_classnames) {
450
-            foreach ($model_classnames as $model_classname => $properties_added_in_this_version) {
451
-                if (is_subclass_of($model, $model_classname)) {
452
-                    $extra_properties = array_merge($extra_properties, $properties_added_in_this_version);
453
-                }
454
-            }
455
-        }
456
-        return $extra_properties;
457
-    }
458
-
459
-
460
-
461
-    /**
462
-     * Gets all the related models for the specified model. It's good to use this
463
-     * in case this model didn't exist for this version or something
464
-     *
465
-     * @param \EEM_Base $model
466
-     * @return \EE_Model_Relation_Base[]
467
-     */
468
-    public function relation_settings(\EEM_Base $model)
469
-    {
470
-        $relations = array();
471
-        foreach ($model->relation_settings() as $relation_name => $relation_obj) {
472
-            if ($this->is_model_name_in_this_version($relation_name)) {
473
-                $relations[$relation_name] = $relation_obj;
474
-            }
475
-        }
476
-        //filter the results, but use the old filter name
477
-        return apply_filters(
478
-            'FHEE__Read__create_entity_from_wpdb_result__related_models_to_include',
479
-            $relations,
480
-            $model
481
-        );
482
-    }
27
+	/**
28
+	 * Constant used in the $_model_changes array to indicate that a model
29
+	 * was completely new in this version
30
+	 */
31
+	const model_added = 'model_added_in_this_version';
32
+
33
+	/**
34
+	 * Top-level keys are versions (major and minor version numbers, eg "4.6")
35
+	 * next-level keys are model names (eg "Event") that underwent some change in that version
36
+	 * and the value is either Model_Version_Info::model_added (indicating the model is completely NEW in this version),
37
+	 * or it's an array where the values are model field names,
38
+	 * or API resource properties (ie, non-model fields that appear in REST API results)
39
+	 * If a version is missing then we don't know anything about what changes it introduced from the previous version
40
+	 *
41
+	 * @var array
42
+	 */
43
+	protected $_model_changes = array();
44
+
45
+	/**
46
+	 * top-level keys are version numbers,
47
+	 * next-level keys are model CLASSNAMES (even parent classnames),
48
+	 * and next-level keys are extra resource properties to attach to those models' resources,
49
+	 * and next-level key-value pairs, where the keys are:
50
+	 * 'raw', 'type', 'nullable', 'table_alias', 'table_column',  'always_available'
51
+	 *
52
+	 * @var array
53
+	 */
54
+	protected $_resource_changes = array();
55
+
56
+	/**
57
+	 * @var string indicating what version of the API was requested
58
+	 * (eg although core might be at version 4.8.11, they may have sent a request
59
+	 * for 4.6)
60
+	 */
61
+	protected $_requested_version = null;
62
+
63
+	/**
64
+	 * Keys are model names, values are their classnames.
65
+	 * We cache this so we only need to calculate this once per request
66
+	 *
67
+	 * @var array
68
+	 */
69
+	protected $_cached_models_for_requested_version = null;
70
+
71
+	/**
72
+	 * @var array
73
+	 */
74
+	protected $_cached_model_changes_between_requested_version_and_current = null;
75
+
76
+	/**
77
+	 * @var array
78
+	 */
79
+	protected $_cached_resource_changes_between_requested_version_and_current = null;
80
+
81
+	/**
82
+	 * 2d array where top-level keys are model names, 2nd-level keys are field names
83
+	 * and values are the actual field objects
84
+	 *
85
+	 * @var array
86
+	 */
87
+	protected $_cached_fields_on_models = array();
88
+
89
+
90
+
91
+	/**
92
+	 * Model_Version_Info constructor.
93
+	 *
94
+	 * @param string $requested_version
95
+	 */
96
+	public function __construct($requested_version)
97
+	{
98
+		$this->_requested_version = $requested_version;
99
+		$this->_model_changes = array(
100
+			'4.8.29' => array(
101
+				//first version where the REST API is in EE core, so no need
102
+				//to specify how its different from the previous
103
+			),
104
+		);
105
+		//setup data for "extra" fields added onto resources which don't actually exist on models
106
+		$this->_resource_changes = apply_filters(
107
+			'FHEE__Model_Version_Info___construct__extra_resource_properties_for_models',
108
+			array()
109
+		);
110
+		$defaults = array(
111
+			'raw'              => false,
112
+			'type'             => 'N/A',
113
+			'nullable'         => true,
114
+			'table_alias'      => 'N/A',
115
+			'table_column'     => 'N/A',
116
+			'always_available' => true,
117
+		);
118
+		foreach ($this->_resource_changes as $version => $model_classnames) {
119
+			foreach ($model_classnames as $model_classname => $extra_fields) {
120
+				foreach ($extra_fields as $fieldname => $field_data) {
121
+					$this->_resource_changes[$model_classname][$fieldname]['name'] = $fieldname;
122
+					foreach ($defaults as $attribute => $default_value) {
123
+						if (! isset($this->_resource_changes[$model_classname][$fieldname][$attribute])) {
124
+							$this->_resource_changes[$model_classname][$fieldname][$attribute] = $default_value;
125
+						}
126
+					}
127
+				}
128
+			}
129
+		}
130
+	}
131
+
132
+
133
+
134
+	/**
135
+	 * Returns a slice of Model_Version_Info::model_changes()'s array
136
+	 * indicating exactly what changes happened between the current core version,
137
+	 * and the version requested
138
+	 *
139
+	 * @return array
140
+	 */
141
+	public function model_changes_between_requested_version_and_current()
142
+	{
143
+		if ($this->_cached_model_changes_between_requested_version_and_current === null) {
144
+			$model_changes = array();
145
+			foreach ($this->model_changes() as $version => $models_changed_in_version) {
146
+				if ($version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version()) {
147
+					$model_changes[$version] = $models_changed_in_version;
148
+				}
149
+			}
150
+			$this->_cached_model_changes_between_requested_version_and_current = $model_changes;
151
+		}
152
+		return $this->_cached_model_changes_between_requested_version_and_current;
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * Returns a slice of Model_Version_Info::model_changes()'s array
159
+	 * indicating exactly what changes happened between the current core version,
160
+	 * and the version requested
161
+	 *
162
+	 * @return array
163
+	 */
164
+	public function resource_changes_between_requested_version_and_current()
165
+	{
166
+		if ($this->_cached_resource_changes_between_requested_version_and_current === null) {
167
+			$resource_changes = array();
168
+			foreach ($this->resource_changes() as $version => $model_classnames) {
169
+				if ($version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version()) {
170
+					$resource_changes[$version] = $model_classnames;
171
+				}
172
+			}
173
+			$this->_cached_resource_changes_between_requested_version_and_current = $resource_changes;
174
+		}
175
+		return $this->_cached_resource_changes_between_requested_version_and_current;
176
+	}
177
+
178
+
179
+
180
+	/**
181
+	 * If a request was sent to 'wp-json/ee/v4.7/events' this would be '4.7'
182
+	 *
183
+	 * @return string like '4.6'
184
+	 */
185
+	public function requested_version()
186
+	{
187
+		return $this->_requested_version;
188
+	}
189
+
190
+
191
+
192
+	/**
193
+	 * Returns an array describing how the models have changed in each version of core
194
+	 * that supports the API (starting at 4.6)
195
+	 * Top-level keys are versions (major and minor version numbers, eg "4.6")
196
+	 * next-level keys are model names (eg "Event") that underwent some change in that version
197
+	 * and the value is either NULL (indicating the model is completely NEW in this version),
198
+	 * or it's an array where fields are value names.
199
+	 * If a version is missing then we don't know anything about what changes it introduced from the previous version
200
+	 *
201
+	 * @return array
202
+	 */
203
+	public function model_changes()
204
+	{
205
+		return $this->_model_changes;
206
+	}
207
+
208
+
209
+
210
+	/**
211
+	 * Takes into account the requested version, and the current version, and
212
+	 * what changed between the two, and tries to return.
213
+	 * Analogous to EE_Registry::instance()->non_abstract_db_models
214
+	 *
215
+	 * @return array keys are model names, values are their classname
216
+	 */
217
+	public function models_for_requested_version()
218
+	{
219
+		if ($this->_cached_models_for_requested_version === null) {
220
+			$all_models_in_current_version = \EE_Registry::instance()->non_abstract_db_models;
221
+			foreach ($this->model_changes_between_requested_version_and_current() as $version => $models_changed) {
222
+				foreach ($models_changed as $model_name => $new_indicator_or_fields_added) {
223
+					if ($new_indicator_or_fields_added === Model_Version_Info::model_added) {
224
+						unset($all_models_in_current_version[$model_name]);
225
+					}
226
+				}
227
+			}
228
+			$this->_cached_models_for_requested_version = apply_filters(
229
+				'FHEE__EventEspresso_core_libraries_rest_api__models_for_requested_version',
230
+				$all_models_in_current_version,
231
+				$this
232
+			);
233
+		}
234
+		return $this->_cached_models_for_requested_version;
235
+	}
236
+
237
+
238
+
239
+	/**
240
+	 * Determines if this is a valid model name in the requested version.
241
+	 * Similar to EE_Registry::instance()->is_model_name(), but takes the requested
242
+	 * version's models into account
243
+	 *
244
+	 * @param string $model_name eg 'Event'
245
+	 * @return boolean
246
+	 */
247
+	public function is_model_name_in_this_version($model_name)
248
+	{
249
+		$model_names = $this->models_for_requested_version();
250
+		if (isset($model_names[$model_name])) {
251
+			return true;
252
+		} else {
253
+			return false;
254
+		}
255
+	}
256
+
257
+
258
+
259
+	/**
260
+	 * Wrapper for EE_Registry::instance()->load_model(), but takes the requested
261
+	 * version's models into account
262
+	 *
263
+	 * @param string $model_name
264
+	 * @return \EEM_Base
265
+	 * @throws \EE_Error
266
+	 */
267
+	public function load_model($model_name)
268
+	{
269
+		if ($this->is_model_name_in_this_version($model_name)) {
270
+			return \EE_Registry::instance()->load_model($model_name);
271
+		} else {
272
+			throw new \EE_Error(
273
+				sprintf(
274
+					__(
275
+						'Cannot load model "%1$s" because it does not exist in version %2$s of Event Espresso',
276
+						'event_espresso'
277
+					),
278
+					$model_name,
279
+					$this->requested_version()
280
+				)
281
+			);
282
+		}
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * Gets all the fields that should exist on this model right now
289
+	 *
290
+	 * @param \EEM_Base $model
291
+	 * @return array|\EE_Model_Field_Base[]
292
+	 */
293
+	public function fields_on_model_in_this_version($model)
294
+	{
295
+		if (! isset($this->_cached_fields_on_models[$model->get_this_model_name()])) {
296
+			//get all model changes between the requested version and current core version
297
+			$changes = $this->model_changes_between_requested_version_and_current();
298
+			//fetch all fields currently on this model
299
+			$current_fields = $model->field_settings();
300
+			//remove all fields that have been added since
301
+			foreach ($changes as $version => $changes_in_version) {
302
+				if (
303
+					isset($changes_in_version[$model->get_this_model_name()])
304
+					&& $changes_in_version[$model->get_this_model_name()] !== Model_Version_Info::model_added
305
+				) {
306
+					$current_fields = array_diff_key(
307
+						$current_fields,
308
+						array_flip($changes_in_version[$model->get_this_model_name()])
309
+					);
310
+				}
311
+			}
312
+			$this->_cached_fields_on_models = $current_fields;
313
+		}
314
+		return $this->_cached_fields_on_models;
315
+	}
316
+
317
+
318
+
319
+	/**
320
+	 * Determines if $object is of one of the classes of $classes. Similar to
321
+	 * in_array(), except this checks if $object is a subclass of the classnames provided
322
+	 * in $classnames
323
+	 *
324
+	 * @param object $object
325
+	 * @param array  $classnames
326
+	 * @return boolean
327
+	 */
328
+	public function is_subclass_of_one($object, $classnames)
329
+	{
330
+		foreach ($classnames as $classname) {
331
+			if (is_a($object, $classname)) {
332
+				return true;
333
+			}
334
+		}
335
+		return false;
336
+	}
337
+
338
+
339
+
340
+	/**
341
+	 * Returns the list of model field classes that that the API basically ignores
342
+	 *
343
+	 * @return array
344
+	 */
345
+	public function fields_ignored()
346
+	{
347
+		return apply_filters(
348
+			'FHEE__Controller_Model_Read_fields_ignored',
349
+			array('EE_Foreign_Key_Field_Base', 'EE_Any_Foreign_Model_Name_Field')
350
+		);
351
+	}
352
+
353
+
354
+
355
+	/**
356
+	 * If this field one that should be ignored by the API?
357
+	 *
358
+	 * @param EE_Model_Field_Base
359
+	 * @return boolean
360
+	 */
361
+	public function field_is_ignored($field_obj)
362
+	{
363
+		return $this->is_subclass_of_one($field_obj, $this->fields_ignored());
364
+	}
365
+
366
+
367
+
368
+	/**
369
+	 * Returns the list of model field classes that have a "raw" and non-raw formats.
370
+	 * Normally the "raw" versions are only accessible to those who can edit them.
371
+	 *
372
+	 * @return array an array of EE_Model_Field_Base child classnames
373
+	 */
374
+	public function fields_that_have_rendered_format()
375
+	{
376
+		return apply_filters(
377
+			'FHEE__Controller_Model_Read__fields_raw',
378
+			array('EE_Post_Content_Field', 'EE_Full_HTML_Field')
379
+		);
380
+	}
381
+
382
+
383
+
384
+	/**
385
+	 * If this field one that has a raw format
386
+	 *
387
+	 * @param EE_Model_Field_Base
388
+	 * @return boolean
389
+	 */
390
+	public function field_has_rendered_format($field_obj)
391
+	{
392
+		return $this->is_subclass_of_one($field_obj, $this->fields_that_have_rendered_format());
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 * Returns the list of model field classes that have a "_pretty" and non-pretty versions.
399
+	 * The pretty version of the field is NOT queryable or editable, but requires no extra permissions
400
+	 * to view
401
+	 *
402
+	 * @return array an array of EE_Model_Field_Base child classnames
403
+	 */
404
+	public function fields_that_have_pretty_format()
405
+	{
406
+		return apply_filters(
407
+			'FHEE__Controller_Model_Read__fields_pretty',
408
+			array('EE_Enum_Integer_Field', 'EE_Enum_Text_Field', 'EE_Money_Field')
409
+		);
410
+	}
411
+
412
+
413
+
414
+	/**
415
+	 * If this field one that has a pretty equivalent
416
+	 *
417
+	 * @param EE_Model_Field_Base
418
+	 * @return boolean
419
+	 */
420
+	public function field_has_pretty_format($field_obj)
421
+	{
422
+		return $this->is_subclass_of_one($field_obj, $this->fields_that_have_pretty_format());
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * Returns an array describing what extra API resource properties have been added through the versions
429
+	 *
430
+	 * @return array @see $this->_extra_resource_properties_for_models
431
+	 */
432
+	public function resource_changes()
433
+	{
434
+		return $this->_resource_changes;
435
+	}
436
+
437
+
438
+
439
+	/**
440
+	 * Returns an array where keys are extra resource properties in this version of the API,
441
+	 * and values are key-value pairs describing the new properties. @see Model_Version::_resource_changes
442
+	 *
443
+	 * @param \EEM_Base $model
444
+	 * @return array
445
+	 */
446
+	public function extra_resource_properties_for_model($model)
447
+	{
448
+		$extra_properties = array();
449
+		foreach ($this->resource_changes_between_requested_version_and_current() as $version => $model_classnames) {
450
+			foreach ($model_classnames as $model_classname => $properties_added_in_this_version) {
451
+				if (is_subclass_of($model, $model_classname)) {
452
+					$extra_properties = array_merge($extra_properties, $properties_added_in_this_version);
453
+				}
454
+			}
455
+		}
456
+		return $extra_properties;
457
+	}
458
+
459
+
460
+
461
+	/**
462
+	 * Gets all the related models for the specified model. It's good to use this
463
+	 * in case this model didn't exist for this version or something
464
+	 *
465
+	 * @param \EEM_Base $model
466
+	 * @return \EE_Model_Relation_Base[]
467
+	 */
468
+	public function relation_settings(\EEM_Base $model)
469
+	{
470
+		$relations = array();
471
+		foreach ($model->relation_settings() as $relation_name => $relation_obj) {
472
+			if ($this->is_model_name_in_this_version($relation_name)) {
473
+				$relations[$relation_name] = $relation_obj;
474
+			}
475
+		}
476
+		//filter the results, but use the old filter name
477
+		return apply_filters(
478
+			'FHEE__Read__create_entity_from_wpdb_result__related_models_to_include',
479
+			$relations,
480
+			$model
481
+		);
482
+	}
483 483
 
484 484
 }
485 485
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\libraries\rest_api;
3 3
 
4
-if (! defined('EVENT_ESPRESSO_VERSION')) {
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5 5
     exit('No direct script access allowed');
6 6
 }
7 7
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                 foreach ($extra_fields as $fieldname => $field_data) {
121 121
                     $this->_resource_changes[$model_classname][$fieldname]['name'] = $fieldname;
122 122
                     foreach ($defaults as $attribute => $default_value) {
123
-                        if (! isset($this->_resource_changes[$model_classname][$fieldname][$attribute])) {
123
+                        if ( ! isset($this->_resource_changes[$model_classname][$fieldname][$attribute])) {
124 124
                             $this->_resource_changes[$model_classname][$fieldname][$attribute] = $default_value;
125 125
                         }
126 126
                     }
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
      */
293 293
     public function fields_on_model_in_this_version($model)
294 294
     {
295
-        if (! isset($this->_cached_fields_on_models[$model->get_this_model_name()])) {
295
+        if ( ! isset($this->_cached_fields_on_models[$model->get_this_model_name()])) {
296 296
             //get all model changes between the requested version and current core version
297 297
             $changes = $this->model_changes_between_requested_version_and_current();
298 298
             //fetch all fields currently on this model
Please login to merge, or discard this patch.
core/libraries/rest_api/Model_Data_Translator.php 2 patches
Indentation   +481 added lines, -481 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 namespace EventEspresso\core\libraries\rest_api;
3 3
 
4 4
 if (! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -27,485 +27,485 @@  discard block
 block discarded – undo
27 27
 class Model_Data_Translator
28 28
 {
29 29
 
30
-    /**
31
-     * We used to use -1 for infinity in the rest api, but that's ambiguous for
32
-     * fields that COULD contain -1; so we use null
33
-     */
34
-    const ee_inf_in_rest = null;
35
-
36
-
37
-
38
-    /**
39
-     * Prepares a possible array of input values from JSON for use by the models
40
-     *
41
-     * @param \EE_Model_Field_Base $field_obj
42
-     * @param mixed                $original_value_maybe_array
43
-     * @param string               $requested_version
44
-     * @param string               $timezone_string treat values as being in this timezone
45
-     * @return mixed
46
-     * @throws \DomainException
47
-     */
48
-    public static function prepare_field_values_from_json(
49
-        $field_obj,
50
-        $original_value_maybe_array,
51
-        $requested_version,
52
-        $timezone_string = 'UTC'
53
-    ) {
54
-        if (is_array($original_value_maybe_array)) {
55
-            $new_value_maybe_array = array();
56
-            foreach ($original_value_maybe_array as $array_key => $array_item) {
57
-                $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_from_json(
58
-                    $field_obj,
59
-                    $array_item,
60
-                    $requested_version,
61
-                    $timezone_string
62
-                );
63
-            }
64
-        } else {
65
-            $new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json(
66
-                $field_obj,
67
-                $original_value_maybe_array,
68
-                $requested_version,
69
-                $timezone_string
70
-            );
71
-        }
72
-        return $new_value_maybe_array;
73
-    }
74
-
75
-
76
-
77
-    /**
78
-     * Prepares an array of field values FOR use in JSON/REST API
79
-     *
80
-     * @param \EE_Model_Field_Base $field_obj
81
-     * @param mixed                $original_value_maybe_array
82
-     * @param string               $request_version (eg 4.8.36)
83
-     * @return array
84
-     */
85
-    public static function prepare_field_values_for_json($field_obj, $original_value_maybe_array, $request_version)
86
-    {
87
-        if (is_array($original_value_maybe_array)) {
88
-            $new_value_maybe_array = array();
89
-            foreach ($original_value_maybe_array as $array_key => $array_item) {
90
-                $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_for_json(
91
-                    $field_obj,
92
-                    $array_item,
93
-                    $request_version
94
-                );
95
-            }
96
-        } else {
97
-            $new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json(
98
-                $field_obj,
99
-                $original_value_maybe_array,
100
-                $request_version
101
-            );
102
-        }
103
-        return $new_value_maybe_array;
104
-    }
105
-
106
-
107
-
108
-    /**
109
-     * Prepares incoming data from the json or $_REQUEST parameters for the models'
110
-     * "$query_params".
111
-     *
112
-     * @param \EE_Model_Field_Base $field_obj
113
-     * @param mixed                $original_value
114
-     * @param string               $requested_version
115
-     * @param string               $timezone_string treat values as being in this timezone
116
-     * @return mixed
117
-     * @throws \DomainException
118
-     */
119
-    public static function prepare_field_value_from_json(
120
-        $field_obj,
121
-        $original_value,
122
-        $requested_version,
123
-        $timezone_string = 'UTC' // UTC
124
-    )
125
-    {
126
-        $timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', '');
127
-        $new_value = null;
128
-        if ($field_obj instanceof \EE_Infinite_Integer_Field
129
-            && in_array($original_value, array(null, ''), true)
130
-        ) {
131
-            $new_value = EE_INF;
132
-        } elseif ($field_obj instanceof \EE_Datetime_Field) {
133
-            list($offset_sign, $offset_secs) = Model_Data_Translator::parse_timezone_offset(
134
-                $field_obj->get_timezone_offset(
135
-                    new \DateTimeZone($timezone_string)
136
-                )
137
-            );
138
-            $offset_string =
139
-                str_pad(
140
-                    floor($offset_secs / HOUR_IN_SECONDS),
141
-                    2,
142
-                    '0',
143
-                    STR_PAD_LEFT
144
-                )
145
-                . ':'
146
-                . str_pad(
147
-                    ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS,
148
-                    2,
149
-                    '0',
150
-                    STR_PAD_LEFT
151
-                );
152
-            $new_value = rest_parse_date($original_value . $offset_sign . $offset_string);
153
-        } else {
154
-            $new_value = $original_value;
155
-        }
156
-        return $new_value;
157
-    }
158
-
159
-
160
-
161
-    /**
162
-     * determines what's going on with them timezone strings
163
-     *
164
-     * @param int $timezone_offset
165
-     * @return array
166
-     */
167
-    private static function parse_timezone_offset($timezone_offset)
168
-    {
169
-        $first_char = substr((string)$timezone_offset, 0, 1);
170
-        if ($first_char === '+' || $first_char === '-') {
171
-            $offset_sign = $first_char;
172
-            $offset_secs = substr((string)$timezone_offset, 1);
173
-        } else {
174
-            $offset_sign = '+';
175
-            $offset_secs = $timezone_offset;
176
-        }
177
-        return array($offset_sign, $offset_secs);
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     * Prepares a field's value for display in the API
184
-     *
185
-     * @param \EE_Model_Field_Base $field_obj
186
-     * @param mixed                $original_value
187
-     * @param string               $requested_version
188
-     * @return mixed
189
-     */
190
-    public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version)
191
-    {
192
-        if ($original_value === EE_INF) {
193
-            $new_value = Model_Data_Translator::ee_inf_in_rest;
194
-        } elseif ($field_obj instanceof \EE_Datetime_Field) {
195
-            if ($original_value instanceof \DateTime) {
196
-                $new_value = $original_value->format('Y-m-d H:i:s');
197
-            } elseif (is_int($original_value)) {
198
-                $new_value = date('Y-m-d H:i:s', $original_value);
199
-            } else {
200
-                $new_value = $original_value;
201
-            }
202
-            $new_value = mysql_to_rfc3339($new_value);
203
-        } else {
204
-            $new_value = $original_value;
205
-        }
206
-        return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
207
-            $new_value,
208
-            $field_obj,
209
-            $original_value,
210
-            $requested_version
211
-        );
212
-    }
213
-
214
-
215
-
216
-    /**
217
-     * Prepares condition-query-parameters (like what's in where and having) from
218
-     * the format expected in the API to use in the models
219
-     *
220
-     * @param array     $inputted_query_params_of_this_type
221
-     * @param \EEM_Base $model
222
-     * @param string    $requested_version
223
-     * @return array
224
-     * @throws \DomainException
225
-     * @throws \EE_Error
226
-     */
227
-    public static function prepare_conditions_query_params_for_models(
228
-        $inputted_query_params_of_this_type,
229
-        \EEM_Base $model,
230
-        $requested_version
231
-    ) {
232
-        $query_param_for_models = array();
233
-        foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
234
-            $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key);
235
-            $field = Model_Data_Translator::deduce_field_from_query_param(
236
-                $query_param_sans_stars,
237
-                $model
238
-            );
239
-            //double-check is it a *_gmt field?
240
-            if (! $field instanceof \EE_Model_Field_Base
241
-                && Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars)
242
-            ) {
243
-                //yep, take off '_gmt', and find the field
244
-                $query_param_key = Model_Data_Translator::remove_gmt_from_field_name($query_param_sans_stars);
245
-                $field = Model_Data_Translator::deduce_field_from_query_param(
246
-                    $query_param_key,
247
-                    $model
248
-                );
249
-                $timezone = 'UTC';
250
-            } else {
251
-                //so it's not a GMT field. Set the timezone on the model to the default
252
-                $timezone = \EEH_DTT_Helper::get_valid_timezone_string();
253
-            }
254
-            if ($field instanceof \EE_Model_Field_Base) {
255
-                //did they specify an operator?
256
-                if (is_array($query_param_value)) {
257
-                    $op = $query_param_value[0];
258
-                    $translated_value = array($op);
259
-                    if (isset($query_param_value[1])) {
260
-                        $value = $query_param_value[1];
261
-                        $translated_value[1] = Model_Data_Translator::prepare_field_values_from_json($field, $value,
262
-                            $requested_version, $timezone);
263
-                    }
264
-                } else {
265
-                    $translated_value = Model_Data_Translator::prepare_field_value_from_json($field, $query_param_value,
266
-                        $requested_version, $timezone);
267
-                }
268
-                $query_param_for_models[$query_param_key] = $translated_value;
269
-            } else {
270
-                //so it's not for a field, assume it's a logic query param key
271
-                $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_models($query_param_value,
272
-                    $model, $requested_version);
273
-            }
274
-        }
275
-        return $query_param_for_models;
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * Mostly checks if the last 4 characters are "_gmt", indicating its a
282
-     * gmt date field name
283
-     *
284
-     * @param string $field_name
285
-     * @return boolean
286
-     */
287
-    public static function is_gmt_date_field_name($field_name)
288
-    {
289
-        return substr(
290
-                   Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name),
291
-                   -4,
292
-                   4
293
-               ) === '_gmt';
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone)
300
-     *
301
-     * @param string $field_name
302
-     * @return string
303
-     */
304
-    public static function remove_gmt_from_field_name($field_name)
305
-    {
306
-        if (! Model_Data_Translator::is_gmt_date_field_name($field_name)) {
307
-            return $field_name;
308
-        }
309
-        $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name);
310
-        $query_param_sans_gmt_and_sans_stars = substr(
311
-            $query_param_sans_stars,
312
-            0,
313
-            strrpos(
314
-                $field_name,
315
-                '_gmt'
316
-            )
317
-        );
318
-        return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name);
319
-    }
320
-
321
-
322
-
323
-    /**
324
-     * Takes a field name from the REST API and prepares it for the model querying
325
-     *
326
-     * @param string $field_name
327
-     * @return string
328
-     */
329
-    public static function prepare_field_name_from_json($field_name)
330
-    {
331
-        if (Model_Data_Translator::is_gmt_date_field_name($field_name)) {
332
-            return Model_Data_Translator::remove_gmt_from_field_name($field_name);
333
-        }
334
-        return $field_name;
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     * Takes array of field names from REST API and prepares for models
341
-     *
342
-     * @param array $field_names
343
-     * @return array of field names (possibly include model prefixes)
344
-     */
345
-    public static function prepare_field_names_from_json(array $field_names)
346
-    {
347
-        $new_array = array();
348
-        foreach ($field_names as $key => $field_name) {
349
-            $new_array[$key] = Model_Data_Translator::prepare_field_name_from_json($field_name);
350
-        }
351
-        return $new_array;
352
-    }
353
-
354
-
355
-
356
-    /**
357
-     * Takes array where array keys are field names (possibly with model path prefixes)
358
-     * from the REST API and prepares them for model querying
359
-     *
360
-     * @param array $field_names_as_keys
361
-     * @return array
362
-     */
363
-    public static function prepare_field_names_in_array_keys_from_json(array $field_names_as_keys)
364
-    {
365
-        $new_array = array();
366
-        foreach ($field_names_as_keys as $field_name => $value) {
367
-            $new_array[Model_Data_Translator::prepare_field_name_from_json($field_name)] = $value;
368
-        }
369
-        return $new_array;
370
-    }
371
-
372
-
373
-
374
-    /**
375
-     * Prepares an array of model query params for use in the REST API
376
-     *
377
-     * @param array     $model_query_params
378
-     * @param \EEM_Base $model
379
-     * @param string    $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4
380
-     *                                     REST API
381
-     * @return array which can be passed into the EE4 REST API when querying a model resource
382
-     * @throws \EE_Error
383
-     */
384
-    public static function prepare_query_params_for_rest_api(
385
-        array $model_query_params,
386
-        \EEM_Base $model,
387
-        $requested_version = null
388
-    ) {
389
-        if ($requested_version === null) {
390
-            $requested_version = \EED_Core_Rest_Api::latest_rest_api_version();
391
-        }
392
-        $rest_query_params = $model_query_params;
393
-        if (isset($model_query_params[0])) {
394
-            $rest_query_params['where'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api(
395
-                $model_query_params[0],
396
-                $model,
397
-                $requested_version
398
-            );
399
-            unset($rest_query_params[0]);
400
-        }
401
-        if (isset($model_query_params['having'])) {
402
-            $rest_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api(
403
-                $model_query_params['having'],
404
-                $model,
405
-                $requested_version
406
-            );
407
-        }
408
-        return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api',
409
-            $rest_query_params, $model_query_params, $model, $requested_version);
410
-    }
411
-
412
-
413
-
414
-    /**
415
-     * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api
416
-     *
417
-     * @param array     $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params
418
-     *                                                      passed into EEM_Base::get_all()
419
-     * @param \EEM_Base $model
420
-     * @param string    $requested_version                  eg "4.8.36"
421
-     * @return array ready for use in the rest api query params
422
-     * @throws \EE_Error
423
-     */
424
-    public static function prepare_conditions_query_params_for_rest_api(
425
-        $inputted_query_params_of_this_type,
426
-        \EEM_Base $model,
427
-        $requested_version
428
-    ) {
429
-        $query_param_for_models = array();
430
-        foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
431
-            $field = Model_Data_Translator::deduce_field_from_query_param(
432
-                Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key),
433
-                $model
434
-            );
435
-            if ($field instanceof \EE_Model_Field_Base) {
436
-                //did they specify an operator?
437
-                if (is_array($query_param_value)) {
438
-                    $op = $query_param_value[0];
439
-                    $translated_value = array($op);
440
-                    if (isset($query_param_value[1])) {
441
-                        $value = $query_param_value[1];
442
-                        $translated_value[1] = Model_Data_Translator::prepare_field_values_for_json($field, $value,
443
-                            $requested_version);
444
-                    }
445
-                } else {
446
-                    $translated_value = Model_Data_Translator::prepare_field_value_for_json($field, $query_param_value,
447
-                        $requested_version);
448
-                }
449
-                $query_param_for_models[$query_param_key] = $translated_value;
450
-            } else {
451
-                //so it's not for a field, assume it's a logic query param key
452
-                $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api($query_param_value,
453
-                    $model, $requested_version);
454
-            }
455
-        }
456
-        return $query_param_for_models;
457
-    }
458
-
459
-
460
-
461
-    /**
462
-     * @param $condition_query_param_key
463
-     * @return string
464
-     */
465
-    public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key)
466
-    {
467
-        $pos_of_star = strpos($condition_query_param_key, '*');
468
-        if ($pos_of_star === false) {
469
-            return $condition_query_param_key;
470
-        } else {
471
-            $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
472
-            return $condition_query_param_sans_star;
473
-        }
474
-    }
475
-
476
-
477
-
478
-    /**
479
-     * Takes the input parameter and finds the model field that it indicates.
480
-     *
481
-     * @param string    $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID
482
-     * @param \EEM_Base $model
483
-     * @return \EE_Model_Field_Base
484
-     * @throws \EE_Error
485
-     */
486
-    public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model)
487
-    {
488
-        //ok, now proceed with deducing which part is the model's name, and which is the field's name
489
-        //which will help us find the database table and column
490
-        $query_param_parts = explode('.', $query_param_name);
491
-        if (empty($query_param_parts)) {
492
-            throw new \EE_Error(sprintf(__('_extract_column_name is empty when trying to extract column and table name from %s',
493
-                'event_espresso'), $query_param_name));
494
-        }
495
-        $number_of_parts = count($query_param_parts);
496
-        $last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
497
-        if ($number_of_parts === 1) {
498
-            $field_name = $last_query_param_part;
499
-        } else {// $number_of_parts >= 2
500
-            //the last part is the column name, and there are only 2parts. therefore...
501
-            $field_name = $last_query_param_part;
502
-            $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]);
503
-        }
504
-        try {
505
-            return $model->field_settings_for($field_name);
506
-        } catch (\EE_Error $e) {
507
-            return null;
508
-        }
509
-    }
30
+	/**
31
+	 * We used to use -1 for infinity in the rest api, but that's ambiguous for
32
+	 * fields that COULD contain -1; so we use null
33
+	 */
34
+	const ee_inf_in_rest = null;
35
+
36
+
37
+
38
+	/**
39
+	 * Prepares a possible array of input values from JSON for use by the models
40
+	 *
41
+	 * @param \EE_Model_Field_Base $field_obj
42
+	 * @param mixed                $original_value_maybe_array
43
+	 * @param string               $requested_version
44
+	 * @param string               $timezone_string treat values as being in this timezone
45
+	 * @return mixed
46
+	 * @throws \DomainException
47
+	 */
48
+	public static function prepare_field_values_from_json(
49
+		$field_obj,
50
+		$original_value_maybe_array,
51
+		$requested_version,
52
+		$timezone_string = 'UTC'
53
+	) {
54
+		if (is_array($original_value_maybe_array)) {
55
+			$new_value_maybe_array = array();
56
+			foreach ($original_value_maybe_array as $array_key => $array_item) {
57
+				$new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_from_json(
58
+					$field_obj,
59
+					$array_item,
60
+					$requested_version,
61
+					$timezone_string
62
+				);
63
+			}
64
+		} else {
65
+			$new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json(
66
+				$field_obj,
67
+				$original_value_maybe_array,
68
+				$requested_version,
69
+				$timezone_string
70
+			);
71
+		}
72
+		return $new_value_maybe_array;
73
+	}
74
+
75
+
76
+
77
+	/**
78
+	 * Prepares an array of field values FOR use in JSON/REST API
79
+	 *
80
+	 * @param \EE_Model_Field_Base $field_obj
81
+	 * @param mixed                $original_value_maybe_array
82
+	 * @param string               $request_version (eg 4.8.36)
83
+	 * @return array
84
+	 */
85
+	public static function prepare_field_values_for_json($field_obj, $original_value_maybe_array, $request_version)
86
+	{
87
+		if (is_array($original_value_maybe_array)) {
88
+			$new_value_maybe_array = array();
89
+			foreach ($original_value_maybe_array as $array_key => $array_item) {
90
+				$new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_for_json(
91
+					$field_obj,
92
+					$array_item,
93
+					$request_version
94
+				);
95
+			}
96
+		} else {
97
+			$new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json(
98
+				$field_obj,
99
+				$original_value_maybe_array,
100
+				$request_version
101
+			);
102
+		}
103
+		return $new_value_maybe_array;
104
+	}
105
+
106
+
107
+
108
+	/**
109
+	 * Prepares incoming data from the json or $_REQUEST parameters for the models'
110
+	 * "$query_params".
111
+	 *
112
+	 * @param \EE_Model_Field_Base $field_obj
113
+	 * @param mixed                $original_value
114
+	 * @param string               $requested_version
115
+	 * @param string               $timezone_string treat values as being in this timezone
116
+	 * @return mixed
117
+	 * @throws \DomainException
118
+	 */
119
+	public static function prepare_field_value_from_json(
120
+		$field_obj,
121
+		$original_value,
122
+		$requested_version,
123
+		$timezone_string = 'UTC' // UTC
124
+	)
125
+	{
126
+		$timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', '');
127
+		$new_value = null;
128
+		if ($field_obj instanceof \EE_Infinite_Integer_Field
129
+			&& in_array($original_value, array(null, ''), true)
130
+		) {
131
+			$new_value = EE_INF;
132
+		} elseif ($field_obj instanceof \EE_Datetime_Field) {
133
+			list($offset_sign, $offset_secs) = Model_Data_Translator::parse_timezone_offset(
134
+				$field_obj->get_timezone_offset(
135
+					new \DateTimeZone($timezone_string)
136
+				)
137
+			);
138
+			$offset_string =
139
+				str_pad(
140
+					floor($offset_secs / HOUR_IN_SECONDS),
141
+					2,
142
+					'0',
143
+					STR_PAD_LEFT
144
+				)
145
+				. ':'
146
+				. str_pad(
147
+					($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS,
148
+					2,
149
+					'0',
150
+					STR_PAD_LEFT
151
+				);
152
+			$new_value = rest_parse_date($original_value . $offset_sign . $offset_string);
153
+		} else {
154
+			$new_value = $original_value;
155
+		}
156
+		return $new_value;
157
+	}
158
+
159
+
160
+
161
+	/**
162
+	 * determines what's going on with them timezone strings
163
+	 *
164
+	 * @param int $timezone_offset
165
+	 * @return array
166
+	 */
167
+	private static function parse_timezone_offset($timezone_offset)
168
+	{
169
+		$first_char = substr((string)$timezone_offset, 0, 1);
170
+		if ($first_char === '+' || $first_char === '-') {
171
+			$offset_sign = $first_char;
172
+			$offset_secs = substr((string)$timezone_offset, 1);
173
+		} else {
174
+			$offset_sign = '+';
175
+			$offset_secs = $timezone_offset;
176
+		}
177
+		return array($offset_sign, $offset_secs);
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 * Prepares a field's value for display in the API
184
+	 *
185
+	 * @param \EE_Model_Field_Base $field_obj
186
+	 * @param mixed                $original_value
187
+	 * @param string               $requested_version
188
+	 * @return mixed
189
+	 */
190
+	public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version)
191
+	{
192
+		if ($original_value === EE_INF) {
193
+			$new_value = Model_Data_Translator::ee_inf_in_rest;
194
+		} elseif ($field_obj instanceof \EE_Datetime_Field) {
195
+			if ($original_value instanceof \DateTime) {
196
+				$new_value = $original_value->format('Y-m-d H:i:s');
197
+			} elseif (is_int($original_value)) {
198
+				$new_value = date('Y-m-d H:i:s', $original_value);
199
+			} else {
200
+				$new_value = $original_value;
201
+			}
202
+			$new_value = mysql_to_rfc3339($new_value);
203
+		} else {
204
+			$new_value = $original_value;
205
+		}
206
+		return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
207
+			$new_value,
208
+			$field_obj,
209
+			$original_value,
210
+			$requested_version
211
+		);
212
+	}
213
+
214
+
215
+
216
+	/**
217
+	 * Prepares condition-query-parameters (like what's in where and having) from
218
+	 * the format expected in the API to use in the models
219
+	 *
220
+	 * @param array     $inputted_query_params_of_this_type
221
+	 * @param \EEM_Base $model
222
+	 * @param string    $requested_version
223
+	 * @return array
224
+	 * @throws \DomainException
225
+	 * @throws \EE_Error
226
+	 */
227
+	public static function prepare_conditions_query_params_for_models(
228
+		$inputted_query_params_of_this_type,
229
+		\EEM_Base $model,
230
+		$requested_version
231
+	) {
232
+		$query_param_for_models = array();
233
+		foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
234
+			$query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key);
235
+			$field = Model_Data_Translator::deduce_field_from_query_param(
236
+				$query_param_sans_stars,
237
+				$model
238
+			);
239
+			//double-check is it a *_gmt field?
240
+			if (! $field instanceof \EE_Model_Field_Base
241
+				&& Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars)
242
+			) {
243
+				//yep, take off '_gmt', and find the field
244
+				$query_param_key = Model_Data_Translator::remove_gmt_from_field_name($query_param_sans_stars);
245
+				$field = Model_Data_Translator::deduce_field_from_query_param(
246
+					$query_param_key,
247
+					$model
248
+				);
249
+				$timezone = 'UTC';
250
+			} else {
251
+				//so it's not a GMT field. Set the timezone on the model to the default
252
+				$timezone = \EEH_DTT_Helper::get_valid_timezone_string();
253
+			}
254
+			if ($field instanceof \EE_Model_Field_Base) {
255
+				//did they specify an operator?
256
+				if (is_array($query_param_value)) {
257
+					$op = $query_param_value[0];
258
+					$translated_value = array($op);
259
+					if (isset($query_param_value[1])) {
260
+						$value = $query_param_value[1];
261
+						$translated_value[1] = Model_Data_Translator::prepare_field_values_from_json($field, $value,
262
+							$requested_version, $timezone);
263
+					}
264
+				} else {
265
+					$translated_value = Model_Data_Translator::prepare_field_value_from_json($field, $query_param_value,
266
+						$requested_version, $timezone);
267
+				}
268
+				$query_param_for_models[$query_param_key] = $translated_value;
269
+			} else {
270
+				//so it's not for a field, assume it's a logic query param key
271
+				$query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_models($query_param_value,
272
+					$model, $requested_version);
273
+			}
274
+		}
275
+		return $query_param_for_models;
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * Mostly checks if the last 4 characters are "_gmt", indicating its a
282
+	 * gmt date field name
283
+	 *
284
+	 * @param string $field_name
285
+	 * @return boolean
286
+	 */
287
+	public static function is_gmt_date_field_name($field_name)
288
+	{
289
+		return substr(
290
+				   Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name),
291
+				   -4,
292
+				   4
293
+			   ) === '_gmt';
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone)
300
+	 *
301
+	 * @param string $field_name
302
+	 * @return string
303
+	 */
304
+	public static function remove_gmt_from_field_name($field_name)
305
+	{
306
+		if (! Model_Data_Translator::is_gmt_date_field_name($field_name)) {
307
+			return $field_name;
308
+		}
309
+		$query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name);
310
+		$query_param_sans_gmt_and_sans_stars = substr(
311
+			$query_param_sans_stars,
312
+			0,
313
+			strrpos(
314
+				$field_name,
315
+				'_gmt'
316
+			)
317
+		);
318
+		return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name);
319
+	}
320
+
321
+
322
+
323
+	/**
324
+	 * Takes a field name from the REST API and prepares it for the model querying
325
+	 *
326
+	 * @param string $field_name
327
+	 * @return string
328
+	 */
329
+	public static function prepare_field_name_from_json($field_name)
330
+	{
331
+		if (Model_Data_Translator::is_gmt_date_field_name($field_name)) {
332
+			return Model_Data_Translator::remove_gmt_from_field_name($field_name);
333
+		}
334
+		return $field_name;
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 * Takes array of field names from REST API and prepares for models
341
+	 *
342
+	 * @param array $field_names
343
+	 * @return array of field names (possibly include model prefixes)
344
+	 */
345
+	public static function prepare_field_names_from_json(array $field_names)
346
+	{
347
+		$new_array = array();
348
+		foreach ($field_names as $key => $field_name) {
349
+			$new_array[$key] = Model_Data_Translator::prepare_field_name_from_json($field_name);
350
+		}
351
+		return $new_array;
352
+	}
353
+
354
+
355
+
356
+	/**
357
+	 * Takes array where array keys are field names (possibly with model path prefixes)
358
+	 * from the REST API and prepares them for model querying
359
+	 *
360
+	 * @param array $field_names_as_keys
361
+	 * @return array
362
+	 */
363
+	public static function prepare_field_names_in_array_keys_from_json(array $field_names_as_keys)
364
+	{
365
+		$new_array = array();
366
+		foreach ($field_names_as_keys as $field_name => $value) {
367
+			$new_array[Model_Data_Translator::prepare_field_name_from_json($field_name)] = $value;
368
+		}
369
+		return $new_array;
370
+	}
371
+
372
+
373
+
374
+	/**
375
+	 * Prepares an array of model query params for use in the REST API
376
+	 *
377
+	 * @param array     $model_query_params
378
+	 * @param \EEM_Base $model
379
+	 * @param string    $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4
380
+	 *                                     REST API
381
+	 * @return array which can be passed into the EE4 REST API when querying a model resource
382
+	 * @throws \EE_Error
383
+	 */
384
+	public static function prepare_query_params_for_rest_api(
385
+		array $model_query_params,
386
+		\EEM_Base $model,
387
+		$requested_version = null
388
+	) {
389
+		if ($requested_version === null) {
390
+			$requested_version = \EED_Core_Rest_Api::latest_rest_api_version();
391
+		}
392
+		$rest_query_params = $model_query_params;
393
+		if (isset($model_query_params[0])) {
394
+			$rest_query_params['where'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api(
395
+				$model_query_params[0],
396
+				$model,
397
+				$requested_version
398
+			);
399
+			unset($rest_query_params[0]);
400
+		}
401
+		if (isset($model_query_params['having'])) {
402
+			$rest_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api(
403
+				$model_query_params['having'],
404
+				$model,
405
+				$requested_version
406
+			);
407
+		}
408
+		return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api',
409
+			$rest_query_params, $model_query_params, $model, $requested_version);
410
+	}
411
+
412
+
413
+
414
+	/**
415
+	 * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api
416
+	 *
417
+	 * @param array     $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params
418
+	 *                                                      passed into EEM_Base::get_all()
419
+	 * @param \EEM_Base $model
420
+	 * @param string    $requested_version                  eg "4.8.36"
421
+	 * @return array ready for use in the rest api query params
422
+	 * @throws \EE_Error
423
+	 */
424
+	public static function prepare_conditions_query_params_for_rest_api(
425
+		$inputted_query_params_of_this_type,
426
+		\EEM_Base $model,
427
+		$requested_version
428
+	) {
429
+		$query_param_for_models = array();
430
+		foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
431
+			$field = Model_Data_Translator::deduce_field_from_query_param(
432
+				Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key),
433
+				$model
434
+			);
435
+			if ($field instanceof \EE_Model_Field_Base) {
436
+				//did they specify an operator?
437
+				if (is_array($query_param_value)) {
438
+					$op = $query_param_value[0];
439
+					$translated_value = array($op);
440
+					if (isset($query_param_value[1])) {
441
+						$value = $query_param_value[1];
442
+						$translated_value[1] = Model_Data_Translator::prepare_field_values_for_json($field, $value,
443
+							$requested_version);
444
+					}
445
+				} else {
446
+					$translated_value = Model_Data_Translator::prepare_field_value_for_json($field, $query_param_value,
447
+						$requested_version);
448
+				}
449
+				$query_param_for_models[$query_param_key] = $translated_value;
450
+			} else {
451
+				//so it's not for a field, assume it's a logic query param key
452
+				$query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api($query_param_value,
453
+					$model, $requested_version);
454
+			}
455
+		}
456
+		return $query_param_for_models;
457
+	}
458
+
459
+
460
+
461
+	/**
462
+	 * @param $condition_query_param_key
463
+	 * @return string
464
+	 */
465
+	public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key)
466
+	{
467
+		$pos_of_star = strpos($condition_query_param_key, '*');
468
+		if ($pos_of_star === false) {
469
+			return $condition_query_param_key;
470
+		} else {
471
+			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
472
+			return $condition_query_param_sans_star;
473
+		}
474
+	}
475
+
476
+
477
+
478
+	/**
479
+	 * Takes the input parameter and finds the model field that it indicates.
480
+	 *
481
+	 * @param string    $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID
482
+	 * @param \EEM_Base $model
483
+	 * @return \EE_Model_Field_Base
484
+	 * @throws \EE_Error
485
+	 */
486
+	public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model)
487
+	{
488
+		//ok, now proceed with deducing which part is the model's name, and which is the field's name
489
+		//which will help us find the database table and column
490
+		$query_param_parts = explode('.', $query_param_name);
491
+		if (empty($query_param_parts)) {
492
+			throw new \EE_Error(sprintf(__('_extract_column_name is empty when trying to extract column and table name from %s',
493
+				'event_espresso'), $query_param_name));
494
+		}
495
+		$number_of_parts = count($query_param_parts);
496
+		$last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
497
+		if ($number_of_parts === 1) {
498
+			$field_name = $last_query_param_part;
499
+		} else {// $number_of_parts >= 2
500
+			//the last part is the column name, and there are only 2parts. therefore...
501
+			$field_name = $last_query_param_part;
502
+			$model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]);
503
+		}
504
+		try {
505
+			return $model->field_settings_for($field_name);
506
+		} catch (\EE_Error $e) {
507
+			return null;
508
+		}
509
+	}
510 510
 
511 511
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\libraries\rest_api;
3 3
 
4
-if (! defined('EVENT_ESPRESSO_VERSION')) {
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5 5
     exit('No direct script access allowed');
6 6
 }
7 7
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
                     '0',
150 150
                     STR_PAD_LEFT
151 151
                 );
152
-            $new_value = rest_parse_date($original_value . $offset_sign . $offset_string);
152
+            $new_value = rest_parse_date($original_value.$offset_sign.$offset_string);
153 153
         } else {
154 154
             $new_value = $original_value;
155 155
         }
@@ -166,10 +166,10 @@  discard block
 block discarded – undo
166 166
      */
167 167
     private static function parse_timezone_offset($timezone_offset)
168 168
     {
169
-        $first_char = substr((string)$timezone_offset, 0, 1);
169
+        $first_char = substr((string) $timezone_offset, 0, 1);
170 170
         if ($first_char === '+' || $first_char === '-') {
171 171
             $offset_sign = $first_char;
172
-            $offset_secs = substr((string)$timezone_offset, 1);
172
+            $offset_secs = substr((string) $timezone_offset, 1);
173 173
         } else {
174 174
             $offset_sign = '+';
175 175
             $offset_secs = $timezone_offset;
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
                 $model
238 238
             );
239 239
             //double-check is it a *_gmt field?
240
-            if (! $field instanceof \EE_Model_Field_Base
240
+            if ( ! $field instanceof \EE_Model_Field_Base
241 241
                 && Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars)
242 242
             ) {
243 243
                 //yep, take off '_gmt', and find the field
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
      */
304 304
     public static function remove_gmt_from_field_name($field_name)
305 305
     {
306
-        if (! Model_Data_Translator::is_gmt_date_field_name($field_name)) {
306
+        if ( ! Model_Data_Translator::is_gmt_date_field_name($field_name)) {
307 307
             return $field_name;
308 308
         }
309 309
         $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name);
Please login to merge, or discard this patch.
core/libraries/rest_api/changes/Changes_In_Base.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -6,78 +6,78 @@
 block discarded – undo
6 6
 abstract class Changes_In_Base
7 7
 {
8 8
 
9
-    /**
10
-     * The version that these changes happened
11
-     *
12
-     * @var string
13
-     */
14
-    protected $_version = null;
9
+	/**
10
+	 * The version that these changes happened
11
+	 *
12
+	 * @var string
13
+	 */
14
+	protected $_version = null;
15 15
 
16 16
 
17 17
 
18
-    /**
19
-     * Called when an EE4 REST API request is made to an earlier version than
20
-     * what is indicated in this class' name.
21
-     * Uses WordPress' add_filter and add_action to modify the EE4 REST API's response
22
-     * so that regardless of what version of EE4 core is running, API clients
23
-     * will have a consistent response
24
-     *
25
-     * @return void
26
-     */
27
-    abstract public function set_hooks();
18
+	/**
19
+	 * Called when an EE4 REST API request is made to an earlier version than
20
+	 * what is indicated in this class' name.
21
+	 * Uses WordPress' add_filter and add_action to modify the EE4 REST API's response
22
+	 * so that regardless of what version of EE4 core is running, API clients
23
+	 * will have a consistent response
24
+	 *
25
+	 * @return void
26
+	 */
27
+	abstract public function set_hooks();
28 28
 
29 29
 
30 30
 
31
-    /**
32
-     * Returns whether or not this class' name indicates its hooks should
33
-     * apply when a request comes in for $requested_version. A class can use
34
-     * other conditions when determining whether to perform their callbacks or not,
35
-     * but this will typically be enough
36
-     *
37
-     * @param string $requested_version eg "4.8.33"
38
-     * @return boolean true: this class' name indicates its filters and actions
39
-     *                                  should take effect. False: this class' name indicates it shouldn't do anything
40
-     */
41
-    public function applies_to_version($requested_version)
42
-    {
43
-        if ($this->version() > $requested_version) {
44
-            return true;
45
-        }
46
-        return false;
47
-    }
31
+	/**
32
+	 * Returns whether or not this class' name indicates its hooks should
33
+	 * apply when a request comes in for $requested_version. A class can use
34
+	 * other conditions when determining whether to perform their callbacks or not,
35
+	 * but this will typically be enough
36
+	 *
37
+	 * @param string $requested_version eg "4.8.33"
38
+	 * @return boolean true: this class' name indicates its filters and actions
39
+	 *                                  should take effect. False: this class' name indicates it shouldn't do anything
40
+	 */
41
+	public function applies_to_version($requested_version)
42
+	{
43
+		if ($this->version() > $requested_version) {
44
+			return true;
45
+		}
46
+		return false;
47
+	}
48 48
 
49 49
 
50 50
 
51
-    /**
52
-     * Gets the EE core version when this changes were made to the rest api.
53
-     * Any requests to earlier versions should have modifications made to them
54
-     * by the callbacks of this class.
55
-     *
56
-     * @return string eg "4.8.33"
57
-     * @throws \EE_Error
58
-     */
59
-    public function version()
60
-    {
61
-        if ($this->_version === null) {
62
-            $matches = array();
63
-            $regex = '~Changes_In_(.*)_(.*)_(.*)$~';
64
-            $success = preg_match(
65
-                $regex,
66
-                get_class($this),
67
-                $matches
68
-            );
69
-            if (! $success) {
70
-                throw new \EE_Error(
71
-                    sprintf(
72
-                        __('The class %1$s was misnamed. It name should match the regex "%2$s"', 'event_espresso'),
73
-                        get_class($this),
74
-                        $regex
75
-                    )
76
-                );
77
-            }
78
-            $this->_version = $matches[1] . '.' . $matches[2] . '.' . $matches[3];
79
-        }
80
-        return $this->_version;
81
-    }
51
+	/**
52
+	 * Gets the EE core version when this changes were made to the rest api.
53
+	 * Any requests to earlier versions should have modifications made to them
54
+	 * by the callbacks of this class.
55
+	 *
56
+	 * @return string eg "4.8.33"
57
+	 * @throws \EE_Error
58
+	 */
59
+	public function version()
60
+	{
61
+		if ($this->_version === null) {
62
+			$matches = array();
63
+			$regex = '~Changes_In_(.*)_(.*)_(.*)$~';
64
+			$success = preg_match(
65
+				$regex,
66
+				get_class($this),
67
+				$matches
68
+			);
69
+			if (! $success) {
70
+				throw new \EE_Error(
71
+					sprintf(
72
+						__('The class %1$s was misnamed. It name should match the regex "%2$s"', 'event_espresso'),
73
+						get_class($this),
74
+						$regex
75
+					)
76
+				);
77
+			}
78
+			$this->_version = $matches[1] . '.' . $matches[2] . '.' . $matches[3];
79
+		}
80
+		return $this->_version;
81
+	}
82 82
 }
83 83
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
                 get_class($this),
67 67
                 $matches
68 68
             );
69
-            if (! $success) {
69
+            if ( ! $success) {
70 70
                 throw new \EE_Error(
71 71
                     sprintf(
72 72
                         __('The class %1$s was misnamed. It name should match the regex "%2$s"', 'event_espresso'),
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
                     )
76 76
                 );
77 77
             }
78
-            $this->_version = $matches[1] . '.' . $matches[2] . '.' . $matches[3];
78
+            $this->_version = $matches[1].'.'.$matches[2].'.'.$matches[3];
79 79
         }
80 80
         return $this->_version;
81 81
     }
Please login to merge, or discard this patch.
core/libraries/rest_api/changes/Changes_In_4_8_36.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -122,9 +122,9 @@
 block discarded – undo
122 122
                 $headers,
123 123
                 array_flip(
124 124
                     array(
125
-                        Base::header_prefix_for_wp . 'Total',
126
-                        Base::header_prefix_for_wp . 'TotalPages',
127
-                        Base::header_prefix_for_wp . 'PageSize',
125
+                        Base::header_prefix_for_wp.'Total',
126
+                        Base::header_prefix_for_wp.'TotalPages',
127
+                        Base::header_prefix_for_wp.'PageSize',
128 128
                     )));
129 129
         }
130 130
         return $headers;
Please login to merge, or discard this patch.
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -14,179 +14,179 @@
 block discarded – undo
14 14
 class Changes_In_4_8_36 extends Changes_In_Base
15 15
 {
16 16
 
17
-    /**
18
-     * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
19
-     */
20
-    public function set_hooks()
21
-    {
22
-        //set a hook to remove the "calculate" query param
23
-        add_filter(
24
-            'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
25
-            array($this, 'remove_calculate_query_param'),
26
-            10,
27
-            3
28
-        );
29
-        //don't add the _calculated_fields either
30
-        add_filter(
31
-            'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal',
32
-            array($this, 'remove_calculated_fields_from_response'),
33
-            10,
34
-            5
35
-        );
36
-        //and also don't add the count headers
37
-        add_filter(
38
-            'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
39
-            array($this, 'remove_headers_new_in_this_version'),
40
-            10,
41
-            3
42
-        );
43
-        //remove the old featured_image part of the response...
44
-        add_filter(
45
-            'FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models',
46
-            array($this, 'add_old_featured_image_part_of_cpt_entities'),
47
-            10,
48
-            5
49
-        );
50
-        //assuming ticket 9425's change gets pushed with 9406, we don't need to
51
-        //remove it from the calculated fields on older requests (because this will
52
-        //be the first version with calculated fields)
53
-        //before this, infinity was -1, now it's null
54
-        add_filter(
55
-            'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
56
-            array($this, 'use_negative_one_for_infinity_before_this_version'),
57
-            10,
58
-            4
59
-        );
60
-    }
61
-
62
-
63
-
64
-    /**
65
-     * Dont show "calculate" as an query param option in the index
66
-     *
67
-     * @param array     $query_params
68
-     * @param \EEM_base $model
69
-     * @param string    $version
70
-     * @return array
71
-     */
72
-    public function remove_calculate_query_param($query_params, \EEM_Base $model, $version)
73
-    {
74
-        if ($this->applies_to_version($version)) {
75
-            unset($query_params['calculate']);
76
-        }
77
-        return $query_params;
78
-    }
79
-
80
-
81
-
82
-    /**
83
-     * Removes the "_calculate_fields" part of entity responses before 4.8.36
84
-     *
85
-     * @param array            $entity_response_array
86
-     * @param \EEM_Base        $model
87
-     * @param string           $request_context
88
-     * @param \WP_REST_Request $request
89
-     * @param Read             $controller
90
-     * @return array
91
-     */
92
-    public function remove_calculated_fields_from_response(
93
-        $entity_response_array,
94
-        \EEM_Base $model,
95
-        $request_context,
96
-        \WP_REST_Request $request,
97
-        Read $controller
98
-    ) {
99
-        if ($this->applies_to_version($controller->get_model_version_info()->requested_version())) {
100
-            unset($entity_response_array['_calculated_fields']);
101
-        }
102
-        return $entity_response_array;
103
-    }
104
-
105
-
106
-
107
-    /**
108
-     * Removes the new headers for requests before 4.8.36
109
-     *
110
-     * @param array  $headers
111
-     * @param Base   $controller
112
-     * @param string $version
113
-     * @return array
114
-     */
115
-    public function remove_headers_new_in_this_version(
116
-        $headers,
117
-        Controller_Base $controller,
118
-        $version
119
-    ) {
120
-        if ($this->applies_to_version($version)) {
121
-            $headers = array_diff_key(
122
-                $headers,
123
-                array_flip(
124
-                    array(
125
-                        Base::header_prefix_for_wp . 'Total',
126
-                        Base::header_prefix_for_wp . 'TotalPages',
127
-                        Base::header_prefix_for_wp . 'PageSize',
128
-                    )));
129
-        }
130
-        return $headers;
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     * Puts the 'featured_image_url' back in for responses before 4.8.36.
137
-     *
138
-     * @param array            $entity_response_array
139
-     * @param \EEM_Base        $model
140
-     * @param string           $request_context
141
-     * @param \WP_REST_Request $request
142
-     * @param Read             $controller
143
-     * @return array
144
-     */
145
-    public function add_old_featured_image_part_of_cpt_entities(
146
-        $entity_response_array,
147
-        \EEM_Base $model,
148
-        $request_context,
149
-        \WP_REST_Request $request,
150
-        Read $controller
151
-    ) {
152
-        if ($this->applies_to_version($controller->get_model_version_info()->requested_version())
153
-            && $model instanceof \EEM_CPT_Base
154
-        ) {
155
-            $attachment = wp_get_attachment_image_src(
156
-                get_post_thumbnail_id($entity_response_array[$model->primary_key_name()]),
157
-                'full'
158
-            );
159
-            $entity_response_array['featured_image_url'] = ! empty($attachment) ? $attachment[0] : null;
160
-        }
161
-        return $entity_response_array;
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     * If the value was infinity, we now use null in our JSON responses,
168
-     * but before this version we used -1.
169
-     *
170
-     * @param mixed                $new_value
171
-     * @param \EE_Model_Field_Base $field_obj
172
-     * @param mixed                $original_value
173
-     * @param string               $requested_value
174
-     * @return mixed
175
-     */
176
-    public function use_negative_one_for_infinity_before_this_version(
177
-        $new_value,
178
-        $field_obj,
179
-        $original_value,
180
-        $requested_value
181
-    ) {
182
-        if ($this->applies_to_version($requested_value)
183
-            && $original_value === EE_INF
184
-        ) {
185
-            //return the old representation of infinity in the JSON
186
-            return -1;
187
-        }
188
-        return $new_value;
189
-    }
17
+	/**
18
+	 * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
19
+	 */
20
+	public function set_hooks()
21
+	{
22
+		//set a hook to remove the "calculate" query param
23
+		add_filter(
24
+			'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
25
+			array($this, 'remove_calculate_query_param'),
26
+			10,
27
+			3
28
+		);
29
+		//don't add the _calculated_fields either
30
+		add_filter(
31
+			'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal',
32
+			array($this, 'remove_calculated_fields_from_response'),
33
+			10,
34
+			5
35
+		);
36
+		//and also don't add the count headers
37
+		add_filter(
38
+			'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
39
+			array($this, 'remove_headers_new_in_this_version'),
40
+			10,
41
+			3
42
+		);
43
+		//remove the old featured_image part of the response...
44
+		add_filter(
45
+			'FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models',
46
+			array($this, 'add_old_featured_image_part_of_cpt_entities'),
47
+			10,
48
+			5
49
+		);
50
+		//assuming ticket 9425's change gets pushed with 9406, we don't need to
51
+		//remove it from the calculated fields on older requests (because this will
52
+		//be the first version with calculated fields)
53
+		//before this, infinity was -1, now it's null
54
+		add_filter(
55
+			'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
56
+			array($this, 'use_negative_one_for_infinity_before_this_version'),
57
+			10,
58
+			4
59
+		);
60
+	}
61
+
62
+
63
+
64
+	/**
65
+	 * Dont show "calculate" as an query param option in the index
66
+	 *
67
+	 * @param array     $query_params
68
+	 * @param \EEM_base $model
69
+	 * @param string    $version
70
+	 * @return array
71
+	 */
72
+	public function remove_calculate_query_param($query_params, \EEM_Base $model, $version)
73
+	{
74
+		if ($this->applies_to_version($version)) {
75
+			unset($query_params['calculate']);
76
+		}
77
+		return $query_params;
78
+	}
79
+
80
+
81
+
82
+	/**
83
+	 * Removes the "_calculate_fields" part of entity responses before 4.8.36
84
+	 *
85
+	 * @param array            $entity_response_array
86
+	 * @param \EEM_Base        $model
87
+	 * @param string           $request_context
88
+	 * @param \WP_REST_Request $request
89
+	 * @param Read             $controller
90
+	 * @return array
91
+	 */
92
+	public function remove_calculated_fields_from_response(
93
+		$entity_response_array,
94
+		\EEM_Base $model,
95
+		$request_context,
96
+		\WP_REST_Request $request,
97
+		Read $controller
98
+	) {
99
+		if ($this->applies_to_version($controller->get_model_version_info()->requested_version())) {
100
+			unset($entity_response_array['_calculated_fields']);
101
+		}
102
+		return $entity_response_array;
103
+	}
104
+
105
+
106
+
107
+	/**
108
+	 * Removes the new headers for requests before 4.8.36
109
+	 *
110
+	 * @param array  $headers
111
+	 * @param Base   $controller
112
+	 * @param string $version
113
+	 * @return array
114
+	 */
115
+	public function remove_headers_new_in_this_version(
116
+		$headers,
117
+		Controller_Base $controller,
118
+		$version
119
+	) {
120
+		if ($this->applies_to_version($version)) {
121
+			$headers = array_diff_key(
122
+				$headers,
123
+				array_flip(
124
+					array(
125
+						Base::header_prefix_for_wp . 'Total',
126
+						Base::header_prefix_for_wp . 'TotalPages',
127
+						Base::header_prefix_for_wp . 'PageSize',
128
+					)));
129
+		}
130
+		return $headers;
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 * Puts the 'featured_image_url' back in for responses before 4.8.36.
137
+	 *
138
+	 * @param array            $entity_response_array
139
+	 * @param \EEM_Base        $model
140
+	 * @param string           $request_context
141
+	 * @param \WP_REST_Request $request
142
+	 * @param Read             $controller
143
+	 * @return array
144
+	 */
145
+	public function add_old_featured_image_part_of_cpt_entities(
146
+		$entity_response_array,
147
+		\EEM_Base $model,
148
+		$request_context,
149
+		\WP_REST_Request $request,
150
+		Read $controller
151
+	) {
152
+		if ($this->applies_to_version($controller->get_model_version_info()->requested_version())
153
+			&& $model instanceof \EEM_CPT_Base
154
+		) {
155
+			$attachment = wp_get_attachment_image_src(
156
+				get_post_thumbnail_id($entity_response_array[$model->primary_key_name()]),
157
+				'full'
158
+			);
159
+			$entity_response_array['featured_image_url'] = ! empty($attachment) ? $attachment[0] : null;
160
+		}
161
+		return $entity_response_array;
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 * If the value was infinity, we now use null in our JSON responses,
168
+	 * but before this version we used -1.
169
+	 *
170
+	 * @param mixed                $new_value
171
+	 * @param \EE_Model_Field_Base $field_obj
172
+	 * @param mixed                $original_value
173
+	 * @param string               $requested_value
174
+	 * @return mixed
175
+	 */
176
+	public function use_negative_one_for_infinity_before_this_version(
177
+		$new_value,
178
+		$field_obj,
179
+		$original_value,
180
+		$requested_value
181
+	) {
182
+		if ($this->applies_to_version($requested_value)
183
+			&& $original_value === EE_INF
184
+		) {
185
+			//return the old representation of infinity in the JSON
186
+			return -1;
187
+		}
188
+		return $new_value;
189
+	}
190 190
 
191 191
 }
192 192
 
Please login to merge, or discard this patch.
core/libraries/rest_api/Rest_Exception.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @since                 $VID:$
13 13
  */
14 14
 if (! defined('EVENT_ESPRESSO_VERSION')) {
15
-    exit('No direct script access allowed');
15
+	exit('No direct script access allowed');
16 16
 }
17 17
 
18 18
 
@@ -20,46 +20,46 @@  discard block
 block discarded – undo
20 20
 class Rest_Exception extends \EE_Error
21 21
 {
22 22
 
23
-    /**
24
-     * @var array
25
-     */
26
-    protected $_wp_error_data = array();
23
+	/**
24
+	 * @var array
25
+	 */
26
+	protected $_wp_error_data = array();
27 27
 
28
-    protected $_wp_error_code = '';
28
+	protected $_wp_error_code = '';
29 29
 
30 30
 
31 31
 
32
-    public function __construct($string_code, $message, $wp_error_data = array(), $previous = null)
33
-    {
34
-        parent::__construct(
35
-            $message,
36
-            500,
37
-            $previous);
38
-        $this->_wp_error_data = $wp_error_data;
39
-        $this->_wp_error_code = $string_code;
40
-    }
32
+	public function __construct($string_code, $message, $wp_error_data = array(), $previous = null)
33
+	{
34
+		parent::__construct(
35
+			$message,
36
+			500,
37
+			$previous);
38
+		$this->_wp_error_data = $wp_error_data;
39
+		$this->_wp_error_code = $string_code;
40
+	}
41 41
 
42 42
 
43 43
 
44
-    /**
45
-     * Array of data that may have been set during the constructor, intended for WP_Error's data
46
-     *
47
-     * @return array
48
-     */
49
-    public function get_data()
50
-    {
51
-        return $this->_wp_error_data;
52
-    }
44
+	/**
45
+	 * Array of data that may have been set during the constructor, intended for WP_Error's data
46
+	 *
47
+	 * @return array
48
+	 */
49
+	public function get_data()
50
+	{
51
+		return $this->_wp_error_data;
52
+	}
53 53
 
54 54
 
55 55
 
56
-    /**
57
-     * Gets the error string
58
-     *
59
-     * @return string
60
-     */
61
-    public function get_string_code()
62
-    {
63
-        return $this->_wp_error_code;
64
-    }
56
+	/**
57
+	 * Gets the error string
58
+	 *
59
+	 * @return string
60
+	 */
61
+	public function get_string_code()
62
+	{
63
+		return $this->_wp_error_code;
64
+	}
65 65
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
  * @author                Mike Nelson
12 12
  * @since                 $VID:$
13 13
  */
14
-if (! defined('EVENT_ESPRESSO_VERSION')) {
14
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
15 15
     exit('No direct script access allowed');
16 16
 }
17 17
 
Please login to merge, or discard this patch.