Completed
Branch BUG-10537-cart-ticket-reservat... (8779cb)
by
unknown
40:49 queued 29:00
created
core/services/formatters/FormatterBase.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -18,27 +18,27 @@
 block discarded – undo
18 18
 abstract class FormatterBase implements FormatterInterface
19 19
 {
20 20
 
21
-    /**
22
-     * Recursively applies the formatting to all VALUES in this multi-dimensional array
23
-     *
24
-     * @param array $input
25
-     * @return array
26
-     * @throws InvalidDataTypeException if $input is not an array
27
-     */
28
-    public function formatArray($input)
29
-    {
30
-        if (! is_array($input)) {
31
-            throw new InvalidDataTypeException('input', $input, 'array');
32
-        }
33
-        //we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead
34
-        $formatter = $this;
35
-        array_walk_recursive(
36
-            $input,
37
-            function (&$value, $key) use ($formatter) {
38
-                $value = $formatter->format($value);
39
-            }
40
-        );
41
-        return $input;
42
-    }}
21
+	/**
22
+	 * Recursively applies the formatting to all VALUES in this multi-dimensional array
23
+	 *
24
+	 * @param array $input
25
+	 * @return array
26
+	 * @throws InvalidDataTypeException if $input is not an array
27
+	 */
28
+	public function formatArray($input)
29
+	{
30
+		if (! is_array($input)) {
31
+			throw new InvalidDataTypeException('input', $input, 'array');
32
+		}
33
+		//we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead
34
+		$formatter = $this;
35
+		array_walk_recursive(
36
+			$input,
37
+			function (&$value, $key) use ($formatter) {
38
+				$value = $formatter->format($value);
39
+			}
40
+		);
41
+		return $input;
42
+	}}
43 43
 // End of file FormatterBase.php
44 44
 // Location: core\services\formatters/FormatterBase.php
45 45
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,14 +27,14 @@
 block discarded – undo
27 27
      */
28 28
     public function formatArray($input)
29 29
     {
30
-        if (! is_array($input)) {
30
+        if ( ! is_array($input)) {
31 31
             throw new InvalidDataTypeException('input', $input, 'array');
32 32
         }
33 33
         //we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead
34 34
         $formatter = $this;
35 35
         array_walk_recursive(
36 36
             $input,
37
-            function (&$value, $key) use ($formatter) {
37
+            function(&$value, $key) use ($formatter) {
38 38
                 $value = $formatter->format($value);
39 39
             }
40 40
         );
Please login to merge, or discard this patch.
modules/core_rest_api/EED_Core_Rest_Api.module.php 1 patch
Indentation   +791 added lines, -791 removed lines patch added patch discarded remove patch
@@ -18,807 +18,807 @@
 block discarded – undo
18 18
 class EED_Core_Rest_Api extends \EED_Module
19 19
 {
20 20
 
21
-    const ee_api_namespace           = 'ee/v';
21
+	const ee_api_namespace           = 'ee/v';
22 22
 
23
-    const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
23
+	const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
24 24
 
25
-    const saved_routes_option_names  = 'ee_core_routes';
25
+	const saved_routes_option_names  = 'ee_core_routes';
26 26
 
27
-    /**
28
-     * string used in _links response bodies to make them globally unique.
29
-     *
30
-     * @see http://v2.wp-api.org/extending/linking/
31
-     */
32
-    const ee_api_link_namespace = 'https://api.eventespresso.com/';
27
+	/**
28
+	 * string used in _links response bodies to make them globally unique.
29
+	 *
30
+	 * @see http://v2.wp-api.org/extending/linking/
31
+	 */
32
+	const ee_api_link_namespace = 'https://api.eventespresso.com/';
33 33
 
34
-    /**
35
-     * @var Calculated_Model_Fields
36
-     */
37
-    protected static $_field_calculator = null;
34
+	/**
35
+	 * @var Calculated_Model_Fields
36
+	 */
37
+	protected static $_field_calculator = null;
38 38
 
39 39
 
40 40
 
41
-    /**
42
-     * @return EED_Core_Rest_Api
43
-     */
44
-    public static function instance()
45
-    {
46
-        self::$_field_calculator = new Calculated_Model_Fields();
47
-        return parent::get_instance(__CLASS__);
48
-    }
41
+	/**
42
+	 * @return EED_Core_Rest_Api
43
+	 */
44
+	public static function instance()
45
+	{
46
+		self::$_field_calculator = new Calculated_Model_Fields();
47
+		return parent::get_instance(__CLASS__);
48
+	}
49 49
 
50 50
 
51 51
 
52
-    /**
53
-     *    set_hooks - for hooking into EE Core, other modules, etc
54
-     *
55
-     * @access    public
56
-     * @return    void
57
-     */
58
-    public static function set_hooks()
59
-    {
60
-        self::set_hooks_both();
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
67
-     *
68
-     * @access    public
69
-     * @return    void
70
-     */
71
-    public static function set_hooks_admin()
72
-    {
73
-        self::set_hooks_both();
74
-    }
75
-
76
-
77
-
78
-    public static function set_hooks_both()
79
-    {
80
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
81
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
82
-        add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
83
-        add_filter('rest_index',
84
-            array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index'));
85
-        EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * sets up hooks which only need to be included as part of REST API requests;
92
-     * other requests like to the frontend or admin etc don't need them
93
-     */
94
-    public static function set_hooks_rest_api()
95
-    {
96
-        //set hooks which account for changes made to the API
97
-        EED_Core_Rest_Api::_set_hooks_for_changes();
98
-    }
99
-
100
-
101
-
102
-    /**
103
-     * public wrapper of _set_hooks_for_changes.
104
-     * Loads all the hooks which make requests to old versions of the API
105
-     * appear the same as they always did
106
-     */
107
-    public static function set_hooks_for_changes()
108
-    {
109
-        self::_set_hooks_for_changes();
110
-    }
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-    /**
119
-     * Loads all the hooks which make requests to old versions of the API
120
-     * appear the same as they always did
121
-     */
122
-    protected static function _set_hooks_for_changes()
123
-    {
124
-        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
125
-        foreach ($folder_contents as $classname_in_namespace => $filepath) {
126
-            //ignore the base parent class
127
-            if ($classname_in_namespace === 'Changes_In_Base') {
128
-                continue;
129
-            }
130
-            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
131
-            if (class_exists($full_classname)) {
132
-                $instance_of_class = new $full_classname;
133
-                if ($instance_of_class instanceof Changes_In_Base) {
134
-                    $instance_of_class->set_hooks();
135
-                }
136
-            }
137
-        }
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * Filters the WP routes to add our EE-related ones. This takes a bit of time
144
-     * so we actually prefer to only do it when an EE plugin is activated or upgraded
145
-     */
146
-    public static function register_routes()
147
-    {
148
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
149
-            foreach ($relative_urls as $endpoint => $routes) {
150
-                foreach ($routes as $route) {
151
-                    $route_args = array(
152
-                        array(
153
-                            'callback' => $route['callback'],
154
-                            'methods'  => $route['methods'],
155
-                            'args'     => isset($route['args']) ? $route['args'] : array(),
156
-                        )
157
-                    );
158
-                    if (isset($route['schema_callback'])) {
159
-                        $model_name = isset($route['schema_callback'][0])
160
-                            ? $route['schema_callback'][0]
161
-                            : '';
162
-                        $version = isset( $route['schema_callback'][1])
163
-                            ? $route['schema_callback'][1]
164
-                            : '';
165
-                        if (! empty($model_name) && ! empty($version)) {
166
-                            $route_args['schema'] = function () use ($model_name, $version) {
167
-                                return ModelRead::handle_schema_request(
168
-                                    $model_name,
169
-                                    $version
170
-                                );
171
-                            };
172
-                        }
173
-                    }
174
-                    register_rest_route(
175
-                        $namespace,
176
-                        $endpoint,
177
-                        $route_args
178
-                    );
179
-                }
180
-            }
181
-        }
182
-    }
183
-
184
-
185
-
186
-    /**
187
-     * Checks if there was a version change or something that merits invalidating the cached
188
-     * route data. If so, invalidates the cached route data so that it gets refreshed
189
-     * next time the WP API is used
190
-     */
191
-    public static function invalidate_cached_route_data_on_version_change()
192
-    {
193
-        if (EE_System::instance()->detect_req_type() != EE_System::req_type_normal) {
194
-            EED_Core_Rest_Api::invalidate_cached_route_data();
195
-        }
196
-        foreach (EE_Registry::instance()->addons as $addon) {
197
-            if ($addon instanceof EE_Addon && $addon->detect_req_type() != EE_System::req_type_normal) {
198
-                EED_Core_Rest_Api::invalidate_cached_route_data();
199
-            }
200
-        }
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * Removes the cached route data so it will get refreshed next time the WP API is used
207
-     */
208
-    public static function invalidate_cached_route_data()
209
-    {
210
-        //delete the saved EE REST API routes
211
-        foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
212
-            delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
213
-        }
214
-    }
215
-
216
-
217
-
218
-    /**
219
-     * Gets the EE route data
220
-     *
221
-     * @return array top-level key is the namespace, next-level key is the route and its value is array{
222
-     * @type string|array $callback
223
-     * @type string       $methods
224
-     * @type boolean      $hidden_endpoint
225
-     * }
226
-     */
227
-    public static function get_ee_route_data()
228
-    {
229
-        $ee_routes = array();
230
-        foreach (self::versions_served() as $version => $hidden_endpoints) {
231
-            $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version($version,
232
-                $hidden_endpoints);
233
-        }
234
-        return $ee_routes;
235
-    }
236
-
237
-
238
-
239
-    /**
240
-     * Gets the EE route data from the wp options if it exists already,
241
-     * otherwise re-generates it and saves it to the option
242
-     *
243
-     * @param string  $version
244
-     * @param boolean $hidden_endpoints
245
-     * @return array
246
-     */
247
-    protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
248
-    {
249
-        $ee_routes = get_option(self::saved_routes_option_names . $version, null);
250
-        if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
251
-            $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
252
-        }
253
-        return $ee_routes;
254
-    }
255
-
256
-
257
-
258
-    /**
259
-     * Saves the EE REST API route data to a wp option and returns it
260
-     *
261
-     * @param string  $version
262
-     * @param boolean $hidden_endpoints
263
-     * @return mixed|null|void
264
-     */
265
-    protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
266
-    {
267
-        $instance = self::instance();
268
-        $routes = apply_filters(
269
-            'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
270
-            array_replace_recursive(
271
-                $instance->_get_config_route_data_for_version($version, $hidden_endpoints),
272
-                $instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
273
-                $instance->_get_model_route_data_for_version($version, $hidden_endpoints),
274
-                $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
275
-            )
276
-        );
277
-        $option_name = self::saved_routes_option_names . $version;
278
-        if (get_option($option_name)) {
279
-            update_option($option_name, $routes, true);
280
-        } else {
281
-            add_option($option_name, $routes, null, 'no');
282
-        }
283
-        return $routes;
284
-    }
285
-
286
-
287
-
288
-    /**
289
-     * Calculates all the EE routes and saves it to a wordpress option so we don't
290
-     * need to calculate it on every request
291
-     *
292
-     * @deprecated since version 4.9.1
293
-     * @return void
294
-     */
295
-    public static function save_ee_routes()
296
-    {
297
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
298
-            $instance = self::instance();
299
-            $routes = apply_filters(
300
-                'EED_Core_Rest_Api__save_ee_routes__routes',
301
-                array_replace_recursive(
302
-                    $instance->_register_config_routes(),
303
-                    $instance->_register_meta_routes(),
304
-                    $instance->_register_model_routes(),
305
-                    $instance->_register_rpc_routes()
306
-                )
307
-            );
308
-            update_option(self::saved_routes_option_names, $routes, true);
309
-        }
310
-    }
311
-
312
-
313
-
314
-    /**
315
-     * Gets all the route information relating to EE models
316
-     *
317
-     * @return array @see get_ee_route_data
318
-     * @deprecated since version 4.9.1
319
-     */
320
-    protected function _register_model_routes()
321
-    {
322
-        $model_routes = array();
323
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
324
-            $model_routes[EED_Core_Rest_Api::ee_api_namespace
325
-                          . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
326
-        }
327
-        return $model_routes;
328
-    }
329
-
330
-
331
-
332
-    /**
333
-     * Gets the route data for EE models in the specified version
334
-     *
335
-     * @param string  $version
336
-     * @param boolean $hidden_endpoint
337
-     * @return array
338
-     */
339
-    protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
340
-    {
341
-        $model_version_info = new Model_Version_Info($version);
342
-        $models_to_register = apply_filters(
343
-            'FHEE__EED_Core_REST_API___register_model_routes',
344
-            $model_version_info->models_for_requested_version()
345
-        );
346
-        //let's not bother having endpoints for extra metas
347
-        unset($models_to_register['Extra_Meta']);
348
-        unset($models_to_register['Extra_Join']);
349
-        $model_routes = array();
350
-        foreach ($models_to_register as $model_name => $model_classname) {
351
-            $model = \EE_Registry::instance()->load_model($model_name);
352
-
353
-            //if this isn't a valid model then let's skip iterate to the next item in the loop.
354
-            if (! $model instanceof EEM_Base) {
355
-                continue;
356
-            }
357
-
358
-            //yes we could just register one route for ALL models, but then they wouldn't show up in the index
359
-            $plural_model_route = EEH_Inflector::pluralize_and_lower($model_name);
360
-            $singular_model_route = $plural_model_route . '/(?P<id>\d+)';
361
-            $model_routes[$plural_model_route] = array(
362
-                array(
363
-                    'callback'        => array(
364
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
365
-                        'handle_request_get_all',
366
-                    ),
367
-                    'methods'         => WP_REST_Server::READABLE,
368
-                    'hidden_endpoint' => $hidden_endpoint,
369
-                    'args'            => $this->_get_read_query_params($model, $version),
370
-                    '_links'          => array(
371
-                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
372
-                    ),
373
-                    'schema_callback' => array($model_name, $version)
374
-                ),
375
-                //						array(
376
-                //							'callback' => array(
377
-                //								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
378
-                //								'handle_request_create_one' ),
379
-                //							'methods' => WP_REST_Server::CREATABLE,
380
-                //							'hidden_endpoint' => $hidden_endpoint
381
-                //						)
382
-            );
383
-            $model_routes[$singular_model_route] = array(
384
-                array(
385
-                    'callback'        => array(
386
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
387
-                        'handle_request_get_one',
388
-                    ),
389
-                    'methods'         => WP_REST_Server::READABLE,
390
-                    'hidden_endpoint' => $hidden_endpoint,
391
-                    'args'            => $this->_get_response_selection_query_params($model, $version),
392
-                ),
393
-                //						array(
394
-                //							'callback' => array(
395
-                //								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
396
-                //								'handle_request_edit_one' ),
397
-                //							'methods' => WP_REST_Server::EDITABLE,
398
-                //							'hidden_endpoint' => $hidden_endpoint
399
-                //							),
400
-            );
401
-            //@todo: also handle  DELETE for a single item
402
-            foreach ($model_version_info->relation_settings($model) as $relation_name => $relation_obj) {
403
-                $related_model_name_endpoint_part = ModelRead::get_related_entity_name(
404
-                    $relation_name,
405
-                    $relation_obj
406
-                );
407
-                $model_routes[$singular_model_route . '/' . $related_model_name_endpoint_part] = array(
408
-                    array(
409
-                        'callback'        => array(
410
-                            'EventEspresso\core\libraries\rest_api\controllers\model\Read',
411
-                            'handle_request_get_related',
412
-                        ),
413
-                        'methods'         => WP_REST_Server::READABLE,
414
-                        'hidden_endpoint' => $hidden_endpoint,
415
-                        'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
416
-                    ),
417
-                    //							array(
418
-                    //								'callback' => array(
419
-                    //									'EventEspresso\core\libraries\rest_api\controllers\model\Write',
420
-                    //									'handle_request_create_or_update_related' ),
421
-                    //								'methods' => WP_REST_Server::EDITABLE,
422
-                    //								'hidden_endpoint' => $hidden_endpoint
423
-                    //							)
424
-                );
425
-                //@todo: handle delete related and possibly remove relation (not sure hwo to distinguish)
426
-            }
427
-        }
428
-        return $model_routes;
429
-    }
430
-
431
-
432
-
433
-    /**
434
-     * Adds all the RPC-style routes (remote procedure call-like routes, ie
435
-     * routes that don't conform to the traditional REST CRUD-style).
436
-     *
437
-     * @deprecated since 4.9.1
438
-     */
439
-    protected function _register_rpc_routes()
440
-    {
441
-        $routes = array();
442
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
443
-            $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version($version,
444
-                $hidden_endpoint);
445
-        }
446
-        return $routes;
447
-    }
448
-
449
-
450
-
451
-    /**
452
-     * @param string  $version
453
-     * @param boolean $hidden_endpoint
454
-     * @return array
455
-     */
456
-    protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
457
-    {
458
-        $this_versions_routes = array();
459
-        //checkin endpoint
460
-        $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
461
-            array(
462
-                'callback'        => array(
463
-                    'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
464
-                    'handle_request_toggle_checkin',
465
-                ),
466
-                'methods'         => WP_REST_Server::CREATABLE,
467
-                'hidden_endpoint' => $hidden_endpoint,
468
-                'args'            => array(
469
-                    'force' => array(
470
-                        'required'    => false,
471
-                        'default'     => false,
472
-                        'description' => __('Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
473
-                            'event_espresso'),
474
-                    ),
475
-                ),
476
-            ),
477
-        );
478
-        return apply_filters(
479
-            'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
480
-            $this_versions_routes,
481
-            $version,
482
-            $hidden_endpoint
483
-        );
484
-    }
485
-
486
-
487
-
488
-    /**
489
-     * Gets the query params that can be used when request one or many
490
-     *
491
-     * @param EEM_Base $model
492
-     * @param string   $version
493
-     * @return array
494
-     */
495
-    protected function _get_response_selection_query_params(\EEM_Base $model, $version)
496
-    {
497
-        return apply_filters(
498
-            'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
499
-            array(
500
-                'include'   => array(
501
-                    'required' => false,
502
-                    'default'  => '*',
503
-                ),
504
-                'calculate' => array(
505
-                    'required' => false,
506
-                    'default'  => '',
507
-                    'enum'     => self::$_field_calculator->retrieve_calculated_fields_for_model($model),
508
-                ),
509
-            ),
510
-            $model,
511
-            $version
512
-        );
513
-    }
514
-
515
-
516
-
517
-    /**
518
-     * Gets info about reading query params that are acceptable
519
-     *
520
-     * @param \EEM_Base $model eg 'Event' or 'Venue'
521
-     * @param  string   $version
522
-     * @return array    describing the args acceptable when querying this model
523
-     * @throws \EE_Error
524
-     */
525
-    protected function _get_read_query_params(\EEM_Base $model, $version)
526
-    {
527
-        $default_orderby = array();
528
-        foreach ($model->get_combined_primary_key_fields() as $key_field) {
529
-            $default_orderby[$key_field->get_name()] = 'ASC';
530
-        }
531
-        return array_merge(
532
-            $this->_get_response_selection_query_params($model, $version),
533
-            array(
534
-                'where'    => array(
535
-                    'required' => false,
536
-                    'default'  => array(),
537
-                ),
538
-                'limit'    => array(
539
-                    'required' => false,
540
-                    'default'  => EED_Core_Rest_Api::get_default_query_limit(),
541
-                ),
542
-                'order_by' => array(
543
-                    'required' => false,
544
-                    'default'  => $default_orderby,
545
-                ),
546
-                'group_by' => array(
547
-                    'required' => false,
548
-                    'default'  => null,
549
-                ),
550
-                'having'   => array(
551
-                    'required' => false,
552
-                    'default'  => null,
553
-                ),
554
-                'caps'     => array(
555
-                    'required' => false,
556
-                    'default'  => EEM_Base::caps_read,
557
-                ),
558
-            )
559
-        );
560
-    }
561
-
562
-
563
-
564
-    /**
565
-     * Gets routes for the config
566
-     *
567
-     * @return array @see _register_model_routes
568
-     * @deprecated since version 4.9.1
569
-     */
570
-    protected function _register_config_routes()
571
-    {
572
-        $config_routes = array();
573
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
574
-            $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version($version,
575
-                $hidden_endpoint);
576
-        }
577
-        return $config_routes;
578
-    }
579
-
580
-
581
-
582
-    /**
583
-     * Gets routes for the config for the specified version
584
-     *
585
-     * @param string  $version
586
-     * @param boolean $hidden_endpoint
587
-     * @return array
588
-     */
589
-    protected function _get_config_route_data_for_version($version, $hidden_endpoint)
590
-    {
591
-        return array(
592
-            'config'    => array(
593
-                array(
594
-                    'callback'        => array(
595
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
596
-                        'handle_request',
597
-                    ),
598
-                    'methods'         => WP_REST_Server::READABLE,
599
-                    'hidden_endpoint' => $hidden_endpoint,
600
-                ),
601
-            ),
602
-            'site_info' => array(
603
-                array(
604
-                    'callback'        => array(
605
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
606
-                        'handle_request_site_info',
607
-                    ),
608
-                    'methods'         => WP_REST_Server::READABLE,
609
-                    'hidden_endpoint' => $hidden_endpoint,
610
-                ),
611
-            ),
612
-        );
613
-    }
614
-
615
-
616
-
617
-    /**
618
-     * Gets the meta info routes
619
-     *
620
-     * @return array @see _register_model_routes
621
-     * @deprecated since version 4.9.1
622
-     */
623
-    protected function _register_meta_routes()
624
-    {
625
-        $meta_routes = array();
626
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
627
-            $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version($version,
628
-                $hidden_endpoint);
629
-        }
630
-        return $meta_routes;
631
-    }
632
-
633
-
634
-
635
-    /**
636
-     * @param string  $version
637
-     * @param boolean $hidden_endpoint
638
-     * @return array
639
-     */
640
-    protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
641
-    {
642
-        return array(
643
-            'resources' => array(
644
-                array(
645
-                    'callback'        => array(
646
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
647
-                        'handle_request_models_meta',
648
-                    ),
649
-                    'methods'         => WP_REST_Server::READABLE,
650
-                    'hidden_endpoint' => $hidden_endpoint,
651
-                ),
652
-            ),
653
-        );
654
-    }
655
-
656
-
657
-
658
-    /**
659
-     * Tries to hide old 4.6 endpoints from the
660
-     *
661
-     * @param array $route_data
662
-     * @return array
663
-     */
664
-    public static function hide_old_endpoints($route_data)
665
-    {
666
-        //allow API clients to override which endpoints get hidden, in case
667
-        //they want to discover particular endpoints
668
-        //also, we don't have access to the request so we have to just grab it from the superglobal
669
-        $force_show_ee_namespace = ltrim(
670
-            EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''),
671
-            '/'
672
-        );
673
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
674
-            foreach ($relative_urls as $endpoint => $routes) {
675
-                foreach ($routes as $route) {
676
-                    //by default, hide "hidden_endpoint"s, unless the request indicates
677
-                    //to $force_show_ee_namespace, in which case only show that one
678
-                    //namespace's endpoints (and hide all others)
679
-                    if (($route['hidden_endpoint'] && $force_show_ee_namespace === '')
680
-                        || ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
681
-                    ) {
682
-                        $full_route = '/' . ltrim($namespace, '/') . '/' . ltrim($endpoint, '/');
683
-                        unset($route_data[$full_route]);
684
-                    }
685
-                }
686
-            }
687
-        }
688
-        return $route_data;
689
-    }
690
-
691
-
692
-
693
-    /**
694
-     * Returns an array describing which versions of core support serving requests for.
695
-     * Keys are core versions' major and minor version, and values are the
696
-     * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
697
-     * data by just removing a few models and fields from the responses. However, 4.15 might remove
698
-     * the answers table entirely, in which case it would be very difficult for
699
-     * it to serve 4.6-style responses.
700
-     * Versions of core that are missing from this array are unknowns.
701
-     * previous ver
702
-     *
703
-     * @return array
704
-     */
705
-    public static function version_compatibilities()
706
-    {
707
-        return apply_filters(
708
-            'FHEE__EED_Core_REST_API__version_compatibilities',
709
-            array(
710
-                '4.8.29' => '4.8.29',
711
-                '4.8.33' => '4.8.29',
712
-                '4.8.34' => '4.8.29',
713
-                '4.8.36' => '4.8.29',
714
-            )
715
-        );
716
-    }
717
-
718
-
719
-
720
-    /**
721
-     * Gets the latest API version served. Eg if there
722
-     * are two versions served of the API, 4.8.29 and 4.8.32, and
723
-     * we are on core version 4.8.34, it will return the string "4.8.32"
724
-     *
725
-     * @return string
726
-     */
727
-    public static function latest_rest_api_version()
728
-    {
729
-        $versions_served = \EED_Core_Rest_Api::versions_served();
730
-        $versions_served_keys = array_keys($versions_served);
731
-        return end($versions_served_keys);
732
-    }
733
-
734
-
735
-
736
-    /**
737
-     * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
738
-     * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
739
-     * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
740
-     * We also indicate whether or not this version should be put in the index or not
741
-     *
742
-     * @return array keys are API version numbers (just major and minor numbers), and values
743
-     * are whether or not they should be hidden
744
-     */
745
-    public static function versions_served()
746
-    {
747
-        $versions_served = array();
748
-        $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
749
-        $lowest_compatible_version = end($possibly_served_versions);
750
-        reset($possibly_served_versions);
751
-        $versions_served_historically = array_keys($possibly_served_versions);
752
-        $latest_version = end($versions_served_historically);
753
-        reset($versions_served_historically);
754
-        //for each version of core we have ever served:
755
-        foreach ($versions_served_historically as $key_versioned_endpoint) {
756
-            //if it's not above the current core version, and it's compatible with the current version of core
757
-            if ($key_versioned_endpoint == $latest_version) {
758
-                //don't hide the latest version in the index
759
-                $versions_served[$key_versioned_endpoint] = false;
760
-            } else if (
761
-                $key_versioned_endpoint < EED_Core_Rest_Api::core_version()
762
-                && $key_versioned_endpoint >= $lowest_compatible_version
763
-            ) {
764
-                //include, but hide, previous versions which are still supported
765
-                $versions_served[$key_versioned_endpoint] = true;
766
-            } elseif (
767
-            apply_filters(
768
-                'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
769
-                false,
770
-                $possibly_served_versions
771
-            )
772
-            ) {
773
-                //if a version is no longer supported, don't include it in index or list of versions served
774
-                $versions_served[$key_versioned_endpoint] = true;
775
-            }
776
-        }
777
-        return $versions_served;
778
-    }
779
-
780
-
781
-
782
-    /**
783
-     * Gets the major and minor version of EE core's version string
784
-     *
785
-     * @return string
786
-     */
787
-    public static function core_version()
788
-    {
789
-        return apply_filters('FHEE__EED_Core_REST_API__core_version',
790
-            implode('.', array_slice(explode('.', espresso_version()), 0, 3)));
791
-    }
792
-
793
-
794
-
795
-    /**
796
-     * Gets the default limit that should be used when querying for resources
797
-     *
798
-     * @return int
799
-     */
800
-    public static function get_default_query_limit()
801
-    {
802
-        //we actually don't use a const because we want folks to always use
803
-        //this method, not the const directly
804
-        return apply_filters(
805
-            'FHEE__EED_Core_Rest_Api__get_default_query_limit',
806
-            50
807
-        );
808
-    }
809
-
810
-
811
-
812
-    /**
813
-     *    run - initial module setup
814
-     *
815
-     * @access    public
816
-     * @param  WP $WP
817
-     * @return    void
818
-     */
819
-    public function run($WP)
820
-    {
821
-    }
52
+	/**
53
+	 *    set_hooks - for hooking into EE Core, other modules, etc
54
+	 *
55
+	 * @access    public
56
+	 * @return    void
57
+	 */
58
+	public static function set_hooks()
59
+	{
60
+		self::set_hooks_both();
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
67
+	 *
68
+	 * @access    public
69
+	 * @return    void
70
+	 */
71
+	public static function set_hooks_admin()
72
+	{
73
+		self::set_hooks_both();
74
+	}
75
+
76
+
77
+
78
+	public static function set_hooks_both()
79
+	{
80
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
81
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
82
+		add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
83
+		add_filter('rest_index',
84
+			array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index'));
85
+		EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * sets up hooks which only need to be included as part of REST API requests;
92
+	 * other requests like to the frontend or admin etc don't need them
93
+	 */
94
+	public static function set_hooks_rest_api()
95
+	{
96
+		//set hooks which account for changes made to the API
97
+		EED_Core_Rest_Api::_set_hooks_for_changes();
98
+	}
99
+
100
+
101
+
102
+	/**
103
+	 * public wrapper of _set_hooks_for_changes.
104
+	 * Loads all the hooks which make requests to old versions of the API
105
+	 * appear the same as they always did
106
+	 */
107
+	public static function set_hooks_for_changes()
108
+	{
109
+		self::_set_hooks_for_changes();
110
+	}
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+	/**
119
+	 * Loads all the hooks which make requests to old versions of the API
120
+	 * appear the same as they always did
121
+	 */
122
+	protected static function _set_hooks_for_changes()
123
+	{
124
+		$folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
125
+		foreach ($folder_contents as $classname_in_namespace => $filepath) {
126
+			//ignore the base parent class
127
+			if ($classname_in_namespace === 'Changes_In_Base') {
128
+				continue;
129
+			}
130
+			$full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
131
+			if (class_exists($full_classname)) {
132
+				$instance_of_class = new $full_classname;
133
+				if ($instance_of_class instanceof Changes_In_Base) {
134
+					$instance_of_class->set_hooks();
135
+				}
136
+			}
137
+		}
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * Filters the WP routes to add our EE-related ones. This takes a bit of time
144
+	 * so we actually prefer to only do it when an EE plugin is activated or upgraded
145
+	 */
146
+	public static function register_routes()
147
+	{
148
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
149
+			foreach ($relative_urls as $endpoint => $routes) {
150
+				foreach ($routes as $route) {
151
+					$route_args = array(
152
+						array(
153
+							'callback' => $route['callback'],
154
+							'methods'  => $route['methods'],
155
+							'args'     => isset($route['args']) ? $route['args'] : array(),
156
+						)
157
+					);
158
+					if (isset($route['schema_callback'])) {
159
+						$model_name = isset($route['schema_callback'][0])
160
+							? $route['schema_callback'][0]
161
+							: '';
162
+						$version = isset( $route['schema_callback'][1])
163
+							? $route['schema_callback'][1]
164
+							: '';
165
+						if (! empty($model_name) && ! empty($version)) {
166
+							$route_args['schema'] = function () use ($model_name, $version) {
167
+								return ModelRead::handle_schema_request(
168
+									$model_name,
169
+									$version
170
+								);
171
+							};
172
+						}
173
+					}
174
+					register_rest_route(
175
+						$namespace,
176
+						$endpoint,
177
+						$route_args
178
+					);
179
+				}
180
+			}
181
+		}
182
+	}
183
+
184
+
185
+
186
+	/**
187
+	 * Checks if there was a version change or something that merits invalidating the cached
188
+	 * route data. If so, invalidates the cached route data so that it gets refreshed
189
+	 * next time the WP API is used
190
+	 */
191
+	public static function invalidate_cached_route_data_on_version_change()
192
+	{
193
+		if (EE_System::instance()->detect_req_type() != EE_System::req_type_normal) {
194
+			EED_Core_Rest_Api::invalidate_cached_route_data();
195
+		}
196
+		foreach (EE_Registry::instance()->addons as $addon) {
197
+			if ($addon instanceof EE_Addon && $addon->detect_req_type() != EE_System::req_type_normal) {
198
+				EED_Core_Rest_Api::invalidate_cached_route_data();
199
+			}
200
+		}
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * Removes the cached route data so it will get refreshed next time the WP API is used
207
+	 */
208
+	public static function invalidate_cached_route_data()
209
+	{
210
+		//delete the saved EE REST API routes
211
+		foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
212
+			delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
213
+		}
214
+	}
215
+
216
+
217
+
218
+	/**
219
+	 * Gets the EE route data
220
+	 *
221
+	 * @return array top-level key is the namespace, next-level key is the route and its value is array{
222
+	 * @type string|array $callback
223
+	 * @type string       $methods
224
+	 * @type boolean      $hidden_endpoint
225
+	 * }
226
+	 */
227
+	public static function get_ee_route_data()
228
+	{
229
+		$ee_routes = array();
230
+		foreach (self::versions_served() as $version => $hidden_endpoints) {
231
+			$ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version($version,
232
+				$hidden_endpoints);
233
+		}
234
+		return $ee_routes;
235
+	}
236
+
237
+
238
+
239
+	/**
240
+	 * Gets the EE route data from the wp options if it exists already,
241
+	 * otherwise re-generates it and saves it to the option
242
+	 *
243
+	 * @param string  $version
244
+	 * @param boolean $hidden_endpoints
245
+	 * @return array
246
+	 */
247
+	protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
248
+	{
249
+		$ee_routes = get_option(self::saved_routes_option_names . $version, null);
250
+		if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
251
+			$ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
252
+		}
253
+		return $ee_routes;
254
+	}
255
+
256
+
257
+
258
+	/**
259
+	 * Saves the EE REST API route data to a wp option and returns it
260
+	 *
261
+	 * @param string  $version
262
+	 * @param boolean $hidden_endpoints
263
+	 * @return mixed|null|void
264
+	 */
265
+	protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
266
+	{
267
+		$instance = self::instance();
268
+		$routes = apply_filters(
269
+			'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
270
+			array_replace_recursive(
271
+				$instance->_get_config_route_data_for_version($version, $hidden_endpoints),
272
+				$instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
273
+				$instance->_get_model_route_data_for_version($version, $hidden_endpoints),
274
+				$instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
275
+			)
276
+		);
277
+		$option_name = self::saved_routes_option_names . $version;
278
+		if (get_option($option_name)) {
279
+			update_option($option_name, $routes, true);
280
+		} else {
281
+			add_option($option_name, $routes, null, 'no');
282
+		}
283
+		return $routes;
284
+	}
285
+
286
+
287
+
288
+	/**
289
+	 * Calculates all the EE routes and saves it to a wordpress option so we don't
290
+	 * need to calculate it on every request
291
+	 *
292
+	 * @deprecated since version 4.9.1
293
+	 * @return void
294
+	 */
295
+	public static function save_ee_routes()
296
+	{
297
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
298
+			$instance = self::instance();
299
+			$routes = apply_filters(
300
+				'EED_Core_Rest_Api__save_ee_routes__routes',
301
+				array_replace_recursive(
302
+					$instance->_register_config_routes(),
303
+					$instance->_register_meta_routes(),
304
+					$instance->_register_model_routes(),
305
+					$instance->_register_rpc_routes()
306
+				)
307
+			);
308
+			update_option(self::saved_routes_option_names, $routes, true);
309
+		}
310
+	}
311
+
312
+
313
+
314
+	/**
315
+	 * Gets all the route information relating to EE models
316
+	 *
317
+	 * @return array @see get_ee_route_data
318
+	 * @deprecated since version 4.9.1
319
+	 */
320
+	protected function _register_model_routes()
321
+	{
322
+		$model_routes = array();
323
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
324
+			$model_routes[EED_Core_Rest_Api::ee_api_namespace
325
+						  . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
326
+		}
327
+		return $model_routes;
328
+	}
329
+
330
+
331
+
332
+	/**
333
+	 * Gets the route data for EE models in the specified version
334
+	 *
335
+	 * @param string  $version
336
+	 * @param boolean $hidden_endpoint
337
+	 * @return array
338
+	 */
339
+	protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
340
+	{
341
+		$model_version_info = new Model_Version_Info($version);
342
+		$models_to_register = apply_filters(
343
+			'FHEE__EED_Core_REST_API___register_model_routes',
344
+			$model_version_info->models_for_requested_version()
345
+		);
346
+		//let's not bother having endpoints for extra metas
347
+		unset($models_to_register['Extra_Meta']);
348
+		unset($models_to_register['Extra_Join']);
349
+		$model_routes = array();
350
+		foreach ($models_to_register as $model_name => $model_classname) {
351
+			$model = \EE_Registry::instance()->load_model($model_name);
352
+
353
+			//if this isn't a valid model then let's skip iterate to the next item in the loop.
354
+			if (! $model instanceof EEM_Base) {
355
+				continue;
356
+			}
357
+
358
+			//yes we could just register one route for ALL models, but then they wouldn't show up in the index
359
+			$plural_model_route = EEH_Inflector::pluralize_and_lower($model_name);
360
+			$singular_model_route = $plural_model_route . '/(?P<id>\d+)';
361
+			$model_routes[$plural_model_route] = array(
362
+				array(
363
+					'callback'        => array(
364
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
365
+						'handle_request_get_all',
366
+					),
367
+					'methods'         => WP_REST_Server::READABLE,
368
+					'hidden_endpoint' => $hidden_endpoint,
369
+					'args'            => $this->_get_read_query_params($model, $version),
370
+					'_links'          => array(
371
+						'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
372
+					),
373
+					'schema_callback' => array($model_name, $version)
374
+				),
375
+				//						array(
376
+				//							'callback' => array(
377
+				//								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
378
+				//								'handle_request_create_one' ),
379
+				//							'methods' => WP_REST_Server::CREATABLE,
380
+				//							'hidden_endpoint' => $hidden_endpoint
381
+				//						)
382
+			);
383
+			$model_routes[$singular_model_route] = array(
384
+				array(
385
+					'callback'        => array(
386
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
387
+						'handle_request_get_one',
388
+					),
389
+					'methods'         => WP_REST_Server::READABLE,
390
+					'hidden_endpoint' => $hidden_endpoint,
391
+					'args'            => $this->_get_response_selection_query_params($model, $version),
392
+				),
393
+				//						array(
394
+				//							'callback' => array(
395
+				//								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
396
+				//								'handle_request_edit_one' ),
397
+				//							'methods' => WP_REST_Server::EDITABLE,
398
+				//							'hidden_endpoint' => $hidden_endpoint
399
+				//							),
400
+			);
401
+			//@todo: also handle  DELETE for a single item
402
+			foreach ($model_version_info->relation_settings($model) as $relation_name => $relation_obj) {
403
+				$related_model_name_endpoint_part = ModelRead::get_related_entity_name(
404
+					$relation_name,
405
+					$relation_obj
406
+				);
407
+				$model_routes[$singular_model_route . '/' . $related_model_name_endpoint_part] = array(
408
+					array(
409
+						'callback'        => array(
410
+							'EventEspresso\core\libraries\rest_api\controllers\model\Read',
411
+							'handle_request_get_related',
412
+						),
413
+						'methods'         => WP_REST_Server::READABLE,
414
+						'hidden_endpoint' => $hidden_endpoint,
415
+						'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
416
+					),
417
+					//							array(
418
+					//								'callback' => array(
419
+					//									'EventEspresso\core\libraries\rest_api\controllers\model\Write',
420
+					//									'handle_request_create_or_update_related' ),
421
+					//								'methods' => WP_REST_Server::EDITABLE,
422
+					//								'hidden_endpoint' => $hidden_endpoint
423
+					//							)
424
+				);
425
+				//@todo: handle delete related and possibly remove relation (not sure hwo to distinguish)
426
+			}
427
+		}
428
+		return $model_routes;
429
+	}
430
+
431
+
432
+
433
+	/**
434
+	 * Adds all the RPC-style routes (remote procedure call-like routes, ie
435
+	 * routes that don't conform to the traditional REST CRUD-style).
436
+	 *
437
+	 * @deprecated since 4.9.1
438
+	 */
439
+	protected function _register_rpc_routes()
440
+	{
441
+		$routes = array();
442
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
443
+			$routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version($version,
444
+				$hidden_endpoint);
445
+		}
446
+		return $routes;
447
+	}
448
+
449
+
450
+
451
+	/**
452
+	 * @param string  $version
453
+	 * @param boolean $hidden_endpoint
454
+	 * @return array
455
+	 */
456
+	protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
457
+	{
458
+		$this_versions_routes = array();
459
+		//checkin endpoint
460
+		$this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
461
+			array(
462
+				'callback'        => array(
463
+					'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
464
+					'handle_request_toggle_checkin',
465
+				),
466
+				'methods'         => WP_REST_Server::CREATABLE,
467
+				'hidden_endpoint' => $hidden_endpoint,
468
+				'args'            => array(
469
+					'force' => array(
470
+						'required'    => false,
471
+						'default'     => false,
472
+						'description' => __('Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
473
+							'event_espresso'),
474
+					),
475
+				),
476
+			),
477
+		);
478
+		return apply_filters(
479
+			'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
480
+			$this_versions_routes,
481
+			$version,
482
+			$hidden_endpoint
483
+		);
484
+	}
485
+
486
+
487
+
488
+	/**
489
+	 * Gets the query params that can be used when request one or many
490
+	 *
491
+	 * @param EEM_Base $model
492
+	 * @param string   $version
493
+	 * @return array
494
+	 */
495
+	protected function _get_response_selection_query_params(\EEM_Base $model, $version)
496
+	{
497
+		return apply_filters(
498
+			'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
499
+			array(
500
+				'include'   => array(
501
+					'required' => false,
502
+					'default'  => '*',
503
+				),
504
+				'calculate' => array(
505
+					'required' => false,
506
+					'default'  => '',
507
+					'enum'     => self::$_field_calculator->retrieve_calculated_fields_for_model($model),
508
+				),
509
+			),
510
+			$model,
511
+			$version
512
+		);
513
+	}
514
+
515
+
516
+
517
+	/**
518
+	 * Gets info about reading query params that are acceptable
519
+	 *
520
+	 * @param \EEM_Base $model eg 'Event' or 'Venue'
521
+	 * @param  string   $version
522
+	 * @return array    describing the args acceptable when querying this model
523
+	 * @throws \EE_Error
524
+	 */
525
+	protected function _get_read_query_params(\EEM_Base $model, $version)
526
+	{
527
+		$default_orderby = array();
528
+		foreach ($model->get_combined_primary_key_fields() as $key_field) {
529
+			$default_orderby[$key_field->get_name()] = 'ASC';
530
+		}
531
+		return array_merge(
532
+			$this->_get_response_selection_query_params($model, $version),
533
+			array(
534
+				'where'    => array(
535
+					'required' => false,
536
+					'default'  => array(),
537
+				),
538
+				'limit'    => array(
539
+					'required' => false,
540
+					'default'  => EED_Core_Rest_Api::get_default_query_limit(),
541
+				),
542
+				'order_by' => array(
543
+					'required' => false,
544
+					'default'  => $default_orderby,
545
+				),
546
+				'group_by' => array(
547
+					'required' => false,
548
+					'default'  => null,
549
+				),
550
+				'having'   => array(
551
+					'required' => false,
552
+					'default'  => null,
553
+				),
554
+				'caps'     => array(
555
+					'required' => false,
556
+					'default'  => EEM_Base::caps_read,
557
+				),
558
+			)
559
+		);
560
+	}
561
+
562
+
563
+
564
+	/**
565
+	 * Gets routes for the config
566
+	 *
567
+	 * @return array @see _register_model_routes
568
+	 * @deprecated since version 4.9.1
569
+	 */
570
+	protected function _register_config_routes()
571
+	{
572
+		$config_routes = array();
573
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
574
+			$config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version($version,
575
+				$hidden_endpoint);
576
+		}
577
+		return $config_routes;
578
+	}
579
+
580
+
581
+
582
+	/**
583
+	 * Gets routes for the config for the specified version
584
+	 *
585
+	 * @param string  $version
586
+	 * @param boolean $hidden_endpoint
587
+	 * @return array
588
+	 */
589
+	protected function _get_config_route_data_for_version($version, $hidden_endpoint)
590
+	{
591
+		return array(
592
+			'config'    => array(
593
+				array(
594
+					'callback'        => array(
595
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
596
+						'handle_request',
597
+					),
598
+					'methods'         => WP_REST_Server::READABLE,
599
+					'hidden_endpoint' => $hidden_endpoint,
600
+				),
601
+			),
602
+			'site_info' => array(
603
+				array(
604
+					'callback'        => array(
605
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
606
+						'handle_request_site_info',
607
+					),
608
+					'methods'         => WP_REST_Server::READABLE,
609
+					'hidden_endpoint' => $hidden_endpoint,
610
+				),
611
+			),
612
+		);
613
+	}
614
+
615
+
616
+
617
+	/**
618
+	 * Gets the meta info routes
619
+	 *
620
+	 * @return array @see _register_model_routes
621
+	 * @deprecated since version 4.9.1
622
+	 */
623
+	protected function _register_meta_routes()
624
+	{
625
+		$meta_routes = array();
626
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
627
+			$meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version($version,
628
+				$hidden_endpoint);
629
+		}
630
+		return $meta_routes;
631
+	}
632
+
633
+
634
+
635
+	/**
636
+	 * @param string  $version
637
+	 * @param boolean $hidden_endpoint
638
+	 * @return array
639
+	 */
640
+	protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
641
+	{
642
+		return array(
643
+			'resources' => array(
644
+				array(
645
+					'callback'        => array(
646
+						'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
647
+						'handle_request_models_meta',
648
+					),
649
+					'methods'         => WP_REST_Server::READABLE,
650
+					'hidden_endpoint' => $hidden_endpoint,
651
+				),
652
+			),
653
+		);
654
+	}
655
+
656
+
657
+
658
+	/**
659
+	 * Tries to hide old 4.6 endpoints from the
660
+	 *
661
+	 * @param array $route_data
662
+	 * @return array
663
+	 */
664
+	public static function hide_old_endpoints($route_data)
665
+	{
666
+		//allow API clients to override which endpoints get hidden, in case
667
+		//they want to discover particular endpoints
668
+		//also, we don't have access to the request so we have to just grab it from the superglobal
669
+		$force_show_ee_namespace = ltrim(
670
+			EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''),
671
+			'/'
672
+		);
673
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
674
+			foreach ($relative_urls as $endpoint => $routes) {
675
+				foreach ($routes as $route) {
676
+					//by default, hide "hidden_endpoint"s, unless the request indicates
677
+					//to $force_show_ee_namespace, in which case only show that one
678
+					//namespace's endpoints (and hide all others)
679
+					if (($route['hidden_endpoint'] && $force_show_ee_namespace === '')
680
+						|| ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
681
+					) {
682
+						$full_route = '/' . ltrim($namespace, '/') . '/' . ltrim($endpoint, '/');
683
+						unset($route_data[$full_route]);
684
+					}
685
+				}
686
+			}
687
+		}
688
+		return $route_data;
689
+	}
690
+
691
+
692
+
693
+	/**
694
+	 * Returns an array describing which versions of core support serving requests for.
695
+	 * Keys are core versions' major and minor version, and values are the
696
+	 * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
697
+	 * data by just removing a few models and fields from the responses. However, 4.15 might remove
698
+	 * the answers table entirely, in which case it would be very difficult for
699
+	 * it to serve 4.6-style responses.
700
+	 * Versions of core that are missing from this array are unknowns.
701
+	 * previous ver
702
+	 *
703
+	 * @return array
704
+	 */
705
+	public static function version_compatibilities()
706
+	{
707
+		return apply_filters(
708
+			'FHEE__EED_Core_REST_API__version_compatibilities',
709
+			array(
710
+				'4.8.29' => '4.8.29',
711
+				'4.8.33' => '4.8.29',
712
+				'4.8.34' => '4.8.29',
713
+				'4.8.36' => '4.8.29',
714
+			)
715
+		);
716
+	}
717
+
718
+
719
+
720
+	/**
721
+	 * Gets the latest API version served. Eg if there
722
+	 * are two versions served of the API, 4.8.29 and 4.8.32, and
723
+	 * we are on core version 4.8.34, it will return the string "4.8.32"
724
+	 *
725
+	 * @return string
726
+	 */
727
+	public static function latest_rest_api_version()
728
+	{
729
+		$versions_served = \EED_Core_Rest_Api::versions_served();
730
+		$versions_served_keys = array_keys($versions_served);
731
+		return end($versions_served_keys);
732
+	}
733
+
734
+
735
+
736
+	/**
737
+	 * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
738
+	 * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
739
+	 * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
740
+	 * We also indicate whether or not this version should be put in the index or not
741
+	 *
742
+	 * @return array keys are API version numbers (just major and minor numbers), and values
743
+	 * are whether or not they should be hidden
744
+	 */
745
+	public static function versions_served()
746
+	{
747
+		$versions_served = array();
748
+		$possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
749
+		$lowest_compatible_version = end($possibly_served_versions);
750
+		reset($possibly_served_versions);
751
+		$versions_served_historically = array_keys($possibly_served_versions);
752
+		$latest_version = end($versions_served_historically);
753
+		reset($versions_served_historically);
754
+		//for each version of core we have ever served:
755
+		foreach ($versions_served_historically as $key_versioned_endpoint) {
756
+			//if it's not above the current core version, and it's compatible with the current version of core
757
+			if ($key_versioned_endpoint == $latest_version) {
758
+				//don't hide the latest version in the index
759
+				$versions_served[$key_versioned_endpoint] = false;
760
+			} else if (
761
+				$key_versioned_endpoint < EED_Core_Rest_Api::core_version()
762
+				&& $key_versioned_endpoint >= $lowest_compatible_version
763
+			) {
764
+				//include, but hide, previous versions which are still supported
765
+				$versions_served[$key_versioned_endpoint] = true;
766
+			} elseif (
767
+			apply_filters(
768
+				'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
769
+				false,
770
+				$possibly_served_versions
771
+			)
772
+			) {
773
+				//if a version is no longer supported, don't include it in index or list of versions served
774
+				$versions_served[$key_versioned_endpoint] = true;
775
+			}
776
+		}
777
+		return $versions_served;
778
+	}
779
+
780
+
781
+
782
+	/**
783
+	 * Gets the major and minor version of EE core's version string
784
+	 *
785
+	 * @return string
786
+	 */
787
+	public static function core_version()
788
+	{
789
+		return apply_filters('FHEE__EED_Core_REST_API__core_version',
790
+			implode('.', array_slice(explode('.', espresso_version()), 0, 3)));
791
+	}
792
+
793
+
794
+
795
+	/**
796
+	 * Gets the default limit that should be used when querying for resources
797
+	 *
798
+	 * @return int
799
+	 */
800
+	public static function get_default_query_limit()
801
+	{
802
+		//we actually don't use a const because we want folks to always use
803
+		//this method, not the const directly
804
+		return apply_filters(
805
+			'FHEE__EED_Core_Rest_Api__get_default_query_limit',
806
+			50
807
+		);
808
+	}
809
+
810
+
811
+
812
+	/**
813
+	 *    run - initial module setup
814
+	 *
815
+	 * @access    public
816
+	 * @param  WP $WP
817
+	 * @return    void
818
+	 */
819
+	public function run($WP)
820
+	{
821
+	}
822 822
 }
823 823
 
824 824
 // End of file EED_Core_Rest_Api.module.php
Please login to merge, or discard this patch.
core/libraries/form_sections/strategies/layout/EE_No_Layout.strategy.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -12,75 +12,75 @@
 block discarded – undo
12 12
 class EE_No_Layout extends EE_Div_Per_Section_Layout
13 13
 {
14 14
 
15
-    /**
16
-     * opening div tag for a form
17
-     *
18
-     * @return string
19
-     */
20
-    public function layout_form_begin()
21
-    {
22
-        return EEH_HTML::nl(1);
23
-    }
15
+	/**
16
+	 * opening div tag for a form
17
+	 *
18
+	 * @return string
19
+	 */
20
+	public function layout_form_begin()
21
+	{
22
+		return EEH_HTML::nl(1);
23
+	}
24 24
 
25 25
 
26
-    /**
27
-     * Lays out the row for the input, including label and errors
28
-     *
29
-     * @param EE_Form_Input_Base $input
30
-     * @return string
31
-     */
32
-    public function layout_input($input)
33
-    {
34
-        $html = '';
35
-        if ($input instanceof EE_Hidden_Input) {
36
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
37
-        } else if ($input instanceof EE_Submit_Input) {
38
-            $html .= EEH_HTML::br();
39
-            $html .= $input->get_html_for_input();
40
-        } else if ($input instanceof EE_Select_Input) {
41
-            $html .= EEH_HTML::br();
42
-            $html .= EEH_HTML::nl(1) . $input->get_html_for_label();
43
-            $html .= EEH_HTML::nl() . $input->get_html_for_errors();
44
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
45
-            $html .= EEH_HTML::nl() . $input->get_html_for_help();
46
-            $html .= EEH_HTML::br();
47
-        } else if ($input instanceof EE_Form_Input_With_Options_Base) {
48
-            $html .= EEH_HTML::br();
49
-            $html .= EEH_HTML::nl() . $input->get_html_for_errors();
50
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
51
-            $html .= EEH_HTML::nl() . $input->get_html_for_help();
52
-        } else {
53
-            $html .= EEH_HTML::br();
54
-            $html .= EEH_HTML::nl(1) . $input->get_html_for_label();
55
-            $html .= EEH_HTML::nl() . $input->get_html_for_errors();
56
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
57
-            $html .= EEH_HTML::nl() . $input->get_html_for_help();
58
-        }
59
-        $html .= EEH_HTML::nl(-1);
60
-        return $html;
61
-    }
26
+	/**
27
+	 * Lays out the row for the input, including label and errors
28
+	 *
29
+	 * @param EE_Form_Input_Base $input
30
+	 * @return string
31
+	 */
32
+	public function layout_input($input)
33
+	{
34
+		$html = '';
35
+		if ($input instanceof EE_Hidden_Input) {
36
+			$html .= EEH_HTML::nl() . $input->get_html_for_input();
37
+		} else if ($input instanceof EE_Submit_Input) {
38
+			$html .= EEH_HTML::br();
39
+			$html .= $input->get_html_for_input();
40
+		} else if ($input instanceof EE_Select_Input) {
41
+			$html .= EEH_HTML::br();
42
+			$html .= EEH_HTML::nl(1) . $input->get_html_for_label();
43
+			$html .= EEH_HTML::nl() . $input->get_html_for_errors();
44
+			$html .= EEH_HTML::nl() . $input->get_html_for_input();
45
+			$html .= EEH_HTML::nl() . $input->get_html_for_help();
46
+			$html .= EEH_HTML::br();
47
+		} else if ($input instanceof EE_Form_Input_With_Options_Base) {
48
+			$html .= EEH_HTML::br();
49
+			$html .= EEH_HTML::nl() . $input->get_html_for_errors();
50
+			$html .= EEH_HTML::nl() . $input->get_html_for_input();
51
+			$html .= EEH_HTML::nl() . $input->get_html_for_help();
52
+		} else {
53
+			$html .= EEH_HTML::br();
54
+			$html .= EEH_HTML::nl(1) . $input->get_html_for_label();
55
+			$html .= EEH_HTML::nl() . $input->get_html_for_errors();
56
+			$html .= EEH_HTML::nl() . $input->get_html_for_input();
57
+			$html .= EEH_HTML::nl() . $input->get_html_for_help();
58
+		}
59
+		$html .= EEH_HTML::nl(-1);
60
+		return $html;
61
+	}
62 62
 
63 63
 
64
-    /**
65
-     * Lays out a row for the subsection
66
-     *
67
-     * @param EE_Form_Section_Proper $form_section
68
-     * @return string
69
-     */
70
-    public function layout_subsection($form_section)
71
-    {
64
+	/**
65
+	 * Lays out a row for the subsection
66
+	 *
67
+	 * @param EE_Form_Section_Proper $form_section
68
+	 * @return string
69
+	 */
70
+	public function layout_subsection($form_section)
71
+	{
72 72
 //		d( $form_section );
73
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
74
-    }
73
+		return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * closing div tag for a form
79
-     *
80
-     * @return string
81
-     */
82
-    public function layout_form_end()
83
-    {
84
-        return EEH_HTML::nl(-1);
85
-    }
77
+	/**
78
+	 * closing div tag for a form
79
+	 *
80
+	 * @return string
81
+	 */
82
+	public function layout_form_end()
83
+	{
84
+		return EEH_HTML::nl(-1);
85
+	}
86 86
 }
87 87
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -33,28 +33,28 @@  discard block
 block discarded – undo
33 33
     {
34 34
         $html = '';
35 35
         if ($input instanceof EE_Hidden_Input) {
36
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
36
+            $html .= EEH_HTML::nl().$input->get_html_for_input();
37 37
         } else if ($input instanceof EE_Submit_Input) {
38 38
             $html .= EEH_HTML::br();
39 39
             $html .= $input->get_html_for_input();
40 40
         } else if ($input instanceof EE_Select_Input) {
41 41
             $html .= EEH_HTML::br();
42
-            $html .= EEH_HTML::nl(1) . $input->get_html_for_label();
43
-            $html .= EEH_HTML::nl() . $input->get_html_for_errors();
44
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
45
-            $html .= EEH_HTML::nl() . $input->get_html_for_help();
42
+            $html .= EEH_HTML::nl(1).$input->get_html_for_label();
43
+            $html .= EEH_HTML::nl().$input->get_html_for_errors();
44
+            $html .= EEH_HTML::nl().$input->get_html_for_input();
45
+            $html .= EEH_HTML::nl().$input->get_html_for_help();
46 46
             $html .= EEH_HTML::br();
47 47
         } else if ($input instanceof EE_Form_Input_With_Options_Base) {
48 48
             $html .= EEH_HTML::br();
49
-            $html .= EEH_HTML::nl() . $input->get_html_for_errors();
50
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
51
-            $html .= EEH_HTML::nl() . $input->get_html_for_help();
49
+            $html .= EEH_HTML::nl().$input->get_html_for_errors();
50
+            $html .= EEH_HTML::nl().$input->get_html_for_input();
51
+            $html .= EEH_HTML::nl().$input->get_html_for_help();
52 52
         } else {
53 53
             $html .= EEH_HTML::br();
54
-            $html .= EEH_HTML::nl(1) . $input->get_html_for_label();
55
-            $html .= EEH_HTML::nl() . $input->get_html_for_errors();
56
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
57
-            $html .= EEH_HTML::nl() . $input->get_html_for_help();
54
+            $html .= EEH_HTML::nl(1).$input->get_html_for_label();
55
+            $html .= EEH_HTML::nl().$input->get_html_for_errors();
56
+            $html .= EEH_HTML::nl().$input->get_html_for_input();
57
+            $html .= EEH_HTML::nl().$input->get_html_for_help();
58 58
         }
59 59
         $html .= EEH_HTML::nl(-1);
60 60
         return $html;
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
     public function layout_subsection($form_section)
71 71
     {
72 72
 //		d( $form_section );
73
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
73
+        return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1);
74 74
     }
75 75
 
76 76
 
Please login to merge, or discard this patch.
core/db_classes/EE_Registration.class.php 1 patch
Spacing   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\exceptions\EntityNotFoundException;
2 2
 
3
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 /**
7 7
  * EE_Registration class
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
 	 *                             		    date_format and the second value is the time format
60 60
 	 * @return EE_Registration
61 61
 	 */
62
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
63
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
64
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
62
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
63
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
64
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
65 65
 	}
66 66
 
67 67
 
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 	 *                          		the website will be used.
73 73
 	 * @return EE_Registration
74 74
 	 */
75
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
76
-		return new self( $props_n_values, TRUE, $timezone );
75
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
76
+		return new self($props_n_values, TRUE, $timezone);
77 77
 	}
78 78
 
79 79
 
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
 	 *
84 84
 	 * @param        int $EVT_ID Event ID
85 85
 	 */
86
-	public function set_event( $EVT_ID = 0 ) {
87
-		$this->set( 'EVT_ID', $EVT_ID );
86
+	public function set_event($EVT_ID = 0) {
87
+		$this->set('EVT_ID', $EVT_ID);
88 88
 	}
89 89
 
90 90
 
@@ -98,18 +98,18 @@  discard block
 block discarded – undo
98 98
      * @throws \EE_Error
99 99
      * @throws \RuntimeException
100 100
      */
101
-	public function set( $field_name, $field_value, $use_default = FALSE ) {
102
-		switch( $field_name ) {
101
+	public function set($field_name, $field_value, $use_default = FALSE) {
102
+		switch ($field_name) {
103 103
 			case 'REG_code' :
104
-				if ( ! empty( $field_value ) && $this->reg_code() === null ) {
105
-					$this->set_reg_code( $field_value, $use_default );
104
+				if ( ! empty($field_value) && $this->reg_code() === null) {
105
+					$this->set_reg_code($field_value, $use_default);
106 106
 				}
107 107
 				break;
108 108
 			case 'STS_ID' :
109
-				$this->set_status( $field_value, $use_default );
109
+				$this->set_status($field_value, $use_default);
110 110
 				break;
111 111
 			default :
112
-				parent::set( $field_name, $field_value, $use_default );
112
+				parent::set($field_name, $field_value, $use_default);
113 113
 		}
114 114
 	}
115 115
 
@@ -127,40 +127,40 @@  discard block
 block discarded – undo
127 127
      * @throws \RuntimeException
128 128
      * @throws \EE_Error
129 129
      */
130
-	public function set_status( $new_STS_ID = NULL, $use_default = FALSE ) {
130
+	public function set_status($new_STS_ID = NULL, $use_default = FALSE) {
131 131
 		// get current REG_Status
132 132
 		$old_STS_ID = $this->status_ID();
133 133
 		// if status has changed
134 134
 		if (
135 135
 			$old_STS_ID !== $new_STS_ID // and that status has actually changed
136
-			&& ! empty( $old_STS_ID ) // and that old status is actually set
137
-			&& ! empty( $new_STS_ID ) // as well as the new status
136
+			&& ! empty($old_STS_ID) // and that old status is actually set
137
+			&& ! empty($new_STS_ID) // as well as the new status
138 138
 			&& $this->ID() // ensure registration is in the db
139 139
 		) {
140 140
             // TO approved
141
-			if ( $new_STS_ID === EEM_Registration::status_id_approved ) {
141
+			if ($new_STS_ID === EEM_Registration::status_id_approved) {
142 142
 				// reserve a space by incrementing ticket and datetime sold values
143 143
 				$this->_reserve_registration_space();
144
-				do_action( 'AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID );
144
+				do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID);
145 145
 			// OR FROM  approved
146
-			} else if ( $old_STS_ID === EEM_Registration::status_id_approved ) {
146
+			} else if ($old_STS_ID === EEM_Registration::status_id_approved) {
147 147
 				// release a space by decrementing ticket and datetime sold values
148 148
 				$this->_release_registration_space();
149
-				do_action( 'AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID );
149
+				do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID);
150 150
 			}
151 151
             // update status
152 152
             parent::set('STS_ID', $new_STS_ID, $use_default);
153 153
             $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID);
154 154
             /** @type EE_Transaction_Payments $transaction_payments */
155 155
             $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
156
-            $transaction_payments->recalculate_transaction_total( $this->transaction(), false );
157
-			$this->transaction()->update_status_based_on_total_paid( true );
158
-			do_action( 'AHEE__EE_Registration__set_status__after_update', $this );
156
+            $transaction_payments->recalculate_transaction_total($this->transaction(), false);
157
+			$this->transaction()->update_status_based_on_total_paid(true);
158
+			do_action('AHEE__EE_Registration__set_status__after_update', $this);
159 159
 			return TRUE;
160 160
 		} else {
161 161
 			//even though the old value matches the new value, it's still good to
162 162
 			//allow the parent set method to have a say
163
-			parent::set( 'STS_ID', $new_STS_ID, $use_default );
163
+			parent::set('STS_ID', $new_STS_ID, $use_default);
164 164
 			return TRUE;
165 165
 		}
166 166
 	}
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	 *        get Status ID
229 229
 	 */
230 230
 	public function status_ID() {
231
-		return $this->get( 'STS_ID' );
231
+		return $this->get('STS_ID');
232 232
 	}
233 233
 
234 234
 
@@ -259,12 +259,12 @@  discard block
 block discarded – undo
259 259
      * @return EE_Ticket|EE_Base_Class
260 260
      * @throws \EE_Error
261 261
      */
262
-	public function ticket( $include_archived = TRUE ) {
262
+	public function ticket($include_archived = TRUE) {
263 263
 		$query_params = array();
264
-		if ( $include_archived ) {
265
-			$query_params[ 'default_where_conditions' ] = 'none';
264
+		if ($include_archived) {
265
+			$query_params['default_where_conditions'] = 'none';
266 266
 		}
267
-		return $this->get_first_related( 'Ticket', $query_params );
267
+		return $this->get_first_related('Ticket', $query_params);
268 268
 	}
269 269
 
270 270
 
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 */
293 293
 	public function wp_user() {
294 294
 		$event = $this->event();
295
-		if ( $event instanceof EE_Event ) {
295
+		if ($event instanceof EE_Event) {
296 296
 			return $event->wp_user();
297 297
 		}
298 298
 		return 0;
@@ -363,8 +363,8 @@  discard block
 block discarded – undo
363 363
 	 *
364 364
 	 * @param        int $ATT_ID Attendee ID
365 365
 	 */
366
-	public function set_attendee_id( $ATT_ID = 0 ) {
367
-		$this->set( 'ATT_ID', $ATT_ID );
366
+	public function set_attendee_id($ATT_ID = 0) {
367
+		$this->set('ATT_ID', $ATT_ID);
368 368
 	}
369 369
 
370 370
 
@@ -374,8 +374,8 @@  discard block
 block discarded – undo
374 374
 	 *
375 375
 	 * @param        int $TXN_ID Transaction ID
376 376
 	 */
377
-	public function set_transaction_id( $TXN_ID = 0 ) {
378
-		$this->set( 'TXN_ID', $TXN_ID );
377
+	public function set_transaction_id($TXN_ID = 0) {
378
+		$this->set('TXN_ID', $TXN_ID);
379 379
 	}
380 380
 
381 381
 
@@ -385,8 +385,8 @@  discard block
 block discarded – undo
385 385
 	 *
386 386
 	 * @param    string $REG_session PHP Session ID
387 387
 	 */
388
-	public function set_session( $REG_session = '' ) {
389
-		$this->set( 'REG_session', $REG_session );
388
+	public function set_session($REG_session = '') {
389
+		$this->set('REG_session', $REG_session);
390 390
 	}
391 391
 
392 392
 
@@ -396,8 +396,8 @@  discard block
 block discarded – undo
396 396
 	 *
397 397
 	 * @param    string $REG_url_link Registration URL Link
398 398
 	 */
399
-	public function set_reg_url_link( $REG_url_link = '' ) {
400
-		$this->set( 'REG_url_link', $REG_url_link );
399
+	public function set_reg_url_link($REG_url_link = '') {
400
+		$this->set('REG_url_link', $REG_url_link);
401 401
 	}
402 402
 
403 403
 
@@ -407,8 +407,8 @@  discard block
 block discarded – undo
407 407
 	 *
408 408
 	 * @param        int $REG_count Primary Attendee
409 409
 	 */
410
-	public function set_count( $REG_count = 1 ) {
411
-		$this->set( 'REG_count', $REG_count );
410
+	public function set_count($REG_count = 1) {
411
+		$this->set('REG_count', $REG_count);
412 412
 	}
413 413
 
414 414
 
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
 	 *
419 419
 	 * @param        boolean $REG_group_size Group Registration
420 420
 	 */
421
-	public function set_group_size( $REG_group_size = FALSE ) {
422
-		$this->set( 'REG_group_size', $REG_group_size );
421
+	public function set_group_size($REG_group_size = FALSE) {
422
+		$this->set('REG_group_size', $REG_group_size);
423 423
 	}
424 424
 
425 425
 
@@ -495,8 +495,8 @@  discard block
 block discarded – undo
495 495
 	 *
496 496
 	 * @param        mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of Date
497 497
 	 */
498
-	public function set_reg_date( $REG_date = FALSE ) {
499
-		$this->set( 'REG_date', $REG_date );
498
+	public function set_reg_date($REG_date = FALSE) {
499
+		$this->set('REG_date', $REG_date);
500 500
 	}
501 501
 
502 502
 
@@ -507,8 +507,8 @@  discard block
 block discarded – undo
507 507
 	 * @access    public
508 508
 	 * @param    float $REG_final_price
509 509
 	 */
510
-	public function set_final_price( $REG_final_price = 0.00 ) {
511
-		$this->set( 'REG_final_price', $REG_final_price );
510
+	public function set_final_price($REG_final_price = 0.00) {
511
+		$this->set('REG_final_price', $REG_final_price);
512 512
 	}
513 513
 
514 514
 
@@ -519,8 +519,8 @@  discard block
 block discarded – undo
519 519
 	 * @access    public
520 520
 	 * @param    float $REG_paid
521 521
 	 */
522
-	public function set_paid( $REG_paid = 0.00 ) {
523
-		$this->set( 'REG_paid', $REG_paid );
522
+	public function set_paid($REG_paid = 0.00) {
523
+		$this->set('REG_paid', $REG_paid);
524 524
 	}
525 525
 
526 526
 
@@ -530,8 +530,8 @@  discard block
 block discarded – undo
530 530
 	 *
531 531
 	 * @param        boolean $REG_att_is_going Attendee Is Going
532 532
 	 */
533
-	public function set_att_is_going( $REG_att_is_going = FALSE ) {
534
-		$this->set( 'REG_att_is_going', $REG_att_is_going );
533
+	public function set_att_is_going($REG_att_is_going = FALSE) {
534
+		$this->set('REG_att_is_going', $REG_att_is_going);
535 535
 	}
536 536
 
537 537
 
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
 	 * @return EE_Attendee
542 542
 	 */
543 543
 	public function attendee() {
544
-		return $this->get_first_related( 'Attendee' );
544
+		return $this->get_first_related('Attendee');
545 545
 	}
546 546
 
547 547
 
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 	 *        get Event ID
551 551
 	 */
552 552
 	public function event_ID() {
553
-		return $this->get( 'EVT_ID' );
553
+		return $this->get('EVT_ID');
554 554
 	}
555 555
 
556 556
 
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
 	 */
561 561
 	public function event_name() {
562 562
 		$event = $this->event_obj();
563
-		if ( $event ) {
563
+		if ($event) {
564 564
 			return $event->name();
565 565
 		} else {
566 566
 			return NULL;
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 	 * @return EE_Event
575 575
 	 */
576 576
 	public function event_obj() {
577
-		return $this->get_first_related( 'Event' );
577
+		return $this->get_first_related('Event');
578 578
 	}
579 579
 
580 580
 
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 	 *        get Attendee ID
584 584
 	 */
585 585
 	public function attendee_ID() {
586
-		return $this->get( 'ATT_ID' );
586
+		return $this->get('ATT_ID');
587 587
 	}
588 588
 
589 589
 
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 	 *        get PHP Session ID
593 593
 	 */
594 594
 	public function session_ID() {
595
-		return $this->get( 'REG_session' );
595
+		return $this->get('REG_session');
596 596
 	}
597 597
 
598 598
 
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
603 603
 	 * @return string
604 604
 	 */
605
-	public function receipt_url( $messenger = 'html' ) {
605
+	public function receipt_url($messenger = 'html') {
606 606
 
607 607
 		/**
608 608
 		 * The below will be deprecated one version after this.  We check first if there is a custom receipt template already in use on old system.  If there is then we just return the standard url for it.
@@ -610,12 +610,12 @@  discard block
 block discarded – undo
610 610
 		 * @since 4.5.0
611 611
 		 */
612 612
 		$template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php';
613
-		$has_custom = EEH_Template::locate_template( $template_relative_path , array(), TRUE, TRUE, TRUE );
613
+		$has_custom = EEH_Template::locate_template($template_relative_path, array(), TRUE, TRUE, TRUE);
614 614
 
615
-		if ( $has_custom ) {
616
-			return add_query_arg( array( 'receipt' => 'true' ), $this->invoice_url( 'launch' ) );
615
+		if ($has_custom) {
616
+			return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch'));
617 617
 		}
618
-		return apply_filters( 'FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt' );
618
+		return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
619 619
 	}
620 620
 
621 621
 
@@ -626,28 +626,28 @@  discard block
 block discarded – undo
626 626
 	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
627 627
 	 * @return string
628 628
 	 */
629
-	public function invoice_url( $messenger = 'html' ) {
629
+	public function invoice_url($messenger = 'html') {
630 630
 		/**
631 631
 		 * The below will be deprecated one version after this.  We check first if there is a custom invoice template already in use on old system.  If there is then we just return the standard url for it.
632 632
 		 *
633 633
 		 * @since 4.5.0
634 634
 		 */
635 635
 		$template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
636
-		$has_custom = EEH_Template::locate_template( $template_relative_path , array(), TRUE, TRUE, TRUE );
636
+		$has_custom = EEH_Template::locate_template($template_relative_path, array(), TRUE, TRUE, TRUE);
637 637
 
638
-		if ( $has_custom ) {
639
-			if ( $messenger == 'html' ) {
640
-				return $this->invoice_url( 'launch' );
638
+		if ($has_custom) {
639
+			if ($messenger == 'html') {
640
+				return $this->invoice_url('launch');
641 641
 			}
642 642
 			$route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
643 643
 
644
-			$query_args = array( 'ee' => $route, 'id' => $this->reg_url_link() );
645
-			if ( $messenger == 'html' ) {
644
+			$query_args = array('ee' => $route, 'id' => $this->reg_url_link());
645
+			if ($messenger == 'html') {
646 646
 				$query_args['html'] = TRUE;
647 647
 			}
648
-			return add_query_arg( $query_args, get_permalink( EE_Registry::instance()->CFG->core->thank_you_page_id ) );
648
+			return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
649 649
 		}
650
-		return apply_filters( 'FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice' );
650
+		return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
651 651
 	}
652 652
 
653 653
 
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
 	 * @throws \EE_Error
661 661
 	 */
662 662
 	public function reg_url_link() {
663
-		return (string)$this->get( 'REG_url_link' );
663
+		return (string) $this->get('REG_url_link');
664 664
 	}
665 665
 
666 666
 
@@ -670,8 +670,8 @@  discard block
 block discarded – undo
670 670
 	 * @param string $type 'download','launch', or 'html' (default is 'launch')
671 671
 	 * @return void
672 672
 	 */
673
-	public function e_invoice_url( $type = 'launch' ) {
674
-		echo $this->invoice_url( $type );
673
+	public function e_invoice_url($type = 'launch') {
674
+		echo $this->invoice_url($type);
675 675
 	}
676 676
 
677 677
 
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
 	 * @return string
692 692
 	 */
693 693
 	public function payment_overview_url() {
694
-		return add_query_arg( array( 'e_reg_url_link' => $this->reg_url_link(), 'step' => 'payment_options', 'revisit' => TRUE ), EE_Registry::instance()->CFG->core->reg_page_url() );
694
+		return add_query_arg(array('e_reg_url_link' => $this->reg_url_link(), 'step' => 'payment_options', 'revisit' => TRUE), EE_Registry::instance()->CFG->core->reg_page_url());
695 695
 	}
696 696
 
697 697
 
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
 	 * @return string
703 703
 	 */
704 704
 	public function edit_attendee_information_url() {
705
-		return add_query_arg( array( 'e_reg_url_link' => $this->reg_url_link(), 'step' => 'attendee_information', 'revisit' => TRUE ), EE_Registry::instance()->CFG->core->reg_page_url() );
705
+		return add_query_arg(array('e_reg_url_link' => $this->reg_url_link(), 'step' => 'attendee_information', 'revisit' => TRUE), EE_Registry::instance()->CFG->core->reg_page_url());
706 706
 	}
707 707
 
708 708
 
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
 	 * @return string
713 713
 	 */
714 714
 	public function get_admin_edit_url() {
715
-		return EEH_URL::add_query_args_and_nonce( array( 'page' => 'espresso_registrations', 'action' => 'view_registration', '_REG_ID' => $this->ID() ), admin_url( 'admin.php' ) );
715
+		return EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_registrations', 'action' => 'view_registration', '_REG_ID' => $this->ID()), admin_url('admin.php'));
716 716
 	}
717 717
 
718 718
 
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
 	 *    is_primary_registrant?
722 722
 	 */
723 723
 	public function is_primary_registrant() {
724
-		return $this->get( 'REG_count' ) == 1 ? TRUE : FALSE;
724
+		return $this->get('REG_count') == 1 ? TRUE : FALSE;
725 725
 	}
726 726
 
727 727
 
@@ -730,12 +730,12 @@  discard block
 block discarded – undo
730 730
 	 * This returns the primary registration object for this registration group (which may be this object).
731 731
 	 * @return EE_Registration
732 732
 	 */
733
-	public function get_primary_registration()  {
734
-		if ( $this->is_primary_registrant() )
733
+	public function get_primary_registration() {
734
+		if ($this->is_primary_registrant())
735 735
 			return $this;
736 736
 
737 737
 		//k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
738
-		$primary_registrant = EEM_Registration::instance()->get_one( array( array('TXN_ID' => $this->transaction_ID(), 'REG_count' => 1 ) ) );
738
+		$primary_registrant = EEM_Registration::instance()->get_one(array(array('TXN_ID' => $this->transaction_ID(), 'REG_count' => 1)));
739 739
 		return $primary_registrant;
740 740
 	}
741 741
 
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
 	* 		@access		public
747 747
 	*/
748 748
 	public function count() {
749
-		return $this->get( 'REG_count' );
749
+		return $this->get('REG_count');
750 750
 	}
751 751
 
752 752
 
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 	 *        get Group Size
756 756
 	 */
757 757
 	public function group_size() {
758
-		return $this->get( 'REG_group_size' );
758
+		return $this->get('REG_group_size');
759 759
 	}
760 760
 
761 761
 
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
 	 *        get Registration Date
765 765
 	 */
766 766
 	public function date() {
767
-		return $this->get( 'REG_date' );
767
+		return $this->get('REG_date');
768 768
 	}
769 769
 
770 770
 
@@ -775,8 +775,8 @@  discard block
 block discarded – undo
775 775
 	 * @param string $time_format
776 776
 	 * @return string
777 777
 	 */
778
-	public function pretty_date( $date_format = NULL, $time_format = NULL ) {
779
-		return $this->get_datetime( 'REG_date', $date_format, $time_format );
778
+	public function pretty_date($date_format = NULL, $time_format = NULL) {
779
+		return $this->get_datetime('REG_date', $date_format, $time_format);
780 780
 	}
781 781
 
782 782
 
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 	 * @return    float
789 789
 	 */
790 790
 	public function final_price() {
791
-		return $this->get( 'REG_final_price' );
791
+		return $this->get('REG_final_price');
792 792
 	}
793 793
 
794 794
 
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
 	 * @return string
800 800
 	 */
801 801
 	public function pretty_final_price() {
802
-		return $this->get_pretty( 'REG_final_price' );
802
+		return $this->get_pretty('REG_final_price');
803 803
 	}
804 804
 
805 805
 
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
 	 * @return 	float
810 810
 	 */
811 811
 	public function paid() {
812
-		return $this->get( 'REG_paid' );
812
+		return $this->get('REG_paid');
813 813
 	}
814 814
 
815 815
 
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
 	 * @return 	float
820 820
 	 */
821 821
 	public function pretty_paid() {
822
-		return $this->get_pretty( 'REG_paid' );
822
+		return $this->get_pretty('REG_paid');
823 823
 	}
824 824
 
825 825
 
@@ -830,11 +830,11 @@  discard block
 block discarded – undo
830 830
 	 * @param array $requires_payment
831 831
 	 * @return bool
832 832
 	 */
833
-	public function owes_monies_and_can_pay( $requires_payment = array()) {
833
+	public function owes_monies_and_can_pay($requires_payment = array()) {
834 834
 		// these reg statuses require payment (if event is not free)
835
-		$requires_payment = ! empty( $requires_payment ) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment();
835
+		$requires_payment = ! empty($requires_payment) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment();
836 836
 		if (
837
-			in_array( $this->status_ID(), $requires_payment ) &&
837
+			in_array($this->status_ID(), $requires_payment) &&
838 838
 			$this->final_price() != 0 &&
839 839
 			$this->final_price() != $this->paid()
840 840
 		) {
@@ -851,8 +851,8 @@  discard block
 block discarded – undo
851 851
 	 * @param bool $show_icons
852 852
 	 * @return void
853 853
 	 */
854
-	public function e_pretty_status( $show_icons = FALSE ) {
855
-		echo $this->pretty_status( $show_icons );
854
+	public function e_pretty_status($show_icons = FALSE) {
855
+		echo $this->pretty_status($show_icons);
856 856
 	}
857 857
 
858 858
 
@@ -863,10 +863,10 @@  discard block
 block discarded – undo
863 863
 	 * @param bool $show_icons
864 864
 	 * @return string
865 865
 	 */
866
-	public function pretty_status( $show_icons = FALSE ) {
867
-		$status = EEM_Status::instance()->localized_status( array( $this->status_ID() => __( 'unknown', 'event_espresso' ) ), FALSE, 'sentence' );
866
+	public function pretty_status($show_icons = FALSE) {
867
+		$status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')), FALSE, 'sentence');
868 868
 		$icon = '';
869
-		switch ( $this->status_ID() ) {
869
+		switch ($this->status_ID()) {
870 870
 			case EEM_Registration::status_id_approved:
871 871
 				$icon = $show_icons ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' : '';
872 872
 				break;
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
 				$icon = $show_icons ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' : '';
890 890
 				break;
891 891
 		}
892
-		return $icon . $status[ $this->status_ID() ];
892
+		return $icon.$status[$this->status_ID()];
893 893
 	}
894 894
 
895 895
 
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
 	 *        get Attendee Is Going
899 899
 	 */
900 900
 	public function att_is_going() {
901
-		return $this->get( 'REG_att_is_going' );
901
+		return $this->get('REG_att_is_going');
902 902
 	}
903 903
 
904 904
 
@@ -908,8 +908,8 @@  discard block
 block discarded – undo
908 908
 	 * @param array $query_params like EEM_Base::get_all
909 909
 	 * @return EE_Answer[]
910 910
 	 */
911
-	public function answers( $query_params = NULL ) {
912
-		return $this->get_many_related( 'Answer', $query_params );
911
+	public function answers($query_params = NULL) {
912
+		return $this->get_many_related('Answer', $query_params);
913 913
 	}
914 914
 
915 915
 
@@ -923,9 +923,9 @@  discard block
 block discarded – undo
923 923
 	 * (because the answer might be an array of answer values, so passing pretty_value=true
924 924
 	 * will convert it into some kind of string)
925 925
 	 */
926
-	public function answer_value_to_question( $question, $pretty_value=true ) {
926
+	public function answer_value_to_question($question, $pretty_value = true) {
927 927
 		$question_id = EEM_Question::instance()->ensure_is_ID($question);
928
-		return EEM_Answer::instance()->get_answer_value_to_question($this,$question_id,$pretty_value);
928
+		return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
929 929
 	}
930 930
 
931 931
 
@@ -938,13 +938,13 @@  discard block
 block discarded – undo
938 938
 	 */
939 939
 	public function question_groups() {
940 940
 		$question_groups = array();
941
-		if ( $this->event() instanceof EE_Event ) {
941
+		if ($this->event() instanceof EE_Event) {
942 942
 			$question_groups = $this->event()->question_groups(
943 943
 				array(
944 944
 					array(
945 945
 						'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false
946 946
 					),
947
-					'order_by' => array( 'QSG_order' => 'ASC' )
947
+					'order_by' => array('QSG_order' => 'ASC')
948 948
 				)
949 949
 			);
950 950
 		}
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
 	 */
962 962
 	public function count_question_groups() {
963 963
 		$qg_count = 0;
964
-		if ( $this->event() instanceof EE_Event ) {
964
+		if ($this->event() instanceof EE_Event) {
965 965
 			$qg_count = $this->event()->count_related(
966 966
 				'Question_Group',
967 967
 				array(
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
 	 * @return string
983 983
 	 */
984 984
 	public function reg_date() {
985
-		return $this->get_datetime( 'REG_date' );
985
+		return $this->get_datetime('REG_date');
986 986
 	}
987 987
 
988 988
 
@@ -994,7 +994,7 @@  discard block
 block discarded – undo
994 994
 	 * @return EE_Datetime_Ticket
995 995
 	 */
996 996
 	public function datetime_ticket() {
997
-		return $this->get_first_related( 'Datetime_Ticket' );
997
+		return $this->get_first_related('Datetime_Ticket');
998 998
 	}
999 999
 
1000 1000
 
@@ -1004,15 +1004,15 @@  discard block
 block discarded – undo
1004 1004
 	 * @param EE_Datetime_Ticket $datetime_ticket
1005 1005
 	 * @return EE_Datetime_Ticket
1006 1006
 	 */
1007
-	public function set_datetime_ticket( $datetime_ticket ) {
1008
-		return $this->_add_relation_to( $datetime_ticket, 'Datetime_Ticket' );
1007
+	public function set_datetime_ticket($datetime_ticket) {
1008
+		return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1009 1009
 	}
1010 1010
 	/**
1011 1011
 	 * Gets deleted
1012 1012
 	 * @return boolean
1013 1013
 	 */
1014 1014
 	public function deleted() {
1015
-		return $this->get( 'REG_deleted' );
1015
+		return $this->get('REG_deleted');
1016 1016
 	}
1017 1017
 
1018 1018
 	/**
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
 	 * @return boolean
1022 1022
 	 */
1023 1023
 	public function set_deleted($deleted) {
1024
-	    if ( $deleted ) {
1024
+	    if ($deleted) {
1025 1025
 	        $this->delete();
1026 1026
         } else {
1027 1027
 	        $this->restore();
@@ -1035,7 +1035,7 @@  discard block
 block discarded – undo
1035 1035
 	 * @return EE_Status
1036 1036
 	 */
1037 1037
 	public function status_obj() {
1038
-		return $this->get_first_related( 'Status' );
1038
+		return $this->get_first_related('Status');
1039 1039
 	}
1040 1040
 
1041 1041
 
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
 	 * @return int
1047 1047
 	 */
1048 1048
 	public function count_checkins() {
1049
-		return $this->get_model()->count_related( $this, 'Checkin' );
1049
+		return $this->get_model()->count_related($this, 'Checkin');
1050 1050
 	}
1051 1051
 
1052 1052
 
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
 	 * @return int
1057 1057
 	 */
1058 1058
 	public function count_checkins_not_checkedout() {
1059
-		return $this->get_model()->count_related( $this, 'Checkin', array( array( 'CHK_in' => 1 ) ) );
1059
+		return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1)));
1060 1060
 	}
1061 1061
 
1062 1062
 
@@ -1069,20 +1069,20 @@  discard block
 block discarded – undo
1069 1069
 	 *
1070 1070
 	 * @return bool
1071 1071
 	 */
1072
-	public function can_checkin( $DTT_OR_ID, $check_approved = TRUE ) {
1073
-		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID( $DTT_OR_ID );
1072
+	public function can_checkin($DTT_OR_ID, $check_approved = TRUE) {
1073
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1074 1074
 
1075 1075
 		//first check registration status
1076
-		if (  ( $check_approved && ! $this->is_approved() ) || ! $DTT_ID ) {
1076
+		if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) {
1077 1077
 			return false;
1078 1078
 		}
1079 1079
 		//is there a datetime ticket that matches this dtt_ID?
1080
-		if ( ! ( EEM_Datetime_Ticket::instance()->exists( array( array( 'TKT_ID' => $this->get('TKT_ID' ), 'DTT_ID' => $DTT_ID ) ) ) ) ) {
1080
+		if ( ! (EEM_Datetime_Ticket::instance()->exists(array(array('TKT_ID' => $this->get('TKT_ID'), 'DTT_ID' => $DTT_ID))))) {
1081 1081
 			return false;
1082 1082
 		}
1083 1083
 
1084 1084
 		//final check is against TKT_uses
1085
-		return $this->verify_can_checkin_against_TKT_uses( $DTT_ID );
1085
+		return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1086 1086
 	}
1087 1087
 
1088 1088
 
@@ -1095,10 +1095,10 @@  discard block
 block discarded – undo
1095 1095
 	 * @param int | EE_Datetime  $DTT_OR_ID  The datetime the registration is being checked against
1096 1096
 	 * @return bool   true means can checkin.  false means cannot checkin.
1097 1097
 	 */
1098
-	public function verify_can_checkin_against_TKT_uses( $DTT_OR_ID ) {
1099
-		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID( $DTT_OR_ID );
1098
+	public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) {
1099
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1100 1100
 
1101
-		if ( ! $DTT_ID ) {
1101
+		if ( ! $DTT_ID) {
1102 1102
 			return false;
1103 1103
 		}
1104 1104
 
@@ -1106,23 +1106,23 @@  discard block
 block discarded – undo
1106 1106
 
1107 1107
 		// if max uses is not set or equals infinity then return true cause its not a factor for whether user can check-in
1108 1108
 		// or not.
1109
-		if ( ! $max_uses || $max_uses === EE_INF ) {
1109
+		if ( ! $max_uses || $max_uses === EE_INF) {
1110 1110
 			return true;
1111 1111
 		}
1112 1112
 
1113 1113
 		//does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1114 1114
 		//go ahead and toggle.
1115
-		if ( EEM_Checkin::instance()->exists( array( array( 'REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID ) ) ) ) {
1115
+		if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) {
1116 1116
 			return true;
1117 1117
 		}
1118 1118
 
1119 1119
 		//made it here so the last check is whether the number of checkins per unique datetime on this registration
1120 1120
 		//disallows further check-ins.
1121
-		$count_unique_dtt_checkins = EEM_Checkin::instance()->count( array( array( 'REG_ID' => $this->ID(), 'CHK_in' => true ) ), 'DTT_ID', true );
1121
+		$count_unique_dtt_checkins = EEM_Checkin::instance()->count(array(array('REG_ID' => $this->ID(), 'CHK_in' => true)), 'DTT_ID', true);
1122 1122
 		// checkins have already reached their max number of uses
1123 1123
 		// so registrant can NOT checkin
1124
-		if ( $count_unique_dtt_checkins >= $max_uses ) {
1125
-			EE_Error::add_error( __( 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
1124
+		if ($count_unique_dtt_checkins >= $max_uses) {
1125
+			EE_Error::add_error(__('Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1126 1126
 			return false;
1127 1127
 		}
1128 1128
 		return true;
@@ -1144,15 +1144,15 @@  discard block
 block discarded – undo
1144 1144
      * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1145 1145
      * @throws EE_Error
1146 1146
      */
1147
-	public function toggle_checkin_status( $DTT_ID = null, $verify = false ) {
1148
-		if ( empty( $DTT_ID ) ) {
1147
+	public function toggle_checkin_status($DTT_ID = null, $verify = false) {
1148
+		if (empty($DTT_ID)) {
1149 1149
 			$datetime = $this->get_latest_related_datetime();
1150 1150
 			$DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1151 1151
 		// verify the registration can checkin for the given DTT_ID
1152
-		} elseif ( ! $this->can_checkin( $DTT_ID, $verify ) ) {
1152
+		} elseif ( ! $this->can_checkin($DTT_ID, $verify)) {
1153 1153
 			EE_Error::add_error(
1154 1154
 					sprintf(
1155
-						__( 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', 'event_espresso'),
1155
+						__('The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', 'event_espresso'),
1156 1156
 						$this->ID(),
1157 1157
 						$DTT_ID
1158 1158
 					),
@@ -1166,8 +1166,8 @@  discard block
 block discarded – undo
1166 1166
 			EE_Registration::checkin_status_out => EE_Registration::checkin_status_in
1167 1167
 		);
1168 1168
 		//start by getting the current status so we know what status we'll be changing to.
1169
-		$cur_status = $this->check_in_status_for_datetime( $DTT_ID, NULL );
1170
-		$status_to = $status_paths[ $cur_status ];
1169
+		$cur_status = $this->check_in_status_for_datetime($DTT_ID, NULL);
1170
+		$status_to = $status_paths[$cur_status];
1171 1171
 		// database only records true for checked IN or false for checked OUT
1172 1172
 		// no record ( null ) means checked in NEVER, but we obviously don't save that
1173 1173
 		$new_status = $status_to === EE_Registration::checkin_status_in ? true : false;
@@ -1175,24 +1175,24 @@  discard block
 block discarded – undo
1175 1175
 		// because we are keeping track of Check-ins over time.
1176 1176
 		// Eventually we'll probably want to show a list table
1177 1177
 		// for the individual Check-ins so that they can be managed.
1178
-		$checkin = EE_Checkin::new_instance( array(
1178
+		$checkin = EE_Checkin::new_instance(array(
1179 1179
 				'REG_ID' => $this->ID(),
1180 1180
 				'DTT_ID' => $DTT_ID,
1181 1181
 				'CHK_in' => $new_status
1182
-		) );
1182
+		));
1183 1183
 		// if the record could not be saved then return false
1184
-		if ( $checkin->save() === 0 ) {
1185
-			if ( WP_DEBUG ) {
1184
+		if ($checkin->save() === 0) {
1185
+			if (WP_DEBUG) {
1186 1186
 				global $wpdb;
1187 1187
 				$error = sprintf(
1188
-					__( 'Registration check in update failed because of the following database error: %1$s%2$s', 'event_espresso' ),
1188
+					__('Registration check in update failed because of the following database error: %1$s%2$s', 'event_espresso'),
1189 1189
 					'<br />',
1190 1190
 					$wpdb->last_error
1191 1191
 				);
1192 1192
 			} else {
1193
-				$error = __( 'Registration check in update failed because of an unknown database error', 'event_espresso' );
1193
+				$error = __('Registration check in update failed because of an unknown database error', 'event_espresso');
1194 1194
 			}
1195
-			EE_Error::add_error( $error, __FILE__, __FUNCTION__, __LINE__ );
1195
+			EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1196 1196
 			return false;
1197 1197
 		}
1198 1198
 		return $status_to;
@@ -1213,7 +1213,7 @@  discard block
 block discarded – undo
1213 1213
 				array(
1214 1214
 					'Ticket.Registration.REG_ID' => $this->ID()
1215 1215
 				),
1216
-				'order_by' => array( 'DTT_EVT_start' => 'DESC' )
1216
+				'order_by' => array('DTT_EVT_start' => 'DESC')
1217 1217
 			)
1218 1218
 		);
1219 1219
 	}
@@ -1232,7 +1232,7 @@  discard block
 block discarded – undo
1232 1232
 				array(
1233 1233
 					'Ticket.Registration.REG_ID' => $this->ID()
1234 1234
 				),
1235
-				'order_by' => array( 'DTT_EVT_start' => 'ASC' )
1235
+				'order_by' => array('DTT_EVT_start' => 'ASC')
1236 1236
 			)
1237 1237
 		);
1238 1238
 	}
@@ -1251,21 +1251,21 @@  discard block
 block discarded – undo
1251 1251
      * @return int                Integer representing Check-in status.
1252 1252
      * @throws \EE_Error
1253 1253
      */
1254
-	public function check_in_status_for_datetime( $DTT_ID = 0, $checkin = null ) {
1254
+	public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) {
1255 1255
 		$checkin_query_params = array(
1256
-			'order_by' => array( 'CHK_timestamp' => 'DESC' )
1256
+			'order_by' => array('CHK_timestamp' => 'DESC')
1257 1257
 		);
1258 1258
 
1259
-		if ( $DTT_ID > 0 ) {
1260
-			$checkin_query_params[0] = array( 'DTT_ID' => $DTT_ID );
1259
+		if ($DTT_ID > 0) {
1260
+			$checkin_query_params[0] = array('DTT_ID' => $DTT_ID);
1261 1261
 		}
1262 1262
 
1263 1263
 		//get checkin object (if exists)
1264 1264
 		$checkin = $checkin instanceof EE_Checkin
1265 1265
             ? $checkin
1266
-            : $this->get_first_related( 'Checkin', $checkin_query_params );
1267
-		if ( $checkin instanceof EE_Checkin ) {
1268
-			if ( $checkin->get( 'CHK_in' ) ) {
1266
+            : $this->get_first_related('Checkin', $checkin_query_params);
1267
+		if ($checkin instanceof EE_Checkin) {
1268
+			if ($checkin->get('CHK_in')) {
1269 1269
 				return EE_Registration::checkin_status_in; //checked in
1270 1270
 			}
1271 1271
 			return EE_Registration::checkin_status_out; //had checked in but is now checked out.
@@ -1281,28 +1281,28 @@  discard block
 block discarded – undo
1281 1281
 	 * @param bool $error  This just flags that you want an error message returned. This is put in so that the error message can be customized with the attendee name.
1282 1282
 	 * @return string         internationalized message
1283 1283
 	 */
1284
-	public function get_checkin_msg( $DTT_ID, $error = FALSE ) {
1284
+	public function get_checkin_msg($DTT_ID, $error = FALSE) {
1285 1285
 		//let's get the attendee first so we can include the name of the attendee
1286
-		$attendee = $this->get_first_related( 'Attendee' );
1287
-		if ( $attendee instanceof EE_Attendee ) {
1288
-			if ( $error ) {
1289
-				return sprintf( __( "%s's check-in status was not changed.", "event_espresso" ), $attendee->full_name() );
1286
+		$attendee = $this->get_first_related('Attendee');
1287
+		if ($attendee instanceof EE_Attendee) {
1288
+			if ($error) {
1289
+				return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name());
1290 1290
 			}
1291
-			$cur_status = $this->check_in_status_for_datetime( $DTT_ID );
1291
+			$cur_status = $this->check_in_status_for_datetime($DTT_ID);
1292 1292
 			//what is the status message going to be?
1293
-			switch ( $cur_status ) {
1293
+			switch ($cur_status) {
1294 1294
 				case EE_Registration::checkin_status_never :
1295
-					return sprintf( __( "%s has been removed from Check-in records", "event_espresso" ), $attendee->full_name() );
1295
+					return sprintf(__("%s has been removed from Check-in records", "event_espresso"), $attendee->full_name());
1296 1296
 					break;
1297 1297
 				case EE_Registration::checkin_status_in :
1298
-					return sprintf( __( '%s has been checked in', 'event_espresso' ), $attendee->full_name() );
1298
+					return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1299 1299
 					break;
1300 1300
 				case EE_Registration::checkin_status_out :
1301
-					return sprintf( __( '%s has been checked out', 'event_espresso' ), $attendee->full_name() );
1301
+					return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1302 1302
 					break;
1303 1303
 			}
1304 1304
 		}
1305
-		return __( "The check-in status could not be determined.", "event_espresso" );
1305
+		return __("The check-in status could not be determined.", "event_espresso");
1306 1306
 	}
1307 1307
 
1308 1308
 
@@ -1326,7 +1326,7 @@  discard block
 block discarded – undo
1326 1326
 	 *        get Registration Code
1327 1327
 	 */
1328 1328
 	public function reg_code() {
1329
-		return $this->get( 'REG_code' );
1329
+		return $this->get('REG_code');
1330 1330
 	}
1331 1331
 
1332 1332
 
@@ -1335,7 +1335,7 @@  discard block
 block discarded – undo
1335 1335
 	 *        get Transaction ID
1336 1336
 	 */
1337 1337
 	public function transaction_ID() {
1338
-		return $this->get( 'TXN_ID' );
1338
+		return $this->get('TXN_ID');
1339 1339
 	}
1340 1340
 
1341 1341
 
@@ -1344,7 +1344,7 @@  discard block
 block discarded – undo
1344 1344
 	 * @return int
1345 1345
 	 */
1346 1346
 	public function ticket_ID() {
1347
-		return $this->get( 'TKT_ID' );
1347
+		return $this->get('TKT_ID');
1348 1348
 	}
1349 1349
 
1350 1350
 
@@ -1356,17 +1356,17 @@  discard block
 block discarded – undo
1356 1356
 	 * @param    string $REG_code Registration Code
1357 1357
 	 * @param	boolean $use_default
1358 1358
 	 */
1359
-	public function set_reg_code( $REG_code, $use_default = FALSE ) {
1360
-		if ( empty( $REG_code )) {
1361
-			EE_Error::add_error( __( 'REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
1359
+	public function set_reg_code($REG_code, $use_default = FALSE) {
1360
+		if (empty($REG_code)) {
1361
+			EE_Error::add_error(__('REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1362 1362
 			return;
1363 1363
 		}
1364
-		if ( ! $this->reg_code() ) {
1365
-			parent::set( 'REG_code', $REG_code, $use_default );
1364
+		if ( ! $this->reg_code()) {
1365
+			parent::set('REG_code', $REG_code, $use_default);
1366 1366
 		} else {
1367 1367
 			EE_Error::doing_it_wrong(
1368
-				__CLASS__ . '::' . __FUNCTION__,
1369
-				__( 'Can not change a registration REG_code once it has been set.', 'event_espresso' ),
1368
+				__CLASS__.'::'.__FUNCTION__,
1369
+				__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1370 1370
 				'4.6.0'
1371 1371
 			);
1372 1372
 		}
@@ -1386,17 +1386,17 @@  discard block
 block discarded – undo
1386 1386
 	 * @return EE_Registration[]  or empty array if this isn't a group registration.
1387 1387
 	 */
1388 1388
 	public function get_all_other_registrations_in_group() {
1389
-		if ( $this->group_size() < 2 ) {
1389
+		if ($this->group_size() < 2) {
1390 1390
 			return array();
1391 1391
 		}
1392 1392
 
1393 1393
 		$query[0] = array(
1394 1394
 			'TXN_ID' => $this->transaction_ID(),
1395
-			'REG_ID' => array( '!=', $this->ID() ),
1395
+			'REG_ID' => array('!=', $this->ID()),
1396 1396
 			'TKT_ID' => $this->ticket_ID()
1397 1397
 			);
1398 1398
 
1399
-		$registrations = $this->get_model()->get_all( $query );
1399
+		$registrations = $this->get_model()->get_all($query);
1400 1400
 		return $registrations;
1401 1401
 	}
1402 1402
 
@@ -1405,14 +1405,14 @@  discard block
 block discarded – undo
1405 1405
 	 * @return string
1406 1406
 	 */
1407 1407
 	public function get_admin_details_link() {
1408
-		EE_Registry::instance()->load_helper( 'URL' );
1408
+		EE_Registry::instance()->load_helper('URL');
1409 1409
 		return EEH_URL::add_query_args_and_nonce(
1410 1410
 			array(
1411 1411
 				'page' => 'espresso_registrations',
1412 1412
 				'action' => 'view_registration',
1413 1413
 				'_REG_ID' => $this->ID()
1414 1414
 			),
1415
-			admin_url( 'admin.php' )
1415
+			admin_url('admin.php')
1416 1416
 		);
1417 1417
 	}
1418 1418
 
@@ -1437,12 +1437,12 @@  discard block
 block discarded – undo
1437 1437
 	 * @return string
1438 1438
 	 */
1439 1439
 	public function get_admin_overview_link() {
1440
-		EE_Registry::instance()->load_helper( 'URL' );
1440
+		EE_Registry::instance()->load_helper('URL');
1441 1441
 		return EEH_URL::add_query_args_and_nonce(
1442 1442
 			array(
1443 1443
 				'page' => 'espresso_registrations'
1444 1444
 			),
1445
-			admin_url( 'admin.php' )
1445
+			admin_url('admin.php')
1446 1446
 		);
1447 1447
 	}
1448 1448
 
@@ -1453,8 +1453,8 @@  discard block
 block discarded – undo
1453 1453
 	 * @return \EE_Registration[]
1454 1454
 	 * @throws \EE_Error
1455 1455
 	 */
1456
-	public function payments( $query_params = array() ) {
1457
-		return $this->get_many_related( 'Payment', $query_params );
1456
+	public function payments($query_params = array()) {
1457
+		return $this->get_many_related('Payment', $query_params);
1458 1458
 	}
1459 1459
 
1460 1460
 
@@ -1464,8 +1464,8 @@  discard block
 block discarded – undo
1464 1464
 	 * @return \EE_Registration_Payment[]
1465 1465
 	 * @throws \EE_Error
1466 1466
 	 */
1467
-	public function registration_payments( $query_params = array() ) {
1468
-		return $this->get_many_related( 'Registration_Payment', $query_params );
1467
+	public function registration_payments($query_params = array()) {
1468
+		return $this->get_many_related('Registration_Payment', $query_params);
1469 1469
 	}
1470 1470
 
1471 1471
 
@@ -1478,7 +1478,7 @@  discard block
 block discarded – undo
1478 1478
 	 * @return EE_Payment_Method|null
1479 1479
 	 */
1480 1480
 	public function payment_method() {
1481
-		return EEM_Payment_Method::instance()->get_last_used_for_registration( $this );
1481
+		return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
1482 1482
 	}
1483 1483
 
1484 1484
 
@@ -1525,7 +1525,7 @@  discard block
 block discarded – undo
1525 1525
      */
1526 1526
     public function delete()
1527 1527
     {
1528
-        if($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1528
+        if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1529 1529
             $this->set_status(EEM_Registration::status_id_cancelled);
1530 1530
         }
1531 1531
         return parent::delete();
Please login to merge, or discard this patch.
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 1 patch
Indentation   +1704 added lines, -1704 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\exceptions\InvalidEntityException;
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
 
@@ -17,1709 +17,1709 @@  discard block
 block discarded – undo
17 17
 class EED_Single_Page_Checkout extends EED_Module
18 18
 {
19 19
 
20
-    /**
21
-     * $_initialized - has the SPCO controller already been initialized ?
22
-     *
23
-     * @access private
24
-     * @var bool $_initialized
25
-     */
26
-    private static $_initialized = false;
27
-
28
-
29
-    /**
30
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
31
-     *
32
-     * @access private
33
-     * @var bool $_valid_checkout
34
-     */
35
-    private static $_checkout_verified = true;
36
-
37
-    /**
38
-     *    $_reg_steps_array - holds initial array of reg steps
39
-     *
40
-     * @access private
41
-     * @var array $_reg_steps_array
42
-     */
43
-    private static $_reg_steps_array = array();
44
-
45
-    /**
46
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
47
-     *
48
-     * @access public
49
-     * @var EE_Checkout $checkout
50
-     */
51
-    public $checkout;
52
-
53
-
54
-
55
-    /**
56
-     * @return EED_Single_Page_Checkout
57
-     */
58
-    public static function instance()
59
-    {
60
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
61
-        return parent::get_instance(__CLASS__);
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * @return EE_CART
68
-     */
69
-    public function cart()
70
-    {
71
-        return $this->checkout->cart;
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * @return EE_Transaction
78
-     */
79
-    public function transaction()
80
-    {
81
-        return $this->checkout->transaction;
82
-    }
83
-
84
-
85
-
86
-    /**
87
-     *    set_hooks - for hooking into EE Core, other modules, etc
88
-     *
89
-     * @access    public
90
-     * @return    void
91
-     * @throws \EE_Error
92
-     */
93
-    public static function set_hooks()
94
-    {
95
-        EED_Single_Page_Checkout::set_definitions();
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
102
-     *
103
-     * @access    public
104
-     * @return    void
105
-     * @throws \EE_Error
106
-     */
107
-    public static function set_hooks_admin()
108
-    {
109
-        EED_Single_Page_Checkout::set_definitions();
110
-        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
111
-            // hook into the top of pre_get_posts to set the reg step routing, which gives other modules or plugins a chance to modify the reg steps, but just before the routes get called
112
-            add_action('pre_get_posts', array('EED_Single_Page_Checkout', 'load_reg_steps'), 1);
113
-            return;
114
-        }
115
-        // going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response
116
-        ob_start();
117
-        EED_Single_Page_Checkout::load_request_handler();
118
-        EED_Single_Page_Checkout::load_reg_steps();
119
-        // set ajax hooks
120
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
121
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
122
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
123
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
124
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
125
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     *    process ajax request
132
-     *
133
-     * @param string $ajax_action
134
-     * @throws \EE_Error
135
-     */
136
-    public static function process_ajax_request($ajax_action)
137
-    {
138
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
139
-        EED_Single_Page_Checkout::instance()->_initialize();
140
-    }
141
-
142
-
143
-
144
-    /**
145
-     *    ajax display registration step
146
-     *
147
-     * @throws \EE_Error
148
-     */
149
-    public static function display_reg_step()
150
-    {
151
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     *    ajax process registration step
158
-     *
159
-     * @throws \EE_Error
160
-     */
161
-    public static function process_reg_step()
162
-    {
163
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     *    ajax process registration step
170
-     *
171
-     * @throws \EE_Error
172
-     */
173
-    public static function update_reg_step()
174
-    {
175
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
176
-    }
177
-
178
-
179
-
180
-    /**
181
-     *   update_checkout
182
-     *
183
-     * @access public
184
-     * @return void
185
-     * @throws \EE_Error
186
-     */
187
-    public static function update_checkout()
188
-    {
189
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
190
-    }
191
-
192
-
193
-
194
-    /**
195
-     *    load_request_handler
196
-     *
197
-     * @access    public
198
-     * @return    void
199
-     */
200
-    public static function load_request_handler()
201
-    {
202
-        // load core Request_Handler class
203
-        if ( ! isset(EE_Registry::instance()->REQ)) {
204
-            EE_Registry::instance()->load_core('Request_Handler');
205
-        }
206
-    }
207
-
208
-
209
-
210
-    /**
211
-     *    set_definitions
212
-     *
213
-     * @access    public
214
-     * @return    void
215
-     * @throws \EE_Error
216
-     */
217
-    public static function set_definitions()
218
-    {
219
-        define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS);
220
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
221
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
222
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
223
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
224
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
225
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
226
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
227
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
228
-            __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
229
-                'event_espresso'),
230
-            '<h4 class="important-notice">',
231
-            '</h4>',
232
-            '<br />',
233
-            '<p>',
234
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
235
-            '">',
236
-            '</a>',
237
-            '</p>'
238
-        );
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * load_reg_steps
245
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
246
-     *
247
-     * @access    private
248
-     * @throws EE_Error
249
-     * @return void
250
-     */
251
-    public static function load_reg_steps()
252
-    {
253
-        static $reg_steps_loaded = false;
254
-        if ($reg_steps_loaded) {
255
-            return;
256
-        }
257
-        // filter list of reg_steps
258
-        $reg_steps_to_load = (array)apply_filters(
259
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
260
-            EED_Single_Page_Checkout::get_reg_steps()
261
-        );
262
-        // sort by key (order)
263
-        ksort($reg_steps_to_load);
264
-        // loop through folders
265
-        foreach ($reg_steps_to_load as $order => $reg_step) {
266
-            // we need a
267
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
268
-                // copy over to the reg_steps_array
269
-                EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
270
-                // register custom key route for each reg step
271
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
272
-                EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step');
273
-                // add AJAX or other hooks
274
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
275
-                    // setup autoloaders if necessary
276
-                    if ( ! class_exists($reg_step['class_name'])) {
277
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], true);
278
-                    }
279
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
280
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
281
-                    }
282
-                }
283
-            }
284
-        }
285
-        $reg_steps_loaded = true;
286
-    }
287
-
288
-
289
-
290
-    /**
291
-     *    get_reg_steps
292
-     *
293
-     * @access    public
294
-     * @return    array
295
-     */
296
-    public static function get_reg_steps()
297
-    {
298
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
299
-        if (empty($reg_steps)) {
300
-            $reg_steps = array(
301
-                10  => array(
302
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
303
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
304
-                    'slug'       => 'attendee_information',
305
-                    'has_hooks'  => false,
306
-                ),
307
-                20  => array(
308
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
309
-                    'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
310
-                    'slug'       => 'registration_confirmation',
311
-                    'has_hooks'  => false,
312
-                ),
313
-                30  => array(
314
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
315
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
316
-                    'slug'       => 'payment_options',
317
-                    'has_hooks'  => true,
318
-                ),
319
-                999 => array(
320
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
321
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
322
-                    'slug'       => 'finalize_registration',
323
-                    'has_hooks'  => false,
324
-                ),
325
-            );
326
-        }
327
-        return $reg_steps;
328
-    }
329
-
330
-
331
-
332
-    /**
333
-     *    registration_checkout_for_admin
334
-     *
335
-     * @access    public
336
-     * @return    string
337
-     * @throws \EE_Error
338
-     */
339
-    public static function registration_checkout_for_admin()
340
-    {
341
-        EED_Single_Page_Checkout::load_reg_steps();
342
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
343
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
344
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
345
-        EED_Single_Page_Checkout::instance()->_initialize();
346
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
347
-        return EE_Registry::instance()->REQ->get_output();
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * process_registration_from_admin
354
-     *
355
-     * @access public
356
-     * @return \EE_Transaction
357
-     * @throws \EE_Error
358
-     */
359
-    public static function process_registration_from_admin()
360
-    {
361
-        EED_Single_Page_Checkout::load_reg_steps();
362
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
363
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
364
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
365
-        EED_Single_Page_Checkout::instance()->_initialize();
366
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
367
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
368
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
369
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
370
-                if ($final_reg_step->process_reg_step()) {
371
-                    $final_reg_step->set_completed();
372
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
373
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
374
-                }
375
-            }
376
-        }
377
-        return null;
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     *    run
384
-     *
385
-     * @access    public
386
-     * @param WP_Query $WP_Query
387
-     * @return    void
388
-     * @throws \EE_Error
389
-     */
390
-    public function run($WP_Query)
391
-    {
392
-        if (
393
-            $WP_Query instanceof WP_Query
394
-            && $WP_Query->is_main_query()
395
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
396
-            && $this->_is_reg_checkout()
397
-        ) {
398
-            $this->_initialize();
399
-        }
400
-    }
401
-
402
-
403
-
404
-    /**
405
-     * determines whether current url matches reg page url
406
-     *
407
-     * @return bool
408
-     */
409
-    protected function _is_reg_checkout()
410
-    {
411
-        // get current permalink for reg page without any extra query args
412
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
413
-        // get request URI for current request, but without the scheme or host
414
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
415
-        $current_request_uri = html_entity_decode($current_request_uri);
416
-        // get array of query args from the current request URI
417
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
418
-        // grab page id if it is set
419
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
420
-        // and remove the page id from the query args (we will re-add it later)
421
-        unset($query_args['page_id']);
422
-        // now strip all query args from current request URI
423
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
424
-        // and re-add the page id if it was set
425
-        if ($page_id) {
426
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
427
-        }
428
-        // remove slashes and ?
429
-        $current_request_uri = trim($current_request_uri, '?/');
430
-        // is current request URI part of the known full reg page URL ?
431
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
432
-    }
433
-
434
-
435
-
436
-    /**
437
-     *    run
438
-     *
439
-     * @access    public
440
-     * @param WP_Query $WP_Query
441
-     * @return    void
442
-     * @throws \EE_Error
443
-     */
444
-    public static function init($WP_Query)
445
-    {
446
-        EED_Single_Page_Checkout::instance()->run($WP_Query);
447
-    }
448
-
449
-
450
-
451
-    /**
452
-     *    _initialize - initial module setup
453
-     *
454
-     * @access    private
455
-     * @throws EE_Error
456
-     * @return    void
457
-     */
458
-    private function _initialize()
459
-    {
460
-        // ensure SPCO doesn't run twice
461
-        if (EED_Single_Page_Checkout::$_initialized) {
462
-            return;
463
-        }
464
-        try {
465
-            $this->_verify_session();
466
-            // setup the EE_Checkout object
467
-            $this->checkout = $this->_initialize_checkout();
468
-            // filter checkout
469
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
470
-            // get the $_GET
471
-            $this->_get_request_vars();
472
-            if ($this->_block_bots()) {
473
-                return;
474
-            }
475
-            // filter continue_reg
476
-            $this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', true, $this->checkout);
477
-            // load the reg steps array
478
-            if ( ! $this->_load_and_instantiate_reg_steps()) {
479
-                EED_Single_Page_Checkout::$_initialized = true;
480
-                return;
481
-            }
482
-            // set the current step
483
-            $this->checkout->set_current_step($this->checkout->step);
484
-            // and the next step
485
-            $this->checkout->set_next_step();
486
-            // verify that everything has been setup correctly
487
-            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
488
-                EED_Single_Page_Checkout::$_initialized = true;
489
-                return;
490
-            }
491
-            // lock the transaction
492
-            $this->checkout->transaction->lock();
493
-            // make sure all of our cached objects are added to their respective model entity mappers
494
-            $this->checkout->refresh_all_entities();
495
-            // set amount owing
496
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
497
-            // initialize each reg step, which gives them the chance to potentially alter the process
498
-            $this->_initialize_reg_steps();
499
-            // DEBUG LOG
500
-            //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
501
-            // get reg form
502
-            if( ! $this->_check_form_submission()) {
503
-                EED_Single_Page_Checkout::$_initialized = true;
504
-                return;
505
-            }
506
-            // checkout the action!!!
507
-            $this->_process_form_action();
508
-            // add some style and make it dance
509
-            $this->add_styles_and_scripts();
510
-            // kk... SPCO has successfully run
511
-            EED_Single_Page_Checkout::$_initialized = true;
512
-            // set no cache headers and constants
513
-            EE_System::do_not_cache();
514
-            // add anchor
515
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
516
-            // remove transaction lock
517
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
518
-        } catch (Exception $e) {
519
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
520
-        }
521
-    }
522
-
523
-
524
-
525
-    /**
526
-     *    _verify_session
527
-     * checks that the session is valid and not expired
528
-     *
529
-     * @access    private
530
-     * @throws EE_Error
531
-     */
532
-    private function _verify_session()
533
-    {
534
-        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
535
-            throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
536
-        }
537
-        // is session still valid ?
538
-        if (EE_Registry::instance()->SSN->expired() && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '') {
539
-            $this->checkout = new EE_Checkout();
540
-            EE_Registry::instance()->SSN->reset_cart();
541
-            EE_Registry::instance()->SSN->reset_checkout();
542
-            EE_Registry::instance()->SSN->reset_transaction();
543
-            EE_Error::add_attention(EE_Registry::$i18n_js_strings['registration_expiration_notice'], __FILE__,
544
-                __FUNCTION__, __LINE__);
545
-            EE_Registry::instance()->SSN->reset_expired();
546
-        }
547
-    }
548
-
549
-
550
-
551
-    /**
552
-     *    _initialize_checkout
553
-     * loads and instantiates EE_Checkout
554
-     *
555
-     * @access    private
556
-     * @throws EE_Error
557
-     * @return EE_Checkout
558
-     */
559
-    private function _initialize_checkout()
560
-    {
561
-        // look in session for existing checkout
562
-        /** @type EE_Checkout $checkout */
563
-        $checkout = EE_Registry::instance()->SSN->checkout();
564
-        // verify
565
-        if ( ! $checkout instanceof EE_Checkout) {
566
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
567
-            $checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), false);
568
-        } else {
569
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
570
-                $this->unlock_transaction();
571
-                wp_safe_redirect($checkout->redirect_url);
572
-                exit();
573
-            }
574
-        }
575
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
576
-        // verify again
577
-        if ( ! $checkout instanceof EE_Checkout) {
578
-            throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
579
-        }
580
-        // reset anything that needs a clean slate for each request
581
-        $checkout->reset_for_current_request();
582
-        return $checkout;
583
-    }
584
-
585
-
586
-
587
-    /**
588
-     *    _get_request_vars
589
-     *
590
-     * @access    private
591
-     * @return    void
592
-     * @throws \EE_Error
593
-     */
594
-    private function _get_request_vars()
595
-    {
596
-        // load classes
597
-        EED_Single_Page_Checkout::load_request_handler();
598
-        //make sure this request is marked as belonging to EE
599
-        EE_Registry::instance()->REQ->set_espresso_page(true);
600
-        // which step is being requested ?
601
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
602
-        // which step is being edited ?
603
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
604
-        // and what we're doing on the current step
605
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
606
-        // timestamp
607
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
608
-        // returning to edit ?
609
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
610
-        // or some other kind of revisit ?
611
-        $this->checkout->revisit = filter_var(
612
-            EE_Registry::instance()->REQ->get('revisit', false),
613
-            FILTER_VALIDATE_BOOLEAN
614
-        );
615
-        // and whether or not to generate a reg form for this request
616
-        $this->checkout->generate_reg_form = filter_var(
617
-            EE_Registry::instance()->REQ->get('generate_reg_form', true),
618
-            FILTER_VALIDATE_BOOLEAN
619
-        );
620
-        // and whether or not to process a reg form submission for this request
621
-        $this->checkout->process_form_submission = filter_var(
622
-            EE_Registry::instance()->REQ->get(
623
-                'process_form_submission',
624
-                $this->checkout->action === 'process_reg_step'
625
-            ),
626
-            FILTER_VALIDATE_BOOLEAN
627
-        );
628
-        $this->checkout->process_form_submission = filter_var(
629
-            $this->checkout->action !== 'display_spco_reg_step'
630
-                ? $this->checkout->process_form_submission
631
-                : false,
632
-            FILTER_VALIDATE_BOOLEAN
633
-        );
634
-        // $this->_display_request_vars();
635
-    }
636
-
637
-
638
-
639
-    /**
640
-     *  _display_request_vars
641
-     *
642
-     * @access    protected
643
-     * @return    void
644
-     */
645
-    protected function _display_request_vars()
646
-    {
647
-        if ( ! WP_DEBUG) {
648
-            return;
649
-        }
650
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
651
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
652
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
653
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
654
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
655
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
656
-        EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
657
-        EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
658
-    }
659
-
660
-
661
-
662
-    /**
663
-     * _block_bots
664
-     * checks that the incoming request has either of the following set:
665
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
666
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
667
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
668
-     * then where you coming from man?
669
-     *
670
-     * @return boolean
671
-     */
672
-    private function _block_bots()
673
-    {
674
-        $invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
675
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
676
-            return true;
677
-        }
678
-        return false;
679
-    }
680
-
681
-
682
-
683
-    /**
684
-     *    _get_first_step
685
-     *  gets slug for first step in $_reg_steps_array
686
-     *
687
-     * @access    private
688
-     * @throws EE_Error
689
-     * @return    string
690
-     */
691
-    private function _get_first_step()
692
-    {
693
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
694
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
695
-    }
696
-
697
-
698
-
699
-    /**
700
-     *    _load_and_instantiate_reg_steps
701
-     *  instantiates each reg step based on the loaded reg_steps array
702
-     *
703
-     * @access    private
704
-     * @throws EE_Error
705
-     * @return    bool
706
-     */
707
-    private function _load_and_instantiate_reg_steps()
708
-    {
709
-        // have reg_steps already been instantiated ?
710
-        if (
711
-            empty($this->checkout->reg_steps)
712
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
713
-        ) {
714
-            // if not, then loop through raw reg steps array
715
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
716
-                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
717
-                    return false;
718
-                }
719
-            }
720
-            EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
721
-            EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
722
-            // skip the registration_confirmation page ?
723
-            if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
724
-                // just remove it from the reg steps array
725
-                $this->checkout->remove_reg_step('registration_confirmation', false);
726
-            } else if (
727
-                isset($this->checkout->reg_steps['registration_confirmation'])
728
-                && EE_Registry::instance()->CFG->registration->reg_confirmation_last
729
-            ) {
730
-                // set the order to something big like 100
731
-                $this->checkout->set_reg_step_order('registration_confirmation', 100);
732
-            }
733
-            // filter the array for good luck
734
-            $this->checkout->reg_steps = apply_filters(
735
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
736
-                $this->checkout->reg_steps
737
-            );
738
-            // finally re-sort based on the reg step class order properties
739
-            $this->checkout->sort_reg_steps();
740
-        } else {
741
-            foreach ($this->checkout->reg_steps as $reg_step) {
742
-                // set all current step stati to FALSE
743
-                $reg_step->set_is_current_step(false);
744
-            }
745
-        }
746
-        if (empty($this->checkout->reg_steps)) {
747
-            EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
748
-            return false;
749
-        }
750
-        // make reg step details available to JS
751
-        $this->checkout->set_reg_step_JSON_info();
752
-        return true;
753
-    }
754
-
755
-
756
-
757
-    /**
758
-     *     _load_and_instantiate_reg_step
759
-     *
760
-     * @access    private
761
-     * @param array $reg_step
762
-     * @param int   $order
763
-     * @return bool
764
-     */
765
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
766
-    {
767
-        // we need a file_path, class_name, and slug to add a reg step
768
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
769
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
770
-            if (
771
-                $this->checkout->reg_url_link
772
-                && $this->checkout->step !== $reg_step['slug']
773
-                && $reg_step['slug'] !== 'finalize_registration'
774
-            ) {
775
-                return true;
776
-            }
777
-            // instantiate step class using file path and class name
778
-            $reg_step_obj = EE_Registry::instance()->load_file(
779
-                $reg_step['file_path'],
780
-                $reg_step['class_name'],
781
-                'class',
782
-                $this->checkout,
783
-                false
784
-            );
785
-            // did we gets the goods ?
786
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
787
-                // set reg step order based on config
788
-                $reg_step_obj->set_order($order);
789
-                // add instantiated reg step object to the master reg steps array
790
-                $this->checkout->add_reg_step($reg_step_obj);
791
-            } else {
792
-                EE_Error::add_error(
793
-                    __('The current step could not be set.', 'event_espresso'),
794
-                    __FILE__, __FUNCTION__, __LINE__
795
-                );
796
-                return false;
797
-            }
798
-        } else {
799
-            if (WP_DEBUG) {
800
-                EE_Error::add_error(
801
-                    sprintf(
802
-                        __('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'),
803
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
804
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
805
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
806
-                        '<ul>',
807
-                        '<li>',
808
-                        '</li>',
809
-                        '</ul>'
810
-                    ),
811
-                    __FILE__, __FUNCTION__, __LINE__
812
-                );
813
-            }
814
-            return false;
815
-        }
816
-        return true;
817
-    }
818
-
819
-
820
-
821
-    /**
822
-     * _verify_transaction_and_get_registrations
823
-     *
824
-     * @access private
825
-     * @return bool
826
-     */
827
-    private function _verify_transaction_and_get_registrations()
828
-    {
829
-        // was there already a valid transaction in the checkout from the session ?
830
-        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
831
-            // get transaction from db or session
832
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
833
-                ? $this->_get_transaction_and_cart_for_previous_visit()
834
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
835
-            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
836
-                EE_Error::add_error(
837
-                    __('Your Registration and Transaction information could not be retrieved from the db.',
838
-                        'event_espresso'),
839
-                    __FILE__, __FUNCTION__, __LINE__
840
-                );
841
-                $this->checkout->transaction = EE_Transaction::new_instance();
842
-                // add some style and make it dance
843
-                $this->add_styles_and_scripts();
844
-                EED_Single_Page_Checkout::$_initialized = true;
845
-                return false;
846
-            }
847
-            // and the registrations for the transaction
848
-            $this->_get_registrations($this->checkout->transaction);
849
-        }
850
-        return true;
851
-    }
852
-
853
-
854
-
855
-    /**
856
-     * _get_transaction_and_cart_for_previous_visit
857
-     *
858
-     * @access private
859
-     * @return mixed EE_Transaction|NULL
860
-     */
861
-    private function _get_transaction_and_cart_for_previous_visit()
862
-    {
863
-        /** @var $TXN_model EEM_Transaction */
864
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
865
-        // because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db
866
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
867
-        // verify transaction
868
-        if ($transaction instanceof EE_Transaction) {
869
-            // and get the cart that was used for that transaction
870
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
871
-            return $transaction;
872
-        } else {
873
-            EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
874
-            return null;
875
-        }
876
-    }
877
-
878
-
879
-
880
-    /**
881
-     * _get_cart_for_transaction
882
-     *
883
-     * @access private
884
-     * @param EE_Transaction $transaction
885
-     * @return EE_Cart
886
-     */
887
-    private function _get_cart_for_transaction($transaction)
888
-    {
889
-        return $this->checkout->get_cart_for_transaction($transaction);
890
-    }
891
-
892
-
893
-
894
-    /**
895
-     * get_cart_for_transaction
896
-     *
897
-     * @access public
898
-     * @param EE_Transaction $transaction
899
-     * @return EE_Cart
900
-     */
901
-    public function get_cart_for_transaction(EE_Transaction $transaction)
902
-    {
903
-        return $this->checkout->get_cart_for_transaction($transaction);
904
-    }
905
-
906
-
907
-
908
-    /**
909
-     * _get_transaction_and_cart_for_current_session
910
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
911
-     *
912
-     * @access private
913
-     * @return EE_Transaction
914
-     * @throws \EE_Error
915
-     */
916
-    private function _get_cart_for_current_session_and_setup_new_transaction()
917
-    {
918
-        //  if there's no transaction, then this is the FIRST visit to SPCO
919
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
920
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
921
-        // and then create a new transaction
922
-        $transaction = $this->_initialize_transaction();
923
-        // verify transaction
924
-        if ($transaction instanceof EE_Transaction) {
925
-            // save it so that we have an ID for other objects to use
926
-            $transaction->save();
927
-            // and save TXN data to the cart
928
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
929
-        } else {
930
-            EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
931
-        }
932
-        return $transaction;
933
-    }
934
-
935
-
936
-
937
-    /**
938
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
939
-     *
940
-     * @access private
941
-     * @return mixed EE_Transaction|NULL
942
-     */
943
-    private function _initialize_transaction()
944
-    {
945
-        try {
946
-            // ensure cart totals have been calculated
947
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
948
-            // grab the cart grand total
949
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
950
-            // create new TXN
951
-            $transaction = EE_Transaction::new_instance(
952
-                array(
953
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
954
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
955
-                    'TXN_paid'      => 0,
956
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
957
-                )
958
-            );
959
-            // save it so that we have an ID for other objects to use
960
-            $transaction->save();
961
-            // set cron job for following up on TXNs after their session has expired
962
-            EE_Cron_Tasks::schedule_expired_transaction_check(
963
-                EE_Registry::instance()->SSN->expiration() + 1,
964
-                $transaction->ID()
965
-            );
966
-            return $transaction;
967
-        } catch (Exception $e) {
968
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
969
-        }
970
-        return null;
971
-    }
972
-
973
-
974
-
975
-    /**
976
-     * _get_registrations
977
-     *
978
-     * @access private
979
-     * @param EE_Transaction $transaction
980
-     * @return void
981
-     * @throws \EventEspresso\core\exceptions\InvalidEntityException
982
-     * @throws \EE_Error
983
-     */
984
-    private function _get_registrations(EE_Transaction $transaction)
985
-    {
986
-        // first step: grab the registrants  { : o
987
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true);
988
-        // verify registrations have been set
989
-        if (empty($registrations)) {
990
-            // if no cached registrations, then check the db
991
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
992
-            // still nothing ? well as long as this isn't a revisit
993
-            if (empty($registrations) && ! $this->checkout->revisit) {
994
-                // generate new registrations from scratch
995
-                $registrations = $this->_initialize_registrations($transaction);
996
-            }
997
-        }
998
-        // sort by their original registration order
999
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1000
-        // then loop thru the array
1001
-        foreach ($registrations as $registration) {
1002
-            // verify each registration
1003
-            if ($registration instanceof EE_Registration) {
1004
-                // we display all attendee info for the primary registrant
1005
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
1006
-                    && $registration->is_primary_registrant()
1007
-                ) {
1008
-                    $this->checkout->primary_revisit = true;
1009
-                    break;
1010
-                } else if ($this->checkout->revisit
1011
-                           && $this->checkout->reg_url_link !== $registration->reg_url_link()
1012
-                ) {
1013
-                    // but hide info if it doesn't belong to you
1014
-                    $transaction->clear_cache('Registration', $registration->ID());
1015
-                }
1016
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1017
-            }
1018
-        }
1019
-    }
1020
-
1021
-
1022
-
1023
-    /**
1024
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1025
-     *
1026
-     * @access private
1027
-     * @param EE_Transaction $transaction
1028
-     * @return    array
1029
-     * @throws \EventEspresso\core\exceptions\InvalidEntityException
1030
-     * @throws \EE_Error
1031
-     */
1032
-    private function _initialize_registrations(EE_Transaction $transaction)
1033
-    {
1034
-        $att_nmbr = 0;
1035
-        $registrations = array();
1036
-        if ($transaction instanceof EE_Transaction) {
1037
-            /** @type EE_Registration_Processor $registration_processor */
1038
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1039
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1040
-            // now let's add the cart items to the $transaction
1041
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1042
-                //do the following for each ticket of this type they selected
1043
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1044
-                    $att_nmbr++;
1045
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1046
-                    $CreateRegistrationCommand = EE_Registry::instance()
1047
-                                                            ->create(
1048
-                                                                'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1049
-                                                                array(
1050
-                                                                    $transaction,
1051
-                                                                    $line_item,
1052
-                                                                    $att_nmbr,
1053
-                                                                    $this->checkout->total_ticket_count,
1054
-                                                                )
1055
-                                                            );
1056
-                    // override capabilities for frontend registrations
1057
-                    if ( ! is_admin()) {
1058
-                        $CreateRegistrationCommand->setCapCheck(
1059
-                            new PublicCapabilities('', 'create_new_registration')
1060
-                        );
1061
-                    }
1062
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1063
-                    if ( ! $registration instanceof EE_Registration) {
1064
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1065
-                    }
1066
-                    $registrations[ $registration->ID() ] = $registration;
1067
-                }
1068
-            }
1069
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1070
-        }
1071
-        return $registrations;
1072
-    }
1073
-
1074
-
1075
-
1076
-    /**
1077
-     * sorts registrations by REG_count
1078
-     *
1079
-     * @access public
1080
-     * @param EE_Registration $reg_A
1081
-     * @param EE_Registration $reg_B
1082
-     * @return int
1083
-     */
1084
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1085
-    {
1086
-        // this shouldn't ever happen within the same TXN, but oh well
1087
-        if ($reg_A->count() === $reg_B->count()) {
1088
-            return 0;
1089
-        }
1090
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1091
-    }
1092
-
1093
-
1094
-
1095
-    /**
1096
-     *    _final_verifications
1097
-     * just makes sure that everything is set up correctly before proceeding
1098
-     *
1099
-     * @access    private
1100
-     * @return    bool
1101
-     * @throws \EE_Error
1102
-     */
1103
-    private function _final_verifications()
1104
-    {
1105
-        // filter checkout
1106
-        $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout);
1107
-        //verify that current step is still set correctly
1108
-        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1109
-            EE_Error::add_error(
1110
-                __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'),
1111
-                __FILE__,
1112
-                __FUNCTION__,
1113
-                __LINE__
1114
-            );
1115
-            return false;
1116
-        }
1117
-        // if returning to SPCO, then verify that primary registrant is set
1118
-        if ( ! empty($this->checkout->reg_url_link)) {
1119
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1120
-            if ( ! $valid_registrant instanceof EE_Registration) {
1121
-                EE_Error::add_error(
1122
-                    __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'),
1123
-                    __FILE__,
1124
-                    __FUNCTION__,
1125
-                    __LINE__
1126
-                );
1127
-                return false;
1128
-            }
1129
-            $valid_registrant = null;
1130
-            foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1131
-                if (
1132
-                    $registration instanceof EE_Registration
1133
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1134
-                ) {
1135
-                    $valid_registrant = $registration;
1136
-                }
1137
-            }
1138
-            if ( ! $valid_registrant instanceof EE_Registration) {
1139
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1140
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1141
-                    // clear the session, mark the checkout as unverified, and try again
1142
-                    EE_Registry::instance()->SSN->clear_session();
1143
-                    EED_Single_Page_Checkout::$_initialized = false;
1144
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1145
-                    $this->_initialize();
1146
-                    EE_Error::reset_notices();
1147
-                    return false;
1148
-                }
1149
-                EE_Error::add_error(
1150
-                    __('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'),
1151
-                    __FILE__,
1152
-                    __FUNCTION__,
1153
-                    __LINE__
1154
-                );
1155
-                return false;
1156
-            }
1157
-        }
1158
-        // now that things have been kinda sufficiently verified,
1159
-        // let's add the checkout to the session so that's available other systems
1160
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1161
-        return true;
1162
-    }
1163
-
1164
-
1165
-
1166
-    /**
1167
-     *    _initialize_reg_steps
1168
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1169
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1170
-     *
1171
-     * @access    private
1172
-     * @param bool $reinitializing
1173
-     * @throws \EE_Error
1174
-     */
1175
-    private function _initialize_reg_steps($reinitializing = false)
1176
-    {
1177
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1178
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1179
-        foreach ($this->checkout->reg_steps as $reg_step) {
1180
-            if ( ! $reg_step->initialize_reg_step()) {
1181
-                // if not initialized then maybe this step is being removed...
1182
-                if ( ! $reinitializing && $reg_step->is_current_step()) {
1183
-                    // if it was the current step, then we need to start over here
1184
-                    $this->_initialize_reg_steps(true);
1185
-                    return;
1186
-                }
1187
-                continue;
1188
-            }
1189
-            // add css and JS for current step
1190
-            $reg_step->enqueue_styles_and_scripts();
1191
-            // i18n
1192
-            $reg_step->translate_js_strings();
1193
-            if ($reg_step->is_current_step()) {
1194
-                // the text that appears on the reg step form submit button
1195
-                $reg_step->set_submit_button_text();
1196
-            }
1197
-        }
1198
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1199
-        do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step);
1200
-    }
1201
-
1202
-
1203
-
1204
-    /**
1205
-     * _check_form_submission
1206
-     *
1207
-     * @access private
1208
-     * @return boolean
1209
-     */
1210
-    private function _check_form_submission()
1211
-    {
1212
-        //does this request require the reg form to be generated ?
1213
-        if ($this->checkout->generate_reg_form) {
1214
-            // ever heard that song by Blue Rodeo ?
1215
-            try {
1216
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1217
-                // if not displaying a form, then check for form submission
1218
-                if (
1219
-                    $this->checkout->process_form_submission
1220
-                    && $this->checkout->current_step->reg_form->was_submitted()
1221
-                ) {
1222
-                    // clear out any old data in case this step is being run again
1223
-                    $this->checkout->current_step->set_valid_data(array());
1224
-                    // capture submitted form data
1225
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1226
-                        apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout)
1227
-                    );
1228
-                    // validate submitted form data
1229
-                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1230
-                        // thou shall not pass !!!
1231
-                        $this->checkout->continue_reg = false;
1232
-                        // any form validation errors?
1233
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1234
-                            $submission_error_messages = array();
1235
-                            // bad, bad, bad registrant
1236
-                            foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) {
1237
-                                if ($validation_error instanceof EE_Validation_Error) {
1238
-                                    $submission_error_messages[] = sprintf(
1239
-                                        __('%s : %s', 'event_espresso'),
1240
-                                        $validation_error->get_form_section()->html_label_text(),
1241
-                                        $validation_error->getMessage()
1242
-                                    );
1243
-                                }
1244
-                            }
1245
-                            EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__);
1246
-                        }
1247
-                        // well not really... what will happen is we'll just get redirected back to redo the current step
1248
-                        $this->go_to_next_step();
1249
-                        return false;
1250
-                    }
1251
-                }
1252
-            } catch (EE_Error $e) {
1253
-                $e->get_error();
1254
-            }
1255
-        }
1256
-        return true;
1257
-    }
1258
-
1259
-
1260
-
1261
-    /**
1262
-     * _process_action
1263
-     *
1264
-     * @access private
1265
-     * @return void
1266
-     * @throws \EE_Error
1267
-     */
1268
-    private function _process_form_action()
1269
-    {
1270
-        // what cha wanna do?
1271
-        switch ($this->checkout->action) {
1272
-            // AJAX next step reg form
1273
-            case 'display_spco_reg_step' :
1274
-                $this->checkout->redirect = false;
1275
-                if (EE_Registry::instance()->REQ->ajax) {
1276
-                    $this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form());
1277
-                }
1278
-                break;
1279
-            default :
1280
-                // meh... do one of those other steps first
1281
-                if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) {
1282
-                    // dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1283
-                    do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step);
1284
-                    // call action on current step
1285
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1286
-                        // good registrant, you get to proceed
1287
-                        if (
1288
-                            $this->checkout->current_step->success_message() !== ''
1289
-                            && apply_filters(
1290
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1291
-                                false
1292
-                            )
1293
-                        ) {
1294
-                            EE_Error::add_success(
1295
-                                $this->checkout->current_step->success_message()
1296
-                                . '<br />' . $this->checkout->next_step->_instructions()
1297
-                            );
1298
-                        }
1299
-                        // pack it up, pack it in...
1300
-                        $this->_setup_redirect();
1301
-                    }
1302
-                    // dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1303
-                    do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step);
1304
-                } else {
1305
-                    EE_Error::add_error(
1306
-                        sprintf(
1307
-                            __('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'),
1308
-                            $this->checkout->action,
1309
-                            $this->checkout->current_step->name()
1310
-                        ),
1311
-                        __FILE__,
1312
-                        __FUNCTION__,
1313
-                        __LINE__
1314
-                    );
1315
-                }
1316
-            // end default
1317
-        }
1318
-        // store our progress so far
1319
-        $this->checkout->stash_transaction_and_checkout();
1320
-        // advance to the next step! If you pass GO, collect $200
1321
-        $this->go_to_next_step();
1322
-    }
1323
-
1324
-
1325
-
1326
-    /**
1327
-     *        add_styles_and_scripts
1328
-     *
1329
-     * @access        public
1330
-     * @return        void
1331
-     */
1332
-    public function add_styles_and_scripts()
1333
-    {
1334
-        // i18n
1335
-        $this->translate_js_strings();
1336
-        if ($this->checkout->admin_request) {
1337
-            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1338
-        } else {
1339
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1340
-        }
1341
-    }
1342
-
1343
-
1344
-
1345
-    /**
1346
-     *        translate_js_strings
1347
-     *
1348
-     * @access        public
1349
-     * @return        void
1350
-     */
1351
-    public function translate_js_strings()
1352
-    {
1353
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1354
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1355
-        EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso');
1356
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso');
1357
-        EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso');
1358
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso');
1359
-        EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso');
1360
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso');
1361
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1362
-            __('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'),
1363
-            '<br/>',
1364
-            '<br/>'
1365
-        );
1366
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1367
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1368
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1369
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1370
-        EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1371
-        EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1372
-        EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1373
-        EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1374
-        EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1375
-        EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1376
-        EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1377
-        EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1378
-        EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1379
-        EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1380
-        EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1381
-        EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1382
-        EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1383
-        EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1384
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1385
-            __(
1386
-                '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
1387
-                'event_espresso'
1388
-            ),
1389
-            '<h4 class="important-notice">',
1390
-            '</h4>',
1391
-            '<br />',
1392
-            '<p>',
1393
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1394
-            '">',
1395
-            '</a>',
1396
-            '</p>'
1397
-        );
1398
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true);
1399
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1400
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1401
-        );
1402
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1403
-            'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1404
-        );
1405
-    }
1406
-
1407
-
1408
-
1409
-    /**
1410
-     *    enqueue_styles_and_scripts
1411
-     *
1412
-     * @access        public
1413
-     * @return        void
1414
-     * @throws \EE_Error
1415
-     */
1416
-    public function enqueue_styles_and_scripts()
1417
-    {
1418
-        // load css
1419
-        wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION);
1420
-        wp_enqueue_style('single_page_checkout');
1421
-        // load JS
1422
-        wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js', array('jquery'), '1.0.1', true);
1423
-        wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js', array('jquery_plugin'), '2.0.2', true);
1424
-        wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true);
1425
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1426
-            $this->checkout->registration_form->enqueue_js();
1427
-        }
1428
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1429
-            $this->checkout->current_step->reg_form->enqueue_js();
1430
-        }
1431
-        wp_enqueue_script('single_page_checkout');
1432
-        /**
1433
-         * global action hook for enqueueing styles and scripts with
1434
-         * spco calls.
1435
-         */
1436
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1437
-        /**
1438
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1439
-         * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1440
-         */
1441
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this);
1442
-    }
1443
-
1444
-
1445
-
1446
-    /**
1447
-     *    display the Registration Single Page Checkout Form
1448
-     *
1449
-     * @access    private
1450
-     * @return    void
1451
-     * @throws \EE_Error
1452
-     */
1453
-    private function _display_spco_reg_form()
1454
-    {
1455
-        // if registering via the admin, just display the reg form for the current step
1456
-        if ($this->checkout->admin_request) {
1457
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1458
-        } else {
1459
-            // add powered by EE msg
1460
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1461
-            $empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1
1462
-                ? true
1463
-                : false;
1464
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1465
-            $cookies_not_set_msg = '';
1466
-            if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) {
1467
-                $cookies_not_set_msg = apply_filters(
1468
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1469
-                    sprintf(
1470
-                        __(
1471
-                            '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1472
-                            'event_espresso'
1473
-                        ),
1474
-                        '<div class="ee-attention">',
1475
-                        '</div>',
1476
-                        '<h6 class="important-notice">',
1477
-                        '</h6>',
1478
-                        '<p>',
1479
-                        '</p>',
1480
-                        '<br />',
1481
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1482
-                        '</a>'
1483
-                    )
1484
-                );
1485
-            }
1486
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1487
-                array(
1488
-                    'name'            => 'single-page-checkout',
1489
-                    'html_id'         => 'ee-single-page-checkout-dv',
1490
-                    'layout_strategy' =>
1491
-                        new EE_Template_Layout(
1492
-                            array(
1493
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1494
-                                'template_args'        => array(
1495
-                                    'empty_cart'              => $empty_cart,
1496
-                                    'revisit'                 => $this->checkout->revisit,
1497
-                                    'reg_steps'               => $this->checkout->reg_steps,
1498
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1499
-                                        ? $this->checkout->next_step->slug()
1500
-                                        : '',
1501
-                                    'cancel_page_url'         => $this->checkout->cancel_page_url,
1502
-                                    'empty_msg'               => apply_filters(
1503
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1504
-                                        sprintf(
1505
-                                            __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1506
-                                                'event_espresso'),
1507
-                                            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1508
-                                            '">',
1509
-                                            '</a>'
1510
-                                        )
1511
-                                    ),
1512
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1513
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1514
-                                    'session_expiration'      =>
1515
-                                        date('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)),
1516
-                                ),
1517
-                            )
1518
-                        ),
1519
-                )
1520
-            );
1521
-            // load template and add to output sent that gets filtered into the_content()
1522
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1523
-        }
1524
-    }
1525
-
1526
-
1527
-
1528
-    /**
1529
-     *    add_extra_finalize_registration_inputs
1530
-     *
1531
-     * @access    public
1532
-     * @param $next_step
1533
-     * @internal  param string $label
1534
-     * @return void
1535
-     */
1536
-    public function add_extra_finalize_registration_inputs($next_step)
1537
-    {
1538
-        if ($next_step === 'finalize_registration') {
1539
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1540
-        }
1541
-    }
1542
-
1543
-
1544
-
1545
-    /**
1546
-     *    display_registration_footer
1547
-     *
1548
-     * @access    public
1549
-     * @return    string
1550
-     */
1551
-    public static function display_registration_footer()
1552
-    {
1553
-        if (
1554
-        apply_filters(
1555
-            'FHEE__EE_Front__Controller__show_reg_footer',
1556
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1557
-        )
1558
-        ) {
1559
-            add_filter(
1560
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1561
-                function ($url) {
1562
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1563
-                }
1564
-            );
1565
-            echo apply_filters(
1566
-                'FHEE__EE_Front_Controller__display_registration_footer',
1567
-                \EEH_Template::powered_by_event_espresso(
1568
-                    '',
1569
-                    'espresso-registration-footer-dv',
1570
-                    array('utm_content' => 'registration_checkout')
1571
-                )
1572
-            );
1573
-        }
1574
-        return '';
1575
-    }
1576
-
1577
-
1578
-
1579
-    /**
1580
-     *    unlock_transaction
1581
-     *
1582
-     * @access    public
1583
-     * @return    void
1584
-     * @throws \EE_Error
1585
-     */
1586
-    public function unlock_transaction()
1587
-    {
1588
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1589
-            $this->checkout->transaction->unlock();
1590
-        }
1591
-    }
1592
-
1593
-
1594
-
1595
-    /**
1596
-     *        _setup_redirect
1597
-     *
1598
-     * @access    private
1599
-     * @return void
1600
-     */
1601
-    private function _setup_redirect()
1602
-    {
1603
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1604
-            $this->checkout->redirect = true;
1605
-            if (empty($this->checkout->redirect_url)) {
1606
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1607
-            }
1608
-            $this->checkout->redirect_url = apply_filters(
1609
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1610
-                $this->checkout->redirect_url,
1611
-                $this->checkout
1612
-            );
1613
-        }
1614
-    }
1615
-
1616
-
1617
-
1618
-    /**
1619
-     *   handle ajax message responses and redirects
1620
-     *
1621
-     * @access public
1622
-     * @return void
1623
-     * @throws \EE_Error
1624
-     */
1625
-    public function go_to_next_step()
1626
-    {
1627
-        if (EE_Registry::instance()->REQ->ajax) {
1628
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1629
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1630
-        }
1631
-        $this->unlock_transaction();
1632
-        // just return for these conditions
1633
-        if (
1634
-            $this->checkout->admin_request
1635
-            || $this->checkout->action === 'redirect_form'
1636
-            || $this->checkout->action === 'update_checkout'
1637
-        ) {
1638
-            return;
1639
-        }
1640
-        // AJAX response
1641
-        $this->_handle_json_response();
1642
-        // redirect to next step or the Thank You page
1643
-        $this->_handle_html_redirects();
1644
-        // hmmm... must be something wrong, so let's just display the form again !
1645
-        $this->_display_spco_reg_form();
1646
-    }
1647
-
1648
-
1649
-
1650
-    /**
1651
-     *   _handle_json_response
1652
-     *
1653
-     * @access protected
1654
-     * @return void
1655
-     */
1656
-    protected function _handle_json_response()
1657
-    {
1658
-        // if this is an ajax request
1659
-        if (EE_Registry::instance()->REQ->ajax) {
1660
-            // DEBUG LOG
1661
-            //$this->checkout->log(
1662
-            //	__CLASS__, __FUNCTION__, __LINE__,
1663
-            //	array(
1664
-            //		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1665
-            //		'redirect'                   => $this->checkout->redirect,
1666
-            //		'continue_reg'               => $this->checkout->continue_reg,
1667
-            //	)
1668
-            //);
1669
-            $this->checkout->json_response->set_registration_time_limit(
1670
-                $this->checkout->get_registration_time_limit()
1671
-            );
1672
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1673
-            // just send the ajax (
1674
-            $json_response = apply_filters(
1675
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1676
-                $this->checkout->json_response
1677
-            );
1678
-            echo $json_response;
1679
-            exit();
1680
-        }
1681
-    }
1682
-
1683
-
1684
-
1685
-    /**
1686
-     *   _handle_redirects
1687
-     *
1688
-     * @access protected
1689
-     * @return void
1690
-     */
1691
-    protected function _handle_html_redirects()
1692
-    {
1693
-        // going somewhere ?
1694
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1695
-            // store notices in a transient
1696
-            EE_Error::get_notices(false, true, true);
1697
-            // DEBUG LOG
1698
-            //$this->checkout->log(
1699
-            //	__CLASS__, __FUNCTION__, __LINE__,
1700
-            //	array(
1701
-            //		'headers_sent' => headers_sent(),
1702
-            //		'redirect_url'     => $this->checkout->redirect_url,
1703
-            //		'headers_list'    => headers_list(),
1704
-            //	)
1705
-            //);
1706
-            wp_safe_redirect($this->checkout->redirect_url);
1707
-            exit();
1708
-        }
1709
-    }
1710
-
1711
-
1712
-
1713
-    /**
1714
-     *   set_checkout_anchor
1715
-     *
1716
-     * @access public
1717
-     * @return void
1718
-     */
1719
-    public function set_checkout_anchor()
1720
-    {
1721
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1722
-    }
20
+	/**
21
+	 * $_initialized - has the SPCO controller already been initialized ?
22
+	 *
23
+	 * @access private
24
+	 * @var bool $_initialized
25
+	 */
26
+	private static $_initialized = false;
27
+
28
+
29
+	/**
30
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
31
+	 *
32
+	 * @access private
33
+	 * @var bool $_valid_checkout
34
+	 */
35
+	private static $_checkout_verified = true;
36
+
37
+	/**
38
+	 *    $_reg_steps_array - holds initial array of reg steps
39
+	 *
40
+	 * @access private
41
+	 * @var array $_reg_steps_array
42
+	 */
43
+	private static $_reg_steps_array = array();
44
+
45
+	/**
46
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
47
+	 *
48
+	 * @access public
49
+	 * @var EE_Checkout $checkout
50
+	 */
51
+	public $checkout;
52
+
53
+
54
+
55
+	/**
56
+	 * @return EED_Single_Page_Checkout
57
+	 */
58
+	public static function instance()
59
+	{
60
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
61
+		return parent::get_instance(__CLASS__);
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * @return EE_CART
68
+	 */
69
+	public function cart()
70
+	{
71
+		return $this->checkout->cart;
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * @return EE_Transaction
78
+	 */
79
+	public function transaction()
80
+	{
81
+		return $this->checkout->transaction;
82
+	}
83
+
84
+
85
+
86
+	/**
87
+	 *    set_hooks - for hooking into EE Core, other modules, etc
88
+	 *
89
+	 * @access    public
90
+	 * @return    void
91
+	 * @throws \EE_Error
92
+	 */
93
+	public static function set_hooks()
94
+	{
95
+		EED_Single_Page_Checkout::set_definitions();
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
102
+	 *
103
+	 * @access    public
104
+	 * @return    void
105
+	 * @throws \EE_Error
106
+	 */
107
+	public static function set_hooks_admin()
108
+	{
109
+		EED_Single_Page_Checkout::set_definitions();
110
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
111
+			// hook into the top of pre_get_posts to set the reg step routing, which gives other modules or plugins a chance to modify the reg steps, but just before the routes get called
112
+			add_action('pre_get_posts', array('EED_Single_Page_Checkout', 'load_reg_steps'), 1);
113
+			return;
114
+		}
115
+		// going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response
116
+		ob_start();
117
+		EED_Single_Page_Checkout::load_request_handler();
118
+		EED_Single_Page_Checkout::load_reg_steps();
119
+		// set ajax hooks
120
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
121
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
122
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
123
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
124
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
125
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 *    process ajax request
132
+	 *
133
+	 * @param string $ajax_action
134
+	 * @throws \EE_Error
135
+	 */
136
+	public static function process_ajax_request($ajax_action)
137
+	{
138
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
139
+		EED_Single_Page_Checkout::instance()->_initialize();
140
+	}
141
+
142
+
143
+
144
+	/**
145
+	 *    ajax display registration step
146
+	 *
147
+	 * @throws \EE_Error
148
+	 */
149
+	public static function display_reg_step()
150
+	{
151
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 *    ajax process registration step
158
+	 *
159
+	 * @throws \EE_Error
160
+	 */
161
+	public static function process_reg_step()
162
+	{
163
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 *    ajax process registration step
170
+	 *
171
+	 * @throws \EE_Error
172
+	 */
173
+	public static function update_reg_step()
174
+	{
175
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
176
+	}
177
+
178
+
179
+
180
+	/**
181
+	 *   update_checkout
182
+	 *
183
+	 * @access public
184
+	 * @return void
185
+	 * @throws \EE_Error
186
+	 */
187
+	public static function update_checkout()
188
+	{
189
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
190
+	}
191
+
192
+
193
+
194
+	/**
195
+	 *    load_request_handler
196
+	 *
197
+	 * @access    public
198
+	 * @return    void
199
+	 */
200
+	public static function load_request_handler()
201
+	{
202
+		// load core Request_Handler class
203
+		if ( ! isset(EE_Registry::instance()->REQ)) {
204
+			EE_Registry::instance()->load_core('Request_Handler');
205
+		}
206
+	}
207
+
208
+
209
+
210
+	/**
211
+	 *    set_definitions
212
+	 *
213
+	 * @access    public
214
+	 * @return    void
215
+	 * @throws \EE_Error
216
+	 */
217
+	public static function set_definitions()
218
+	{
219
+		define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS);
220
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
221
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
222
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
223
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
224
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
225
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
226
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
227
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
228
+			__('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
229
+				'event_espresso'),
230
+			'<h4 class="important-notice">',
231
+			'</h4>',
232
+			'<br />',
233
+			'<p>',
234
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
235
+			'">',
236
+			'</a>',
237
+			'</p>'
238
+		);
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * load_reg_steps
245
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
246
+	 *
247
+	 * @access    private
248
+	 * @throws EE_Error
249
+	 * @return void
250
+	 */
251
+	public static function load_reg_steps()
252
+	{
253
+		static $reg_steps_loaded = false;
254
+		if ($reg_steps_loaded) {
255
+			return;
256
+		}
257
+		// filter list of reg_steps
258
+		$reg_steps_to_load = (array)apply_filters(
259
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
260
+			EED_Single_Page_Checkout::get_reg_steps()
261
+		);
262
+		// sort by key (order)
263
+		ksort($reg_steps_to_load);
264
+		// loop through folders
265
+		foreach ($reg_steps_to_load as $order => $reg_step) {
266
+			// we need a
267
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
268
+				// copy over to the reg_steps_array
269
+				EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
270
+				// register custom key route for each reg step
271
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
272
+				EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step');
273
+				// add AJAX or other hooks
274
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
275
+					// setup autoloaders if necessary
276
+					if ( ! class_exists($reg_step['class_name'])) {
277
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], true);
278
+					}
279
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
280
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
281
+					}
282
+				}
283
+			}
284
+		}
285
+		$reg_steps_loaded = true;
286
+	}
287
+
288
+
289
+
290
+	/**
291
+	 *    get_reg_steps
292
+	 *
293
+	 * @access    public
294
+	 * @return    array
295
+	 */
296
+	public static function get_reg_steps()
297
+	{
298
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
299
+		if (empty($reg_steps)) {
300
+			$reg_steps = array(
301
+				10  => array(
302
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
303
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
304
+					'slug'       => 'attendee_information',
305
+					'has_hooks'  => false,
306
+				),
307
+				20  => array(
308
+					'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
309
+					'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
310
+					'slug'       => 'registration_confirmation',
311
+					'has_hooks'  => false,
312
+				),
313
+				30  => array(
314
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
315
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
316
+					'slug'       => 'payment_options',
317
+					'has_hooks'  => true,
318
+				),
319
+				999 => array(
320
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
321
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
322
+					'slug'       => 'finalize_registration',
323
+					'has_hooks'  => false,
324
+				),
325
+			);
326
+		}
327
+		return $reg_steps;
328
+	}
329
+
330
+
331
+
332
+	/**
333
+	 *    registration_checkout_for_admin
334
+	 *
335
+	 * @access    public
336
+	 * @return    string
337
+	 * @throws \EE_Error
338
+	 */
339
+	public static function registration_checkout_for_admin()
340
+	{
341
+		EED_Single_Page_Checkout::load_reg_steps();
342
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
343
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
344
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
345
+		EED_Single_Page_Checkout::instance()->_initialize();
346
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
347
+		return EE_Registry::instance()->REQ->get_output();
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * process_registration_from_admin
354
+	 *
355
+	 * @access public
356
+	 * @return \EE_Transaction
357
+	 * @throws \EE_Error
358
+	 */
359
+	public static function process_registration_from_admin()
360
+	{
361
+		EED_Single_Page_Checkout::load_reg_steps();
362
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
363
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
364
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
365
+		EED_Single_Page_Checkout::instance()->_initialize();
366
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
367
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
368
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
369
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
370
+				if ($final_reg_step->process_reg_step()) {
371
+					$final_reg_step->set_completed();
372
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
373
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
374
+				}
375
+			}
376
+		}
377
+		return null;
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 *    run
384
+	 *
385
+	 * @access    public
386
+	 * @param WP_Query $WP_Query
387
+	 * @return    void
388
+	 * @throws \EE_Error
389
+	 */
390
+	public function run($WP_Query)
391
+	{
392
+		if (
393
+			$WP_Query instanceof WP_Query
394
+			&& $WP_Query->is_main_query()
395
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
396
+			&& $this->_is_reg_checkout()
397
+		) {
398
+			$this->_initialize();
399
+		}
400
+	}
401
+
402
+
403
+
404
+	/**
405
+	 * determines whether current url matches reg page url
406
+	 *
407
+	 * @return bool
408
+	 */
409
+	protected function _is_reg_checkout()
410
+	{
411
+		// get current permalink for reg page without any extra query args
412
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
413
+		// get request URI for current request, but without the scheme or host
414
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
415
+		$current_request_uri = html_entity_decode($current_request_uri);
416
+		// get array of query args from the current request URI
417
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
418
+		// grab page id if it is set
419
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
420
+		// and remove the page id from the query args (we will re-add it later)
421
+		unset($query_args['page_id']);
422
+		// now strip all query args from current request URI
423
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
424
+		// and re-add the page id if it was set
425
+		if ($page_id) {
426
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
427
+		}
428
+		// remove slashes and ?
429
+		$current_request_uri = trim($current_request_uri, '?/');
430
+		// is current request URI part of the known full reg page URL ?
431
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
432
+	}
433
+
434
+
435
+
436
+	/**
437
+	 *    run
438
+	 *
439
+	 * @access    public
440
+	 * @param WP_Query $WP_Query
441
+	 * @return    void
442
+	 * @throws \EE_Error
443
+	 */
444
+	public static function init($WP_Query)
445
+	{
446
+		EED_Single_Page_Checkout::instance()->run($WP_Query);
447
+	}
448
+
449
+
450
+
451
+	/**
452
+	 *    _initialize - initial module setup
453
+	 *
454
+	 * @access    private
455
+	 * @throws EE_Error
456
+	 * @return    void
457
+	 */
458
+	private function _initialize()
459
+	{
460
+		// ensure SPCO doesn't run twice
461
+		if (EED_Single_Page_Checkout::$_initialized) {
462
+			return;
463
+		}
464
+		try {
465
+			$this->_verify_session();
466
+			// setup the EE_Checkout object
467
+			$this->checkout = $this->_initialize_checkout();
468
+			// filter checkout
469
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
470
+			// get the $_GET
471
+			$this->_get_request_vars();
472
+			if ($this->_block_bots()) {
473
+				return;
474
+			}
475
+			// filter continue_reg
476
+			$this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', true, $this->checkout);
477
+			// load the reg steps array
478
+			if ( ! $this->_load_and_instantiate_reg_steps()) {
479
+				EED_Single_Page_Checkout::$_initialized = true;
480
+				return;
481
+			}
482
+			// set the current step
483
+			$this->checkout->set_current_step($this->checkout->step);
484
+			// and the next step
485
+			$this->checkout->set_next_step();
486
+			// verify that everything has been setup correctly
487
+			if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
488
+				EED_Single_Page_Checkout::$_initialized = true;
489
+				return;
490
+			}
491
+			// lock the transaction
492
+			$this->checkout->transaction->lock();
493
+			// make sure all of our cached objects are added to their respective model entity mappers
494
+			$this->checkout->refresh_all_entities();
495
+			// set amount owing
496
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
497
+			// initialize each reg step, which gives them the chance to potentially alter the process
498
+			$this->_initialize_reg_steps();
499
+			// DEBUG LOG
500
+			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
501
+			// get reg form
502
+			if( ! $this->_check_form_submission()) {
503
+				EED_Single_Page_Checkout::$_initialized = true;
504
+				return;
505
+			}
506
+			// checkout the action!!!
507
+			$this->_process_form_action();
508
+			// add some style and make it dance
509
+			$this->add_styles_and_scripts();
510
+			// kk... SPCO has successfully run
511
+			EED_Single_Page_Checkout::$_initialized = true;
512
+			// set no cache headers and constants
513
+			EE_System::do_not_cache();
514
+			// add anchor
515
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
516
+			// remove transaction lock
517
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
518
+		} catch (Exception $e) {
519
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
520
+		}
521
+	}
522
+
523
+
524
+
525
+	/**
526
+	 *    _verify_session
527
+	 * checks that the session is valid and not expired
528
+	 *
529
+	 * @access    private
530
+	 * @throws EE_Error
531
+	 */
532
+	private function _verify_session()
533
+	{
534
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
535
+			throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
536
+		}
537
+		// is session still valid ?
538
+		if (EE_Registry::instance()->SSN->expired() && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '') {
539
+			$this->checkout = new EE_Checkout();
540
+			EE_Registry::instance()->SSN->reset_cart();
541
+			EE_Registry::instance()->SSN->reset_checkout();
542
+			EE_Registry::instance()->SSN->reset_transaction();
543
+			EE_Error::add_attention(EE_Registry::$i18n_js_strings['registration_expiration_notice'], __FILE__,
544
+				__FUNCTION__, __LINE__);
545
+			EE_Registry::instance()->SSN->reset_expired();
546
+		}
547
+	}
548
+
549
+
550
+
551
+	/**
552
+	 *    _initialize_checkout
553
+	 * loads and instantiates EE_Checkout
554
+	 *
555
+	 * @access    private
556
+	 * @throws EE_Error
557
+	 * @return EE_Checkout
558
+	 */
559
+	private function _initialize_checkout()
560
+	{
561
+		// look in session for existing checkout
562
+		/** @type EE_Checkout $checkout */
563
+		$checkout = EE_Registry::instance()->SSN->checkout();
564
+		// verify
565
+		if ( ! $checkout instanceof EE_Checkout) {
566
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
567
+			$checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), false);
568
+		} else {
569
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
570
+				$this->unlock_transaction();
571
+				wp_safe_redirect($checkout->redirect_url);
572
+				exit();
573
+			}
574
+		}
575
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
576
+		// verify again
577
+		if ( ! $checkout instanceof EE_Checkout) {
578
+			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
579
+		}
580
+		// reset anything that needs a clean slate for each request
581
+		$checkout->reset_for_current_request();
582
+		return $checkout;
583
+	}
584
+
585
+
586
+
587
+	/**
588
+	 *    _get_request_vars
589
+	 *
590
+	 * @access    private
591
+	 * @return    void
592
+	 * @throws \EE_Error
593
+	 */
594
+	private function _get_request_vars()
595
+	{
596
+		// load classes
597
+		EED_Single_Page_Checkout::load_request_handler();
598
+		//make sure this request is marked as belonging to EE
599
+		EE_Registry::instance()->REQ->set_espresso_page(true);
600
+		// which step is being requested ?
601
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
602
+		// which step is being edited ?
603
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
604
+		// and what we're doing on the current step
605
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
606
+		// timestamp
607
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
608
+		// returning to edit ?
609
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
610
+		// or some other kind of revisit ?
611
+		$this->checkout->revisit = filter_var(
612
+			EE_Registry::instance()->REQ->get('revisit', false),
613
+			FILTER_VALIDATE_BOOLEAN
614
+		);
615
+		// and whether or not to generate a reg form for this request
616
+		$this->checkout->generate_reg_form = filter_var(
617
+			EE_Registry::instance()->REQ->get('generate_reg_form', true),
618
+			FILTER_VALIDATE_BOOLEAN
619
+		);
620
+		// and whether or not to process a reg form submission for this request
621
+		$this->checkout->process_form_submission = filter_var(
622
+			EE_Registry::instance()->REQ->get(
623
+				'process_form_submission',
624
+				$this->checkout->action === 'process_reg_step'
625
+			),
626
+			FILTER_VALIDATE_BOOLEAN
627
+		);
628
+		$this->checkout->process_form_submission = filter_var(
629
+			$this->checkout->action !== 'display_spco_reg_step'
630
+				? $this->checkout->process_form_submission
631
+				: false,
632
+			FILTER_VALIDATE_BOOLEAN
633
+		);
634
+		// $this->_display_request_vars();
635
+	}
636
+
637
+
638
+
639
+	/**
640
+	 *  _display_request_vars
641
+	 *
642
+	 * @access    protected
643
+	 * @return    void
644
+	 */
645
+	protected function _display_request_vars()
646
+	{
647
+		if ( ! WP_DEBUG) {
648
+			return;
649
+		}
650
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
651
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
652
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
653
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
654
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
655
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
656
+		EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
657
+		EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
658
+	}
659
+
660
+
661
+
662
+	/**
663
+	 * _block_bots
664
+	 * checks that the incoming request has either of the following set:
665
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
666
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
667
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
668
+	 * then where you coming from man?
669
+	 *
670
+	 * @return boolean
671
+	 */
672
+	private function _block_bots()
673
+	{
674
+		$invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
675
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
676
+			return true;
677
+		}
678
+		return false;
679
+	}
680
+
681
+
682
+
683
+	/**
684
+	 *    _get_first_step
685
+	 *  gets slug for first step in $_reg_steps_array
686
+	 *
687
+	 * @access    private
688
+	 * @throws EE_Error
689
+	 * @return    string
690
+	 */
691
+	private function _get_first_step()
692
+	{
693
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
694
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
695
+	}
696
+
697
+
698
+
699
+	/**
700
+	 *    _load_and_instantiate_reg_steps
701
+	 *  instantiates each reg step based on the loaded reg_steps array
702
+	 *
703
+	 * @access    private
704
+	 * @throws EE_Error
705
+	 * @return    bool
706
+	 */
707
+	private function _load_and_instantiate_reg_steps()
708
+	{
709
+		// have reg_steps already been instantiated ?
710
+		if (
711
+			empty($this->checkout->reg_steps)
712
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
713
+		) {
714
+			// if not, then loop through raw reg steps array
715
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
716
+				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
717
+					return false;
718
+				}
719
+			}
720
+			EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
721
+			EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
722
+			// skip the registration_confirmation page ?
723
+			if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
724
+				// just remove it from the reg steps array
725
+				$this->checkout->remove_reg_step('registration_confirmation', false);
726
+			} else if (
727
+				isset($this->checkout->reg_steps['registration_confirmation'])
728
+				&& EE_Registry::instance()->CFG->registration->reg_confirmation_last
729
+			) {
730
+				// set the order to something big like 100
731
+				$this->checkout->set_reg_step_order('registration_confirmation', 100);
732
+			}
733
+			// filter the array for good luck
734
+			$this->checkout->reg_steps = apply_filters(
735
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
736
+				$this->checkout->reg_steps
737
+			);
738
+			// finally re-sort based on the reg step class order properties
739
+			$this->checkout->sort_reg_steps();
740
+		} else {
741
+			foreach ($this->checkout->reg_steps as $reg_step) {
742
+				// set all current step stati to FALSE
743
+				$reg_step->set_is_current_step(false);
744
+			}
745
+		}
746
+		if (empty($this->checkout->reg_steps)) {
747
+			EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
748
+			return false;
749
+		}
750
+		// make reg step details available to JS
751
+		$this->checkout->set_reg_step_JSON_info();
752
+		return true;
753
+	}
754
+
755
+
756
+
757
+	/**
758
+	 *     _load_and_instantiate_reg_step
759
+	 *
760
+	 * @access    private
761
+	 * @param array $reg_step
762
+	 * @param int   $order
763
+	 * @return bool
764
+	 */
765
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
766
+	{
767
+		// we need a file_path, class_name, and slug to add a reg step
768
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
769
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
770
+			if (
771
+				$this->checkout->reg_url_link
772
+				&& $this->checkout->step !== $reg_step['slug']
773
+				&& $reg_step['slug'] !== 'finalize_registration'
774
+			) {
775
+				return true;
776
+			}
777
+			// instantiate step class using file path and class name
778
+			$reg_step_obj = EE_Registry::instance()->load_file(
779
+				$reg_step['file_path'],
780
+				$reg_step['class_name'],
781
+				'class',
782
+				$this->checkout,
783
+				false
784
+			);
785
+			// did we gets the goods ?
786
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
787
+				// set reg step order based on config
788
+				$reg_step_obj->set_order($order);
789
+				// add instantiated reg step object to the master reg steps array
790
+				$this->checkout->add_reg_step($reg_step_obj);
791
+			} else {
792
+				EE_Error::add_error(
793
+					__('The current step could not be set.', 'event_espresso'),
794
+					__FILE__, __FUNCTION__, __LINE__
795
+				);
796
+				return false;
797
+			}
798
+		} else {
799
+			if (WP_DEBUG) {
800
+				EE_Error::add_error(
801
+					sprintf(
802
+						__('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'),
803
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
804
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
805
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
806
+						'<ul>',
807
+						'<li>',
808
+						'</li>',
809
+						'</ul>'
810
+					),
811
+					__FILE__, __FUNCTION__, __LINE__
812
+				);
813
+			}
814
+			return false;
815
+		}
816
+		return true;
817
+	}
818
+
819
+
820
+
821
+	/**
822
+	 * _verify_transaction_and_get_registrations
823
+	 *
824
+	 * @access private
825
+	 * @return bool
826
+	 */
827
+	private function _verify_transaction_and_get_registrations()
828
+	{
829
+		// was there already a valid transaction in the checkout from the session ?
830
+		if ( ! $this->checkout->transaction instanceof EE_Transaction) {
831
+			// get transaction from db or session
832
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
833
+				? $this->_get_transaction_and_cart_for_previous_visit()
834
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
835
+			if ( ! $this->checkout->transaction instanceof EE_Transaction) {
836
+				EE_Error::add_error(
837
+					__('Your Registration and Transaction information could not be retrieved from the db.',
838
+						'event_espresso'),
839
+					__FILE__, __FUNCTION__, __LINE__
840
+				);
841
+				$this->checkout->transaction = EE_Transaction::new_instance();
842
+				// add some style and make it dance
843
+				$this->add_styles_and_scripts();
844
+				EED_Single_Page_Checkout::$_initialized = true;
845
+				return false;
846
+			}
847
+			// and the registrations for the transaction
848
+			$this->_get_registrations($this->checkout->transaction);
849
+		}
850
+		return true;
851
+	}
852
+
853
+
854
+
855
+	/**
856
+	 * _get_transaction_and_cart_for_previous_visit
857
+	 *
858
+	 * @access private
859
+	 * @return mixed EE_Transaction|NULL
860
+	 */
861
+	private function _get_transaction_and_cart_for_previous_visit()
862
+	{
863
+		/** @var $TXN_model EEM_Transaction */
864
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
865
+		// because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db
866
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
867
+		// verify transaction
868
+		if ($transaction instanceof EE_Transaction) {
869
+			// and get the cart that was used for that transaction
870
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
871
+			return $transaction;
872
+		} else {
873
+			EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
874
+			return null;
875
+		}
876
+	}
877
+
878
+
879
+
880
+	/**
881
+	 * _get_cart_for_transaction
882
+	 *
883
+	 * @access private
884
+	 * @param EE_Transaction $transaction
885
+	 * @return EE_Cart
886
+	 */
887
+	private function _get_cart_for_transaction($transaction)
888
+	{
889
+		return $this->checkout->get_cart_for_transaction($transaction);
890
+	}
891
+
892
+
893
+
894
+	/**
895
+	 * get_cart_for_transaction
896
+	 *
897
+	 * @access public
898
+	 * @param EE_Transaction $transaction
899
+	 * @return EE_Cart
900
+	 */
901
+	public function get_cart_for_transaction(EE_Transaction $transaction)
902
+	{
903
+		return $this->checkout->get_cart_for_transaction($transaction);
904
+	}
905
+
906
+
907
+
908
+	/**
909
+	 * _get_transaction_and_cart_for_current_session
910
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
911
+	 *
912
+	 * @access private
913
+	 * @return EE_Transaction
914
+	 * @throws \EE_Error
915
+	 */
916
+	private function _get_cart_for_current_session_and_setup_new_transaction()
917
+	{
918
+		//  if there's no transaction, then this is the FIRST visit to SPCO
919
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
920
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
921
+		// and then create a new transaction
922
+		$transaction = $this->_initialize_transaction();
923
+		// verify transaction
924
+		if ($transaction instanceof EE_Transaction) {
925
+			// save it so that we have an ID for other objects to use
926
+			$transaction->save();
927
+			// and save TXN data to the cart
928
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
929
+		} else {
930
+			EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
931
+		}
932
+		return $transaction;
933
+	}
934
+
935
+
936
+
937
+	/**
938
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
939
+	 *
940
+	 * @access private
941
+	 * @return mixed EE_Transaction|NULL
942
+	 */
943
+	private function _initialize_transaction()
944
+	{
945
+		try {
946
+			// ensure cart totals have been calculated
947
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
948
+			// grab the cart grand total
949
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
950
+			// create new TXN
951
+			$transaction = EE_Transaction::new_instance(
952
+				array(
953
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
954
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
955
+					'TXN_paid'      => 0,
956
+					'STS_ID'        => EEM_Transaction::failed_status_code,
957
+				)
958
+			);
959
+			// save it so that we have an ID for other objects to use
960
+			$transaction->save();
961
+			// set cron job for following up on TXNs after their session has expired
962
+			EE_Cron_Tasks::schedule_expired_transaction_check(
963
+				EE_Registry::instance()->SSN->expiration() + 1,
964
+				$transaction->ID()
965
+			);
966
+			return $transaction;
967
+		} catch (Exception $e) {
968
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
969
+		}
970
+		return null;
971
+	}
972
+
973
+
974
+
975
+	/**
976
+	 * _get_registrations
977
+	 *
978
+	 * @access private
979
+	 * @param EE_Transaction $transaction
980
+	 * @return void
981
+	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
982
+	 * @throws \EE_Error
983
+	 */
984
+	private function _get_registrations(EE_Transaction $transaction)
985
+	{
986
+		// first step: grab the registrants  { : o
987
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true);
988
+		// verify registrations have been set
989
+		if (empty($registrations)) {
990
+			// if no cached registrations, then check the db
991
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
992
+			// still nothing ? well as long as this isn't a revisit
993
+			if (empty($registrations) && ! $this->checkout->revisit) {
994
+				// generate new registrations from scratch
995
+				$registrations = $this->_initialize_registrations($transaction);
996
+			}
997
+		}
998
+		// sort by their original registration order
999
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1000
+		// then loop thru the array
1001
+		foreach ($registrations as $registration) {
1002
+			// verify each registration
1003
+			if ($registration instanceof EE_Registration) {
1004
+				// we display all attendee info for the primary registrant
1005
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
1006
+					&& $registration->is_primary_registrant()
1007
+				) {
1008
+					$this->checkout->primary_revisit = true;
1009
+					break;
1010
+				} else if ($this->checkout->revisit
1011
+						   && $this->checkout->reg_url_link !== $registration->reg_url_link()
1012
+				) {
1013
+					// but hide info if it doesn't belong to you
1014
+					$transaction->clear_cache('Registration', $registration->ID());
1015
+				}
1016
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1017
+			}
1018
+		}
1019
+	}
1020
+
1021
+
1022
+
1023
+	/**
1024
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1025
+	 *
1026
+	 * @access private
1027
+	 * @param EE_Transaction $transaction
1028
+	 * @return    array
1029
+	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
1030
+	 * @throws \EE_Error
1031
+	 */
1032
+	private function _initialize_registrations(EE_Transaction $transaction)
1033
+	{
1034
+		$att_nmbr = 0;
1035
+		$registrations = array();
1036
+		if ($transaction instanceof EE_Transaction) {
1037
+			/** @type EE_Registration_Processor $registration_processor */
1038
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1039
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1040
+			// now let's add the cart items to the $transaction
1041
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1042
+				//do the following for each ticket of this type they selected
1043
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1044
+					$att_nmbr++;
1045
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1046
+					$CreateRegistrationCommand = EE_Registry::instance()
1047
+															->create(
1048
+																'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1049
+																array(
1050
+																	$transaction,
1051
+																	$line_item,
1052
+																	$att_nmbr,
1053
+																	$this->checkout->total_ticket_count,
1054
+																)
1055
+															);
1056
+					// override capabilities for frontend registrations
1057
+					if ( ! is_admin()) {
1058
+						$CreateRegistrationCommand->setCapCheck(
1059
+							new PublicCapabilities('', 'create_new_registration')
1060
+						);
1061
+					}
1062
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1063
+					if ( ! $registration instanceof EE_Registration) {
1064
+						throw new InvalidEntityException($registration, 'EE_Registration');
1065
+					}
1066
+					$registrations[ $registration->ID() ] = $registration;
1067
+				}
1068
+			}
1069
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1070
+		}
1071
+		return $registrations;
1072
+	}
1073
+
1074
+
1075
+
1076
+	/**
1077
+	 * sorts registrations by REG_count
1078
+	 *
1079
+	 * @access public
1080
+	 * @param EE_Registration $reg_A
1081
+	 * @param EE_Registration $reg_B
1082
+	 * @return int
1083
+	 */
1084
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1085
+	{
1086
+		// this shouldn't ever happen within the same TXN, but oh well
1087
+		if ($reg_A->count() === $reg_B->count()) {
1088
+			return 0;
1089
+		}
1090
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1091
+	}
1092
+
1093
+
1094
+
1095
+	/**
1096
+	 *    _final_verifications
1097
+	 * just makes sure that everything is set up correctly before proceeding
1098
+	 *
1099
+	 * @access    private
1100
+	 * @return    bool
1101
+	 * @throws \EE_Error
1102
+	 */
1103
+	private function _final_verifications()
1104
+	{
1105
+		// filter checkout
1106
+		$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout);
1107
+		//verify that current step is still set correctly
1108
+		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1109
+			EE_Error::add_error(
1110
+				__('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'),
1111
+				__FILE__,
1112
+				__FUNCTION__,
1113
+				__LINE__
1114
+			);
1115
+			return false;
1116
+		}
1117
+		// if returning to SPCO, then verify that primary registrant is set
1118
+		if ( ! empty($this->checkout->reg_url_link)) {
1119
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1120
+			if ( ! $valid_registrant instanceof EE_Registration) {
1121
+				EE_Error::add_error(
1122
+					__('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'),
1123
+					__FILE__,
1124
+					__FUNCTION__,
1125
+					__LINE__
1126
+				);
1127
+				return false;
1128
+			}
1129
+			$valid_registrant = null;
1130
+			foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1131
+				if (
1132
+					$registration instanceof EE_Registration
1133
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1134
+				) {
1135
+					$valid_registrant = $registration;
1136
+				}
1137
+			}
1138
+			if ( ! $valid_registrant instanceof EE_Registration) {
1139
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1140
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1141
+					// clear the session, mark the checkout as unverified, and try again
1142
+					EE_Registry::instance()->SSN->clear_session();
1143
+					EED_Single_Page_Checkout::$_initialized = false;
1144
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1145
+					$this->_initialize();
1146
+					EE_Error::reset_notices();
1147
+					return false;
1148
+				}
1149
+				EE_Error::add_error(
1150
+					__('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'),
1151
+					__FILE__,
1152
+					__FUNCTION__,
1153
+					__LINE__
1154
+				);
1155
+				return false;
1156
+			}
1157
+		}
1158
+		// now that things have been kinda sufficiently verified,
1159
+		// let's add the checkout to the session so that's available other systems
1160
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1161
+		return true;
1162
+	}
1163
+
1164
+
1165
+
1166
+	/**
1167
+	 *    _initialize_reg_steps
1168
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1169
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1170
+	 *
1171
+	 * @access    private
1172
+	 * @param bool $reinitializing
1173
+	 * @throws \EE_Error
1174
+	 */
1175
+	private function _initialize_reg_steps($reinitializing = false)
1176
+	{
1177
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1178
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1179
+		foreach ($this->checkout->reg_steps as $reg_step) {
1180
+			if ( ! $reg_step->initialize_reg_step()) {
1181
+				// if not initialized then maybe this step is being removed...
1182
+				if ( ! $reinitializing && $reg_step->is_current_step()) {
1183
+					// if it was the current step, then we need to start over here
1184
+					$this->_initialize_reg_steps(true);
1185
+					return;
1186
+				}
1187
+				continue;
1188
+			}
1189
+			// add css and JS for current step
1190
+			$reg_step->enqueue_styles_and_scripts();
1191
+			// i18n
1192
+			$reg_step->translate_js_strings();
1193
+			if ($reg_step->is_current_step()) {
1194
+				// the text that appears on the reg step form submit button
1195
+				$reg_step->set_submit_button_text();
1196
+			}
1197
+		}
1198
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1199
+		do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step);
1200
+	}
1201
+
1202
+
1203
+
1204
+	/**
1205
+	 * _check_form_submission
1206
+	 *
1207
+	 * @access private
1208
+	 * @return boolean
1209
+	 */
1210
+	private function _check_form_submission()
1211
+	{
1212
+		//does this request require the reg form to be generated ?
1213
+		if ($this->checkout->generate_reg_form) {
1214
+			// ever heard that song by Blue Rodeo ?
1215
+			try {
1216
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1217
+				// if not displaying a form, then check for form submission
1218
+				if (
1219
+					$this->checkout->process_form_submission
1220
+					&& $this->checkout->current_step->reg_form->was_submitted()
1221
+				) {
1222
+					// clear out any old data in case this step is being run again
1223
+					$this->checkout->current_step->set_valid_data(array());
1224
+					// capture submitted form data
1225
+					$this->checkout->current_step->reg_form->receive_form_submission(
1226
+						apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout)
1227
+					);
1228
+					// validate submitted form data
1229
+					if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1230
+						// thou shall not pass !!!
1231
+						$this->checkout->continue_reg = false;
1232
+						// any form validation errors?
1233
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1234
+							$submission_error_messages = array();
1235
+							// bad, bad, bad registrant
1236
+							foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) {
1237
+								if ($validation_error instanceof EE_Validation_Error) {
1238
+									$submission_error_messages[] = sprintf(
1239
+										__('%s : %s', 'event_espresso'),
1240
+										$validation_error->get_form_section()->html_label_text(),
1241
+										$validation_error->getMessage()
1242
+									);
1243
+								}
1244
+							}
1245
+							EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__);
1246
+						}
1247
+						// well not really... what will happen is we'll just get redirected back to redo the current step
1248
+						$this->go_to_next_step();
1249
+						return false;
1250
+					}
1251
+				}
1252
+			} catch (EE_Error $e) {
1253
+				$e->get_error();
1254
+			}
1255
+		}
1256
+		return true;
1257
+	}
1258
+
1259
+
1260
+
1261
+	/**
1262
+	 * _process_action
1263
+	 *
1264
+	 * @access private
1265
+	 * @return void
1266
+	 * @throws \EE_Error
1267
+	 */
1268
+	private function _process_form_action()
1269
+	{
1270
+		// what cha wanna do?
1271
+		switch ($this->checkout->action) {
1272
+			// AJAX next step reg form
1273
+			case 'display_spco_reg_step' :
1274
+				$this->checkout->redirect = false;
1275
+				if (EE_Registry::instance()->REQ->ajax) {
1276
+					$this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form());
1277
+				}
1278
+				break;
1279
+			default :
1280
+				// meh... do one of those other steps first
1281
+				if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) {
1282
+					// dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1283
+					do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step);
1284
+					// call action on current step
1285
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1286
+						// good registrant, you get to proceed
1287
+						if (
1288
+							$this->checkout->current_step->success_message() !== ''
1289
+							&& apply_filters(
1290
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1291
+								false
1292
+							)
1293
+						) {
1294
+							EE_Error::add_success(
1295
+								$this->checkout->current_step->success_message()
1296
+								. '<br />' . $this->checkout->next_step->_instructions()
1297
+							);
1298
+						}
1299
+						// pack it up, pack it in...
1300
+						$this->_setup_redirect();
1301
+					}
1302
+					// dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1303
+					do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step);
1304
+				} else {
1305
+					EE_Error::add_error(
1306
+						sprintf(
1307
+							__('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'),
1308
+							$this->checkout->action,
1309
+							$this->checkout->current_step->name()
1310
+						),
1311
+						__FILE__,
1312
+						__FUNCTION__,
1313
+						__LINE__
1314
+					);
1315
+				}
1316
+			// end default
1317
+		}
1318
+		// store our progress so far
1319
+		$this->checkout->stash_transaction_and_checkout();
1320
+		// advance to the next step! If you pass GO, collect $200
1321
+		$this->go_to_next_step();
1322
+	}
1323
+
1324
+
1325
+
1326
+	/**
1327
+	 *        add_styles_and_scripts
1328
+	 *
1329
+	 * @access        public
1330
+	 * @return        void
1331
+	 */
1332
+	public function add_styles_and_scripts()
1333
+	{
1334
+		// i18n
1335
+		$this->translate_js_strings();
1336
+		if ($this->checkout->admin_request) {
1337
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1338
+		} else {
1339
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1340
+		}
1341
+	}
1342
+
1343
+
1344
+
1345
+	/**
1346
+	 *        translate_js_strings
1347
+	 *
1348
+	 * @access        public
1349
+	 * @return        void
1350
+	 */
1351
+	public function translate_js_strings()
1352
+	{
1353
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1354
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1355
+		EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso');
1356
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso');
1357
+		EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso');
1358
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso');
1359
+		EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso');
1360
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso');
1361
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1362
+			__('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'),
1363
+			'<br/>',
1364
+			'<br/>'
1365
+		);
1366
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1367
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1368
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1369
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1370
+		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1371
+		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1372
+		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1373
+		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1374
+		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1375
+		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1376
+		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1377
+		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1378
+		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1379
+		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1380
+		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1381
+		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1382
+		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1383
+		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1384
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1385
+			__(
1386
+				'%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
1387
+				'event_espresso'
1388
+			),
1389
+			'<h4 class="important-notice">',
1390
+			'</h4>',
1391
+			'<br />',
1392
+			'<p>',
1393
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1394
+			'">',
1395
+			'</a>',
1396
+			'</p>'
1397
+		);
1398
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true);
1399
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1400
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1401
+		);
1402
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1403
+			'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1404
+		);
1405
+	}
1406
+
1407
+
1408
+
1409
+	/**
1410
+	 *    enqueue_styles_and_scripts
1411
+	 *
1412
+	 * @access        public
1413
+	 * @return        void
1414
+	 * @throws \EE_Error
1415
+	 */
1416
+	public function enqueue_styles_and_scripts()
1417
+	{
1418
+		// load css
1419
+		wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION);
1420
+		wp_enqueue_style('single_page_checkout');
1421
+		// load JS
1422
+		wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js', array('jquery'), '1.0.1', true);
1423
+		wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js', array('jquery_plugin'), '2.0.2', true);
1424
+		wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true);
1425
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1426
+			$this->checkout->registration_form->enqueue_js();
1427
+		}
1428
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1429
+			$this->checkout->current_step->reg_form->enqueue_js();
1430
+		}
1431
+		wp_enqueue_script('single_page_checkout');
1432
+		/**
1433
+		 * global action hook for enqueueing styles and scripts with
1434
+		 * spco calls.
1435
+		 */
1436
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1437
+		/**
1438
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1439
+		 * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1440
+		 */
1441
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this);
1442
+	}
1443
+
1444
+
1445
+
1446
+	/**
1447
+	 *    display the Registration Single Page Checkout Form
1448
+	 *
1449
+	 * @access    private
1450
+	 * @return    void
1451
+	 * @throws \EE_Error
1452
+	 */
1453
+	private function _display_spco_reg_form()
1454
+	{
1455
+		// if registering via the admin, just display the reg form for the current step
1456
+		if ($this->checkout->admin_request) {
1457
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1458
+		} else {
1459
+			// add powered by EE msg
1460
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1461
+			$empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1
1462
+				? true
1463
+				: false;
1464
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1465
+			$cookies_not_set_msg = '';
1466
+			if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) {
1467
+				$cookies_not_set_msg = apply_filters(
1468
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1469
+					sprintf(
1470
+						__(
1471
+							'%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1472
+							'event_espresso'
1473
+						),
1474
+						'<div class="ee-attention">',
1475
+						'</div>',
1476
+						'<h6 class="important-notice">',
1477
+						'</h6>',
1478
+						'<p>',
1479
+						'</p>',
1480
+						'<br />',
1481
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1482
+						'</a>'
1483
+					)
1484
+				);
1485
+			}
1486
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1487
+				array(
1488
+					'name'            => 'single-page-checkout',
1489
+					'html_id'         => 'ee-single-page-checkout-dv',
1490
+					'layout_strategy' =>
1491
+						new EE_Template_Layout(
1492
+							array(
1493
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1494
+								'template_args'        => array(
1495
+									'empty_cart'              => $empty_cart,
1496
+									'revisit'                 => $this->checkout->revisit,
1497
+									'reg_steps'               => $this->checkout->reg_steps,
1498
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1499
+										? $this->checkout->next_step->slug()
1500
+										: '',
1501
+									'cancel_page_url'         => $this->checkout->cancel_page_url,
1502
+									'empty_msg'               => apply_filters(
1503
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1504
+										sprintf(
1505
+											__('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1506
+												'event_espresso'),
1507
+											'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1508
+											'">',
1509
+											'</a>'
1510
+										)
1511
+									),
1512
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1513
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1514
+									'session_expiration'      =>
1515
+										date('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)),
1516
+								),
1517
+							)
1518
+						),
1519
+				)
1520
+			);
1521
+			// load template and add to output sent that gets filtered into the_content()
1522
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1523
+		}
1524
+	}
1525
+
1526
+
1527
+
1528
+	/**
1529
+	 *    add_extra_finalize_registration_inputs
1530
+	 *
1531
+	 * @access    public
1532
+	 * @param $next_step
1533
+	 * @internal  param string $label
1534
+	 * @return void
1535
+	 */
1536
+	public function add_extra_finalize_registration_inputs($next_step)
1537
+	{
1538
+		if ($next_step === 'finalize_registration') {
1539
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1540
+		}
1541
+	}
1542
+
1543
+
1544
+
1545
+	/**
1546
+	 *    display_registration_footer
1547
+	 *
1548
+	 * @access    public
1549
+	 * @return    string
1550
+	 */
1551
+	public static function display_registration_footer()
1552
+	{
1553
+		if (
1554
+		apply_filters(
1555
+			'FHEE__EE_Front__Controller__show_reg_footer',
1556
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1557
+		)
1558
+		) {
1559
+			add_filter(
1560
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1561
+				function ($url) {
1562
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1563
+				}
1564
+			);
1565
+			echo apply_filters(
1566
+				'FHEE__EE_Front_Controller__display_registration_footer',
1567
+				\EEH_Template::powered_by_event_espresso(
1568
+					'',
1569
+					'espresso-registration-footer-dv',
1570
+					array('utm_content' => 'registration_checkout')
1571
+				)
1572
+			);
1573
+		}
1574
+		return '';
1575
+	}
1576
+
1577
+
1578
+
1579
+	/**
1580
+	 *    unlock_transaction
1581
+	 *
1582
+	 * @access    public
1583
+	 * @return    void
1584
+	 * @throws \EE_Error
1585
+	 */
1586
+	public function unlock_transaction()
1587
+	{
1588
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1589
+			$this->checkout->transaction->unlock();
1590
+		}
1591
+	}
1592
+
1593
+
1594
+
1595
+	/**
1596
+	 *        _setup_redirect
1597
+	 *
1598
+	 * @access    private
1599
+	 * @return void
1600
+	 */
1601
+	private function _setup_redirect()
1602
+	{
1603
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1604
+			$this->checkout->redirect = true;
1605
+			if (empty($this->checkout->redirect_url)) {
1606
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1607
+			}
1608
+			$this->checkout->redirect_url = apply_filters(
1609
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1610
+				$this->checkout->redirect_url,
1611
+				$this->checkout
1612
+			);
1613
+		}
1614
+	}
1615
+
1616
+
1617
+
1618
+	/**
1619
+	 *   handle ajax message responses and redirects
1620
+	 *
1621
+	 * @access public
1622
+	 * @return void
1623
+	 * @throws \EE_Error
1624
+	 */
1625
+	public function go_to_next_step()
1626
+	{
1627
+		if (EE_Registry::instance()->REQ->ajax) {
1628
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1629
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1630
+		}
1631
+		$this->unlock_transaction();
1632
+		// just return for these conditions
1633
+		if (
1634
+			$this->checkout->admin_request
1635
+			|| $this->checkout->action === 'redirect_form'
1636
+			|| $this->checkout->action === 'update_checkout'
1637
+		) {
1638
+			return;
1639
+		}
1640
+		// AJAX response
1641
+		$this->_handle_json_response();
1642
+		// redirect to next step or the Thank You page
1643
+		$this->_handle_html_redirects();
1644
+		// hmmm... must be something wrong, so let's just display the form again !
1645
+		$this->_display_spco_reg_form();
1646
+	}
1647
+
1648
+
1649
+
1650
+	/**
1651
+	 *   _handle_json_response
1652
+	 *
1653
+	 * @access protected
1654
+	 * @return void
1655
+	 */
1656
+	protected function _handle_json_response()
1657
+	{
1658
+		// if this is an ajax request
1659
+		if (EE_Registry::instance()->REQ->ajax) {
1660
+			// DEBUG LOG
1661
+			//$this->checkout->log(
1662
+			//	__CLASS__, __FUNCTION__, __LINE__,
1663
+			//	array(
1664
+			//		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1665
+			//		'redirect'                   => $this->checkout->redirect,
1666
+			//		'continue_reg'               => $this->checkout->continue_reg,
1667
+			//	)
1668
+			//);
1669
+			$this->checkout->json_response->set_registration_time_limit(
1670
+				$this->checkout->get_registration_time_limit()
1671
+			);
1672
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1673
+			// just send the ajax (
1674
+			$json_response = apply_filters(
1675
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1676
+				$this->checkout->json_response
1677
+			);
1678
+			echo $json_response;
1679
+			exit();
1680
+		}
1681
+	}
1682
+
1683
+
1684
+
1685
+	/**
1686
+	 *   _handle_redirects
1687
+	 *
1688
+	 * @access protected
1689
+	 * @return void
1690
+	 */
1691
+	protected function _handle_html_redirects()
1692
+	{
1693
+		// going somewhere ?
1694
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1695
+			// store notices in a transient
1696
+			EE_Error::get_notices(false, true, true);
1697
+			// DEBUG LOG
1698
+			//$this->checkout->log(
1699
+			//	__CLASS__, __FUNCTION__, __LINE__,
1700
+			//	array(
1701
+			//		'headers_sent' => headers_sent(),
1702
+			//		'redirect_url'     => $this->checkout->redirect_url,
1703
+			//		'headers_list'    => headers_list(),
1704
+			//	)
1705
+			//);
1706
+			wp_safe_redirect($this->checkout->redirect_url);
1707
+			exit();
1708
+		}
1709
+	}
1710
+
1711
+
1712
+
1713
+	/**
1714
+	 *   set_checkout_anchor
1715
+	 *
1716
+	 * @access public
1717
+	 * @return void
1718
+	 */
1719
+	public function set_checkout_anchor()
1720
+	{
1721
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1722
+	}
1723 1723
 
1724 1724
 
1725 1725
 
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/config/Read.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -42,27 +42,27 @@  discard block
 block discarded – undo
42 42
 	
43 43
 	/**
44 44
 	 * Handles the request for public site info
45
-     * @global $wp_json_basic_auth_success boolean set by the basic auth plugin, indicates if the current user could be authenticated using basic auth data
46
-     * @global $wp_json_basic_auth_received_data boolean set by the basic auth plugin, indicates if basic auth data was somehow received
45
+	 * @global $wp_json_basic_auth_success boolean set by the basic auth plugin, indicates if the current user could be authenticated using basic auth data
46
+	 * @global $wp_json_basic_auth_received_data boolean set by the basic auth plugin, indicates if basic auth data was somehow received
47 47
 	 * @param \WP_REST_Request $request
48 48
 	 * @return \EE_Config|\WP_Error
49 49
 	 */
50 50
 	public static function handle_request_site_info( \WP_REST_Request $request) {
51
-	    global $wp_json_basic_auth_success, $wp_json_basic_auth_received_data;
52
-        $insecure_usage_of_basic_auth = apply_filters(
53
-            'EventEspresso__core__libraries__rest_api__controllers__config__handle_request_site_info__insecure_usage_of_basic_auth',
54
-            $wp_json_basic_auth_success && ! is_ssl(),
55
-            $request
56
-        );
57
-        if( $insecure_usage_of_basic_auth ) {
58
-            $warning = sprintf(
59
-                esc_html__( 'Your data is not secured with SSL. %1$sPlease see our recommendations.%2$s', 'event_espresso' ),
60
-                '<a href="https://eventespresso.com/wiki/rest-api-security-recommendations/">',
61
-                '</a>'
62
-            );
63
-        } else {
64
-            $warning = '';
65
-        }
51
+		global $wp_json_basic_auth_success, $wp_json_basic_auth_received_data;
52
+		$insecure_usage_of_basic_auth = apply_filters(
53
+			'EventEspresso__core__libraries__rest_api__controllers__config__handle_request_site_info__insecure_usage_of_basic_auth',
54
+			$wp_json_basic_auth_success && ! is_ssl(),
55
+			$request
56
+		);
57
+		if( $insecure_usage_of_basic_auth ) {
58
+			$warning = sprintf(
59
+				esc_html__( 'Your data is not secured with SSL. %1$sPlease see our recommendations.%2$s', 'event_espresso' ),
60
+				'<a href="https://eventespresso.com/wiki/rest-api-security-recommendations/">',
61
+				'</a>'
62
+			);
63
+		} else {
64
+			$warning = '';
65
+		}
66 66
 		return array(
67 67
 			'default_timezone' => array(
68 68
 				'pretty' => \EEH_DTT_Helper::get_timezone_string_for_display(),
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
 				'offset' => \EEH_DTT_Helper::get_site_timezone_gmt_offset(),
71 71
 			),
72 72
 			'default_currency' => \EE_Config::instance()->currency,
73
-            'authentication' => array(
74
-                'received_basic_auth_data' => (bool)$wp_json_basic_auth_received_data,
75
-                'insecure_usage_of_basic_auth' => (bool)$insecure_usage_of_basic_auth,
76
-                'warning' => $warning
77
-            )
73
+			'authentication' => array(
74
+				'received_basic_auth_data' => (bool)$wp_json_basic_auth_received_data,
75
+				'insecure_usage_of_basic_auth' => (bool)$insecure_usage_of_basic_auth,
76
+				'warning' => $warning
77
+			)
78 78
 		);
79 79
 	}
80 80
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 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\controllers\config;
3
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 /**
@@ -21,11 +21,11 @@  discard block
 block discarded – undo
21 21
 	 * @param \WP_REST_Request $request
22 22
 	 * @return \EE_Config|\WP_Error
23 23
 	 */
24
-	public static function handle_request( \WP_REST_Request $request) {
24
+	public static function handle_request(\WP_REST_Request $request) {
25 25
 		$cap = \EE_Restriction_Generator_Base::get_default_restrictions_cap();
26
-		if( \EE_Capabilities::instance()->current_user_can( $cap, 'read_over_api' ) ){
26
+		if (\EE_Capabilities::instance()->current_user_can($cap, 'read_over_api')) {
27 27
 			return \EE_Config::instance();
28
-		}else{
28
+		} else {
29 29
 			return new \WP_Error(
30 30
 				'cannot_read_config',
31 31
 				sprintf(
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 					),
36 36
 					$cap
37 37
 				),
38
-				array( 'status' => 403 )
38
+				array('status' => 403)
39 39
 			);
40 40
 		}
41 41
 	}
@@ -47,16 +47,16 @@  discard block
 block discarded – undo
47 47
 	 * @param \WP_REST_Request $request
48 48
 	 * @return \EE_Config|\WP_Error
49 49
 	 */
50
-	public static function handle_request_site_info( \WP_REST_Request $request) {
50
+	public static function handle_request_site_info(\WP_REST_Request $request) {
51 51
 	    global $wp_json_basic_auth_success, $wp_json_basic_auth_received_data;
52 52
         $insecure_usage_of_basic_auth = apply_filters(
53 53
             'EventEspresso__core__libraries__rest_api__controllers__config__handle_request_site_info__insecure_usage_of_basic_auth',
54 54
             $wp_json_basic_auth_success && ! is_ssl(),
55 55
             $request
56 56
         );
57
-        if( $insecure_usage_of_basic_auth ) {
57
+        if ($insecure_usage_of_basic_auth) {
58 58
             $warning = sprintf(
59
-                esc_html__( 'Your data is not secured with SSL. %1$sPlease see our recommendations.%2$s', 'event_espresso' ),
59
+                esc_html__('Your data is not secured with SSL. %1$sPlease see our recommendations.%2$s', 'event_espresso'),
60 60
                 '<a href="https://eventespresso.com/wiki/rest-api-security-recommendations/">',
61 61
                 '</a>'
62 62
             );
@@ -66,13 +66,13 @@  discard block
 block discarded – undo
66 66
 		return array(
67 67
 			'default_timezone' => array(
68 68
 				'pretty' => \EEH_DTT_Helper::get_timezone_string_for_display(),
69
-				'string' => get_option( 'timezone_string' ),
69
+				'string' => get_option('timezone_string'),
70 70
 				'offset' => \EEH_DTT_Helper::get_site_timezone_gmt_offset(),
71 71
 			),
72 72
 			'default_currency' => \EE_Config::instance()->currency,
73 73
             'authentication' => array(
74
-                'received_basic_auth_data' => (bool)$wp_json_basic_auth_received_data,
75
-                'insecure_usage_of_basic_auth' => (bool)$insecure_usage_of_basic_auth,
74
+                'received_basic_auth_data' => (bool) $wp_json_basic_auth_received_data,
75
+                'insecure_usage_of_basic_auth' => (bool) $insecure_usage_of_basic_auth,
76 76
                 'warning' => $warning
77 77
             )
78 78
 		);
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.34.rc.004');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.34.rc.004');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
283 283
\ No newline at end of file
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorRowStandard.php 1 patch
Indentation   +392 added lines, -392 removed lines patch added patch discarded remove patch
@@ -19,398 +19,398 @@
 block discarded – undo
19 19
 class TicketSelectorRowStandard extends TicketSelectorRow
20 20
 {
21 21
 
22
-    /**
23
-     * @var TicketDetails $ticket_details
24
-     */
25
-    protected $ticket_details;
26
-
27
-    /**
28
-     * @var \EE_Ticket_Selector_Config $template_settings
29
-     */
30
-    protected $template_settings;
31
-
32
-    /**
33
-     * @var \EE_Tax_Config $tax_settings
34
-     */
35
-    protected $tax_settings;
36
-
37
-    /**
38
-     * @var boolean $prices_displayed_including_taxes
39
-     */
40
-    protected $prices_displayed_including_taxes;
41
-
42
-    /**
43
-     * @var int $row
44
-     */
45
-    protected $row;
46
-
47
-    /**
48
-     * @var int $cols
49
-     */
50
-    protected $cols;
51
-
52
-    /**
53
-     * @var boolean $hidden_input_qty
54
-     */
55
-    protected $hidden_input_qty;
56
-
57
-    /**
58
-     * @var string $ticket_datetime_classes
59
-     */
60
-    protected $ticket_datetime_classes;
61
-
62
-
63
-
64
-    /**
65
-     * TicketDetails constructor.
66
-     *
67
-     * @param TicketDetails  $ticket_details
68
-     * @param \EE_Tax_Config $tax_settings
69
-     * @param int            $total_tickets
70
-     * @param int            $max_atndz
71
-     * @param int            $row
72
-     * @param int            $cols
73
-     * @param boolean        $required_ticket_sold_out
74
-     * @param string         $event_status
75
-     * @param string         $ticket_datetime_classes
76
-     * @throws EE_Error
77
-     * @throws UnexpectedEntityException
78
-     */
79
-    public function __construct(
80
-        TicketDetails $ticket_details,
81
-        \EE_Tax_Config $tax_settings,
82
-        $total_tickets,
83
-        $max_atndz,
84
-        $row,
85
-        $cols,
86
-        $required_ticket_sold_out,
87
-        $event_status,
88
-        $ticket_datetime_classes
89
-    ) {
90
-        $this->ticket = $ticket_details->getTicket();
91
-        $this->ticket_details = $ticket_details;
92
-        $this->template_settings = $ticket_details->getTemplateSettings();
93
-        $this->tax_settings = $tax_settings;
94
-        $this->total_tickets = $total_tickets;
95
-        $this->max_atndz = $max_atndz;
96
-        $this->row = $row;
97
-        $this->cols = $cols;
98
-        $this->date_format = $ticket_details->getDateFormat();
99
-        $this->ticket_datetime_classes = $ticket_datetime_classes;
100
-        parent::__construct($this->ticket, $max_atndz, $this->date_format, $event_status, $required_ticket_sold_out);
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * other ticket rows will need to know if a required ticket is sold out,
107
-     * so that they are not offered for sale
108
-     *
109
-     * @return boolean
110
-     */
111
-    public function getRequiredTicketSoldOut()
112
-    {
113
-        return $this->required_ticket_sold_out;
114
-    }
115
-
116
-
117
-
118
-    /**
119
-     * @return int
120
-     */
121
-    public function getCols()
122
-    {
123
-        return $this->cols;
124
-    }
125
-
126
-
127
-
128
-    /**
129
-     * getHtml
130
-     *
131
-     * @return string
132
-     * @throws EE_Error
133
-     */
134
-    public function getHtml()
135
-    {
136
-        $min = 0;
137
-        $max = $this->ticket->max();
138
-        $remaining = $this->ticket->remaining();
139
-        if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) {
140
-            list($min, $max) = $this->setTicketMinAndMax($remaining);
141
-        } else {
142
-            // set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
143
-            $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
144
-                ? $this->ticket->start_date()
145
-                : $this->required_ticket_sold_out;
146
-        }
147
-        list($ticket_price, $ticket_bundle) = $this->getTicketPriceDetails();
148
-        list($tkt_status, $ticket_status, $status_class) = $this->getTicketStatusClasses($remaining);
149
-        /**
150
-         * Allow plugins to hook in and abort the generation and display of this row to do
151
-         * something else if they want.
152
-         * For an addon to abort things, all they have to do is register a filter with this hook, and
153
-         * return a value that is NOT false.  Whatever is returned gets echoed instead of the
154
-         * current row.
155
-         *
156
-         * @var string|bool
157
-         */
158
-        $ticket_selector_row_html = apply_filters(
159
-            'FHEE__ticket_selector_chart_template__do_ticket_entire_row',
160
-            false,
161
-            $this->ticket,
162
-            $max,
163
-            $min,
164
-            $this->required_ticket_sold_out,
165
-            $ticket_price,
166
-            $ticket_bundle,
167
-            $ticket_status,
168
-            $status_class
169
-        );
170
-        if ($ticket_selector_row_html !== false) {
171
-            return $ticket_selector_row_html;
172
-        }
173
-        $ticket_selector_row_html = \EEH_HTML::tr(
174
-            '', '',
175
-            "tckt-slctr-tbl-tr {$status_class}{$this->ticket_datetime_classes} " . espresso_get_object_css_class($this->ticket)
176
-        );
177
-        /**
178
-         * Allow plugins to hook in and abort the generation and display of the contents of this
179
-         * row to do something else if they want.
180
-         * For an addon to abort things, all they have to do is register a filter with this hook, and
181
-         * return a value that is NOT false.  Whatever is returned gets echoed instead of the
182
-         * current row.
183
-         *
184
-         * @var string|bool
185
-         */
186
-        $new_row_cells_content = apply_filters(
187
-            'FHEE__ticket_selector_chart_template__do_ticket_inside_row',
188
-            false,
189
-            $this->ticket,
190
-            $max,
191
-            $min,
192
-            $this->required_ticket_sold_out,
193
-            $ticket_price,
194
-            $ticket_bundle,
195
-            $ticket_status,
196
-            $status_class
197
-        );
198
-        if ($new_row_cells_content !== false) {
199
-            return $ticket_selector_row_html
200
-                   . $new_row_cells_content
201
-                   . \EEH_HTML::trx();
202
-        }
203
-        $this->hidden_input_qty = $this->max_atndz > 1 ? true : false;
204
-
205
-        $ticket_selector_row_html .= $this->ticketNameTableCell();
206
-        $ticket_selector_row_html .= $this->ticketPriceTableCell($ticket_price, $ticket_bundle);
207
-        $ticket_selector_row_html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr');
208
-        $this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining);
209
-        if (empty($this->ticket_status_display)) {
210
-            if ($this->max_atndz === 1) {
211
-                // only ONE attendee is allowed to register at a time
212
-                $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
213
-            } else if ($max > 0) {
214
-                $ticket_selector_row_html .= $this->ticketQuantitySelector($min, $max);
215
-            }
216
-        }
217
-        $ticket_selector_row_html .= $this->ticket_status_display;
218
-        $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
219
-        $ticket_selector_row_html .= $this->ticket_details->display($ticket_price, $remaining, $this->cols);
220
-        $ticket_selector_row_html .= \EEH_HTML::tdx();
221
-        $ticket_selector_row_html .= \EEH_HTML::trx();
222
-
223
-
224
-        $this->row++;
225
-        return $ticket_selector_row_html;
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * setTicketMinAndMax
232
-     *
233
-     * @param int $remaining
234
-     * @return array
235
-     * @throws EE_Error
236
-     */
237
-    protected function setTicketMinAndMax($remaining)
238
-    {
239
-        // offer the number of $tickets_remaining or $this->max_atndz, whichever is smaller
240
-        $max = min($remaining, $this->max_atndz);
241
-        // but... we also want to restrict the number of tickets by the ticket max setting,
242
-        // however, the max still can't be higher than what was just set above
243
-        $max = $this->ticket->max() > 0 ? min($this->ticket->max(), $max) : $max;
244
-        // and we also want to restrict the minimum number of tickets by the ticket min setting
245
-        $min = $this->ticket->min() > 0 ? $this->ticket->min() : 0;
246
-        // and if the ticket is required, then make sure that min qty is at least 1
247
-        $min = $this->ticket->required() ? max($min, 1) : $min;
248
-        return array($min, $max);
249
-    }
250
-
251
-
252
-
253
-    /**
254
-     * getTicketPriceDetails
255
-     *
256
-     * @return array
257
-     * @throws EE_Error
258
-     */
259
-    protected function getTicketPriceDetails()
260
-    {
261
-        $ticket_price = $this->tax_settings->prices_displayed_including_taxes
262
-            ? $this->ticket->get_ticket_total_with_taxes()
263
-            : $this->ticket->get_ticket_subtotal();
264
-        $ticket_bundle = false;
265
-        $ticket_min = $this->ticket->min();
266
-        // for ticket bundles, set min and max qty the same
267
-        if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
268
-            $ticket_price *= $ticket_min;
269
-            $ticket_bundle = true;
270
-        }
271
-        $ticket_price = apply_filters(
272
-            'FHEE__ticket_selector_chart_template__ticket_price',
273
-            $ticket_price,
274
-            $this->ticket
275
-        );
276
-        return array($ticket_price, $ticket_bundle);
277
-    }
278
-
279
-
280
-
281
-
282
-    /**
283
-     * ticketNameTableCell
284
-     *
285
-     * @return string
286
-     * @throws EE_Error
287
-     */
288
-    protected function ticketNameTableCell()
289
-    {
290
-        $html = \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name');
291
-        $html .= \EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
292
-        $html .= $this->ticket_details->getShowHideLinks();
293
-        if ($this->ticket->required()) {
294
-            $html .= \EEH_HTML::p(
295
-                    apply_filters(
296
-                            'FHEE__ticket_selector_chart_template__ticket_required_message',
297
-                            esc_html__('This ticket is required and must be purchased.', 'event_espresso')
298
-                    ),
299
-                    '', 'ticket-required-pg'
300
-            );
301
-        }
302
-        $html .= \EEH_HTML::tdx();
303
-        return $html;
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     * ticketPriceTableCell
310
-     *
311
-     * @param float $ticket_price
312
-     * @param bool  $ticket_bundle
313
-     * @return string
314
-     * @throws EE_Error
315
-     */
316
-    protected function ticketPriceTableCell($ticket_price, $ticket_bundle)
317
-    {
318
-        $html = '';
319
-        if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
320
-            $html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght');
321
-            $html .= \EEH_Template::format_currency($ticket_price);
322
-            $html .= $this->ticket->taxable()
323
-                ? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )
324
-                : '';
325
-            $html .= '&nbsp;';
326
-            $html .= \EEH_HTML::span(
327
-                $ticket_bundle
328
-                    ? apply_filters(
329
-                        'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
330
-                        __(' / bundle', 'event_espresso')
331
-                    )
332
-                    : apply_filters(
333
-                        'FHEE__ticket_selector_chart_template__per_ticket_text',
334
-                        __('', 'event_espresso')
335
-                    ),
336
-                '', 'smaller-text no-bold'
337
-            );
338
-            $html .= '&nbsp;';
339
-            $html .= \EEH_HTML::tdx();
340
-            $this->cols++;
341
-        }
342
-        return $html;
343
-    }
344
-
345
-
346
-
347
-    /**
348
-     * onlyOneAttendeeCanRegister
349
-     *
350
-     * @return string
351
-     */
352
-    protected function onlyOneAttendeeCanRegister()
353
-    {
354
-        // display submit button since we have tickets available
355
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
356
-        $this->hidden_input_qty = false;
357
-        $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';
358
-        $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
359
-        $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';
360
-        $html .= $this->total_tickets === 1 ? ' checked="checked"' : '';
361
-        $html .= ' title=""/>';
362
-        return $html;
363
-    }
364
-
365
-
366
-
367
-    /**
368
-     * ticketQuantitySelector
369
-     *
370
-     * @param int $min
371
-     * @param int $max
372
-     * @return string
373
-     * @throws EE_Error
374
-     */
375
-    protected function ticketQuantitySelector($min = 0, $max = 0)
376
-    {
377
-        // display submit button since we have tickets available
378
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
379
-        $this->hidden_input_qty = false;
380
-        $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';
381
-        $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
382
-        $html .= ' class="ticket-selector-tbl-qty-slct">';
383
-        // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
384
-        if ($min !== 0 && ! $this->ticket->required()) {
385
-            $html .= '<option value="0">&nbsp;0&nbsp;</option>';
386
-        }
387
-        // offer ticket quantities from the min to the max
388
-        for ($i = $min; $i <= $max; $i++) {
389
-            $html .= '<option value="' . $i . '">&nbsp;' . $i . '&nbsp;</option>';
390
-        }
391
-        $html .= '</select>';
392
-        return $html;
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     * getHiddenInputs
399
-     *
400
-     * @return string
401
-     * @throws EE_Error
402
-     */
403
-    protected function ticketQtyAndIdHiddenInputs()
404
-    {
405
-        $html = '';
406
-        // depending on group reg we need to change the format for qty
407
-        if ($this->hidden_input_qty) {
408
-            $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';
409
-        }
410
-        $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';
411
-        $html .= ' value="' . $this->ticket->ID() . '"/>';
412
-        return $html;
413
-    }
22
+	/**
23
+	 * @var TicketDetails $ticket_details
24
+	 */
25
+	protected $ticket_details;
26
+
27
+	/**
28
+	 * @var \EE_Ticket_Selector_Config $template_settings
29
+	 */
30
+	protected $template_settings;
31
+
32
+	/**
33
+	 * @var \EE_Tax_Config $tax_settings
34
+	 */
35
+	protected $tax_settings;
36
+
37
+	/**
38
+	 * @var boolean $prices_displayed_including_taxes
39
+	 */
40
+	protected $prices_displayed_including_taxes;
41
+
42
+	/**
43
+	 * @var int $row
44
+	 */
45
+	protected $row;
46
+
47
+	/**
48
+	 * @var int $cols
49
+	 */
50
+	protected $cols;
51
+
52
+	/**
53
+	 * @var boolean $hidden_input_qty
54
+	 */
55
+	protected $hidden_input_qty;
56
+
57
+	/**
58
+	 * @var string $ticket_datetime_classes
59
+	 */
60
+	protected $ticket_datetime_classes;
61
+
62
+
63
+
64
+	/**
65
+	 * TicketDetails constructor.
66
+	 *
67
+	 * @param TicketDetails  $ticket_details
68
+	 * @param \EE_Tax_Config $tax_settings
69
+	 * @param int            $total_tickets
70
+	 * @param int            $max_atndz
71
+	 * @param int            $row
72
+	 * @param int            $cols
73
+	 * @param boolean        $required_ticket_sold_out
74
+	 * @param string         $event_status
75
+	 * @param string         $ticket_datetime_classes
76
+	 * @throws EE_Error
77
+	 * @throws UnexpectedEntityException
78
+	 */
79
+	public function __construct(
80
+		TicketDetails $ticket_details,
81
+		\EE_Tax_Config $tax_settings,
82
+		$total_tickets,
83
+		$max_atndz,
84
+		$row,
85
+		$cols,
86
+		$required_ticket_sold_out,
87
+		$event_status,
88
+		$ticket_datetime_classes
89
+	) {
90
+		$this->ticket = $ticket_details->getTicket();
91
+		$this->ticket_details = $ticket_details;
92
+		$this->template_settings = $ticket_details->getTemplateSettings();
93
+		$this->tax_settings = $tax_settings;
94
+		$this->total_tickets = $total_tickets;
95
+		$this->max_atndz = $max_atndz;
96
+		$this->row = $row;
97
+		$this->cols = $cols;
98
+		$this->date_format = $ticket_details->getDateFormat();
99
+		$this->ticket_datetime_classes = $ticket_datetime_classes;
100
+		parent::__construct($this->ticket, $max_atndz, $this->date_format, $event_status, $required_ticket_sold_out);
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * other ticket rows will need to know if a required ticket is sold out,
107
+	 * so that they are not offered for sale
108
+	 *
109
+	 * @return boolean
110
+	 */
111
+	public function getRequiredTicketSoldOut()
112
+	{
113
+		return $this->required_ticket_sold_out;
114
+	}
115
+
116
+
117
+
118
+	/**
119
+	 * @return int
120
+	 */
121
+	public function getCols()
122
+	{
123
+		return $this->cols;
124
+	}
125
+
126
+
127
+
128
+	/**
129
+	 * getHtml
130
+	 *
131
+	 * @return string
132
+	 * @throws EE_Error
133
+	 */
134
+	public function getHtml()
135
+	{
136
+		$min = 0;
137
+		$max = $this->ticket->max();
138
+		$remaining = $this->ticket->remaining();
139
+		if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) {
140
+			list($min, $max) = $this->setTicketMinAndMax($remaining);
141
+		} else {
142
+			// set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
143
+			$this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
144
+				? $this->ticket->start_date()
145
+				: $this->required_ticket_sold_out;
146
+		}
147
+		list($ticket_price, $ticket_bundle) = $this->getTicketPriceDetails();
148
+		list($tkt_status, $ticket_status, $status_class) = $this->getTicketStatusClasses($remaining);
149
+		/**
150
+		 * Allow plugins to hook in and abort the generation and display of this row to do
151
+		 * something else if they want.
152
+		 * For an addon to abort things, all they have to do is register a filter with this hook, and
153
+		 * return a value that is NOT false.  Whatever is returned gets echoed instead of the
154
+		 * current row.
155
+		 *
156
+		 * @var string|bool
157
+		 */
158
+		$ticket_selector_row_html = apply_filters(
159
+			'FHEE__ticket_selector_chart_template__do_ticket_entire_row',
160
+			false,
161
+			$this->ticket,
162
+			$max,
163
+			$min,
164
+			$this->required_ticket_sold_out,
165
+			$ticket_price,
166
+			$ticket_bundle,
167
+			$ticket_status,
168
+			$status_class
169
+		);
170
+		if ($ticket_selector_row_html !== false) {
171
+			return $ticket_selector_row_html;
172
+		}
173
+		$ticket_selector_row_html = \EEH_HTML::tr(
174
+			'', '',
175
+			"tckt-slctr-tbl-tr {$status_class}{$this->ticket_datetime_classes} " . espresso_get_object_css_class($this->ticket)
176
+		);
177
+		/**
178
+		 * Allow plugins to hook in and abort the generation and display of the contents of this
179
+		 * row to do something else if they want.
180
+		 * For an addon to abort things, all they have to do is register a filter with this hook, and
181
+		 * return a value that is NOT false.  Whatever is returned gets echoed instead of the
182
+		 * current row.
183
+		 *
184
+		 * @var string|bool
185
+		 */
186
+		$new_row_cells_content = apply_filters(
187
+			'FHEE__ticket_selector_chart_template__do_ticket_inside_row',
188
+			false,
189
+			$this->ticket,
190
+			$max,
191
+			$min,
192
+			$this->required_ticket_sold_out,
193
+			$ticket_price,
194
+			$ticket_bundle,
195
+			$ticket_status,
196
+			$status_class
197
+		);
198
+		if ($new_row_cells_content !== false) {
199
+			return $ticket_selector_row_html
200
+				   . $new_row_cells_content
201
+				   . \EEH_HTML::trx();
202
+		}
203
+		$this->hidden_input_qty = $this->max_atndz > 1 ? true : false;
204
+
205
+		$ticket_selector_row_html .= $this->ticketNameTableCell();
206
+		$ticket_selector_row_html .= $this->ticketPriceTableCell($ticket_price, $ticket_bundle);
207
+		$ticket_selector_row_html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr');
208
+		$this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining);
209
+		if (empty($this->ticket_status_display)) {
210
+			if ($this->max_atndz === 1) {
211
+				// only ONE attendee is allowed to register at a time
212
+				$ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
213
+			} else if ($max > 0) {
214
+				$ticket_selector_row_html .= $this->ticketQuantitySelector($min, $max);
215
+			}
216
+		}
217
+		$ticket_selector_row_html .= $this->ticket_status_display;
218
+		$ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
219
+		$ticket_selector_row_html .= $this->ticket_details->display($ticket_price, $remaining, $this->cols);
220
+		$ticket_selector_row_html .= \EEH_HTML::tdx();
221
+		$ticket_selector_row_html .= \EEH_HTML::trx();
222
+
223
+
224
+		$this->row++;
225
+		return $ticket_selector_row_html;
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * setTicketMinAndMax
232
+	 *
233
+	 * @param int $remaining
234
+	 * @return array
235
+	 * @throws EE_Error
236
+	 */
237
+	protected function setTicketMinAndMax($remaining)
238
+	{
239
+		// offer the number of $tickets_remaining or $this->max_atndz, whichever is smaller
240
+		$max = min($remaining, $this->max_atndz);
241
+		// but... we also want to restrict the number of tickets by the ticket max setting,
242
+		// however, the max still can't be higher than what was just set above
243
+		$max = $this->ticket->max() > 0 ? min($this->ticket->max(), $max) : $max;
244
+		// and we also want to restrict the minimum number of tickets by the ticket min setting
245
+		$min = $this->ticket->min() > 0 ? $this->ticket->min() : 0;
246
+		// and if the ticket is required, then make sure that min qty is at least 1
247
+		$min = $this->ticket->required() ? max($min, 1) : $min;
248
+		return array($min, $max);
249
+	}
250
+
251
+
252
+
253
+	/**
254
+	 * getTicketPriceDetails
255
+	 *
256
+	 * @return array
257
+	 * @throws EE_Error
258
+	 */
259
+	protected function getTicketPriceDetails()
260
+	{
261
+		$ticket_price = $this->tax_settings->prices_displayed_including_taxes
262
+			? $this->ticket->get_ticket_total_with_taxes()
263
+			: $this->ticket->get_ticket_subtotal();
264
+		$ticket_bundle = false;
265
+		$ticket_min = $this->ticket->min();
266
+		// for ticket bundles, set min and max qty the same
267
+		if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
268
+			$ticket_price *= $ticket_min;
269
+			$ticket_bundle = true;
270
+		}
271
+		$ticket_price = apply_filters(
272
+			'FHEE__ticket_selector_chart_template__ticket_price',
273
+			$ticket_price,
274
+			$this->ticket
275
+		);
276
+		return array($ticket_price, $ticket_bundle);
277
+	}
278
+
279
+
280
+
281
+
282
+	/**
283
+	 * ticketNameTableCell
284
+	 *
285
+	 * @return string
286
+	 * @throws EE_Error
287
+	 */
288
+	protected function ticketNameTableCell()
289
+	{
290
+		$html = \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name');
291
+		$html .= \EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
292
+		$html .= $this->ticket_details->getShowHideLinks();
293
+		if ($this->ticket->required()) {
294
+			$html .= \EEH_HTML::p(
295
+					apply_filters(
296
+							'FHEE__ticket_selector_chart_template__ticket_required_message',
297
+							esc_html__('This ticket is required and must be purchased.', 'event_espresso')
298
+					),
299
+					'', 'ticket-required-pg'
300
+			);
301
+		}
302
+		$html .= \EEH_HTML::tdx();
303
+		return $html;
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 * ticketPriceTableCell
310
+	 *
311
+	 * @param float $ticket_price
312
+	 * @param bool  $ticket_bundle
313
+	 * @return string
314
+	 * @throws EE_Error
315
+	 */
316
+	protected function ticketPriceTableCell($ticket_price, $ticket_bundle)
317
+	{
318
+		$html = '';
319
+		if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
320
+			$html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght');
321
+			$html .= \EEH_Template::format_currency($ticket_price);
322
+			$html .= $this->ticket->taxable()
323
+				? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )
324
+				: '';
325
+			$html .= '&nbsp;';
326
+			$html .= \EEH_HTML::span(
327
+				$ticket_bundle
328
+					? apply_filters(
329
+						'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
330
+						__(' / bundle', 'event_espresso')
331
+					)
332
+					: apply_filters(
333
+						'FHEE__ticket_selector_chart_template__per_ticket_text',
334
+						__('', 'event_espresso')
335
+					),
336
+				'', 'smaller-text no-bold'
337
+			);
338
+			$html .= '&nbsp;';
339
+			$html .= \EEH_HTML::tdx();
340
+			$this->cols++;
341
+		}
342
+		return $html;
343
+	}
344
+
345
+
346
+
347
+	/**
348
+	 * onlyOneAttendeeCanRegister
349
+	 *
350
+	 * @return string
351
+	 */
352
+	protected function onlyOneAttendeeCanRegister()
353
+	{
354
+		// display submit button since we have tickets available
355
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
356
+		$this->hidden_input_qty = false;
357
+		$html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';
358
+		$html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
359
+		$html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';
360
+		$html .= $this->total_tickets === 1 ? ' checked="checked"' : '';
361
+		$html .= ' title=""/>';
362
+		return $html;
363
+	}
364
+
365
+
366
+
367
+	/**
368
+	 * ticketQuantitySelector
369
+	 *
370
+	 * @param int $min
371
+	 * @param int $max
372
+	 * @return string
373
+	 * @throws EE_Error
374
+	 */
375
+	protected function ticketQuantitySelector($min = 0, $max = 0)
376
+	{
377
+		// display submit button since we have tickets available
378
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
379
+		$this->hidden_input_qty = false;
380
+		$html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';
381
+		$html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
382
+		$html .= ' class="ticket-selector-tbl-qty-slct">';
383
+		// this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
384
+		if ($min !== 0 && ! $this->ticket->required()) {
385
+			$html .= '<option value="0">&nbsp;0&nbsp;</option>';
386
+		}
387
+		// offer ticket quantities from the min to the max
388
+		for ($i = $min; $i <= $max; $i++) {
389
+			$html .= '<option value="' . $i . '">&nbsp;' . $i . '&nbsp;</option>';
390
+		}
391
+		$html .= '</select>';
392
+		return $html;
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 * getHiddenInputs
399
+	 *
400
+	 * @return string
401
+	 * @throws EE_Error
402
+	 */
403
+	protected function ticketQtyAndIdHiddenInputs()
404
+	{
405
+		$html = '';
406
+		// depending on group reg we need to change the format for qty
407
+		if ($this->hidden_input_qty) {
408
+			$html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';
409
+		}
410
+		$html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';
411
+		$html .= ' value="' . $this->ticket->ID() . '"/>';
412
+		return $html;
413
+	}
414 414
 
415 415
 }
416 416
 // End of file TicketSelectorRowStandard.php
Please login to merge, or discard this patch.