Completed
Branch FET-10768-extract-admin-bar (07b6f3)
by
unknown
127:29 queued 115:38
created
core/EE_Registry.core.php 1 patch
Indentation   +1340 added lines, -1340 removed lines patch added patch discarded remove patch
@@ -16,1376 +16,1376 @@
 block discarded – undo
16 16
 class EE_Registry
17 17
 {
18 18
 
19
-    /**
20
-     *    EE_Registry Object
21
-     *
22
-     * @var EE_Registry $_instance
23
-     * @access    private
24
-     */
25
-    private static $_instance = null;
26
-
27
-    /**
28
-     * @var EE_Dependency_Map $_dependency_map
29
-     * @access    protected
30
-     */
31
-    protected $_dependency_map = null;
32
-
33
-    /**
34
-     * @var array $_class_abbreviations
35
-     * @access    protected
36
-     */
37
-    protected $_class_abbreviations = array();
38
-
39
-    /**
40
-     * @access public
41
-     * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS
42
-     */
43
-    public $BUS;
44
-
45
-    /**
46
-     *    EE_Cart Object
47
-     *
48
-     * @access    public
49
-     * @var    EE_Cart $CART
50
-     */
51
-    public $CART = null;
52
-
53
-    /**
54
-     *    EE_Config Object
55
-     *
56
-     * @access    public
57
-     * @var    EE_Config $CFG
58
-     */
59
-    public $CFG = null;
60
-
61
-    /**
62
-     * EE_Network_Config Object
63
-     *
64
-     * @access public
65
-     * @var EE_Network_Config $NET_CFG
66
-     */
67
-    public $NET_CFG = null;
68
-
69
-    /**
70
-     *    StdClass object for storing library classes in
71
-     *
72
-     * @public LIB
73
-     * @var StdClass $LIB
74
-     */
75
-    public $LIB = null;
76
-
77
-    /**
78
-     *    EE_Request_Handler Object
79
-     *
80
-     * @access    public
81
-     * @var    EE_Request_Handler $REQ
82
-     */
83
-    public $REQ = null;
84
-
85
-    /**
86
-     *    EE_Session Object
87
-     *
88
-     * @access    public
89
-     * @var    EE_Session $SSN
90
-     */
91
-    public $SSN = null;
92
-
93
-    /**
94
-     * holds the ee capabilities object.
95
-     *
96
-     * @since 4.5.0
97
-     * @var EE_Capabilities
98
-     */
99
-    public $CAP = null;
100
-
101
-    /**
102
-     * holds the EE_Message_Resource_Manager object.
103
-     *
104
-     * @since 4.9.0
105
-     * @var EE_Message_Resource_Manager
106
-     */
107
-    public $MRM = null;
108
-
109
-
110
-    /**
111
-     * Holds the Assets Registry instance
112
-     * @var Registry
113
-     */
114
-    public $AssetsRegistry = null;
115
-
116
-    /**
117
-     *    $addons - StdClass object for holding addons which have registered themselves to work with EE core
118
-     *
119
-     * @access    public
120
-     * @var    EE_Addon[]
121
-     */
122
-    public $addons = null;
123
-
124
-    /**
125
-     *    $models
126
-     * @access    public
127
-     * @var    EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
128
-     */
129
-    public $models = array();
130
-
131
-    /**
132
-     *    $modules
133
-     * @access    public
134
-     * @var    EED_Module[] $modules
135
-     */
136
-    public $modules = null;
137
-
138
-    /**
139
-     *    $shortcodes
140
-     * @access    public
141
-     * @var    EES_Shortcode[] $shortcodes
142
-     */
143
-    public $shortcodes = null;
144
-
145
-    /**
146
-     *    $widgets
147
-     * @access    public
148
-     * @var    WP_Widget[] $widgets
149
-     */
150
-    public $widgets = null;
151
-
152
-    /**
153
-     * $non_abstract_db_models
154
-     * @access public
155
-     * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models
156
-     * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
157
-     * Keys are model "short names" (eg "Event") as used in model relations, and values are
158
-     * classnames (eg "EEM_Event")
159
-     */
160
-    public $non_abstract_db_models = array();
161
-
162
-
163
-    /**
164
-     *    $i18n_js_strings - internationalization for JS strings
165
-     *    usage:   EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' );
166
-     *    in js file:  var translatedString = eei18n.string_key;
167
-     *
168
-     * @access    public
169
-     * @var    array
170
-     */
171
-    public static $i18n_js_strings = array();
172
-
173
-
174
-    /**
175
-     *    $main_file - path to espresso.php
176
-     *
177
-     * @access    public
178
-     * @var    array
179
-     */
180
-    public $main_file;
181
-
182
-    /**
183
-     * array of ReflectionClass objects where the key is the class name
184
-     *
185
-     * @access    public
186
-     * @var ReflectionClass[]
187
-     */
188
-    public $_reflectors;
189
-
190
-    /**
191
-     * boolean flag to indicate whether or not to load/save dependencies from/to the cache
192
-     *
193
-     * @access    protected
194
-     * @var boolean $_cache_on
195
-     */
196
-    protected $_cache_on = true;
197
-
198
-
199
-
200
-    /**
201
-     * @singleton method used to instantiate class object
202
-     * @access    public
203
-     * @param  \EE_Dependency_Map $dependency_map
204
-     * @return \EE_Registry instance
205
-     */
206
-    public static function instance(\EE_Dependency_Map $dependency_map = null)
207
-    {
208
-        // check if class object is instantiated
209
-        if ( ! self::$_instance instanceof EE_Registry) {
210
-            self::$_instance = new EE_Registry($dependency_map);
211
-        }
212
-        return self::$_instance;
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     *protected constructor to prevent direct creation
219
-     *
220
-     * @Constructor
221
-     * @access protected
222
-     * @param  \EE_Dependency_Map $dependency_map
223
-     * @return \EE_Registry
224
-     */
225
-    protected function __construct(\EE_Dependency_Map $dependency_map)
226
-    {
227
-        $this->_dependency_map = $dependency_map;
228
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
229
-    }
230
-
231
-
232
-
233
-    /**
234
-     * initialize
235
-     */
236
-    public function initialize()
237
-    {
238
-        $this->_class_abbreviations = apply_filters(
239
-            'FHEE__EE_Registry____construct___class_abbreviations',
240
-            array(
241
-                'EE_Config'                                       => 'CFG',
242
-                'EE_Session'                                      => 'SSN',
243
-                'EE_Capabilities'                                 => 'CAP',
244
-                'EE_Cart'                                         => 'CART',
245
-                'EE_Network_Config'                               => 'NET_CFG',
246
-                'EE_Request_Handler'                              => 'REQ',
247
-                'EE_Message_Resource_Manager'                     => 'MRM',
248
-                'EventEspresso\core\services\commands\CommandBus' => 'BUS',
249
-                'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
250
-            )
251
-        );
252
-        // class library
253
-        $this->LIB = new stdClass();
254
-        $this->addons = new stdClass();
255
-        $this->modules = new stdClass();
256
-        $this->shortcodes = new stdClass();
257
-        $this->widgets = new stdClass();
258
-        $this->load_core('Base', array(), true);
259
-        // add our request and response objects to the cache
260
-        $request_loader = $this->_dependency_map->class_loader('EE_Request');
261
-        $this->_set_cached_class(
262
-            $request_loader(),
263
-            'EE_Request'
264
-        );
265
-        $response_loader = $this->_dependency_map->class_loader('EE_Response');
266
-        $this->_set_cached_class(
267
-            $response_loader(),
268
-            'EE_Response'
269
-        );
270
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     *    init
277
-     *
278
-     * @access    public
279
-     * @return    void
280
-     */
281
-    public function init()
282
-    {
283
-        // Get current page protocol
284
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
285
-        // Output admin-ajax.php URL with same protocol as current page
286
-        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
287
-        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
288
-    }
289
-
290
-
291
-
292
-    /**
293
-     * localize_i18n_js_strings
294
-     *
295
-     * @return string
296
-     */
297
-    public static function localize_i18n_js_strings()
298
-    {
299
-        $i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
300
-        foreach ($i18n_js_strings as $key => $value) {
301
-            if (is_scalar($value)) {
302
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
303
-            }
304
-        }
305
-        return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
306
-    }
307
-
308
-
309
-
310
-    /**
311
-     * @param mixed string | EED_Module $module
312
-     */
313
-    public function add_module($module)
314
-    {
315
-        if ($module instanceof EED_Module) {
316
-            $module_class = get_class($module);
317
-            $this->modules->{$module_class} = $module;
318
-        } else {
319
-            if ( ! class_exists('EE_Module_Request_Router')) {
320
-                $this->load_core('Module_Request_Router');
321
-            }
322
-            $this->modules->{$module} = EE_Module_Request_Router::module_factory($module);
323
-        }
324
-    }
325
-
326
-
327
-
328
-    /**
329
-     * @param string $module_name
330
-     * @return mixed EED_Module | NULL
331
-     */
332
-    public function get_module($module_name = '')
333
-    {
334
-        return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null;
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     *    loads core classes - must be singletons
341
-     *
342
-     * @access    public
343
-     * @param string $class_name - simple class name ie: session
344
-     * @param mixed  $arguments
345
-     * @param bool   $load_only
346
-     * @return mixed
347
-     */
348
-    public function load_core($class_name, $arguments = array(), $load_only = false)
349
-    {
350
-        $core_paths = apply_filters(
351
-            'FHEE__EE_Registry__load_core__core_paths',
352
-            array(
353
-                EE_CORE,
354
-                EE_ADMIN,
355
-                EE_CPTS,
356
-                EE_CORE . 'data_migration_scripts' . DS,
357
-                EE_CORE . 'request_stack' . DS,
358
-                EE_CORE . 'middleware' . DS,
359
-            )
360
-        );
361
-        // retrieve instantiated class
362
-        return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only);
363
-    }
364
-
365
-
366
-
367
-    /**
368
-     *    loads service classes
369
-     *
370
-     * @access    public
371
-     * @param string $class_name - simple class name ie: session
372
-     * @param mixed  $arguments
373
-     * @param bool   $load_only
374
-     * @return mixed
375
-     */
376
-    public function load_service($class_name, $arguments = array(), $load_only = false)
377
-    {
378
-        $service_paths = apply_filters(
379
-            'FHEE__EE_Registry__load_service__service_paths',
380
-            array(
381
-                EE_CORE . 'services' . DS,
382
-            )
383
-        );
384
-        // retrieve instantiated class
385
-        return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only);
386
-    }
387
-
388
-
389
-
390
-    /**
391
-     *    loads data_migration_scripts
392
-     *
393
-     * @access    public
394
-     * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
395
-     * @param mixed  $arguments
396
-     * @return EE_Data_Migration_Script_Base|mixed
397
-     */
398
-    public function load_dms($class_name, $arguments = array())
399
-    {
400
-        // retrieve instantiated class
401
-        return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false);
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     *    loads object creating classes - must be singletons
408
-     *
409
-     * @param string $class_name - simple class name ie: attendee
410
-     * @param mixed  $arguments  - an array of arguments to pass to the class
411
-     * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to instantiate
412
-     * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop)
413
-     * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate (default)
414
-     * @return EE_Base_Class | bool
415
-     */
416
-    public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
417
-    {
418
-        $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array(
419
-            EE_CORE,
420
-            EE_CLASSES,
421
-            EE_BUSINESS,
422
-        ));
423
-        // retrieve instantiated class
424
-        return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only);
425
-    }
426
-
427
-
428
-
429
-    /**
430
-     *    loads helper classes - must be singletons
431
-     *
432
-     * @param string $class_name - simple class name ie: price
433
-     * @param mixed  $arguments
434
-     * @param bool   $load_only
435
-     * @return EEH_Base | bool
436
-     */
437
-    public function load_helper($class_name, $arguments = array(), $load_only = true)
438
-    {
439
-        // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
440
-        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
441
-        // retrieve instantiated class
442
-        return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only);
443
-    }
444
-
445
-
446
-
447
-    /**
448
-     *    loads core classes - must be singletons
449
-     *
450
-     * @access    public
451
-     * @param string $class_name - simple class name ie: session
452
-     * @param mixed  $arguments
453
-     * @param bool   $load_only
454
-     * @param bool   $cache      whether to cache the object or not.
455
-     * @return mixed
456
-     */
457
-    public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
458
-    {
459
-        $paths = array(
460
-            EE_LIBRARIES,
461
-            EE_LIBRARIES . 'messages' . DS,
462
-            EE_LIBRARIES . 'shortcodes' . DS,
463
-            EE_LIBRARIES . 'qtips' . DS,
464
-            EE_LIBRARIES . 'payment_methods' . DS,
465
-        );
466
-        // retrieve instantiated class
467
-        return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
468
-    }
469
-
470
-
471
-
472
-    /**
473
-     *    loads model classes - must be singletons
474
-     *
475
-     * @param string $class_name - simple class name ie: price
476
-     * @param mixed  $arguments
477
-     * @param bool   $load_only
478
-     * @return EEM_Base | bool
479
-     */
480
-    public function load_model($class_name, $arguments = array(), $load_only = false)
481
-    {
482
-        $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array(
483
-            EE_MODELS,
484
-            EE_CORE,
485
-        ));
486
-        // retrieve instantiated class
487
-        return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only);
488
-    }
489
-
490
-
491
-
492
-    /**
493
-     *    loads model classes - must be singletons
494
-     *
495
-     * @param string $class_name - simple class name ie: price
496
-     * @param mixed  $arguments
497
-     * @param bool   $load_only
498
-     * @return mixed | bool
499
-     */
500
-    public function load_model_class($class_name, $arguments = array(), $load_only = true)
501
-    {
502
-        $paths = array(
503
-            EE_MODELS . 'fields' . DS,
504
-            EE_MODELS . 'helpers' . DS,
505
-            EE_MODELS . 'relations' . DS,
506
-            EE_MODELS . 'strategies' . DS,
507
-        );
508
-        // retrieve instantiated class
509
-        return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
510
-    }
511
-
512
-
513
-
514
-    /**
515
-     * Determines if $model_name is the name of an actual EE model.
516
-     *
517
-     * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
518
-     * @return boolean
519
-     */
520
-    public function is_model_name($model_name)
521
-    {
522
-        return isset($this->models[$model_name]) ? true : false;
523
-    }
524
-
525
-
526
-
527
-    /**
528
-     *    generic class loader
529
-     *
530
-     * @param string $path_to_file - directory path to file location, not including filename
531
-     * @param string $file_name    - file name  ie:  my_file.php, including extension
532
-     * @param string $type         - file type - core? class? helper? model?
533
-     * @param mixed  $arguments
534
-     * @param bool   $load_only
535
-     * @return mixed
536
-     */
537
-    public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
538
-    {
539
-        // retrieve instantiated class
540
-        return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only);
541
-    }
542
-
543
-
544
-
545
-    /**
546
-     *    load_addon
547
-     *
548
-     * @param string $path_to_file - directory path to file location, not including filename
549
-     * @param string $class_name   - full class name  ie:  My_Class
550
-     * @param string $type         - file type - core? class? helper? model?
551
-     * @param mixed  $arguments
552
-     * @param bool   $load_only
553
-     * @return EE_Addon
554
-     */
555
-    public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
556
-    {
557
-        // retrieve instantiated class
558
-        return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only);
559
-    }
560
-
561
-
562
-
563
-    /**
564
-     * instantiates, caches, and automatically resolves dependencies
565
-     * for classes that use a Fully Qualified Class Name.
566
-     * if the class is not capable of being loaded using PSR-4 autoloading,
567
-     * then you need to use one of the existing load_*() methods
568
-     * which can resolve the classname and filepath from the passed arguments
569
-     *
570
-     * @param bool|string $class_name   Fully Qualified Class Name
571
-     * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
572
-     * @param bool        $cache        whether to cache the instantiated object for reuse
573
-     * @param bool        $from_db      some classes are instantiated from the db
574
-     *                                  and thus call a different method to instantiate
575
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
576
-     * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
577
-     * @return mixed                    null = failure to load or instantiate class object.
578
-     *                                  object = class loaded and instantiated successfully.
579
-     *                                  bool = fail or success when $load_only is true
580
-     */
581
-    public function create(
582
-        $class_name = false,
583
-        $arguments = array(),
584
-        $cache = false,
585
-        $from_db = false,
586
-        $load_only = false,
587
-        $addon = false
588
-    ) {
589
-        $class_name = ltrim($class_name, '\\');
590
-        $class_name = $this->_dependency_map->get_alias($class_name);
591
-        if ( ! class_exists($class_name)) {
592
-            // maybe the class is registered with a preceding \
593
-            $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name;
594
-            // still doesn't exist ?
595
-            if ( ! class_exists($class_name)) {
596
-                return null;
597
-            }
598
-        }
599
-        // if we're only loading the class and it already exists, then let's just return true immediately
600
-        if ($load_only) {
601
-            return true;
602
-        }
603
-        $addon = $addon ? 'addon' : '';
604
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
605
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
606
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
607
-        if ($this->_cache_on && $cache && ! $load_only) {
608
-            // return object if it's already cached
609
-            $cached_class = $this->_get_cached_class($class_name, $addon);
610
-            if ($cached_class !== null) {
611
-                return $cached_class;
612
-            }
613
-        }
614
-        // instantiate the requested object
615
-        $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
616
-        if ($this->_cache_on && $cache) {
617
-            // save it for later... kinda like gum  { : $
618
-            $this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
619
-        }
620
-        $this->_cache_on = true;
621
-        return $class_obj;
622
-    }
623
-
624
-
625
-
626
-    /**
627
-     * instantiates, caches, and injects dependencies for classes
628
-     *
629
-     * @param array       $file_paths   an array of paths to folders to look in
630
-     * @param string      $class_prefix EE  or EEM or... ???
631
-     * @param bool|string $class_name   $class name
632
-     * @param string      $type         file type - core? class? helper? model?
633
-     * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
634
-     * @param bool        $from_db      some classes are instantiated from the db
635
-     *                                  and thus call a different method to instantiate
636
-     * @param bool        $cache        whether to cache the instantiated object for reuse
637
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
638
-     * @return null|object|bool         null = failure to load or instantiate class object.
639
-     *                                  object = class loaded and instantiated successfully.
640
-     *                                  bool = fail or success when $load_only is true
641
-     */
642
-    protected function _load(
643
-        $file_paths = array(),
644
-        $class_prefix = 'EE_',
645
-        $class_name = false,
646
-        $type = 'class',
647
-        $arguments = array(),
648
-        $from_db = false,
649
-        $cache = true,
650
-        $load_only = false
651
-    ) {
652
-        $class_name = ltrim($class_name, '\\');
653
-        // strip php file extension
654
-        $class_name = str_replace('.php', '', trim($class_name));
655
-        // does the class have a prefix ?
656
-        if ( ! empty($class_prefix) && $class_prefix != 'addon') {
657
-            // make sure $class_prefix is uppercase
658
-            $class_prefix = strtoupper(trim($class_prefix));
659
-            // add class prefix ONCE!!!
660
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
661
-        }
662
-        $class_name = $this->_dependency_map->get_alias($class_name);
663
-        $class_exists = class_exists($class_name);
664
-        // if we're only loading the class and it already exists, then let's just return true immediately
665
-        if ($load_only && $class_exists) {
666
-            return true;
667
-        }
668
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
669
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
670
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
671
-        if ($this->_cache_on && $cache && ! $load_only) {
672
-            // return object if it's already cached
673
-            $cached_class = $this->_get_cached_class($class_name, $class_prefix);
674
-            if ($cached_class !== null) {
675
-                return $cached_class;
676
-            }
677
-        }
678
-        // if the class doesn't already exist.. then we need to try and find the file and load it
679
-        if ( ! $class_exists) {
680
-            // get full path to file
681
-            $path = $this->_resolve_path($class_name, $type, $file_paths);
682
-            // load the file
683
-            $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
684
-            // if loading failed, or we are only loading a file but NOT instantiating an object
685
-            if ( ! $loaded || $load_only) {
686
-                // return boolean if only loading, or null if an object was expected
687
-                return $load_only ? $loaded : null;
688
-            }
689
-        }
690
-        // instantiate the requested object
691
-        $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
692
-        if ($this->_cache_on && $cache) {
693
-            // save it for later... kinda like gum  { : $
694
-            $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
695
-        }
696
-        $this->_cache_on = true;
697
-        return $class_obj;
698
-    }
699
-
700
-
701
-
702
-    /**
703
-     * _get_cached_class
704
-     * attempts to find a cached version of the requested class
705
-     * by looking in the following places:
706
-     *        $this->{$class_abbreviation}            ie:    $this->CART
707
-     *        $this->{$class_name}                        ie:    $this->Some_Class
708
-     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
709
-     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
710
-     *
711
-     * @access protected
712
-     * @param string $class_name
713
-     * @param string $class_prefix
714
-     * @return mixed
715
-     */
716
-    protected function _get_cached_class($class_name, $class_prefix = '')
717
-    {
718
-        if (isset($this->_class_abbreviations[$class_name])) {
719
-            $class_abbreviation = $this->_class_abbreviations[$class_name];
720
-        } else {
721
-            // have to specify something, but not anything that will conflict
722
-            $class_abbreviation = 'FANCY_BATMAN_PANTS';
723
-        }
724
-        // check if class has already been loaded, and return it if it has been
725
-        if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
726
-            return $this->{$class_abbreviation};
727
-        } else if (isset ($this->{$class_name})) {
728
-            return $this->{$class_name};
729
-        } else if (isset ($this->LIB->{$class_name})) {
730
-            return $this->LIB->{$class_name};
731
-        } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) {
732
-            return $this->addons->{$class_name};
733
-        }
734
-        return null;
735
-    }
736
-
737
-
738
-
739
-    /**
740
-     * _resolve_path
741
-     * attempts to find a full valid filepath for the requested class.
742
-     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
743
-     * then returns that path if the target file has been found and is readable
744
-     *
745
-     * @access protected
746
-     * @param string $class_name
747
-     * @param string $type
748
-     * @param array  $file_paths
749
-     * @return string | bool
750
-     */
751
-    protected function _resolve_path($class_name, $type = '', $file_paths = array())
752
-    {
753
-        // make sure $file_paths is an array
754
-        $file_paths = is_array($file_paths) ? $file_paths : array($file_paths);
755
-        // cycle thru paths
756
-        foreach ($file_paths as $key => $file_path) {
757
-            // convert all separators to proper DS, if no filepath, then use EE_CLASSES
758
-            $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
759
-            // prep file type
760
-            $type = ! empty($type) ? trim($type, '.') . '.' : '';
761
-            // build full file path
762
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
763
-            //does the file exist and can be read ?
764
-            if (is_readable($file_paths[$key])) {
765
-                return $file_paths[$key];
766
-            }
767
-        }
768
-        return false;
769
-    }
770
-
771
-
772
-
773
-    /**
774
-     * _require_file
775
-     * basically just performs a require_once()
776
-     * but with some error handling
777
-     *
778
-     * @access protected
779
-     * @param  string $path
780
-     * @param  string $class_name
781
-     * @param  string $type
782
-     * @param  array  $file_paths
783
-     * @return boolean
784
-     * @throws \EE_Error
785
-     */
786
-    protected function _require_file($path, $class_name, $type = '', $file_paths = array())
787
-    {
788
-        // don't give up! you gotta...
789
-        try {
790
-            //does the file exist and can it be read ?
791
-            if ( ! $path) {
792
-                // so sorry, can't find the file
793
-                throw new EE_Error (
794
-                    sprintf(
795
-                        __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'),
796
-                        trim($type, '.'),
797
-                        $class_name,
798
-                        '<br />' . implode(',<br />', $file_paths)
799
-                    )
800
-                );
801
-            }
802
-            // get the file
803
-            require_once($path);
804
-            // if the class isn't already declared somewhere
805
-            if (class_exists($class_name, false) === false) {
806
-                // so sorry, not a class
807
-                throw new EE_Error(
808
-                    sprintf(
809
-                        __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
810
-                        $type,
811
-                        $path,
812
-                        $class_name
813
-                    )
814
-                );
815
-            }
816
-        } catch (EE_Error $e) {
817
-            $e->get_error();
818
-            return false;
819
-        }
820
-        return true;
821
-    }
822
-
823
-
824
-
825
-    /**
826
-     * _create_object
827
-     * Attempts to instantiate the requested class via any of the
828
-     * commonly used instantiation methods employed throughout EE.
829
-     * The priority for instantiation is as follows:
830
-     *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
831
-     *        - model objects via their 'new_instance_from_db' method
832
-     *        - model objects via their 'new_instance' method
833
-     *        - "singleton" classes" via their 'instance' method
834
-     *    - standard instantiable classes via their __constructor
835
-     * Prior to instantiation, if the classname exists in the dependency_map,
836
-     * then the constructor for the requested class will be examined to determine
837
-     * if any dependencies exist, and if they can be injected.
838
-     * If so, then those classes will be added to the array of arguments passed to the constructor
839
-     *
840
-     * @access protected
841
-     * @param string $class_name
842
-     * @param array  $arguments
843
-     * @param string $type
844
-     * @param bool   $from_db
845
-     * @return null | object
846
-     * @throws \EE_Error
847
-     */
848
-    protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
849
-    {
850
-        $class_obj = null;
851
-        $instantiation_mode = '0) none';
852
-        // don't give up! you gotta...
853
-        try {
854
-            // create reflection
855
-            $reflector = $this->get_ReflectionClass($class_name);
856
-            // make sure arguments are an array
857
-            $arguments = is_array($arguments) ? $arguments : array($arguments);
858
-            // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
859
-            // else wrap it in an additional array so that it doesn't get split into multiple parameters
860
-            $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
861
-                ? $arguments
862
-                : array($arguments);
863
-            // attempt to inject dependencies ?
864
-            if ($this->_dependency_map->has($class_name)) {
865
-                $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
866
-            }
867
-            // instantiate the class if possible
868
-            if ($reflector->isAbstract()) {
869
-                // nothing to instantiate, loading file was enough
870
-                // does not throw an exception so $instantiation_mode is unused
871
-                // $instantiation_mode = "1) no constructor abstract class";
872
-                $class_obj = true;
873
-            } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) {
874
-                // no constructor = static methods only... nothing to instantiate, loading file was enough
875
-                $instantiation_mode = "2) no constructor but instantiable";
876
-                $class_obj = $reflector->newInstance();
877
-            } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
878
-                $instantiation_mode = "3) new_instance_from_db()";
879
-                $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
880
-            } else if (method_exists($class_name, 'new_instance')) {
881
-                $instantiation_mode = "4) new_instance()";
882
-                $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
883
-            } else if (method_exists($class_name, 'instance')) {
884
-                $instantiation_mode = "5) instance()";
885
-                $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
886
-            } else if ($reflector->isInstantiable()) {
887
-                $instantiation_mode = "6) constructor";
888
-                $class_obj = $reflector->newInstanceArgs($arguments);
889
-            } else {
890
-                // heh ? something's not right !
891
-                throw new EE_Error(
892
-                    sprintf(
893
-                        __('The %s file %s could not be instantiated.', 'event_espresso'),
894
-                        $type,
895
-                        $class_name
896
-                    )
897
-                );
898
-            }
899
-        } catch (Exception $e) {
900
-            if ( ! $e instanceof EE_Error) {
901
-                $e = new EE_Error(
902
-                    sprintf(
903
-                        __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'),
904
-                        $class_name,
905
-                        '<br />',
906
-                        $e->getMessage(),
907
-                        $instantiation_mode
908
-                    )
909
-                );
910
-            }
911
-            $e->get_error();
912
-        }
913
-        return $class_obj;
914
-    }
915
-
916
-
917
-
918
-    /**
919
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
920
-     * @param array $array
921
-     * @return bool
922
-     */
923
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
924
-    {
925
-        return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
926
-    }
927
-
928
-
929
-
930
-    /**
931
-     * getReflectionClass
932
-     * checks if a ReflectionClass object has already been generated for a class
933
-     * and returns that instead of creating a new one
934
-     *
935
-     * @access public
936
-     * @param string $class_name
937
-     * @return ReflectionClass
938
-     */
939
-    public function get_ReflectionClass($class_name)
940
-    {
941
-        if (
942
-            ! isset($this->_reflectors[$class_name])
943
-            || ! $this->_reflectors[$class_name] instanceof ReflectionClass
944
-        ) {
945
-            $this->_reflectors[$class_name] = new ReflectionClass($class_name);
946
-        }
947
-        return $this->_reflectors[$class_name];
948
-    }
949
-
950
-
951
-
952
-    /**
953
-     * _resolve_dependencies
954
-     * examines the constructor for the requested class to determine
955
-     * if any dependencies exist, and if they can be injected.
956
-     * If so, then those classes will be added to the array of arguments passed to the constructor
957
-     * PLZ NOTE: this is achieved by type hinting the constructor params
958
-     * For example:
959
-     *        if attempting to load a class "Foo" with the following constructor:
960
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
961
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
962
-     *        but only IF they are NOT already present in the incoming arguments array,
963
-     *        and the correct classes can be loaded
964
-     *
965
-     * @access protected
966
-     * @param ReflectionClass $reflector
967
-     * @param string          $class_name
968
-     * @param array           $arguments
969
-     * @return array
970
-     * @throws \ReflectionException
971
-     */
972
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
973
-    {
974
-        // let's examine the constructor
975
-        $constructor = $reflector->getConstructor();
976
-        // whu? huh? nothing?
977
-        if ( ! $constructor) {
978
-            return $arguments;
979
-        }
980
-        // get constructor parameters
981
-        $params = $constructor->getParameters();
982
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
983
-        $argument_keys = array_keys($arguments);
984
-        // now loop thru all of the constructors expected parameters
985
-        foreach ($params as $index => $param) {
986
-            // is this a dependency for a specific class ?
987
-            $param_class = $param->getClass() ? $param->getClass()->name : null;
988
-            if (
989
-                // param is not even a class
990
-                empty($param_class)
991
-                // and something already exists in the incoming arguments for this param
992
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
993
-            ) {
994
-                // so let's skip this argument and move on to the next
995
-                continue;
996
-            } else if (
997
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
998
-                ! empty($param_class)
999
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1000
-                && $arguments[$argument_keys[$index]] instanceof $param_class
1001
-            ) {
1002
-                // skip this argument and move on to the next
1003
-                continue;
1004
-            } else if (
1005
-                // parameter is type hinted as a class, and should be injected
1006
-                ! empty($param_class)
1007
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1008
-            ) {
1009
-                $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index);
1010
-            } else {
1011
-                try {
1012
-                    $arguments[$index] = $param->getDefaultValue();
1013
-                } catch (ReflectionException $e) {
1014
-                    throw new ReflectionException(
1015
-                        sprintf(
1016
-                            __('%1$s for parameter "$%2$s"', 'event_espresso'),
1017
-                            $e->getMessage(),
1018
-                            $param->getName()
1019
-                        )
1020
-                    );
1021
-                }
1022
-            }
1023
-        }
1024
-        return $arguments;
1025
-    }
1026
-
1027
-
1028
-
1029
-    /**
1030
-     * @access protected
1031
-     * @param string $class_name
1032
-     * @param string $param_class
1033
-     * @param array  $arguments
1034
-     * @param mixed  $index
1035
-     * @return array
1036
-     */
1037
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1038
-    {
1039
-        $dependency = null;
1040
-        // should dependency be loaded from cache ?
1041
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class)
1042
-                    !== EE_Dependency_Map::load_new_object
1043
-            ? true
1044
-            : false;
1045
-        // we might have a dependency...
1046
-        // let's MAYBE try and find it in our cache if that's what's been requested
1047
-        $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null;
1048
-        // and grab it if it exists
1049
-        if ($cached_class instanceof $param_class) {
1050
-            $dependency = $cached_class;
1051
-        } else if ($param_class != $class_name) {
1052
-            // obtain the loader method from the dependency map
1053
-            $loader = $this->_dependency_map->class_loader($param_class);
1054
-            // is loader a custom closure ?
1055
-            if ($loader instanceof Closure) {
1056
-                $dependency = $loader();
1057
-            } else {
1058
-                // set the cache on property for the recursive loading call
1059
-                $this->_cache_on = $cache_on;
1060
-                // if not, then let's try and load it via the registry
1061
-                if (method_exists($this, $loader)) {
1062
-                    $dependency = $this->{$loader}($param_class);
1063
-                } else {
1064
-                    $dependency = $this->create($param_class, array(), $cache_on);
1065
-                }
1066
-            }
1067
-        }
1068
-        // did we successfully find the correct dependency ?
1069
-        if ($dependency instanceof $param_class) {
1070
-            // then let's inject it into the incoming array of arguments at the correct location
1071
-            if (isset($argument_keys[$index])) {
1072
-                $arguments[$argument_keys[$index]] = $dependency;
1073
-            } else {
1074
-                $arguments[$index] = $dependency;
1075
-            }
1076
-        }
1077
-        return $arguments;
1078
-    }
1079
-
1080
-
1081
-
1082
-    /**
1083
-     * _set_cached_class
1084
-     * attempts to cache the instantiated class locally
1085
-     * in one of the following places, in the following order:
1086
-     *        $this->{class_abbreviation}   ie:    $this->CART
1087
-     *        $this->{$class_name}          ie:    $this->Some_Class
1088
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1089
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1090
-     *
1091
-     * @access protected
1092
-     * @param object $class_obj
1093
-     * @param string $class_name
1094
-     * @param string $class_prefix
1095
-     * @param bool   $from_db
1096
-     * @return void
1097
-     */
1098
-    protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1099
-    {
1100
-        if (empty($class_obj)) {
1101
-            return;
1102
-        }
1103
-        // return newly instantiated class
1104
-        if (isset($this->_class_abbreviations[$class_name])) {
1105
-            $class_abbreviation = $this->_class_abbreviations[$class_name];
1106
-            $this->{$class_abbreviation} = $class_obj;
1107
-        } else if (property_exists($this, $class_name)) {
1108
-            $this->{$class_name} = $class_obj;
1109
-        } else if ($class_prefix == 'addon') {
1110
-            $this->addons->{$class_name} = $class_obj;
1111
-        } else if ( ! $from_db) {
1112
-            $this->LIB->{$class_name} = $class_obj;
1113
-        }
1114
-    }
1115
-
1116
-
1117
-
1118
-    /**
1119
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1120
-     *
1121
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1122
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1123
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1124
-     * @param array  $arguments
1125
-     * @return object
1126
-     */
1127
-    public static function factory($classname, $arguments = array())
1128
-    {
1129
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1130
-        if ($loader instanceof Closure) {
1131
-            return $loader($arguments);
1132
-        } else if (method_exists(EE_Registry::instance(), $loader)) {
1133
-            return EE_Registry::instance()->{$loader}($classname, $arguments);
1134
-        }
1135
-        return null;
1136
-    }
1137
-
1138
-
1139
-
1140
-    /**
1141
-     * Gets the addon by its name/slug (not classname. For that, just
1142
-     * use the classname as the property name on EE_Config::instance()->addons)
1143
-     *
1144
-     * @param string $name
1145
-     * @return EE_Addon
1146
-     */
1147
-    public function get_addon_by_name($name)
1148
-    {
1149
-        foreach ($this->addons as $addon) {
1150
-            if ($addon->name() == $name) {
1151
-                return $addon;
1152
-            }
1153
-        }
1154
-        return null;
1155
-    }
1156
-
1157
-
1158
-
1159
-    /**
1160
-     * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is
1161
-     * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname}
1162
-     *
1163
-     * @return EE_Addon[] where the KEYS are the addon's name()
1164
-     */
1165
-    public function get_addons_by_name()
1166
-    {
1167
-        $addons = array();
1168
-        foreach ($this->addons as $addon) {
1169
-            $addons[$addon->name()] = $addon;
1170
-        }
1171
-        return $addons;
1172
-    }
1173
-
1174
-
1175
-
1176
-    /**
1177
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1178
-     * a stale copy of it around
1179
-     *
1180
-     * @param string $model_name
1181
-     * @return \EEM_Base
1182
-     * @throws \EE_Error
1183
-     */
1184
-    public function reset_model($model_name)
1185
-    {
1186
-        $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name;
1187
-        if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1188
-            return null;
1189
-        }
1190
-        //get that model reset it and make sure we nuke the old reference to it
1191
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) {
1192
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1193
-        } else {
1194
-            throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1195
-        }
1196
-        return $this->LIB->{$model_class_name};
1197
-    }
1198
-
1199
-
1200
-
1201
-    /**
1202
-     * Resets the registry.
1203
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog
1204
-     * is used in a multisite install.  Here is a list of things that are NOT reset.
1205
-     * - $_dependency_map
1206
-     * - $_class_abbreviations
1207
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1208
-     * - $REQ:  Still on the same request so no need to change.
1209
-     * - $CAP: There is no site specific state in the EE_Capability class.
1210
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session
1211
-     *         can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1212
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1213
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1214
-     *             switch or on the restore.
1215
-     * - $modules
1216
-     * - $shortcodes
1217
-     * - $widgets
1218
-     *
1219
-     * @param boolean $hard             whether to reset data in the database too, or just refresh
1220
-     *                                  the Registry to its state at the beginning of the request
1221
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1222
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
1223
-     *                                  currently reinstantiate the singletons at the moment)
1224
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so client
1225
-     *                                  code instead can just change the model context to a different blog id if necessary
1226
-     * @return EE_Registry
1227
-     */
1228
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1229
-    {
1230
-        $instance = self::instance();
1231
-        EEH_Activation::reset();
1232
-        //properties that get reset
1233
-        $instance->_cache_on = true;
1234
-        $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1235
-        $instance->CART = null;
1236
-        $instance->MRM = null;
1237
-        $instance->AssetsRegistry = null;
1238
-        $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1239
-        //messages reset
1240
-        EED_Messages::reset();
1241
-        if ($reset_models) {
1242
-            foreach (array_keys($instance->non_abstract_db_models) as $model_name) {
1243
-                $instance->reset_model($model_name);
1244
-            }
1245
-        }
1246
-        $instance->LIB = new stdClass();
1247
-        return $instance;
1248
-    }
1249
-
1250
-
1251
-
1252
-    /**
1253
-     * @override magic methods
1254
-     * @return void
1255
-     */
1256
-    public final function __destruct()
1257
-    {
1258
-    }
1259
-
1260
-
1261
-
1262
-    /**
1263
-     * @param $a
1264
-     * @param $b
1265
-     */
1266
-    public final function __call($a, $b)
1267
-    {
1268
-    }
1269
-
1270
-
1271
-
1272
-    /**
1273
-     * @param $a
1274
-     */
1275
-    public final function __get($a)
1276
-    {
1277
-    }
1278
-
1279
-
1280
-
1281
-    /**
1282
-     * @param $a
1283
-     * @param $b
1284
-     */
1285
-    public final function __set($a, $b)
1286
-    {
1287
-    }
1288
-
1289
-
1290
-
1291
-    /**
1292
-     * @param $a
1293
-     */
1294
-    public final function __isset($a)
1295
-    {
1296
-    }
19
+	/**
20
+	 *    EE_Registry Object
21
+	 *
22
+	 * @var EE_Registry $_instance
23
+	 * @access    private
24
+	 */
25
+	private static $_instance = null;
26
+
27
+	/**
28
+	 * @var EE_Dependency_Map $_dependency_map
29
+	 * @access    protected
30
+	 */
31
+	protected $_dependency_map = null;
32
+
33
+	/**
34
+	 * @var array $_class_abbreviations
35
+	 * @access    protected
36
+	 */
37
+	protected $_class_abbreviations = array();
38
+
39
+	/**
40
+	 * @access public
41
+	 * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS
42
+	 */
43
+	public $BUS;
44
+
45
+	/**
46
+	 *    EE_Cart Object
47
+	 *
48
+	 * @access    public
49
+	 * @var    EE_Cart $CART
50
+	 */
51
+	public $CART = null;
52
+
53
+	/**
54
+	 *    EE_Config Object
55
+	 *
56
+	 * @access    public
57
+	 * @var    EE_Config $CFG
58
+	 */
59
+	public $CFG = null;
60
+
61
+	/**
62
+	 * EE_Network_Config Object
63
+	 *
64
+	 * @access public
65
+	 * @var EE_Network_Config $NET_CFG
66
+	 */
67
+	public $NET_CFG = null;
68
+
69
+	/**
70
+	 *    StdClass object for storing library classes in
71
+	 *
72
+	 * @public LIB
73
+	 * @var StdClass $LIB
74
+	 */
75
+	public $LIB = null;
76
+
77
+	/**
78
+	 *    EE_Request_Handler Object
79
+	 *
80
+	 * @access    public
81
+	 * @var    EE_Request_Handler $REQ
82
+	 */
83
+	public $REQ = null;
84
+
85
+	/**
86
+	 *    EE_Session Object
87
+	 *
88
+	 * @access    public
89
+	 * @var    EE_Session $SSN
90
+	 */
91
+	public $SSN = null;
92
+
93
+	/**
94
+	 * holds the ee capabilities object.
95
+	 *
96
+	 * @since 4.5.0
97
+	 * @var EE_Capabilities
98
+	 */
99
+	public $CAP = null;
100
+
101
+	/**
102
+	 * holds the EE_Message_Resource_Manager object.
103
+	 *
104
+	 * @since 4.9.0
105
+	 * @var EE_Message_Resource_Manager
106
+	 */
107
+	public $MRM = null;
108
+
109
+
110
+	/**
111
+	 * Holds the Assets Registry instance
112
+	 * @var Registry
113
+	 */
114
+	public $AssetsRegistry = null;
115
+
116
+	/**
117
+	 *    $addons - StdClass object for holding addons which have registered themselves to work with EE core
118
+	 *
119
+	 * @access    public
120
+	 * @var    EE_Addon[]
121
+	 */
122
+	public $addons = null;
123
+
124
+	/**
125
+	 *    $models
126
+	 * @access    public
127
+	 * @var    EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
128
+	 */
129
+	public $models = array();
130
+
131
+	/**
132
+	 *    $modules
133
+	 * @access    public
134
+	 * @var    EED_Module[] $modules
135
+	 */
136
+	public $modules = null;
137
+
138
+	/**
139
+	 *    $shortcodes
140
+	 * @access    public
141
+	 * @var    EES_Shortcode[] $shortcodes
142
+	 */
143
+	public $shortcodes = null;
144
+
145
+	/**
146
+	 *    $widgets
147
+	 * @access    public
148
+	 * @var    WP_Widget[] $widgets
149
+	 */
150
+	public $widgets = null;
151
+
152
+	/**
153
+	 * $non_abstract_db_models
154
+	 * @access public
155
+	 * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models
156
+	 * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
157
+	 * Keys are model "short names" (eg "Event") as used in model relations, and values are
158
+	 * classnames (eg "EEM_Event")
159
+	 */
160
+	public $non_abstract_db_models = array();
161
+
162
+
163
+	/**
164
+	 *    $i18n_js_strings - internationalization for JS strings
165
+	 *    usage:   EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' );
166
+	 *    in js file:  var translatedString = eei18n.string_key;
167
+	 *
168
+	 * @access    public
169
+	 * @var    array
170
+	 */
171
+	public static $i18n_js_strings = array();
172
+
173
+
174
+	/**
175
+	 *    $main_file - path to espresso.php
176
+	 *
177
+	 * @access    public
178
+	 * @var    array
179
+	 */
180
+	public $main_file;
181
+
182
+	/**
183
+	 * array of ReflectionClass objects where the key is the class name
184
+	 *
185
+	 * @access    public
186
+	 * @var ReflectionClass[]
187
+	 */
188
+	public $_reflectors;
189
+
190
+	/**
191
+	 * boolean flag to indicate whether or not to load/save dependencies from/to the cache
192
+	 *
193
+	 * @access    protected
194
+	 * @var boolean $_cache_on
195
+	 */
196
+	protected $_cache_on = true;
197
+
198
+
199
+
200
+	/**
201
+	 * @singleton method used to instantiate class object
202
+	 * @access    public
203
+	 * @param  \EE_Dependency_Map $dependency_map
204
+	 * @return \EE_Registry instance
205
+	 */
206
+	public static function instance(\EE_Dependency_Map $dependency_map = null)
207
+	{
208
+		// check if class object is instantiated
209
+		if ( ! self::$_instance instanceof EE_Registry) {
210
+			self::$_instance = new EE_Registry($dependency_map);
211
+		}
212
+		return self::$_instance;
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 *protected constructor to prevent direct creation
219
+	 *
220
+	 * @Constructor
221
+	 * @access protected
222
+	 * @param  \EE_Dependency_Map $dependency_map
223
+	 * @return \EE_Registry
224
+	 */
225
+	protected function __construct(\EE_Dependency_Map $dependency_map)
226
+	{
227
+		$this->_dependency_map = $dependency_map;
228
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
229
+	}
230
+
231
+
232
+
233
+	/**
234
+	 * initialize
235
+	 */
236
+	public function initialize()
237
+	{
238
+		$this->_class_abbreviations = apply_filters(
239
+			'FHEE__EE_Registry____construct___class_abbreviations',
240
+			array(
241
+				'EE_Config'                                       => 'CFG',
242
+				'EE_Session'                                      => 'SSN',
243
+				'EE_Capabilities'                                 => 'CAP',
244
+				'EE_Cart'                                         => 'CART',
245
+				'EE_Network_Config'                               => 'NET_CFG',
246
+				'EE_Request_Handler'                              => 'REQ',
247
+				'EE_Message_Resource_Manager'                     => 'MRM',
248
+				'EventEspresso\core\services\commands\CommandBus' => 'BUS',
249
+				'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
250
+			)
251
+		);
252
+		// class library
253
+		$this->LIB = new stdClass();
254
+		$this->addons = new stdClass();
255
+		$this->modules = new stdClass();
256
+		$this->shortcodes = new stdClass();
257
+		$this->widgets = new stdClass();
258
+		$this->load_core('Base', array(), true);
259
+		// add our request and response objects to the cache
260
+		$request_loader = $this->_dependency_map->class_loader('EE_Request');
261
+		$this->_set_cached_class(
262
+			$request_loader(),
263
+			'EE_Request'
264
+		);
265
+		$response_loader = $this->_dependency_map->class_loader('EE_Response');
266
+		$this->_set_cached_class(
267
+			$response_loader(),
268
+			'EE_Response'
269
+		);
270
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 *    init
277
+	 *
278
+	 * @access    public
279
+	 * @return    void
280
+	 */
281
+	public function init()
282
+	{
283
+		// Get current page protocol
284
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
285
+		// Output admin-ajax.php URL with same protocol as current page
286
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
287
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
288
+	}
289
+
290
+
291
+
292
+	/**
293
+	 * localize_i18n_js_strings
294
+	 *
295
+	 * @return string
296
+	 */
297
+	public static function localize_i18n_js_strings()
298
+	{
299
+		$i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
300
+		foreach ($i18n_js_strings as $key => $value) {
301
+			if (is_scalar($value)) {
302
+				$i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
303
+			}
304
+		}
305
+		return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
306
+	}
307
+
308
+
309
+
310
+	/**
311
+	 * @param mixed string | EED_Module $module
312
+	 */
313
+	public function add_module($module)
314
+	{
315
+		if ($module instanceof EED_Module) {
316
+			$module_class = get_class($module);
317
+			$this->modules->{$module_class} = $module;
318
+		} else {
319
+			if ( ! class_exists('EE_Module_Request_Router')) {
320
+				$this->load_core('Module_Request_Router');
321
+			}
322
+			$this->modules->{$module} = EE_Module_Request_Router::module_factory($module);
323
+		}
324
+	}
325
+
326
+
327
+
328
+	/**
329
+	 * @param string $module_name
330
+	 * @return mixed EED_Module | NULL
331
+	 */
332
+	public function get_module($module_name = '')
333
+	{
334
+		return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null;
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 *    loads core classes - must be singletons
341
+	 *
342
+	 * @access    public
343
+	 * @param string $class_name - simple class name ie: session
344
+	 * @param mixed  $arguments
345
+	 * @param bool   $load_only
346
+	 * @return mixed
347
+	 */
348
+	public function load_core($class_name, $arguments = array(), $load_only = false)
349
+	{
350
+		$core_paths = apply_filters(
351
+			'FHEE__EE_Registry__load_core__core_paths',
352
+			array(
353
+				EE_CORE,
354
+				EE_ADMIN,
355
+				EE_CPTS,
356
+				EE_CORE . 'data_migration_scripts' . DS,
357
+				EE_CORE . 'request_stack' . DS,
358
+				EE_CORE . 'middleware' . DS,
359
+			)
360
+		);
361
+		// retrieve instantiated class
362
+		return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only);
363
+	}
364
+
365
+
366
+
367
+	/**
368
+	 *    loads service classes
369
+	 *
370
+	 * @access    public
371
+	 * @param string $class_name - simple class name ie: session
372
+	 * @param mixed  $arguments
373
+	 * @param bool   $load_only
374
+	 * @return mixed
375
+	 */
376
+	public function load_service($class_name, $arguments = array(), $load_only = false)
377
+	{
378
+		$service_paths = apply_filters(
379
+			'FHEE__EE_Registry__load_service__service_paths',
380
+			array(
381
+				EE_CORE . 'services' . DS,
382
+			)
383
+		);
384
+		// retrieve instantiated class
385
+		return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only);
386
+	}
387
+
388
+
389
+
390
+	/**
391
+	 *    loads data_migration_scripts
392
+	 *
393
+	 * @access    public
394
+	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
395
+	 * @param mixed  $arguments
396
+	 * @return EE_Data_Migration_Script_Base|mixed
397
+	 */
398
+	public function load_dms($class_name, $arguments = array())
399
+	{
400
+		// retrieve instantiated class
401
+		return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false);
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 *    loads object creating classes - must be singletons
408
+	 *
409
+	 * @param string $class_name - simple class name ie: attendee
410
+	 * @param mixed  $arguments  - an array of arguments to pass to the class
411
+	 * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to instantiate
412
+	 * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop)
413
+	 * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate (default)
414
+	 * @return EE_Base_Class | bool
415
+	 */
416
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
417
+	{
418
+		$paths = apply_filters('FHEE__EE_Registry__load_class__paths', array(
419
+			EE_CORE,
420
+			EE_CLASSES,
421
+			EE_BUSINESS,
422
+		));
423
+		// retrieve instantiated class
424
+		return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only);
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 *    loads helper classes - must be singletons
431
+	 *
432
+	 * @param string $class_name - simple class name ie: price
433
+	 * @param mixed  $arguments
434
+	 * @param bool   $load_only
435
+	 * @return EEH_Base | bool
436
+	 */
437
+	public function load_helper($class_name, $arguments = array(), $load_only = true)
438
+	{
439
+		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
440
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
441
+		// retrieve instantiated class
442
+		return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only);
443
+	}
444
+
445
+
446
+
447
+	/**
448
+	 *    loads core classes - must be singletons
449
+	 *
450
+	 * @access    public
451
+	 * @param string $class_name - simple class name ie: session
452
+	 * @param mixed  $arguments
453
+	 * @param bool   $load_only
454
+	 * @param bool   $cache      whether to cache the object or not.
455
+	 * @return mixed
456
+	 */
457
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
458
+	{
459
+		$paths = array(
460
+			EE_LIBRARIES,
461
+			EE_LIBRARIES . 'messages' . DS,
462
+			EE_LIBRARIES . 'shortcodes' . DS,
463
+			EE_LIBRARIES . 'qtips' . DS,
464
+			EE_LIBRARIES . 'payment_methods' . DS,
465
+		);
466
+		// retrieve instantiated class
467
+		return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
468
+	}
469
+
470
+
471
+
472
+	/**
473
+	 *    loads model classes - must be singletons
474
+	 *
475
+	 * @param string $class_name - simple class name ie: price
476
+	 * @param mixed  $arguments
477
+	 * @param bool   $load_only
478
+	 * @return EEM_Base | bool
479
+	 */
480
+	public function load_model($class_name, $arguments = array(), $load_only = false)
481
+	{
482
+		$paths = apply_filters('FHEE__EE_Registry__load_model__paths', array(
483
+			EE_MODELS,
484
+			EE_CORE,
485
+		));
486
+		// retrieve instantiated class
487
+		return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only);
488
+	}
489
+
490
+
491
+
492
+	/**
493
+	 *    loads model classes - must be singletons
494
+	 *
495
+	 * @param string $class_name - simple class name ie: price
496
+	 * @param mixed  $arguments
497
+	 * @param bool   $load_only
498
+	 * @return mixed | bool
499
+	 */
500
+	public function load_model_class($class_name, $arguments = array(), $load_only = true)
501
+	{
502
+		$paths = array(
503
+			EE_MODELS . 'fields' . DS,
504
+			EE_MODELS . 'helpers' . DS,
505
+			EE_MODELS . 'relations' . DS,
506
+			EE_MODELS . 'strategies' . DS,
507
+		);
508
+		// retrieve instantiated class
509
+		return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
510
+	}
511
+
512
+
513
+
514
+	/**
515
+	 * Determines if $model_name is the name of an actual EE model.
516
+	 *
517
+	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
518
+	 * @return boolean
519
+	 */
520
+	public function is_model_name($model_name)
521
+	{
522
+		return isset($this->models[$model_name]) ? true : false;
523
+	}
524
+
525
+
526
+
527
+	/**
528
+	 *    generic class loader
529
+	 *
530
+	 * @param string $path_to_file - directory path to file location, not including filename
531
+	 * @param string $file_name    - file name  ie:  my_file.php, including extension
532
+	 * @param string $type         - file type - core? class? helper? model?
533
+	 * @param mixed  $arguments
534
+	 * @param bool   $load_only
535
+	 * @return mixed
536
+	 */
537
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
538
+	{
539
+		// retrieve instantiated class
540
+		return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only);
541
+	}
542
+
543
+
544
+
545
+	/**
546
+	 *    load_addon
547
+	 *
548
+	 * @param string $path_to_file - directory path to file location, not including filename
549
+	 * @param string $class_name   - full class name  ie:  My_Class
550
+	 * @param string $type         - file type - core? class? helper? model?
551
+	 * @param mixed  $arguments
552
+	 * @param bool   $load_only
553
+	 * @return EE_Addon
554
+	 */
555
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
556
+	{
557
+		// retrieve instantiated class
558
+		return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only);
559
+	}
560
+
561
+
562
+
563
+	/**
564
+	 * instantiates, caches, and automatically resolves dependencies
565
+	 * for classes that use a Fully Qualified Class Name.
566
+	 * if the class is not capable of being loaded using PSR-4 autoloading,
567
+	 * then you need to use one of the existing load_*() methods
568
+	 * which can resolve the classname and filepath from the passed arguments
569
+	 *
570
+	 * @param bool|string $class_name   Fully Qualified Class Name
571
+	 * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
572
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
573
+	 * @param bool        $from_db      some classes are instantiated from the db
574
+	 *                                  and thus call a different method to instantiate
575
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
576
+	 * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
577
+	 * @return mixed                    null = failure to load or instantiate class object.
578
+	 *                                  object = class loaded and instantiated successfully.
579
+	 *                                  bool = fail or success when $load_only is true
580
+	 */
581
+	public function create(
582
+		$class_name = false,
583
+		$arguments = array(),
584
+		$cache = false,
585
+		$from_db = false,
586
+		$load_only = false,
587
+		$addon = false
588
+	) {
589
+		$class_name = ltrim($class_name, '\\');
590
+		$class_name = $this->_dependency_map->get_alias($class_name);
591
+		if ( ! class_exists($class_name)) {
592
+			// maybe the class is registered with a preceding \
593
+			$class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name;
594
+			// still doesn't exist ?
595
+			if ( ! class_exists($class_name)) {
596
+				return null;
597
+			}
598
+		}
599
+		// if we're only loading the class and it already exists, then let's just return true immediately
600
+		if ($load_only) {
601
+			return true;
602
+		}
603
+		$addon = $addon ? 'addon' : '';
604
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
605
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
606
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
607
+		if ($this->_cache_on && $cache && ! $load_only) {
608
+			// return object if it's already cached
609
+			$cached_class = $this->_get_cached_class($class_name, $addon);
610
+			if ($cached_class !== null) {
611
+				return $cached_class;
612
+			}
613
+		}
614
+		// instantiate the requested object
615
+		$class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
616
+		if ($this->_cache_on && $cache) {
617
+			// save it for later... kinda like gum  { : $
618
+			$this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
619
+		}
620
+		$this->_cache_on = true;
621
+		return $class_obj;
622
+	}
623
+
624
+
625
+
626
+	/**
627
+	 * instantiates, caches, and injects dependencies for classes
628
+	 *
629
+	 * @param array       $file_paths   an array of paths to folders to look in
630
+	 * @param string      $class_prefix EE  or EEM or... ???
631
+	 * @param bool|string $class_name   $class name
632
+	 * @param string      $type         file type - core? class? helper? model?
633
+	 * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
634
+	 * @param bool        $from_db      some classes are instantiated from the db
635
+	 *                                  and thus call a different method to instantiate
636
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
637
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
638
+	 * @return null|object|bool         null = failure to load or instantiate class object.
639
+	 *                                  object = class loaded and instantiated successfully.
640
+	 *                                  bool = fail or success when $load_only is true
641
+	 */
642
+	protected function _load(
643
+		$file_paths = array(),
644
+		$class_prefix = 'EE_',
645
+		$class_name = false,
646
+		$type = 'class',
647
+		$arguments = array(),
648
+		$from_db = false,
649
+		$cache = true,
650
+		$load_only = false
651
+	) {
652
+		$class_name = ltrim($class_name, '\\');
653
+		// strip php file extension
654
+		$class_name = str_replace('.php', '', trim($class_name));
655
+		// does the class have a prefix ?
656
+		if ( ! empty($class_prefix) && $class_prefix != 'addon') {
657
+			// make sure $class_prefix is uppercase
658
+			$class_prefix = strtoupper(trim($class_prefix));
659
+			// add class prefix ONCE!!!
660
+			$class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
661
+		}
662
+		$class_name = $this->_dependency_map->get_alias($class_name);
663
+		$class_exists = class_exists($class_name);
664
+		// if we're only loading the class and it already exists, then let's just return true immediately
665
+		if ($load_only && $class_exists) {
666
+			return true;
667
+		}
668
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
669
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
670
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
671
+		if ($this->_cache_on && $cache && ! $load_only) {
672
+			// return object if it's already cached
673
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix);
674
+			if ($cached_class !== null) {
675
+				return $cached_class;
676
+			}
677
+		}
678
+		// if the class doesn't already exist.. then we need to try and find the file and load it
679
+		if ( ! $class_exists) {
680
+			// get full path to file
681
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
682
+			// load the file
683
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
684
+			// if loading failed, or we are only loading a file but NOT instantiating an object
685
+			if ( ! $loaded || $load_only) {
686
+				// return boolean if only loading, or null if an object was expected
687
+				return $load_only ? $loaded : null;
688
+			}
689
+		}
690
+		// instantiate the requested object
691
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
692
+		if ($this->_cache_on && $cache) {
693
+			// save it for later... kinda like gum  { : $
694
+			$this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
695
+		}
696
+		$this->_cache_on = true;
697
+		return $class_obj;
698
+	}
699
+
700
+
701
+
702
+	/**
703
+	 * _get_cached_class
704
+	 * attempts to find a cached version of the requested class
705
+	 * by looking in the following places:
706
+	 *        $this->{$class_abbreviation}            ie:    $this->CART
707
+	 *        $this->{$class_name}                        ie:    $this->Some_Class
708
+	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
709
+	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
710
+	 *
711
+	 * @access protected
712
+	 * @param string $class_name
713
+	 * @param string $class_prefix
714
+	 * @return mixed
715
+	 */
716
+	protected function _get_cached_class($class_name, $class_prefix = '')
717
+	{
718
+		if (isset($this->_class_abbreviations[$class_name])) {
719
+			$class_abbreviation = $this->_class_abbreviations[$class_name];
720
+		} else {
721
+			// have to specify something, but not anything that will conflict
722
+			$class_abbreviation = 'FANCY_BATMAN_PANTS';
723
+		}
724
+		// check if class has already been loaded, and return it if it has been
725
+		if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
726
+			return $this->{$class_abbreviation};
727
+		} else if (isset ($this->{$class_name})) {
728
+			return $this->{$class_name};
729
+		} else if (isset ($this->LIB->{$class_name})) {
730
+			return $this->LIB->{$class_name};
731
+		} else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) {
732
+			return $this->addons->{$class_name};
733
+		}
734
+		return null;
735
+	}
736
+
737
+
738
+
739
+	/**
740
+	 * _resolve_path
741
+	 * attempts to find a full valid filepath for the requested class.
742
+	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
743
+	 * then returns that path if the target file has been found and is readable
744
+	 *
745
+	 * @access protected
746
+	 * @param string $class_name
747
+	 * @param string $type
748
+	 * @param array  $file_paths
749
+	 * @return string | bool
750
+	 */
751
+	protected function _resolve_path($class_name, $type = '', $file_paths = array())
752
+	{
753
+		// make sure $file_paths is an array
754
+		$file_paths = is_array($file_paths) ? $file_paths : array($file_paths);
755
+		// cycle thru paths
756
+		foreach ($file_paths as $key => $file_path) {
757
+			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
758
+			$file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
759
+			// prep file type
760
+			$type = ! empty($type) ? trim($type, '.') . '.' : '';
761
+			// build full file path
762
+			$file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
763
+			//does the file exist and can be read ?
764
+			if (is_readable($file_paths[$key])) {
765
+				return $file_paths[$key];
766
+			}
767
+		}
768
+		return false;
769
+	}
770
+
771
+
772
+
773
+	/**
774
+	 * _require_file
775
+	 * basically just performs a require_once()
776
+	 * but with some error handling
777
+	 *
778
+	 * @access protected
779
+	 * @param  string $path
780
+	 * @param  string $class_name
781
+	 * @param  string $type
782
+	 * @param  array  $file_paths
783
+	 * @return boolean
784
+	 * @throws \EE_Error
785
+	 */
786
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array())
787
+	{
788
+		// don't give up! you gotta...
789
+		try {
790
+			//does the file exist and can it be read ?
791
+			if ( ! $path) {
792
+				// so sorry, can't find the file
793
+				throw new EE_Error (
794
+					sprintf(
795
+						__('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'),
796
+						trim($type, '.'),
797
+						$class_name,
798
+						'<br />' . implode(',<br />', $file_paths)
799
+					)
800
+				);
801
+			}
802
+			// get the file
803
+			require_once($path);
804
+			// if the class isn't already declared somewhere
805
+			if (class_exists($class_name, false) === false) {
806
+				// so sorry, not a class
807
+				throw new EE_Error(
808
+					sprintf(
809
+						__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
810
+						$type,
811
+						$path,
812
+						$class_name
813
+					)
814
+				);
815
+			}
816
+		} catch (EE_Error $e) {
817
+			$e->get_error();
818
+			return false;
819
+		}
820
+		return true;
821
+	}
822
+
823
+
824
+
825
+	/**
826
+	 * _create_object
827
+	 * Attempts to instantiate the requested class via any of the
828
+	 * commonly used instantiation methods employed throughout EE.
829
+	 * The priority for instantiation is as follows:
830
+	 *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
831
+	 *        - model objects via their 'new_instance_from_db' method
832
+	 *        - model objects via their 'new_instance' method
833
+	 *        - "singleton" classes" via their 'instance' method
834
+	 *    - standard instantiable classes via their __constructor
835
+	 * Prior to instantiation, if the classname exists in the dependency_map,
836
+	 * then the constructor for the requested class will be examined to determine
837
+	 * if any dependencies exist, and if they can be injected.
838
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
839
+	 *
840
+	 * @access protected
841
+	 * @param string $class_name
842
+	 * @param array  $arguments
843
+	 * @param string $type
844
+	 * @param bool   $from_db
845
+	 * @return null | object
846
+	 * @throws \EE_Error
847
+	 */
848
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
849
+	{
850
+		$class_obj = null;
851
+		$instantiation_mode = '0) none';
852
+		// don't give up! you gotta...
853
+		try {
854
+			// create reflection
855
+			$reflector = $this->get_ReflectionClass($class_name);
856
+			// make sure arguments are an array
857
+			$arguments = is_array($arguments) ? $arguments : array($arguments);
858
+			// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
859
+			// else wrap it in an additional array so that it doesn't get split into multiple parameters
860
+			$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
861
+				? $arguments
862
+				: array($arguments);
863
+			// attempt to inject dependencies ?
864
+			if ($this->_dependency_map->has($class_name)) {
865
+				$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
866
+			}
867
+			// instantiate the class if possible
868
+			if ($reflector->isAbstract()) {
869
+				// nothing to instantiate, loading file was enough
870
+				// does not throw an exception so $instantiation_mode is unused
871
+				// $instantiation_mode = "1) no constructor abstract class";
872
+				$class_obj = true;
873
+			} else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) {
874
+				// no constructor = static methods only... nothing to instantiate, loading file was enough
875
+				$instantiation_mode = "2) no constructor but instantiable";
876
+				$class_obj = $reflector->newInstance();
877
+			} else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
878
+				$instantiation_mode = "3) new_instance_from_db()";
879
+				$class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
880
+			} else if (method_exists($class_name, 'new_instance')) {
881
+				$instantiation_mode = "4) new_instance()";
882
+				$class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
883
+			} else if (method_exists($class_name, 'instance')) {
884
+				$instantiation_mode = "5) instance()";
885
+				$class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
886
+			} else if ($reflector->isInstantiable()) {
887
+				$instantiation_mode = "6) constructor";
888
+				$class_obj = $reflector->newInstanceArgs($arguments);
889
+			} else {
890
+				// heh ? something's not right !
891
+				throw new EE_Error(
892
+					sprintf(
893
+						__('The %s file %s could not be instantiated.', 'event_espresso'),
894
+						$type,
895
+						$class_name
896
+					)
897
+				);
898
+			}
899
+		} catch (Exception $e) {
900
+			if ( ! $e instanceof EE_Error) {
901
+				$e = new EE_Error(
902
+					sprintf(
903
+						__('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'),
904
+						$class_name,
905
+						'<br />',
906
+						$e->getMessage(),
907
+						$instantiation_mode
908
+					)
909
+				);
910
+			}
911
+			$e->get_error();
912
+		}
913
+		return $class_obj;
914
+	}
915
+
916
+
917
+
918
+	/**
919
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
920
+	 * @param array $array
921
+	 * @return bool
922
+	 */
923
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
924
+	{
925
+		return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
926
+	}
927
+
928
+
929
+
930
+	/**
931
+	 * getReflectionClass
932
+	 * checks if a ReflectionClass object has already been generated for a class
933
+	 * and returns that instead of creating a new one
934
+	 *
935
+	 * @access public
936
+	 * @param string $class_name
937
+	 * @return ReflectionClass
938
+	 */
939
+	public function get_ReflectionClass($class_name)
940
+	{
941
+		if (
942
+			! isset($this->_reflectors[$class_name])
943
+			|| ! $this->_reflectors[$class_name] instanceof ReflectionClass
944
+		) {
945
+			$this->_reflectors[$class_name] = new ReflectionClass($class_name);
946
+		}
947
+		return $this->_reflectors[$class_name];
948
+	}
949
+
950
+
951
+
952
+	/**
953
+	 * _resolve_dependencies
954
+	 * examines the constructor for the requested class to determine
955
+	 * if any dependencies exist, and if they can be injected.
956
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
957
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
958
+	 * For example:
959
+	 *        if attempting to load a class "Foo" with the following constructor:
960
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
961
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
962
+	 *        but only IF they are NOT already present in the incoming arguments array,
963
+	 *        and the correct classes can be loaded
964
+	 *
965
+	 * @access protected
966
+	 * @param ReflectionClass $reflector
967
+	 * @param string          $class_name
968
+	 * @param array           $arguments
969
+	 * @return array
970
+	 * @throws \ReflectionException
971
+	 */
972
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
973
+	{
974
+		// let's examine the constructor
975
+		$constructor = $reflector->getConstructor();
976
+		// whu? huh? nothing?
977
+		if ( ! $constructor) {
978
+			return $arguments;
979
+		}
980
+		// get constructor parameters
981
+		$params = $constructor->getParameters();
982
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
983
+		$argument_keys = array_keys($arguments);
984
+		// now loop thru all of the constructors expected parameters
985
+		foreach ($params as $index => $param) {
986
+			// is this a dependency for a specific class ?
987
+			$param_class = $param->getClass() ? $param->getClass()->name : null;
988
+			if (
989
+				// param is not even a class
990
+				empty($param_class)
991
+				// and something already exists in the incoming arguments for this param
992
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
993
+			) {
994
+				// so let's skip this argument and move on to the next
995
+				continue;
996
+			} else if (
997
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
998
+				! empty($param_class)
999
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1000
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
1001
+			) {
1002
+				// skip this argument and move on to the next
1003
+				continue;
1004
+			} else if (
1005
+				// parameter is type hinted as a class, and should be injected
1006
+				! empty($param_class)
1007
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1008
+			) {
1009
+				$arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index);
1010
+			} else {
1011
+				try {
1012
+					$arguments[$index] = $param->getDefaultValue();
1013
+				} catch (ReflectionException $e) {
1014
+					throw new ReflectionException(
1015
+						sprintf(
1016
+							__('%1$s for parameter "$%2$s"', 'event_espresso'),
1017
+							$e->getMessage(),
1018
+							$param->getName()
1019
+						)
1020
+					);
1021
+				}
1022
+			}
1023
+		}
1024
+		return $arguments;
1025
+	}
1026
+
1027
+
1028
+
1029
+	/**
1030
+	 * @access protected
1031
+	 * @param string $class_name
1032
+	 * @param string $param_class
1033
+	 * @param array  $arguments
1034
+	 * @param mixed  $index
1035
+	 * @return array
1036
+	 */
1037
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1038
+	{
1039
+		$dependency = null;
1040
+		// should dependency be loaded from cache ?
1041
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class)
1042
+					!== EE_Dependency_Map::load_new_object
1043
+			? true
1044
+			: false;
1045
+		// we might have a dependency...
1046
+		// let's MAYBE try and find it in our cache if that's what's been requested
1047
+		$cached_class = $cache_on ? $this->_get_cached_class($param_class) : null;
1048
+		// and grab it if it exists
1049
+		if ($cached_class instanceof $param_class) {
1050
+			$dependency = $cached_class;
1051
+		} else if ($param_class != $class_name) {
1052
+			// obtain the loader method from the dependency map
1053
+			$loader = $this->_dependency_map->class_loader($param_class);
1054
+			// is loader a custom closure ?
1055
+			if ($loader instanceof Closure) {
1056
+				$dependency = $loader();
1057
+			} else {
1058
+				// set the cache on property for the recursive loading call
1059
+				$this->_cache_on = $cache_on;
1060
+				// if not, then let's try and load it via the registry
1061
+				if (method_exists($this, $loader)) {
1062
+					$dependency = $this->{$loader}($param_class);
1063
+				} else {
1064
+					$dependency = $this->create($param_class, array(), $cache_on);
1065
+				}
1066
+			}
1067
+		}
1068
+		// did we successfully find the correct dependency ?
1069
+		if ($dependency instanceof $param_class) {
1070
+			// then let's inject it into the incoming array of arguments at the correct location
1071
+			if (isset($argument_keys[$index])) {
1072
+				$arguments[$argument_keys[$index]] = $dependency;
1073
+			} else {
1074
+				$arguments[$index] = $dependency;
1075
+			}
1076
+		}
1077
+		return $arguments;
1078
+	}
1079
+
1080
+
1081
+
1082
+	/**
1083
+	 * _set_cached_class
1084
+	 * attempts to cache the instantiated class locally
1085
+	 * in one of the following places, in the following order:
1086
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1087
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1088
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1089
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1090
+	 *
1091
+	 * @access protected
1092
+	 * @param object $class_obj
1093
+	 * @param string $class_name
1094
+	 * @param string $class_prefix
1095
+	 * @param bool   $from_db
1096
+	 * @return void
1097
+	 */
1098
+	protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1099
+	{
1100
+		if (empty($class_obj)) {
1101
+			return;
1102
+		}
1103
+		// return newly instantiated class
1104
+		if (isset($this->_class_abbreviations[$class_name])) {
1105
+			$class_abbreviation = $this->_class_abbreviations[$class_name];
1106
+			$this->{$class_abbreviation} = $class_obj;
1107
+		} else if (property_exists($this, $class_name)) {
1108
+			$this->{$class_name} = $class_obj;
1109
+		} else if ($class_prefix == 'addon') {
1110
+			$this->addons->{$class_name} = $class_obj;
1111
+		} else if ( ! $from_db) {
1112
+			$this->LIB->{$class_name} = $class_obj;
1113
+		}
1114
+	}
1115
+
1116
+
1117
+
1118
+	/**
1119
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1120
+	 *
1121
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1122
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1123
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1124
+	 * @param array  $arguments
1125
+	 * @return object
1126
+	 */
1127
+	public static function factory($classname, $arguments = array())
1128
+	{
1129
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1130
+		if ($loader instanceof Closure) {
1131
+			return $loader($arguments);
1132
+		} else if (method_exists(EE_Registry::instance(), $loader)) {
1133
+			return EE_Registry::instance()->{$loader}($classname, $arguments);
1134
+		}
1135
+		return null;
1136
+	}
1137
+
1138
+
1139
+
1140
+	/**
1141
+	 * Gets the addon by its name/slug (not classname. For that, just
1142
+	 * use the classname as the property name on EE_Config::instance()->addons)
1143
+	 *
1144
+	 * @param string $name
1145
+	 * @return EE_Addon
1146
+	 */
1147
+	public function get_addon_by_name($name)
1148
+	{
1149
+		foreach ($this->addons as $addon) {
1150
+			if ($addon->name() == $name) {
1151
+				return $addon;
1152
+			}
1153
+		}
1154
+		return null;
1155
+	}
1156
+
1157
+
1158
+
1159
+	/**
1160
+	 * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is
1161
+	 * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname}
1162
+	 *
1163
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1164
+	 */
1165
+	public function get_addons_by_name()
1166
+	{
1167
+		$addons = array();
1168
+		foreach ($this->addons as $addon) {
1169
+			$addons[$addon->name()] = $addon;
1170
+		}
1171
+		return $addons;
1172
+	}
1173
+
1174
+
1175
+
1176
+	/**
1177
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1178
+	 * a stale copy of it around
1179
+	 *
1180
+	 * @param string $model_name
1181
+	 * @return \EEM_Base
1182
+	 * @throws \EE_Error
1183
+	 */
1184
+	public function reset_model($model_name)
1185
+	{
1186
+		$model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name;
1187
+		if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1188
+			return null;
1189
+		}
1190
+		//get that model reset it and make sure we nuke the old reference to it
1191
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) {
1192
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1193
+		} else {
1194
+			throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1195
+		}
1196
+		return $this->LIB->{$model_class_name};
1197
+	}
1198
+
1199
+
1200
+
1201
+	/**
1202
+	 * Resets the registry.
1203
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog
1204
+	 * is used in a multisite install.  Here is a list of things that are NOT reset.
1205
+	 * - $_dependency_map
1206
+	 * - $_class_abbreviations
1207
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1208
+	 * - $REQ:  Still on the same request so no need to change.
1209
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1210
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session
1211
+	 *         can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1212
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1213
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1214
+	 *             switch or on the restore.
1215
+	 * - $modules
1216
+	 * - $shortcodes
1217
+	 * - $widgets
1218
+	 *
1219
+	 * @param boolean $hard             whether to reset data in the database too, or just refresh
1220
+	 *                                  the Registry to its state at the beginning of the request
1221
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1222
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
1223
+	 *                                  currently reinstantiate the singletons at the moment)
1224
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so client
1225
+	 *                                  code instead can just change the model context to a different blog id if necessary
1226
+	 * @return EE_Registry
1227
+	 */
1228
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1229
+	{
1230
+		$instance = self::instance();
1231
+		EEH_Activation::reset();
1232
+		//properties that get reset
1233
+		$instance->_cache_on = true;
1234
+		$instance->CFG = EE_Config::reset($hard, $reinstantiate);
1235
+		$instance->CART = null;
1236
+		$instance->MRM = null;
1237
+		$instance->AssetsRegistry = null;
1238
+		$instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1239
+		//messages reset
1240
+		EED_Messages::reset();
1241
+		if ($reset_models) {
1242
+			foreach (array_keys($instance->non_abstract_db_models) as $model_name) {
1243
+				$instance->reset_model($model_name);
1244
+			}
1245
+		}
1246
+		$instance->LIB = new stdClass();
1247
+		return $instance;
1248
+	}
1249
+
1250
+
1251
+
1252
+	/**
1253
+	 * @override magic methods
1254
+	 * @return void
1255
+	 */
1256
+	public final function __destruct()
1257
+	{
1258
+	}
1259
+
1260
+
1261
+
1262
+	/**
1263
+	 * @param $a
1264
+	 * @param $b
1265
+	 */
1266
+	public final function __call($a, $b)
1267
+	{
1268
+	}
1269
+
1270
+
1271
+
1272
+	/**
1273
+	 * @param $a
1274
+	 */
1275
+	public final function __get($a)
1276
+	{
1277
+	}
1278
+
1279
+
1280
+
1281
+	/**
1282
+	 * @param $a
1283
+	 * @param $b
1284
+	 */
1285
+	public final function __set($a, $b)
1286
+	{
1287
+	}
1288
+
1289
+
1290
+
1291
+	/**
1292
+	 * @param $a
1293
+	 */
1294
+	public final function __isset($a)
1295
+	{
1296
+	}
1297 1297
 
1298 1298
 
1299 1299
 
1300
-    /**
1301
-     * @param $a
1302
-     */
1303
-    public final function __unset($a)
1304
-    {
1305
-    }
1300
+	/**
1301
+	 * @param $a
1302
+	 */
1303
+	public final function __unset($a)
1304
+	{
1305
+	}
1306 1306
 
1307 1307
 
1308 1308
 
1309
-    /**
1310
-     * @return array
1311
-     */
1312
-    public final function __sleep()
1313
-    {
1314
-        return array();
1315
-    }
1309
+	/**
1310
+	 * @return array
1311
+	 */
1312
+	public final function __sleep()
1313
+	{
1314
+		return array();
1315
+	}
1316 1316
 
1317 1317
 
1318 1318
 
1319
-    public final function __wakeup()
1320
-    {
1321
-    }
1319
+	public final function __wakeup()
1320
+	{
1321
+	}
1322 1322
 
1323 1323
 
1324 1324
 
1325
-    /**
1326
-     * @return string
1327
-     */
1328
-    public final function __toString()
1329
-    {
1330
-        return '';
1331
-    }
1325
+	/**
1326
+	 * @return string
1327
+	 */
1328
+	public final function __toString()
1329
+	{
1330
+		return '';
1331
+	}
1332 1332
 
1333 1333
 
1334 1334
 
1335
-    public final function __invoke()
1336
-    {
1337
-    }
1335
+	public final function __invoke()
1336
+	{
1337
+	}
1338 1338
 
1339 1339
 
1340 1340
 
1341
-    public final static function __set_state($array = array())
1342
-    {
1343
-        return EE_Registry::instance();
1344
-    }
1341
+	public final static function __set_state($array = array())
1342
+	{
1343
+		return EE_Registry::instance();
1344
+	}
1345 1345
 
1346 1346
 
1347 1347
 
1348
-    public final function __clone()
1349
-    {
1350
-    }
1348
+	public final function __clone()
1349
+	{
1350
+	}
1351 1351
 
1352 1352
 
1353 1353
 
1354
-    /**
1355
-     * @param $a
1356
-     * @param $b
1357
-     */
1358
-    public final static function __callStatic($a, $b)
1359
-    {
1360
-    }
1354
+	/**
1355
+	 * @param $a
1356
+	 * @param $b
1357
+	 */
1358
+	public final static function __callStatic($a, $b)
1359
+	{
1360
+	}
1361 1361
 
1362 1362
 
1363 1363
 
1364
-    /**
1365
-     * Gets all the custom post type models defined
1366
-     *
1367
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1368
-     */
1369
-    public function cpt_models()
1370
-    {
1371
-        $cpt_models = array();
1372
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1373
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1374
-                $cpt_models[$short_name] = $classname;
1375
-            }
1376
-        }
1377
-        return $cpt_models;
1378
-    }
1364
+	/**
1365
+	 * Gets all the custom post type models defined
1366
+	 *
1367
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1368
+	 */
1369
+	public function cpt_models()
1370
+	{
1371
+		$cpt_models = array();
1372
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1373
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1374
+				$cpt_models[$short_name] = $classname;
1375
+			}
1376
+		}
1377
+		return $cpt_models;
1378
+	}
1379 1379
 
1380 1380
 
1381 1381
 
1382
-    /**
1383
-     * @return \EE_Config
1384
-     */
1385
-    public static function CFG()
1386
-    {
1387
-        return self::instance()->CFG;
1388
-    }
1382
+	/**
1383
+	 * @return \EE_Config
1384
+	 */
1385
+	public static function CFG()
1386
+	{
1387
+		return self::instance()->CFG;
1388
+	}
1389 1389
 
1390 1390
 
1391 1391
 }
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 2 patches
Indentation   +648 added lines, -648 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\loaders\LoaderInterface;
5 5
 
6 6
 if (! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -22,653 +22,653 @@  discard block
 block discarded – undo
22 22
 {
23 23
 
24 24
 
25
-    /**
26
-     * This means that the requested class dependency is not present in the dependency map
27
-     */
28
-    const not_registered = 0;
29
-
30
-
31
-    /**
32
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
33
-     */
34
-    const load_new_object = 1;
35
-
36
-    /**
37
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
38
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
39
-     */
40
-    const load_from_cache = 2;
41
-
42
-    /**
43
-     * @type EE_Dependency_Map $_instance
44
-     */
45
-    protected static $_instance;
46
-
47
-    /**
48
-     * @type EE_Request $request
49
-     */
50
-    protected $_request;
51
-
52
-    /**
53
-     * @type EE_Response $response
54
-     */
55
-    protected $_response;
56
-
57
-    /**
58
-     * @type LoaderInterface $loader
59
-     */
60
-    protected $loader;
61
-
62
-    /**
63
-     * @type array $_dependency_map
64
-     */
65
-    protected $_dependency_map = array();
66
-
67
-    /**
68
-     * @type array $_class_loaders
69
-     */
70
-    protected $_class_loaders = array();
71
-
72
-    /**
73
-     * @type array $_aliases
74
-     */
75
-    protected $_aliases = array();
76
-
77
-
78
-
79
-    /**
80
-     * EE_Dependency_Map constructor.
81
-     *
82
-     * @param EE_Request  $request
83
-     * @param EE_Response $response
84
-     */
85
-    protected function __construct(EE_Request $request, EE_Response $response)
86
-    {
87
-        $this->_request = $request;
88
-        $this->_response = $response;
89
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
90
-        do_action('EE_Dependency_Map____construct');
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     * @throws InvalidDataTypeException
97
-     * @throws InvalidInterfaceException
98
-     * @throws InvalidArgumentException
99
-     */
100
-    public function initialize()
101
-    {
102
-        $this->_register_core_dependencies();
103
-        $this->_register_core_class_loaders();
104
-        $this->_register_core_aliases();
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * @singleton method used to instantiate class object
111
-     * @access    public
112
-     * @param EE_Request  $request
113
-     * @param EE_Response $response
114
-     * @return EE_Dependency_Map
115
-     */
116
-    public static function instance(EE_Request $request = null, EE_Response $response = null)
117
-    {
118
-        // check if class object is instantiated, and instantiated properly
119
-        if (! self::$_instance instanceof EE_Dependency_Map) {
120
-            self::$_instance = new EE_Dependency_Map($request, $response);
121
-        }
122
-        return self::$_instance;
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * @param LoaderInterface $loader
129
-     */
130
-    public function setLoader(LoaderInterface $loader)
131
-    {
132
-        $this->loader = $loader;
133
-    }
134
-
135
-
136
-
137
-    /**
138
-     * @param string $class
139
-     * @param array  $dependencies
140
-     * @return boolean
141
-     */
142
-    public static function register_dependencies($class, $dependencies)
143
-    {
144
-        if (! isset(self::$_instance->_dependency_map[$class])) {
145
-            // we need to make sure that any aliases used when registering a dependency
146
-            // get resolved to the correct class name
147
-            foreach ((array)$dependencies as $dependency => $load_source) {
148
-                $alias = self::$_instance->get_alias($dependency);
149
-                unset($dependencies[$dependency]);
150
-                $dependencies[$alias] = $load_source;
151
-            }
152
-            self::$_instance->_dependency_map[$class] = (array)$dependencies;
153
-            return true;
154
-        }
155
-        return false;
156
-    }
157
-
158
-
159
-
160
-    /**
161
-     * @param string $class_name
162
-     * @param string $loader
163
-     * @return bool
164
-     * @throws EE_Error
165
-     */
166
-    public static function register_class_loader($class_name, $loader = 'load_core')
167
-    {
168
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
169
-        if (
170
-            ! is_callable($loader)
171
-            && (
172
-                strpos($loader, 'load_') !== 0
173
-                || ! method_exists('EE_Registry', $loader)
174
-            )
175
-        ) {
176
-            throw new EE_Error(
177
-                sprintf(
178
-                    esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'),
179
-                    $loader
180
-                )
181
-            );
182
-        }
183
-        $class_name = self::$_instance->get_alias($class_name);
184
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
185
-            self::$_instance->_class_loaders[$class_name] = $loader;
186
-            return true;
187
-        }
188
-        return false;
189
-    }
190
-
191
-
192
-
193
-    /**
194
-     * @return array
195
-     */
196
-    public function dependency_map()
197
-    {
198
-        return $this->_dependency_map;
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     * returns TRUE if dependency map contains a listing for the provided class name
205
-     *
206
-     * @param string $class_name
207
-     * @return boolean
208
-     */
209
-    public function has($class_name = '')
210
-    {
211
-        return isset($this->_dependency_map[$class_name]) ? true : false;
212
-    }
213
-
214
-
215
-
216
-    /**
217
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
218
-     *
219
-     * @param string $class_name
220
-     * @param string $dependency
221
-     * @return bool
222
-     */
223
-    public function has_dependency_for_class($class_name = '', $dependency = '')
224
-    {
225
-        $dependency = $this->get_alias($dependency);
226
-        return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
227
-            ? true
228
-            : false;
229
-    }
230
-
231
-
232
-
233
-    /**
234
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
235
-     *
236
-     * @param string $class_name
237
-     * @param string $dependency
238
-     * @return int
239
-     */
240
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
241
-    {
242
-        $dependency = $this->get_alias($dependency);
243
-        return $this->has_dependency_for_class($class_name, $dependency)
244
-            ? $this->_dependency_map[$class_name][$dependency]
245
-            : EE_Dependency_Map::not_registered;
246
-    }
247
-
248
-
249
-
250
-    /**
251
-     * @param string $class_name
252
-     * @return string | Closure
253
-     */
254
-    public function class_loader($class_name)
255
-    {
256
-        $class_name = $this->get_alias($class_name);
257
-        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
258
-    }
259
-
260
-
261
-
262
-    /**
263
-     * @return array
264
-     */
265
-    public function class_loaders()
266
-    {
267
-        return $this->_class_loaders;
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * adds an alias for a classname
274
-     *
275
-     * @param string $class_name the class name that should be used (concrete class to replace interface)
276
-     * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
277
-     * @param string $for_class  the class that has the dependency (is type hinting for the interface)
278
-     */
279
-    public function add_alias($class_name, $alias, $for_class = '')
280
-    {
281
-        if ($for_class !== '') {
282
-            if (! isset($this->_aliases[$for_class])) {
283
-                $this->_aliases[$for_class] = array();
284
-            }
285
-            $this->_aliases[$for_class][$class_name] = $alias;
286
-        }
287
-        $this->_aliases[$class_name] = $alias;
288
-    }
289
-
290
-
291
-
292
-    /**
293
-     * returns TRUE if the provided class name has an alias
294
-     *
295
-     * @param string $class_name
296
-     * @param string $for_class
297
-     * @return bool
298
-     */
299
-    public function has_alias($class_name = '', $for_class = '')
300
-    {
301
-        return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
302
-               || (
303
-                   isset($this->_aliases[$class_name])
304
-                   && ! is_array($this->_aliases[$class_name])
305
-               );
306
-    }
307
-
308
-
309
-
310
-    /**
311
-     * returns alias for class name if one exists, otherwise returns the original classname
312
-     * functions recursively, so that multiple aliases can be used to drill down to a classname
313
-     *  for example:
314
-     *      if the following two entries were added to the _aliases array:
315
-     *          array(
316
-     *              'interface_alias'           => 'some\namespace\interface'
317
-     *              'some\namespace\interface'  => 'some\namespace\classname'
318
-     *          )
319
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
320
-     *      to load an instance of 'some\namespace\classname'
321
-     *
322
-     * @param string $class_name
323
-     * @param string $for_class
324
-     * @return string
325
-     */
326
-    public function get_alias($class_name = '', $for_class = '')
327
-    {
328
-        if (! $this->has_alias($class_name, $for_class)) {
329
-            return $class_name;
330
-        }
331
-        if ($for_class !== '') {
332
-            return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
333
-        }
334
-        return $this->get_alias($this->_aliases[$class_name]);
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
341
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
342
-     * This is done by using the following class constants:
343
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
344
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
345
-     */
346
-    protected function _register_core_dependencies()
347
-    {
348
-        $this->_dependency_map = array(
349
-            'EE_Request_Handler'                                                                                          => array(
350
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
351
-            ),
352
-            'EE_System'                                                                                                   => array(
353
-                'EE_Registry' => EE_Dependency_Map::load_from_cache,
354
-            ),
355
-            'EE_Session'                                                                                                  => array(
356
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
357
-                'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
358
-            ),
359
-            'EE_Cart'                                                                                                     => array(
360
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
361
-            ),
362
-            'EE_Front_Controller'                                                                                         => array(
363
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
364
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
365
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
366
-            ),
367
-            'EE_Messenger_Collection_Loader'                                                                              => array(
368
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
369
-            ),
370
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
371
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
372
-            ),
373
-            'EE_Message_Resource_Manager'                                                                                 => array(
374
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
375
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
376
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
377
-            ),
378
-            'EE_Message_Factory'                                                                                          => array(
379
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
380
-            ),
381
-            'EE_messages'                                                                                                 => array(
382
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
383
-            ),
384
-            'EE_Messages_Generator'                                                                                       => array(
385
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
386
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
387
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
388
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
389
-            ),
390
-            'EE_Messages_Processor'                                                                                       => array(
391
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
392
-            ),
393
-            'EE_Messages_Queue'                                                                                           => array(
394
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
395
-            ),
396
-            'EE_Messages_Template_Defaults'                                                                               => array(
397
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
398
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
399
-            ),
400
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
401
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
402
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
403
-            ),
404
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
405
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
406
-            ),
407
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
408
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
409
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
410
-            ),
411
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
412
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
413
-            ),
414
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
415
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
416
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
417
-            ),
418
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
419
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
420
-            ),
421
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
422
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
423
-            ),
424
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
425
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
426
-            ),
427
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
428
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
429
-            ),
430
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
431
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
432
-            ),
433
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
434
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
435
-            ),
436
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
437
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
438
-            ),
439
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
440
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
441
-            ),
442
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
443
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
444
-            ),
445
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
446
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
447
-            ),
448
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
449
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
450
-            ),
451
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
452
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
453
-            ),
454
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
455
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
456
-            ),
457
-            'EE_Data_Migration_Class_Base'                                                                                => array(
458
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
459
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
460
-            ),
461
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
462
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
463
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
464
-            ),
465
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
466
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
467
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
468
-            ),
469
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
470
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
471
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
472
-            ),
473
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
474
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
475
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
476
-            ),
477
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
478
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
479
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
480
-            ),
481
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
482
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
483
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
484
-            ),
485
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
486
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
487
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
488
-            ),
489
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
490
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
491
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
492
-            ),
493
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
494
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
495
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
496
-            ),
497
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
498
-                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
499
-                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
500
-            ),
501
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
502
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
503
-            ),
504
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
505
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
506
-            ),
507
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
508
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
509
-            ),
510
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
511
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
512
-            ),
513
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
514
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
515
-            ),
516
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
517
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
518
-            ),
519
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
520
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
521
-            ),
522
-            'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
523
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
524
-            ),
525
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
526
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
527
-            ),
528
-        );
529
-    }
530
-
531
-
532
-
533
-    /**
534
-     * Registers how core classes are loaded.
535
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
536
-     *        'EE_Request_Handler' => 'load_core'
537
-     *        'EE_Messages_Queue'  => 'load_lib'
538
-     *        'EEH_Debug_Tools'    => 'load_helper'
539
-     * or, if greater control is required, by providing a custom closure. For example:
540
-     *        'Some_Class' => function () {
541
-     *            return new Some_Class();
542
-     *        },
543
-     * This is required for instantiating dependencies
544
-     * where an interface has been type hinted in a class constructor. For example:
545
-     *        'Required_Interface' => function () {
546
-     *            return new A_Class_That_Implements_Required_Interface();
547
-     *        },
548
-     */
549
-    protected function _register_core_class_loaders()
550
-    {
551
-        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
552
-        //be used in a closure.
553
-        $request = &$this->_request;
554
-        $response = &$this->_response;
555
-        $loader = &$this->loader;
556
-        $this->_class_loaders = array(
557
-            //load_core
558
-            'EE_Capabilities'                      => 'load_core',
559
-            'EE_Encryption'                        => 'load_core',
560
-            'EE_Front_Controller'                  => 'load_core',
561
-            'EE_Module_Request_Router'             => 'load_core',
562
-            'EE_Registry'                          => 'load_core',
563
-            'EE_Request'                           => function () use (&$request) {
564
-                return $request;
565
-            },
566
-            'EE_Response'                          => function () use (&$response) {
567
-                return $response;
568
-            },
569
-            'EE_Request_Handler'                   => 'load_core',
570
-            'EE_Session'                           => 'load_core',
571
-            'EE_System'                            => 'load_core',
572
-            //load_lib
573
-            'EE_Message_Resource_Manager'          => 'load_lib',
574
-            'EE_Message_Type_Collection'           => 'load_lib',
575
-            'EE_Message_Type_Collection_Loader'    => 'load_lib',
576
-            'EE_Messenger_Collection'              => 'load_lib',
577
-            'EE_Messenger_Collection_Loader'       => 'load_lib',
578
-            'EE_Messages_Processor'                => 'load_lib',
579
-            'EE_Message_Repository'                => 'load_lib',
580
-            'EE_Messages_Queue'                    => 'load_lib',
581
-            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
582
-            'EE_Message_Template_Group_Collection' => 'load_lib',
583
-            'EE_Messages_Generator'                => function () {
584
-                return EE_Registry::instance()->load_lib(
585
-                    'Messages_Generator',
586
-                    array(),
587
-                    false,
588
-                    false
589
-                );
590
-            },
591
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
592
-                return EE_Registry::instance()->load_lib(
593
-                    'Messages_Template_Defaults',
594
-                    $arguments,
595
-                    false,
596
-                    false
597
-                );
598
-            },
599
-            //load_model
600
-            'EEM_Message_Template_Group'           => 'load_model',
601
-            'EEM_Message_Template'                 => 'load_model',
602
-            //load_helper
603
-            'EEH_Parse_Shortcodes'                 => function () {
604
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
605
-                    return new EEH_Parse_Shortcodes();
606
-                }
607
-                return null;
608
-            },
609
-            'EE_Template_Config'                   => function () {
610
-                return EE_Config::instance()->template_settings;
611
-            },
612
-            'EE_Currency_Config'                   => function () {
613
-                return EE_Config::instance()->currency;
614
-            },
615
-            'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
616
-                return $loader;
617
-            },
618
-        );
619
-    }
620
-
621
-
622
-
623
-    /**
624
-     * can be used for supplying alternate names for classes,
625
-     * or for connecting interface names to instantiable classes
626
-     */
627
-    protected function _register_core_aliases()
628
-    {
629
-        $this->_aliases = array(
630
-            'CommandBusInterface'                                                 => 'EventEspresso\core\services\commands\CommandBusInterface',
631
-            'EventEspresso\core\services\commands\CommandBusInterface'            => 'EventEspresso\core\services\commands\CommandBus',
632
-            'CommandHandlerManagerInterface'                                      => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
633
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager',
634
-            'CapChecker'                                                          => 'EventEspresso\core\services\commands\middleware\CapChecker',
635
-            'AddActionHook'                                                       => 'EventEspresso\core\services\commands\middleware\AddActionHook',
636
-            'CapabilitiesChecker'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
637
-            'CapabilitiesCheckerInterface'                                        => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
638
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
639
-            'CreateRegistrationService'                                           => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
640
-            'CreateRegCodeCommandHandler'                                         => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
641
-            'CreateRegUrlLinkCommandHandler'                                      => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
642
-            'CreateRegistrationCommandHandler'                                    => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
643
-            'CopyRegistrationDetailsCommandHandler'                               => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
644
-            'CopyRegistrationPaymentsCommandHandler'                              => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
645
-            'CancelRegistrationAndTicketLineItemCommandHandler'                   => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
646
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'           => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
647
-            'CreateTicketLineItemCommandHandler'                                  => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
648
-            'TableManager'                                                        => 'EventEspresso\core\services\database\TableManager',
649
-            'TableAnalysis'                                                       => 'EventEspresso\core\services\database\TableAnalysis',
650
-            'EspressoShortcode'                                                   => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
651
-            'ShortcodeInterface'                                                  => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
652
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'           => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
653
-            'EventEspresso\core\services\cache\CacheStorageInterface'             => 'EventEspresso\core\services\cache\TransientCacheStorage',
654
-            'LoaderInterface'                                                     => 'EventEspresso\core\services\loaders\LoaderInterface',
655
-            'EventEspresso\core\services\loaders\LoaderInterface'                 => 'EventEspresso\core\services\loaders\Loader',
656
-            'CommandFactoryInterface'                                             => 'EventEspresso\core\services\commands\CommandFactoryInterface',
657
-            'EventEspresso\core\services\commands\CommandFactoryInterface'        => 'EventEspresso\core\services\commands\CommandFactory',
658
-        );
659
-    }
660
-
661
-
662
-
663
-    /**
664
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
665
-     * request Primarily used by unit tests.
666
-     */
667
-    public function reset()
668
-    {
669
-        $this->_register_core_class_loaders();
670
-        $this->_register_core_dependencies();
671
-    }
25
+	/**
26
+	 * This means that the requested class dependency is not present in the dependency map
27
+	 */
28
+	const not_registered = 0;
29
+
30
+
31
+	/**
32
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
33
+	 */
34
+	const load_new_object = 1;
35
+
36
+	/**
37
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
38
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
39
+	 */
40
+	const load_from_cache = 2;
41
+
42
+	/**
43
+	 * @type EE_Dependency_Map $_instance
44
+	 */
45
+	protected static $_instance;
46
+
47
+	/**
48
+	 * @type EE_Request $request
49
+	 */
50
+	protected $_request;
51
+
52
+	/**
53
+	 * @type EE_Response $response
54
+	 */
55
+	protected $_response;
56
+
57
+	/**
58
+	 * @type LoaderInterface $loader
59
+	 */
60
+	protected $loader;
61
+
62
+	/**
63
+	 * @type array $_dependency_map
64
+	 */
65
+	protected $_dependency_map = array();
66
+
67
+	/**
68
+	 * @type array $_class_loaders
69
+	 */
70
+	protected $_class_loaders = array();
71
+
72
+	/**
73
+	 * @type array $_aliases
74
+	 */
75
+	protected $_aliases = array();
76
+
77
+
78
+
79
+	/**
80
+	 * EE_Dependency_Map constructor.
81
+	 *
82
+	 * @param EE_Request  $request
83
+	 * @param EE_Response $response
84
+	 */
85
+	protected function __construct(EE_Request $request, EE_Response $response)
86
+	{
87
+		$this->_request = $request;
88
+		$this->_response = $response;
89
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
90
+		do_action('EE_Dependency_Map____construct');
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 * @throws InvalidDataTypeException
97
+	 * @throws InvalidInterfaceException
98
+	 * @throws InvalidArgumentException
99
+	 */
100
+	public function initialize()
101
+	{
102
+		$this->_register_core_dependencies();
103
+		$this->_register_core_class_loaders();
104
+		$this->_register_core_aliases();
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * @singleton method used to instantiate class object
111
+	 * @access    public
112
+	 * @param EE_Request  $request
113
+	 * @param EE_Response $response
114
+	 * @return EE_Dependency_Map
115
+	 */
116
+	public static function instance(EE_Request $request = null, EE_Response $response = null)
117
+	{
118
+		// check if class object is instantiated, and instantiated properly
119
+		if (! self::$_instance instanceof EE_Dependency_Map) {
120
+			self::$_instance = new EE_Dependency_Map($request, $response);
121
+		}
122
+		return self::$_instance;
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * @param LoaderInterface $loader
129
+	 */
130
+	public function setLoader(LoaderInterface $loader)
131
+	{
132
+		$this->loader = $loader;
133
+	}
134
+
135
+
136
+
137
+	/**
138
+	 * @param string $class
139
+	 * @param array  $dependencies
140
+	 * @return boolean
141
+	 */
142
+	public static function register_dependencies($class, $dependencies)
143
+	{
144
+		if (! isset(self::$_instance->_dependency_map[$class])) {
145
+			// we need to make sure that any aliases used when registering a dependency
146
+			// get resolved to the correct class name
147
+			foreach ((array)$dependencies as $dependency => $load_source) {
148
+				$alias = self::$_instance->get_alias($dependency);
149
+				unset($dependencies[$dependency]);
150
+				$dependencies[$alias] = $load_source;
151
+			}
152
+			self::$_instance->_dependency_map[$class] = (array)$dependencies;
153
+			return true;
154
+		}
155
+		return false;
156
+	}
157
+
158
+
159
+
160
+	/**
161
+	 * @param string $class_name
162
+	 * @param string $loader
163
+	 * @return bool
164
+	 * @throws EE_Error
165
+	 */
166
+	public static function register_class_loader($class_name, $loader = 'load_core')
167
+	{
168
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
169
+		if (
170
+			! is_callable($loader)
171
+			&& (
172
+				strpos($loader, 'load_') !== 0
173
+				|| ! method_exists('EE_Registry', $loader)
174
+			)
175
+		) {
176
+			throw new EE_Error(
177
+				sprintf(
178
+					esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'),
179
+					$loader
180
+				)
181
+			);
182
+		}
183
+		$class_name = self::$_instance->get_alias($class_name);
184
+		if (! isset(self::$_instance->_class_loaders[$class_name])) {
185
+			self::$_instance->_class_loaders[$class_name] = $loader;
186
+			return true;
187
+		}
188
+		return false;
189
+	}
190
+
191
+
192
+
193
+	/**
194
+	 * @return array
195
+	 */
196
+	public function dependency_map()
197
+	{
198
+		return $this->_dependency_map;
199
+	}
200
+
201
+
202
+
203
+	/**
204
+	 * returns TRUE if dependency map contains a listing for the provided class name
205
+	 *
206
+	 * @param string $class_name
207
+	 * @return boolean
208
+	 */
209
+	public function has($class_name = '')
210
+	{
211
+		return isset($this->_dependency_map[$class_name]) ? true : false;
212
+	}
213
+
214
+
215
+
216
+	/**
217
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
218
+	 *
219
+	 * @param string $class_name
220
+	 * @param string $dependency
221
+	 * @return bool
222
+	 */
223
+	public function has_dependency_for_class($class_name = '', $dependency = '')
224
+	{
225
+		$dependency = $this->get_alias($dependency);
226
+		return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
227
+			? true
228
+			: false;
229
+	}
230
+
231
+
232
+
233
+	/**
234
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
235
+	 *
236
+	 * @param string $class_name
237
+	 * @param string $dependency
238
+	 * @return int
239
+	 */
240
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
241
+	{
242
+		$dependency = $this->get_alias($dependency);
243
+		return $this->has_dependency_for_class($class_name, $dependency)
244
+			? $this->_dependency_map[$class_name][$dependency]
245
+			: EE_Dependency_Map::not_registered;
246
+	}
247
+
248
+
249
+
250
+	/**
251
+	 * @param string $class_name
252
+	 * @return string | Closure
253
+	 */
254
+	public function class_loader($class_name)
255
+	{
256
+		$class_name = $this->get_alias($class_name);
257
+		return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
258
+	}
259
+
260
+
261
+
262
+	/**
263
+	 * @return array
264
+	 */
265
+	public function class_loaders()
266
+	{
267
+		return $this->_class_loaders;
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * adds an alias for a classname
274
+	 *
275
+	 * @param string $class_name the class name that should be used (concrete class to replace interface)
276
+	 * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
277
+	 * @param string $for_class  the class that has the dependency (is type hinting for the interface)
278
+	 */
279
+	public function add_alias($class_name, $alias, $for_class = '')
280
+	{
281
+		if ($for_class !== '') {
282
+			if (! isset($this->_aliases[$for_class])) {
283
+				$this->_aliases[$for_class] = array();
284
+			}
285
+			$this->_aliases[$for_class][$class_name] = $alias;
286
+		}
287
+		$this->_aliases[$class_name] = $alias;
288
+	}
289
+
290
+
291
+
292
+	/**
293
+	 * returns TRUE if the provided class name has an alias
294
+	 *
295
+	 * @param string $class_name
296
+	 * @param string $for_class
297
+	 * @return bool
298
+	 */
299
+	public function has_alias($class_name = '', $for_class = '')
300
+	{
301
+		return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
302
+			   || (
303
+				   isset($this->_aliases[$class_name])
304
+				   && ! is_array($this->_aliases[$class_name])
305
+			   );
306
+	}
307
+
308
+
309
+
310
+	/**
311
+	 * returns alias for class name if one exists, otherwise returns the original classname
312
+	 * functions recursively, so that multiple aliases can be used to drill down to a classname
313
+	 *  for example:
314
+	 *      if the following two entries were added to the _aliases array:
315
+	 *          array(
316
+	 *              'interface_alias'           => 'some\namespace\interface'
317
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
318
+	 *          )
319
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
320
+	 *      to load an instance of 'some\namespace\classname'
321
+	 *
322
+	 * @param string $class_name
323
+	 * @param string $for_class
324
+	 * @return string
325
+	 */
326
+	public function get_alias($class_name = '', $for_class = '')
327
+	{
328
+		if (! $this->has_alias($class_name, $for_class)) {
329
+			return $class_name;
330
+		}
331
+		if ($for_class !== '') {
332
+			return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
333
+		}
334
+		return $this->get_alias($this->_aliases[$class_name]);
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
341
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
342
+	 * This is done by using the following class constants:
343
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
344
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
345
+	 */
346
+	protected function _register_core_dependencies()
347
+	{
348
+		$this->_dependency_map = array(
349
+			'EE_Request_Handler'                                                                                          => array(
350
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
351
+			),
352
+			'EE_System'                                                                                                   => array(
353
+				'EE_Registry' => EE_Dependency_Map::load_from_cache,
354
+			),
355
+			'EE_Session'                                                                                                  => array(
356
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
357
+				'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
358
+			),
359
+			'EE_Cart'                                                                                                     => array(
360
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
361
+			),
362
+			'EE_Front_Controller'                                                                                         => array(
363
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
364
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
365
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
366
+			),
367
+			'EE_Messenger_Collection_Loader'                                                                              => array(
368
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
369
+			),
370
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
371
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
372
+			),
373
+			'EE_Message_Resource_Manager'                                                                                 => array(
374
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
375
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
376
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
377
+			),
378
+			'EE_Message_Factory'                                                                                          => array(
379
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
380
+			),
381
+			'EE_messages'                                                                                                 => array(
382
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
383
+			),
384
+			'EE_Messages_Generator'                                                                                       => array(
385
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
386
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
387
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
388
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
389
+			),
390
+			'EE_Messages_Processor'                                                                                       => array(
391
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
392
+			),
393
+			'EE_Messages_Queue'                                                                                           => array(
394
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
395
+			),
396
+			'EE_Messages_Template_Defaults'                                                                               => array(
397
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
398
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
399
+			),
400
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
401
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
402
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
403
+			),
404
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
405
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
406
+			),
407
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
408
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
409
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
410
+			),
411
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
412
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
413
+			),
414
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
415
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
416
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
417
+			),
418
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
419
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
420
+			),
421
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
422
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
423
+			),
424
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
425
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
426
+			),
427
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
428
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
429
+			),
430
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
431
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
432
+			),
433
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
434
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
435
+			),
436
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
437
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
438
+			),
439
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
440
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
441
+			),
442
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
443
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
444
+			),
445
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
446
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
447
+			),
448
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
449
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
450
+			),
451
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
452
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
453
+			),
454
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
455
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
456
+			),
457
+			'EE_Data_Migration_Class_Base'                                                                                => array(
458
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
459
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
460
+			),
461
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
462
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
463
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
464
+			),
465
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
466
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
467
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
468
+			),
469
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
470
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
471
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
472
+			),
473
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
474
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
475
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
476
+			),
477
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
478
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
479
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
480
+			),
481
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
482
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
483
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
484
+			),
485
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
486
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
487
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
488
+			),
489
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
490
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
491
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
492
+			),
493
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
494
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
495
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
496
+			),
497
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
498
+				'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
499
+				'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
500
+			),
501
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
502
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
503
+			),
504
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
505
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
506
+			),
507
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
508
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
509
+			),
510
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
511
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
512
+			),
513
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
514
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
515
+			),
516
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
517
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
518
+			),
519
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
520
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
521
+			),
522
+			'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
523
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
524
+			),
525
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
526
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
527
+			),
528
+		);
529
+	}
530
+
531
+
532
+
533
+	/**
534
+	 * Registers how core classes are loaded.
535
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
536
+	 *        'EE_Request_Handler' => 'load_core'
537
+	 *        'EE_Messages_Queue'  => 'load_lib'
538
+	 *        'EEH_Debug_Tools'    => 'load_helper'
539
+	 * or, if greater control is required, by providing a custom closure. For example:
540
+	 *        'Some_Class' => function () {
541
+	 *            return new Some_Class();
542
+	 *        },
543
+	 * This is required for instantiating dependencies
544
+	 * where an interface has been type hinted in a class constructor. For example:
545
+	 *        'Required_Interface' => function () {
546
+	 *            return new A_Class_That_Implements_Required_Interface();
547
+	 *        },
548
+	 */
549
+	protected function _register_core_class_loaders()
550
+	{
551
+		//for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
552
+		//be used in a closure.
553
+		$request = &$this->_request;
554
+		$response = &$this->_response;
555
+		$loader = &$this->loader;
556
+		$this->_class_loaders = array(
557
+			//load_core
558
+			'EE_Capabilities'                      => 'load_core',
559
+			'EE_Encryption'                        => 'load_core',
560
+			'EE_Front_Controller'                  => 'load_core',
561
+			'EE_Module_Request_Router'             => 'load_core',
562
+			'EE_Registry'                          => 'load_core',
563
+			'EE_Request'                           => function () use (&$request) {
564
+				return $request;
565
+			},
566
+			'EE_Response'                          => function () use (&$response) {
567
+				return $response;
568
+			},
569
+			'EE_Request_Handler'                   => 'load_core',
570
+			'EE_Session'                           => 'load_core',
571
+			'EE_System'                            => 'load_core',
572
+			//load_lib
573
+			'EE_Message_Resource_Manager'          => 'load_lib',
574
+			'EE_Message_Type_Collection'           => 'load_lib',
575
+			'EE_Message_Type_Collection_Loader'    => 'load_lib',
576
+			'EE_Messenger_Collection'              => 'load_lib',
577
+			'EE_Messenger_Collection_Loader'       => 'load_lib',
578
+			'EE_Messages_Processor'                => 'load_lib',
579
+			'EE_Message_Repository'                => 'load_lib',
580
+			'EE_Messages_Queue'                    => 'load_lib',
581
+			'EE_Messages_Data_Handler_Collection'  => 'load_lib',
582
+			'EE_Message_Template_Group_Collection' => 'load_lib',
583
+			'EE_Messages_Generator'                => function () {
584
+				return EE_Registry::instance()->load_lib(
585
+					'Messages_Generator',
586
+					array(),
587
+					false,
588
+					false
589
+				);
590
+			},
591
+			'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
592
+				return EE_Registry::instance()->load_lib(
593
+					'Messages_Template_Defaults',
594
+					$arguments,
595
+					false,
596
+					false
597
+				);
598
+			},
599
+			//load_model
600
+			'EEM_Message_Template_Group'           => 'load_model',
601
+			'EEM_Message_Template'                 => 'load_model',
602
+			//load_helper
603
+			'EEH_Parse_Shortcodes'                 => function () {
604
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
605
+					return new EEH_Parse_Shortcodes();
606
+				}
607
+				return null;
608
+			},
609
+			'EE_Template_Config'                   => function () {
610
+				return EE_Config::instance()->template_settings;
611
+			},
612
+			'EE_Currency_Config'                   => function () {
613
+				return EE_Config::instance()->currency;
614
+			},
615
+			'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
616
+				return $loader;
617
+			},
618
+		);
619
+	}
620
+
621
+
622
+
623
+	/**
624
+	 * can be used for supplying alternate names for classes,
625
+	 * or for connecting interface names to instantiable classes
626
+	 */
627
+	protected function _register_core_aliases()
628
+	{
629
+		$this->_aliases = array(
630
+			'CommandBusInterface'                                                 => 'EventEspresso\core\services\commands\CommandBusInterface',
631
+			'EventEspresso\core\services\commands\CommandBusInterface'            => 'EventEspresso\core\services\commands\CommandBus',
632
+			'CommandHandlerManagerInterface'                                      => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
633
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager',
634
+			'CapChecker'                                                          => 'EventEspresso\core\services\commands\middleware\CapChecker',
635
+			'AddActionHook'                                                       => 'EventEspresso\core\services\commands\middleware\AddActionHook',
636
+			'CapabilitiesChecker'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
637
+			'CapabilitiesCheckerInterface'                                        => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
638
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
639
+			'CreateRegistrationService'                                           => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
640
+			'CreateRegCodeCommandHandler'                                         => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
641
+			'CreateRegUrlLinkCommandHandler'                                      => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
642
+			'CreateRegistrationCommandHandler'                                    => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
643
+			'CopyRegistrationDetailsCommandHandler'                               => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
644
+			'CopyRegistrationPaymentsCommandHandler'                              => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
645
+			'CancelRegistrationAndTicketLineItemCommandHandler'                   => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
646
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'           => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
647
+			'CreateTicketLineItemCommandHandler'                                  => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
648
+			'TableManager'                                                        => 'EventEspresso\core\services\database\TableManager',
649
+			'TableAnalysis'                                                       => 'EventEspresso\core\services\database\TableAnalysis',
650
+			'EspressoShortcode'                                                   => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
651
+			'ShortcodeInterface'                                                  => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
652
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'           => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
653
+			'EventEspresso\core\services\cache\CacheStorageInterface'             => 'EventEspresso\core\services\cache\TransientCacheStorage',
654
+			'LoaderInterface'                                                     => 'EventEspresso\core\services\loaders\LoaderInterface',
655
+			'EventEspresso\core\services\loaders\LoaderInterface'                 => 'EventEspresso\core\services\loaders\Loader',
656
+			'CommandFactoryInterface'                                             => 'EventEspresso\core\services\commands\CommandFactoryInterface',
657
+			'EventEspresso\core\services\commands\CommandFactoryInterface'        => 'EventEspresso\core\services\commands\CommandFactory',
658
+		);
659
+	}
660
+
661
+
662
+
663
+	/**
664
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
665
+	 * request Primarily used by unit tests.
666
+	 */
667
+	public function reset()
668
+	{
669
+		$this->_register_core_class_loaders();
670
+		$this->_register_core_dependencies();
671
+	}
672 672
 
673 673
 
674 674
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\exceptions\InvalidInterfaceException;
4 4
 use EventEspresso\core\services\loaders\LoaderInterface;
5 5
 
6
-if (! defined('EVENT_ESPRESSO_VERSION')) {
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7 7
     exit('No direct script access allowed');
8 8
 }
9 9
 
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
     public static function instance(EE_Request $request = null, EE_Response $response = null)
117 117
     {
118 118
         // check if class object is instantiated, and instantiated properly
119
-        if (! self::$_instance instanceof EE_Dependency_Map) {
119
+        if ( ! self::$_instance instanceof EE_Dependency_Map) {
120 120
             self::$_instance = new EE_Dependency_Map($request, $response);
121 121
         }
122 122
         return self::$_instance;
@@ -141,15 +141,15 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public static function register_dependencies($class, $dependencies)
143 143
     {
144
-        if (! isset(self::$_instance->_dependency_map[$class])) {
144
+        if ( ! isset(self::$_instance->_dependency_map[$class])) {
145 145
             // we need to make sure that any aliases used when registering a dependency
146 146
             // get resolved to the correct class name
147
-            foreach ((array)$dependencies as $dependency => $load_source) {
147
+            foreach ((array) $dependencies as $dependency => $load_source) {
148 148
                 $alias = self::$_instance->get_alias($dependency);
149 149
                 unset($dependencies[$dependency]);
150 150
                 $dependencies[$alias] = $load_source;
151 151
             }
152
-            self::$_instance->_dependency_map[$class] = (array)$dependencies;
152
+            self::$_instance->_dependency_map[$class] = (array) $dependencies;
153 153
             return true;
154 154
         }
155 155
         return false;
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
             );
182 182
         }
183 183
         $class_name = self::$_instance->get_alias($class_name);
184
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
184
+        if ( ! isset(self::$_instance->_class_loaders[$class_name])) {
185 185
             self::$_instance->_class_loaders[$class_name] = $loader;
186 186
             return true;
187 187
         }
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
     public function add_alias($class_name, $alias, $for_class = '')
280 280
     {
281 281
         if ($for_class !== '') {
282
-            if (! isset($this->_aliases[$for_class])) {
282
+            if ( ! isset($this->_aliases[$for_class])) {
283 283
                 $this->_aliases[$for_class] = array();
284 284
             }
285 285
             $this->_aliases[$for_class][$class_name] = $alias;
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
      */
326 326
     public function get_alias($class_name = '', $for_class = '')
327 327
     {
328
-        if (! $this->has_alias($class_name, $for_class)) {
328
+        if ( ! $this->has_alias($class_name, $for_class)) {
329 329
             return $class_name;
330 330
         }
331 331
         if ($for_class !== '') {
@@ -560,10 +560,10 @@  discard block
 block discarded – undo
560 560
             'EE_Front_Controller'                  => 'load_core',
561 561
             'EE_Module_Request_Router'             => 'load_core',
562 562
             'EE_Registry'                          => 'load_core',
563
-            'EE_Request'                           => function () use (&$request) {
563
+            'EE_Request'                           => function() use (&$request) {
564 564
                 return $request;
565 565
             },
566
-            'EE_Response'                          => function () use (&$response) {
566
+            'EE_Response'                          => function() use (&$response) {
567 567
                 return $response;
568 568
             },
569 569
             'EE_Request_Handler'                   => 'load_core',
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
             'EE_Messages_Queue'                    => 'load_lib',
581 581
             'EE_Messages_Data_Handler_Collection'  => 'load_lib',
582 582
             'EE_Message_Template_Group_Collection' => 'load_lib',
583
-            'EE_Messages_Generator'                => function () {
583
+            'EE_Messages_Generator'                => function() {
584 584
                 return EE_Registry::instance()->load_lib(
585 585
                     'Messages_Generator',
586 586
                     array(),
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
                     false
589 589
                 );
590 590
             },
591
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
591
+            'EE_Messages_Template_Defaults'        => function($arguments = array()) {
592 592
                 return EE_Registry::instance()->load_lib(
593 593
                     'Messages_Template_Defaults',
594 594
                     $arguments,
@@ -600,19 +600,19 @@  discard block
 block discarded – undo
600 600
             'EEM_Message_Template_Group'           => 'load_model',
601 601
             'EEM_Message_Template'                 => 'load_model',
602 602
             //load_helper
603
-            'EEH_Parse_Shortcodes'                 => function () {
603
+            'EEH_Parse_Shortcodes'                 => function() {
604 604
                 if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
605 605
                     return new EEH_Parse_Shortcodes();
606 606
                 }
607 607
                 return null;
608 608
             },
609
-            'EE_Template_Config'                   => function () {
609
+            'EE_Template_Config'                   => function() {
610 610
                 return EE_Config::instance()->template_settings;
611 611
             },
612
-            'EE_Currency_Config'                   => function () {
612
+            'EE_Currency_Config'                   => function() {
613 613
                 return EE_Config::instance()->currency;
614 614
             },
615
-            'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
615
+            'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) {
616 616
                 return $loader;
617 617
             },
618 618
         );
Please login to merge, or discard this patch.
core/services/assets/Registry.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
         global $wp_version;
72 72
         wp_register_script(
73 73
             'eejs-core',
74
-            EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js',
74
+            EE_PLUGIN_DIR_URL.'core/services/assets/core_assets/eejs-core.js',
75 75
             array(),
76 76
             EVENT_ESPRESSO_VERSION,
77 77
             true
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
             //js.api
82 82
             wp_register_script(
83 83
                 'eejs-api',
84
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
84
+                EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js',
85 85
                 array('underscore', 'eejs-core'),
86 86
                 EVENT_ESPRESSO_VERSION,
87 87
                 true
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
             $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
90 90
             $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
91 91
         }
92
-        if (! is_admin()) {
92
+        if ( ! is_admin()) {
93 93
             $this->loadCoreCss();
94 94
         }
95 95
         $this->loadCoreJs();
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      */
183 183
     public function addTemplate($template_reference, $template_content)
184 184
     {
185
-        if (! isset($this->jsdata['templates'])) {
185
+        if ( ! isset($this->jsdata['templates'])) {
186 186
             $this->jsdata['templates'] = array();
187 187
         }
188 188
         //no overrides allowed.
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
     private function loadCoreCss()
280 280
     {
281 281
         if ($this->template_config->enable_default_style) {
282
-            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
283
-                ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
284
-                : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
282
+            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')
283
+                ? EVENT_ESPRESSO_UPLOAD_DIR.'css/espresso_default.css'
284
+                : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css';
285 285
             wp_register_style(
286 286
                 'espresso_default',
287 287
                 $default_stylesheet_path,
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
             if ($this->template_config->custom_style_sheet !== null) {
293 293
                 wp_register_style(
294 294
                     'espresso_custom_css',
295
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
295
+                    EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet,
296 296
                     array('espresso_default'),
297 297
                     EVENT_ESPRESSO_VERSION
298 298
                 );
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
         // load core js
311 311
         wp_register_script(
312 312
             'espresso_core',
313
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
313
+            EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
314 314
             array('jquery'),
315 315
             EVENT_ESPRESSO_VERSION,
316 316
             true
@@ -328,14 +328,14 @@  discard block
 block discarded – undo
328 328
         // register jQuery Validate and additional methods
329 329
         wp_register_script(
330 330
             'jquery-validate',
331
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
331
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js',
332 332
             array('jquery'),
333 333
             '1.15.0',
334 334
             true
335 335
         );
336 336
         wp_register_script(
337 337
             'jquery-validate-extra-methods',
338
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
338
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js',
339 339
             array('jquery', 'jquery-validate'),
340 340
             '1.15.0',
341 341
             true
@@ -353,14 +353,14 @@  discard block
 block discarded – undo
353 353
         // @link http://josscrowcroft.github.io/accounting.js/
354 354
         wp_register_script(
355 355
             'ee-accounting-core',
356
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
356
+            EE_THIRD_PARTY_URL.'accounting/accounting.js',
357 357
             array('underscore'),
358 358
             '0.3.2',
359 359
             true
360 360
         );
361 361
         wp_register_script(
362 362
             'ee-accounting',
363
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
363
+            EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js',
364 364
             array('ee-accounting-core'),
365 365
             EVENT_ESPRESSO_VERSION,
366 366
             true
Please login to merge, or discard this patch.
Indentation   +384 added lines, -384 removed lines patch added patch discarded remove patch
@@ -23,394 +23,394 @@
 block discarded – undo
23 23
 class Registry
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Template_Config $template_config
28
-     */
29
-    protected $template_config;
30
-
31
-    /**
32
-     * @var EE_Currency_Config $currency_config
33
-     */
34
-    protected $currency_config;
35
-
36
-    /**
37
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
38
-     *
39
-     * @var array
40
-     */
41
-    protected $jsdata = array();
42
-
43
-
44
-
45
-    /**
46
-     * Registry constructor.
47
-     * Hooking into WP actions for script registry.
48
-     *
49
-     * @param EE_Template_Config $template_config
50
-     * @param EE_Currency_Config $currency_config
51
-     */
52
-    public function __construct(EE_Template_Config $template_config, EE_Currency_Config $currency_config)
53
-    {
54
-        $this->template_config = $template_config;
55
-        $this->currency_config = $currency_config;
56
-        add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
57
-        add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
58
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
59
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
60
-    }
61
-
62
-
63
-
64
-    /**
65
-     * Callback for the WP script actions.
66
-     * Used to register globally accessible core scripts.
67
-     * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
68
-     */
69
-    public function scripts()
70
-    {
71
-        global $wp_version;
72
-        wp_register_script(
73
-            'eejs-core',
74
-            EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js',
75
-            array(),
76
-            EVENT_ESPRESSO_VERSION,
77
-            true
78
-        );
79
-        //only run this if WordPress 4.4.0 > is in use.
80
-        if (version_compare($wp_version, '4.4.0', '>')) {
81
-            //js.api
82
-            wp_register_script(
83
-                'eejs-api',
84
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
85
-                array('underscore', 'eejs-core'),
86
-                EVENT_ESPRESSO_VERSION,
87
-                true
88
-            );
89
-            $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
90
-            $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
91
-        }
92
-        if (! is_admin()) {
93
-            $this->loadCoreCss();
94
-        }
95
-        $this->loadCoreJs();
96
-        $this->loadJqueryValidate();
97
-        $this->loadAccountingJs();
98
-        $this->loadQtipJs();
99
-    }
100
-
101
-
102
-
103
-    /**
104
-     * Call back for the script print in frontend and backend.
105
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
106
-     *
107
-     * @since 4.9.31.rc.015
108
-     */
109
-    public function enqueueData()
110
-    {
111
-        wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata));
112
-        wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
113
-        $this->localizeAccountingJs();
114
-    }
115
-
116
-
117
-
118
-    /**
119
-     * Used to add data to eejs.data object.
120
-     * Note:  Overriding existing data is not allowed.
121
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
122
-     * If the data you add is something like this:
123
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
124
-     * It will be exposed in the page source as:
125
-     *  eejs.data.my_plugin_data.foo == gar
126
-     *
127
-     * @param string       $key   Key used to access your data
128
-     * @param string|array $value Value to attach to key
129
-     * @throws InvalidArgumentException
130
-     */
131
-    public function addData($key, $value)
132
-    {
133
-        if ($this->verifyDataNotExisting($key)) {
134
-            $this->jsdata[$key] = $value;
135
-        }
136
-    }
137
-
138
-
139
-
140
-    /**
141
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
142
-     * elements in an array.
143
-     * When you use this method, the value you include will be appended to the end of an array on $key.
144
-     * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
145
-     * object like this, eejs.data.test = [ my_data,
146
-     * ]
147
-     * If there has already been a scalar value attached to the data object given key, then
148
-     * this will throw an exception.
149
-     *
150
-     * @param string       $key   Key to attach data to.
151
-     * @param string|array $value Value being registered.
152
-     * @throws InvalidArgumentException
153
-     */
154
-    public function pushData($key, $value)
155
-    {
156
-        if (isset($this->jsdata[$key])
157
-            && ! is_array($this->jsdata[$key])
158
-        ) {
159
-            throw new invalidArgumentException(
160
-                sprintf(
161
-                    __(
162
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
26
+	/**
27
+	 * @var EE_Template_Config $template_config
28
+	 */
29
+	protected $template_config;
30
+
31
+	/**
32
+	 * @var EE_Currency_Config $currency_config
33
+	 */
34
+	protected $currency_config;
35
+
36
+	/**
37
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
38
+	 *
39
+	 * @var array
40
+	 */
41
+	protected $jsdata = array();
42
+
43
+
44
+
45
+	/**
46
+	 * Registry constructor.
47
+	 * Hooking into WP actions for script registry.
48
+	 *
49
+	 * @param EE_Template_Config $template_config
50
+	 * @param EE_Currency_Config $currency_config
51
+	 */
52
+	public function __construct(EE_Template_Config $template_config, EE_Currency_Config $currency_config)
53
+	{
54
+		$this->template_config = $template_config;
55
+		$this->currency_config = $currency_config;
56
+		add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
57
+		add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
58
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
59
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
60
+	}
61
+
62
+
63
+
64
+	/**
65
+	 * Callback for the WP script actions.
66
+	 * Used to register globally accessible core scripts.
67
+	 * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
68
+	 */
69
+	public function scripts()
70
+	{
71
+		global $wp_version;
72
+		wp_register_script(
73
+			'eejs-core',
74
+			EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js',
75
+			array(),
76
+			EVENT_ESPRESSO_VERSION,
77
+			true
78
+		);
79
+		//only run this if WordPress 4.4.0 > is in use.
80
+		if (version_compare($wp_version, '4.4.0', '>')) {
81
+			//js.api
82
+			wp_register_script(
83
+				'eejs-api',
84
+				EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
85
+				array('underscore', 'eejs-core'),
86
+				EVENT_ESPRESSO_VERSION,
87
+				true
88
+			);
89
+			$this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
90
+			$this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
91
+		}
92
+		if (! is_admin()) {
93
+			$this->loadCoreCss();
94
+		}
95
+		$this->loadCoreJs();
96
+		$this->loadJqueryValidate();
97
+		$this->loadAccountingJs();
98
+		$this->loadQtipJs();
99
+	}
100
+
101
+
102
+
103
+	/**
104
+	 * Call back for the script print in frontend and backend.
105
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
106
+	 *
107
+	 * @since 4.9.31.rc.015
108
+	 */
109
+	public function enqueueData()
110
+	{
111
+		wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata));
112
+		wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
113
+		$this->localizeAccountingJs();
114
+	}
115
+
116
+
117
+
118
+	/**
119
+	 * Used to add data to eejs.data object.
120
+	 * Note:  Overriding existing data is not allowed.
121
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
122
+	 * If the data you add is something like this:
123
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
124
+	 * It will be exposed in the page source as:
125
+	 *  eejs.data.my_plugin_data.foo == gar
126
+	 *
127
+	 * @param string       $key   Key used to access your data
128
+	 * @param string|array $value Value to attach to key
129
+	 * @throws InvalidArgumentException
130
+	 */
131
+	public function addData($key, $value)
132
+	{
133
+		if ($this->verifyDataNotExisting($key)) {
134
+			$this->jsdata[$key] = $value;
135
+		}
136
+	}
137
+
138
+
139
+
140
+	/**
141
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
142
+	 * elements in an array.
143
+	 * When you use this method, the value you include will be appended to the end of an array on $key.
144
+	 * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
145
+	 * object like this, eejs.data.test = [ my_data,
146
+	 * ]
147
+	 * If there has already been a scalar value attached to the data object given key, then
148
+	 * this will throw an exception.
149
+	 *
150
+	 * @param string       $key   Key to attach data to.
151
+	 * @param string|array $value Value being registered.
152
+	 * @throws InvalidArgumentException
153
+	 */
154
+	public function pushData($key, $value)
155
+	{
156
+		if (isset($this->jsdata[$key])
157
+			&& ! is_array($this->jsdata[$key])
158
+		) {
159
+			throw new invalidArgumentException(
160
+				sprintf(
161
+					__(
162
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
163 163
                          push values to this data element when it is an array.',
164
-                        'event_espresso'
165
-                    ),
166
-                    $key,
167
-                    __METHOD__
168
-                )
169
-            );
170
-        }
171
-        $this->jsdata[$key][] = $value;
172
-    }
173
-
174
-
175
-
176
-    /**
177
-     * Used to set content used by javascript for a template.
178
-     * Note: Overrides of existing registered templates are not allowed.
179
-     *
180
-     * @param string $template_reference
181
-     * @param string $template_content
182
-     * @throws InvalidArgumentException
183
-     */
184
-    public function addTemplate($template_reference, $template_content)
185
-    {
186
-        if (! isset($this->jsdata['templates'])) {
187
-            $this->jsdata['templates'] = array();
188
-        }
189
-        //no overrides allowed.
190
-        if (isset($this->jsdata['templates'][$template_reference])) {
191
-            throw new invalidArgumentException(
192
-                sprintf(
193
-                    __(
194
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
195
-                        'event_espresso'
196
-                    ),
197
-                    $template_reference
198
-                )
199
-            );
200
-        }
201
-        $this->jsdata['templates'][$template_reference] = $template_content;
202
-    }
203
-
204
-
205
-
206
-    /**
207
-     * Retrieve the template content already registered for the given reference.
208
-     *
209
-     * @param string $template_reference
210
-     * @return string
211
-     */
212
-    public function getTemplate($template_reference)
213
-    {
214
-        return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference])
215
-            ? $this->jsdata['templates'][$template_reference]
216
-            : '';
217
-    }
218
-
219
-
220
-
221
-    /**
222
-     * Retrieve registered data.
223
-     *
224
-     * @param string $key Name of key to attach data to.
225
-     * @return mixed                If there is no for the given key, then false is returned.
226
-     */
227
-    public function getData($key)
228
-    {
229
-        return isset($this->jsdata[$key])
230
-            ? $this->jsdata[$key]
231
-            : false;
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * Verifies whether the given data exists already on the jsdata array.
238
-     * Overriding data is not allowed.
239
-     *
240
-     * @param string $key Index for data.
241
-     * @return bool        If valid then return true.
242
-     * @throws InvalidArgumentException if data already exists.
243
-     */
244
-    protected function verifyDataNotExisting($key)
245
-    {
246
-        if (isset($this->jsdata[$key])) {
247
-            if (is_array($this->jsdata[$key])) {
248
-                throw new InvalidArgumentException(
249
-                    sprintf(
250
-                        __(
251
-                            'The value for %1$s already exists in the Registry::eejs object.
164
+						'event_espresso'
165
+					),
166
+					$key,
167
+					__METHOD__
168
+				)
169
+			);
170
+		}
171
+		$this->jsdata[$key][] = $value;
172
+	}
173
+
174
+
175
+
176
+	/**
177
+	 * Used to set content used by javascript for a template.
178
+	 * Note: Overrides of existing registered templates are not allowed.
179
+	 *
180
+	 * @param string $template_reference
181
+	 * @param string $template_content
182
+	 * @throws InvalidArgumentException
183
+	 */
184
+	public function addTemplate($template_reference, $template_content)
185
+	{
186
+		if (! isset($this->jsdata['templates'])) {
187
+			$this->jsdata['templates'] = array();
188
+		}
189
+		//no overrides allowed.
190
+		if (isset($this->jsdata['templates'][$template_reference])) {
191
+			throw new invalidArgumentException(
192
+				sprintf(
193
+					__(
194
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
195
+						'event_espresso'
196
+					),
197
+					$template_reference
198
+				)
199
+			);
200
+		}
201
+		$this->jsdata['templates'][$template_reference] = $template_content;
202
+	}
203
+
204
+
205
+
206
+	/**
207
+	 * Retrieve the template content already registered for the given reference.
208
+	 *
209
+	 * @param string $template_reference
210
+	 * @return string
211
+	 */
212
+	public function getTemplate($template_reference)
213
+	{
214
+		return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference])
215
+			? $this->jsdata['templates'][$template_reference]
216
+			: '';
217
+	}
218
+
219
+
220
+
221
+	/**
222
+	 * Retrieve registered data.
223
+	 *
224
+	 * @param string $key Name of key to attach data to.
225
+	 * @return mixed                If there is no for the given key, then false is returned.
226
+	 */
227
+	public function getData($key)
228
+	{
229
+		return isset($this->jsdata[$key])
230
+			? $this->jsdata[$key]
231
+			: false;
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 * Verifies whether the given data exists already on the jsdata array.
238
+	 * Overriding data is not allowed.
239
+	 *
240
+	 * @param string $key Index for data.
241
+	 * @return bool        If valid then return true.
242
+	 * @throws InvalidArgumentException if data already exists.
243
+	 */
244
+	protected function verifyDataNotExisting($key)
245
+	{
246
+		if (isset($this->jsdata[$key])) {
247
+			if (is_array($this->jsdata[$key])) {
248
+				throw new InvalidArgumentException(
249
+					sprintf(
250
+						__(
251
+							'The value for %1$s already exists in the Registry::eejs object.
252 252
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
253 253
                             %2$s method to push your value to the array.',
254
-                            'event_espresso'
255
-                        ),
256
-                        $key,
257
-                        'pushData()'
258
-                    )
259
-                );
260
-            }
261
-            throw new InvalidArgumentException(
262
-                sprintf(
263
-                    __(
264
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
254
+							'event_espresso'
255
+						),
256
+						$key,
257
+						'pushData()'
258
+					)
259
+				);
260
+			}
261
+			throw new InvalidArgumentException(
262
+				sprintf(
263
+					__(
264
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
265 265
                         allowed.  Consider attaching your value to a different key',
266
-                        'event_espresso'
267
-                    ),
268
-                    $key
269
-                )
270
-            );
271
-        }
272
-        return true;
273
-    }
274
-
275
-
276
-
277
-    /**
278
-     * registers core default stylesheets
279
-     */
280
-    private function loadCoreCss()
281
-    {
282
-        if ($this->template_config->enable_default_style) {
283
-            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
284
-                ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
285
-                : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
286
-            wp_register_style(
287
-                'espresso_default',
288
-                $default_stylesheet_path,
289
-                array('dashicons'),
290
-                EVENT_ESPRESSO_VERSION
291
-            );
292
-            //Load custom style sheet if available
293
-            if ($this->template_config->custom_style_sheet !== null) {
294
-                wp_register_style(
295
-                    'espresso_custom_css',
296
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
297
-                    array('espresso_default'),
298
-                    EVENT_ESPRESSO_VERSION
299
-                );
300
-            }
301
-        }
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * registers core default javascript
308
-     */
309
-    private function loadCoreJs()
310
-    {
311
-        // load core js
312
-        wp_register_script(
313
-            'espresso_core',
314
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
315
-            array('jquery'),
316
-            EVENT_ESPRESSO_VERSION,
317
-            true
318
-        );
319
-    }
320
-
321
-
322
-
323
-    /**
324
-     * registers jQuery Validate for form validation
325
-     */
326
-    private function loadJqueryValidate()
327
-    {
328
-        // register jQuery Validate and additional methods
329
-        wp_register_script(
330
-            'jquery-validate',
331
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
332
-            array('jquery'),
333
-            '1.15.0',
334
-            true
335
-        );
336
-        wp_register_script(
337
-            'jquery-validate-extra-methods',
338
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
339
-            array('jquery', 'jquery-validate'),
340
-            '1.15.0',
341
-            true
342
-        );
343
-    }
344
-
345
-
346
-
347
-    /**
348
-     * registers accounting.js for performing client-side calculations
349
-     */
350
-    private function loadAccountingJs()
351
-    {
352
-        //accounting.js library
353
-        // @link http://josscrowcroft.github.io/accounting.js/
354
-        wp_register_script(
355
-            'ee-accounting-core',
356
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
357
-            array('underscore'),
358
-            '0.3.2',
359
-            true
360
-        );
361
-        wp_register_script(
362
-            'ee-accounting',
363
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
364
-            array('ee-accounting-core'),
365
-            EVENT_ESPRESSO_VERSION,
366
-            true
367
-        );
368
-    }
369
-
370
-
371
-
372
-    /**
373
-     * registers accounting.js for performing client-side calculations
374
-     */
375
-    private function localizeAccountingJs()
376
-    {
377
-        wp_localize_script(
378
-            'ee-accounting',
379
-            'EE_ACCOUNTING_CFG',
380
-            array(
381
-                'currency' => array(
382
-                    'symbol'    => $this->currency_config->sign,
383
-                    'format'    => array(
384
-                        'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
385
-                        'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
386
-                        'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
387
-                    ),
388
-                    'decimal'   => $this->currency_config->dec_mrk,
389
-                    'thousand'  => $this->currency_config->thsnds,
390
-                    'precision' => $this->currency_config->dec_plc,
391
-                ),
392
-                'number'   => array(
393
-                    'precision' => 0,
394
-                    'thousand'  => $this->currency_config->thsnds,
395
-                    'decimal'   => $this->currency_config->dec_mrk,
396
-                ),
397
-            )
398
-        );
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * registers assets for cleaning your ears
405
-     */
406
-    private function loadQtipJs()
407
-    {
408
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
409
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
410
-        if (apply_filters('FHEE_load_qtip', false)) {
411
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
412
-        }
413
-    }
266
+						'event_espresso'
267
+					),
268
+					$key
269
+				)
270
+			);
271
+		}
272
+		return true;
273
+	}
274
+
275
+
276
+
277
+	/**
278
+	 * registers core default stylesheets
279
+	 */
280
+	private function loadCoreCss()
281
+	{
282
+		if ($this->template_config->enable_default_style) {
283
+			$default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
284
+				? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
285
+				: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
286
+			wp_register_style(
287
+				'espresso_default',
288
+				$default_stylesheet_path,
289
+				array('dashicons'),
290
+				EVENT_ESPRESSO_VERSION
291
+			);
292
+			//Load custom style sheet if available
293
+			if ($this->template_config->custom_style_sheet !== null) {
294
+				wp_register_style(
295
+					'espresso_custom_css',
296
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
297
+					array('espresso_default'),
298
+					EVENT_ESPRESSO_VERSION
299
+				);
300
+			}
301
+		}
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * registers core default javascript
308
+	 */
309
+	private function loadCoreJs()
310
+	{
311
+		// load core js
312
+		wp_register_script(
313
+			'espresso_core',
314
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
315
+			array('jquery'),
316
+			EVENT_ESPRESSO_VERSION,
317
+			true
318
+		);
319
+	}
320
+
321
+
322
+
323
+	/**
324
+	 * registers jQuery Validate for form validation
325
+	 */
326
+	private function loadJqueryValidate()
327
+	{
328
+		// register jQuery Validate and additional methods
329
+		wp_register_script(
330
+			'jquery-validate',
331
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
332
+			array('jquery'),
333
+			'1.15.0',
334
+			true
335
+		);
336
+		wp_register_script(
337
+			'jquery-validate-extra-methods',
338
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
339
+			array('jquery', 'jquery-validate'),
340
+			'1.15.0',
341
+			true
342
+		);
343
+	}
344
+
345
+
346
+
347
+	/**
348
+	 * registers accounting.js for performing client-side calculations
349
+	 */
350
+	private function loadAccountingJs()
351
+	{
352
+		//accounting.js library
353
+		// @link http://josscrowcroft.github.io/accounting.js/
354
+		wp_register_script(
355
+			'ee-accounting-core',
356
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
357
+			array('underscore'),
358
+			'0.3.2',
359
+			true
360
+		);
361
+		wp_register_script(
362
+			'ee-accounting',
363
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
364
+			array('ee-accounting-core'),
365
+			EVENT_ESPRESSO_VERSION,
366
+			true
367
+		);
368
+	}
369
+
370
+
371
+
372
+	/**
373
+	 * registers accounting.js for performing client-side calculations
374
+	 */
375
+	private function localizeAccountingJs()
376
+	{
377
+		wp_localize_script(
378
+			'ee-accounting',
379
+			'EE_ACCOUNTING_CFG',
380
+			array(
381
+				'currency' => array(
382
+					'symbol'    => $this->currency_config->sign,
383
+					'format'    => array(
384
+						'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
385
+						'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
386
+						'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
387
+					),
388
+					'decimal'   => $this->currency_config->dec_mrk,
389
+					'thousand'  => $this->currency_config->thsnds,
390
+					'precision' => $this->currency_config->dec_plc,
391
+				),
392
+				'number'   => array(
393
+					'precision' => 0,
394
+					'thousand'  => $this->currency_config->thsnds,
395
+					'decimal'   => $this->currency_config->dec_mrk,
396
+				),
397
+			)
398
+		);
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * registers assets for cleaning your ears
405
+	 */
406
+	private function loadQtipJs()
407
+	{
408
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
409
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
410
+		if (apply_filters('FHEE_load_qtip', false)) {
411
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
412
+		}
413
+	}
414 414
 
415 415
 
416 416
 
Please login to merge, or discard this patch.
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 2 patches
Indentation   +1849 added lines, -1849 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\InvalidEntityException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -20,1854 +20,1854 @@  discard block
 block discarded – undo
20 20
 class EED_Single_Page_Checkout extends EED_Module
21 21
 {
22 22
 
23
-    /**
24
-     * $_initialized - has the SPCO controller already been initialized ?
25
-     *
26
-     * @access private
27
-     * @var bool $_initialized
28
-     */
29
-    private static $_initialized = false;
30
-
31
-
32
-    /**
33
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
-     *
35
-     * @access private
36
-     * @var bool $_valid_checkout
37
-     */
38
-    private static $_checkout_verified = true;
39
-
40
-    /**
41
-     *    $_reg_steps_array - holds initial array of reg steps
42
-     *
43
-     * @access private
44
-     * @var array $_reg_steps_array
45
-     */
46
-    private static $_reg_steps_array = array();
47
-
48
-    /**
49
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
-     *
51
-     * @access public
52
-     * @var EE_Checkout $checkout
53
-     */
54
-    public $checkout;
55
-
56
-
57
-
58
-    /**
59
-     * @return EED_Module|EED_Single_Page_Checkout
60
-     */
61
-    public static function instance()
62
-    {
63
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
-        return parent::get_instance(__CLASS__);
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * @return EE_CART
71
-     */
72
-    public function cart()
73
-    {
74
-        return $this->checkout->cart;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * @return EE_Transaction
81
-     */
82
-    public function transaction()
83
-    {
84
-        return $this->checkout->transaction;
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     *    set_hooks - for hooking into EE Core, other modules, etc
91
-     *
92
-     * @access    public
93
-     * @return    void
94
-     * @throws EE_Error
95
-     */
96
-    public static function set_hooks()
97
-    {
98
-        EED_Single_Page_Checkout::set_definitions();
99
-    }
100
-
101
-
102
-
103
-    /**
104
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
-     *
106
-     * @access    public
107
-     * @return    void
108
-     * @throws EE_Error
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        EED_Single_Page_Checkout::set_definitions();
113
-        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
-            return;
115
-        }
116
-        // going to start an output buffer in case anything gets accidentally output
117
-        // that might disrupt our JSON response
118
-        ob_start();
119
-        EED_Single_Page_Checkout::load_request_handler();
120
-        EED_Single_Page_Checkout::load_reg_steps();
121
-        // set ajax hooks
122
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     *    process ajax request
134
-     *
135
-     * @param string $ajax_action
136
-     * @throws EE_Error
137
-     */
138
-    public static function process_ajax_request($ajax_action)
139
-    {
140
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
141
-        EED_Single_Page_Checkout::instance()->_initialize();
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     *    ajax display registration step
148
-     *
149
-     * @throws EE_Error
150
-     */
151
-    public static function display_reg_step()
152
-    {
153
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     *    ajax process registration step
160
-     *
161
-     * @throws EE_Error
162
-     */
163
-    public static function process_reg_step()
164
-    {
165
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     *    ajax process registration step
172
-     *
173
-     * @throws EE_Error
174
-     */
175
-    public static function update_reg_step()
176
-    {
177
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     *   update_checkout
184
-     *
185
-     * @access public
186
-     * @return void
187
-     * @throws EE_Error
188
-     */
189
-    public static function update_checkout()
190
-    {
191
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
-    }
193
-
194
-
195
-
196
-    /**
197
-     *    load_request_handler
198
-     *
199
-     * @access    public
200
-     * @return    void
201
-     */
202
-    public static function load_request_handler()
203
-    {
204
-        // load core Request_Handler class
205
-        if (EE_Registry::instance()->REQ !== null) {
206
-            EE_Registry::instance()->load_core('Request_Handler');
207
-        }
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     *    set_definitions
214
-     *
215
-     * @access    public
216
-     * @return    void
217
-     * @throws EE_Error
218
-     */
219
-    public static function set_definitions()
220
-    {
221
-        if(defined('SPCO_BASE_PATH')) {
222
-            return;
223
-        }
224
-        define(
225
-            'SPCO_BASE_PATH',
226
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
-        );
228
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
236
-            __('%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',
237
-                'event_espresso'),
238
-            '<h4 class="important-notice">',
239
-            '</h4>',
240
-            '<br />',
241
-            '<p>',
242
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
243
-            '">',
244
-            '</a>',
245
-            '</p>'
246
-        );
247
-    }
248
-
249
-
250
-
251
-    /**
252
-     * load_reg_steps
253
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
254
-     *
255
-     * @access    private
256
-     * @throws EE_Error
257
-     */
258
-    public static function load_reg_steps()
259
-    {
260
-        static $reg_steps_loaded = false;
261
-        if ($reg_steps_loaded) {
262
-            return;
263
-        }
264
-        // filter list of reg_steps
265
-        $reg_steps_to_load = (array)apply_filters(
266
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
267
-            EED_Single_Page_Checkout::get_reg_steps()
268
-        );
269
-        // sort by key (order)
270
-        ksort($reg_steps_to_load);
271
-        // loop through folders
272
-        foreach ($reg_steps_to_load as $order => $reg_step) {
273
-            // we need a
274
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
275
-                // copy over to the reg_steps_array
276
-                EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
277
-                // register custom key route for each reg step
278
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
279
-                EE_Config::register_route(
280
-                    $reg_step['slug'],
281
-                    'EED_Single_Page_Checkout',
282
-                    'run',
283
-                    'step'
284
-                );
285
-                // add AJAX or other hooks
286
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
287
-                    // setup autoloaders if necessary
288
-                    if ( ! class_exists($reg_step['class_name'])) {
289
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
290
-                            $reg_step['file_path'],
291
-                            true
292
-                        );
293
-                    }
294
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
295
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
296
-                    }
297
-                }
298
-            }
299
-        }
300
-        $reg_steps_loaded = true;
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     *    get_reg_steps
307
-     *
308
-     * @access    public
309
-     * @return    array
310
-     */
311
-    public static function get_reg_steps()
312
-    {
313
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
314
-        if (empty($reg_steps)) {
315
-            $reg_steps = array(
316
-                10  => array(
317
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
318
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
319
-                    'slug'       => 'attendee_information',
320
-                    'has_hooks'  => false,
321
-                ),
322
-                20  => array(
323
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
324
-                    'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
325
-                    'slug'       => 'registration_confirmation',
326
-                    'has_hooks'  => false,
327
-                ),
328
-                30  => array(
329
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
330
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
331
-                    'slug'       => 'payment_options',
332
-                    'has_hooks'  => true,
333
-                ),
334
-                999 => array(
335
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
336
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
337
-                    'slug'       => 'finalize_registration',
338
-                    'has_hooks'  => false,
339
-                ),
340
-            );
341
-        }
342
-        return $reg_steps;
343
-    }
344
-
345
-
346
-
347
-    /**
348
-     *    registration_checkout_for_admin
349
-     *
350
-     * @access    public
351
-     * @return    string
352
-     * @throws EE_Error
353
-     */
354
-    public static function registration_checkout_for_admin()
355
-    {
356
-        EED_Single_Page_Checkout::load_request_handler();
357
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
358
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
359
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
360
-        EED_Single_Page_Checkout::instance()->_initialize();
361
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
362
-        return EE_Registry::instance()->REQ->get_output();
363
-    }
364
-
365
-
366
-
367
-    /**
368
-     * process_registration_from_admin
369
-     *
370
-     * @access public
371
-     * @return \EE_Transaction
372
-     * @throws EE_Error
373
-     */
374
-    public static function process_registration_from_admin()
375
-    {
376
-        EED_Single_Page_Checkout::load_request_handler();
377
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
378
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
379
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
380
-        EED_Single_Page_Checkout::instance()->_initialize();
381
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
382
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
383
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
384
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
385
-                if ($final_reg_step->process_reg_step()) {
386
-                    $final_reg_step->set_completed();
387
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
388
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
389
-                }
390
-            }
391
-        }
392
-        return null;
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     *    run
399
-     *
400
-     * @access    public
401
-     * @param WP_Query $WP_Query
402
-     * @return    void
403
-     * @throws EE_Error
404
-     */
405
-    public function run($WP_Query)
406
-    {
407
-        if (
408
-            $WP_Query instanceof WP_Query
409
-            && $WP_Query->is_main_query()
410
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
411
-            && $this->_is_reg_checkout()
412
-        ) {
413
-            $this->_initialize();
414
-        }
415
-    }
416
-
417
-
418
-
419
-    /**
420
-     * determines whether current url matches reg page url
421
-     *
422
-     * @return bool
423
-     */
424
-    protected function _is_reg_checkout()
425
-    {
426
-        // get current permalink for reg page without any extra query args
427
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
428
-        // get request URI for current request, but without the scheme or host
429
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
430
-        $current_request_uri = html_entity_decode($current_request_uri);
431
-        // get array of query args from the current request URI
432
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
433
-        // grab page id if it is set
434
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
435
-        // and remove the page id from the query args (we will re-add it later)
436
-        unset($query_args['page_id']);
437
-        // now strip all query args from current request URI
438
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
439
-        // and re-add the page id if it was set
440
-        if ($page_id) {
441
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
442
-        }
443
-        // remove slashes and ?
444
-        $current_request_uri = trim($current_request_uri, '?/');
445
-        // is current request URI part of the known full reg page URL ?
446
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
447
-    }
448
-
449
-
450
-
451
-    /**
452
-     * @param WP_Query $wp_query
453
-     * @return    void
454
-     * @throws EE_Error
455
-     */
456
-    public static function init($wp_query)
457
-    {
458
-        EED_Single_Page_Checkout::instance()->run($wp_query);
459
-    }
460
-
461
-
462
-
463
-    /**
464
-     *    _initialize - initial module setup
465
-     *
466
-     * @access    private
467
-     * @throws EE_Error
468
-     * @return    void
469
-     */
470
-    private function _initialize()
471
-    {
472
-        // ensure SPCO doesn't run twice
473
-        if (EED_Single_Page_Checkout::$_initialized) {
474
-            return;
475
-        }
476
-        try {
477
-            EED_Single_Page_Checkout::load_reg_steps();
478
-            $this->_verify_session();
479
-            // setup the EE_Checkout object
480
-            $this->checkout = $this->_initialize_checkout();
481
-            // filter checkout
482
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
483
-            // get the $_GET
484
-            $this->_get_request_vars();
485
-            if ($this->_block_bots()) {
486
-                return;
487
-            }
488
-            // filter continue_reg
489
-            $this->checkout->continue_reg = apply_filters(
490
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
491
-                true,
492
-                $this->checkout
493
-            );
494
-            // load the reg steps array
495
-            if ( ! $this->_load_and_instantiate_reg_steps()) {
496
-                EED_Single_Page_Checkout::$_initialized = true;
497
-                return;
498
-            }
499
-            // set the current step
500
-            $this->checkout->set_current_step($this->checkout->step);
501
-            // and the next step
502
-            $this->checkout->set_next_step();
503
-            // verify that everything has been setup correctly
504
-            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
505
-                EED_Single_Page_Checkout::$_initialized = true;
506
-                return;
507
-            }
508
-            // lock the transaction
509
-            $this->checkout->transaction->lock();
510
-            // make sure all of our cached objects are added to their respective model entity mappers
511
-            $this->checkout->refresh_all_entities();
512
-            // set amount owing
513
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
514
-            // initialize each reg step, which gives them the chance to potentially alter the process
515
-            $this->_initialize_reg_steps();
516
-            // DEBUG LOG
517
-            //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
518
-            // get reg form
519
-            if( ! $this->_check_form_submission()) {
520
-                EED_Single_Page_Checkout::$_initialized = true;
521
-                return;
522
-            }
523
-            // checkout the action!!!
524
-            $this->_process_form_action();
525
-            // add some style and make it dance
526
-            $this->add_styles_and_scripts();
527
-            // kk... SPCO has successfully run
528
-            EED_Single_Page_Checkout::$_initialized = true;
529
-            // set no cache headers and constants
530
-            EE_System::do_not_cache();
531
-            // add anchor
532
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
533
-            // remove transaction lock
534
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
535
-        } catch (Exception $e) {
536
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
537
-        }
538
-    }
539
-
540
-
541
-
542
-    /**
543
-     *    _verify_session
544
-     * checks that the session is valid and not expired
545
-     *
546
-     * @access    private
547
-     * @throws EE_Error
548
-     */
549
-    private function _verify_session()
550
-    {
551
-        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
552
-            throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
553
-        }
554
-        // is session still valid ?
555
-        if (
556
-            EE_Registry::instance()->SSN->expired()
557
-            && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
558
-        ) {
559
-            $this->checkout = new EE_Checkout();
560
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
561
-            // EE_Registry::instance()->SSN->reset_cart();
562
-            // EE_Registry::instance()->SSN->reset_checkout();
563
-            // EE_Registry::instance()->SSN->reset_transaction();
564
-            EE_Error::add_attention(
565
-                EE_Registry::$i18n_js_strings['registration_expiration_notice'],
566
-                __FILE__, __FUNCTION__, __LINE__
567
-            );
568
-            // EE_Registry::instance()->SSN->reset_expired();
569
-        }
570
-    }
571
-
572
-
573
-
574
-    /**
575
-     *    _initialize_checkout
576
-     * loads and instantiates EE_Checkout
577
-     *
578
-     * @access    private
579
-     * @throws EE_Error
580
-     * @return EE_Checkout
581
-     */
582
-    private function _initialize_checkout()
583
-    {
584
-        // look in session for existing checkout
585
-        /** @type EE_Checkout $checkout */
586
-        $checkout = EE_Registry::instance()->SSN->checkout();
587
-        // verify
588
-        if ( ! $checkout instanceof EE_Checkout) {
589
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
590
-            $checkout = EE_Registry::instance()->load_file(
591
-                SPCO_INC_PATH,
592
-                'EE_Checkout',
593
-                'class', array(),
594
-                false
595
-            );
596
-        } else {
597
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
598
-                $this->unlock_transaction();
599
-                wp_safe_redirect($checkout->redirect_url);
600
-                exit();
601
-            }
602
-        }
603
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
604
-        // verify again
605
-        if ( ! $checkout instanceof EE_Checkout) {
606
-            throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
607
-        }
608
-        // reset anything that needs a clean slate for each request
609
-        $checkout->reset_for_current_request();
610
-        return $checkout;
611
-    }
612
-
613
-
614
-
615
-    /**
616
-     *    _get_request_vars
617
-     *
618
-     * @access    private
619
-     * @return    void
620
-     * @throws EE_Error
621
-     */
622
-    private function _get_request_vars()
623
-    {
624
-        // load classes
625
-        EED_Single_Page_Checkout::load_request_handler();
626
-        //make sure this request is marked as belonging to EE
627
-        EE_Registry::instance()->REQ->set_espresso_page(true);
628
-        // which step is being requested ?
629
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
630
-        // which step is being edited ?
631
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
632
-        // and what we're doing on the current step
633
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
634
-        // timestamp
635
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
636
-        // returning to edit ?
637
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
638
-        // or some other kind of revisit ?
639
-        $this->checkout->revisit = filter_var(
640
-            EE_Registry::instance()->REQ->get('revisit', false),
641
-            FILTER_VALIDATE_BOOLEAN
642
-        );
643
-        // and whether or not to generate a reg form for this request
644
-        $this->checkout->generate_reg_form = filter_var(
645
-            EE_Registry::instance()->REQ->get('generate_reg_form', true),
646
-            FILTER_VALIDATE_BOOLEAN
647
-        );
648
-        // and whether or not to process a reg form submission for this request
649
-        $this->checkout->process_form_submission = filter_var(
650
-            EE_Registry::instance()->REQ->get(
651
-                'process_form_submission',
652
-                $this->checkout->action === 'process_reg_step'
653
-            ),
654
-            FILTER_VALIDATE_BOOLEAN
655
-        );
656
-        $this->checkout->process_form_submission = filter_var(
657
-            $this->checkout->action !== 'display_spco_reg_step'
658
-                ? $this->checkout->process_form_submission
659
-                : false,
660
-            FILTER_VALIDATE_BOOLEAN
661
-        );
662
-        // $this->_display_request_vars();
663
-    }
664
-
665
-
666
-
667
-    /**
668
-     *  _display_request_vars
669
-     *
670
-     * @access    protected
671
-     * @return    void
672
-     */
673
-    protected function _display_request_vars()
674
-    {
675
-        if ( ! WP_DEBUG) {
676
-            return;
677
-        }
678
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
679
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
680
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
681
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
682
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
683
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
684
-        EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
685
-        EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * _block_bots
692
-     * checks that the incoming request has either of the following set:
693
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
694
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
695
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
696
-     * then where you coming from man?
697
-     *
698
-     * @return boolean
699
-     */
700
-    private function _block_bots()
701
-    {
702
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
703
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
704
-            return true;
705
-        }
706
-        return false;
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     *    _get_first_step
713
-     *  gets slug for first step in $_reg_steps_array
714
-     *
715
-     * @access    private
716
-     * @throws EE_Error
717
-     * @return    string
718
-     */
719
-    private function _get_first_step()
720
-    {
721
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
722
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
723
-    }
724
-
725
-
726
-
727
-    /**
728
-     *    _load_and_instantiate_reg_steps
729
-     *  instantiates each reg step based on the loaded reg_steps array
730
-     *
731
-     * @access    private
732
-     * @throws EE_Error
733
-     * @return    bool
734
-     */
735
-    private function _load_and_instantiate_reg_steps()
736
-    {
737
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
738
-        // have reg_steps already been instantiated ?
739
-        if (
740
-            empty($this->checkout->reg_steps)
741
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
742
-        ) {
743
-            // if not, then loop through raw reg steps array
744
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
745
-                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
746
-                    return false;
747
-                }
748
-            }
749
-            EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
750
-            EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
751
-            // skip the registration_confirmation page ?
752
-            if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
753
-                // just remove it from the reg steps array
754
-                $this->checkout->remove_reg_step('registration_confirmation', false);
755
-            } else if (
756
-                isset($this->checkout->reg_steps['registration_confirmation'])
757
-                && EE_Registry::instance()->CFG->registration->reg_confirmation_last
758
-            ) {
759
-                // set the order to something big like 100
760
-                $this->checkout->set_reg_step_order('registration_confirmation', 100);
761
-            }
762
-            // filter the array for good luck
763
-            $this->checkout->reg_steps = apply_filters(
764
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
765
-                $this->checkout->reg_steps
766
-            );
767
-            // finally re-sort based on the reg step class order properties
768
-            $this->checkout->sort_reg_steps();
769
-        } else {
770
-            foreach ($this->checkout->reg_steps as $reg_step) {
771
-                // set all current step stati to FALSE
772
-                $reg_step->set_is_current_step(false);
773
-            }
774
-        }
775
-        if (empty($this->checkout->reg_steps)) {
776
-            EE_Error::add_error(
777
-                __('No Reg Steps were loaded..', 'event_espresso'),
778
-                __FILE__, __FUNCTION__, __LINE__
779
-            );
780
-            return false;
781
-        }
782
-        // make reg step details available to JS
783
-        $this->checkout->set_reg_step_JSON_info();
784
-        return true;
785
-    }
786
-
787
-
788
-
789
-    /**
790
-     *     _load_and_instantiate_reg_step
791
-     *
792
-     * @access    private
793
-     * @param array $reg_step
794
-     * @param int   $order
795
-     * @return bool
796
-     */
797
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
798
-    {
799
-        // we need a file_path, class_name, and slug to add a reg step
800
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
801
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
802
-            if (
803
-                $this->checkout->reg_url_link
804
-                && $this->checkout->step !== $reg_step['slug']
805
-                && $reg_step['slug'] !== 'finalize_registration'
806
-                // normally at this point we would NOT load the reg step, but this filter can change that
807
-                && apply_filters(
808
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
809
-                    true,
810
-                    $reg_step,
811
-                    $this->checkout
812
-                )
813
-            ) {
814
-                return true;
815
-            }
816
-            // instantiate step class using file path and class name
817
-            $reg_step_obj = EE_Registry::instance()->load_file(
818
-                $reg_step['file_path'],
819
-                $reg_step['class_name'],
820
-                'class',
821
-                $this->checkout,
822
-                false
823
-            );
824
-            // did we gets the goods ?
825
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
826
-                // set reg step order based on config
827
-                $reg_step_obj->set_order($order);
828
-                // add instantiated reg step object to the master reg steps array
829
-                $this->checkout->add_reg_step($reg_step_obj);
830
-            } else {
831
-                EE_Error::add_error(
832
-                    __('The current step could not be set.', 'event_espresso'),
833
-                    __FILE__, __FUNCTION__, __LINE__
834
-                );
835
-                return false;
836
-            }
837
-        } else {
838
-            if (WP_DEBUG) {
839
-                EE_Error::add_error(
840
-                    sprintf(
841
-                        __(
842
-                            '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',
843
-                            'event_espresso'
844
-                        ),
845
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
846
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
847
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
848
-                        '<ul>',
849
-                        '<li>',
850
-                        '</li>',
851
-                        '</ul>'
852
-                    ),
853
-                    __FILE__, __FUNCTION__, __LINE__
854
-                );
855
-            }
856
-            return false;
857
-        }
858
-        return true;
859
-    }
860
-
861
-
862
-    /**
863
-     * _verify_transaction_and_get_registrations
864
-     *
865
-     * @access private
866
-     * @return bool
867
-     * @throws InvalidDataTypeException
868
-     * @throws InvalidEntityException
869
-     * @throws EE_Error
870
-     */
871
-    private function _verify_transaction_and_get_registrations()
872
-    {
873
-        // was there already a valid transaction in the checkout from the session ?
874
-        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
875
-            // get transaction from db or session
876
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
877
-                ? $this->_get_transaction_and_cart_for_previous_visit()
878
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
879
-            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
880
-                EE_Error::add_error(
881
-                    __('Your Registration and Transaction information could not be retrieved from the db.',
882
-                        'event_espresso'),
883
-                    __FILE__, __FUNCTION__, __LINE__
884
-                );
885
-                $this->checkout->transaction = EE_Transaction::new_instance();
886
-                // add some style and make it dance
887
-                $this->add_styles_and_scripts();
888
-                EED_Single_Page_Checkout::$_initialized = true;
889
-                return false;
890
-            }
891
-            // and the registrations for the transaction
892
-            $this->_get_registrations($this->checkout->transaction);
893
-        }
894
-        return true;
895
-    }
896
-
897
-
898
-
899
-    /**
900
-     * _get_transaction_and_cart_for_previous_visit
901
-     *
902
-     * @access private
903
-     * @return mixed EE_Transaction|NULL
904
-     */
905
-    private function _get_transaction_and_cart_for_previous_visit()
906
-    {
907
-        /** @var $TXN_model EEM_Transaction */
908
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
909
-        // because the reg_url_link is present in the request,
910
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
911
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
912
-        // verify transaction
913
-        if ($transaction instanceof EE_Transaction) {
914
-            // and get the cart that was used for that transaction
915
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
916
-            return $transaction;
917
-        }
918
-        EE_Error::add_error(
919
-            __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
920
-            __FILE__, __FUNCTION__, __LINE__
921
-        );
922
-        return null;
923
-
924
-    }
925
-
926
-
927
-
928
-    /**
929
-     * _get_cart_for_transaction
930
-     *
931
-     * @access private
932
-     * @param EE_Transaction $transaction
933
-     * @return EE_Cart
934
-     */
935
-    private function _get_cart_for_transaction($transaction)
936
-    {
937
-        return $this->checkout->get_cart_for_transaction($transaction);
938
-    }
939
-
940
-
941
-
942
-    /**
943
-     * get_cart_for_transaction
944
-     *
945
-     * @access public
946
-     * @param EE_Transaction $transaction
947
-     * @return EE_Cart
948
-     */
949
-    public function get_cart_for_transaction(EE_Transaction $transaction)
950
-    {
951
-        return $this->checkout->get_cart_for_transaction($transaction);
952
-    }
953
-
954
-
955
-
956
-    /**
957
-     * _get_transaction_and_cart_for_current_session
958
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
959
-     *
960
-     * @access private
961
-     * @return EE_Transaction
962
-     * @throws EE_Error
963
-     */
964
-    private function _get_cart_for_current_session_and_setup_new_transaction()
965
-    {
966
-        //  if there's no transaction, then this is the FIRST visit to SPCO
967
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
968
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
969
-        // and then create a new transaction
970
-        $transaction = $this->_initialize_transaction();
971
-        // verify transaction
972
-        if ($transaction instanceof EE_Transaction) {
973
-            // save it so that we have an ID for other objects to use
974
-            $transaction->save();
975
-            // and save TXN data to the cart
976
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
977
-        } else {
978
-            EE_Error::add_error(
979
-                __('A Valid Transaction could not be initialized.', 'event_espresso'),
980
-                __FILE__, __FUNCTION__, __LINE__
981
-            );
982
-        }
983
-        return $transaction;
984
-    }
985
-
986
-
987
-
988
-    /**
989
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
990
-     *
991
-     * @access private
992
-     * @return mixed EE_Transaction|NULL
993
-     */
994
-    private function _initialize_transaction()
995
-    {
996
-        try {
997
-            // ensure cart totals have been calculated
998
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
999
-            // grab the cart grand total
1000
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
1001
-            // create new TXN
1002
-            $transaction = EE_Transaction::new_instance(
1003
-                array(
1004
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1005
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1006
-                    'TXN_paid'      => 0,
1007
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
1008
-                )
1009
-            );
1010
-            // save it so that we have an ID for other objects to use
1011
-            $transaction->save();
1012
-            // set cron job for following up on TXNs after their session has expired
1013
-            EE_Cron_Tasks::schedule_expired_transaction_check(
1014
-                EE_Registry::instance()->SSN->expiration() + 1,
1015
-                $transaction->ID()
1016
-            );
1017
-            return $transaction;
1018
-        } catch (Exception $e) {
1019
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1020
-        }
1021
-        return null;
1022
-    }
1023
-
1024
-
1025
-    /**
1026
-     * _get_registrations
1027
-     *
1028
-     * @access private
1029
-     * @param EE_Transaction $transaction
1030
-     * @return void
1031
-     * @throws InvalidDataTypeException
1032
-     * @throws InvalidEntityException
1033
-     * @throws EE_Error
1034
-     */
1035
-    private function _get_registrations(EE_Transaction $transaction)
1036
-    {
1037
-        // first step: grab the registrants  { : o
1038
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true);
1039
-        // verify registrations have been set
1040
-        if (empty($registrations)) {
1041
-            // if no cached registrations, then check the db
1042
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1043
-            // still nothing ? well as long as this isn't a revisit
1044
-            if (empty($registrations) && ! $this->checkout->revisit) {
1045
-                // generate new registrations from scratch
1046
-                $registrations = $this->_initialize_registrations($transaction);
1047
-            }
1048
-        }
1049
-        // sort by their original registration order
1050
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1051
-        // then loop thru the array
1052
-        foreach ($registrations as $registration) {
1053
-            // verify each registration
1054
-            if ($registration instanceof EE_Registration) {
1055
-                // we display all attendee info for the primary registrant
1056
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
1057
-                    && $registration->is_primary_registrant()
1058
-                ) {
1059
-                    $this->checkout->primary_revisit = true;
1060
-                    break;
1061
-                }
1062
-                if ($this->checkout->revisit
1063
-                           && $this->checkout->reg_url_link !== $registration->reg_url_link()
1064
-                ) {
1065
-                    // but hide info if it doesn't belong to you
1066
-                    $transaction->clear_cache('Registration', $registration->ID());
1067
-                }
1068
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1069
-            }
1070
-        }
1071
-    }
1072
-
1073
-
1074
-    /**
1075
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1076
-     *
1077
-     * @access private
1078
-     * @param EE_Transaction $transaction
1079
-     * @return    array
1080
-     * @throws InvalidDataTypeException
1081
-     * @throws InvalidEntityException
1082
-     * @throws EE_Error
1083
-     */
1084
-    private function _initialize_registrations(EE_Transaction $transaction)
1085
-    {
1086
-        $att_nmbr = 0;
1087
-        $registrations = array();
1088
-        if ($transaction instanceof EE_Transaction) {
1089
-            /** @type EE_Registration_Processor $registration_processor */
1090
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1091
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1092
-            // now let's add the cart items to the $transaction
1093
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1094
-                //do the following for each ticket of this type they selected
1095
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1096
-                    $att_nmbr++;
1097
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1098
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1099
-                        'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1100
-                        array(
1101
-                            $transaction,
1102
-                            $line_item,
1103
-                            $att_nmbr,
1104
-                            $this->checkout->total_ticket_count,
1105
-                        )
1106
-                    );
1107
-                    // override capabilities for frontend registrations
1108
-                    if ( ! is_admin()) {
1109
-                        $CreateRegistrationCommand->setCapCheck(
1110
-                            new PublicCapabilities('', 'create_new_registration')
1111
-                        );
1112
-                    }
1113
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1114
-                    if ( ! $registration instanceof EE_Registration) {
1115
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1116
-                    }
1117
-                    $registrations[ $registration->ID() ] = $registration;
1118
-                }
1119
-            }
1120
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1121
-        }
1122
-        return $registrations;
1123
-    }
1124
-
1125
-
1126
-
1127
-    /**
1128
-     * sorts registrations by REG_count
1129
-     *
1130
-     * @access public
1131
-     * @param EE_Registration $reg_A
1132
-     * @param EE_Registration $reg_B
1133
-     * @return int
1134
-     */
1135
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1136
-    {
1137
-        // this shouldn't ever happen within the same TXN, but oh well
1138
-        if ($reg_A->count() === $reg_B->count()) {
1139
-            return 0;
1140
-        }
1141
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1142
-    }
1143
-
1144
-
1145
-
1146
-    /**
1147
-     *    _final_verifications
1148
-     * just makes sure that everything is set up correctly before proceeding
1149
-     *
1150
-     * @access    private
1151
-     * @return    bool
1152
-     * @throws EE_Error
1153
-     */
1154
-    private function _final_verifications()
1155
-    {
1156
-        // filter checkout
1157
-        $this->checkout = apply_filters(
1158
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1159
-            $this->checkout
1160
-        );
1161
-        //verify that current step is still set correctly
1162
-        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1163
-            EE_Error::add_error(
1164
-                __('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'),
1165
-                __FILE__,
1166
-                __FUNCTION__,
1167
-                __LINE__
1168
-            );
1169
-            return false;
1170
-        }
1171
-        // if returning to SPCO, then verify that primary registrant is set
1172
-        if ( ! empty($this->checkout->reg_url_link)) {
1173
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1174
-            if ( ! $valid_registrant instanceof EE_Registration) {
1175
-                EE_Error::add_error(
1176
-                    __('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'),
1177
-                    __FILE__,
1178
-                    __FUNCTION__,
1179
-                    __LINE__
1180
-                );
1181
-                return false;
1182
-            }
1183
-            $valid_registrant = null;
1184
-            foreach (
1185
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1186
-            ) {
1187
-                if (
1188
-                    $registration instanceof EE_Registration
1189
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1190
-                ) {
1191
-                    $valid_registrant = $registration;
1192
-                }
1193
-            }
1194
-            if ( ! $valid_registrant instanceof EE_Registration) {
1195
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1196
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1197
-                    // clear the session, mark the checkout as unverified, and try again
1198
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1199
-                    EED_Single_Page_Checkout::$_initialized = false;
1200
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1201
-                    $this->_initialize();
1202
-                    EE_Error::reset_notices();
1203
-                    return false;
1204
-                }
1205
-                EE_Error::add_error(
1206
-                    __(
1207
-                        '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.',
1208
-                        'event_espresso'
1209
-                    ),
1210
-                    __FILE__,
1211
-                    __FUNCTION__,
1212
-                    __LINE__
1213
-                );
1214
-                return false;
1215
-            }
1216
-        }
1217
-        // now that things have been kinda sufficiently verified,
1218
-        // let's add the checkout to the session so that it's available to other systems
1219
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1220
-        return true;
1221
-    }
1222
-
1223
-
1224
-
1225
-    /**
1226
-     *    _initialize_reg_steps
1227
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1228
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1229
-     *
1230
-     * @access    private
1231
-     * @param bool $reinitializing
1232
-     * @throws EE_Error
1233
-     */
1234
-    private function _initialize_reg_steps($reinitializing = false)
1235
-    {
1236
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1237
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1238
-        foreach ($this->checkout->reg_steps as $reg_step) {
1239
-            if ( ! $reg_step->initialize_reg_step()) {
1240
-                // if not initialized then maybe this step is being removed...
1241
-                if ( ! $reinitializing && $reg_step->is_current_step()) {
1242
-                    // if it was the current step, then we need to start over here
1243
-                    $this->_initialize_reg_steps(true);
1244
-                    return;
1245
-                }
1246
-                continue;
1247
-            }
1248
-            // add css and JS for current step
1249
-            $reg_step->enqueue_styles_and_scripts();
1250
-            // i18n
1251
-            $reg_step->translate_js_strings();
1252
-            if ($reg_step->is_current_step()) {
1253
-                // the text that appears on the reg step form submit button
1254
-                $reg_step->set_submit_button_text();
1255
-            }
1256
-        }
1257
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1258
-        do_action(
1259
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1260
-            $this->checkout->current_step
1261
-        );
1262
-    }
1263
-
1264
-
1265
-
1266
-    /**
1267
-     * _check_form_submission
1268
-     *
1269
-     * @access private
1270
-     * @return boolean
1271
-     */
1272
-    private function _check_form_submission()
1273
-    {
1274
-        //does this request require the reg form to be generated ?
1275
-        if ($this->checkout->generate_reg_form) {
1276
-            // ever heard that song by Blue Rodeo ?
1277
-            try {
1278
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1279
-                // if not displaying a form, then check for form submission
1280
-                if (
1281
-                    $this->checkout->process_form_submission
1282
-                    && $this->checkout->current_step->reg_form->was_submitted()
1283
-                ) {
1284
-                    // clear out any old data in case this step is being run again
1285
-                    $this->checkout->current_step->set_valid_data(array());
1286
-                    // capture submitted form data
1287
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1288
-                        apply_filters(
1289
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1290
-                            EE_Registry::instance()->REQ->params(),
1291
-                            $this->checkout
1292
-                        )
1293
-                    );
1294
-                    // validate submitted form data
1295
-                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1296
-                        // thou shall not pass !!!
1297
-                        $this->checkout->continue_reg = false;
1298
-                        // any form validation errors?
1299
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1300
-                            $submission_error_messages = array();
1301
-                            // bad, bad, bad registrant
1302
-                            foreach (
1303
-                                $this->checkout->current_step->reg_form->get_validation_errors_accumulated()
1304
-                                as $validation_error
1305
-                            ) {
1306
-                                if ($validation_error instanceof EE_Validation_Error) {
1307
-                                    $submission_error_messages[] = sprintf(
1308
-                                        __('%s : %s', 'event_espresso'),
1309
-                                        $validation_error->get_form_section()->html_label_text(),
1310
-                                        $validation_error->getMessage()
1311
-                                    );
1312
-                                }
1313
-                            }
1314
-                            EE_Error::add_error(
1315
-                                implode('<br />', $submission_error_messages),
1316
-                                __FILE__, __FUNCTION__, __LINE__
1317
-                            );
1318
-                        }
1319
-                        // well not really... what will happen is
1320
-                        // we'll just get redirected back to redo the current step
1321
-                        $this->go_to_next_step();
1322
-                        return false;
1323
-                    }
1324
-                }
1325
-            } catch (EE_Error $e) {
1326
-                $e->get_error();
1327
-            }
1328
-        }
1329
-        return true;
1330
-    }
1331
-
1332
-
1333
-
1334
-    /**
1335
-     * _process_action
1336
-     *
1337
-     * @access private
1338
-     * @return void
1339
-     * @throws EE_Error
1340
-     */
1341
-    private function _process_form_action()
1342
-    {
1343
-        // what cha wanna do?
1344
-        switch ($this->checkout->action) {
1345
-            // AJAX next step reg form
1346
-            case 'display_spco_reg_step' :
1347
-                $this->checkout->redirect = false;
1348
-                if (EE_Registry::instance()->REQ->ajax) {
1349
-                    $this->checkout->json_response->set_reg_step_html(
1350
-                        $this->checkout->current_step->display_reg_form()
1351
-                    );
1352
-                }
1353
-                break;
1354
-            default :
1355
-                // meh... do one of those other steps first
1356
-                if (
1357
-                    ! empty($this->checkout->action)
1358
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1359
-                ) {
1360
-                    // dynamically creates hook point like:
1361
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1362
-                    do_action(
1363
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1364
-                        $this->checkout->current_step
1365
-                    );
1366
-                    // call action on current step
1367
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1368
-                        // good registrant, you get to proceed
1369
-                        if (
1370
-                            $this->checkout->current_step->success_message() !== ''
1371
-                            && apply_filters(
1372
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1373
-                                false
1374
-                            )
1375
-                        ) {
1376
-                            EE_Error::add_success(
1377
-                                $this->checkout->current_step->success_message()
1378
-                                . '<br />' . $this->checkout->next_step->_instructions()
1379
-                            );
1380
-                        }
1381
-                        // pack it up, pack it in...
1382
-                        $this->_setup_redirect();
1383
-                    }
1384
-                    // dynamically creates hook point like:
1385
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1386
-                    do_action(
1387
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1388
-                        $this->checkout->current_step
1389
-                    );
1390
-                } else {
1391
-                    EE_Error::add_error(
1392
-                        sprintf(
1393
-                            __(
1394
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1395
-                                'event_espresso'
1396
-                            ),
1397
-                            $this->checkout->action,
1398
-                            $this->checkout->current_step->name()
1399
-                        ),
1400
-                        __FILE__,
1401
-                        __FUNCTION__,
1402
-                        __LINE__
1403
-                    );
1404
-                }
1405
-            // end default
1406
-        }
1407
-        // store our progress so far
1408
-        $this->checkout->stash_transaction_and_checkout();
1409
-        // advance to the next step! If you pass GO, collect $200
1410
-        $this->go_to_next_step();
1411
-    }
1412
-
1413
-
1414
-
1415
-    /**
1416
-     *        add_styles_and_scripts
1417
-     *
1418
-     * @access        public
1419
-     * @return        void
1420
-     */
1421
-    public function add_styles_and_scripts()
1422
-    {
1423
-        // i18n
1424
-        $this->translate_js_strings();
1425
-        if ($this->checkout->admin_request) {
1426
-            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1427
-        } else {
1428
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1429
-        }
1430
-    }
1431
-
1432
-
1433
-
1434
-    /**
1435
-     *        translate_js_strings
1436
-     *
1437
-     * @access        public
1438
-     * @return        void
1439
-     */
1440
-    public function translate_js_strings()
1441
-    {
1442
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1443
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1444
-        EE_Registry::$i18n_js_strings['server_error'] = __(
1445
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1446
-            'event_espresso'
1447
-        );
1448
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1449
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1450
-            'event_espresso'
1451
-        );
1452
-        EE_Registry::$i18n_js_strings['validation_error'] = __(
1453
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1454
-            'event_espresso'
1455
-        );
1456
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1457
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1458
-            'event_espresso'
1459
-        );
1460
-        EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1461
-            'This registration step could not be completed. Please refresh the page and try again.',
1462
-            'event_espresso'
1463
-        );
1464
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1465
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1466
-            'event_espresso'
1467
-        );
1468
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1469
-            __(
1470
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1471
-                'event_espresso'
1472
-            ),
1473
-            '<br/>',
1474
-            '<br/>'
1475
-        );
1476
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1477
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1478
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1479
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1480
-        EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1481
-        EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1482
-        EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1483
-        EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1484
-        EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1485
-        EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1486
-        EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1487
-        EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1488
-        EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1489
-        EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1490
-        EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1491
-        EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1492
-        EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1493
-        EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1494
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1495
-            __(
1496
-                '%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',
1497
-                'event_espresso'
1498
-            ),
1499
-            '<h4 class="important-notice">',
1500
-            '</h4>',
1501
-            '<br />',
1502
-            '<p>',
1503
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1504
-            '">',
1505
-            '</a>',
1506
-            '</p>'
1507
-        );
1508
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1509
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1510
-            true
1511
-        );
1512
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1513
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1514
-        );
1515
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1516
-            'M d, Y H:i:s',
1517
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1518
-        );
1519
-    }
1520
-
1521
-
1522
-
1523
-    /**
1524
-     *    enqueue_styles_and_scripts
1525
-     *
1526
-     * @access        public
1527
-     * @return        void
1528
-     * @throws EE_Error
1529
-     */
1530
-    public function enqueue_styles_and_scripts()
1531
-    {
1532
-        // load css
1533
-        wp_register_style(
1534
-            'single_page_checkout',
1535
-            SPCO_CSS_URL . 'single_page_checkout.css',
1536
-            array('espresso_default'),
1537
-            EVENT_ESPRESSO_VERSION
1538
-        );
1539
-        wp_enqueue_style('single_page_checkout');
1540
-        // load JS
1541
-        wp_register_script(
1542
-            'jquery_plugin',
1543
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1544
-            array('jquery'),
1545
-            '1.0.1',
1546
-            true
1547
-        );
1548
-        wp_register_script(
1549
-            'jquery_countdown',
1550
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1551
-            array('jquery_plugin'),
1552
-            '2.0.2',
1553
-            true
1554
-        );
1555
-        wp_register_script(
1556
-            'single_page_checkout',
1557
-            SPCO_JS_URL . 'single_page_checkout.js',
1558
-            array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1559
-            EVENT_ESPRESSO_VERSION,
1560
-            true
1561
-        );
1562
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1563
-            $this->checkout->registration_form->enqueue_js();
1564
-        }
1565
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1566
-            $this->checkout->current_step->reg_form->enqueue_js();
1567
-        }
1568
-        wp_enqueue_script('single_page_checkout');
1569
-        /**
1570
-         * global action hook for enqueueing styles and scripts with
1571
-         * spco calls.
1572
-         */
1573
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1574
-        /**
1575
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1576
-         * The hook will end up being something like:
1577
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1578
-         */
1579
-        do_action(
1580
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1581
-            $this
1582
-        );
1583
-    }
1584
-
1585
-
1586
-
1587
-    /**
1588
-     *    display the Registration Single Page Checkout Form
1589
-     *
1590
-     * @access    private
1591
-     * @return    void
1592
-     * @throws EE_Error
1593
-     */
1594
-    private function _display_spco_reg_form()
1595
-    {
1596
-        // if registering via the admin, just display the reg form for the current step
1597
-        if ($this->checkout->admin_request) {
1598
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1599
-        } else {
1600
-            // add powered by EE msg
1601
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1602
-            $empty_cart = count(
1603
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1604
-            ) < 1;
1605
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1606
-            $cookies_not_set_msg = '';
1607
-            if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) {
1608
-                $cookies_not_set_msg = apply_filters(
1609
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1610
-                    sprintf(
1611
-                        __(
1612
-                            '%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',
1613
-                            'event_espresso'
1614
-                        ),
1615
-                        '<div class="ee-attention">',
1616
-                        '</div>',
1617
-                        '<h6 class="important-notice">',
1618
-                        '</h6>',
1619
-                        '<p>',
1620
-                        '</p>',
1621
-                        '<br />',
1622
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1623
-                        '</a>'
1624
-                    )
1625
-                );
1626
-            }
1627
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1628
-                array(
1629
-                    'name'            => 'single-page-checkout',
1630
-                    'html_id'         => 'ee-single-page-checkout-dv',
1631
-                    'layout_strategy' =>
1632
-                        new EE_Template_Layout(
1633
-                            array(
1634
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1635
-                                'template_args'        => array(
1636
-                                    'empty_cart'              => $empty_cart,
1637
-                                    'revisit'                 => $this->checkout->revisit,
1638
-                                    'reg_steps'               => $this->checkout->reg_steps,
1639
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1640
-                                        ? $this->checkout->next_step->slug()
1641
-                                        : '',
1642
-                                    'cancel_page_url'         => $this->checkout->cancel_page_url,
1643
-                                    'empty_msg'               => apply_filters(
1644
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1645
-                                        sprintf(
1646
-                                            __(
1647
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1648
-                                                'event_espresso'
1649
-                                            ),
1650
-                                            '<a href="'
1651
-                                            . get_post_type_archive_link('espresso_events')
1652
-                                            . '" title="',
1653
-                                            '">',
1654
-                                            '</a>'
1655
-                                        )
1656
-                                    ),
1657
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1658
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1659
-                                    'session_expiration'      => gmdate(
1660
-                                        'M d, Y H:i:s',
1661
-                                        EE_Registry::instance()->SSN->expiration()
1662
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1663
-                                    ),
1664
-                                ),
1665
-                            )
1666
-                        ),
1667
-                )
1668
-            );
1669
-            // load template and add to output sent that gets filtered into the_content()
1670
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1671
-        }
1672
-    }
1673
-
1674
-
1675
-
1676
-    /**
1677
-     *    add_extra_finalize_registration_inputs
1678
-     *
1679
-     * @access    public
1680
-     * @param $next_step
1681
-     * @internal  param string $label
1682
-     * @return void
1683
-     */
1684
-    public function add_extra_finalize_registration_inputs($next_step)
1685
-    {
1686
-        if ($next_step === 'finalize_registration') {
1687
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1688
-        }
1689
-    }
1690
-
1691
-
1692
-
1693
-    /**
1694
-     *    display_registration_footer
1695
-     *
1696
-     * @access    public
1697
-     * @return    string
1698
-     */
1699
-    public static function display_registration_footer()
1700
-    {
1701
-        if (
1702
-        apply_filters(
1703
-            'FHEE__EE_Front__Controller__show_reg_footer',
1704
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1705
-        )
1706
-        ) {
1707
-            add_filter(
1708
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1709
-                function ($url) {
1710
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1711
-                }
1712
-            );
1713
-            echo apply_filters(
1714
-                'FHEE__EE_Front_Controller__display_registration_footer',
1715
-                \EEH_Template::powered_by_event_espresso(
1716
-                    '',
1717
-                    'espresso-registration-footer-dv',
1718
-                    array('utm_content' => 'registration_checkout')
1719
-                )
1720
-            );
1721
-        }
1722
-        return '';
1723
-    }
1724
-
1725
-
1726
-
1727
-    /**
1728
-     *    unlock_transaction
1729
-     *
1730
-     * @access    public
1731
-     * @return    void
1732
-     * @throws EE_Error
1733
-     */
1734
-    public function unlock_transaction()
1735
-    {
1736
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1737
-            $this->checkout->transaction->unlock();
1738
-        }
1739
-    }
1740
-
1741
-
1742
-
1743
-    /**
1744
-     *        _setup_redirect
1745
-     *
1746
-     * @access    private
1747
-     * @return void
1748
-     */
1749
-    private function _setup_redirect()
1750
-    {
1751
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1752
-            $this->checkout->redirect = true;
1753
-            if (empty($this->checkout->redirect_url)) {
1754
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1755
-            }
1756
-            $this->checkout->redirect_url = apply_filters(
1757
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1758
-                $this->checkout->redirect_url,
1759
-                $this->checkout
1760
-            );
1761
-        }
1762
-    }
1763
-
1764
-
1765
-
1766
-    /**
1767
-     *   handle ajax message responses and redirects
1768
-     *
1769
-     * @access public
1770
-     * @return void
1771
-     * @throws EE_Error
1772
-     */
1773
-    public function go_to_next_step()
1774
-    {
1775
-        if (EE_Registry::instance()->REQ->ajax) {
1776
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1777
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1778
-        }
1779
-        $this->unlock_transaction();
1780
-        // just return for these conditions
1781
-        if (
1782
-            $this->checkout->admin_request
1783
-            || $this->checkout->action === 'redirect_form'
1784
-            || $this->checkout->action === 'update_checkout'
1785
-        ) {
1786
-            return;
1787
-        }
1788
-        // AJAX response
1789
-        $this->_handle_json_response();
1790
-        // redirect to next step or the Thank You page
1791
-        $this->_handle_html_redirects();
1792
-        // hmmm... must be something wrong, so let's just display the form again !
1793
-        $this->_display_spco_reg_form();
1794
-    }
1795
-
1796
-
1797
-
1798
-    /**
1799
-     *   _handle_json_response
1800
-     *
1801
-     * @access protected
1802
-     * @return void
1803
-     */
1804
-    protected function _handle_json_response()
1805
-    {
1806
-        // if this is an ajax request
1807
-        if (EE_Registry::instance()->REQ->ajax) {
1808
-            // DEBUG LOG
1809
-            //$this->checkout->log(
1810
-            //	__CLASS__, __FUNCTION__, __LINE__,
1811
-            //	array(
1812
-            //		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1813
-            //		'redirect'                   => $this->checkout->redirect,
1814
-            //		'continue_reg'               => $this->checkout->continue_reg,
1815
-            //	)
1816
-            //);
1817
-            $this->checkout->json_response->set_registration_time_limit(
1818
-                $this->checkout->get_registration_time_limit()
1819
-            );
1820
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1821
-            // just send the ajax (
1822
-            $json_response = apply_filters(
1823
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1824
-                $this->checkout->json_response
1825
-            );
1826
-            echo $json_response;
1827
-            exit();
1828
-        }
1829
-    }
1830
-
1831
-
1832
-
1833
-    /**
1834
-     *   _handle_redirects
1835
-     *
1836
-     * @access protected
1837
-     * @return void
1838
-     */
1839
-    protected function _handle_html_redirects()
1840
-    {
1841
-        // going somewhere ?
1842
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1843
-            // store notices in a transient
1844
-            EE_Error::get_notices(false, true, true);
1845
-            // DEBUG LOG
1846
-            //$this->checkout->log(
1847
-            //	__CLASS__, __FUNCTION__, __LINE__,
1848
-            //	array(
1849
-            //		'headers_sent' => headers_sent(),
1850
-            //		'redirect_url'     => $this->checkout->redirect_url,
1851
-            //		'headers_list'    => headers_list(),
1852
-            //	)
1853
-            //);
1854
-            wp_safe_redirect($this->checkout->redirect_url);
1855
-            exit();
1856
-        }
1857
-    }
1858
-
1859
-
1860
-
1861
-    /**
1862
-     *   set_checkout_anchor
1863
-     *
1864
-     * @access public
1865
-     * @return void
1866
-     */
1867
-    public function set_checkout_anchor()
1868
-    {
1869
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1870
-    }
23
+	/**
24
+	 * $_initialized - has the SPCO controller already been initialized ?
25
+	 *
26
+	 * @access private
27
+	 * @var bool $_initialized
28
+	 */
29
+	private static $_initialized = false;
30
+
31
+
32
+	/**
33
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
+	 *
35
+	 * @access private
36
+	 * @var bool $_valid_checkout
37
+	 */
38
+	private static $_checkout_verified = true;
39
+
40
+	/**
41
+	 *    $_reg_steps_array - holds initial array of reg steps
42
+	 *
43
+	 * @access private
44
+	 * @var array $_reg_steps_array
45
+	 */
46
+	private static $_reg_steps_array = array();
47
+
48
+	/**
49
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
+	 *
51
+	 * @access public
52
+	 * @var EE_Checkout $checkout
53
+	 */
54
+	public $checkout;
55
+
56
+
57
+
58
+	/**
59
+	 * @return EED_Module|EED_Single_Page_Checkout
60
+	 */
61
+	public static function instance()
62
+	{
63
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
+		return parent::get_instance(__CLASS__);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * @return EE_CART
71
+	 */
72
+	public function cart()
73
+	{
74
+		return $this->checkout->cart;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * @return EE_Transaction
81
+	 */
82
+	public function transaction()
83
+	{
84
+		return $this->checkout->transaction;
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 *    set_hooks - for hooking into EE Core, other modules, etc
91
+	 *
92
+	 * @access    public
93
+	 * @return    void
94
+	 * @throws EE_Error
95
+	 */
96
+	public static function set_hooks()
97
+	{
98
+		EED_Single_Page_Checkout::set_definitions();
99
+	}
100
+
101
+
102
+
103
+	/**
104
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
+	 *
106
+	 * @access    public
107
+	 * @return    void
108
+	 * @throws EE_Error
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		EED_Single_Page_Checkout::set_definitions();
113
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
+			return;
115
+		}
116
+		// going to start an output buffer in case anything gets accidentally output
117
+		// that might disrupt our JSON response
118
+		ob_start();
119
+		EED_Single_Page_Checkout::load_request_handler();
120
+		EED_Single_Page_Checkout::load_reg_steps();
121
+		// set ajax hooks
122
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 *    process ajax request
134
+	 *
135
+	 * @param string $ajax_action
136
+	 * @throws EE_Error
137
+	 */
138
+	public static function process_ajax_request($ajax_action)
139
+	{
140
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
141
+		EED_Single_Page_Checkout::instance()->_initialize();
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 *    ajax display registration step
148
+	 *
149
+	 * @throws EE_Error
150
+	 */
151
+	public static function display_reg_step()
152
+	{
153
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 *    ajax process registration step
160
+	 *
161
+	 * @throws EE_Error
162
+	 */
163
+	public static function process_reg_step()
164
+	{
165
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 *    ajax process registration step
172
+	 *
173
+	 * @throws EE_Error
174
+	 */
175
+	public static function update_reg_step()
176
+	{
177
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 *   update_checkout
184
+	 *
185
+	 * @access public
186
+	 * @return void
187
+	 * @throws EE_Error
188
+	 */
189
+	public static function update_checkout()
190
+	{
191
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
+	}
193
+
194
+
195
+
196
+	/**
197
+	 *    load_request_handler
198
+	 *
199
+	 * @access    public
200
+	 * @return    void
201
+	 */
202
+	public static function load_request_handler()
203
+	{
204
+		// load core Request_Handler class
205
+		if (EE_Registry::instance()->REQ !== null) {
206
+			EE_Registry::instance()->load_core('Request_Handler');
207
+		}
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 *    set_definitions
214
+	 *
215
+	 * @access    public
216
+	 * @return    void
217
+	 * @throws EE_Error
218
+	 */
219
+	public static function set_definitions()
220
+	{
221
+		if(defined('SPCO_BASE_PATH')) {
222
+			return;
223
+		}
224
+		define(
225
+			'SPCO_BASE_PATH',
226
+			rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
+		);
228
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
236
+			__('%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',
237
+				'event_espresso'),
238
+			'<h4 class="important-notice">',
239
+			'</h4>',
240
+			'<br />',
241
+			'<p>',
242
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
243
+			'">',
244
+			'</a>',
245
+			'</p>'
246
+		);
247
+	}
248
+
249
+
250
+
251
+	/**
252
+	 * load_reg_steps
253
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
254
+	 *
255
+	 * @access    private
256
+	 * @throws EE_Error
257
+	 */
258
+	public static function load_reg_steps()
259
+	{
260
+		static $reg_steps_loaded = false;
261
+		if ($reg_steps_loaded) {
262
+			return;
263
+		}
264
+		// filter list of reg_steps
265
+		$reg_steps_to_load = (array)apply_filters(
266
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
267
+			EED_Single_Page_Checkout::get_reg_steps()
268
+		);
269
+		// sort by key (order)
270
+		ksort($reg_steps_to_load);
271
+		// loop through folders
272
+		foreach ($reg_steps_to_load as $order => $reg_step) {
273
+			// we need a
274
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
275
+				// copy over to the reg_steps_array
276
+				EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
277
+				// register custom key route for each reg step
278
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
279
+				EE_Config::register_route(
280
+					$reg_step['slug'],
281
+					'EED_Single_Page_Checkout',
282
+					'run',
283
+					'step'
284
+				);
285
+				// add AJAX or other hooks
286
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
287
+					// setup autoloaders if necessary
288
+					if ( ! class_exists($reg_step['class_name'])) {
289
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
290
+							$reg_step['file_path'],
291
+							true
292
+						);
293
+					}
294
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
295
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
296
+					}
297
+				}
298
+			}
299
+		}
300
+		$reg_steps_loaded = true;
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 *    get_reg_steps
307
+	 *
308
+	 * @access    public
309
+	 * @return    array
310
+	 */
311
+	public static function get_reg_steps()
312
+	{
313
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
314
+		if (empty($reg_steps)) {
315
+			$reg_steps = array(
316
+				10  => array(
317
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
318
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
319
+					'slug'       => 'attendee_information',
320
+					'has_hooks'  => false,
321
+				),
322
+				20  => array(
323
+					'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
324
+					'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
325
+					'slug'       => 'registration_confirmation',
326
+					'has_hooks'  => false,
327
+				),
328
+				30  => array(
329
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
330
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
331
+					'slug'       => 'payment_options',
332
+					'has_hooks'  => true,
333
+				),
334
+				999 => array(
335
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
336
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
337
+					'slug'       => 'finalize_registration',
338
+					'has_hooks'  => false,
339
+				),
340
+			);
341
+		}
342
+		return $reg_steps;
343
+	}
344
+
345
+
346
+
347
+	/**
348
+	 *    registration_checkout_for_admin
349
+	 *
350
+	 * @access    public
351
+	 * @return    string
352
+	 * @throws EE_Error
353
+	 */
354
+	public static function registration_checkout_for_admin()
355
+	{
356
+		EED_Single_Page_Checkout::load_request_handler();
357
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
358
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
359
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
360
+		EED_Single_Page_Checkout::instance()->_initialize();
361
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
362
+		return EE_Registry::instance()->REQ->get_output();
363
+	}
364
+
365
+
366
+
367
+	/**
368
+	 * process_registration_from_admin
369
+	 *
370
+	 * @access public
371
+	 * @return \EE_Transaction
372
+	 * @throws EE_Error
373
+	 */
374
+	public static function process_registration_from_admin()
375
+	{
376
+		EED_Single_Page_Checkout::load_request_handler();
377
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
378
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
379
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
380
+		EED_Single_Page_Checkout::instance()->_initialize();
381
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
382
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
383
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
384
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
385
+				if ($final_reg_step->process_reg_step()) {
386
+					$final_reg_step->set_completed();
387
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
388
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
389
+				}
390
+			}
391
+		}
392
+		return null;
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 *    run
399
+	 *
400
+	 * @access    public
401
+	 * @param WP_Query $WP_Query
402
+	 * @return    void
403
+	 * @throws EE_Error
404
+	 */
405
+	public function run($WP_Query)
406
+	{
407
+		if (
408
+			$WP_Query instanceof WP_Query
409
+			&& $WP_Query->is_main_query()
410
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
411
+			&& $this->_is_reg_checkout()
412
+		) {
413
+			$this->_initialize();
414
+		}
415
+	}
416
+
417
+
418
+
419
+	/**
420
+	 * determines whether current url matches reg page url
421
+	 *
422
+	 * @return bool
423
+	 */
424
+	protected function _is_reg_checkout()
425
+	{
426
+		// get current permalink for reg page without any extra query args
427
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
428
+		// get request URI for current request, but without the scheme or host
429
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
430
+		$current_request_uri = html_entity_decode($current_request_uri);
431
+		// get array of query args from the current request URI
432
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
433
+		// grab page id if it is set
434
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
435
+		// and remove the page id from the query args (we will re-add it later)
436
+		unset($query_args['page_id']);
437
+		// now strip all query args from current request URI
438
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
439
+		// and re-add the page id if it was set
440
+		if ($page_id) {
441
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
442
+		}
443
+		// remove slashes and ?
444
+		$current_request_uri = trim($current_request_uri, '?/');
445
+		// is current request URI part of the known full reg page URL ?
446
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
447
+	}
448
+
449
+
450
+
451
+	/**
452
+	 * @param WP_Query $wp_query
453
+	 * @return    void
454
+	 * @throws EE_Error
455
+	 */
456
+	public static function init($wp_query)
457
+	{
458
+		EED_Single_Page_Checkout::instance()->run($wp_query);
459
+	}
460
+
461
+
462
+
463
+	/**
464
+	 *    _initialize - initial module setup
465
+	 *
466
+	 * @access    private
467
+	 * @throws EE_Error
468
+	 * @return    void
469
+	 */
470
+	private function _initialize()
471
+	{
472
+		// ensure SPCO doesn't run twice
473
+		if (EED_Single_Page_Checkout::$_initialized) {
474
+			return;
475
+		}
476
+		try {
477
+			EED_Single_Page_Checkout::load_reg_steps();
478
+			$this->_verify_session();
479
+			// setup the EE_Checkout object
480
+			$this->checkout = $this->_initialize_checkout();
481
+			// filter checkout
482
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
483
+			// get the $_GET
484
+			$this->_get_request_vars();
485
+			if ($this->_block_bots()) {
486
+				return;
487
+			}
488
+			// filter continue_reg
489
+			$this->checkout->continue_reg = apply_filters(
490
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
491
+				true,
492
+				$this->checkout
493
+			);
494
+			// load the reg steps array
495
+			if ( ! $this->_load_and_instantiate_reg_steps()) {
496
+				EED_Single_Page_Checkout::$_initialized = true;
497
+				return;
498
+			}
499
+			// set the current step
500
+			$this->checkout->set_current_step($this->checkout->step);
501
+			// and the next step
502
+			$this->checkout->set_next_step();
503
+			// verify that everything has been setup correctly
504
+			if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
505
+				EED_Single_Page_Checkout::$_initialized = true;
506
+				return;
507
+			}
508
+			// lock the transaction
509
+			$this->checkout->transaction->lock();
510
+			// make sure all of our cached objects are added to their respective model entity mappers
511
+			$this->checkout->refresh_all_entities();
512
+			// set amount owing
513
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
514
+			// initialize each reg step, which gives them the chance to potentially alter the process
515
+			$this->_initialize_reg_steps();
516
+			// DEBUG LOG
517
+			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
518
+			// get reg form
519
+			if( ! $this->_check_form_submission()) {
520
+				EED_Single_Page_Checkout::$_initialized = true;
521
+				return;
522
+			}
523
+			// checkout the action!!!
524
+			$this->_process_form_action();
525
+			// add some style and make it dance
526
+			$this->add_styles_and_scripts();
527
+			// kk... SPCO has successfully run
528
+			EED_Single_Page_Checkout::$_initialized = true;
529
+			// set no cache headers and constants
530
+			EE_System::do_not_cache();
531
+			// add anchor
532
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
533
+			// remove transaction lock
534
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
535
+		} catch (Exception $e) {
536
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
537
+		}
538
+	}
539
+
540
+
541
+
542
+	/**
543
+	 *    _verify_session
544
+	 * checks that the session is valid and not expired
545
+	 *
546
+	 * @access    private
547
+	 * @throws EE_Error
548
+	 */
549
+	private function _verify_session()
550
+	{
551
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
552
+			throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
553
+		}
554
+		// is session still valid ?
555
+		if (
556
+			EE_Registry::instance()->SSN->expired()
557
+			&& EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
558
+		) {
559
+			$this->checkout = new EE_Checkout();
560
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
561
+			// EE_Registry::instance()->SSN->reset_cart();
562
+			// EE_Registry::instance()->SSN->reset_checkout();
563
+			// EE_Registry::instance()->SSN->reset_transaction();
564
+			EE_Error::add_attention(
565
+				EE_Registry::$i18n_js_strings['registration_expiration_notice'],
566
+				__FILE__, __FUNCTION__, __LINE__
567
+			);
568
+			// EE_Registry::instance()->SSN->reset_expired();
569
+		}
570
+	}
571
+
572
+
573
+
574
+	/**
575
+	 *    _initialize_checkout
576
+	 * loads and instantiates EE_Checkout
577
+	 *
578
+	 * @access    private
579
+	 * @throws EE_Error
580
+	 * @return EE_Checkout
581
+	 */
582
+	private function _initialize_checkout()
583
+	{
584
+		// look in session for existing checkout
585
+		/** @type EE_Checkout $checkout */
586
+		$checkout = EE_Registry::instance()->SSN->checkout();
587
+		// verify
588
+		if ( ! $checkout instanceof EE_Checkout) {
589
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
590
+			$checkout = EE_Registry::instance()->load_file(
591
+				SPCO_INC_PATH,
592
+				'EE_Checkout',
593
+				'class', array(),
594
+				false
595
+			);
596
+		} else {
597
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
598
+				$this->unlock_transaction();
599
+				wp_safe_redirect($checkout->redirect_url);
600
+				exit();
601
+			}
602
+		}
603
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
604
+		// verify again
605
+		if ( ! $checkout instanceof EE_Checkout) {
606
+			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
607
+		}
608
+		// reset anything that needs a clean slate for each request
609
+		$checkout->reset_for_current_request();
610
+		return $checkout;
611
+	}
612
+
613
+
614
+
615
+	/**
616
+	 *    _get_request_vars
617
+	 *
618
+	 * @access    private
619
+	 * @return    void
620
+	 * @throws EE_Error
621
+	 */
622
+	private function _get_request_vars()
623
+	{
624
+		// load classes
625
+		EED_Single_Page_Checkout::load_request_handler();
626
+		//make sure this request is marked as belonging to EE
627
+		EE_Registry::instance()->REQ->set_espresso_page(true);
628
+		// which step is being requested ?
629
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
630
+		// which step is being edited ?
631
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
632
+		// and what we're doing on the current step
633
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
634
+		// timestamp
635
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
636
+		// returning to edit ?
637
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
638
+		// or some other kind of revisit ?
639
+		$this->checkout->revisit = filter_var(
640
+			EE_Registry::instance()->REQ->get('revisit', false),
641
+			FILTER_VALIDATE_BOOLEAN
642
+		);
643
+		// and whether or not to generate a reg form for this request
644
+		$this->checkout->generate_reg_form = filter_var(
645
+			EE_Registry::instance()->REQ->get('generate_reg_form', true),
646
+			FILTER_VALIDATE_BOOLEAN
647
+		);
648
+		// and whether or not to process a reg form submission for this request
649
+		$this->checkout->process_form_submission = filter_var(
650
+			EE_Registry::instance()->REQ->get(
651
+				'process_form_submission',
652
+				$this->checkout->action === 'process_reg_step'
653
+			),
654
+			FILTER_VALIDATE_BOOLEAN
655
+		);
656
+		$this->checkout->process_form_submission = filter_var(
657
+			$this->checkout->action !== 'display_spco_reg_step'
658
+				? $this->checkout->process_form_submission
659
+				: false,
660
+			FILTER_VALIDATE_BOOLEAN
661
+		);
662
+		// $this->_display_request_vars();
663
+	}
664
+
665
+
666
+
667
+	/**
668
+	 *  _display_request_vars
669
+	 *
670
+	 * @access    protected
671
+	 * @return    void
672
+	 */
673
+	protected function _display_request_vars()
674
+	{
675
+		if ( ! WP_DEBUG) {
676
+			return;
677
+		}
678
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
679
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
680
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
681
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
682
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
683
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
684
+		EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
685
+		EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * _block_bots
692
+	 * checks that the incoming request has either of the following set:
693
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
694
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
695
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
696
+	 * then where you coming from man?
697
+	 *
698
+	 * @return boolean
699
+	 */
700
+	private function _block_bots()
701
+	{
702
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
703
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
704
+			return true;
705
+		}
706
+		return false;
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 *    _get_first_step
713
+	 *  gets slug for first step in $_reg_steps_array
714
+	 *
715
+	 * @access    private
716
+	 * @throws EE_Error
717
+	 * @return    string
718
+	 */
719
+	private function _get_first_step()
720
+	{
721
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
722
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
723
+	}
724
+
725
+
726
+
727
+	/**
728
+	 *    _load_and_instantiate_reg_steps
729
+	 *  instantiates each reg step based on the loaded reg_steps array
730
+	 *
731
+	 * @access    private
732
+	 * @throws EE_Error
733
+	 * @return    bool
734
+	 */
735
+	private function _load_and_instantiate_reg_steps()
736
+	{
737
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
738
+		// have reg_steps already been instantiated ?
739
+		if (
740
+			empty($this->checkout->reg_steps)
741
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
742
+		) {
743
+			// if not, then loop through raw reg steps array
744
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
745
+				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
746
+					return false;
747
+				}
748
+			}
749
+			EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
750
+			EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
751
+			// skip the registration_confirmation page ?
752
+			if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
753
+				// just remove it from the reg steps array
754
+				$this->checkout->remove_reg_step('registration_confirmation', false);
755
+			} else if (
756
+				isset($this->checkout->reg_steps['registration_confirmation'])
757
+				&& EE_Registry::instance()->CFG->registration->reg_confirmation_last
758
+			) {
759
+				// set the order to something big like 100
760
+				$this->checkout->set_reg_step_order('registration_confirmation', 100);
761
+			}
762
+			// filter the array for good luck
763
+			$this->checkout->reg_steps = apply_filters(
764
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
765
+				$this->checkout->reg_steps
766
+			);
767
+			// finally re-sort based on the reg step class order properties
768
+			$this->checkout->sort_reg_steps();
769
+		} else {
770
+			foreach ($this->checkout->reg_steps as $reg_step) {
771
+				// set all current step stati to FALSE
772
+				$reg_step->set_is_current_step(false);
773
+			}
774
+		}
775
+		if (empty($this->checkout->reg_steps)) {
776
+			EE_Error::add_error(
777
+				__('No Reg Steps were loaded..', 'event_espresso'),
778
+				__FILE__, __FUNCTION__, __LINE__
779
+			);
780
+			return false;
781
+		}
782
+		// make reg step details available to JS
783
+		$this->checkout->set_reg_step_JSON_info();
784
+		return true;
785
+	}
786
+
787
+
788
+
789
+	/**
790
+	 *     _load_and_instantiate_reg_step
791
+	 *
792
+	 * @access    private
793
+	 * @param array $reg_step
794
+	 * @param int   $order
795
+	 * @return bool
796
+	 */
797
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
798
+	{
799
+		// we need a file_path, class_name, and slug to add a reg step
800
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
801
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
802
+			if (
803
+				$this->checkout->reg_url_link
804
+				&& $this->checkout->step !== $reg_step['slug']
805
+				&& $reg_step['slug'] !== 'finalize_registration'
806
+				// normally at this point we would NOT load the reg step, but this filter can change that
807
+				&& apply_filters(
808
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
809
+					true,
810
+					$reg_step,
811
+					$this->checkout
812
+				)
813
+			) {
814
+				return true;
815
+			}
816
+			// instantiate step class using file path and class name
817
+			$reg_step_obj = EE_Registry::instance()->load_file(
818
+				$reg_step['file_path'],
819
+				$reg_step['class_name'],
820
+				'class',
821
+				$this->checkout,
822
+				false
823
+			);
824
+			// did we gets the goods ?
825
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
826
+				// set reg step order based on config
827
+				$reg_step_obj->set_order($order);
828
+				// add instantiated reg step object to the master reg steps array
829
+				$this->checkout->add_reg_step($reg_step_obj);
830
+			} else {
831
+				EE_Error::add_error(
832
+					__('The current step could not be set.', 'event_espresso'),
833
+					__FILE__, __FUNCTION__, __LINE__
834
+				);
835
+				return false;
836
+			}
837
+		} else {
838
+			if (WP_DEBUG) {
839
+				EE_Error::add_error(
840
+					sprintf(
841
+						__(
842
+							'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',
843
+							'event_espresso'
844
+						),
845
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
846
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
847
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
848
+						'<ul>',
849
+						'<li>',
850
+						'</li>',
851
+						'</ul>'
852
+					),
853
+					__FILE__, __FUNCTION__, __LINE__
854
+				);
855
+			}
856
+			return false;
857
+		}
858
+		return true;
859
+	}
860
+
861
+
862
+	/**
863
+	 * _verify_transaction_and_get_registrations
864
+	 *
865
+	 * @access private
866
+	 * @return bool
867
+	 * @throws InvalidDataTypeException
868
+	 * @throws InvalidEntityException
869
+	 * @throws EE_Error
870
+	 */
871
+	private function _verify_transaction_and_get_registrations()
872
+	{
873
+		// was there already a valid transaction in the checkout from the session ?
874
+		if ( ! $this->checkout->transaction instanceof EE_Transaction) {
875
+			// get transaction from db or session
876
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
877
+				? $this->_get_transaction_and_cart_for_previous_visit()
878
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
879
+			if ( ! $this->checkout->transaction instanceof EE_Transaction) {
880
+				EE_Error::add_error(
881
+					__('Your Registration and Transaction information could not be retrieved from the db.',
882
+						'event_espresso'),
883
+					__FILE__, __FUNCTION__, __LINE__
884
+				);
885
+				$this->checkout->transaction = EE_Transaction::new_instance();
886
+				// add some style and make it dance
887
+				$this->add_styles_and_scripts();
888
+				EED_Single_Page_Checkout::$_initialized = true;
889
+				return false;
890
+			}
891
+			// and the registrations for the transaction
892
+			$this->_get_registrations($this->checkout->transaction);
893
+		}
894
+		return true;
895
+	}
896
+
897
+
898
+
899
+	/**
900
+	 * _get_transaction_and_cart_for_previous_visit
901
+	 *
902
+	 * @access private
903
+	 * @return mixed EE_Transaction|NULL
904
+	 */
905
+	private function _get_transaction_and_cart_for_previous_visit()
906
+	{
907
+		/** @var $TXN_model EEM_Transaction */
908
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
909
+		// because the reg_url_link is present in the request,
910
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
911
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
912
+		// verify transaction
913
+		if ($transaction instanceof EE_Transaction) {
914
+			// and get the cart that was used for that transaction
915
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
916
+			return $transaction;
917
+		}
918
+		EE_Error::add_error(
919
+			__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
920
+			__FILE__, __FUNCTION__, __LINE__
921
+		);
922
+		return null;
923
+
924
+	}
925
+
926
+
927
+
928
+	/**
929
+	 * _get_cart_for_transaction
930
+	 *
931
+	 * @access private
932
+	 * @param EE_Transaction $transaction
933
+	 * @return EE_Cart
934
+	 */
935
+	private function _get_cart_for_transaction($transaction)
936
+	{
937
+		return $this->checkout->get_cart_for_transaction($transaction);
938
+	}
939
+
940
+
941
+
942
+	/**
943
+	 * get_cart_for_transaction
944
+	 *
945
+	 * @access public
946
+	 * @param EE_Transaction $transaction
947
+	 * @return EE_Cart
948
+	 */
949
+	public function get_cart_for_transaction(EE_Transaction $transaction)
950
+	{
951
+		return $this->checkout->get_cart_for_transaction($transaction);
952
+	}
953
+
954
+
955
+
956
+	/**
957
+	 * _get_transaction_and_cart_for_current_session
958
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
959
+	 *
960
+	 * @access private
961
+	 * @return EE_Transaction
962
+	 * @throws EE_Error
963
+	 */
964
+	private function _get_cart_for_current_session_and_setup_new_transaction()
965
+	{
966
+		//  if there's no transaction, then this is the FIRST visit to SPCO
967
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
968
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
969
+		// and then create a new transaction
970
+		$transaction = $this->_initialize_transaction();
971
+		// verify transaction
972
+		if ($transaction instanceof EE_Transaction) {
973
+			// save it so that we have an ID for other objects to use
974
+			$transaction->save();
975
+			// and save TXN data to the cart
976
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
977
+		} else {
978
+			EE_Error::add_error(
979
+				__('A Valid Transaction could not be initialized.', 'event_espresso'),
980
+				__FILE__, __FUNCTION__, __LINE__
981
+			);
982
+		}
983
+		return $transaction;
984
+	}
985
+
986
+
987
+
988
+	/**
989
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
990
+	 *
991
+	 * @access private
992
+	 * @return mixed EE_Transaction|NULL
993
+	 */
994
+	private function _initialize_transaction()
995
+	{
996
+		try {
997
+			// ensure cart totals have been calculated
998
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
999
+			// grab the cart grand total
1000
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
1001
+			// create new TXN
1002
+			$transaction = EE_Transaction::new_instance(
1003
+				array(
1004
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1005
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1006
+					'TXN_paid'      => 0,
1007
+					'STS_ID'        => EEM_Transaction::failed_status_code,
1008
+				)
1009
+			);
1010
+			// save it so that we have an ID for other objects to use
1011
+			$transaction->save();
1012
+			// set cron job for following up on TXNs after their session has expired
1013
+			EE_Cron_Tasks::schedule_expired_transaction_check(
1014
+				EE_Registry::instance()->SSN->expiration() + 1,
1015
+				$transaction->ID()
1016
+			);
1017
+			return $transaction;
1018
+		} catch (Exception $e) {
1019
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1020
+		}
1021
+		return null;
1022
+	}
1023
+
1024
+
1025
+	/**
1026
+	 * _get_registrations
1027
+	 *
1028
+	 * @access private
1029
+	 * @param EE_Transaction $transaction
1030
+	 * @return void
1031
+	 * @throws InvalidDataTypeException
1032
+	 * @throws InvalidEntityException
1033
+	 * @throws EE_Error
1034
+	 */
1035
+	private function _get_registrations(EE_Transaction $transaction)
1036
+	{
1037
+		// first step: grab the registrants  { : o
1038
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true);
1039
+		// verify registrations have been set
1040
+		if (empty($registrations)) {
1041
+			// if no cached registrations, then check the db
1042
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1043
+			// still nothing ? well as long as this isn't a revisit
1044
+			if (empty($registrations) && ! $this->checkout->revisit) {
1045
+				// generate new registrations from scratch
1046
+				$registrations = $this->_initialize_registrations($transaction);
1047
+			}
1048
+		}
1049
+		// sort by their original registration order
1050
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1051
+		// then loop thru the array
1052
+		foreach ($registrations as $registration) {
1053
+			// verify each registration
1054
+			if ($registration instanceof EE_Registration) {
1055
+				// we display all attendee info for the primary registrant
1056
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
1057
+					&& $registration->is_primary_registrant()
1058
+				) {
1059
+					$this->checkout->primary_revisit = true;
1060
+					break;
1061
+				}
1062
+				if ($this->checkout->revisit
1063
+						   && $this->checkout->reg_url_link !== $registration->reg_url_link()
1064
+				) {
1065
+					// but hide info if it doesn't belong to you
1066
+					$transaction->clear_cache('Registration', $registration->ID());
1067
+				}
1068
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1069
+			}
1070
+		}
1071
+	}
1072
+
1073
+
1074
+	/**
1075
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1076
+	 *
1077
+	 * @access private
1078
+	 * @param EE_Transaction $transaction
1079
+	 * @return    array
1080
+	 * @throws InvalidDataTypeException
1081
+	 * @throws InvalidEntityException
1082
+	 * @throws EE_Error
1083
+	 */
1084
+	private function _initialize_registrations(EE_Transaction $transaction)
1085
+	{
1086
+		$att_nmbr = 0;
1087
+		$registrations = array();
1088
+		if ($transaction instanceof EE_Transaction) {
1089
+			/** @type EE_Registration_Processor $registration_processor */
1090
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1091
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1092
+			// now let's add the cart items to the $transaction
1093
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1094
+				//do the following for each ticket of this type they selected
1095
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1096
+					$att_nmbr++;
1097
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1098
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1099
+						'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1100
+						array(
1101
+							$transaction,
1102
+							$line_item,
1103
+							$att_nmbr,
1104
+							$this->checkout->total_ticket_count,
1105
+						)
1106
+					);
1107
+					// override capabilities for frontend registrations
1108
+					if ( ! is_admin()) {
1109
+						$CreateRegistrationCommand->setCapCheck(
1110
+							new PublicCapabilities('', 'create_new_registration')
1111
+						);
1112
+					}
1113
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1114
+					if ( ! $registration instanceof EE_Registration) {
1115
+						throw new InvalidEntityException($registration, 'EE_Registration');
1116
+					}
1117
+					$registrations[ $registration->ID() ] = $registration;
1118
+				}
1119
+			}
1120
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1121
+		}
1122
+		return $registrations;
1123
+	}
1124
+
1125
+
1126
+
1127
+	/**
1128
+	 * sorts registrations by REG_count
1129
+	 *
1130
+	 * @access public
1131
+	 * @param EE_Registration $reg_A
1132
+	 * @param EE_Registration $reg_B
1133
+	 * @return int
1134
+	 */
1135
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1136
+	{
1137
+		// this shouldn't ever happen within the same TXN, but oh well
1138
+		if ($reg_A->count() === $reg_B->count()) {
1139
+			return 0;
1140
+		}
1141
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1142
+	}
1143
+
1144
+
1145
+
1146
+	/**
1147
+	 *    _final_verifications
1148
+	 * just makes sure that everything is set up correctly before proceeding
1149
+	 *
1150
+	 * @access    private
1151
+	 * @return    bool
1152
+	 * @throws EE_Error
1153
+	 */
1154
+	private function _final_verifications()
1155
+	{
1156
+		// filter checkout
1157
+		$this->checkout = apply_filters(
1158
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1159
+			$this->checkout
1160
+		);
1161
+		//verify that current step is still set correctly
1162
+		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1163
+			EE_Error::add_error(
1164
+				__('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'),
1165
+				__FILE__,
1166
+				__FUNCTION__,
1167
+				__LINE__
1168
+			);
1169
+			return false;
1170
+		}
1171
+		// if returning to SPCO, then verify that primary registrant is set
1172
+		if ( ! empty($this->checkout->reg_url_link)) {
1173
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1174
+			if ( ! $valid_registrant instanceof EE_Registration) {
1175
+				EE_Error::add_error(
1176
+					__('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'),
1177
+					__FILE__,
1178
+					__FUNCTION__,
1179
+					__LINE__
1180
+				);
1181
+				return false;
1182
+			}
1183
+			$valid_registrant = null;
1184
+			foreach (
1185
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1186
+			) {
1187
+				if (
1188
+					$registration instanceof EE_Registration
1189
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1190
+				) {
1191
+					$valid_registrant = $registration;
1192
+				}
1193
+			}
1194
+			if ( ! $valid_registrant instanceof EE_Registration) {
1195
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1196
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1197
+					// clear the session, mark the checkout as unverified, and try again
1198
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1199
+					EED_Single_Page_Checkout::$_initialized = false;
1200
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1201
+					$this->_initialize();
1202
+					EE_Error::reset_notices();
1203
+					return false;
1204
+				}
1205
+				EE_Error::add_error(
1206
+					__(
1207
+						'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.',
1208
+						'event_espresso'
1209
+					),
1210
+					__FILE__,
1211
+					__FUNCTION__,
1212
+					__LINE__
1213
+				);
1214
+				return false;
1215
+			}
1216
+		}
1217
+		// now that things have been kinda sufficiently verified,
1218
+		// let's add the checkout to the session so that it's available to other systems
1219
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1220
+		return true;
1221
+	}
1222
+
1223
+
1224
+
1225
+	/**
1226
+	 *    _initialize_reg_steps
1227
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1228
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1229
+	 *
1230
+	 * @access    private
1231
+	 * @param bool $reinitializing
1232
+	 * @throws EE_Error
1233
+	 */
1234
+	private function _initialize_reg_steps($reinitializing = false)
1235
+	{
1236
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1237
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1238
+		foreach ($this->checkout->reg_steps as $reg_step) {
1239
+			if ( ! $reg_step->initialize_reg_step()) {
1240
+				// if not initialized then maybe this step is being removed...
1241
+				if ( ! $reinitializing && $reg_step->is_current_step()) {
1242
+					// if it was the current step, then we need to start over here
1243
+					$this->_initialize_reg_steps(true);
1244
+					return;
1245
+				}
1246
+				continue;
1247
+			}
1248
+			// add css and JS for current step
1249
+			$reg_step->enqueue_styles_and_scripts();
1250
+			// i18n
1251
+			$reg_step->translate_js_strings();
1252
+			if ($reg_step->is_current_step()) {
1253
+				// the text that appears on the reg step form submit button
1254
+				$reg_step->set_submit_button_text();
1255
+			}
1256
+		}
1257
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1258
+		do_action(
1259
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1260
+			$this->checkout->current_step
1261
+		);
1262
+	}
1263
+
1264
+
1265
+
1266
+	/**
1267
+	 * _check_form_submission
1268
+	 *
1269
+	 * @access private
1270
+	 * @return boolean
1271
+	 */
1272
+	private function _check_form_submission()
1273
+	{
1274
+		//does this request require the reg form to be generated ?
1275
+		if ($this->checkout->generate_reg_form) {
1276
+			// ever heard that song by Blue Rodeo ?
1277
+			try {
1278
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1279
+				// if not displaying a form, then check for form submission
1280
+				if (
1281
+					$this->checkout->process_form_submission
1282
+					&& $this->checkout->current_step->reg_form->was_submitted()
1283
+				) {
1284
+					// clear out any old data in case this step is being run again
1285
+					$this->checkout->current_step->set_valid_data(array());
1286
+					// capture submitted form data
1287
+					$this->checkout->current_step->reg_form->receive_form_submission(
1288
+						apply_filters(
1289
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1290
+							EE_Registry::instance()->REQ->params(),
1291
+							$this->checkout
1292
+						)
1293
+					);
1294
+					// validate submitted form data
1295
+					if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1296
+						// thou shall not pass !!!
1297
+						$this->checkout->continue_reg = false;
1298
+						// any form validation errors?
1299
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1300
+							$submission_error_messages = array();
1301
+							// bad, bad, bad registrant
1302
+							foreach (
1303
+								$this->checkout->current_step->reg_form->get_validation_errors_accumulated()
1304
+								as $validation_error
1305
+							) {
1306
+								if ($validation_error instanceof EE_Validation_Error) {
1307
+									$submission_error_messages[] = sprintf(
1308
+										__('%s : %s', 'event_espresso'),
1309
+										$validation_error->get_form_section()->html_label_text(),
1310
+										$validation_error->getMessage()
1311
+									);
1312
+								}
1313
+							}
1314
+							EE_Error::add_error(
1315
+								implode('<br />', $submission_error_messages),
1316
+								__FILE__, __FUNCTION__, __LINE__
1317
+							);
1318
+						}
1319
+						// well not really... what will happen is
1320
+						// we'll just get redirected back to redo the current step
1321
+						$this->go_to_next_step();
1322
+						return false;
1323
+					}
1324
+				}
1325
+			} catch (EE_Error $e) {
1326
+				$e->get_error();
1327
+			}
1328
+		}
1329
+		return true;
1330
+	}
1331
+
1332
+
1333
+
1334
+	/**
1335
+	 * _process_action
1336
+	 *
1337
+	 * @access private
1338
+	 * @return void
1339
+	 * @throws EE_Error
1340
+	 */
1341
+	private function _process_form_action()
1342
+	{
1343
+		// what cha wanna do?
1344
+		switch ($this->checkout->action) {
1345
+			// AJAX next step reg form
1346
+			case 'display_spco_reg_step' :
1347
+				$this->checkout->redirect = false;
1348
+				if (EE_Registry::instance()->REQ->ajax) {
1349
+					$this->checkout->json_response->set_reg_step_html(
1350
+						$this->checkout->current_step->display_reg_form()
1351
+					);
1352
+				}
1353
+				break;
1354
+			default :
1355
+				// meh... do one of those other steps first
1356
+				if (
1357
+					! empty($this->checkout->action)
1358
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1359
+				) {
1360
+					// dynamically creates hook point like:
1361
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1362
+					do_action(
1363
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1364
+						$this->checkout->current_step
1365
+					);
1366
+					// call action on current step
1367
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1368
+						// good registrant, you get to proceed
1369
+						if (
1370
+							$this->checkout->current_step->success_message() !== ''
1371
+							&& apply_filters(
1372
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1373
+								false
1374
+							)
1375
+						) {
1376
+							EE_Error::add_success(
1377
+								$this->checkout->current_step->success_message()
1378
+								. '<br />' . $this->checkout->next_step->_instructions()
1379
+							);
1380
+						}
1381
+						// pack it up, pack it in...
1382
+						$this->_setup_redirect();
1383
+					}
1384
+					// dynamically creates hook point like:
1385
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1386
+					do_action(
1387
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1388
+						$this->checkout->current_step
1389
+					);
1390
+				} else {
1391
+					EE_Error::add_error(
1392
+						sprintf(
1393
+							__(
1394
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1395
+								'event_espresso'
1396
+							),
1397
+							$this->checkout->action,
1398
+							$this->checkout->current_step->name()
1399
+						),
1400
+						__FILE__,
1401
+						__FUNCTION__,
1402
+						__LINE__
1403
+					);
1404
+				}
1405
+			// end default
1406
+		}
1407
+		// store our progress so far
1408
+		$this->checkout->stash_transaction_and_checkout();
1409
+		// advance to the next step! If you pass GO, collect $200
1410
+		$this->go_to_next_step();
1411
+	}
1412
+
1413
+
1414
+
1415
+	/**
1416
+	 *        add_styles_and_scripts
1417
+	 *
1418
+	 * @access        public
1419
+	 * @return        void
1420
+	 */
1421
+	public function add_styles_and_scripts()
1422
+	{
1423
+		// i18n
1424
+		$this->translate_js_strings();
1425
+		if ($this->checkout->admin_request) {
1426
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1427
+		} else {
1428
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1429
+		}
1430
+	}
1431
+
1432
+
1433
+
1434
+	/**
1435
+	 *        translate_js_strings
1436
+	 *
1437
+	 * @access        public
1438
+	 * @return        void
1439
+	 */
1440
+	public function translate_js_strings()
1441
+	{
1442
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1443
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1444
+		EE_Registry::$i18n_js_strings['server_error'] = __(
1445
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1446
+			'event_espresso'
1447
+		);
1448
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1449
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1450
+			'event_espresso'
1451
+		);
1452
+		EE_Registry::$i18n_js_strings['validation_error'] = __(
1453
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1454
+			'event_espresso'
1455
+		);
1456
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1457
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1458
+			'event_espresso'
1459
+		);
1460
+		EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1461
+			'This registration step could not be completed. Please refresh the page and try again.',
1462
+			'event_espresso'
1463
+		);
1464
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1465
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1466
+			'event_espresso'
1467
+		);
1468
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1469
+			__(
1470
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1471
+				'event_espresso'
1472
+			),
1473
+			'<br/>',
1474
+			'<br/>'
1475
+		);
1476
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1477
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1478
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1479
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1480
+		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1481
+		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1482
+		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1483
+		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1484
+		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1485
+		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1486
+		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1487
+		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1488
+		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1489
+		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1490
+		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1491
+		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1492
+		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1493
+		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1494
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1495
+			__(
1496
+				'%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',
1497
+				'event_espresso'
1498
+			),
1499
+			'<h4 class="important-notice">',
1500
+			'</h4>',
1501
+			'<br />',
1502
+			'<p>',
1503
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1504
+			'">',
1505
+			'</a>',
1506
+			'</p>'
1507
+		);
1508
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1509
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1510
+			true
1511
+		);
1512
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1513
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1514
+		);
1515
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1516
+			'M d, Y H:i:s',
1517
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1518
+		);
1519
+	}
1520
+
1521
+
1522
+
1523
+	/**
1524
+	 *    enqueue_styles_and_scripts
1525
+	 *
1526
+	 * @access        public
1527
+	 * @return        void
1528
+	 * @throws EE_Error
1529
+	 */
1530
+	public function enqueue_styles_and_scripts()
1531
+	{
1532
+		// load css
1533
+		wp_register_style(
1534
+			'single_page_checkout',
1535
+			SPCO_CSS_URL . 'single_page_checkout.css',
1536
+			array('espresso_default'),
1537
+			EVENT_ESPRESSO_VERSION
1538
+		);
1539
+		wp_enqueue_style('single_page_checkout');
1540
+		// load JS
1541
+		wp_register_script(
1542
+			'jquery_plugin',
1543
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1544
+			array('jquery'),
1545
+			'1.0.1',
1546
+			true
1547
+		);
1548
+		wp_register_script(
1549
+			'jquery_countdown',
1550
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1551
+			array('jquery_plugin'),
1552
+			'2.0.2',
1553
+			true
1554
+		);
1555
+		wp_register_script(
1556
+			'single_page_checkout',
1557
+			SPCO_JS_URL . 'single_page_checkout.js',
1558
+			array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1559
+			EVENT_ESPRESSO_VERSION,
1560
+			true
1561
+		);
1562
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1563
+			$this->checkout->registration_form->enqueue_js();
1564
+		}
1565
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1566
+			$this->checkout->current_step->reg_form->enqueue_js();
1567
+		}
1568
+		wp_enqueue_script('single_page_checkout');
1569
+		/**
1570
+		 * global action hook for enqueueing styles and scripts with
1571
+		 * spco calls.
1572
+		 */
1573
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1574
+		/**
1575
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1576
+		 * The hook will end up being something like:
1577
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1578
+		 */
1579
+		do_action(
1580
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1581
+			$this
1582
+		);
1583
+	}
1584
+
1585
+
1586
+
1587
+	/**
1588
+	 *    display the Registration Single Page Checkout Form
1589
+	 *
1590
+	 * @access    private
1591
+	 * @return    void
1592
+	 * @throws EE_Error
1593
+	 */
1594
+	private function _display_spco_reg_form()
1595
+	{
1596
+		// if registering via the admin, just display the reg form for the current step
1597
+		if ($this->checkout->admin_request) {
1598
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1599
+		} else {
1600
+			// add powered by EE msg
1601
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1602
+			$empty_cart = count(
1603
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1604
+			) < 1;
1605
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1606
+			$cookies_not_set_msg = '';
1607
+			if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) {
1608
+				$cookies_not_set_msg = apply_filters(
1609
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1610
+					sprintf(
1611
+						__(
1612
+							'%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',
1613
+							'event_espresso'
1614
+						),
1615
+						'<div class="ee-attention">',
1616
+						'</div>',
1617
+						'<h6 class="important-notice">',
1618
+						'</h6>',
1619
+						'<p>',
1620
+						'</p>',
1621
+						'<br />',
1622
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1623
+						'</a>'
1624
+					)
1625
+				);
1626
+			}
1627
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1628
+				array(
1629
+					'name'            => 'single-page-checkout',
1630
+					'html_id'         => 'ee-single-page-checkout-dv',
1631
+					'layout_strategy' =>
1632
+						new EE_Template_Layout(
1633
+							array(
1634
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1635
+								'template_args'        => array(
1636
+									'empty_cart'              => $empty_cart,
1637
+									'revisit'                 => $this->checkout->revisit,
1638
+									'reg_steps'               => $this->checkout->reg_steps,
1639
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1640
+										? $this->checkout->next_step->slug()
1641
+										: '',
1642
+									'cancel_page_url'         => $this->checkout->cancel_page_url,
1643
+									'empty_msg'               => apply_filters(
1644
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1645
+										sprintf(
1646
+											__(
1647
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1648
+												'event_espresso'
1649
+											),
1650
+											'<a href="'
1651
+											. get_post_type_archive_link('espresso_events')
1652
+											. '" title="',
1653
+											'">',
1654
+											'</a>'
1655
+										)
1656
+									),
1657
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1658
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1659
+									'session_expiration'      => gmdate(
1660
+										'M d, Y H:i:s',
1661
+										EE_Registry::instance()->SSN->expiration()
1662
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1663
+									),
1664
+								),
1665
+							)
1666
+						),
1667
+				)
1668
+			);
1669
+			// load template and add to output sent that gets filtered into the_content()
1670
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1671
+		}
1672
+	}
1673
+
1674
+
1675
+
1676
+	/**
1677
+	 *    add_extra_finalize_registration_inputs
1678
+	 *
1679
+	 * @access    public
1680
+	 * @param $next_step
1681
+	 * @internal  param string $label
1682
+	 * @return void
1683
+	 */
1684
+	public function add_extra_finalize_registration_inputs($next_step)
1685
+	{
1686
+		if ($next_step === 'finalize_registration') {
1687
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1688
+		}
1689
+	}
1690
+
1691
+
1692
+
1693
+	/**
1694
+	 *    display_registration_footer
1695
+	 *
1696
+	 * @access    public
1697
+	 * @return    string
1698
+	 */
1699
+	public static function display_registration_footer()
1700
+	{
1701
+		if (
1702
+		apply_filters(
1703
+			'FHEE__EE_Front__Controller__show_reg_footer',
1704
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1705
+		)
1706
+		) {
1707
+			add_filter(
1708
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1709
+				function ($url) {
1710
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1711
+				}
1712
+			);
1713
+			echo apply_filters(
1714
+				'FHEE__EE_Front_Controller__display_registration_footer',
1715
+				\EEH_Template::powered_by_event_espresso(
1716
+					'',
1717
+					'espresso-registration-footer-dv',
1718
+					array('utm_content' => 'registration_checkout')
1719
+				)
1720
+			);
1721
+		}
1722
+		return '';
1723
+	}
1724
+
1725
+
1726
+
1727
+	/**
1728
+	 *    unlock_transaction
1729
+	 *
1730
+	 * @access    public
1731
+	 * @return    void
1732
+	 * @throws EE_Error
1733
+	 */
1734
+	public function unlock_transaction()
1735
+	{
1736
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1737
+			$this->checkout->transaction->unlock();
1738
+		}
1739
+	}
1740
+
1741
+
1742
+
1743
+	/**
1744
+	 *        _setup_redirect
1745
+	 *
1746
+	 * @access    private
1747
+	 * @return void
1748
+	 */
1749
+	private function _setup_redirect()
1750
+	{
1751
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1752
+			$this->checkout->redirect = true;
1753
+			if (empty($this->checkout->redirect_url)) {
1754
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1755
+			}
1756
+			$this->checkout->redirect_url = apply_filters(
1757
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1758
+				$this->checkout->redirect_url,
1759
+				$this->checkout
1760
+			);
1761
+		}
1762
+	}
1763
+
1764
+
1765
+
1766
+	/**
1767
+	 *   handle ajax message responses and redirects
1768
+	 *
1769
+	 * @access public
1770
+	 * @return void
1771
+	 * @throws EE_Error
1772
+	 */
1773
+	public function go_to_next_step()
1774
+	{
1775
+		if (EE_Registry::instance()->REQ->ajax) {
1776
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1777
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1778
+		}
1779
+		$this->unlock_transaction();
1780
+		// just return for these conditions
1781
+		if (
1782
+			$this->checkout->admin_request
1783
+			|| $this->checkout->action === 'redirect_form'
1784
+			|| $this->checkout->action === 'update_checkout'
1785
+		) {
1786
+			return;
1787
+		}
1788
+		// AJAX response
1789
+		$this->_handle_json_response();
1790
+		// redirect to next step or the Thank You page
1791
+		$this->_handle_html_redirects();
1792
+		// hmmm... must be something wrong, so let's just display the form again !
1793
+		$this->_display_spco_reg_form();
1794
+	}
1795
+
1796
+
1797
+
1798
+	/**
1799
+	 *   _handle_json_response
1800
+	 *
1801
+	 * @access protected
1802
+	 * @return void
1803
+	 */
1804
+	protected function _handle_json_response()
1805
+	{
1806
+		// if this is an ajax request
1807
+		if (EE_Registry::instance()->REQ->ajax) {
1808
+			// DEBUG LOG
1809
+			//$this->checkout->log(
1810
+			//	__CLASS__, __FUNCTION__, __LINE__,
1811
+			//	array(
1812
+			//		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1813
+			//		'redirect'                   => $this->checkout->redirect,
1814
+			//		'continue_reg'               => $this->checkout->continue_reg,
1815
+			//	)
1816
+			//);
1817
+			$this->checkout->json_response->set_registration_time_limit(
1818
+				$this->checkout->get_registration_time_limit()
1819
+			);
1820
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1821
+			// just send the ajax (
1822
+			$json_response = apply_filters(
1823
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1824
+				$this->checkout->json_response
1825
+			);
1826
+			echo $json_response;
1827
+			exit();
1828
+		}
1829
+	}
1830
+
1831
+
1832
+
1833
+	/**
1834
+	 *   _handle_redirects
1835
+	 *
1836
+	 * @access protected
1837
+	 * @return void
1838
+	 */
1839
+	protected function _handle_html_redirects()
1840
+	{
1841
+		// going somewhere ?
1842
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1843
+			// store notices in a transient
1844
+			EE_Error::get_notices(false, true, true);
1845
+			// DEBUG LOG
1846
+			//$this->checkout->log(
1847
+			//	__CLASS__, __FUNCTION__, __LINE__,
1848
+			//	array(
1849
+			//		'headers_sent' => headers_sent(),
1850
+			//		'redirect_url'     => $this->checkout->redirect_url,
1851
+			//		'headers_list'    => headers_list(),
1852
+			//	)
1853
+			//);
1854
+			wp_safe_redirect($this->checkout->redirect_url);
1855
+			exit();
1856
+		}
1857
+	}
1858
+
1859
+
1860
+
1861
+	/**
1862
+	 *   set_checkout_anchor
1863
+	 *
1864
+	 * @access public
1865
+	 * @return void
1866
+	 */
1867
+	public function set_checkout_anchor()
1868
+	{
1869
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1870
+	}
1871 1871
 
1872 1872
 
1873 1873
 
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -218,19 +218,19 @@  discard block
 block discarded – undo
218 218
      */
219 219
     public static function set_definitions()
220 220
     {
221
-        if(defined('SPCO_BASE_PATH')) {
221
+        if (defined('SPCO_BASE_PATH')) {
222 222
             return;
223 223
         }
224 224
         define(
225 225
             'SPCO_BASE_PATH',
226
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
226
+            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS
227 227
         );
228
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
228
+        define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS);
229
+        define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS);
230
+        define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS);
231
+        define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS);
232
+        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS);
233
+        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS);
234 234
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235 235
         EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
236 236
             __('%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',
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
             '</h4>',
240 240
             '<br />',
241 241
             '<p>',
242
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
242
+            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
243 243
             '">',
244 244
             '</a>',
245 245
             '</p>'
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
             return;
263 263
         }
264 264
         // filter list of reg_steps
265
-        $reg_steps_to_load = (array)apply_filters(
265
+        $reg_steps_to_load = (array) apply_filters(
266 266
             'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
267 267
             EED_Single_Page_Checkout::get_reg_steps()
268 268
         );
@@ -314,25 +314,25 @@  discard block
 block discarded – undo
314 314
         if (empty($reg_steps)) {
315 315
             $reg_steps = array(
316 316
                 10  => array(
317
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
317
+                    'file_path'  => SPCO_REG_STEPS_PATH.'attendee_information',
318 318
                     'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
319 319
                     'slug'       => 'attendee_information',
320 320
                     'has_hooks'  => false,
321 321
                 ),
322 322
                 20  => array(
323
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
323
+                    'file_path'  => SPCO_REG_STEPS_PATH.'registration_confirmation',
324 324
                     'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
325 325
                     'slug'       => 'registration_confirmation',
326 326
                     'has_hooks'  => false,
327 327
                 ),
328 328
                 30  => array(
329
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
329
+                    'file_path'  => SPCO_REG_STEPS_PATH.'payment_options',
330 330
                     'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
331 331
                     'slug'       => 'payment_options',
332 332
                     'has_hooks'  => true,
333 333
                 ),
334 334
                 999 => array(
335
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
335
+                    'file_path'  => SPCO_REG_STEPS_PATH.'finalize_registration',
336 336
                     'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
337 337
                     'slug'       => 'finalize_registration',
338 338
                     'has_hooks'  => false,
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
             // DEBUG LOG
517 517
             //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
518 518
             // get reg form
519
-            if( ! $this->_check_form_submission()) {
519
+            if ( ! $this->_check_form_submission()) {
520 520
                 EED_Single_Page_Checkout::$_initialized = true;
521 521
                 return;
522 522
             }
@@ -1114,7 +1114,7 @@  discard block
 block discarded – undo
1114 1114
                     if ( ! $registration instanceof EE_Registration) {
1115 1115
                         throw new InvalidEntityException($registration, 'EE_Registration');
1116 1116
                     }
1117
-                    $registrations[ $registration->ID() ] = $registration;
1117
+                    $registrations[$registration->ID()] = $registration;
1118 1118
                 }
1119 1119
             }
1120 1120
             $registration_processor->fix_reg_final_price_rounding_issue($transaction);
@@ -1375,7 +1375,7 @@  discard block
 block discarded – undo
1375 1375
                         ) {
1376 1376
                             EE_Error::add_success(
1377 1377
                                 $this->checkout->current_step->success_message()
1378
-                                . '<br />' . $this->checkout->next_step->_instructions()
1378
+                                . '<br />'.$this->checkout->next_step->_instructions()
1379 1379
                             );
1380 1380
                         }
1381 1381
                         // pack it up, pack it in...
@@ -1500,7 +1500,7 @@  discard block
 block discarded – undo
1500 1500
             '</h4>',
1501 1501
             '<br />',
1502 1502
             '<p>',
1503
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1503
+            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1504 1504
             '">',
1505 1505
             '</a>',
1506 1506
             '</p>'
@@ -1532,7 +1532,7 @@  discard block
 block discarded – undo
1532 1532
         // load css
1533 1533
         wp_register_style(
1534 1534
             'single_page_checkout',
1535
-            SPCO_CSS_URL . 'single_page_checkout.css',
1535
+            SPCO_CSS_URL.'single_page_checkout.css',
1536 1536
             array('espresso_default'),
1537 1537
             EVENT_ESPRESSO_VERSION
1538 1538
         );
@@ -1540,21 +1540,21 @@  discard block
 block discarded – undo
1540 1540
         // load JS
1541 1541
         wp_register_script(
1542 1542
             'jquery_plugin',
1543
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1543
+            EE_THIRD_PARTY_URL.'jquery	.plugin.min.js',
1544 1544
             array('jquery'),
1545 1545
             '1.0.1',
1546 1546
             true
1547 1547
         );
1548 1548
         wp_register_script(
1549 1549
             'jquery_countdown',
1550
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1550
+            EE_THIRD_PARTY_URL.'jquery	.countdown.min.js',
1551 1551
             array('jquery_plugin'),
1552 1552
             '2.0.2',
1553 1553
             true
1554 1554
         );
1555 1555
         wp_register_script(
1556 1556
             'single_page_checkout',
1557
-            SPCO_JS_URL . 'single_page_checkout.js',
1557
+            SPCO_JS_URL.'single_page_checkout.js',
1558 1558
             array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1559 1559
             EVENT_ESPRESSO_VERSION,
1560 1560
             true
@@ -1577,7 +1577,7 @@  discard block
 block discarded – undo
1577 1577
          *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1578 1578
          */
1579 1579
         do_action(
1580
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1580
+            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(),
1581 1581
             $this
1582 1582
         );
1583 1583
     }
@@ -1631,7 +1631,7 @@  discard block
 block discarded – undo
1631 1631
                     'layout_strategy' =>
1632 1632
                         new EE_Template_Layout(
1633 1633
                             array(
1634
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1634
+                                'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php',
1635 1635
                                 'template_args'        => array(
1636 1636
                                     'empty_cart'              => $empty_cart,
1637 1637
                                     'revisit'                 => $this->checkout->revisit,
@@ -1706,7 +1706,7 @@  discard block
 block discarded – undo
1706 1706
         ) {
1707 1707
             add_filter(
1708 1708
                 'FHEE__EEH_Template__powered_by_event_espresso__url',
1709
-                function ($url) {
1709
+                function($url) {
1710 1710
                     return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1711 1711
                 }
1712 1712
             );
Please login to merge, or discard this patch.
modules/thank_you_page/EED_Thank_You_Page.module.php 1 patch
Indentation   +916 added lines, -916 removed lines patch added patch discarded remove patch
@@ -14,757 +14,757 @@  discard block
 block discarded – undo
14 14
 class EED_Thank_You_Page extends EED_Module
15 15
 {
16 16
 
17
-    /**
18
-     * time in seconds to wait for the IPN to arrive before telling the registrant to bugger off ( 1200s = 20 minutes )
19
-     */
20
-    const IPN_wait_time = 1200;
21
-
22
-    /**
23
-     * The transaction specified by the reg_url_link passed from the Request, or from the Session
24
-     *
25
-     * @var EE_Transaction $_current_txn
26
-     */
27
-    private $_current_txn;
28
-
29
-    /**
30
-     * @var EE_Registration $_primary_registrant
31
-     */
32
-    private $_primary_registrant;
33
-
34
-    /**
35
-     * The reg_url_link passed from the Request, or from the Session
36
-     *
37
-     * @var string $_reg_url_link
38
-     */
39
-    private $_reg_url_link;
40
-
41
-    /**
42
-     * whether the incoming reg_url_link is for the primary registrant or not
43
-     *
44
-     * @var boolean $_is_primary
45
-     */
46
-    private $_is_primary;
47
-
48
-    /**
49
-     * The URL for revisiting the SPCO attendee information step
50
-     *
51
-     * @var string $_SPCO_attendee_information_url
52
-     */
53
-    private $_SPCO_attendee_information_url;
54
-
55
-    /**
56
-     * The URL for revisiting the SPCO payment options step
57
-     *
58
-     * @var string $_SPCO_payment_options_url
59
-     */
60
-    private $_SPCO_payment_options_url;
61
-
62
-    /**
63
-     * whether to display the Payment Options link
64
-     *
65
-     * @var boolean $_show_try_pay_again_link
66
-     */
67
-    private $_show_try_pay_again_link = false;
68
-
69
-    /**
70
-     * whether payments are allowed at this time
71
-     *
72
-     * @var boolean $_payments_closed
73
-     */
74
-    private $_payments_closed = false;
75
-
76
-    /**
77
-     * whether the selected payment method is Bank, Check , Invoice, etc
78
-     *
79
-     * @var boolean $_is_offline_payment_method
80
-     */
81
-    private $_is_offline_payment_method = true;
82
-
83
-
84
-
85
-    /**
86
-     * @return EED_Module|EED_Thank_You_Page
87
-     */
88
-    public static function instance()
89
-    {
90
-        return parent::get_instance(__CLASS__);
91
-    }
92
-
93
-
94
-    /**
95
-     * set_hooks - for hooking into EE Core, modules, etc
96
-     *
97
-     * @return void
98
-     */
99
-    public static function set_hooks()
100
-    {
101
-        add_action('wp_loaded', array('EED_Thank_You_Page', 'set_definitions'), 2);
102
-    }
103
-
104
-
105
-
106
-    /**
107
-     * set_hooks_admin - for hooking into EE Admin Core, modules, etc
108
-     *
109
-     * @return void
110
-     */
111
-    public static function set_hooks_admin()
112
-    {
113
-        // AJAX for IPN monitoring
114
-        add_filter('heartbeat_received', array('EED_Thank_You_Page', 'thank_you_page_IPN_monitor'), 10, 3);
115
-        add_filter(
116
-            'heartbeat_nopriv_received',
117
-            array('EED_Thank_You_Page', 'thank_you_page_IPN_monitor'),
118
-            10,
119
-            3
120
-        );
121
-        add_action(
122
-            'wp_ajax_espresso_resend_reg_confirmation_email',
123
-            array('EED_Thank_You_Page', 'resend_reg_confirmation_email'),
124
-            10,
125
-            2
126
-        );
127
-        add_action(
128
-            'wp_ajax_nopriv_espresso_resend_reg_confirmation_email',
129
-            array('EED_Thank_You_Page', 'resend_reg_confirmation_email'),
130
-            10,
131
-            2
132
-        );
133
-    }
134
-
135
-
136
-
137
-    /**
138
-     * set_definitions
139
-     *
140
-     * @return void
141
-     */
142
-    public static function set_definitions()
143
-    {
144
-        define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
145
-        define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS);
146
-    }
147
-
148
-
149
-
150
-    /**
151
-     * get_txn
152
-     *
153
-     * @return EE_Transaction
154
-     */
155
-    public function get_txn()
156
-    {
157
-        if ($this->_current_txn instanceof EE_Transaction) {
158
-            return $this->_current_txn;
159
-        }
160
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
161
-        if ( ! $TXN_model instanceof EEM_Transaction) {
162
-            EE_Error::add_error(
163
-                __('The transaction model could not be established.', 'event_espresso'),
164
-                __FILE__,
165
-                __FUNCTION__,
166
-                __LINE__
167
-            );
168
-            return null;
169
-        }
170
-        //get the transaction. yes, we may have just loaded it, but it may have been updated, or this may be via an ajax request
171
-        $this->_current_txn = $TXN_model->get_transaction_from_reg_url_link($this->_reg_url_link);
172
-        // verify TXN
173
-        if (WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction) {
174
-            EE_Error::add_error(
175
-                __(
176
-                    'No transaction information could be retrieved or the transaction data is not of the correct type.',
177
-                    'event_espresso'
178
-                ),
179
-                __FILE__,
180
-                __FUNCTION__,
181
-                __LINE__
182
-            );
183
-            return null;
184
-        }
185
-        return $this->_current_txn;
186
-    }
187
-
188
-
189
-
190
-    /**
191
-     * get_txn_payments
192
-     *
193
-     * @param int $since
194
-     * @return mixed array of EE_Payment || FALSE
195
-     * @throws \EE_Error
196
-     */
197
-    public function get_txn_payments($since = 0)
198
-    {
199
-        if ( ! $this->get_txn()) {
200
-            return false;
201
-        }
202
-        $args = array('order_by' => array('PAY_timestamp' => 'ASC'));
203
-        if ($since > 0) {
204
-            $args[0] = array('PAY_timestamp' => array('>', $since));
205
-        }
206
-        // get array of payments with most recent first
207
-        return $this->_current_txn->payments($args);
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     * get_reg_url_link
214
-     *
215
-     * @return void
216
-     */
217
-    private function _get_reg_url_link()
218
-    {
219
-        if ( ! empty($this->_reg_url_link)) {
220
-            return;
221
-        }
222
-        // only do thank you page stuff if we have a REG_url_link in the url
223
-        if (WP_DEBUG && ! EE_Registry::instance()->REQ->is_set('e_reg_url_link')) {
224
-            EE_Error::add_error(
225
-                __(
226
-                    'No transaction information could be retrieved because the registration URL link is missing or invalid.',
227
-                    'event_espresso'
228
-                ),
229
-                __FILE__,
230
-                __FUNCTION__,
231
-                __LINE__
232
-            );
233
-            return;
234
-        }
235
-        // check for reg_url_link
236
-        $this->_reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link');
237
-    }
238
-
239
-
240
-
241
-    /**
242
-     * set_reg_url_link
243
-     *
244
-     * @param string $reg_url_link
245
-     */
246
-    public function set_reg_url_link($reg_url_link = null)
247
-    {
248
-        $this->_reg_url_link = ! empty($reg_url_link) ? $reg_url_link : $this->_reg_url_link;
249
-    }
250
-
251
-
252
-
253
-    /**
254
-     * run - initial module setup
255
-     * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
256
-     *
257
-     * @param WP $WP
258
-     * @return void
259
-     * @throws \EE_Error
260
-     */
261
-    public function run($WP)
262
-    {
263
-
264
-    }
265
-
266
-
267
-
268
-    /**
269
-     * load_resources
270
-     *
271
-     * @return void
272
-     * @throws \EE_Error
273
-     */
274
-    public function load_resources() {
275
-        $this->_get_reg_url_link();
276
-        // resend_reg_confirmation_email ?
277
-        if (EE_Registry::instance()->REQ->is_set('resend')) {
278
-            EED_Thank_You_Page::resend_reg_confirmation_email();
279
-        }
280
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
281
-        $this->_translate_strings();
282
-        // load assets
283
-        add_action('wp_enqueue_scripts', array($this, 'load_js'), 10);
284
-    }
285
-
286
-
287
-
288
-    /**
289
-     * load_js
290
-     *
291
-     * @return void
292
-     */
293
-    protected function _translate_strings()
294
-    {
295
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->_reg_url_link;
296
-        EE_Registry::$i18n_js_strings['initial_access'] = time();
297
-        EE_Registry::$i18n_js_strings['IPN_wait_time'] = EED_Thank_You_Page::IPN_wait_time;
298
-        EE_Registry::$i18n_js_strings['TXN_complete'] = EEM_Transaction::complete_status_code;
299
-        EE_Registry::$i18n_js_strings['TXN_incomplete'] = EEM_Transaction::incomplete_status_code;
300
-        EE_Registry::$i18n_js_strings['checking_for_new_payments'] = __(
301
-            'checking for new payments...',
302
-            'event_espresso'
303
-        );
304
-        EE_Registry::$i18n_js_strings['loading_payment_info'] = __(
305
-            'loading payment information...',
306
-            'event_espresso'
307
-        );
308
-        EE_Registry::$i18n_js_strings['server_error'] = __(
309
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again.',
310
-            'event_espresso'
311
-        );
312
-        EE_Registry::$i18n_js_strings['slow_IPN'] = apply_filters(
313
-            'EED_Thank_You_Page__load_js__slow_IPN',
314
-            sprintf(
315
-                __(
316
-                    '%sThe Payment Notification appears to be taking longer than usual to arrive. Maybe check back later or just wait for your payment and registration confirmation results to be sent to you via email. We apologize for any inconvenience this may have caused.%s',
317
-                    'event_espresso'
318
-                ),
319
-                '<div id="espresso-thank-you-page-slow-IPN-dv" class="ee-attention jst-left">',
320
-                '</div>'
321
-            )
322
-        );
323
-    }
324
-
325
-
326
-
327
-    /**
328
-     * load_js
329
-     *
330
-     * @return void
331
-     */
332
-    public function load_js()
333
-    {
334
-        wp_register_script(
335
-            'thank_you_page',
336
-            THANK_YOU_ASSETS_URL . 'thank_you_page.js',
337
-            array('espresso_core', 'heartbeat'),
338
-            EVENT_ESPRESSO_VERSION,
339
-            true
340
-        );
341
-        wp_enqueue_script('thank_you_page');
342
-        wp_enqueue_style('espresso_default');
343
-    }
344
-
345
-
346
-
347
-    /**
348
-     * init
349
-     *
350
-     * @return void
351
-     * @throws \EE_Error
352
-     */
353
-    public function init()
354
-    {
355
-        $this->_get_reg_url_link();
356
-        if ( ! $this->get_txn()) {
357
-            echo EEH_HTML::div(
358
-                EEH_HTML::h4(__('We\'re sorry...', 'event_espresso'), '', '') .
359
-                sprintf(
360
-                    __(
361
-                        'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s',
362
-                        'event_espresso'
363
-                    ),
364
-                    '<br/>'
365
-                ),
366
-                '',
367
-                'ee-attention'
368
-            );
369
-            return null;
370
-        }
371
-        // if we've made it to the Thank You page, then let's toggle any "Failed" transactions to "Incomplete"
372
-        if ($this->_current_txn->status_ID() === EEM_Transaction::failed_status_code) {
373
-            $this->_current_txn->set_status(EEM_Transaction::incomplete_status_code);
374
-            $this->_current_txn->save();
375
-        }
376
-        $this->_primary_registrant = $this->_current_txn->primary_registration() instanceof EE_Registration
377
-            ? $this->_current_txn->primary_registration()
378
-            : null;
379
-        $this->_is_primary = $this->_primary_registrant->reg_url_link() === $this->_reg_url_link ? true : false;
380
-        $show_try_pay_again_link_default = apply_filters(
381
-            'AFEE__EED_Thank_You_Page__init__show_try_pay_again_link_default',
382
-            true
383
-        );
384
-        $this->_show_try_pay_again_link = $show_try_pay_again_link_default;
385
-        // txn status ?
386
-        if ($this->_current_txn->is_completed()) {
387
-            $this->_show_try_pay_again_link = $show_try_pay_again_link_default;
388
-        } else if (
389
-            $this->_current_txn->is_incomplete()
390
-            && ($this->_primary_registrant->is_approved()
391
-                || $this->_primary_registrant->is_pending_payment())
392
-        ) {
393
-            $this->_show_try_pay_again_link = true;
394
-        } else if ($this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment()) {
395
-            // its pending
396
-            $this->_show_try_pay_again_link = isset(
397
-                                                  EE_Registry::instance()->CFG->registration->show_pending_payment_options
398
-                                              )
399
-                                              && EE_Registry::instance()->CFG->registration->show_pending_payment_options
400
-                ? true
401
-                : $show_try_pay_again_link_default;
402
-        }
403
-        $this->_payments_closed = ! $this->_current_txn->payment_method() instanceof EE_Payment_Method
404
-            ? true
405
-            : false;
406
-        $this->_is_offline_payment_method = false;
407
-        if (
408
-            // if payment method is unknown
409
-            ! $this->_current_txn->payment_method() instanceof EE_Payment_Method
410
-            || (
411
-                // or is an offline payment method
412
-                $this->_current_txn->payment_method() instanceof EE_Payment_Method
413
-                && $this->_current_txn->payment_method()->is_off_line()
414
-            )
415
-        ) {
416
-            $this->_is_offline_payment_method = true;
417
-        }
418
-        // link to SPCO
419
-        $revisit_spco_url = add_query_arg(
420
-            array('ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link),
421
-            EE_Registry::instance()->CFG->core->reg_page_url()
422
-        );
423
-        // link to SPCO payment_options
424
-        $this->_SPCO_payment_options_url = $this->_primary_registrant instanceof EE_Registration
425
-            ? $this->_primary_registrant->payment_overview_url()
426
-            : add_query_arg(
427
-                array('step' => 'payment_options'),
428
-                $revisit_spco_url
429
-            );
430
-        // link to SPCO attendee_information
431
-        $this->_SPCO_attendee_information_url = $this->_primary_registrant instanceof EE_Registration
432
-            ? $this->_primary_registrant->edit_attendee_information_url()
433
-            : false;
434
-        do_action('AHEE__EED_Thank_You_Page__init_end', $this->_current_txn);
435
-        // set no cache headers and constants
436
-        EE_System::do_not_cache();
437
-    }
438
-
439
-
440
-
441
-    /**
442
-     * display_thank_you_page_results
443
-     *
444
-     * @return string
445
-     * @throws \EE_Error
446
-     */
447
-    public function thank_you_page_results()
448
-    {
449
-        $this->init();
450
-        if ( ! $this->_current_txn instanceof EE_Transaction) {
451
-            return EE_Error::get_notices();
452
-        }
453
-        // link to receipt
454
-        $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url('html');
455
-        if ( ! empty($template_args['TXN_receipt_url'])) {
456
-            $template_args['order_conf_desc'] = __(
457
-                '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.',
458
-                'event_espresso'
459
-            );
460
-        } else {
461
-            $template_args['order_conf_desc'] = __(
462
-                '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation.',
463
-                'event_espresso'
464
-            );
465
-        }
466
-        $template_args['transaction'] = $this->_current_txn;
467
-        $template_args['revisit'] = EE_Registry::instance()->REQ->get('revisit', false);
468
-        add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_registration_details'));
469
-        if ($this->_is_primary && ! $this->_current_txn->is_free()) {
470
-            add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content'));
471
-        }
472
-        return EEH_Template::locate_template(
473
-            THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php',
474
-            $template_args,
475
-            true,
476
-            true
477
-        );
478
-    }
479
-
480
-
481
-
482
-    /**
483
-     * thank_you_page_IPN_monitor
484
-     * this basically just pulls the TXN based on the reg_url_link sent from the server,
485
-     * then checks that the TXN status is not failed, and that no other errors have been generated.
486
-     * it also calculates the IPN wait time since the Thank You page was first loaded
487
-     *
488
-     * @param array $response
489
-     * @param array $data
490
-     * @return array
491
-     * @throws \EE_Error
492
-     */
493
-    public static function thank_you_page_IPN_monitor($response = array(), $data = array())
494
-    {
495
-        // does this heartbeat contain our data ?
496
-        if ( ! isset($data['espresso_thank_you_page'])) {
497
-            return $response;
498
-        }
499
-        // check for reg_url_link in the incoming heartbeat data
500
-        if ( ! isset($data['espresso_thank_you_page']['e_reg_url_link'])) {
501
-            $response['espresso_thank_you_page'] = array(
502
-                'errors' => ! empty($notices['errors'])
503
-                    ? $notices['errors']
504
-                    : __(
505
-                        'No transaction information could be retrieved because the registration URL link is missing or invalid.',
506
-                        'event_espresso'
507
-                    )
508
-            );
509
-            return $response;
510
-        }
511
-        // kk heartbeat has our data
512
-        $response['espresso_thank_you_page'] = array();
513
-        // set_definitions, instantiate the thank you page class, and get the ball rolling
514
-        EED_Thank_You_Page::set_definitions();
515
-        /** @var $espresso_thank_you_page EED_Thank_You_Page */
516
-        $espresso_thank_you_page = EED_Thank_You_Page::instance();
517
-        $espresso_thank_you_page->set_reg_url_link($data['espresso_thank_you_page']['e_reg_url_link']);
518
-        $espresso_thank_you_page->init();
519
-        //get TXN
520
-        $TXN = $espresso_thank_you_page->get_txn();
521
-        // no TXN? then get out
522
-        if ( ! $TXN instanceof EE_Transaction) {
523
-            $notices = EE_Error::get_notices();
524
-            $response['espresso_thank_you_page'] = array(
525
-                'errors' => ! empty($notices['errors'])
526
-                    ? $notices['errors']
527
-                    : sprintf(
528
-                        __(
529
-                            'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)',
530
-                            'event_espresso'
531
-                        ),
532
-                        __LINE__
533
-                    )
534
-            );
535
-            return $response;
536
-        }
537
-        // grab transient of TXN's status
538
-        $txn_status = isset($data['espresso_thank_you_page']['txn_status'])
539
-            ? $data['espresso_thank_you_page']['txn_status']
540
-            : null;
541
-        // has the TXN status changed since we last checked (or empty because this is the first time running through this code)?
542
-        if ($txn_status !== $TXN->status_ID()) {
543
-            // switch between two possible basic outcomes
544
-            switch ($TXN->status_ID()) {
545
-                // TXN has been updated in some way
546
-                case EEM_Transaction::overpaid_status_code:
547
-                case EEM_Transaction::complete_status_code:
548
-                case EEM_Transaction::incomplete_status_code:
549
-                    // send updated TXN results back to client,
550
-                    $response['espresso_thank_you_page'] = array(
551
-                        'transaction_details' => $espresso_thank_you_page->get_transaction_details(),
552
-                        'txn_status'          => $TXN->status_ID()
553
-                    );
554
-                    break;
555
-                // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back...
556
-                case EEM_Transaction::failed_status_code:
557
-                default:
558
-                    // keep on waiting...
559
-                    return $espresso_thank_you_page->_update_server_wait_time($data['espresso_thank_you_page']);
560
-            }
561
-            // or is the TXN still failed (never been updated) ???
562
-        } else if ($TXN->failed()) {
563
-            // keep on waiting...
564
-            return $espresso_thank_you_page->_update_server_wait_time($data['espresso_thank_you_page']);
565
-        }
566
-        // TXN is happening so let's get the payments now
567
-        // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked
568
-        $since = isset($data['espresso_thank_you_page']['get_payments_since'])
569
-            ? $data['espresso_thank_you_page']['get_payments_since']
570
-            : 0;
571
-        // then check for payments
572
-        $payments = $espresso_thank_you_page->get_txn_payments($since);
573
-        // has a payment been processed ?
574
-        if ( ! empty($payments) || $espresso_thank_you_page->_is_offline_payment_method) {
575
-            if ($since) {
576
-                $response['espresso_thank_you_page'] = array(
577
-                    'new_payments'        => $espresso_thank_you_page->get_new_payments($payments),
578
-                    'transaction_details' => $espresso_thank_you_page->get_transaction_details(),
579
-                    'txn_status'          => $TXN->status_ID()
580
-                );
581
-            } else {
582
-                $response['espresso_thank_you_page']['payment_details'] = $espresso_thank_you_page->get_payment_details(
583
-                    $payments
584
-                );
585
-            }
586
-            // reset time to check for payments
587
-            $response['espresso_thank_you_page']['get_payments_since'] = time();
588
-        } else {
589
-            $response['espresso_thank_you_page']['get_payments_since'] = $since;
590
-        }
591
-        return $response;
592
-    }
593
-
594
-
595
-
596
-    /**
597
-     * _update_server_wait_time
598
-     *
599
-     * @param array $thank_you_page_data thank you page portion of the incoming JSON array from the WP heartbeat data
600
-     * @return array
601
-     * @throws \EE_Error
602
-     */
603
-    private function _update_server_wait_time($thank_you_page_data = array())
604
-    {
605
-        $response['espresso_thank_you_page'] = array(
606
-            'still_waiting' => isset($thank_you_page_data['initial_access'])
607
-                ? time() - $thank_you_page_data['initial_access']
608
-                : 0,
609
-            'txn_status'    => $this->_current_txn->status_ID()
610
-        );
611
-        return $response;
612
-    }
613
-
614
-
615
-
616
-    /**
617
-     * get_registration_details
618
-     *
619
-     * @throws \EE_Error
620
-     */
621
-    public function get_registration_details()
622
-    {
623
-        //prepare variables for displaying
624
-        $template_args = array();
625
-        $template_args['transaction'] = $this->_current_txn;
626
-        $template_args['reg_url_link'] = $this->_reg_url_link;
627
-        $template_args['is_primary'] = $this->_is_primary;
628
-        $template_args['SPCO_attendee_information_url'] = $this->_SPCO_attendee_information_url;
629
-        $template_args['resend_reg_confirmation_url'] = add_query_arg(
630
-            array('token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true'),
631
-            EE_Registry::instance()->CFG->core->thank_you_page_url()
632
-        );
633
-        // verify template arguments
634
-        EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
635
-        EEH_Template_Validator::verify_isnt_null(
636
-            $template_args['SPCO_attendee_information_url'],
637
-            '$SPCO_attendee_information_url'
638
-        );
639
-        echo EEH_Template::locate_template(
640
-            THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php',
641
-            $template_args,
642
-            true,
643
-            true
644
-        );
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     * resend_reg_confirmation_email
651
-     *
652
-     * @throws \EE_Error
653
-     */
654
-    public static function resend_reg_confirmation_email()
655
-    {
656
-        EE_Registry::instance()->load_core('Request_Handler');
657
-        $reg_url_link = EE_Registry::instance()->REQ->get('token');
658
-        // was a REG_ID passed ?
659
-        if ($reg_url_link) {
660
-            $registration = EE_Registry::instance()->load_model('Registration')->get_one(
661
-                array(array('REG_url_link' => $reg_url_link))
662
-            );
663
-            if ($registration instanceof EE_Registration) {
664
-                // resend email
665
-                EED_Messages::process_resend(array('_REG_ID' => $registration->ID()));
666
-            } else {
667
-                EE_Error::add_error(
668
-                    __(
669
-                        'The Registration Confirmation email could not be sent because a valid Registration could not be retrieved from the database.',
670
-                        'event_espresso'
671
-                    ),
672
-                    __FILE__,
673
-                    __FUNCTION__,
674
-                    __LINE__
675
-                );
676
-            }
677
-        } else {
678
-            EE_Error::add_error(
679
-                __(
680
-                    'The Registration Confirmation email could not be sent because a registration token is missing or invalid.',
681
-                    'event_espresso'
682
-                ),
683
-                __FILE__,
684
-                __FUNCTION__,
685
-                __LINE__
686
-            );
687
-        }
688
-        // request sent via AJAX ?
689
-        if (EE_FRONT_AJAX) {
690
-            echo wp_json_encode(EE_Error::get_notices(false));
691
-            die();
692
-            // or was JS disabled ?
693
-        } else {
694
-            // save errors so that they get picked up on the next request
695
-            EE_Error::get_notices(true, true);
696
-            wp_safe_redirect(
697
-                add_query_arg(
698
-                    array('e_reg_url_link' => $reg_url_link),
699
-                    EE_Registry::instance()->CFG->core->thank_you_page_url()
700
-                )
701
-            );
702
-        }
703
-    }
704
-
705
-
706
-
707
-    /**
708
-     * get_ajax_content
709
-     *
710
-     * @return void
711
-     * @throws \EE_Error
712
-     */
713
-    public function get_ajax_content()
714
-    {
715
-        if ( ! $this->get_txn()) {
716
-            return;
717
-        }
718
-        // first determine which event(s) require pre-approval or not
719
-        $events = array();
720
-        $events_requiring_pre_approval = array();
721
-        foreach ($this->_current_txn->registrations() as $registration) {
722
-            if ($registration instanceof EE_Registration) {
723
-                $event = $registration->event();
724
-                if ($event instanceof EE_Event) {
725
-                    if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) {
726
-                        $events_requiring_pre_approval[$event->ID()] = $event;
727
-                    } else {
728
-                        $events[$event->ID()] = $event;
729
-                    }
730
-                }
731
-            }
732
-        }
733
-        $this->display_details_for_events_requiring_pre_approval($events_requiring_pre_approval);
734
-        $this->display_details_for_events($events);
735
-    }
736
-
737
-
738
-
739
-    /**
740
-     * display_details_for_events
741
-     *
742
-     * @param EE_Event[] $events
743
-     * @return void
744
-     */
745
-    public function display_details_for_events($events = array())
746
-    {
747
-        if ( ! empty($events)) {
748
-            ?>
17
+	/**
18
+	 * time in seconds to wait for the IPN to arrive before telling the registrant to bugger off ( 1200s = 20 minutes )
19
+	 */
20
+	const IPN_wait_time = 1200;
21
+
22
+	/**
23
+	 * The transaction specified by the reg_url_link passed from the Request, or from the Session
24
+	 *
25
+	 * @var EE_Transaction $_current_txn
26
+	 */
27
+	private $_current_txn;
28
+
29
+	/**
30
+	 * @var EE_Registration $_primary_registrant
31
+	 */
32
+	private $_primary_registrant;
33
+
34
+	/**
35
+	 * The reg_url_link passed from the Request, or from the Session
36
+	 *
37
+	 * @var string $_reg_url_link
38
+	 */
39
+	private $_reg_url_link;
40
+
41
+	/**
42
+	 * whether the incoming reg_url_link is for the primary registrant or not
43
+	 *
44
+	 * @var boolean $_is_primary
45
+	 */
46
+	private $_is_primary;
47
+
48
+	/**
49
+	 * The URL for revisiting the SPCO attendee information step
50
+	 *
51
+	 * @var string $_SPCO_attendee_information_url
52
+	 */
53
+	private $_SPCO_attendee_information_url;
54
+
55
+	/**
56
+	 * The URL for revisiting the SPCO payment options step
57
+	 *
58
+	 * @var string $_SPCO_payment_options_url
59
+	 */
60
+	private $_SPCO_payment_options_url;
61
+
62
+	/**
63
+	 * whether to display the Payment Options link
64
+	 *
65
+	 * @var boolean $_show_try_pay_again_link
66
+	 */
67
+	private $_show_try_pay_again_link = false;
68
+
69
+	/**
70
+	 * whether payments are allowed at this time
71
+	 *
72
+	 * @var boolean $_payments_closed
73
+	 */
74
+	private $_payments_closed = false;
75
+
76
+	/**
77
+	 * whether the selected payment method is Bank, Check , Invoice, etc
78
+	 *
79
+	 * @var boolean $_is_offline_payment_method
80
+	 */
81
+	private $_is_offline_payment_method = true;
82
+
83
+
84
+
85
+	/**
86
+	 * @return EED_Module|EED_Thank_You_Page
87
+	 */
88
+	public static function instance()
89
+	{
90
+		return parent::get_instance(__CLASS__);
91
+	}
92
+
93
+
94
+	/**
95
+	 * set_hooks - for hooking into EE Core, modules, etc
96
+	 *
97
+	 * @return void
98
+	 */
99
+	public static function set_hooks()
100
+	{
101
+		add_action('wp_loaded', array('EED_Thank_You_Page', 'set_definitions'), 2);
102
+	}
103
+
104
+
105
+
106
+	/**
107
+	 * set_hooks_admin - for hooking into EE Admin Core, modules, etc
108
+	 *
109
+	 * @return void
110
+	 */
111
+	public static function set_hooks_admin()
112
+	{
113
+		// AJAX for IPN monitoring
114
+		add_filter('heartbeat_received', array('EED_Thank_You_Page', 'thank_you_page_IPN_monitor'), 10, 3);
115
+		add_filter(
116
+			'heartbeat_nopriv_received',
117
+			array('EED_Thank_You_Page', 'thank_you_page_IPN_monitor'),
118
+			10,
119
+			3
120
+		);
121
+		add_action(
122
+			'wp_ajax_espresso_resend_reg_confirmation_email',
123
+			array('EED_Thank_You_Page', 'resend_reg_confirmation_email'),
124
+			10,
125
+			2
126
+		);
127
+		add_action(
128
+			'wp_ajax_nopriv_espresso_resend_reg_confirmation_email',
129
+			array('EED_Thank_You_Page', 'resend_reg_confirmation_email'),
130
+			10,
131
+			2
132
+		);
133
+	}
134
+
135
+
136
+
137
+	/**
138
+	 * set_definitions
139
+	 *
140
+	 * @return void
141
+	 */
142
+	public static function set_definitions()
143
+	{
144
+		define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
145
+		define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS);
146
+	}
147
+
148
+
149
+
150
+	/**
151
+	 * get_txn
152
+	 *
153
+	 * @return EE_Transaction
154
+	 */
155
+	public function get_txn()
156
+	{
157
+		if ($this->_current_txn instanceof EE_Transaction) {
158
+			return $this->_current_txn;
159
+		}
160
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
161
+		if ( ! $TXN_model instanceof EEM_Transaction) {
162
+			EE_Error::add_error(
163
+				__('The transaction model could not be established.', 'event_espresso'),
164
+				__FILE__,
165
+				__FUNCTION__,
166
+				__LINE__
167
+			);
168
+			return null;
169
+		}
170
+		//get the transaction. yes, we may have just loaded it, but it may have been updated, or this may be via an ajax request
171
+		$this->_current_txn = $TXN_model->get_transaction_from_reg_url_link($this->_reg_url_link);
172
+		// verify TXN
173
+		if (WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction) {
174
+			EE_Error::add_error(
175
+				__(
176
+					'No transaction information could be retrieved or the transaction data is not of the correct type.',
177
+					'event_espresso'
178
+				),
179
+				__FILE__,
180
+				__FUNCTION__,
181
+				__LINE__
182
+			);
183
+			return null;
184
+		}
185
+		return $this->_current_txn;
186
+	}
187
+
188
+
189
+
190
+	/**
191
+	 * get_txn_payments
192
+	 *
193
+	 * @param int $since
194
+	 * @return mixed array of EE_Payment || FALSE
195
+	 * @throws \EE_Error
196
+	 */
197
+	public function get_txn_payments($since = 0)
198
+	{
199
+		if ( ! $this->get_txn()) {
200
+			return false;
201
+		}
202
+		$args = array('order_by' => array('PAY_timestamp' => 'ASC'));
203
+		if ($since > 0) {
204
+			$args[0] = array('PAY_timestamp' => array('>', $since));
205
+		}
206
+		// get array of payments with most recent first
207
+		return $this->_current_txn->payments($args);
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 * get_reg_url_link
214
+	 *
215
+	 * @return void
216
+	 */
217
+	private function _get_reg_url_link()
218
+	{
219
+		if ( ! empty($this->_reg_url_link)) {
220
+			return;
221
+		}
222
+		// only do thank you page stuff if we have a REG_url_link in the url
223
+		if (WP_DEBUG && ! EE_Registry::instance()->REQ->is_set('e_reg_url_link')) {
224
+			EE_Error::add_error(
225
+				__(
226
+					'No transaction information could be retrieved because the registration URL link is missing or invalid.',
227
+					'event_espresso'
228
+				),
229
+				__FILE__,
230
+				__FUNCTION__,
231
+				__LINE__
232
+			);
233
+			return;
234
+		}
235
+		// check for reg_url_link
236
+		$this->_reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link');
237
+	}
238
+
239
+
240
+
241
+	/**
242
+	 * set_reg_url_link
243
+	 *
244
+	 * @param string $reg_url_link
245
+	 */
246
+	public function set_reg_url_link($reg_url_link = null)
247
+	{
248
+		$this->_reg_url_link = ! empty($reg_url_link) ? $reg_url_link : $this->_reg_url_link;
249
+	}
250
+
251
+
252
+
253
+	/**
254
+	 * run - initial module setup
255
+	 * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
256
+	 *
257
+	 * @param WP $WP
258
+	 * @return void
259
+	 * @throws \EE_Error
260
+	 */
261
+	public function run($WP)
262
+	{
263
+
264
+	}
265
+
266
+
267
+
268
+	/**
269
+	 * load_resources
270
+	 *
271
+	 * @return void
272
+	 * @throws \EE_Error
273
+	 */
274
+	public function load_resources() {
275
+		$this->_get_reg_url_link();
276
+		// resend_reg_confirmation_email ?
277
+		if (EE_Registry::instance()->REQ->is_set('resend')) {
278
+			EED_Thank_You_Page::resend_reg_confirmation_email();
279
+		}
280
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
281
+		$this->_translate_strings();
282
+		// load assets
283
+		add_action('wp_enqueue_scripts', array($this, 'load_js'), 10);
284
+	}
285
+
286
+
287
+
288
+	/**
289
+	 * load_js
290
+	 *
291
+	 * @return void
292
+	 */
293
+	protected function _translate_strings()
294
+	{
295
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->_reg_url_link;
296
+		EE_Registry::$i18n_js_strings['initial_access'] = time();
297
+		EE_Registry::$i18n_js_strings['IPN_wait_time'] = EED_Thank_You_Page::IPN_wait_time;
298
+		EE_Registry::$i18n_js_strings['TXN_complete'] = EEM_Transaction::complete_status_code;
299
+		EE_Registry::$i18n_js_strings['TXN_incomplete'] = EEM_Transaction::incomplete_status_code;
300
+		EE_Registry::$i18n_js_strings['checking_for_new_payments'] = __(
301
+			'checking for new payments...',
302
+			'event_espresso'
303
+		);
304
+		EE_Registry::$i18n_js_strings['loading_payment_info'] = __(
305
+			'loading payment information...',
306
+			'event_espresso'
307
+		);
308
+		EE_Registry::$i18n_js_strings['server_error'] = __(
309
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again.',
310
+			'event_espresso'
311
+		);
312
+		EE_Registry::$i18n_js_strings['slow_IPN'] = apply_filters(
313
+			'EED_Thank_You_Page__load_js__slow_IPN',
314
+			sprintf(
315
+				__(
316
+					'%sThe Payment Notification appears to be taking longer than usual to arrive. Maybe check back later or just wait for your payment and registration confirmation results to be sent to you via email. We apologize for any inconvenience this may have caused.%s',
317
+					'event_espresso'
318
+				),
319
+				'<div id="espresso-thank-you-page-slow-IPN-dv" class="ee-attention jst-left">',
320
+				'</div>'
321
+			)
322
+		);
323
+	}
324
+
325
+
326
+
327
+	/**
328
+	 * load_js
329
+	 *
330
+	 * @return void
331
+	 */
332
+	public function load_js()
333
+	{
334
+		wp_register_script(
335
+			'thank_you_page',
336
+			THANK_YOU_ASSETS_URL . 'thank_you_page.js',
337
+			array('espresso_core', 'heartbeat'),
338
+			EVENT_ESPRESSO_VERSION,
339
+			true
340
+		);
341
+		wp_enqueue_script('thank_you_page');
342
+		wp_enqueue_style('espresso_default');
343
+	}
344
+
345
+
346
+
347
+	/**
348
+	 * init
349
+	 *
350
+	 * @return void
351
+	 * @throws \EE_Error
352
+	 */
353
+	public function init()
354
+	{
355
+		$this->_get_reg_url_link();
356
+		if ( ! $this->get_txn()) {
357
+			echo EEH_HTML::div(
358
+				EEH_HTML::h4(__('We\'re sorry...', 'event_espresso'), '', '') .
359
+				sprintf(
360
+					__(
361
+						'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s',
362
+						'event_espresso'
363
+					),
364
+					'<br/>'
365
+				),
366
+				'',
367
+				'ee-attention'
368
+			);
369
+			return null;
370
+		}
371
+		// if we've made it to the Thank You page, then let's toggle any "Failed" transactions to "Incomplete"
372
+		if ($this->_current_txn->status_ID() === EEM_Transaction::failed_status_code) {
373
+			$this->_current_txn->set_status(EEM_Transaction::incomplete_status_code);
374
+			$this->_current_txn->save();
375
+		}
376
+		$this->_primary_registrant = $this->_current_txn->primary_registration() instanceof EE_Registration
377
+			? $this->_current_txn->primary_registration()
378
+			: null;
379
+		$this->_is_primary = $this->_primary_registrant->reg_url_link() === $this->_reg_url_link ? true : false;
380
+		$show_try_pay_again_link_default = apply_filters(
381
+			'AFEE__EED_Thank_You_Page__init__show_try_pay_again_link_default',
382
+			true
383
+		);
384
+		$this->_show_try_pay_again_link = $show_try_pay_again_link_default;
385
+		// txn status ?
386
+		if ($this->_current_txn->is_completed()) {
387
+			$this->_show_try_pay_again_link = $show_try_pay_again_link_default;
388
+		} else if (
389
+			$this->_current_txn->is_incomplete()
390
+			&& ($this->_primary_registrant->is_approved()
391
+				|| $this->_primary_registrant->is_pending_payment())
392
+		) {
393
+			$this->_show_try_pay_again_link = true;
394
+		} else if ($this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment()) {
395
+			// its pending
396
+			$this->_show_try_pay_again_link = isset(
397
+												  EE_Registry::instance()->CFG->registration->show_pending_payment_options
398
+											  )
399
+											  && EE_Registry::instance()->CFG->registration->show_pending_payment_options
400
+				? true
401
+				: $show_try_pay_again_link_default;
402
+		}
403
+		$this->_payments_closed = ! $this->_current_txn->payment_method() instanceof EE_Payment_Method
404
+			? true
405
+			: false;
406
+		$this->_is_offline_payment_method = false;
407
+		if (
408
+			// if payment method is unknown
409
+			! $this->_current_txn->payment_method() instanceof EE_Payment_Method
410
+			|| (
411
+				// or is an offline payment method
412
+				$this->_current_txn->payment_method() instanceof EE_Payment_Method
413
+				&& $this->_current_txn->payment_method()->is_off_line()
414
+			)
415
+		) {
416
+			$this->_is_offline_payment_method = true;
417
+		}
418
+		// link to SPCO
419
+		$revisit_spco_url = add_query_arg(
420
+			array('ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link),
421
+			EE_Registry::instance()->CFG->core->reg_page_url()
422
+		);
423
+		// link to SPCO payment_options
424
+		$this->_SPCO_payment_options_url = $this->_primary_registrant instanceof EE_Registration
425
+			? $this->_primary_registrant->payment_overview_url()
426
+			: add_query_arg(
427
+				array('step' => 'payment_options'),
428
+				$revisit_spco_url
429
+			);
430
+		// link to SPCO attendee_information
431
+		$this->_SPCO_attendee_information_url = $this->_primary_registrant instanceof EE_Registration
432
+			? $this->_primary_registrant->edit_attendee_information_url()
433
+			: false;
434
+		do_action('AHEE__EED_Thank_You_Page__init_end', $this->_current_txn);
435
+		// set no cache headers and constants
436
+		EE_System::do_not_cache();
437
+	}
438
+
439
+
440
+
441
+	/**
442
+	 * display_thank_you_page_results
443
+	 *
444
+	 * @return string
445
+	 * @throws \EE_Error
446
+	 */
447
+	public function thank_you_page_results()
448
+	{
449
+		$this->init();
450
+		if ( ! $this->_current_txn instanceof EE_Transaction) {
451
+			return EE_Error::get_notices();
452
+		}
453
+		// link to receipt
454
+		$template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url('html');
455
+		if ( ! empty($template_args['TXN_receipt_url'])) {
456
+			$template_args['order_conf_desc'] = __(
457
+				'%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.',
458
+				'event_espresso'
459
+			);
460
+		} else {
461
+			$template_args['order_conf_desc'] = __(
462
+				'%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation.',
463
+				'event_espresso'
464
+			);
465
+		}
466
+		$template_args['transaction'] = $this->_current_txn;
467
+		$template_args['revisit'] = EE_Registry::instance()->REQ->get('revisit', false);
468
+		add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_registration_details'));
469
+		if ($this->_is_primary && ! $this->_current_txn->is_free()) {
470
+			add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content'));
471
+		}
472
+		return EEH_Template::locate_template(
473
+			THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php',
474
+			$template_args,
475
+			true,
476
+			true
477
+		);
478
+	}
479
+
480
+
481
+
482
+	/**
483
+	 * thank_you_page_IPN_monitor
484
+	 * this basically just pulls the TXN based on the reg_url_link sent from the server,
485
+	 * then checks that the TXN status is not failed, and that no other errors have been generated.
486
+	 * it also calculates the IPN wait time since the Thank You page was first loaded
487
+	 *
488
+	 * @param array $response
489
+	 * @param array $data
490
+	 * @return array
491
+	 * @throws \EE_Error
492
+	 */
493
+	public static function thank_you_page_IPN_monitor($response = array(), $data = array())
494
+	{
495
+		// does this heartbeat contain our data ?
496
+		if ( ! isset($data['espresso_thank_you_page'])) {
497
+			return $response;
498
+		}
499
+		// check for reg_url_link in the incoming heartbeat data
500
+		if ( ! isset($data['espresso_thank_you_page']['e_reg_url_link'])) {
501
+			$response['espresso_thank_you_page'] = array(
502
+				'errors' => ! empty($notices['errors'])
503
+					? $notices['errors']
504
+					: __(
505
+						'No transaction information could be retrieved because the registration URL link is missing or invalid.',
506
+						'event_espresso'
507
+					)
508
+			);
509
+			return $response;
510
+		}
511
+		// kk heartbeat has our data
512
+		$response['espresso_thank_you_page'] = array();
513
+		// set_definitions, instantiate the thank you page class, and get the ball rolling
514
+		EED_Thank_You_Page::set_definitions();
515
+		/** @var $espresso_thank_you_page EED_Thank_You_Page */
516
+		$espresso_thank_you_page = EED_Thank_You_Page::instance();
517
+		$espresso_thank_you_page->set_reg_url_link($data['espresso_thank_you_page']['e_reg_url_link']);
518
+		$espresso_thank_you_page->init();
519
+		//get TXN
520
+		$TXN = $espresso_thank_you_page->get_txn();
521
+		// no TXN? then get out
522
+		if ( ! $TXN instanceof EE_Transaction) {
523
+			$notices = EE_Error::get_notices();
524
+			$response['espresso_thank_you_page'] = array(
525
+				'errors' => ! empty($notices['errors'])
526
+					? $notices['errors']
527
+					: sprintf(
528
+						__(
529
+							'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)',
530
+							'event_espresso'
531
+						),
532
+						__LINE__
533
+					)
534
+			);
535
+			return $response;
536
+		}
537
+		// grab transient of TXN's status
538
+		$txn_status = isset($data['espresso_thank_you_page']['txn_status'])
539
+			? $data['espresso_thank_you_page']['txn_status']
540
+			: null;
541
+		// has the TXN status changed since we last checked (or empty because this is the first time running through this code)?
542
+		if ($txn_status !== $TXN->status_ID()) {
543
+			// switch between two possible basic outcomes
544
+			switch ($TXN->status_ID()) {
545
+				// TXN has been updated in some way
546
+				case EEM_Transaction::overpaid_status_code:
547
+				case EEM_Transaction::complete_status_code:
548
+				case EEM_Transaction::incomplete_status_code:
549
+					// send updated TXN results back to client,
550
+					$response['espresso_thank_you_page'] = array(
551
+						'transaction_details' => $espresso_thank_you_page->get_transaction_details(),
552
+						'txn_status'          => $TXN->status_ID()
553
+					);
554
+					break;
555
+				// or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back...
556
+				case EEM_Transaction::failed_status_code:
557
+				default:
558
+					// keep on waiting...
559
+					return $espresso_thank_you_page->_update_server_wait_time($data['espresso_thank_you_page']);
560
+			}
561
+			// or is the TXN still failed (never been updated) ???
562
+		} else if ($TXN->failed()) {
563
+			// keep on waiting...
564
+			return $espresso_thank_you_page->_update_server_wait_time($data['espresso_thank_you_page']);
565
+		}
566
+		// TXN is happening so let's get the payments now
567
+		// if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked
568
+		$since = isset($data['espresso_thank_you_page']['get_payments_since'])
569
+			? $data['espresso_thank_you_page']['get_payments_since']
570
+			: 0;
571
+		// then check for payments
572
+		$payments = $espresso_thank_you_page->get_txn_payments($since);
573
+		// has a payment been processed ?
574
+		if ( ! empty($payments) || $espresso_thank_you_page->_is_offline_payment_method) {
575
+			if ($since) {
576
+				$response['espresso_thank_you_page'] = array(
577
+					'new_payments'        => $espresso_thank_you_page->get_new_payments($payments),
578
+					'transaction_details' => $espresso_thank_you_page->get_transaction_details(),
579
+					'txn_status'          => $TXN->status_ID()
580
+				);
581
+			} else {
582
+				$response['espresso_thank_you_page']['payment_details'] = $espresso_thank_you_page->get_payment_details(
583
+					$payments
584
+				);
585
+			}
586
+			// reset time to check for payments
587
+			$response['espresso_thank_you_page']['get_payments_since'] = time();
588
+		} else {
589
+			$response['espresso_thank_you_page']['get_payments_since'] = $since;
590
+		}
591
+		return $response;
592
+	}
593
+
594
+
595
+
596
+	/**
597
+	 * _update_server_wait_time
598
+	 *
599
+	 * @param array $thank_you_page_data thank you page portion of the incoming JSON array from the WP heartbeat data
600
+	 * @return array
601
+	 * @throws \EE_Error
602
+	 */
603
+	private function _update_server_wait_time($thank_you_page_data = array())
604
+	{
605
+		$response['espresso_thank_you_page'] = array(
606
+			'still_waiting' => isset($thank_you_page_data['initial_access'])
607
+				? time() - $thank_you_page_data['initial_access']
608
+				: 0,
609
+			'txn_status'    => $this->_current_txn->status_ID()
610
+		);
611
+		return $response;
612
+	}
613
+
614
+
615
+
616
+	/**
617
+	 * get_registration_details
618
+	 *
619
+	 * @throws \EE_Error
620
+	 */
621
+	public function get_registration_details()
622
+	{
623
+		//prepare variables for displaying
624
+		$template_args = array();
625
+		$template_args['transaction'] = $this->_current_txn;
626
+		$template_args['reg_url_link'] = $this->_reg_url_link;
627
+		$template_args['is_primary'] = $this->_is_primary;
628
+		$template_args['SPCO_attendee_information_url'] = $this->_SPCO_attendee_information_url;
629
+		$template_args['resend_reg_confirmation_url'] = add_query_arg(
630
+			array('token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true'),
631
+			EE_Registry::instance()->CFG->core->thank_you_page_url()
632
+		);
633
+		// verify template arguments
634
+		EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
635
+		EEH_Template_Validator::verify_isnt_null(
636
+			$template_args['SPCO_attendee_information_url'],
637
+			'$SPCO_attendee_information_url'
638
+		);
639
+		echo EEH_Template::locate_template(
640
+			THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php',
641
+			$template_args,
642
+			true,
643
+			true
644
+		);
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 * resend_reg_confirmation_email
651
+	 *
652
+	 * @throws \EE_Error
653
+	 */
654
+	public static function resend_reg_confirmation_email()
655
+	{
656
+		EE_Registry::instance()->load_core('Request_Handler');
657
+		$reg_url_link = EE_Registry::instance()->REQ->get('token');
658
+		// was a REG_ID passed ?
659
+		if ($reg_url_link) {
660
+			$registration = EE_Registry::instance()->load_model('Registration')->get_one(
661
+				array(array('REG_url_link' => $reg_url_link))
662
+			);
663
+			if ($registration instanceof EE_Registration) {
664
+				// resend email
665
+				EED_Messages::process_resend(array('_REG_ID' => $registration->ID()));
666
+			} else {
667
+				EE_Error::add_error(
668
+					__(
669
+						'The Registration Confirmation email could not be sent because a valid Registration could not be retrieved from the database.',
670
+						'event_espresso'
671
+					),
672
+					__FILE__,
673
+					__FUNCTION__,
674
+					__LINE__
675
+				);
676
+			}
677
+		} else {
678
+			EE_Error::add_error(
679
+				__(
680
+					'The Registration Confirmation email could not be sent because a registration token is missing or invalid.',
681
+					'event_espresso'
682
+				),
683
+				__FILE__,
684
+				__FUNCTION__,
685
+				__LINE__
686
+			);
687
+		}
688
+		// request sent via AJAX ?
689
+		if (EE_FRONT_AJAX) {
690
+			echo wp_json_encode(EE_Error::get_notices(false));
691
+			die();
692
+			// or was JS disabled ?
693
+		} else {
694
+			// save errors so that they get picked up on the next request
695
+			EE_Error::get_notices(true, true);
696
+			wp_safe_redirect(
697
+				add_query_arg(
698
+					array('e_reg_url_link' => $reg_url_link),
699
+					EE_Registry::instance()->CFG->core->thank_you_page_url()
700
+				)
701
+			);
702
+		}
703
+	}
704
+
705
+
706
+
707
+	/**
708
+	 * get_ajax_content
709
+	 *
710
+	 * @return void
711
+	 * @throws \EE_Error
712
+	 */
713
+	public function get_ajax_content()
714
+	{
715
+		if ( ! $this->get_txn()) {
716
+			return;
717
+		}
718
+		// first determine which event(s) require pre-approval or not
719
+		$events = array();
720
+		$events_requiring_pre_approval = array();
721
+		foreach ($this->_current_txn->registrations() as $registration) {
722
+			if ($registration instanceof EE_Registration) {
723
+				$event = $registration->event();
724
+				if ($event instanceof EE_Event) {
725
+					if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) {
726
+						$events_requiring_pre_approval[$event->ID()] = $event;
727
+					} else {
728
+						$events[$event->ID()] = $event;
729
+					}
730
+				}
731
+			}
732
+		}
733
+		$this->display_details_for_events_requiring_pre_approval($events_requiring_pre_approval);
734
+		$this->display_details_for_events($events);
735
+	}
736
+
737
+
738
+
739
+	/**
740
+	 * display_details_for_events
741
+	 *
742
+	 * @param EE_Event[] $events
743
+	 * @return void
744
+	 */
745
+	public function display_details_for_events($events = array())
746
+	{
747
+		if ( ! empty($events)) {
748
+			?>
749 749
             <div id="espresso-thank-you-page-ajax-content-dv">
750 750
                 <div id="espresso-thank-you-page-ajax-transaction-dv"></div>
751 751
                 <div id="espresso-thank-you-page-ajax-payment-dv"></div>
752 752
                 <div id="espresso-thank-you-page-ajax-loading-dv">
753 753
                     <div id="ee-ajax-loading-dv" class="float-left lt-blue-text">
754 754
                         <span class="dashicons dashicons-upload"></span><span id="ee-ajax-loading-msg-spn"><?php _e(
755
-                                'loading transaction and payment information...',
756
-                                'event_espresso'
757
-                            ); ?></span>
755
+								'loading transaction and payment information...',
756
+								'event_espresso'
757
+							); ?></span>
758 758
                     </div>
759 759
                     <?php if ( ! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?>
760 760
                         <p id="ee-ajax-loading-pg" class="highlight-bg small-text clear">
761 761
                             <?php echo apply_filters(
762
-                                'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg',
763
-                                __(
764
-                                    'Some payment gateways can take 15 minutes or more to return their payment notification, so please be patient if you require payment confirmation as soon as possible. Please note that as soon as everything is finalized, we will send your full payment and registration confirmation results to you via email.',
765
-                                    'event_espresso'
766
-                                )
767
-                            ); ?>
762
+								'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg',
763
+								__(
764
+									'Some payment gateways can take 15 minutes or more to return their payment notification, so please be patient if you require payment confirmation as soon as possible. Please note that as soon as everything is finalized, we will send your full payment and registration confirmation results to you via email.',
765
+									'event_espresso'
766
+								)
767
+							); ?>
768 768
                             <br/>
769 769
                             <span class="jst-rght ee-block small-text lt-grey-text">
770 770
 								<?php _e('current wait time ', 'event_espresso'); ?>
@@ -775,120 +775,120 @@  discard block
 block discarded – undo
775 775
                 <div class="clear"></div>
776 776
             </div>
777 777
             <?php
778
-        }
779
-    }
778
+		}
779
+	}
780 780
 
781 781
 
782 782
 
783
-    /**
784
-     * display_details_for_events_requiring_pre_approval
785
-     *
786
-     * @param EE_Event[] $events
787
-     * @return void
788
-     */
789
-    public function display_details_for_events_requiring_pre_approval($events = array())
790
-    {
791
-        if ( ! empty($events)) {
792
-            ?>
783
+	/**
784
+	 * display_details_for_events_requiring_pre_approval
785
+	 *
786
+	 * @param EE_Event[] $events
787
+	 * @return void
788
+	 */
789
+	public function display_details_for_events_requiring_pre_approval($events = array())
790
+	{
791
+		if ( ! empty($events)) {
792
+			?>
793 793
             <div id="espresso-thank-you-page-not-approved-message-dv">
794 794
                 <h4 class="orange-text"><?php _e('Important Notice:', 'event_espresso'); ?></h4>
795 795
                 <p id="events-requiring-pre-approval-pg" class="small-text">
796 796
                     <?php echo apply_filters(
797
-                        'AHEE__EED_Thank_You_Page__get_ajax_content__not_approved_message',
798
-                        __(
799
-                            'The following Event(s) you have registered for do not require payment at this time and will not be billed for during this transaction. Billing will only occur after all attendees have been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.',
800
-                            'event_espresso'
801
-                        )
802
-                    ); ?>
797
+						'AHEE__EED_Thank_You_Page__get_ajax_content__not_approved_message',
798
+						__(
799
+							'The following Event(s) you have registered for do not require payment at this time and will not be billed for during this transaction. Billing will only occur after all attendees have been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.',
800
+							'event_espresso'
801
+						)
802
+					); ?>
803 803
                 </p>
804 804
                 <ul class="events-requiring-pre-approval-ul">
805 805
                     <?php foreach ($events as $event) {
806
-                        if ($event instanceof EE_Event) {
807
-                            echo '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>',
808
-                            $event->name(),
809
-                            '</li>';
810
-                        }
811
-                    } ?>
806
+						if ($event instanceof EE_Event) {
807
+							echo '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>',
808
+							$event->name(),
809
+							'</li>';
810
+						}
811
+					} ?>
812 812
                 </ul>
813 813
                 <div class="clear"></div>
814 814
             </div>
815 815
             <?php
816
-        }
817
-    }
818
-
819
-
820
-
821
-    /**
822
-     * get_transaction_details
823
-     *
824
-     * @return string
825
-     * @throws \EE_Error
826
-     */
827
-    public function get_transaction_details()
828
-    {
829
-        //prepare variables for displaying
830
-        $template_args = array();
831
-        $template_args['transaction'] = $this->_current_txn;
832
-        $template_args['reg_url_link'] = $this->_reg_url_link;
833
-        $template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(true);
834
-        // link to SPCO payment_options
835
-        $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link;
836
-        $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url;
837
-        // verify template arguments
838
-        EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
839
-        EEH_Template_Validator::verify_isnt_null(
840
-            $template_args['show_try_pay_again_link'],
841
-            '$show_try_pay_again_link'
842
-        );
843
-        EEH_Template_Validator::verify_isnt_null(
844
-            $template_args['SPCO_payment_options_url'],
845
-            '$SPCO_payment_options_url'
846
-        );
847
-        return EEH_Template::locate_template(
848
-            THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php',
849
-            $template_args,
850
-            true,
851
-            true
852
-        );
853
-    }
854
-
855
-
856
-
857
-    /**
858
-     * get_payment_row_html
859
-     *
860
-     * @param EE_Payment $payment
861
-     * @return string
862
-     * @throws \EE_Error
863
-     */
864
-    public function get_payment_row_html($payment = null)
865
-    {
866
-        $html = '';
867
-        if ($payment instanceof EE_Payment) {
868
-            if (
869
-                $payment->payment_method() instanceof EE_Payment_Method
870
-                && $payment->status() === EEM_Payment::status_id_failed
871
-                && $payment->payment_method()->is_off_site()
872
-            ) {
873
-                // considering the registrant has made it to the Thank You page,
874
-                // any failed payments may actually be pending and the IPN is just slow
875
-                // so let's
876
-                $payment->set_status(EEM_Payment::status_id_pending);
877
-            }
878
-            $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined
879
-                ? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>'
880
-                : '';
881
-            $html .= '
816
+		}
817
+	}
818
+
819
+
820
+
821
+	/**
822
+	 * get_transaction_details
823
+	 *
824
+	 * @return string
825
+	 * @throws \EE_Error
826
+	 */
827
+	public function get_transaction_details()
828
+	{
829
+		//prepare variables for displaying
830
+		$template_args = array();
831
+		$template_args['transaction'] = $this->_current_txn;
832
+		$template_args['reg_url_link'] = $this->_reg_url_link;
833
+		$template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(true);
834
+		// link to SPCO payment_options
835
+		$template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link;
836
+		$template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url;
837
+		// verify template arguments
838
+		EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
839
+		EEH_Template_Validator::verify_isnt_null(
840
+			$template_args['show_try_pay_again_link'],
841
+			'$show_try_pay_again_link'
842
+		);
843
+		EEH_Template_Validator::verify_isnt_null(
844
+			$template_args['SPCO_payment_options_url'],
845
+			'$SPCO_payment_options_url'
846
+		);
847
+		return EEH_Template::locate_template(
848
+			THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php',
849
+			$template_args,
850
+			true,
851
+			true
852
+		);
853
+	}
854
+
855
+
856
+
857
+	/**
858
+	 * get_payment_row_html
859
+	 *
860
+	 * @param EE_Payment $payment
861
+	 * @return string
862
+	 * @throws \EE_Error
863
+	 */
864
+	public function get_payment_row_html($payment = null)
865
+	{
866
+		$html = '';
867
+		if ($payment instanceof EE_Payment) {
868
+			if (
869
+				$payment->payment_method() instanceof EE_Payment_Method
870
+				&& $payment->status() === EEM_Payment::status_id_failed
871
+				&& $payment->payment_method()->is_off_site()
872
+			) {
873
+				// considering the registrant has made it to the Thank You page,
874
+				// any failed payments may actually be pending and the IPN is just slow
875
+				// so let's
876
+				$payment->set_status(EEM_Payment::status_id_pending);
877
+			}
878
+			$payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined
879
+				? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>'
880
+				: '';
881
+			$html .= '
882 882
 				<tr>
883 883
 					<td>
884 884
 						' . $payment->timestamp() . '
885 885
 					</td>
886 886
 					<td>
887 887
 						' . (
888
-                $payment->payment_method() instanceof EE_Payment_Method
889
-                    ? $payment->payment_method()->name()
890
-                    : __('Unknown', 'event_espresso')
891
-                ) . '
888
+				$payment->payment_method() instanceof EE_Payment_Method
889
+					? $payment->payment_method()->name()
890
+					: __('Unknown', 'event_espresso')
891
+				) . '
892 892
 					</td>
893 893
 					<td class="jst-rght">
894 894
 						' . EEH_Template::format_currency($payment->amount()) . '
@@ -897,87 +897,87 @@  discard block
 block discarded – undo
897 897
 						' . $payment->pretty_status(true) . $payment_declined_msg . '
898 898
 					</td>
899 899
 				</tr>';
900
-            do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment);
901
-        }
902
-        return $html;
903
-    }
904
-
905
-
906
-
907
-    /**
908
-     * get_payment_details
909
-     *
910
-     * @param array $payments
911
-     * @return string
912
-     * @throws \EE_Error
913
-     */
914
-    public function get_payment_details($payments = array())
915
-    {
916
-        //prepare variables for displaying
917
-        $template_args = array();
918
-        $template_args['transaction'] = $this->_current_txn;
919
-        $template_args['reg_url_link'] = $this->_reg_url_link;
920
-        $template_args['payments'] = array();
921
-        foreach ($payments as $payment) {
922
-            $template_args['payments'][] = $this->get_payment_row_html($payment);
923
-        }
924
-        //create a hacky payment object, but dont save it
925
-        $payment = EE_Payment::new_instance(
926
-            array(
927
-                'TXN_ID'        => $this->_current_txn->ID(),
928
-                'STS_ID'        => EEM_Payment::status_id_pending,
929
-                'PAY_timestamp' => time(),
930
-                'PAY_amount'    => $this->_current_txn->total(),
931
-                'PMD_ID'        => $this->_current_txn->payment_method_ID()
932
-            )
933
-        );
934
-        $payment_method = $this->_current_txn->payment_method();
935
-        if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) {
936
-            $template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment);
937
-        } else {
938
-            $template_args['gateway_content'] = '';
939
-        }
940
-        // link to SPCO payment_options
941
-        $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link;
942
-        $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url;
943
-        // verify template arguments
944
-        EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
945
-        EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments');
946
-        EEH_Template_Validator::verify_isnt_null(
947
-            $template_args['show_try_pay_again_link'],
948
-            '$show_try_pay_again_link'
949
-        );
950
-        EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content');
951
-        EEH_Template_Validator::verify_isnt_null(
952
-            $template_args['SPCO_payment_options_url'],
953
-            '$SPCO_payment_options_url'
954
-        );
955
-        return EEH_Template::locate_template(
956
-            THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php',
957
-            $template_args,
958
-            true,
959
-            true
960
-        );
961
-    }
962
-
963
-
964
-
965
-    /**
966
-     * get_payment_details
967
-     *
968
-     * @param array $payments
969
-     * @return string
970
-     * @throws \EE_Error
971
-     */
972
-    public function get_new_payments($payments = array())
973
-    {
974
-        $payments_html = '';
975
-        //prepare variables for displaying
976
-        foreach ($payments as $payment) {
977
-            $payments_html .= $this->get_payment_row_html($payment);
978
-        }
979
-        return $payments_html;
980
-    }
900
+			do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment);
901
+		}
902
+		return $html;
903
+	}
904
+
905
+
906
+
907
+	/**
908
+	 * get_payment_details
909
+	 *
910
+	 * @param array $payments
911
+	 * @return string
912
+	 * @throws \EE_Error
913
+	 */
914
+	public function get_payment_details($payments = array())
915
+	{
916
+		//prepare variables for displaying
917
+		$template_args = array();
918
+		$template_args['transaction'] = $this->_current_txn;
919
+		$template_args['reg_url_link'] = $this->_reg_url_link;
920
+		$template_args['payments'] = array();
921
+		foreach ($payments as $payment) {
922
+			$template_args['payments'][] = $this->get_payment_row_html($payment);
923
+		}
924
+		//create a hacky payment object, but dont save it
925
+		$payment = EE_Payment::new_instance(
926
+			array(
927
+				'TXN_ID'        => $this->_current_txn->ID(),
928
+				'STS_ID'        => EEM_Payment::status_id_pending,
929
+				'PAY_timestamp' => time(),
930
+				'PAY_amount'    => $this->_current_txn->total(),
931
+				'PMD_ID'        => $this->_current_txn->payment_method_ID()
932
+			)
933
+		);
934
+		$payment_method = $this->_current_txn->payment_method();
935
+		if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) {
936
+			$template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment);
937
+		} else {
938
+			$template_args['gateway_content'] = '';
939
+		}
940
+		// link to SPCO payment_options
941
+		$template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link;
942
+		$template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url;
943
+		// verify template arguments
944
+		EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
945
+		EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments');
946
+		EEH_Template_Validator::verify_isnt_null(
947
+			$template_args['show_try_pay_again_link'],
948
+			'$show_try_pay_again_link'
949
+		);
950
+		EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content');
951
+		EEH_Template_Validator::verify_isnt_null(
952
+			$template_args['SPCO_payment_options_url'],
953
+			'$SPCO_payment_options_url'
954
+		);
955
+		return EEH_Template::locate_template(
956
+			THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php',
957
+			$template_args,
958
+			true,
959
+			true
960
+		);
961
+	}
962
+
963
+
964
+
965
+	/**
966
+	 * get_payment_details
967
+	 *
968
+	 * @param array $payments
969
+	 * @return string
970
+	 * @throws \EE_Error
971
+	 */
972
+	public function get_new_payments($payments = array())
973
+	{
974
+		$payments_html = '';
975
+		//prepare variables for displaying
976
+		foreach ($payments as $payment) {
977
+			$payments_html .= $this->get_payment_row_html($payment);
978
+		}
979
+		return $payments_html;
980
+	}
981 981
 
982 982
 
983 983
 }
Please login to merge, or discard this patch.
admin/extend/transactions/Extend_Transactions_Admin_Page.core.php 2 patches
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -32,224 +32,224 @@  discard block
 block discarded – undo
32 32
 {
33 33
 
34 34
 
35
-    /**
36
-     * This is used to hold the reports template data which is setup early in the request.
37
-     * @type array
38
-     */
39
-    protected $_reports_template_data = array();
40
-
41
-    /**
42
-     * @Constructor
43
-     * @access public
44
-     *
45
-     * @param bool $routing
46
-     *
47
-     * @return \Extend_Transactions_Admin_Page
48
-     */
49
-    public function __construct($routing = true)
50
-    {
51
-        parent::__construct($routing);
52
-        define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/');
53
-        define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/');
54
-        define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/');
55
-    }
56
-
57
-
58
-    /**
59
-     *    _extend_page_config
60
-     *
61
-     * @access protected
62
-     * @return void
63
-     */
64
-    protected function _extend_page_config()
65
-    {
66
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions';
67
-
68
-        $new_page_routes = array(
69
-            'reports' => array(
70
-                'func'       => '_transaction_reports',
71
-                'capability' => 'ee_read_transactions'
72
-            )
73
-        );
74
-
75
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
76
-
77
-        $new_page_config    = array(
78
-            'reports' => array(
79
-                'nav'           => array(
80
-                    'label' => __('Reports', 'event_espresso'),
81
-                    'order' => 20
82
-                ),
83
-                'help_tabs'     => array(
84
-                    'transactions_reports_help_tab' => array(
85
-                        'title'    => __('Transaction Reports', 'event_espresso'),
86
-                        'filename' => 'transactions_reports'
87
-                    )
88
-                ),
89
-                /*'help_tour' => array( 'Transaction_Reports_Help_Tour' ),*/
90
-                'require_nonce' => false
91
-            )
92
-        );
93
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
94
-    }
95
-
96
-
97
-    /**
98
-     *    load_scripts_styles_reports
99
-     *
100
-     * @access public
101
-     * @return void
102
-     */
103
-    public function load_scripts_styles_reports()
104
-    {
105
-        wp_register_script(
106
-            'ee-txn-reports-js',
107
-            TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js',
108
-            array('google-charts'),
109
-            EVENT_ESPRESSO_VERSION,
110
-            true
111
-        );
112
-        wp_enqueue_script('ee-txn-reports-js');
113
-        $this->_transaction_reports_js_setup();
114
-        EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts();
115
-    }
116
-
117
-
118
-    /**
119
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
120
-     * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method.
121
-     */
122
-    protected function _transaction_reports_js_setup()
123
-    {
124
-        $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report();
125
-        $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report();
126
-    }
127
-
128
-
129
-    /**
130
-     * _transaction_reports
131
-     *    generates Business Reports regarding Transactions
132
-     *
133
-     * @return void
134
-     */
135
-    protected function _transaction_reports()
136
-    {
137
-        $template_path                              = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
138
-        $this->_admin_page_title                    = __('Transactions', 'event_espresso');
139
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
140
-            $this->_reports_template_data, true);
141
-
142
-        // the final template wrapper
143
-        $this->display_admin_page_with_no_sidebar();
144
-    }
145
-
146
-
147
-    /**
148
-     * _revenue_per_day_report
149
-     * generates Business Report showing Total Revenue per Day.
150
-     *
151
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
152
-     *
153
-     * @return string
154
-     */
155
-    private function _revenue_per_day_report($period = '-1 month')
156
-    {
157
-
158
-        $report_ID = 'txn-admin-revenue-per-day-report-dv';
159
-
160
-        $TXN = EEM_Transaction::instance();
161
-
162
-        $results  = $TXN->get_revenue_per_day_report($period);
163
-        $results  = (array)$results;
164
-        $revenue  = array();
165
-        $subtitle = '';
166
-
167
-        if ($results) {
168
-            $revenue[] = array(
169
-                __('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'),
170
-                __('Total Revenue', 'event_espresso')
171
-            );
172
-            foreach ($results as $result) {
173
-                $revenue[] = array($result->txnDate, (float)$result->revenue);
174
-            }
175
-
176
-            //setup the date range.
177
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
178
-            $ending_date    = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
179
-            $subtitle       = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
180
-                $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d'));
181
-        }
182
-
183
-        $report_title = esc_html__('Total Revenue per Day', 'event_espresso');
184
-
185
-        $report_params = array(
186
-            'title'     => $report_title,
187
-            'subtitle'  => $subtitle,
188
-            'id'        => $report_ID,
189
-            'revenue'   => $revenue,
190
-            'noResults' => empty($revenue) || count($revenue) === 1,
191
-            'noTxnMsg'  => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
192
-                '<h2>' . $report_title . '</h2><p>', '</p>')
193
-        );
194
-        wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params);
195
-
196
-        return $report_ID;
197
-    }
198
-
199
-
200
-    /**
201
-     * _revenue_per_event_report
202
-     * generates Business Report showing total revenue per event.
203
-     *
204
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
205
-     *
206
-     * @return int
207
-     */
208
-    private function _revenue_per_event_report($period = '-1 month')
209
-    {
210
-
211
-        $report_ID = 'txn-admin-revenue-per-event-report-dv';
212
-
213
-        $TXN      = EEM_Transaction::instance();
214
-        $results  = $TXN->get_revenue_per_event_report($period);
215
-        $results  = (array)$results;
216
-        $revenue  = array();
217
-        $subtitle = '';
218
-
219
-        if ($results) {
220
-            $revenue[] = array(
221
-                __('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'),
222
-                __('Total Revenue', 'event_espresso')
223
-            );
224
-            foreach ($results as $result) {
225
-                if ($result->revenue > 1) {
226
-                    $event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8'));
227
-                    $event_name = wp_trim_words($event_name, 5, '...');
228
-                    $revenue[]  = array($event_name, (float)$result->revenue);
229
-                }
230
-            }
231
-
232
-            //setup the date range.
233
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
234
-            $ending_date    = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
235
-            $subtitle       = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
236
-                $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d'));
237
-        }
238
-
239
-        $report_title = esc_html__('Total Revenue per Event', 'event_espresso');
240
-
241
-        $report_params = array(
242
-            'title'     => $report_title,
243
-            'subtitle'  => $subtitle,
244
-            'id'        => $report_ID,
245
-            'revenue'   => $revenue,
246
-            'noResults' => empty($revenue),
247
-            'noTxnMsg'  => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
248
-                '<h2>' . $report_title . '</h2><p>', '</p>')
249
-        );
250
-        wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params);
251
-
252
-        return $report_ID;
253
-    }
35
+	/**
36
+	 * This is used to hold the reports template data which is setup early in the request.
37
+	 * @type array
38
+	 */
39
+	protected $_reports_template_data = array();
40
+
41
+	/**
42
+	 * @Constructor
43
+	 * @access public
44
+	 *
45
+	 * @param bool $routing
46
+	 *
47
+	 * @return \Extend_Transactions_Admin_Page
48
+	 */
49
+	public function __construct($routing = true)
50
+	{
51
+		parent::__construct($routing);
52
+		define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/');
53
+		define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/');
54
+		define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/');
55
+	}
56
+
57
+
58
+	/**
59
+	 *    _extend_page_config
60
+	 *
61
+	 * @access protected
62
+	 * @return void
63
+	 */
64
+	protected function _extend_page_config()
65
+	{
66
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions';
67
+
68
+		$new_page_routes = array(
69
+			'reports' => array(
70
+				'func'       => '_transaction_reports',
71
+				'capability' => 'ee_read_transactions'
72
+			)
73
+		);
74
+
75
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
76
+
77
+		$new_page_config    = array(
78
+			'reports' => array(
79
+				'nav'           => array(
80
+					'label' => __('Reports', 'event_espresso'),
81
+					'order' => 20
82
+				),
83
+				'help_tabs'     => array(
84
+					'transactions_reports_help_tab' => array(
85
+						'title'    => __('Transaction Reports', 'event_espresso'),
86
+						'filename' => 'transactions_reports'
87
+					)
88
+				),
89
+				/*'help_tour' => array( 'Transaction_Reports_Help_Tour' ),*/
90
+				'require_nonce' => false
91
+			)
92
+		);
93
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
94
+	}
95
+
96
+
97
+	/**
98
+	 *    load_scripts_styles_reports
99
+	 *
100
+	 * @access public
101
+	 * @return void
102
+	 */
103
+	public function load_scripts_styles_reports()
104
+	{
105
+		wp_register_script(
106
+			'ee-txn-reports-js',
107
+			TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js',
108
+			array('google-charts'),
109
+			EVENT_ESPRESSO_VERSION,
110
+			true
111
+		);
112
+		wp_enqueue_script('ee-txn-reports-js');
113
+		$this->_transaction_reports_js_setup();
114
+		EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts();
115
+	}
116
+
117
+
118
+	/**
119
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
120
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method.
121
+	 */
122
+	protected function _transaction_reports_js_setup()
123
+	{
124
+		$this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report();
125
+		$this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report();
126
+	}
127
+
128
+
129
+	/**
130
+	 * _transaction_reports
131
+	 *    generates Business Reports regarding Transactions
132
+	 *
133
+	 * @return void
134
+	 */
135
+	protected function _transaction_reports()
136
+	{
137
+		$template_path                              = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
138
+		$this->_admin_page_title                    = __('Transactions', 'event_espresso');
139
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
140
+			$this->_reports_template_data, true);
141
+
142
+		// the final template wrapper
143
+		$this->display_admin_page_with_no_sidebar();
144
+	}
145
+
146
+
147
+	/**
148
+	 * _revenue_per_day_report
149
+	 * generates Business Report showing Total Revenue per Day.
150
+	 *
151
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
152
+	 *
153
+	 * @return string
154
+	 */
155
+	private function _revenue_per_day_report($period = '-1 month')
156
+	{
157
+
158
+		$report_ID = 'txn-admin-revenue-per-day-report-dv';
159
+
160
+		$TXN = EEM_Transaction::instance();
161
+
162
+		$results  = $TXN->get_revenue_per_day_report($period);
163
+		$results  = (array)$results;
164
+		$revenue  = array();
165
+		$subtitle = '';
166
+
167
+		if ($results) {
168
+			$revenue[] = array(
169
+				__('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'),
170
+				__('Total Revenue', 'event_espresso')
171
+			);
172
+			foreach ($results as $result) {
173
+				$revenue[] = array($result->txnDate, (float)$result->revenue);
174
+			}
175
+
176
+			//setup the date range.
177
+			$beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
178
+			$ending_date    = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
179
+			$subtitle       = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
180
+				$beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d'));
181
+		}
182
+
183
+		$report_title = esc_html__('Total Revenue per Day', 'event_espresso');
184
+
185
+		$report_params = array(
186
+			'title'     => $report_title,
187
+			'subtitle'  => $subtitle,
188
+			'id'        => $report_ID,
189
+			'revenue'   => $revenue,
190
+			'noResults' => empty($revenue) || count($revenue) === 1,
191
+			'noTxnMsg'  => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
192
+				'<h2>' . $report_title . '</h2><p>', '</p>')
193
+		);
194
+		wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params);
195
+
196
+		return $report_ID;
197
+	}
198
+
199
+
200
+	/**
201
+	 * _revenue_per_event_report
202
+	 * generates Business Report showing total revenue per event.
203
+	 *
204
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
205
+	 *
206
+	 * @return int
207
+	 */
208
+	private function _revenue_per_event_report($period = '-1 month')
209
+	{
210
+
211
+		$report_ID = 'txn-admin-revenue-per-event-report-dv';
212
+
213
+		$TXN      = EEM_Transaction::instance();
214
+		$results  = $TXN->get_revenue_per_event_report($period);
215
+		$results  = (array)$results;
216
+		$revenue  = array();
217
+		$subtitle = '';
218
+
219
+		if ($results) {
220
+			$revenue[] = array(
221
+				__('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'),
222
+				__('Total Revenue', 'event_espresso')
223
+			);
224
+			foreach ($results as $result) {
225
+				if ($result->revenue > 1) {
226
+					$event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8'));
227
+					$event_name = wp_trim_words($event_name, 5, '...');
228
+					$revenue[]  = array($event_name, (float)$result->revenue);
229
+				}
230
+			}
231
+
232
+			//setup the date range.
233
+			$beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
234
+			$ending_date    = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
235
+			$subtitle       = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
236
+				$beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d'));
237
+		}
238
+
239
+		$report_title = esc_html__('Total Revenue per Event', 'event_espresso');
240
+
241
+		$report_params = array(
242
+			'title'     => $report_title,
243
+			'subtitle'  => $subtitle,
244
+			'id'        => $report_ID,
245
+			'revenue'   => $revenue,
246
+			'noResults' => empty($revenue),
247
+			'noTxnMsg'  => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
248
+				'<h2>' . $report_title . '</h2><p>', '</p>')
249
+		);
250
+		wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params);
251
+
252
+		return $report_ID;
253
+	}
254 254
 
255 255
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
     public function __construct($routing = true)
50 50
     {
51 51
         parent::__construct($routing);
52
-        define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/');
53
-        define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/');
54
-        define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/');
52
+        define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'transactions/templates/');
53
+        define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'transactions/assets/');
54
+        define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'transactions/assets/');
55 55
     }
56 56
 
57 57
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      */
64 64
     protected function _extend_page_config()
65 65
     {
66
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions';
66
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'transactions';
67 67
 
68 68
         $new_page_routes = array(
69 69
             'reports' => array(
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
     {
105 105
         wp_register_script(
106 106
             'ee-txn-reports-js',
107
-            TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js',
107
+            TXN_CAF_ASSETS_URL.'ee-transaction-admin-reports.js',
108 108
             array('google-charts'),
109 109
             EVENT_ESPRESSO_VERSION,
110 110
             true
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
      */
135 135
     protected function _transaction_reports()
136 136
     {
137
-        $template_path                              = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
137
+        $template_path                              = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
138 138
         $this->_admin_page_title                    = __('Transactions', 'event_espresso');
139 139
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
140 140
             $this->_reports_template_data, true);
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
         $TXN = EEM_Transaction::instance();
161 161
 
162 162
         $results  = $TXN->get_revenue_per_day_report($period);
163
-        $results  = (array)$results;
163
+        $results  = (array) $results;
164 164
         $revenue  = array();
165 165
         $subtitle = '';
166 166
 
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
                 __('Total Revenue', 'event_espresso')
171 171
             );
172 172
             foreach ($results as $result) {
173
-                $revenue[] = array($result->txnDate, (float)$result->revenue);
173
+                $revenue[] = array($result->txnDate, (float) $result->revenue);
174 174
             }
175 175
 
176 176
             //setup the date range.
177
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
177
+            $beginning_date = new DateTime('now'.$period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
178 178
             $ending_date    = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
179 179
             $subtitle       = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
180 180
                 $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d'));
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
             'revenue'   => $revenue,
190 190
             'noResults' => empty($revenue) || count($revenue) === 1,
191 191
             'noTxnMsg'  => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
192
-                '<h2>' . $report_title . '</h2><p>', '</p>')
192
+                '<h2>'.$report_title.'</h2><p>', '</p>')
193 193
         );
194 194
         wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params);
195 195
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 
213 213
         $TXN      = EEM_Transaction::instance();
214 214
         $results  = $TXN->get_revenue_per_event_report($period);
215
-        $results  = (array)$results;
215
+        $results  = (array) $results;
216 216
         $revenue  = array();
217 217
         $subtitle = '';
218 218
 
@@ -225,12 +225,12 @@  discard block
 block discarded – undo
225 225
                 if ($result->revenue > 1) {
226 226
                     $event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8'));
227 227
                     $event_name = wp_trim_words($event_name, 5, '...');
228
-                    $revenue[]  = array($event_name, (float)$result->revenue);
228
+                    $revenue[]  = array($event_name, (float) $result->revenue);
229 229
                 }
230 230
             }
231 231
 
232 232
             //setup the date range.
233
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
233
+            $beginning_date = new DateTime('now'.$period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
234 234
             $ending_date    = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
235 235
             $subtitle       = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
236 236
                 $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d'));
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
             'revenue'   => $revenue,
246 246
             'noResults' => empty($revenue),
247 247
             'noTxnMsg'  => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
248
-                '<h2>' . $report_title . '</h2><p>', '</p>')
248
+                '<h2>'.$report_title.'</h2><p>', '</p>')
249 249
         );
250 250
         wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params);
251 251
 
Please login to merge, or discard this patch.
payment_methods/Paypal_Express/EEG_Paypal_Express.gateway.php 2 patches
Indentation   +97 added lines, -99 removed lines patch added patch discarded remove patch
@@ -44,77 +44,76 @@  discard block
 block discarded – undo
44 44
 	 */
45 45
 	protected $_image_url;
46 46
 
47
-    /**
48
-     * gateway URL variable
49
-     *
50
-     * @var string
51
-     */
52
-    protected $_base_gateway_url = '';
53
-
54
-
55
-
56
-    /**
57
-     * EEG_Paypal_Express constructor.
58
-     */
59
-    public function __construct()
60
-    {
61
-        $this->_currencies_supported = array(
62
-            'USD',
63
-            'AUD',
64
-            'BRL',
65
-            'CAD',
66
-            'CZK',
67
-            'DKK',
68
-            'EUR',
69
-            'HKD',
70
-            'HUF',
71
-            'ILS',
72
-            'JPY',
73
-            'MYR',
74
-            'MXN',
75
-            'NOK',
76
-            'NZD',
77
-            'PHP',
78
-            'PLN',
79
-            'GBP',
80
-            'RUB',
81
-            'SGD',
82
-            'SEK',
83
-            'CHF',
84
-            'TWD',
85
-            'THB',
86
-            'TRY'
87
-        );
88
-        parent::__construct();
89
-    }
90
-
91
-
92
-
93
-    /**
94
-	 * Sets the gateway URL variable based on whether debug mode is enabled or not.
47
+	/**
48
+	 * gateway URL variable
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $_base_gateway_url = '';
53
+
54
+
55
+
56
+	/**
57
+	 * EEG_Paypal_Express constructor.
58
+	 */
59
+	public function __construct()
60
+	{
61
+		$this->_currencies_supported = array(
62
+			'USD',
63
+			'AUD',
64
+			'BRL',
65
+			'CAD',
66
+			'CZK',
67
+			'DKK',
68
+			'EUR',
69
+			'HKD',
70
+			'HUF',
71
+			'ILS',
72
+			'JPY',
73
+			'MYR',
74
+			'MXN',
75
+			'NOK',
76
+			'NZD',
77
+			'PHP',
78
+			'PLN',
79
+			'GBP',
80
+			'RUB',
81
+			'SGD',
82
+			'SEK',
83
+			'CHF',
84
+			'TWD',
85
+			'THB',
86
+			'TRY'
87
+		);
88
+		parent::__construct();
89
+	}
90
+
95 91
 
92
+
93
+	/**
94
+	 * Sets the gateway URL variable based on whether debug mode is enabled or not.
96 95
 	 *
97 96
 *@param array $settings_array
98 97
 	 */
99 98
 	public function set_settings( $settings_array ) {
100 99
 		parent::set_settings($settings_array);
101 100
 		// Redirect URL.
102
-        $this->_base_gateway_url = $this->_debug_mode
103
-            ? 'https://api-3t.sandbox.paypal.com/nvp'
104
-            : 'https://api-3t.paypal.com/nvp';
101
+		$this->_base_gateway_url = $this->_debug_mode
102
+			? 'https://api-3t.sandbox.paypal.com/nvp'
103
+			: 'https://api-3t.paypal.com/nvp';
105 104
 	}
106 105
 
107 106
 
108 107
 
109
-    /**
110
-     * @param EEI_Payment $payment
111
-     * @param array       $billing_info
112
-     * @param string      $return_url
113
-     * @param string      $notify_url
114
-     * @param string      $cancel_url
115
-     * @return \EE_Payment|\EEI_Payment
116
-     * @throws \EE_Error
117
-     */
108
+	/**
109
+	 * @param EEI_Payment $payment
110
+	 * @param array       $billing_info
111
+	 * @param string      $return_url
112
+	 * @param string      $notify_url
113
+	 * @param string      $cancel_url
114
+	 * @return \EE_Payment|\EEI_Payment
115
+	 * @throws \EE_Error
116
+	 */
118 117
 	public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) {
119 118
 		if ( ! $payment instanceof EEI_Payment ) {
120 119
 			$payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) );
@@ -202,9 +201,9 @@  discard block
 block discarded – undo
202 201
 				$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
203 202
 				// Item quantity.
204 203
 				$token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1;
205
-                // Digital item is sold.
206
-                $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
207
-                $item_num++;
204
+				// Digital item is sold.
205
+				$token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
206
+				$item_num++;
208 207
 			}
209 208
 		} else {
210 209
 			// Just one Item.
@@ -277,7 +276,6 @@  discard block
 block discarded – undo
277 276
 
278 277
 
279 278
 	/**
280
-
281 279
 	 *  @param array $update_info {
282 280
 	 *	  @type string $gateway_txn_id
283 281
 	 *	  @type string status an EEMI_Payment status
@@ -297,8 +295,8 @@  discard block
 block discarded – undo
297 295
 				return $payment;
298 296
 			}
299 297
 			$primary_registrant = $transaction->primary_registration();
300
-            $payment_details = $payment->details();
301
-            // Check if we still have the token.
298
+			$payment_details = $payment->details();
299
+			// Check if we still have the token.
302 300
 			if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) {
303 301
 				$payment->set_status( $this->_pay_model->failed_status() );
304 302
 				return $payment;
@@ -407,35 +405,35 @@  discard block
 block discarded – undo
407 405
 	 */
408 406
 	public function _ppExpress_check_response( $request_response ) {
409 407
 		if ( is_wp_error( $request_response ) || empty($request_response['body']) ) {
410
-            // If we got here then there was an error in this request.
411
-            return array('status' => false, 'args' => $request_response);
412
-        }
413
-        $response_args = array();
414
-        parse_str( urldecode($request_response['body']), $response_args );
415
-        if ( ! isset($response_args['ACK'])) {
416
-            return array('status' => false, 'args' => $request_response);
417
-        }
418
-        if (
419
-            (
420
-                isset($response_args['PAYERID'])
421
-                || isset($response_args['TOKEN'])
422
-                || isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
423
-                || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
424
-            )
425
-            && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
426
-        ) {
427
-            // Response status OK, return response parameters for further processing.
428
-            return array('status' => true, 'args' => $response_args);
429
-        }
430
-        $errors = $this->_get_errors($response_args);
431
-        return array('status' => false, 'args' => $errors);
408
+			// If we got here then there was an error in this request.
409
+			return array('status' => false, 'args' => $request_response);
410
+		}
411
+		$response_args = array();
412
+		parse_str( urldecode($request_response['body']), $response_args );
413
+		if ( ! isset($response_args['ACK'])) {
414
+			return array('status' => false, 'args' => $request_response);
415
+		}
416
+		if (
417
+			(
418
+				isset($response_args['PAYERID'])
419
+				|| isset($response_args['TOKEN'])
420
+				|| isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
421
+				|| (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
422
+			)
423
+			&& in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
424
+		) {
425
+			// Response status OK, return response parameters for further processing.
426
+			return array('status' => true, 'args' => $response_args);
427
+		}
428
+		$errors = $this->_get_errors($response_args);
429
+		return array('status' => false, 'args' => $errors);
432 430
 	}
433 431
 
434 432
 
435 433
 	/**
436
-     *  Log a "Cleared" request.
437
-     *
438
-     * @param array $request
434
+	 *  Log a "Cleared" request.
435
+	 *
436
+	 * @param array $request
439 437
 	 * @param EEI_Payment  $payment
440 438
 	 * @param string  		$info
441 439
 	 * @return void
@@ -458,17 +456,17 @@  discard block
 block discarded – undo
458 456
 		$n = 0;
459 457
 		while ( isset($data_array["L_ERRORCODE{$n}"]) ) {
460 458
 			$l_error_code = isset($data_array["L_ERRORCODE{$n}"])
461
-                ? $data_array["L_ERRORCODE{$n}"]
462
-                : '';
459
+				? $data_array["L_ERRORCODE{$n}"]
460
+				: '';
463 461
 			$l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"])
464
-                ? $data_array["L_SEVERITYCODE{$n}"]
465
-                : '';
462
+				? $data_array["L_SEVERITYCODE{$n}"]
463
+				: '';
466 464
 			$l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"])
467
-                ? $data_array["L_SHORTMESSAGE{$n}"]
468
-                : '';
465
+				? $data_array["L_SHORTMESSAGE{$n}"]
466
+				: '';
469 467
 			$l_long_message = isset($data_array["L_LONGMESSAGE{$n}"])
470
-                ? $data_array["L_LONGMESSAGE{$n}"]
471
-                : '';
468
+				? $data_array["L_LONGMESSAGE{$n}"]
469
+				: '';
472 470
 
473 471
 			if ( $n === 0 ) {
474 472
 				$errors = array(
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' )) { exit('NO direct script access allowed'); }
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('NO direct script access allowed'); }
2 2
 
3 3
 /**
4 4
  * ----------------------------------------------
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 *
97 97
 *@param array $settings_array
98 98
 	 */
99
-	public function set_settings( $settings_array ) {
99
+	public function set_settings($settings_array) {
100 100
 		parent::set_settings($settings_array);
101 101
 		// Redirect URL.
102 102
         $this->_base_gateway_url = $this->_debug_mode
@@ -115,19 +115,19 @@  discard block
 block discarded – undo
115 115
      * @return \EE_Payment|\EEI_Payment
116 116
      * @throws \EE_Error
117 117
      */
118
-	public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) {
119
-		if ( ! $payment instanceof EEI_Payment ) {
120
-			$payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) );
121
-			$payment->set_status( $this->_pay_model->failed_status() );
118
+	public function set_redirection_info($payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL) {
119
+		if ( ! $payment instanceof EEI_Payment) {
120
+			$payment->set_gateway_response(__('Error. No associated payment was found.', 'event_espresso'));
121
+			$payment->set_status($this->_pay_model->failed_status());
122 122
 			return $payment;
123 123
 		}
124 124
 		$transaction = $payment->transaction();
125
-		if ( ! $transaction instanceof EEI_Transaction ) {
126
-			$payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) );
127
-			$payment->set_status( $this->_pay_model->failed_status() );
125
+		if ( ! $transaction instanceof EEI_Transaction) {
126
+			$payment->set_gateway_response(__('Could not process this payment because it has no associated transaction.', 'event_espresso'));
127
+			$payment->set_status($this->_pay_model->failed_status());
128 128
 			return $payment;
129 129
 		}
130
-		$order_description = substr( $this->_format_order_description($payment), 0, 127 );
130
+		$order_description = substr($this->_format_order_description($payment), 0, 127);
131 131
 		$primary_registration = $transaction->primary_registration();
132 132
 		$primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : false;
133 133
 		$locale = explode('-', get_bloginfo('language'));
@@ -141,37 +141,37 @@  discard block
 block discarded – undo
141 141
 			'RETURNURL' => $return_url,
142 142
 			'CANCELURL' => $cancel_url,
143 143
 			'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
144
-			'SOLUTIONTYPE' => 'Sole',	// Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional.
145
-			'BUTTONSOURCE' => 'EventEspresso_SP',//EE will blow up if you change this
144
+			'SOLUTIONTYPE' => 'Sole', // Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional.
145
+			'BUTTONSOURCE' => 'EventEspresso_SP', //EE will blow up if you change this
146 146
 			'LOCALECODE' => $locale[1]	// Locale of the pages displayed by PayPal during Express Checkout.
147 147
 		);
148 148
 
149 149
 		// Show itemized list.
150
-		if ( $this->_money->compare_floats( $payment->amount(), $transaction->total(), '==' ) ) {
150
+		if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
151 151
 			$item_num = 0;
152 152
 			$itemized_sum = 0;
153 153
 			$total_line_items = $transaction->total_line_item();
154 154
 			// Go through each item in the list.
155
-			foreach ( $total_line_items->get_items() as $line_item ) {
156
-				if ( $line_item instanceof EE_Line_Item ) {
155
+			foreach ($total_line_items->get_items() as $line_item) {
156
+				if ($line_item instanceof EE_Line_Item) {
157 157
 					// PayPal doesn't like line items with 0.00 amount, so we may skip those.
158
-					if ( EEH_Money::compare_floats( $line_item->total(), '0.00', '==' ) ) {
158
+					if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
159 159
 						continue;
160 160
 					}
161 161
 
162 162
 					$unit_price = $line_item->unit_price();
163 163
 					$line_item_quantity = $line_item->quantity();
164 164
 					// This is a discount.
165
-					if ( $line_item->is_percent() ) {
165
+					if ($line_item->is_percent()) {
166 166
 						$unit_price = $line_item->total();
167 167
 						$line_item_quantity = 1;
168 168
 					}
169 169
 					// Item Name.
170
-					$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name( $line_item, $payment), 0, 127);
170
+					$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name($line_item, $payment), 0, 127);
171 171
 					// Item description.
172
-					$token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc( $line_item, $payment), 0, 127);
172
+					$token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc($line_item, $payment), 0, 127);
173 173
 					// Cost of individual item.
174
-					$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $unit_price );
174
+					$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($unit_price);
175 175
 					// Item Number.
176 176
 					$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
177 177
 					// Item quantity.
@@ -188,16 +188,16 @@  discard block
 block discarded – undo
188 188
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
189 189
 			$token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
190 190
 
191
-			$itemized_sum_diff_from_txn_total = round( $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2 );
191
+			$itemized_sum_diff_from_txn_total = round($transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2);
192 192
 			// If we were not able to recognize some item like promotion, surcharge or cancellation,
193 193
 			// add the difference as an extra line item.
194
-			if ( $this->_money->compare_floats( $itemized_sum_diff_from_txn_total, 0, '!=' ) ) {
194
+			if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
195 195
 				// Item Name.
196
-				$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr( __( 'Other (promotion/surcharge/cancellation)', 'event_espresso' ), 0, 127 );
196
+				$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr(__('Other (promotion/surcharge/cancellation)', 'event_espresso'), 0, 127);
197 197
 				// Item description.
198 198
 				$token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = '';
199 199
 				// Cost of individual item.
200
-				$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $itemized_sum_diff_from_txn_total );
200
+				$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($itemized_sum_diff_from_txn_total);
201 201
 				// Item Number.
202 202
 				$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
203 203
 				// Item quantity.
@@ -209,11 +209,11 @@  discard block
 block discarded – undo
209 209
 		} else {
210 210
 			// Just one Item.
211 211
 			// Item Name.
212
-			$token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr( $this->_format_partial_payment_line_item_name($payment), 0, 127 );
212
+			$token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr($this->_format_partial_payment_line_item_name($payment), 0, 127);
213 213
 			// Item description.
214
-			$token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr( $this->_format_partial_payment_line_item_desc($payment), 0, 127 );
214
+			$token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr($this->_format_partial_payment_line_item_desc($payment), 0, 127);
215 215
 			// Cost of individual item.
216
-			$token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency( $payment->amount() );
216
+			$token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount());
217 217
 			// Item Number.
218 218
 			$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
219 219
 			// Item quantity.
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
 			// Digital item is sold.
222 222
 			$token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
223 223
 			// Item's sales S/H and tax amount.
224
-			$token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency( $payment->amount() );
224
+			$token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount());
225 225
 			$token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0';
226 226
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
227 227
 			$token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
228 228
 		}
229 229
 		// Automatically filling out shipping and contact information.
230
-		if ( $this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee ) {
231
-			$token_request_dtls['NOSHIPPING'] = '2';	//  If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
230
+		if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
231
+			$token_request_dtls['NOSHIPPING'] = '2'; //  If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
232 232
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
233 233
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
234 234
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
@@ -237,14 +237,14 @@  discard block
 block discarded – undo
237 237
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
238 238
 			$token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
239 239
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
240
-		} elseif ( ! $this->_request_shipping_addr ) {
240
+		} elseif ( ! $this->_request_shipping_addr) {
241 241
 			// Do not request shipping details on the PP Checkout page.
242 242
 			$token_request_dtls['NOSHIPPING'] = '1';
243 243
 			$token_request_dtls['REQCONFIRMSHIPPING'] = '0';
244 244
 
245 245
 		}
246 246
 		// Used a business/personal logo on the PayPal page.
247
-		if ( ! empty($this->_image_url) ) {
247
+		if ( ! empty($this->_image_url)) {
248 248
 			$token_request_dtls['LOGOIMG'] = $this->_image_url;
249 249
 		}
250 250
 		$token_request_dtls = apply_filters(
@@ -253,23 +253,23 @@  discard block
 block discarded – undo
253 253
 			$this
254 254
 		);
255 255
 		// Request PayPal token.
256
-		$token_request_response = $this->_ppExpress_request( $token_request_dtls, 'Payment Token', $payment );
257
-		$token_rstatus = $this->_ppExpress_check_response( $token_request_response );
258
-		$response_args = ( isset($token_rstatus['args']) && is_array($token_rstatus['args']) ) ? $token_rstatus['args'] : array();
259
-		if ( $token_rstatus['status'] ) {
256
+		$token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
257
+		$token_rstatus = $this->_ppExpress_check_response($token_request_response);
258
+		$response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) ? $token_rstatus['args'] : array();
259
+		if ($token_rstatus['status']) {
260 260
 			// We got the Token so we may continue with the payment and redirect the client.
261
-			$payment->set_details( $response_args );
261
+			$payment->set_details($response_args);
262 262
 
263 263
 			$gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
264
-			$payment->set_redirect_url( $gateway_url . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' . $response_args['TOKEN'] );
264
+			$payment->set_redirect_url($gateway_url.'/checkoutnow?useraction=commit&cmd=_express-checkout&token='.$response_args['TOKEN']);
265 265
 		} else {
266
-			if ( isset($response_args['L_ERRORCODE']) ) {
267
-				$payment->set_gateway_response( $response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE'] );
266
+			if (isset($response_args['L_ERRORCODE'])) {
267
+				$payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']);
268 268
 			} else {
269
-				$payment->set_gateway_response( __( 'Error occurred while trying to setup the Express Checkout.', 'event_espresso' ) );
269
+				$payment->set_gateway_response(__('Error occurred while trying to setup the Express Checkout.', 'event_espresso'));
270 270
 			}
271
-			$payment->set_details( $response_args );
272
-			$payment->set_status( $this->_pay_model->failed_status() );
271
+			$payment->set_details($response_args);
272
+			$payment->set_status($this->_pay_model->failed_status());
273 273
 		}
274 274
 
275 275
 		return $payment;
@@ -285,22 +285,22 @@  discard block
 block discarded – undo
285 285
 	 *  @param EEI_Transaction $transaction
286 286
 	 *  @return EEI_Payment
287 287
 	 */
288
-	public function handle_payment_update( $update_info, $transaction ) {
288
+	public function handle_payment_update($update_info, $transaction) {
289 289
 		$payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
290 290
 
291
-		if ( $payment instanceof EEI_Payment ) {
292
-			$this->log( array( 'Return from Authorization' => $update_info ), $payment );
291
+		if ($payment instanceof EEI_Payment) {
292
+			$this->log(array('Return from Authorization' => $update_info), $payment);
293 293
 			$transaction = $payment->transaction();
294
-			if ( ! $transaction instanceof EEI_Transaction ) {
295
-				$payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) );
296
-				$payment->set_status( $this->_pay_model->failed_status() );
294
+			if ( ! $transaction instanceof EEI_Transaction) {
295
+				$payment->set_gateway_response(__('Could not process this payment because it has no associated transaction.', 'event_espresso'));
296
+				$payment->set_status($this->_pay_model->failed_status());
297 297
 				return $payment;
298 298
 			}
299 299
 			$primary_registrant = $transaction->primary_registration();
300 300
             $payment_details = $payment->details();
301 301
             // Check if we still have the token.
302
-			if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) {
303
-				$payment->set_status( $this->_pay_model->failed_status() );
302
+			if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
303
+				$payment->set_status($this->_pay_model->failed_status());
304 304
 				return $payment;
305 305
 			}
306 306
 
@@ -309,10 +309,10 @@  discard block
 block discarded – undo
309 309
 				'TOKEN' => $payment_details['TOKEN']
310 310
 			);
311 311
 			// Request Customer Details.
312
-			$cdetails_request_response = $this->_ppExpress_request( $cdetails_request_dtls, 'Customer Details', $payment );
313
-			$cdetails_rstatus = $this->_ppExpress_check_response( $cdetails_request_response );
314
-			$cdata_response_args = ( isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']) ) ? $cdetails_rstatus['args'] : array();
315
-			if ( $cdetails_rstatus['status'] ) {
312
+			$cdetails_request_response = $this->_ppExpress_request($cdetails_request_dtls, 'Customer Details', $payment);
313
+			$cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
314
+			$cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) ? $cdetails_rstatus['args'] : array();
315
+			if ($cdetails_rstatus['status']) {
316 316
 				// We got the PayerID so now we can Complete the transaction.
317 317
 				$docheckout_request_dtls = array(
318 318
 					'METHOD' => 'DoExpressCheckoutPayment',
@@ -323,39 +323,39 @@  discard block
 block discarded – undo
323 323
 					'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code()
324 324
 				);
325 325
 				// Payment Checkout/Capture.
326
-				$docheckout_request_response = $this->_ppExpress_request( $docheckout_request_dtls, 'Do Payment', $payment );
327
-				$docheckout_rstatus = $this->_ppExpress_check_response( $docheckout_request_response );
328
-				$docheckout_response_args = ( isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']) ) ? $docheckout_rstatus['args'] : array();
329
-				if ( $docheckout_rstatus['status'] ) {
326
+				$docheckout_request_response = $this->_ppExpress_request($docheckout_request_dtls, 'Do Payment', $payment);
327
+				$docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
328
+				$docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) ? $docheckout_rstatus['args'] : array();
329
+				if ($docheckout_rstatus['status']) {
330 330
 					// All is well, payment approved.
331 331
 					$primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : '';
332
-					$payment->set_extra_accntng( $primary_registration_code );
333
-					$payment->set_amount( isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0 );
334
-					$payment->set_txn_id_chq_nmbr( isset( $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] ) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null );
335
-					$payment->set_details( $cdata_response_args );
336
-					$payment->set_gateway_response( isset( $docheckout_response_args['PAYMENTINFO_0_ACK'] ) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : '' );
337
-					$payment->set_status( $this->_pay_model->approved_status() );
332
+					$payment->set_extra_accntng($primary_registration_code);
333
+					$payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0);
334
+					$payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null);
335
+					$payment->set_details($cdata_response_args);
336
+					$payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : '');
337
+					$payment->set_status($this->_pay_model->approved_status());
338 338
 				} else {
339
-					if ( isset($docheckout_response_args['L_ERRORCODE']) ) {
340
-						$payment->set_gateway_response( $docheckout_response_args['L_ERRORCODE'] . '; ' . $docheckout_response_args['L_SHORTMESSAGE'] );
339
+					if (isset($docheckout_response_args['L_ERRORCODE'])) {
340
+						$payment->set_gateway_response($docheckout_response_args['L_ERRORCODE'].'; '.$docheckout_response_args['L_SHORTMESSAGE']);
341 341
 					} else {
342
-						$payment->set_gateway_response( __( 'Error occurred while trying to Capture the funds.', 'event_espresso' ) );
342
+						$payment->set_gateway_response(__('Error occurred while trying to Capture the funds.', 'event_espresso'));
343 343
 					}
344
-					$payment->set_details( $docheckout_response_args );
345
-					$payment->set_status( $this->_pay_model->declined_status() );
344
+					$payment->set_details($docheckout_response_args);
345
+					$payment->set_status($this->_pay_model->declined_status());
346 346
 				}
347 347
 			} else {
348
-				if ( isset($cdata_response_args['L_ERRORCODE']) ) {
349
-					$payment->set_gateway_response( $cdata_response_args['L_ERRORCODE'] . '; ' . $cdata_response_args['L_SHORTMESSAGE'] );
348
+				if (isset($cdata_response_args['L_ERRORCODE'])) {
349
+					$payment->set_gateway_response($cdata_response_args['L_ERRORCODE'].'; '.$cdata_response_args['L_SHORTMESSAGE']);
350 350
 				} else {
351
-					$payment->set_gateway_response( __( 'Error occurred while trying to get payment Details from PayPal.', 'event_espresso' ) );
351
+					$payment->set_gateway_response(__('Error occurred while trying to get payment Details from PayPal.', 'event_espresso'));
352 352
 				}
353
-				$payment->set_details( $cdata_response_args );
354
-				$payment->set_status( $this->_pay_model->failed_status() );
353
+				$payment->set_details($cdata_response_args);
354
+				$payment->set_status($this->_pay_model->failed_status());
355 355
 			}
356 356
 		} else {
357
-			$payment->set_gateway_response( __( 'Error occurred while trying to process the payment.', 'event_espresso' ) );
358
-			$payment->set_status( $this->_pay_model->failed_status() );
357
+			$payment->set_gateway_response(__('Error occurred while trying to process the payment.', 'event_espresso'));
358
+			$payment->set_status($this->_pay_model->failed_status());
359 359
 		}
360 360
 
361 361
 		return $payment;
@@ -370,16 +370,16 @@  discard block
 block discarded – undo
370 370
 	 *  @param EEI_Payment  $payment
371 371
 	 *	@return mixed
372 372
 	 */
373
-	public function _ppExpress_request( $request_params, $request_text, $payment ) {
373
+	public function _ppExpress_request($request_params, $request_text, $payment) {
374 374
 		$request_dtls = array(
375 375
 			'VERSION' => '204.0',
376
-			'USER' => urlencode( $this->_api_username ),
377
-			'PWD' => urlencode( $this->_api_password ),
378
-			'SIGNATURE' => urlencode( $this->_api_signature )
376
+			'USER' => urlencode($this->_api_username),
377
+			'PWD' => urlencode($this->_api_password),
378
+			'SIGNATURE' => urlencode($this->_api_signature)
379 379
 		);
380
-		$dtls = array_merge( $request_dtls, $request_params );
380
+		$dtls = array_merge($request_dtls, $request_params);
381 381
 
382
-		$this->_log_clean_request( $dtls, $payment, $request_text . ' Request' );
382
+		$this->_log_clean_request($dtls, $payment, $request_text.' Request');
383 383
 		// Request Customer Details.
384 384
 		$request_response = wp_remote_post(
385 385
 			$this->_base_gateway_url,
@@ -389,11 +389,11 @@  discard block
 block discarded – undo
389 389
 				'httpversion' => '1.1',
390 390
 				'cookies' => array(),
391 391
 				'headers' => array(),
392
-				'body' => http_build_query( $dtls )
392
+				'body' => http_build_query($dtls)
393 393
 			)
394 394
 		);
395 395
 		// Log the response.
396
-		$this->log( array( $request_text . ' Response' => $request_response), $payment );
396
+		$this->log(array($request_text.' Response' => $request_response), $payment);
397 397
 
398 398
 		return $request_response;
399 399
 	}
@@ -405,13 +405,13 @@  discard block
 block discarded – undo
405 405
 	 *	@param mixed        $request_response
406 406
 	 *	@return array
407 407
 	 */
408
-	public function _ppExpress_check_response( $request_response ) {
409
-		if ( is_wp_error( $request_response ) || empty($request_response['body']) ) {
408
+	public function _ppExpress_check_response($request_response) {
409
+		if (is_wp_error($request_response) || empty($request_response['body'])) {
410 410
             // If we got here then there was an error in this request.
411 411
             return array('status' => false, 'args' => $request_response);
412 412
         }
413 413
         $response_args = array();
414
-        parse_str( urldecode($request_response['body']), $response_args );
414
+        parse_str(urldecode($request_response['body']), $response_args);
415 415
         if ( ! isset($response_args['ACK'])) {
416 416
             return array('status' => false, 'args' => $request_response);
417 417
         }
@@ -440,10 +440,10 @@  discard block
 block discarded – undo
440 440
 	 * @param string  		$info
441 441
 	 * @return void
442 442
 	 */
443
-	private function _log_clean_request($request, $payment, $info ) {
443
+	private function _log_clean_request($request, $payment, $info) {
444 444
 		$cleaned_request_data = $request;
445 445
 		unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
446
-		$this->log( array($info => $cleaned_request_data), $payment );
446
+		$this->log(array($info => $cleaned_request_data), $payment);
447 447
 	}
448 448
 
449 449
 
@@ -453,10 +453,10 @@  discard block
 block discarded – undo
453 453
 	 *  @param array	$data_array
454 454
 	 *  @return array
455 455
 	 */
456
-	private function _get_errors( $data_array ) {
456
+	private function _get_errors($data_array) {
457 457
 		$errors = array();
458 458
 		$n = 0;
459
-		while ( isset($data_array["L_ERRORCODE{$n}"]) ) {
459
+		while (isset($data_array["L_ERRORCODE{$n}"])) {
460 460
 			$l_error_code = isset($data_array["L_ERRORCODE{$n}"])
461 461
                 ? $data_array["L_ERRORCODE{$n}"]
462 462
                 : '';
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
                 ? $data_array["L_LONGMESSAGE{$n}"]
471 471
                 : '';
472 472
 
473
-			if ( $n === 0 ) {
473
+			if ($n === 0) {
474 474
 				$errors = array(
475 475
 					'L_ERRORCODE' => $l_error_code,
476 476
 					'L_SHORTMESSAGE' => $l_short_message,
@@ -478,10 +478,10 @@  discard block
 block discarded – undo
478 478
 					'L_SEVERITYCODE' => $l_severity_code
479 479
 				);
480 480
 			} else {
481
-				$errors['L_ERRORCODE'] .= ', ' . $l_error_code;
482
-				$errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
483
-				$errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
484
-				$errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
481
+				$errors['L_ERRORCODE'] .= ', '.$l_error_code;
482
+				$errors['L_SHORTMESSAGE'] .= ', '.$l_short_message;
483
+				$errors['L_LONGMESSAGE'] .= ', '.$l_long_message;
484
+				$errors['L_SEVERITYCODE'] .= ', '.$l_severity_code;
485 485
 			}
486 486
 
487 487
 			$n++;
Please login to merge, or discard this patch.
reg_steps/payment_options/EE_SPCO_Reg_Step_Payment_Options.class.php 2 patches
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -286,41 +286,41 @@  discard block
 block discarded – undo
286 286
 			$this->checkout->revisit
287 287
 		);
288 288
 		foreach ( $registrations as $REG_ID => $registration ) {
289
-            /** @var $registration EE_Registration */
290
-            // has this registration lost it's space ?
289
+			/** @var $registration EE_Registration */
290
+			// has this registration lost it's space ?
291 291
 			if ( isset( $ejected_registrations[ $REG_ID ] ) ) {
292 292
 				$insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event();
293 293
 				continue;
294 294
 			}
295
-            // event requires admin approval
296
-            if ($registration->status_ID() === EEM_Registration::status_id_not_approved) {
297
-                // add event to list of events with pre-approval reg status
298
-                $registrations_requiring_pre_approval[$REG_ID] = $registration;
299
-                do_action(
300
-                    'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval',
301
-                    $registration->event(),
302
-                    $this
303
-                );
304
-                continue;
305
-            }
306
-            if (
295
+			// event requires admin approval
296
+			if ($registration->status_ID() === EEM_Registration::status_id_not_approved) {
297
+				// add event to list of events with pre-approval reg status
298
+				$registrations_requiring_pre_approval[$REG_ID] = $registration;
299
+				do_action(
300
+					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval',
301
+					$registration->event(),
302
+					$this
303
+				);
304
+				continue;
305
+			}
306
+			if (
307 307
 				// returning registrant
308 308
 				$this->checkout->revisit
309 309
 				// anything other than Approved
310 310
 				&& $registration->status_ID() !== EEM_Registration::status_id_approved
311
-                && (
312
-                    $registration->event()->is_sold_out()
313
-                    || $registration->event()->is_sold_out( true )
314
-                )
315
-            ) {
316
-                // add event to list of events that are sold out
317
-                $sold_out_events[ $registration->event()->ID() ] = $registration->event();
318
-                do_action(
319
-                    'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
320
-                    $registration->event(),
321
-                    $this
322
-                );
323
-                continue;
311
+				&& (
312
+					$registration->event()->is_sold_out()
313
+					|| $registration->event()->is_sold_out( true )
314
+				)
315
+			) {
316
+				// add event to list of events that are sold out
317
+				$sold_out_events[ $registration->event()->ID() ] = $registration->event();
318
+				do_action(
319
+					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
320
+					$registration->event(),
321
+					$this
322
+				);
323
+				continue;
324 324
 			}
325 325
 			// are they allowed to pay now and is there monies owing?
326 326
 			if ( $registration->owes_monies_and_can_pay() ) {
@@ -428,11 +428,11 @@  discard block
 block discarded – undo
428 428
 			new EE_Billable_Line_Item_Filter(
429 429
 				EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations(
430 430
 					EE_Registry::instance()->SSN->checkout()->transaction->registrations(
431
-                        EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
432
-                    )
431
+						EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
432
+					)
433 433
 				)
434 434
 			)
435
-        );
435
+		);
436 436
 		$line_item_filter_collection->add( new EE_Non_Zero_Line_Item_Filter() );
437 437
 		return $line_item_filter_collection;
438 438
 	}
@@ -481,46 +481,46 @@  discard block
 block discarded – undo
481 481
 	 * @throws \EE_Error
482 482
 	 */
483 483
 	public static function find_registrations_that_lost_their_space( array $registrations, $revisit = false ) {
484
-        // registrations per event
484
+		// registrations per event
485 485
 		$event_reg_count = array();
486 486
 		// spaces left per event
487 487
 		$event_spaces_remaining = array();
488
-        // tickets left sorted by ID
489
-        $tickets_remaining = array();
490
-        // registrations that have lost their space
488
+		// tickets left sorted by ID
489
+		$tickets_remaining = array();
490
+		// registrations that have lost their space
491 491
 		$ejected_registrations = array();
492 492
 		foreach ( $registrations as $REG_ID => $registration ) {
493
-            if (
494
-                $registration->status_ID() === EEM_Registration::status_id_approved
495
-                || apply_filters(
496
-                    'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment',
497
-                    false,
498
-                    $registration,
499
-                    $revisit
500
-                )
501
-            ) {
502
-                continue;
493
+			if (
494
+				$registration->status_ID() === EEM_Registration::status_id_approved
495
+				|| apply_filters(
496
+					'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment',
497
+					false,
498
+					$registration,
499
+					$revisit
500
+				)
501
+			) {
502
+				continue;
503 503
 			}
504 504
 			$EVT_ID = $registration->event_ID();
505
-            $ticket = $registration->ticket();
506
-            if ( ! isset($tickets_remaining[$ticket->ID()])) {
507
-                $tickets_remaining[$ticket->ID()] = $ticket->remaining();
508
-            }
509
-            if ($tickets_remaining[$ticket->ID()] > 0) {
510
-                if ( ! isset($event_reg_count[$EVT_ID])) {
511
-                    $event_reg_count[$EVT_ID] = 0;
512
-                }
513
-                $event_reg_count[$EVT_ID]++;
514
-                if ( ! isset($event_spaces_remaining[$EVT_ID])) {
515
-                    $event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale();
516
-                }
517
-            }
505
+			$ticket = $registration->ticket();
506
+			if ( ! isset($tickets_remaining[$ticket->ID()])) {
507
+				$tickets_remaining[$ticket->ID()] = $ticket->remaining();
508
+			}
509
+			if ($tickets_remaining[$ticket->ID()] > 0) {
510
+				if ( ! isset($event_reg_count[$EVT_ID])) {
511
+					$event_reg_count[$EVT_ID] = 0;
512
+				}
513
+				$event_reg_count[$EVT_ID]++;
514
+				if ( ! isset($event_spaces_remaining[$EVT_ID])) {
515
+					$event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale();
516
+				}
517
+			}
518 518
 			if (
519 519
 				$revisit
520 520
 				&& (
521
-                    $tickets_remaining[$ticket->ID()] === 0
522
-				    || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ]
523
-                )
521
+					$tickets_remaining[$ticket->ID()] === 0
522
+					|| $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ]
523
+				)
524 524
 			) {
525 525
 				$ejected_registrations[ $REG_ID ] = $registration->event();
526 526
 				if ( $registration->status_ID() !== EEM_Registration::status_id_wait_list ) {
@@ -589,9 +589,9 @@  discard block
 block discarded – undo
589 589
 				'layout_strategy'		=> new EE_Template_Layout(
590 590
 					array(
591 591
 						'layout_template_file' => SPCO_REG_STEPS_PATH
592
-						                          . $this->_slug
593
-						                          . DS
594
-						                          . 'sold_out_events.template.php',
592
+												  . $this->_slug
593
+												  . DS
594
+												  . 'sold_out_events.template.php',
595 595
 						'template_args'        => apply_filters(
596 596
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
597 597
 							array(
@@ -644,9 +644,9 @@  discard block
 block discarded – undo
644 644
 				'layout_strategy' => new EE_Template_Layout(
645 645
 					array(
646 646
 						'layout_template_file' => SPCO_REG_STEPS_PATH
647
-						                          . $this->_slug
648
-						                          . DS
649
-						                          . 'sold_out_events.template.php',
647
+												  . $this->_slug
648
+												  . DS
649
+												  . 'sold_out_events.template.php',
650 650
 						'template_args'        => apply_filters(
651 651
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args',
652 652
 							array(
@@ -694,9 +694,9 @@  discard block
 block discarded – undo
694 694
 				'layout_strategy'		=> new EE_Template_Layout(
695 695
 					array(
696 696
 						'layout_template_file' => SPCO_REG_STEPS_PATH
697
-						                          . $this->_slug
698
-						                          . DS
699
-						                          . 'events_requiring_pre_approval.template.php', // layout_template
697
+												  . $this->_slug
698
+												  . DS
699
+												  . 'events_requiring_pre_approval.template.php', // layout_template
700 700
 						'template_args'        => apply_filters(
701 701
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
702 702
 							array(
@@ -734,9 +734,9 @@  discard block
 block discarded – undo
734 734
 				'layout_strategy' 	=> new EE_Template_Layout(
735 735
 					array(
736 736
 						'layout_template_file' => SPCO_REG_STEPS_PATH
737
-						                          . $this->_slug
738
-						                          . DS
739
-						                          . 'no_payment_required.template.php', // layout_template
737
+												  . $this->_slug
738
+												  . DS
739
+												  . 'no_payment_required.template.php', // layout_template
740 740
 						'template_args'        => apply_filters(
741 741
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args',
742 742
 							array(
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
 					$available_payment_method_options[ $payment_method->slug() ] = $payment_method_button;
965 965
 				}
966 966
 				$payment_methods_billing_info[ $payment_method->slug()
967
-				                               . '-info' ] = $this->_payment_method_billing_info(
967
+											   . '-info' ] = $this->_payment_method_billing_info(
968 968
 					$payment_method
969 969
 				);
970 970
 			}
@@ -1152,7 +1152,7 @@  discard block
 block discarded – undo
1152 1152
 		// fill form with attendee info if applicable
1153 1153
 		if (
1154 1154
 			$payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form
1155
-		    && $this->checkout->transaction_has_primary_registrant()
1155
+			&& $this->checkout->transaction_has_primary_registrant()
1156 1156
 		) {
1157 1157
 			$payment_method_billing_form->populate_from_attendee(
1158 1158
 				$this->checkout->transaction->primary_registration()->attendee()
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
 		// and debug content
1162 1162
 		if (
1163 1163
 			$payment_method_billing_form instanceof EE_Billing_Info_Form
1164
-		    && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1164
+			&& $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1165 1165
 		) {
1166 1166
 			$payment_method_billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1167 1167
 				$payment_method_billing_form
@@ -1336,7 +1336,7 @@  discard block
 block discarded – undo
1336 1336
 		}
1337 1337
 		// and debug content
1338 1338
 		if ( $this->checkout->billing_form instanceof EE_Billing_Info_Form
1339
-		     && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1339
+			 && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1340 1340
 		) {
1341 1341
 			$this->checkout->billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1342 1342
 				$this->checkout->billing_form
@@ -1506,8 +1506,8 @@  discard block
 block discarded – undo
1506 1506
 		}
1507 1507
 		// does this attendee already exist in the db ? we're searching using a combination of first name, last name, AND email address
1508 1508
 		if ( ! empty( $attendee_data['ATT_fname'] )
1509
-		     && ! empty( $attendee_data['ATT_lname'] )
1510
-		     && ! empty( $attendee_data['ATT_email'] )
1509
+			 && ! empty( $attendee_data['ATT_lname'] )
1510
+			 && ! empty( $attendee_data['ATT_email'] )
1511 1511
 		) {
1512 1512
 			$existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee(
1513 1513
 				array(
@@ -1754,7 +1754,7 @@  discard block
 block discarded – undo
1754 1754
 			$payment_status = $payment->status();
1755 1755
 			if (
1756 1756
 				$payment_status === EEM_Payment::status_id_approved
1757
-			    || $payment_status === EEM_Payment::status_id_pending
1757
+				|| $payment_status === EEM_Payment::status_id_pending
1758 1758
 			) {
1759 1759
 				return true;
1760 1760
 			} else {
@@ -1980,8 +1980,8 @@  discard block
 block discarded – undo
1980 1980
 			return false;
1981 1981
 		}
1982 1982
 		if ( ! $primary_registration->_add_relation_to( $this->checkout->primary_attendee_obj, 'Attendee' )
1983
-		       instanceof
1984
-		       EE_Attendee
1983
+			   instanceof
1984
+			   EE_Attendee
1985 1985
 		) {
1986 1986
 			EE_Error::add_error(
1987 1987
 				sprintf(
@@ -2454,14 +2454,14 @@  discard block
 block discarded – undo
2454 2454
 
2455 2455
 
2456 2456
 
2457
-    /**
2458
-     * _validate_return
2459
-     *
2460
-     * @access private
2461
-     * @return void
2462
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
2463
-     * @throws \EE_Error
2464
-     */
2457
+	/**
2458
+	 * _validate_return
2459
+	 *
2460
+	 * @access private
2461
+	 * @return void
2462
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
2463
+	 * @throws \EE_Error
2464
+	 */
2465 2465
 	private function _validate_offsite_return() {
2466 2466
 		$TXN_ID = (int)EE_Registry::instance()->REQ->get( 'spco_txn', 0 );
2467 2467
 		if ( $TXN_ID !== $this->checkout->transaction->ID() ) {
@@ -2487,20 +2487,20 @@  discard block
 block discarded – undo
2487 2487
 				? $primary_registrant->session_ID()
2488 2488
 				: null;
2489 2489
 			// validate current Session ID and compare against valid TXN session ID
2490
-            if (
2491
-                $invalid_TXN // if this is already true, then skip other checks
2492
-                || EE_Session::instance()->id() === null
2493
-                || (
2494
-                    // WARNING !!!
2495
-                    // this could be PayPal sending back duplicate requests (ya they do that)
2496
-                    // or it **could** mean someone is simply registering AGAIN after having just done so
2497
-                    // so now we need to determine if this current TXN looks valid or not
2498
-                    // and whether this reg step has even been started ?
2499
-                    EE_Session::instance()->id() === $valid_TXN_SID
2500
-                    // really? you're half way through this reg step, but you never started it ?
2501
-                    && $this->checkout->transaction->reg_step_completed($this->slug()) === false
2502
-                )
2503
-            ) {
2490
+			if (
2491
+				$invalid_TXN // if this is already true, then skip other checks
2492
+				|| EE_Session::instance()->id() === null
2493
+				|| (
2494
+					// WARNING !!!
2495
+					// this could be PayPal sending back duplicate requests (ya they do that)
2496
+					// or it **could** mean someone is simply registering AGAIN after having just done so
2497
+					// so now we need to determine if this current TXN looks valid or not
2498
+					// and whether this reg step has even been started ?
2499
+					EE_Session::instance()->id() === $valid_TXN_SID
2500
+					// really? you're half way through this reg step, but you never started it ?
2501
+					&& $this->checkout->transaction->reg_step_completed($this->slug()) === false
2502
+				)
2503
+			) {
2504 2504
 				$invalid_TXN = true;
2505 2505
 			}
2506 2506
 			if ( $invalid_TXN ) {
@@ -2702,19 +2702,19 @@  discard block
 block discarded – undo
2702 2702
 
2703 2703
 
2704 2704
 
2705
-    /**
2706
-     *    __sleep
2707
-     * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization
2708
-     * EE_Checkout will handle the reimplementation of itself upon waking,
2709
-     * but we won't bother with the reg form, because if needed, it will be regenerated anyways
2710
-     *
2711
-     * @return array
2712
-     */
2713
-    public function __sleep()
2714
-    {
2715
-        // remove the reg form and the checkout
2716
-        return array_diff( array_keys( get_object_vars( $this ) ), array( 'reg_form', 'checkout', 'line_item_display' ) );
2717
-    }
2705
+	/**
2706
+	 *    __sleep
2707
+	 * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization
2708
+	 * EE_Checkout will handle the reimplementation of itself upon waking,
2709
+	 * but we won't bother with the reg form, because if needed, it will be regenerated anyways
2710
+	 *
2711
+	 * @return array
2712
+	 */
2713
+	public function __sleep()
2714
+	{
2715
+		// remove the reg form and the checkout
2716
+		return array_diff( array_keys( get_object_vars( $this ) ), array( 'reg_form', 'checkout', 'line_item_display' ) );
2717
+	}
2718 2718
 
2719 2719
 
2720 2720
 
Please login to merge, or discard this patch.
Spacing   +359 added lines, -359 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -38,32 +38,32 @@  discard block
 block discarded – undo
38 38
 	public static function set_hooks() {
39 39
 		add_filter(
40 40
 			'FHEE__SPCO__EE_Line_Item_Filter_Collection',
41
-			array( 'EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters' )
41
+			array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters')
42 42
 		);
43 43
 		add_action(
44 44
 			'wp_ajax_switch_spco_billing_form',
45
-			array( 'EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form' )
45
+			array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form')
46 46
 		);
47 47
 		add_action(
48 48
 			'wp_ajax_nopriv_switch_spco_billing_form',
49
-			array( 'EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form' )
49
+			array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form')
50 50
 		);
51
-		add_action( 'wp_ajax_save_payer_details', array( 'EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details' ) );
51
+		add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details'));
52 52
 		add_action(
53 53
 			'wp_ajax_nopriv_save_payer_details',
54
-			array( 'EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details' )
54
+			array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')
55 55
 		);
56 56
 		add_action(
57 57
 			'wp_ajax_get_transaction_details_for_gateways',
58
-			array( 'EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details' )
58
+			array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details')
59 59
 		);
60 60
 		add_action(
61 61
 			'wp_ajax_nopriv_get_transaction_details_for_gateways',
62
-			array( 'EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details' )
62
+			array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details')
63 63
 		);
64 64
 		add_filter(
65 65
 			'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
66
-			array( 'EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method' ),
66
+			array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'),
67 67
 			10,
68 68
 			1
69 69
 		);
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	 * @throws \EE_Error
78 78
 	 */
79 79
 	public static function switch_spco_billing_form() {
80
-		EED_Single_Page_Checkout::process_ajax_request( 'switch_payment_method' );
80
+		EED_Single_Page_Checkout::process_ajax_request('switch_payment_method');
81 81
 	}
82 82
 
83 83
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 * @throws \EE_Error
89 89
 	 */
90 90
 	public static function save_payer_details() {
91
-		EED_Single_Page_Checkout::process_ajax_request( 'save_payer_details_via_ajax' );
91
+		EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax');
92 92
 	}
93 93
 
94 94
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 * @throws \EE_Error
100 100
 	 */
101 101
 	public static function get_transaction_details() {
102
-		EED_Single_Page_Checkout::process_ajax_request( 'get_transaction_details_for_gateways' );
102
+		EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways');
103 103
 	}
104 104
 
105 105
 
@@ -126,10 +126,10 @@  discard block
 block discarded – undo
126 126
 	 * @access    public
127 127
 	 * @param    EE_Checkout $checkout
128 128
 	 */
129
-	public function __construct( EE_Checkout $checkout ) {
129
+	public function __construct(EE_Checkout $checkout) {
130 130
 		$this->_slug = 'payment_options';
131
-		$this->_name = __( 'Payment Options', 'event_espresso' );
132
-		$this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php';
131
+		$this->_name = __('Payment Options', 'event_espresso');
132
+		$this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'payment_options_main.template.php';
133 133
 		$this->checkout = $checkout;
134 134
 		$this->_reset_success_message();
135 135
 		$this->set_instructions(
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	/**
155 155
 	 * @param null $line_item_display
156 156
 	 */
157
-	public function set_line_item_display( $line_item_display ) {
157
+	public function set_line_item_display($line_item_display) {
158 158
 		$this->line_item_display = $line_item_display;
159 159
 	}
160 160
 
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
 	/**
173 173
 	 * @param boolean $handle_IPN_in_this_request
174 174
 	 */
175
-	public function set_handle_IPN_in_this_request( $handle_IPN_in_this_request ) {
176
-		$this->handle_IPN_in_this_request = filter_var( $handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN );
175
+	public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) {
176
+		$this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN);
177 177
 	}
178 178
 
179 179
 
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
 	public function enqueue_styles_and_scripts() {
209 209
 		$transaction = $this->checkout->transaction;
210 210
 		//if the transaction isn't set or nothing is owed on it, don't enqueue any JS
211
-		if( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats( $transaction->remaining(), 0 ) ) {
211
+		if ( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) {
212 212
 			return;
213 213
 		}
214
-		foreach( EEM_Payment_Method::instance()->get_all_for_transaction( $transaction, EEM_Payment_Method::scope_cart ) as $payment_method ) {
214
+		foreach (EEM_Payment_Method::instance()->get_all_for_transaction($transaction, EEM_Payment_Method::scope_cart) as $payment_method) {
215 215
 			$type_obj = $payment_method->type_obj();
216
-			if( $type_obj instanceof EE_PMT_Base ) {
217
-				$billing_form = $type_obj->generate_new_billing_form( $transaction );
218
-				if( $billing_form instanceof EE_Form_Section_Proper ) {
216
+			if ($type_obj instanceof EE_PMT_Base) {
217
+				$billing_form = $type_obj->generate_new_billing_form($transaction);
218
+				if ($billing_form instanceof EE_Form_Section_Proper) {
219 219
 					$billing_form->enqueue_js();
220 220
 				}
221 221
 			}
@@ -240,20 +240,20 @@  discard block
 block discarded – undo
240 240
 			// 	$ 0.00 transactions (no payment required)
241 241
 			! $this->checkout->payment_required()
242 242
 			// but do NOT remove if current action being called belongs to this reg step
243
-			&& ! is_callable( array( $this, $this->checkout->action ) )
243
+			&& ! is_callable(array($this, $this->checkout->action))
244 244
 			&& ! $this->completed()
245 245
 		) {
246 246
 			// and if so, then we no longer need the Payment Options step
247
-			if ( $this->is_current_step() ) {
247
+			if ($this->is_current_step()) {
248 248
 				$this->checkout->generate_reg_form = false;
249 249
 			}
250
-			$this->checkout->remove_reg_step( $this->_slug );
250
+			$this->checkout->remove_reg_step($this->_slug);
251 251
 			// DEBUG LOG
252 252
 			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
253 253
 			return false;
254 254
 		}
255 255
 		// load EEM_Payment_Method
256
-		EE_Registry::instance()->load_model( 'Payment_Method' );
256
+		EE_Registry::instance()->load_model('Payment_Method');
257 257
 		// get all active payment methods
258 258
 		$this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
259 259
 			$this->checkout->transaction,
@@ -280,16 +280,16 @@  discard block
 block discarded – undo
280 280
 		$insufficient_spaces_available = array();
281 281
 		$no_payment_required = true;
282 282
 		// loop thru registrations to gather info
283
-		$registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params );
283
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
284 284
 		$ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
285 285
 			$registrations,
286 286
 			$this->checkout->revisit
287 287
 		);
288
-		foreach ( $registrations as $REG_ID => $registration ) {
288
+		foreach ($registrations as $REG_ID => $registration) {
289 289
             /** @var $registration EE_Registration */
290 290
             // has this registration lost it's space ?
291
-			if ( isset( $ejected_registrations[ $REG_ID ] ) ) {
292
-				$insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event();
291
+			if (isset($ejected_registrations[$REG_ID])) {
292
+				$insufficient_spaces_available[$registration->event()->ID()] = $registration->event();
293 293
 				continue;
294 294
 			}
295 295
             // event requires admin approval
@@ -310,11 +310,11 @@  discard block
 block discarded – undo
310 310
 				&& $registration->status_ID() !== EEM_Registration::status_id_approved
311 311
                 && (
312 312
                     $registration->event()->is_sold_out()
313
-                    || $registration->event()->is_sold_out( true )
313
+                    || $registration->event()->is_sold_out(true)
314 314
                 )
315 315
             ) {
316 316
                 // add event to list of events that are sold out
317
-                $sold_out_events[ $registration->event()->ID() ] = $registration->event();
317
+                $sold_out_events[$registration->event()->ID()] = $registration->event();
318 318
                 do_action(
319 319
                     'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
320 320
                     $registration->event(),
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
                 continue;
324 324
 			}
325 325
 			// are they allowed to pay now and is there monies owing?
326
-			if ( $registration->owes_monies_and_can_pay() ) {
327
-				$registrations_requiring_payment[ $REG_ID ] = $registration;
326
+			if ($registration->owes_monies_and_can_pay()) {
327
+				$registrations_requiring_payment[$REG_ID] = $registration;
328 328
 				do_action(
329 329
 					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment',
330 330
 					$registration->event(),
@@ -335,29 +335,29 @@  discard block
 block discarded – undo
335 335
 				&& $registration->status_ID() !== EEM_Registration::status_id_not_approved
336 336
 				&& $registration->ticket()->is_free()
337 337
 			) {
338
-				$registrations_for_free_events[ $registration->event()->ID() ] = $registration;
338
+				$registrations_for_free_events[$registration->event()->ID()] = $registration;
339 339
 			}
340 340
 		}
341 341
 		$subsections = array();
342 342
 		// now decide which template to load
343
-		if ( ! empty( $sold_out_events ) ) {
344
-			$subsections['sold_out_events'] = $this->_sold_out_events( $sold_out_events );
343
+		if ( ! empty($sold_out_events)) {
344
+			$subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events);
345 345
 		}
346
-		if ( ! empty( $insufficient_spaces_available ) ) {
346
+		if ( ! empty($insufficient_spaces_available)) {
347 347
 			$subsections['insufficient_space'] = $this->_insufficient_spaces_available(
348 348
 				$insufficient_spaces_available
349 349
 			);
350 350
 		}
351
-		if ( ! empty( $registrations_requiring_pre_approval ) ) {
351
+		if ( ! empty($registrations_requiring_pre_approval)) {
352 352
 			$subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval(
353 353
 				$registrations_requiring_pre_approval
354 354
 			);
355 355
 		}
356
-		if ( ! empty( $registrations_for_free_events ) ) {
357
-			$subsections['no_payment_required'] = $this->_no_payment_required( $registrations_for_free_events );
356
+		if ( ! empty($registrations_for_free_events)) {
357
+			$subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events);
358 358
 		}
359
-		if ( ! empty( $registrations_requiring_payment ) ) {
360
-			if ( $this->checkout->amount_owing > 0 ) {
359
+		if ( ! empty($registrations_requiring_payment)) {
360
+			if ($this->checkout->amount_owing > 0) {
361 361
 				// autoload Line_Item_Display classes
362 362
 				EEH_Autoloader::register_line_item_filter_autoloaders();
363 363
 				$line_item_filter_processor = new EE_Line_Item_Filter_Processor(
@@ -370,15 +370,15 @@  discard block
 block discarded – undo
370 370
 				/** @var EE_Line_Item $filtered_line_item_tree */
371 371
 				$filtered_line_item_tree = $line_item_filter_processor->process();
372 372
 				EEH_Autoloader::register_line_item_display_autoloaders();
373
-				$this->set_line_item_display( new EE_Line_Item_Display( 'spco' ) );
373
+				$this->set_line_item_display(new EE_Line_Item_Display('spco'));
374 374
 				$subsections['payment_options'] = $this->_display_payment_options(
375 375
 					$this->line_item_display->display_line_item(
376 376
 						$filtered_line_item_tree,
377
-						array( 'registrations' => $registrations )
377
+						array('registrations' => $registrations)
378 378
 					)
379 379
 				);
380 380
 				$this->checkout->amount_owing = $filtered_line_item_tree->total();
381
-				$this->_apply_registration_payments_to_amount_owing( $registrations );
381
+				$this->_apply_registration_payments_to_amount_owing($registrations);
382 382
 			}
383 383
 			$no_payment_required = false;
384 384
 		} else {
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 		$this->_save_selected_method_of_payment();
388 388
 
389 389
 		$subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs();
390
-		$subsections['extra_hidden_inputs' ] = $this->_extra_hidden_inputs( $no_payment_required );
390
+		$subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required);
391 391
 
392 392
 		return new EE_Form_Section_Proper(
393 393
 			array(
@@ -414,14 +414,14 @@  discard block
 block discarded – undo
414 414
 	 * @return \EE_Line_Item_Filter_Collection
415 415
 	 * @throws \EE_Error
416 416
 	 */
417
-	public static function add_spco_line_item_filters( EE_Line_Item_Filter_Collection $line_item_filter_collection ) {
418
-		if ( ! EE_Registry::instance()->SSN instanceof EE_Session ) {
417
+	public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) {
418
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
419 419
 			return $line_item_filter_collection;
420 420
 		}
421
-		if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout ) {
421
+		if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) {
422 422
 			return $line_item_filter_collection;
423 423
 		}
424
-		if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction ) {
424
+		if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) {
425 425
 			return $line_item_filter_collection;
426 426
 		}
427 427
 		$line_item_filter_collection->add(
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 				)
434 434
 			)
435 435
         );
436
-		$line_item_filter_collection->add( new EE_Non_Zero_Line_Item_Filter() );
436
+		$line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter());
437 437
 		return $line_item_filter_collection;
438 438
 	}
439 439
 
@@ -449,15 +449,15 @@  discard block
 block discarded – undo
449 449
 	 * @return \EE_Registration[]
450 450
 	 * @throws \EE_Error
451 451
 	 */
452
-	public static function remove_ejected_registrations( array $registrations ) {
452
+	public static function remove_ejected_registrations(array $registrations) {
453 453
 		$ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
454 454
 			$registrations,
455 455
 			EE_Registry::instance()->SSN->checkout()->revisit
456 456
 		);
457
-		foreach ( $registrations as $REG_ID => $registration ) {
457
+		foreach ($registrations as $REG_ID => $registration) {
458 458
 			// has this registration lost it's space ?
459
-			if ( isset( $ejected_registrations[ $REG_ID ] ) ) {
460
-				unset( $registrations[ $REG_ID ] );
459
+			if (isset($ejected_registrations[$REG_ID])) {
460
+				unset($registrations[$REG_ID]);
461 461
 				continue;
462 462
 			}
463 463
 		}
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	 * @return array
481 481
 	 * @throws \EE_Error
482 482
 	 */
483
-	public static function find_registrations_that_lost_their_space( array $registrations, $revisit = false ) {
483
+	public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) {
484 484
         // registrations per event
485 485
 		$event_reg_count = array();
486 486
 		// spaces left per event
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         $tickets_remaining = array();
490 490
         // registrations that have lost their space
491 491
 		$ejected_registrations = array();
492
-		foreach ( $registrations as $REG_ID => $registration ) {
492
+		foreach ($registrations as $REG_ID => $registration) {
493 493
             if (
494 494
                 $registration->status_ID() === EEM_Registration::status_id_approved
495 495
                 || apply_filters(
@@ -519,13 +519,13 @@  discard block
 block discarded – undo
519 519
 				$revisit
520 520
 				&& (
521 521
                     $tickets_remaining[$ticket->ID()] === 0
522
-				    || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ]
522
+				    || $event_reg_count[$EVT_ID] > $event_spaces_remaining[$EVT_ID]
523 523
                 )
524 524
 			) {
525
-				$ejected_registrations[ $REG_ID ] = $registration->event();
526
-				if ( $registration->status_ID() !== EEM_Registration::status_id_wait_list ) {
525
+				$ejected_registrations[$REG_ID] = $registration->event();
526
+				if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) {
527 527
 					/** @type EE_Registration_Processor $registration_processor */
528
-					$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
528
+					$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
529 529
 					// at this point, we should have enough details about the registrant to consider the registration NOT incomplete
530 530
 					$registration_processor->manually_update_registration_status(
531 531
 						$registration,
@@ -560,8 +560,8 @@  discard block
 block discarded – undo
560 560
 	 * @return void
561 561
 	 */
562 562
 	protected function _hide_reg_step_submit_button_if_revisit() {
563
-		if ( $this->checkout->revisit ) {
564
-			add_filter( 'FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string' );
563
+		if ($this->checkout->revisit) {
564
+			add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string');
565 565
 		}
566 566
 	}
567 567
 
@@ -575,13 +575,13 @@  discard block
 block discarded – undo
575 575
 	 * @return \EE_Form_Section_Proper
576 576
 	 * @throws \EE_Error
577 577
 	 */
578
-	private function _sold_out_events( $sold_out_events_array = array() ) {
578
+	private function _sold_out_events($sold_out_events_array = array()) {
579 579
 		// set some defaults
580 580
 		$this->checkout->selected_method_of_payment = 'events_sold_out';
581 581
 		$sold_out_events = '';
582
-		foreach ( $sold_out_events_array as $sold_out_event ) {
582
+		foreach ($sold_out_events_array as $sold_out_event) {
583 583
 			$sold_out_events .= EEH_HTML::li(
584
-				EEH_HTML::span( '  ' .$sold_out_event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text' )
584
+				EEH_HTML::span('  '.$sold_out_event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text')
585 585
 			);
586 586
 		}
587 587
 		return new EE_Form_Section_Proper(
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 								'sold_out_events_msg' => apply_filters(
600 600
 									'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg',
601 601
 									sprintf(
602
-										__( 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', 'event_espresso' ),
602
+										__('It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', 'event_espresso'),
603 603
 										'<strong>',
604 604
 										'</strong>',
605 605
 										'<br />'
@@ -624,14 +624,14 @@  discard block
 block discarded – undo
624 624
 	 * @return \EE_Form_Section_Proper
625 625
 	 * @throws \EE_Error
626 626
 	 */
627
-	private function _insufficient_spaces_available( $insufficient_spaces_events_array = array() ) {
627
+	private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) {
628 628
 		// set some defaults
629 629
 		$this->checkout->selected_method_of_payment = 'invoice';
630 630
 		$insufficient_space_events = '';
631
-		foreach ( $insufficient_spaces_events_array as $event ) {
632
-			if ( $event instanceof EE_Event ) {
631
+		foreach ($insufficient_spaces_events_array as $event) {
632
+			if ($event instanceof EE_Event) {
633 633
 				$insufficient_space_events .= EEH_HTML::li(
634
-					EEH_HTML::span( ' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text' )
634
+					EEH_HTML::span(' '.$event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text')
635 635
 				);
636 636
 			}
637 637
 		}
@@ -675,17 +675,17 @@  discard block
 block discarded – undo
675 675
 	 * @return \EE_Form_Section_Proper
676 676
 	 * @throws \EE_Error
677 677
 	 */
678
-	private function _registrations_requiring_pre_approval( $registrations_requiring_pre_approval = array() ) {
678
+	private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) {
679 679
 		$events_requiring_pre_approval = '';
680
-		foreach ( $registrations_requiring_pre_approval as $registration ) {
681
-			if ( $registration instanceof EE_Registration && $registration->event() instanceof EE_Event ) {
682
-				$events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li(
680
+		foreach ($registrations_requiring_pre_approval as $registration) {
681
+			if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) {
682
+				$events_requiring_pre_approval[$registration->event()->ID()] = EEH_HTML::li(
683 683
 					EEH_HTML::span(
684 684
 						'',
685 685
 						'',
686 686
 						'dashicons dashicons-marker ee-icon-size-16 orange-text'
687 687
 					)
688
-					. EEH_HTML::span( $registration->event()->name(), '', 'orange-text' )
688
+					. EEH_HTML::span($registration->event()->name(), '', 'orange-text')
689 689
 				);
690 690
 			}
691 691
 		}
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
 						'template_args'        => apply_filters(
701 701
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
702 702
 							array(
703
-								'events_requiring_pre_approval'     => implode( '', $events_requiring_pre_approval ),
703
+								'events_requiring_pre_approval'     => implode('', $events_requiring_pre_approval),
704 704
 								'events_requiring_pre_approval_msg' => apply_filters(
705 705
 									'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg',
706 706
 									__(
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 	 * @return \EE_Form_Section_Proper
726 726
 	 * @throws \EE_Error
727 727
 	 */
728
-	private function _no_payment_required( $registrations_for_free_events = array() ) {
728
+	private function _no_payment_required($registrations_for_free_events = array()) {
729 729
 		// set some defaults
730 730
 		$this->checkout->selected_method_of_payment = 'no_payment_required';
731 731
 		// generate no_payment_required form
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
 								'ticket_count'                  => array(),
746 746
 								'registrations_for_free_events' => $registrations_for_free_events,
747 747
 								'no_payment_required_msg'       => EEH_HTML::p(
748
-									__( 'This is a free event, so no billing will occur.', 'event_espresso' )
748
+									__('This is a free event, so no billing will occur.', 'event_espresso')
749 749
 								)
750 750
 							)
751 751
 						),
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
 	 * @return \EE_Form_Section_Proper
765 765
 	 * @throws \EE_Error
766 766
 	 */
767
-	private function _display_payment_options( $transaction_details = '' ) {
767
+	private function _display_payment_options($transaction_details = '') {
768 768
 		// has method_of_payment been set by no-js user?
769 769
 		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment();
770 770
 		// build payment options form
@@ -776,14 +776,14 @@  discard block
 block discarded – undo
776 776
 						'before_payment_options' => apply_filters(
777 777
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options',
778 778
 							new EE_Form_Section_Proper(
779
-								array( 'layout_strategy' => new EE_Div_Per_Section_Layout() )
779
+								array('layout_strategy' => new EE_Div_Per_Section_Layout())
780 780
 							)
781 781
 						),
782 782
 						'payment_options'        => $this->_setup_payment_options(),
783 783
 						'after_payment_options'  => apply_filters(
784 784
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options',
785 785
 							new EE_Form_Section_Proper(
786
-								array( 'layout_strategy' => new EE_Div_Per_Section_Layout() )
786
+								array('layout_strategy' => new EE_Div_Per_Section_Layout())
787 787
 							)
788 788
 						),
789 789
 					),
@@ -814,10 +814,10 @@  discard block
 block discarded – undo
814 814
 	 * @return \EE_Form_Section_Proper
815 815
 	 * @throws \EE_Error
816 816
 	 */
817
-	private function _extra_hidden_inputs( $no_payment_required = true ) {
817
+	private function _extra_hidden_inputs($no_payment_required = true) {
818 818
 		return new EE_Form_Section_Proper(
819 819
 			array(
820
-				'html_id'         => 'ee-' . $this->slug() . '-extra-hidden-inputs',
820
+				'html_id'         => 'ee-'.$this->slug().'-extra-hidden-inputs',
821 821
 				'layout_strategy' => new EE_Div_Per_Section_Layout(),
822 822
 				'subsections'     => array(
823 823
 					'spco_no_payment_required' => new EE_Hidden_Input(
@@ -849,16 +849,16 @@  discard block
 block discarded – undo
849 849
 	 * @access protected
850 850
 	 * @param array $registrations
851 851
 	 */
852
-	protected function _apply_registration_payments_to_amount_owing( array $registrations ) {
852
+	protected function _apply_registration_payments_to_amount_owing(array $registrations) {
853 853
 		$payments = array();
854
-		foreach ( $registrations as $registration ) {
855
-			if ( $registration instanceof EE_Registration && $registration->owes_monies_and_can_pay() ) {
854
+		foreach ($registrations as $registration) {
855
+			if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
856 856
 				$payments += $registration->registration_payments();
857 857
 			}
858 858
 		}
859
-		if ( ! empty( $payments ) ) {
860
-			foreach ( $payments as $payment ) {
861
-				if ( $payment instanceof EE_Registration_Payment ) {
859
+		if ( ! empty($payments)) {
860
+			foreach ($payments as $payment) {
861
+				if ($payment instanceof EE_Registration_Payment) {
862 862
 					$this->checkout->amount_owing -= $payment->amount();
863 863
 				}
864 864
 			}
@@ -874,11 +874,11 @@  discard block
 block discarded – undo
874 874
 	 * @param    bool $force_reset
875 875
 	 * @return    void
876 876
 	 */
877
-	private function _reset_selected_method_of_payment( $force_reset = false ) {
877
+	private function _reset_selected_method_of_payment($force_reset = false) {
878 878
 		$reset_payment_method = $force_reset
879 879
 			? true
880
-			: sanitize_text_field( EE_Registry::instance()->REQ->get( 'reset_payment_method', false ) );
881
-		if ( $reset_payment_method ) {
880
+			: sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false));
881
+		if ($reset_payment_method) {
882 882
 			$this->checkout->selected_method_of_payment = null;
883 883
 			$this->checkout->payment_method = null;
884 884
 			$this->checkout->billing_form = null;
@@ -897,12 +897,12 @@  discard block
 block discarded – undo
897 897
 	 * @param string $selected_method_of_payment
898 898
 	 * @return  void
899 899
 	 */
900
-	private function _save_selected_method_of_payment( $selected_method_of_payment = '' ) {
901
-		$selected_method_of_payment = ! empty( $selected_method_of_payment )
900
+	private function _save_selected_method_of_payment($selected_method_of_payment = '') {
901
+		$selected_method_of_payment = ! empty($selected_method_of_payment)
902 902
 			? $selected_method_of_payment
903 903
 			: $this->checkout->selected_method_of_payment;
904 904
 		EE_Registry::instance()->SSN->set_session_data(
905
-			array( 'selected_method_of_payment' => $selected_method_of_payment )
905
+			array('selected_method_of_payment' => $selected_method_of_payment)
906 906
 		);
907 907
 	}
908 908
 
@@ -918,19 +918,19 @@  discard block
 block discarded – undo
918 918
 		// load payment method classes
919 919
 		$this->checkout->available_payment_methods = $this->_get_available_payment_methods();
920 920
 		// switch up header depending on number of available payment methods
921
-		$payment_method_header = count( $this->checkout->available_payment_methods ) > 1
921
+		$payment_method_header = count($this->checkout->available_payment_methods) > 1
922 922
 			? apply_filters(
923 923
 				'FHEE__registration_page_payment_options__method_of_payment_hdr',
924
-				__( 'Please Select Your Method of Payment', 'event_espresso' )
924
+				__('Please Select Your Method of Payment', 'event_espresso')
925 925
 			)
926 926
 			: apply_filters(
927 927
 				'FHEE__registration_page_payment_options__method_of_payment_hdr',
928
-				__( 'Method of Payment', 'event_espresso' )
928
+				__('Method of Payment', 'event_espresso')
929 929
 			);
930 930
 		$available_payment_methods = array(
931 931
 			// display the "Payment Method" header
932 932
 			'payment_method_header' => new EE_Form_Section_HTML(
933
-				EEH_HTML::h4( $payment_method_header, 'method-of-payment-hdr' )
933
+				EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr')
934 934
 			)
935 935
 		);
936 936
 		// the list of actual payment methods ( invoice, paypal, etc ) in a  ( slug => HTML )  format
@@ -939,32 +939,32 @@  discard block
 block discarded – undo
939 939
 		// additional instructions to be displayed and hidden below payment methods (adding a clearing div to start)
940 940
 		$payment_methods_billing_info = array(
941 941
 			new EE_Form_Section_HTML(
942
-				EEH_HTML::div( '<br />', '', '', 'clear:both;' )
942
+				EEH_HTML::div('<br />', '', '', 'clear:both;')
943 943
 			)
944 944
 		);
945 945
 		// loop through payment methods
946
-		foreach ( $this->checkout->available_payment_methods as $payment_method ) {
947
-			if ( $payment_method instanceof EE_Payment_Method ) {
946
+		foreach ($this->checkout->available_payment_methods as $payment_method) {
947
+			if ($payment_method instanceof EE_Payment_Method) {
948 948
 				$payment_method_button = EEH_HTML::img(
949 949
 					$payment_method->button_url(),
950 950
 					$payment_method->name(),
951
-					'spco-payment-method-' . $payment_method->slug() . '-btn-img',
951
+					'spco-payment-method-'.$payment_method->slug().'-btn-img',
952 952
 					'spco-payment-method-btn-img'
953 953
 				);
954 954
 				// check if any payment methods are set as default
955 955
 				// if payment method is already selected OR nothing is selected and this payment method should be open_by_default
956 956
 				if (
957
-					( $this->checkout->selected_method_of_payment === $payment_method->slug() )
958
-					|| ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default() )
957
+					($this->checkout->selected_method_of_payment === $payment_method->slug())
958
+					|| ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default())
959 959
 				) {
960 960
 					$this->checkout->selected_method_of_payment = $payment_method->slug();
961 961
 					$this->_save_selected_method_of_payment();
962
-					$default_payment_method_option[ $payment_method->slug() ] = $payment_method_button;
962
+					$default_payment_method_option[$payment_method->slug()] = $payment_method_button;
963 963
 				} else {
964
-					$available_payment_method_options[ $payment_method->slug() ] = $payment_method_button;
964
+					$available_payment_method_options[$payment_method->slug()] = $payment_method_button;
965 965
 				}
966
-				$payment_methods_billing_info[ $payment_method->slug()
967
-				                               . '-info' ] = $this->_payment_method_billing_info(
966
+				$payment_methods_billing_info[$payment_method->slug()
967
+				                               . '-info'] = $this->_payment_method_billing_info(
968 968
 					$payment_method
969 969
 				);
970 970
 			}
@@ -994,12 +994,12 @@  discard block
 block discarded – undo
994 994
 	 * @return EE_Payment_Method[]
995 995
 	 */
996 996
 	protected function _get_available_payment_methods() {
997
-		if ( ! empty( $this->checkout->available_payment_methods ) ) {
997
+		if ( ! empty($this->checkout->available_payment_methods)) {
998 998
 			return $this->checkout->available_payment_methods;
999 999
 		}
1000 1000
 		$available_payment_methods = array();
1001 1001
 		// load EEM_Payment_Method
1002
-		EE_Registry::instance()->load_model( 'Payment_Method' );
1002
+		EE_Registry::instance()->load_model('Payment_Method');
1003 1003
 		/** @type EEM_Payment_Method $EEM_Payment_Method */
1004 1004
 		$EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method;
1005 1005
 		// get all active payment methods
@@ -1007,9 +1007,9 @@  discard block
 block discarded – undo
1007 1007
 			$this->checkout->transaction,
1008 1008
 			EEM_Payment_Method::scope_cart
1009 1009
 		);
1010
-		foreach ( $payment_methods as $payment_method ) {
1011
-			if ( $payment_method instanceof EE_Payment_Method ) {
1012
-				$available_payment_methods[ $payment_method->slug() ] = $payment_method;
1010
+		foreach ($payment_methods as $payment_method) {
1011
+			if ($payment_method instanceof EE_Payment_Method) {
1012
+				$available_payment_methods[$payment_method->slug()] = $payment_method;
1013 1013
 			}
1014 1014
 		}
1015 1015
 		return $available_payment_methods;
@@ -1024,14 +1024,14 @@  discard block
 block discarded – undo
1024 1024
 	 * @param    array $available_payment_method_options
1025 1025
 	 * @return    \EE_Form_Section_Proper
1026 1026
 	 */
1027
-	private function _available_payment_method_inputs( $available_payment_method_options = array() ) {
1027
+	private function _available_payment_method_inputs($available_payment_method_options = array()) {
1028 1028
 		// generate inputs
1029 1029
 		return new EE_Form_Section_Proper(
1030 1030
 			array(
1031 1031
 				'html_id'         => 'ee-available-payment-method-inputs',
1032 1032
 				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1033 1033
 				'subsections'     => array(
1034
-					'' => new EE_Radio_Button_Input (
1034
+					'' => new EE_Radio_Button_Input(
1035 1035
 						$available_payment_method_options,
1036 1036
 						array(
1037 1037
 							'html_name'          => 'selected_method_of_payment',
@@ -1056,28 +1056,28 @@  discard block
 block discarded – undo
1056 1056
 	 * @return    \EE_Form_Section_Proper
1057 1057
 	 * @throws \EE_Error
1058 1058
 	 */
1059
-	private function _payment_method_billing_info( EE_Payment_Method $payment_method ) {
1059
+	private function _payment_method_billing_info(EE_Payment_Method $payment_method) {
1060 1060
 		$currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug()
1061 1061
 			? true
1062 1062
 			: false;
1063 1063
 		// generate the billing form for payment method
1064 1064
 		$billing_form = $currently_selected
1065
-			? $this->_get_billing_form_for_payment_method( $payment_method )
1065
+			? $this->_get_billing_form_for_payment_method($payment_method)
1066 1066
 			: new EE_Form_Section_HTML();
1067 1067
 		$this->checkout->billing_form = $currently_selected
1068 1068
 			? $billing_form
1069 1069
 			: $this->checkout->billing_form;
1070 1070
 		// it's all in the details
1071 1071
 		$info_html = EEH_HTML::h3(
1072
-			__( 'Important information regarding your payment', 'event_espresso' ),
1072
+			__('Important information regarding your payment', 'event_espresso'),
1073 1073
 			'',
1074 1074
 			'spco-payment-method-hdr'
1075 1075
 		);
1076 1076
 		// add some info regarding the step, either from what's saved in the admin,
1077 1077
 		// or a default string depending on whether the PM has a billing form or not
1078
-		if ( $payment_method->description() ) {
1078
+		if ($payment_method->description()) {
1079 1079
 			$payment_method_info = $payment_method->description();
1080
-		} elseif ( $billing_form instanceof EE_Billing_Info_Form ) {
1080
+		} elseif ($billing_form instanceof EE_Billing_Info_Form) {
1081 1081
 			$payment_method_info = sprintf(
1082 1082
 				__(
1083 1083
 					'Please provide the following billing information, then click the "%1$s" button below in order to proceed.',
@@ -1087,7 +1087,7 @@  discard block
 block discarded – undo
1087 1087
 			);
1088 1088
 		} else {
1089 1089
 			$payment_method_info = sprintf(
1090
-				__( 'Please click the "%1$s" button below in order to proceed.', 'event_espresso' ),
1090
+				__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'),
1091 1091
 				$this->submit_button_text()
1092 1092
 			);
1093 1093
 		}
@@ -1101,13 +1101,13 @@  discard block
 block discarded – undo
1101 1101
 		);
1102 1102
 		return new EE_Form_Section_Proper(
1103 1103
 			array(
1104
-				'html_id'         => 'spco-payment-method-info-' . $payment_method->slug(),
1104
+				'html_id'         => 'spco-payment-method-info-'.$payment_method->slug(),
1105 1105
 				'html_class'      => 'spco-payment-method-info-dv',
1106 1106
 				// only display the selected or default PM
1107 1107
 				'html_style'      => $currently_selected ? '' : 'display:none;',
1108 1108
 				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1109 1109
 				'subsections'     => array(
1110
-					'info'         => new EE_Form_Section_HTML( $info_html ),
1110
+					'info'         => new EE_Form_Section_HTML($info_html),
1111 1111
 					'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML()
1112 1112
 				)
1113 1113
 			)
@@ -1125,15 +1125,15 @@  discard block
 block discarded – undo
1125 1125
 	 */
1126 1126
 	public function get_billing_form_html_for_payment_method() {
1127 1127
 		// how have they chosen to pay?
1128
-		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( true );
1128
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1129 1129
 		$this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment();
1130
-		if ( ! $this->checkout->payment_method instanceof EE_Payment_Method ) {
1130
+		if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) {
1131 1131
 			return false;
1132 1132
 		}
1133
-		if ( apply_filters(
1133
+		if (apply_filters(
1134 1134
 			'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1135 1135
 			false
1136
-		) ) {
1136
+		)) {
1137 1137
 			EE_Error::add_success(
1138 1138
 				apply_filters(
1139 1139
 					'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
@@ -1148,7 +1148,7 @@  discard block
 block discarded – undo
1148 1148
 			);
1149 1149
 		}
1150 1150
 		// now generate billing form for selected method of payment
1151
-		$payment_method_billing_form = $this->_get_billing_form_for_payment_method( $this->checkout->payment_method );
1151
+		$payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method);
1152 1152
 		// fill form with attendee info if applicable
1153 1153
 		if (
1154 1154
 			$payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form
@@ -1170,10 +1170,10 @@  discard block
 block discarded – undo
1170 1170
 		$billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper
1171 1171
 			? $payment_method_billing_form->get_html()
1172 1172
 			: '';
1173
-		$this->checkout->json_response->set_return_data( array( 'payment_method_info' => $billing_info ) );
1173
+		$this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info));
1174 1174
 		// localize validation rules for main form
1175 1175
 		$this->checkout->current_step->reg_form->localize_validation_rules();
1176
-		$this->checkout->json_response->add_validation_rules( EE_Form_Section_Proper::js_localization() );
1176
+		$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1177 1177
 		return true;
1178 1178
 	}
1179 1179
 
@@ -1187,18 +1187,18 @@  discard block
 block discarded – undo
1187 1187
 	 * @return \EE_Billing_Info_Form|\EE_Form_Section_HTML
1188 1188
 	 * @throws \EE_Error
1189 1189
 	 */
1190
-	private function _get_billing_form_for_payment_method( EE_Payment_Method $payment_method ) {
1190
+	private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) {
1191 1191
 		$billing_form = $payment_method->type_obj()->billing_form(
1192 1192
 			$this->checkout->transaction,
1193
-			array( 'amount_owing' => $this->checkout->amount_owing )
1193
+			array('amount_owing' => $this->checkout->amount_owing)
1194 1194
 		);
1195
-		if ( $billing_form instanceof EE_Billing_Info_Form ) {
1195
+		if ($billing_form instanceof EE_Billing_Info_Form) {
1196 1196
 			if (
1197 1197
 				apply_filters(
1198 1198
 					'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1199 1199
 					false
1200 1200
 				)
1201
-				&& EE_Registry::instance()->REQ->is_set( 'payment_method' )
1201
+				&& EE_Registry::instance()->REQ->is_set('payment_method')
1202 1202
 			) {
1203 1203
 				EE_Error::add_success(
1204 1204
 					apply_filters(
@@ -1240,15 +1240,15 @@  discard block
 block discarded – undo
1240 1240
 		$request_param = 'selected_method_of_payment'
1241 1241
 	) {
1242 1242
 		// is selected_method_of_payment set in the request ?
1243
-		$selected_method_of_payment = EE_Registry::instance()->REQ->get( $request_param, false );
1244
-		if ( $selected_method_of_payment ) {
1243
+		$selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false);
1244
+		if ($selected_method_of_payment) {
1245 1245
 			// sanitize it
1246
-			$selected_method_of_payment = is_array( $selected_method_of_payment )
1247
-				? array_shift( $selected_method_of_payment )
1246
+			$selected_method_of_payment = is_array($selected_method_of_payment)
1247
+				? array_shift($selected_method_of_payment)
1248 1248
 				: $selected_method_of_payment;
1249
-			$selected_method_of_payment = sanitize_text_field( $selected_method_of_payment );
1249
+			$selected_method_of_payment = sanitize_text_field($selected_method_of_payment);
1250 1250
 			// store it in the session so that it's available for all subsequent requests including AJAX
1251
-			$this->_save_selected_method_of_payment( $selected_method_of_payment );
1251
+			$this->_save_selected_method_of_payment($selected_method_of_payment);
1252 1252
 		} else {
1253 1253
 			// or is is set in the session ?
1254 1254
 			$selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data(
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
 			);
1257 1257
 		}
1258 1258
 		// do ya really really gotta have it?
1259
-		if ( empty( $selected_method_of_payment ) && $required ) {
1259
+		if (empty($selected_method_of_payment) && $required) {
1260 1260
 			EE_Error::add_error(
1261 1261
 				sprintf(
1262 1262
 					__(
@@ -1265,7 +1265,7 @@  discard block
 block discarded – undo
1265 1265
 					),
1266 1266
 					'<br/>',
1267 1267
 					'<br/>',
1268
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1268
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
1269 1269
 				),
1270 1270
 				__FILE__,
1271 1271
 				__FUNCTION__,
@@ -1292,13 +1292,13 @@  discard block
 block discarded – undo
1292 1292
 	 * @throws \EE_Error
1293 1293
 	 */
1294 1294
 	public function switch_payment_method() {
1295
-		if ( ! $this->_verify_payment_method_is_set() ) {
1295
+		if ( ! $this->_verify_payment_method_is_set()) {
1296 1296
 			return false;
1297 1297
 		}
1298
-		if ( apply_filters(
1298
+		if (apply_filters(
1299 1299
 			'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1300 1300
 			false
1301
-		) ) {
1301
+		)) {
1302 1302
 			EE_Error::add_success(
1303 1303
 				apply_filters(
1304 1304
 					'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
@@ -1313,7 +1313,7 @@  discard block
 block discarded – undo
1313 1313
 			);
1314 1314
 		}
1315 1315
 		// generate billing form for selected method of payment if it hasn't been done already
1316
-		if ( $this->checkout->payment_method->type_obj()->has_billing_form() ) {
1316
+		if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1317 1317
 			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1318 1318
 				$this->checkout->payment_method
1319 1319
 			);
@@ -1335,7 +1335,7 @@  discard block
 block discarded – undo
1335 1335
 			);
1336 1336
 		}
1337 1337
 		// and debug content
1338
-		if ( $this->checkout->billing_form instanceof EE_Billing_Info_Form
1338
+		if ($this->checkout->billing_form instanceof EE_Billing_Info_Form
1339 1339
 		     && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1340 1340
 		) {
1341 1341
 			$this->checkout->billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
@@ -1343,15 +1343,15 @@  discard block
 block discarded – undo
1343 1343
 			);
1344 1344
 		}
1345 1345
 		// get html and validation rules for form
1346
-		if ( $this->checkout->billing_form instanceof EE_Form_Section_Proper ) {
1346
+		if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) {
1347 1347
 			$this->checkout->json_response->set_return_data(
1348
-				array( 'payment_method_info' => $this->checkout->billing_form->get_html() )
1348
+				array('payment_method_info' => $this->checkout->billing_form->get_html())
1349 1349
 			);
1350 1350
 			// localize validation rules for main form
1351
-			$this->checkout->billing_form->localize_validation_rules( true );
1352
-			$this->checkout->json_response->add_validation_rules( EE_Form_Section_Proper::js_localization() );
1351
+			$this->checkout->billing_form->localize_validation_rules(true);
1352
+			$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1353 1353
 		} else {
1354
-			$this->checkout->json_response->set_return_data( array( 'payment_method_info' => '' ) );
1354
+			$this->checkout->json_response->set_return_data(array('payment_method_info' => ''));
1355 1355
 		}
1356 1356
 		//prevents advancement to next step
1357 1357
 		$this->checkout->continue_reg = false;
@@ -1368,18 +1368,18 @@  discard block
 block discarded – undo
1368 1368
 	 */
1369 1369
 	protected function _verify_payment_method_is_set() {
1370 1370
 		// generate billing form for selected method of payment if it hasn't been done already
1371
-		if ( empty( $this->checkout->selected_method_of_payment ) ) {
1371
+		if (empty($this->checkout->selected_method_of_payment)) {
1372 1372
 			// how have they chosen to pay?
1373
-			$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( true );
1373
+			$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1374 1374
 		} else {
1375 1375
 			// choose your own adventure based on method_of_payment
1376
-			switch ( $this->checkout->selected_method_of_payment ) {
1376
+			switch ($this->checkout->selected_method_of_payment) {
1377 1377
 				case 'events_sold_out' :
1378 1378
 					EE_Error::add_attention(
1379 1379
 						apply_filters(
1380 1380
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg',
1381
-							__( 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.',
1382
-								'event_espresso' )
1381
+							__('It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.',
1382
+								'event_espresso')
1383 1383
 						),
1384 1384
 						__FILE__, __FUNCTION__, __LINE__
1385 1385
 					);
@@ -1389,7 +1389,7 @@  discard block
 block discarded – undo
1389 1389
 					EE_Error::add_attention(
1390 1390
 						apply_filters(
1391 1391
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg',
1392
-							__( 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', 'event_espresso' )
1392
+							__('It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', 'event_espresso')
1393 1393
 						),
1394 1394
 						__FILE__, __FUNCTION__, __LINE__
1395 1395
 					);
@@ -1399,7 +1399,7 @@  discard block
 block discarded – undo
1399 1399
 					EE_Error::add_attention(
1400 1400
 						apply_filters(
1401 1401
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg',
1402
-							__( 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', 'event_espresso' )
1402
+							__('It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', 'event_espresso')
1403 1403
 						),
1404 1404
 						__FILE__, __FUNCTION__, __LINE__
1405 1405
 					);
@@ -1409,7 +1409,7 @@  discard block
 block discarded – undo
1409 1409
 			}
1410 1410
 		}
1411 1411
 		// verify payment method
1412
-		if ( ! $this->checkout->payment_method instanceof EE_Payment_Method ) {
1412
+		if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) {
1413 1413
 			// get payment method for selected method of payment
1414 1414
 			$this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment();
1415 1415
 		}
@@ -1428,25 +1428,25 @@  discard block
 block discarded – undo
1428 1428
 	 * @throws \EE_Error
1429 1429
 	 */
1430 1430
 	public function save_payer_details_via_ajax() {
1431
-		if ( ! $this->_verify_payment_method_is_set() ) {
1431
+		if ( ! $this->_verify_payment_method_is_set()) {
1432 1432
 			return;
1433 1433
 		}
1434 1434
 		// generate billing form for selected method of payment if it hasn't been done already
1435
-		if ( $this->checkout->payment_method->type_obj()->has_billing_form() ) {
1435
+		if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1436 1436
 			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1437 1437
 				$this->checkout->payment_method
1438 1438
 			);
1439 1439
 		}
1440 1440
 		// generate primary attendee from payer info if applicable
1441
-		if ( ! $this->checkout->transaction_has_primary_registrant() ) {
1441
+		if ( ! $this->checkout->transaction_has_primary_registrant()) {
1442 1442
 			$attendee = $this->_create_attendee_from_request_data();
1443
-			if ( $attendee instanceof EE_Attendee ) {
1444
-				foreach ( $this->checkout->transaction->registrations() as $registration ) {
1445
-					if ( $registration->is_primary_registrant() ) {
1443
+			if ($attendee instanceof EE_Attendee) {
1444
+				foreach ($this->checkout->transaction->registrations() as $registration) {
1445
+					if ($registration->is_primary_registrant()) {
1446 1446
 						$this->checkout->primary_attendee_obj = $attendee;
1447
-						$registration->_add_relation_to( $attendee, 'Attendee' );
1448
-						$registration->set_attendee_id( $attendee->ID() );
1449
-						$registration->update_cache_after_object_save( 'Attendee', $attendee );
1447
+						$registration->_add_relation_to($attendee, 'Attendee');
1448
+						$registration->set_attendee_id($attendee->ID());
1449
+						$registration->update_cache_after_object_save('Attendee', $attendee);
1450 1450
 					}
1451 1451
 				}
1452 1452
 			}
@@ -1464,50 +1464,50 @@  discard block
 block discarded – undo
1464 1464
 	 */
1465 1465
 	protected function _create_attendee_from_request_data() {
1466 1466
 		// get State ID
1467
-		$STA_ID = ! empty( $_REQUEST['state'] ) ? sanitize_text_field( $_REQUEST['state'] ) : '';
1468
-		if ( ! empty( $STA_ID ) ) {
1467
+		$STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : '';
1468
+		if ( ! empty($STA_ID)) {
1469 1469
 			// can we get state object from name ?
1470
-			EE_Registry::instance()->load_model( 'State' );
1471
-			$state = EEM_State::instance()->get_col( array( array( 'STA_name' => $STA_ID ), 'limit' => 1 ), 'STA_ID' );
1472
-			$STA_ID = is_array( $state ) && ! empty( $state ) ? reset( $state ) : $STA_ID;
1470
+			EE_Registry::instance()->load_model('State');
1471
+			$state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID');
1472
+			$STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID;
1473 1473
 		}
1474 1474
 		// get Country ISO
1475
-		$CNT_ISO = ! empty( $_REQUEST['country'] ) ? sanitize_text_field( $_REQUEST['country'] ) : '';
1476
-		if ( ! empty( $CNT_ISO ) ) {
1475
+		$CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : '';
1476
+		if ( ! empty($CNT_ISO)) {
1477 1477
 			// can we get country object from name ?
1478
-			EE_Registry::instance()->load_model( 'Country' );
1478
+			EE_Registry::instance()->load_model('Country');
1479 1479
 			$country = EEM_Country::instance()->get_col(
1480
-				array( array( 'CNT_name' => $CNT_ISO ), 'limit' => 1 ),
1480
+				array(array('CNT_name' => $CNT_ISO), 'limit' => 1),
1481 1481
 				'CNT_ISO'
1482 1482
 			);
1483
-			$CNT_ISO = is_array( $country ) && ! empty( $country ) ? reset( $country ) : $CNT_ISO;
1483
+			$CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO;
1484 1484
 		}
1485 1485
 		// grab attendee data
1486 1486
 		$attendee_data = array(
1487
-			'ATT_fname'    => ! empty( $_REQUEST['first_name'] ) ? sanitize_text_field( $_REQUEST['first_name'] ) : '',
1488
-			'ATT_lname'    => ! empty( $_REQUEST['last_name'] ) ? sanitize_text_field( $_REQUEST['last_name'] ) : '',
1489
-			'ATT_email'    => ! empty( $_REQUEST['email'] ) ? sanitize_email( $_REQUEST['email'] ) : '',
1490
-			'ATT_address'  => ! empty( $_REQUEST['address'] ) ? sanitize_text_field( $_REQUEST['address'] ) : '',
1491
-			'ATT_address2' => ! empty( $_REQUEST['address2'] ) ? sanitize_text_field( $_REQUEST['address2'] ) : '',
1492
-			'ATT_city'     => ! empty( $_REQUEST['city'] ) ? sanitize_text_field( $_REQUEST['city'] ) : '',
1487
+			'ATT_fname'    => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '',
1488
+			'ATT_lname'    => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '',
1489
+			'ATT_email'    => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '',
1490
+			'ATT_address'  => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '',
1491
+			'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '',
1492
+			'ATT_city'     => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '',
1493 1493
 			'STA_ID'       => $STA_ID,
1494 1494
 			'CNT_ISO'      => $CNT_ISO,
1495
-			'ATT_zip'      => ! empty( $_REQUEST['zip'] ) ? sanitize_text_field( $_REQUEST['zip'] ) : '',
1496
-			'ATT_phone'    => ! empty( $_REQUEST['phone'] ) ? sanitize_text_field( $_REQUEST['phone'] ) : '',
1495
+			'ATT_zip'      => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '',
1496
+			'ATT_phone'    => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '',
1497 1497
 		);
1498 1498
 		// validate the email address since it is the most important piece of info
1499
-		if ( empty( $attendee_data['ATT_email'] ) || $attendee_data['ATT_email'] !== $_REQUEST['email'] ) {
1499
+		if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) {
1500 1500
 			EE_Error::add_error(
1501
-				__( 'An invalid email address was submitted.', 'event_espresso' ),
1501
+				__('An invalid email address was submitted.', 'event_espresso'),
1502 1502
 				__FILE__,
1503 1503
 				__FUNCTION__,
1504 1504
 				__LINE__
1505 1505
 			);
1506 1506
 		}
1507 1507
 		// does this attendee already exist in the db ? we're searching using a combination of first name, last name, AND email address
1508
-		if ( ! empty( $attendee_data['ATT_fname'] )
1509
-		     && ! empty( $attendee_data['ATT_lname'] )
1510
-		     && ! empty( $attendee_data['ATT_email'] )
1508
+		if ( ! empty($attendee_data['ATT_fname'])
1509
+		     && ! empty($attendee_data['ATT_lname'])
1510
+		     && ! empty($attendee_data['ATT_email'])
1511 1511
 		) {
1512 1512
 			$existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee(
1513 1513
 				array(
@@ -1516,19 +1516,19 @@  discard block
 block discarded – undo
1516 1516
 					'ATT_email' => $attendee_data['ATT_email']
1517 1517
 				)
1518 1518
 			);
1519
-			if ( $existing_attendee instanceof EE_Attendee ) {
1519
+			if ($existing_attendee instanceof EE_Attendee) {
1520 1520
 				return $existing_attendee;
1521 1521
 			}
1522 1522
 		}
1523 1523
 		// no existing attendee? kk let's create a new one
1524 1524
 		// kinda lame, but we need a first and last name to create an attendee, so use the email address if those don't exist
1525
-		$attendee_data['ATT_fname'] = ! empty( $attendee_data['ATT_fname'] )
1525
+		$attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname'])
1526 1526
 			? $attendee_data['ATT_fname']
1527 1527
 			: $attendee_data['ATT_email'];
1528
-		$attendee_data['ATT_lname'] = ! empty( $attendee_data['ATT_lname'] )
1528
+		$attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname'])
1529 1529
 			? $attendee_data['ATT_lname']
1530 1530
 			: $attendee_data['ATT_email'];
1531
-		return EE_Attendee::new_instance( $attendee_data );
1531
+		return EE_Attendee::new_instance($attendee_data);
1532 1532
 	}
1533 1533
 
1534 1534
 
@@ -1546,26 +1546,26 @@  discard block
 block discarded – undo
1546 1546
 		// how have they chosen to pay?
1547 1547
 		$this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free()
1548 1548
 			? 'no_payment_required'
1549
-			: $this->_get_selected_method_of_payment( true );
1549
+			: $this->_get_selected_method_of_payment(true);
1550 1550
 		// choose your own adventure based on method_of_payment
1551
-		switch ( $this->checkout->selected_method_of_payment ) {
1551
+		switch ($this->checkout->selected_method_of_payment) {
1552 1552
 
1553 1553
 			case 'events_sold_out' :
1554 1554
 				$this->checkout->redirect = true;
1555 1555
 				$this->checkout->redirect_url = $this->checkout->cancel_page_url;
1556
-				$this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url );
1556
+				$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1557 1557
 				// mark this reg step as completed
1558 1558
 				$this->set_completed();
1559 1559
 				return false;
1560 1560
 				break;
1561 1561
 
1562 1562
 			case 'payments_closed' :
1563
-				if ( apply_filters(
1563
+				if (apply_filters(
1564 1564
 					'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success',
1565 1565
 					false
1566
-				) ) {
1566
+				)) {
1567 1567
 					EE_Error::add_success(
1568
-						__( 'no payment required at this time.', 'event_espresso' ),
1568
+						__('no payment required at this time.', 'event_espresso'),
1569 1569
 						__FILE__,
1570 1570
 						__FUNCTION__,
1571 1571
 						__LINE__
@@ -1577,12 +1577,12 @@  discard block
 block discarded – undo
1577 1577
 				break;
1578 1578
 
1579 1579
 			case 'no_payment_required' :
1580
-				if ( apply_filters(
1580
+				if (apply_filters(
1581 1581
 					'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success',
1582 1582
 					false
1583
-				) ) {
1583
+				)) {
1584 1584
 					EE_Error::add_success(
1585
-						__( 'no payment required.', 'event_espresso' ),
1585
+						__('no payment required.', 'event_espresso'),
1586 1586
 						__FILE__,
1587 1587
 						__FUNCTION__,
1588 1588
 						__LINE__
@@ -1602,15 +1602,15 @@  discard block
 block discarded – undo
1602 1602
 					EE_Registry::instance()->SSN->checkout()->revisit
1603 1603
 				);
1604 1604
 				// calculate difference between the two arrays
1605
-				$registrations = array_diff( $registrations, $ejected_registrations );
1606
-				if ( empty( $registrations ) ) {
1605
+				$registrations = array_diff($registrations, $ejected_registrations);
1606
+				if (empty($registrations)) {
1607 1607
 					$this->_redirect_because_event_sold_out();
1608 1608
 					return false;
1609 1609
 				}
1610 1610
 				$payment_successful = $this->_process_payment();
1611
-				if ( $payment_successful ) {
1611
+				if ($payment_successful) {
1612 1612
 					$this->checkout->continue_reg = true;
1613
-					$this->_maybe_set_completed( $this->checkout->payment_method );
1613
+					$this->_maybe_set_completed($this->checkout->payment_method);
1614 1614
 				} else {
1615 1615
 					$this->checkout->continue_reg = false;
1616 1616
 				}
@@ -1631,10 +1631,10 @@  discard block
 block discarded – undo
1631 1631
 		$this->checkout->continue_reg = false;
1632 1632
 		// set redirect URL
1633 1633
 		$this->checkout->redirect_url = add_query_arg(
1634
-			array( 'e_reg_url_link' => $this->checkout->reg_url_link ),
1634
+			array('e_reg_url_link' => $this->checkout->reg_url_link),
1635 1635
 			$this->checkout->current_step->reg_step_url()
1636 1636
 		);
1637
-		$this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url );
1637
+		$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1638 1638
 	}
1639 1639
 
1640 1640
 
@@ -1647,8 +1647,8 @@  discard block
 block discarded – undo
1647 1647
 	 * @return void
1648 1648
 	 * @throws \EE_Error
1649 1649
 	 */
1650
-	protected function _maybe_set_completed( EE_Payment_Method $payment_method ) {
1651
-		switch ( $payment_method->type_obj()->payment_occurs() ) {
1650
+	protected function _maybe_set_completed(EE_Payment_Method $payment_method) {
1651
+		switch ($payment_method->type_obj()->payment_occurs()) {
1652 1652
 			case EE_PMT_Base::offsite :
1653 1653
 				break;
1654 1654
 			case EE_PMT_Base::onsite :
@@ -1671,7 +1671,7 @@  discard block
 block discarded – undo
1671 1671
 	public function update_reg_step() {
1672 1672
 		$success = true;
1673 1673
 		// if payment required
1674
-		if ( $this->checkout->transaction->total() > 0 ) {
1674
+		if ($this->checkout->transaction->total() > 0) {
1675 1675
 			do_action(
1676 1676
 				'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway',
1677 1677
 				$this->checkout->transaction
@@ -1679,13 +1679,13 @@  discard block
 block discarded – undo
1679 1679
 			// attempt payment via payment method
1680 1680
 			$success = $this->process_reg_step();
1681 1681
 		}
1682
-		if ( $success && ! $this->checkout->redirect ) {
1682
+		if ($success && ! $this->checkout->redirect) {
1683 1683
 			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn(
1684 1684
 				$this->checkout->transaction->ID()
1685 1685
 			);
1686 1686
 			// set return URL
1687 1687
 			$this->checkout->redirect_url = add_query_arg(
1688
-				array( 'e_reg_url_link' => $this->checkout->reg_url_link ),
1688
+				array('e_reg_url_link' => $this->checkout->reg_url_link),
1689 1689
 				$this->checkout->thank_you_page_url
1690 1690
 			);
1691 1691
 		}
@@ -1703,36 +1703,36 @@  discard block
 block discarded – undo
1703 1703
 	 */
1704 1704
 	private function _process_payment() {
1705 1705
 		// basically confirm that the event hasn't sold out since they hit the page
1706
-		if ( ! $this->_last_second_ticket_verifications() ) {
1706
+		if ( ! $this->_last_second_ticket_verifications()) {
1707 1707
 			return false;
1708 1708
 		}
1709 1709
 		// ya gotta make a choice man
1710
-		if ( empty( $this->checkout->selected_method_of_payment ) ) {
1710
+		if (empty($this->checkout->selected_method_of_payment)) {
1711 1711
 			$this->checkout->json_response->set_plz_select_method_of_payment(
1712
-				__( 'Please select a method of payment before proceeding.', 'event_espresso' )
1712
+				__('Please select a method of payment before proceeding.', 'event_espresso')
1713 1713
 			);
1714 1714
 			return false;
1715 1715
 		}
1716 1716
 		// get EE_Payment_Method object
1717
-		if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() ) {
1717
+		if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
1718 1718
 			return false;
1719 1719
 		}
1720 1720
 		// setup billing form
1721
-		if ( $this->checkout->payment_method->is_on_site() ) {
1721
+		if ($this->checkout->payment_method->is_on_site()) {
1722 1722
 			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1723 1723
 				$this->checkout->payment_method
1724 1724
 			);
1725 1725
 			// bad billing form ?
1726
-			if ( ! $this->_billing_form_is_valid() ) {
1726
+			if ( ! $this->_billing_form_is_valid()) {
1727 1727
 				return false;
1728 1728
 			}
1729 1729
 		}
1730 1730
 		// ensure primary registrant has been fully processed
1731
-		if ( ! $this->_setup_primary_registrant_prior_to_payment() ) {
1731
+		if ( ! $this->_setup_primary_registrant_prior_to_payment()) {
1732 1732
 			return false;
1733 1733
 		}
1734 1734
 		// if session is close to expiring (under 10 minutes by default)
1735
-		if ( ( time() - EE_Registry::instance()->SSN->expiration() ) < EE_Registry::instance()->SSN->extension() ) {
1735
+		if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) {
1736 1736
 			// add some time to session expiration so that payment can be completed
1737 1737
 			EE_Registry::instance()->SSN->extend_expiration();
1738 1738
 		}
@@ -1741,12 +1741,12 @@  discard block
 block discarded – undo
1741 1741
 		// in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations for events with a default reg status of Approved
1742 1742
 		//$transaction_processor->toggle_registration_statuses_for_default_approved_events( $this->checkout->transaction, $this->checkout->reg_cache_where_params );
1743 1743
 		// attempt payment
1744
-		$payment = $this->_attempt_payment( $this->checkout->payment_method );
1744
+		$payment = $this->_attempt_payment($this->checkout->payment_method);
1745 1745
 		// process results
1746
-		$payment = $this->_validate_payment( $payment );
1747
-		$payment = $this->_post_payment_processing( $payment );
1746
+		$payment = $this->_validate_payment($payment);
1747
+		$payment = $this->_post_payment_processing($payment);
1748 1748
 		// verify payment
1749
-		if ( $payment instanceof EE_Payment ) {
1749
+		if ($payment instanceof EE_Payment) {
1750 1750
 			// store that for later
1751 1751
 			$this->checkout->payment = $payment;
1752 1752
 			// we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned
@@ -1760,7 +1760,7 @@  discard block
 block discarded – undo
1760 1760
 			} else {
1761 1761
 				return false;
1762 1762
 			}
1763
-		} else if ( $payment === true ) {
1763
+		} else if ($payment === true) {
1764 1764
 			// please note that offline payment methods will NOT make a payment,
1765 1765
 			// but instead just mark themselves as the PMD_ID on the transaction, and return true
1766 1766
 			$this->checkout->payment = $payment;
@@ -1780,22 +1780,22 @@  discard block
 block discarded – undo
1780 1780
 	 */
1781 1781
 	protected function _last_second_ticket_verifications() {
1782 1782
 		// don't bother re-validating if not a return visit
1783
-		if ( ! $this->checkout->revisit ) {
1783
+		if ( ! $this->checkout->revisit) {
1784 1784
 			return true;
1785 1785
 		}
1786 1786
 		$registrations = $this->checkout->transaction->registrations();
1787
-		if ( empty( $registrations ) ) {
1787
+		if (empty($registrations)) {
1788 1788
 			return false;
1789 1789
 		}
1790
-		foreach ( $registrations as $registration ) {
1791
-			if ( $registration instanceof EE_Registration ) {
1790
+		foreach ($registrations as $registration) {
1791
+			if ($registration instanceof EE_Registration) {
1792 1792
 				$event = $registration->event_obj();
1793
-				if ( $event instanceof EE_Event && $event->is_sold_out( true ) ) {
1793
+				if ($event instanceof EE_Event && $event->is_sold_out(true)) {
1794 1794
 					EE_Error::add_error(
1795 1795
 						apply_filters(
1796 1796
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg',
1797 1797
 							sprintf(
1798
-								__( 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', 'event_espresso' ),
1798
+								__('It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', 'event_espresso'),
1799 1799
 								$event->name()
1800 1800
 							)
1801 1801
 						),
@@ -1825,7 +1825,7 @@  discard block
 block discarded – undo
1825 1825
 		);
1826 1826
 		$html = $payment_method_billing_info->get_html();
1827 1827
 		$html .= $this->checkout->redirect_form;
1828
-		EE_Registry::instance()->REQ->add_output( $html );
1828
+		EE_Registry::instance()->REQ->add_output($html);
1829 1829
 		return true;
1830 1830
 	}
1831 1831
 
@@ -1839,28 +1839,28 @@  discard block
 block discarded – undo
1839 1839
 	 * @throws \EE_Error
1840 1840
 	 */
1841 1841
 	private function _billing_form_is_valid() {
1842
-		if ( ! $this->checkout->payment_method->type_obj()->has_billing_form() ) {
1842
+		if ( ! $this->checkout->payment_method->type_obj()->has_billing_form()) {
1843 1843
 			return true;
1844 1844
 		}
1845
-		if ( $this->checkout->billing_form instanceof EE_Billing_Info_Form ) {
1846
-			if ( $this->checkout->billing_form->was_submitted() ) {
1845
+		if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) {
1846
+			if ($this->checkout->billing_form->was_submitted()) {
1847 1847
 				$this->checkout->billing_form->receive_form_submission();
1848
-				if ( $this->checkout->billing_form->is_valid() ) {
1848
+				if ($this->checkout->billing_form->is_valid()) {
1849 1849
 					return true;
1850 1850
 				}
1851 1851
 				$validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated();
1852 1852
 				$error_strings = array();
1853
-				foreach ( $validation_errors as $validation_error ) {
1854
-					if ( $validation_error instanceof EE_Validation_Error ) {
1853
+				foreach ($validation_errors as $validation_error) {
1854
+					if ($validation_error instanceof EE_Validation_Error) {
1855 1855
 						$form_section = $validation_error->get_form_section();
1856
-						if ( $form_section instanceof EE_Form_Input_Base ) {
1856
+						if ($form_section instanceof EE_Form_Input_Base) {
1857 1857
 							$label = $form_section->html_label_text();
1858
-						} elseif ( $form_section instanceof EE_Form_Section_Base ) {
1858
+						} elseif ($form_section instanceof EE_Form_Section_Base) {
1859 1859
 							$label = $form_section->name();
1860 1860
 						} else {
1861
-							$label = __( 'Validation Error', 'event_espresso' );
1861
+							$label = __('Validation Error', 'event_espresso');
1862 1862
 						}
1863
-						$error_strings[] = sprintf( '%1$s: %2$s', $label, $validation_error->getMessage() );
1863
+						$error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage());
1864 1864
 					}
1865 1865
 				}
1866 1866
 				EE_Error::add_error(
@@ -1870,7 +1870,7 @@  discard block
 block discarded – undo
1870 1870
 							'event_espresso'
1871 1871
 						),
1872 1872
 						'<br/>',
1873
-						implode( '<br/>', $error_strings )
1873
+						implode('<br/>', $error_strings)
1874 1874
 					),
1875 1875
 					__FILE__,
1876 1876
 					__FUNCTION__,
@@ -1889,7 +1889,7 @@  discard block
 block discarded – undo
1889 1889
 			}
1890 1890
 		} else {
1891 1891
 			EE_Error::add_error(
1892
-				__( 'The submitted billing form is invalid possibly due to a technical reason.', 'event_espresso' ),
1892
+				__('The submitted billing form is invalid possibly due to a technical reason.', 'event_espresso'),
1893 1893
 				__FILE__,
1894 1894
 				__FUNCTION__,
1895 1895
 				__LINE__
@@ -1928,7 +1928,7 @@  discard block
 block discarded – undo
1928 1928
 		// save the TXN ( which clears cached copy of primary_registration)
1929 1929
 		$this->checkout->transaction->save();
1930 1930
 		// grab TXN ID and save it to the primary_registration
1931
-		$primary_registration->set_transaction_id( $this->checkout->transaction->ID() );
1931
+		$primary_registration->set_transaction_id($this->checkout->transaction->ID());
1932 1932
 		// save what we have so far
1933 1933
 		$primary_registration->save();
1934 1934
 		return true;
@@ -1946,7 +1946,7 @@  discard block
 block discarded – undo
1946 1946
 	private function _capture_primary_registration_data_from_billing_form() {
1947 1947
 		// convert billing form data into an attendee
1948 1948
 		$this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data();
1949
-		if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee ) {
1949
+		if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee) {
1950 1950
 			EE_Error::add_error(
1951 1951
 				sprintf(
1952 1952
 					__(
@@ -1954,7 +1954,7 @@  discard block
 block discarded – undo
1954 1954
 						'event_espresso'
1955 1955
 					),
1956 1956
 					'<br/>',
1957
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1957
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
1958 1958
 				),
1959 1959
 				__FILE__,
1960 1960
 				__FUNCTION__,
@@ -1963,7 +1963,7 @@  discard block
 block discarded – undo
1963 1963
 			return false;
1964 1964
 		}
1965 1965
 		$primary_registration = $this->checkout->transaction->primary_registration();
1966
-		if ( ! $primary_registration instanceof EE_Registration ) {
1966
+		if ( ! $primary_registration instanceof EE_Registration) {
1967 1967
 			EE_Error::add_error(
1968 1968
 				sprintf(
1969 1969
 					__(
@@ -1971,7 +1971,7 @@  discard block
 block discarded – undo
1971 1971
 						'event_espresso'
1972 1972
 					),
1973 1973
 					'<br/>',
1974
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1974
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
1975 1975
 				),
1976 1976
 				__FILE__,
1977 1977
 				__FUNCTION__,
@@ -1979,7 +1979,7 @@  discard block
 block discarded – undo
1979 1979
 			);
1980 1980
 			return false;
1981 1981
 		}
1982
-		if ( ! $primary_registration->_add_relation_to( $this->checkout->primary_attendee_obj, 'Attendee' )
1982
+		if ( ! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee')
1983 1983
 		       instanceof
1984 1984
 		       EE_Attendee
1985 1985
 		) {
@@ -1990,7 +1990,7 @@  discard block
 block discarded – undo
1990 1990
 						'event_espresso'
1991 1991
 					),
1992 1992
 					'<br/>',
1993
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1993
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
1994 1994
 				),
1995 1995
 				__FILE__,
1996 1996
 				__FUNCTION__,
@@ -1999,9 +1999,9 @@  discard block
 block discarded – undo
1999 1999
 			return false;
2000 2000
 		}
2001 2001
 		/** @type EE_Registration_Processor $registration_processor */
2002
-		$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
2002
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
2003 2003
 		// at this point, we should have enough details about the registrant to consider the registration NOT incomplete
2004
-		$registration_processor->toggle_incomplete_registration_status_to_default( $primary_registration );
2004
+		$registration_processor->toggle_incomplete_registration_status_to_default($primary_registration);
2005 2005
 		return true;
2006 2006
 	}
2007 2007
 
@@ -2016,22 +2016,22 @@  discard block
 block discarded – undo
2016 2016
 	 * @throws \EE_Error
2017 2017
 	 */
2018 2018
 	private function _get_payment_method_for_selected_method_of_payment() {
2019
-		if ( $this->checkout->selected_method_of_payment === 'events_sold_out' ) {
2019
+		if ($this->checkout->selected_method_of_payment === 'events_sold_out') {
2020 2020
 			$this->_redirect_because_event_sold_out();
2021 2021
 			return null;
2022 2022
 		}
2023 2023
 		// get EE_Payment_Method object
2024
-		if ( isset( $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ] ) ) {
2025
-			$payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ];
2024
+		if (isset($this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment])) {
2025
+			$payment_method = $this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment];
2026 2026
 		} else {
2027 2027
 			// load EEM_Payment_Method
2028
-			EE_Registry::instance()->load_model( 'Payment_Method' );
2028
+			EE_Registry::instance()->load_model('Payment_Method');
2029 2029
 			/** @type EEM_Payment_Method $EEM_Payment_Method */
2030 2030
 			$EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method;
2031
-			$payment_method = $EEM_Payment_Method->get_one_by_slug( $this->checkout->selected_method_of_payment );
2031
+			$payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment);
2032 2032
 		}
2033 2033
 		// verify $payment_method
2034
-		if ( ! $payment_method instanceof EE_Payment_Method ) {
2034
+		if ( ! $payment_method instanceof EE_Payment_Method) {
2035 2035
 			// not a payment
2036 2036
 			EE_Error::add_error(
2037 2037
 				sprintf(
@@ -2040,7 +2040,7 @@  discard block
 block discarded – undo
2040 2040
 						'event_espresso'
2041 2041
 					),
2042 2042
 					'<br/>',
2043
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
2043
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2044 2044
 				),
2045 2045
 				__FILE__,
2046 2046
 				__FUNCTION__,
@@ -2049,7 +2049,7 @@  discard block
 block discarded – undo
2049 2049
 			return null;
2050 2050
 		}
2051 2051
 		// and verify it has a valid Payment_Method Type object
2052
-		if ( ! $payment_method->type_obj() instanceof EE_PMT_Base ) {
2052
+		if ( ! $payment_method->type_obj() instanceof EE_PMT_Base) {
2053 2053
 			// not a payment
2054 2054
 			EE_Error::add_error(
2055 2055
 				sprintf(
@@ -2058,7 +2058,7 @@  discard block
 block discarded – undo
2058 2058
 						'event_espresso'
2059 2059
 					),
2060 2060
 					'<br/>',
2061
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
2061
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2062 2062
 				),
2063 2063
 				__FILE__,
2064 2064
 				__FUNCTION__,
@@ -2079,29 +2079,29 @@  discard block
 block discarded – undo
2079 2079
 	 * @return    mixed    EE_Payment | boolean
2080 2080
 	 * @throws \EE_Error
2081 2081
 	 */
2082
-	private function _attempt_payment( EE_Payment_Method $payment_method ) {
2082
+	private function _attempt_payment(EE_Payment_Method $payment_method) {
2083 2083
 		$payment = null;
2084 2084
 		$this->checkout->transaction->save();
2085
-		$payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' );
2086
-		if ( ! $payment_processor instanceof EE_Payment_Processor ) {
2085
+		$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2086
+		if ( ! $payment_processor instanceof EE_Payment_Processor) {
2087 2087
 			return false;
2088 2088
 		}
2089 2089
 		try {
2090
-			$payment_processor->set_revisit( $this->checkout->revisit );
2090
+			$payment_processor->set_revisit($this->checkout->revisit);
2091 2091
 			// generate payment object
2092 2092
 			$payment = $payment_processor->process_payment(
2093 2093
 				$payment_method,
2094 2094
 				$this->checkout->transaction,
2095 2095
 				$this->checkout->amount_owing,
2096 2096
 				$this->checkout->billing_form,
2097
-				$this->_get_return_url( $payment_method ),
2097
+				$this->_get_return_url($payment_method),
2098 2098
 				'CART',
2099 2099
 				$this->checkout->admin_request,
2100 2100
 				true,
2101 2101
 				$this->reg_step_url()
2102 2102
 			);
2103
-		} catch ( Exception $e ) {
2104
-			$this->_handle_payment_processor_exception( $e );
2103
+		} catch (Exception $e) {
2104
+			$this->_handle_payment_processor_exception($e);
2105 2105
 		}
2106 2106
 		return $payment;
2107 2107
 	}
@@ -2116,7 +2116,7 @@  discard block
 block discarded – undo
2116 2116
 	 * @return void
2117 2117
 	 * @throws \EE_Error
2118 2118
 	 */
2119
-	protected function _handle_payment_processor_exception( Exception $e ) {
2119
+	protected function _handle_payment_processor_exception(Exception $e) {
2120 2120
 		EE_Error::add_error(
2121 2121
 			sprintf(
2122 2122
 				__(
@@ -2124,7 +2124,7 @@  discard block
 block discarded – undo
2124 2124
 					'event_espresso'
2125 2125
 				),
2126 2126
 				'<br/>',
2127
-				EE_Registry::instance()->CFG->organization->get_pretty( 'email' ),
2127
+				EE_Registry::instance()->CFG->organization->get_pretty('email'),
2128 2128
 				$e->getMessage(),
2129 2129
 				$e->getFile(),
2130 2130
 				$e->getLine()
@@ -2145,9 +2145,9 @@  discard block
 block discarded – undo
2145 2145
 	 * @return string
2146 2146
 	 * @throws \EE_Error
2147 2147
 	 */
2148
-	protected function _get_return_url( EE_Payment_Method $payment_method ) {
2148
+	protected function _get_return_url(EE_Payment_Method $payment_method) {
2149 2149
 		$return_url = '';
2150
-		switch ( $payment_method->type_obj()->payment_occurs() ) {
2150
+		switch ($payment_method->type_obj()->payment_occurs()) {
2151 2151
 			case EE_PMT_Base::offsite :
2152 2152
 				$return_url = add_query_arg(
2153 2153
 					array(
@@ -2176,12 +2176,12 @@  discard block
 block discarded – undo
2176 2176
 	 * @return EE_Payment | FALSE
2177 2177
 	 * @throws \EE_Error
2178 2178
 	 */
2179
-	private function _validate_payment( $payment = null ) {
2180
-		if ( $this->checkout->payment_method->is_off_line() ) {
2179
+	private function _validate_payment($payment = null) {
2180
+		if ($this->checkout->payment_method->is_off_line()) {
2181 2181
 			return true;
2182 2182
 		}
2183 2183
 		// verify payment object
2184
-		if ( ! $payment instanceof EE_Payment ) {
2184
+		if ( ! $payment instanceof EE_Payment) {
2185 2185
 			// not a payment
2186 2186
 			EE_Error::add_error(
2187 2187
 				sprintf(
@@ -2190,7 +2190,7 @@  discard block
 block discarded – undo
2190 2190
 						'event_espresso'
2191 2191
 					),
2192 2192
 					'<br/>',
2193
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
2193
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2194 2194
 				),
2195 2195
 				__FILE__,
2196 2196
 				__FUNCTION__,
@@ -2211,27 +2211,27 @@  discard block
 block discarded – undo
2211 2211
 	 * @return bool
2212 2212
 	 * @throws \EE_Error
2213 2213
 	 */
2214
-	private function _post_payment_processing( $payment = null ) {
2214
+	private function _post_payment_processing($payment = null) {
2215 2215
 		// Off-Line payment?
2216
-		if ( $payment === true ) {
2216
+		if ($payment === true) {
2217 2217
 			//$this->_setup_redirect_for_next_step();
2218 2218
 			return true;
2219 2219
 		// On-Site payment?
2220
-		} else if ( $this->checkout->payment_method->is_on_site() ) {
2221
-			if ( ! $this->_process_payment_status( $payment, EE_PMT_Base::onsite ) ) {
2220
+		} else if ($this->checkout->payment_method->is_on_site()) {
2221
+			if ( ! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) {
2222 2222
 				//$this->_setup_redirect_for_next_step();
2223 2223
 				$this->checkout->continue_reg = false;
2224 2224
 			}
2225 2225
 		// Off-Site payment?
2226
-		} else if ( $this->checkout->payment_method->is_off_site() ) {
2226
+		} else if ($this->checkout->payment_method->is_off_site()) {
2227 2227
 			// if a payment object was made and it specifies a redirect url, then we'll setup that redirect info
2228
-			if ( $payment instanceof EE_Payment && $payment->redirect_url() ) {
2229
-				do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()' );
2228
+			if ($payment instanceof EE_Payment && $payment->redirect_url()) {
2229
+				do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()');
2230 2230
 				$this->checkout->redirect = true;
2231 2231
 				$this->checkout->redirect_form = $payment->redirect_form();
2232
-				$this->checkout->redirect_url = $this->reg_step_url( 'redirect_form' );
2232
+				$this->checkout->redirect_url = $this->reg_step_url('redirect_form');
2233 2233
 				// set JSON response
2234
-				$this->checkout->json_response->set_redirect_form( $this->checkout->redirect_form );
2234
+				$this->checkout->json_response->set_redirect_form($this->checkout->redirect_form);
2235 2235
 				// set cron job for finalizing the TXN
2236 2236
 				// in case the user does not return from the off-site gateway
2237 2237
 				EE_Cron_Tasks::schedule_finalize_abandoned_transactions_check(
@@ -2239,7 +2239,7 @@  discard block
 block discarded – undo
2239 2239
 					$this->checkout->transaction->ID()
2240 2240
 				);
2241 2241
 				// and lastly, let's bump the payment status to pending
2242
-				$payment->set_status( EEM_Payment::status_id_pending );
2242
+				$payment->set_status(EEM_Payment::status_id_pending);
2243 2243
 				$payment->save();
2244 2244
 			} else {
2245 2245
 				// not a payment
@@ -2251,7 +2251,7 @@  discard block
 block discarded – undo
2251 2251
 							'event_espresso'
2252 2252
 						),
2253 2253
 						'<br/>',
2254
-						EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
2254
+						EE_Registry::instance()->CFG->organization->get_pretty('email')
2255 2255
 					),
2256 2256
 					__FILE__,
2257 2257
 					__FUNCTION__,
@@ -2289,21 +2289,21 @@  discard block
 block discarded – undo
2289 2289
 	 * @return bool
2290 2290
 	 * @throws \EE_Error
2291 2291
 	 */
2292
-	private function _process_payment_status( $payment, $payment_occurs = EE_PMT_Base::offline ) {
2292
+	private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) {
2293 2293
 		// off-line payment? carry on
2294
-		if ( $payment_occurs === EE_PMT_Base::offline ) {
2294
+		if ($payment_occurs === EE_PMT_Base::offline) {
2295 2295
 			return true;
2296 2296
 		}
2297 2297
 		// verify payment validity
2298
-		if ( $payment instanceof EE_Payment ) {
2299
-			do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()' );
2298
+		if ($payment instanceof EE_Payment) {
2299
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()');
2300 2300
 			$msg = $payment->gateway_response();
2301 2301
 			// check results
2302
-			switch ( $payment->status() ) {
2302
+			switch ($payment->status()) {
2303 2303
 				// good payment
2304 2304
 				case EEM_Payment::status_id_approved :
2305 2305
 					EE_Error::add_success(
2306
-						__( 'Your payment was processed successfully.', 'event_espresso' ),
2306
+						__('Your payment was processed successfully.', 'event_espresso'),
2307 2307
 						__FILE__,
2308 2308
 						__FUNCTION__,
2309 2309
 						__LINE__
@@ -2312,45 +2312,45 @@  discard block
 block discarded – undo
2312 2312
 					break;
2313 2313
 				// slow payment
2314 2314
 				case EEM_Payment::status_id_pending :
2315
-					if ( empty( $msg ) ) {
2315
+					if (empty($msg)) {
2316 2316
 						$msg = __(
2317 2317
 							'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.',
2318 2318
 							'event_espresso'
2319 2319
 						);
2320 2320
 					}
2321
-					EE_Error::add_success( $msg, __FILE__, __FUNCTION__, __LINE__ );
2321
+					EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__);
2322 2322
 					return true;
2323 2323
 					break;
2324 2324
 				// don't wanna payment
2325 2325
 				case EEM_Payment::status_id_cancelled :
2326
-					if ( empty( $msg ) ) {
2326
+					if (empty($msg)) {
2327 2327
 						$msg = _n(
2328 2328
 							'Payment cancelled. Please try again.',
2329 2329
 							'Payment cancelled. Please try again or select another method of payment.',
2330
-							count( $this->checkout->available_payment_methods ),
2330
+							count($this->checkout->available_payment_methods),
2331 2331
 							'event_espresso'
2332 2332
 						);
2333 2333
 					}
2334
-					EE_Error::add_attention( $msg, __FILE__, __FUNCTION__, __LINE__ );
2334
+					EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2335 2335
 					return false;
2336 2336
 					break;
2337 2337
 				// not enough payment
2338 2338
 				case EEM_Payment::status_id_declined :
2339
-					if ( empty( $msg ) ) {
2339
+					if (empty($msg)) {
2340 2340
 						$msg = _n(
2341 2341
 							'We\'re sorry but your payment was declined. Please try again.',
2342 2342
 							'We\'re sorry but your payment was declined. Please try again or select another method of payment.',
2343
-							count( $this->checkout->available_payment_methods ),
2343
+							count($this->checkout->available_payment_methods),
2344 2344
 							'event_espresso'
2345 2345
 						);
2346 2346
 					}
2347
-					EE_Error::add_attention( $msg, __FILE__, __FUNCTION__, __LINE__ );
2347
+					EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2348 2348
 					return false;
2349 2349
 					break;
2350 2350
 				// bad payment
2351 2351
 				case EEM_Payment::status_id_failed :
2352
-					if ( ! empty( $msg ) ) {
2353
-						EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
2352
+					if ( ! empty($msg)) {
2353
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2354 2354
 						return false;
2355 2355
 					}
2356 2356
 					// default to error below
@@ -2359,7 +2359,7 @@  discard block
 block discarded – undo
2359 2359
 		}
2360 2360
 		// off-site payment gateway responses are too unreliable, so let's just assume that
2361 2361
 		// the payment processing is just running slower than the registrant's request
2362
-		if ( $payment_occurs === EE_PMT_Base::offsite ) {
2362
+		if ($payment_occurs === EE_PMT_Base::offsite) {
2363 2363
 			return true;
2364 2364
 		}
2365 2365
 		EE_Error::add_error(
@@ -2369,7 +2369,7 @@  discard block
 block discarded – undo
2369 2369
 					'event_espresso'
2370 2370
 				),
2371 2371
 				'<br/>',
2372
-				EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
2372
+				EE_Registry::instance()->CFG->organization->get_pretty('email')
2373 2373
 			),
2374 2374
 			__FILE__,
2375 2375
 			__FUNCTION__,
@@ -2402,13 +2402,13 @@  discard block
 block discarded – undo
2402 2402
 	public function process_gateway_response() {
2403 2403
 		$payment = null;
2404 2404
 		// how have they chosen to pay?
2405
-		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( true );
2405
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
2406 2406
 		// get EE_Payment_Method object
2407
-		if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() ) {
2407
+		if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
2408 2408
 			$this->checkout->continue_reg = false;
2409 2409
 			return false;
2410 2410
 		}
2411
-		if ( ! $this->checkout->payment_method->is_off_site() ) {
2411
+		if ( ! $this->checkout->payment_method->is_off_site()) {
2412 2412
 			return false;
2413 2413
 		}
2414 2414
 		$this->_validate_offsite_return();
@@ -2422,23 +2422,23 @@  discard block
 block discarded – undo
2422 2422
 		//	true
2423 2423
 		//);
2424 2424
 		// verify TXN
2425
-		if ( $this->checkout->transaction instanceof EE_Transaction ) {
2425
+		if ($this->checkout->transaction instanceof EE_Transaction) {
2426 2426
 			$gateway = $this->checkout->payment_method->type_obj()->get_gateway();
2427
-			if ( ! $gateway instanceof EE_Offsite_Gateway ) {
2427
+			if ( ! $gateway instanceof EE_Offsite_Gateway) {
2428 2428
 				$this->checkout->continue_reg = false;
2429 2429
 				return false;
2430 2430
 			}
2431
-			$payment = $this->_process_off_site_payment( $gateway );
2432
-			$payment = $this->_process_cancelled_payments( $payment );
2433
-			$payment = $this->_validate_payment( $payment );
2431
+			$payment = $this->_process_off_site_payment($gateway);
2432
+			$payment = $this->_process_cancelled_payments($payment);
2433
+			$payment = $this->_validate_payment($payment);
2434 2434
 			// if payment was not declined by the payment gateway or cancelled by the registrant
2435
-			if ( $this->_process_payment_status( $payment, EE_PMT_Base::offsite ) ) {
2435
+			if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) {
2436 2436
 				//$this->_setup_redirect_for_next_step();
2437 2437
 				// store that for later
2438 2438
 				$this->checkout->payment = $payment;
2439 2439
 				// mark this reg step as completed, as long as gateway doesn't use a separate IPN request,
2440 2440
 				// because we will complete this step during the IPN processing then
2441
-				if ( $gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request() ) {
2441
+				if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) {
2442 2442
 					$this->set_completed();
2443 2443
 				}
2444 2444
 				return true;
@@ -2463,21 +2463,21 @@  discard block
 block discarded – undo
2463 2463
      * @throws \EE_Error
2464 2464
      */
2465 2465
 	private function _validate_offsite_return() {
2466
-		$TXN_ID = (int)EE_Registry::instance()->REQ->get( 'spco_txn', 0 );
2467
-		if ( $TXN_ID !== $this->checkout->transaction->ID() ) {
2466
+		$TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0);
2467
+		if ($TXN_ID !== $this->checkout->transaction->ID()) {
2468 2468
 			// Houston... we might have a problem
2469 2469
 			$invalid_TXN = false;
2470 2470
 			// first gather some info
2471
-			$valid_TXN = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID );
2471
+			$valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2472 2472
 			$primary_registrant = $valid_TXN instanceof EE_Transaction
2473 2473
 				? $valid_TXN->primary_registration()
2474 2474
 				: null;
2475 2475
 			// let's start by retrieving the cart for this TXN
2476
-			$cart = $this->checkout->get_cart_for_transaction( $this->checkout->transaction );
2477
-			if ( $cart instanceof EE_Cart ) {
2476
+			$cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction);
2477
+			if ($cart instanceof EE_Cart) {
2478 2478
 				// verify that the current cart has tickets
2479 2479
 				$tickets = $cart->get_tickets();
2480
-				if ( empty( $tickets ) ) {
2480
+				if (empty($tickets)) {
2481 2481
 					$invalid_TXN = true;
2482 2482
 				}
2483 2483
 			} else {
@@ -2503,21 +2503,21 @@  discard block
 block discarded – undo
2503 2503
             ) {
2504 2504
 				$invalid_TXN = true;
2505 2505
 			}
2506
-			if ( $invalid_TXN ) {
2506
+			if ($invalid_TXN) {
2507 2507
 				// is the valid TXN completed ?
2508
-				if ( $valid_TXN instanceof EE_Transaction ) {
2508
+				if ($valid_TXN instanceof EE_Transaction) {
2509 2509
 					// has this step even been started ?
2510
-					$reg_step_completed = $valid_TXN->reg_step_completed( $this->slug() );
2511
-					if ( $reg_step_completed !== false && $reg_step_completed !== true ) {
2510
+					$reg_step_completed = $valid_TXN->reg_step_completed($this->slug());
2511
+					if ($reg_step_completed !== false && $reg_step_completed !== true) {
2512 2512
 						// so it **looks** like this is a double request from PayPal
2513 2513
 						// so let's try to pick up where we left off
2514 2514
 						$this->checkout->transaction = $valid_TXN;
2515
-						$this->checkout->refresh_all_entities( true );
2515
+						$this->checkout->refresh_all_entities(true);
2516 2516
 						return;
2517 2517
 					}
2518 2518
 				}
2519 2519
 				// you appear to be lost?
2520
-				$this->_redirect_wayward_request( $primary_registrant );
2520
+				$this->_redirect_wayward_request($primary_registrant);
2521 2521
 			}
2522 2522
 		}
2523 2523
 	}
@@ -2532,14 +2532,14 @@  discard block
 block discarded – undo
2532 2532
 	 * @return bool
2533 2533
 	 * @throws \EE_Error
2534 2534
 	 */
2535
-	private function _redirect_wayward_request( EE_Registration $primary_registrant ) {
2536
-		if ( ! $primary_registrant instanceof EE_Registration ) {
2535
+	private function _redirect_wayward_request(EE_Registration $primary_registrant) {
2536
+		if ( ! $primary_registrant instanceof EE_Registration) {
2537 2537
 			// try redirecting based on the current TXN
2538 2538
 			$primary_registrant = $this->checkout->transaction instanceof EE_Transaction
2539 2539
 				? $this->checkout->transaction->primary_registration()
2540 2540
 				: null;
2541 2541
 		}
2542
-		if ( ! $primary_registrant instanceof EE_Registration ) {
2542
+		if ( ! $primary_registrant instanceof EE_Registration) {
2543 2543
 			EE_Error::add_error(
2544 2544
 				sprintf(
2545 2545
 					__(
@@ -2547,7 +2547,7 @@  discard block
 block discarded – undo
2547 2547
 						'event_espresso'
2548 2548
 					),
2549 2549
 					'<br/>',
2550
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
2550
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2551 2551
 				),
2552 2552
 				__FILE__,
2553 2553
 				__FUNCTION__,
@@ -2578,17 +2578,17 @@  discard block
 block discarded – undo
2578 2578
 	 * @return \EE_Payment
2579 2579
 	 * @throws \EE_Error
2580 2580
 	 */
2581
-	private function _process_off_site_payment( EE_Offsite_Gateway $gateway ) {
2581
+	private function _process_off_site_payment(EE_Offsite_Gateway $gateway) {
2582 2582
 		try {
2583 2583
 			$request_data = \EE_Registry::instance()->REQ->params();
2584 2584
 			// if gateway uses_separate_IPN_request, then we don't have to process the IPN manually
2585 2585
 			$this->set_handle_IPN_in_this_request(
2586
-				$gateway->handle_IPN_in_this_request( $request_data, false )
2586
+				$gateway->handle_IPN_in_this_request($request_data, false)
2587 2587
 			);
2588
-			if ( $this->handle_IPN_in_this_request() ) {
2588
+			if ($this->handle_IPN_in_this_request()) {
2589 2589
 				// get payment details and process results
2590 2590
 				/** @type EE_Payment_Processor $payment_processor */
2591
-				$payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' );
2591
+				$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2592 2592
 				$payment = $payment_processor->process_ipn(
2593 2593
 					$request_data,
2594 2594
 					$this->checkout->transaction,
@@ -2601,14 +2601,14 @@  discard block
 block discarded – undo
2601 2601
 				$payment = $this->checkout->transaction->last_payment();
2602 2602
 				//$payment_source = 'last_payment';
2603 2603
 			}
2604
-		} catch ( Exception $e ) {
2604
+		} catch (Exception $e) {
2605 2605
 			// let's just eat the exception and try to move on using any previously set payment info
2606 2606
 			$payment = $this->checkout->transaction->last_payment();
2607 2607
 			//$payment_source = 'last_payment after Exception';
2608 2608
 			// but if we STILL don't have a payment object
2609
-			if ( ! $payment instanceof EE_Payment ) {
2609
+			if ( ! $payment instanceof EE_Payment) {
2610 2610
 				// then we'll object ! ( not object like a thing... but object like what a lawyer says ! )
2611
-				$this->_handle_payment_processor_exception( $e );
2611
+				$this->_handle_payment_processor_exception($e);
2612 2612
 			}
2613 2613
 		}
2614 2614
 		// DEBUG LOG
@@ -2633,13 +2633,13 @@  discard block
 block discarded – undo
2633 2633
 	 * @return EE_Payment | FALSE
2634 2634
 	 * @throws \EE_Error
2635 2635
 	 */
2636
-	private function _process_cancelled_payments( $payment = null ) {
2636
+	private function _process_cancelled_payments($payment = null) {
2637 2637
 		if (
2638 2638
 			$payment instanceof EE_Payment
2639
-			&& isset( $_REQUEST['ee_cancel_payment'] )
2639
+			&& isset($_REQUEST['ee_cancel_payment'])
2640 2640
 			&& $payment->status() === EEM_Payment::status_id_failed
2641 2641
 		) {
2642
-			$payment->set_status( EEM_Payment::status_id_cancelled );
2642
+			$payment->set_status(EEM_Payment::status_id_cancelled);
2643 2643
 		}
2644 2644
 		return $payment;
2645 2645
 	}
@@ -2656,14 +2656,14 @@  discard block
 block discarded – undo
2656 2656
 	public function get_transaction_details_for_gateways() {
2657 2657
 		$txn_details = array();
2658 2658
 		// ya gotta make a choice man
2659
-		if ( empty( $this->checkout->selected_method_of_payment ) ) {
2659
+		if (empty($this->checkout->selected_method_of_payment)) {
2660 2660
 			$txn_details = array(
2661
-				'error' => __( 'Please select a method of payment before proceeding.', 'event_espresso' )
2661
+				'error' => __('Please select a method of payment before proceeding.', 'event_espresso')
2662 2662
 			);
2663 2663
 		}
2664 2664
 		// get EE_Payment_Method object
2665 2665
 		if (
2666
-			empty( $txn_details )
2666
+			empty($txn_details)
2667 2667
 			&&
2668 2668
 			! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()
2669 2669
 		) {
@@ -2675,8 +2675,8 @@  discard block
 block discarded – undo
2675 2675
 				)
2676 2676
 			);
2677 2677
 		}
2678
-		if ( empty( $txn_details ) && $this->checkout->transaction instanceof EE_Transaction ) {
2679
-			$return_url = $this->_get_return_url( $this->checkout->payment_method );
2678
+		if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) {
2679
+			$return_url = $this->_get_return_url($this->checkout->payment_method);
2680 2680
 			$txn_details = array(
2681 2681
 				'TXN_ID'         => $this->checkout->transaction->ID(),
2682 2682
 				'TXN_timestamp'  => $this->checkout->transaction->datetime(),
@@ -2687,7 +2687,7 @@  discard block
 block discarded – undo
2687 2687
 				'PMD_ID'         => $this->checkout->transaction->payment_method_ID(),
2688 2688
 				'payment_amount' => $this->checkout->amount_owing,
2689 2689
 				'return_url'     => $return_url,
2690
-				'cancel_url'     => add_query_arg( array( 'ee_cancel_payment' => true ), $return_url ),
2690
+				'cancel_url'     => add_query_arg(array('ee_cancel_payment' => true), $return_url),
2691 2691
 				'notify_url'     => EE_Config::instance()->core->txn_page_url(
2692 2692
 					array(
2693 2693
 						'e_reg_url_link'    => $this->checkout->transaction->primary_registration()->reg_url_link(),
@@ -2696,7 +2696,7 @@  discard block
 block discarded – undo
2696 2696
 				)
2697 2697
 			);
2698 2698
 		}
2699
-		echo wp_json_encode( $txn_details );
2699
+		echo wp_json_encode($txn_details);
2700 2700
 		exit();
2701 2701
 	}
2702 2702
 
@@ -2713,7 +2713,7 @@  discard block
 block discarded – undo
2713 2713
     public function __sleep()
2714 2714
     {
2715 2715
         // remove the reg form and the checkout
2716
-        return array_diff( array_keys( get_object_vars( $this ) ), array( 'reg_form', 'checkout', 'line_item_display' ) );
2716
+        return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display'));
2717 2717
     }
2718 2718
 
2719 2719
 
Please login to merge, or discard this patch.
core/helpers/EEH_Event_View.helper.php 1 patch
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -32,49 +32,49 @@  discard block
 block discarded – undo
32 32
 
33 33
 
34 34
 
35
-    /**
36
-     * get_event
37
-     * attempts to retrieve an EE_Event object any way it can
38
-     *
39
-     * @param int|WP_Post $EVT_ID
40
-     * @return EE_Event|null
41
-     * @throws \EE_Error
42
-     */
35
+	/**
36
+	 * get_event
37
+	 * attempts to retrieve an EE_Event object any way it can
38
+	 *
39
+	 * @param int|WP_Post $EVT_ID
40
+	 * @return EE_Event|null
41
+	 * @throws \EE_Error
42
+	 */
43 43
 	public static function get_event( $EVT_ID = 0 ) {
44
-        // international newspaper?
45
-        global $post;
46
-        $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
47
-            ? $EVT_ID->ID
48
-            : absint($EVT_ID);
49
-        // do we already have the Event  you are looking for?
50
-        if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
51
-            return EEH_Event_View::$_event;
52
-        }
53
-        //reset property so that the new event is cached.
54
-        EEH_Event_View::$_event = null;
55
-
56
-        if ($EVT_ID || $post instanceof WP_Post) {
57
-            //if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID
58
-            //then let's just use that cached event on the $post object.
59
-            if (($post instanceof WP_Post 
60
-                    && $post->post_type === 'espresso_events'
61
-                    )
62
-                && isset($post->EE_Event)
63
-                && ($EVT_ID === 0
64
-                    || $EVT_ID === $post->ID
65
-                    )
66
-            ) {
67
-                EEH_Event_View::$_event = $post->EE_Event;
68
-            }
69
-
70
-            //If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID.
71
-            if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
72
-                EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
73
-            }
74
-        }
75
-
76
-        return EEH_Event_View::$_event;
77
-    }
44
+		// international newspaper?
45
+		global $post;
46
+		$EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
47
+			? $EVT_ID->ID
48
+			: absint($EVT_ID);
49
+		// do we already have the Event  you are looking for?
50
+		if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
51
+			return EEH_Event_View::$_event;
52
+		}
53
+		//reset property so that the new event is cached.
54
+		EEH_Event_View::$_event = null;
55
+
56
+		if ($EVT_ID || $post instanceof WP_Post) {
57
+			//if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID
58
+			//then let's just use that cached event on the $post object.
59
+			if (($post instanceof WP_Post 
60
+					&& $post->post_type === 'espresso_events'
61
+					)
62
+				&& isset($post->EE_Event)
63
+				&& ($EVT_ID === 0
64
+					|| $EVT_ID === $post->ID
65
+					)
66
+			) {
67
+				EEH_Event_View::$_event = $post->EE_Event;
68
+			}
69
+
70
+			//If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID.
71
+			if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
72
+				EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
73
+			}
74
+		}
75
+
76
+		return EEH_Event_View::$_event;
77
+	}
78 78
 
79 79
 
80 80
 
@@ -150,58 +150,58 @@  discard block
 block discarded – undo
150 150
 	 * @return    string
151 151
 	 */
152 152
 	public static function event_content_or_excerpt( $num_words = NULL, $more = NULL ) {
153
-        global $post;
153
+		global $post;
154 154
 		ob_start();
155 155
 		if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) {
156 156
 			// admin has chosen "full description"
157
-            // for the "Event Espresso - Events > Templates > Display Description" option
157
+			// for the "Event Espresso - Events > Templates > Display Description" option
158 158
 			the_content();
159 159
 		} else if (( is_archive() && espresso_display_excerpt_in_event_list() ) ) {
160
-            if ( has_excerpt( $post->ID )) {
161
-                // admin has chosen "excerpt (short desc)"
162
-                // for the "Event Espresso - Events > Templates > Display Description" option
163
-                // AND an excerpt actually exists
164
-                the_excerpt();
165
-            } else {
166
-                // admin has chosen "excerpt (short desc)"
167
-                // for the "Event Espresso - Events > Templates > Display Description" option
168
-                // but NO excerpt actually exists, so we need to create one
169
-                if ( ! empty( $num_words )) {
170
-                    if ( empty( $more )) {
171
-                        $more_link_text = __( '(more&hellip;)' );
172
-                        $more = ' <a href="' . get_permalink() . '"';
173
-                        $more .= ' class="more-link"';
174
-                        $more .= \EED_Events_Archive::link_target();
175
-                        $more .= '>' . $more_link_text . '</a>';
176
-                        $more = apply_filters( 'the_content_more_link', $more, $more_link_text );
177
-                    }
178
-                    $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' ));
179
-
180
-                    $content =  wp_trim_words( $content, $num_words, ' ' ) . $more;
181
-                } else {
182
-                    $content =  get_the_content();
183
-                }
184
-                global $allowedtags;
185
-                // make sure links are allowed
186
-                $allowedtags['a'] = isset($allowedtags['a'])
187
-                    ? $allowedtags['a']
188
-                    : array();
189
-                // as well as target attribute
190
-                $allowedtags['a']['target'] = isset($allowedtags['a']['target'])
191
-                    ? $allowedtags['a']['target']
192
-                    : false;
193
-                // but get previous value so we can reset it
194
-                $prev_value = $allowedtags['a']['target'];
195
-                $allowedtags['a']['target'] = true;
196
-                $content = wp_kses( $content, $allowedtags );
197
-                $content = strip_shortcodes( $content );
198
-                echo apply_filters( 'the_content', $content );
199
-                $allowedtags['a']['target'] = $prev_value;
200
-            }
201
-        } else {
202
-            // admin has chosen "none"
203
-            // for the "Event Espresso - Events > Templates > Display Description" option
204
-            echo apply_filters( 'the_content', '' );
160
+			if ( has_excerpt( $post->ID )) {
161
+				// admin has chosen "excerpt (short desc)"
162
+				// for the "Event Espresso - Events > Templates > Display Description" option
163
+				// AND an excerpt actually exists
164
+				the_excerpt();
165
+			} else {
166
+				// admin has chosen "excerpt (short desc)"
167
+				// for the "Event Espresso - Events > Templates > Display Description" option
168
+				// but NO excerpt actually exists, so we need to create one
169
+				if ( ! empty( $num_words )) {
170
+					if ( empty( $more )) {
171
+						$more_link_text = __( '(more&hellip;)' );
172
+						$more = ' <a href="' . get_permalink() . '"';
173
+						$more .= ' class="more-link"';
174
+						$more .= \EED_Events_Archive::link_target();
175
+						$more .= '>' . $more_link_text . '</a>';
176
+						$more = apply_filters( 'the_content_more_link', $more, $more_link_text );
177
+					}
178
+					$content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' ));
179
+
180
+					$content =  wp_trim_words( $content, $num_words, ' ' ) . $more;
181
+				} else {
182
+					$content =  get_the_content();
183
+				}
184
+				global $allowedtags;
185
+				// make sure links are allowed
186
+				$allowedtags['a'] = isset($allowedtags['a'])
187
+					? $allowedtags['a']
188
+					: array();
189
+				// as well as target attribute
190
+				$allowedtags['a']['target'] = isset($allowedtags['a']['target'])
191
+					? $allowedtags['a']['target']
192
+					: false;
193
+				// but get previous value so we can reset it
194
+				$prev_value = $allowedtags['a']['target'];
195
+				$allowedtags['a']['target'] = true;
196
+				$content = wp_kses( $content, $allowedtags );
197
+				$content = strip_shortcodes( $content );
198
+				echo apply_filters( 'the_content', $content );
199
+				$allowedtags['a']['target'] = $prev_value;
200
+			}
201
+		} else {
202
+			// admin has chosen "none"
203
+			// for the "Event Espresso - Events > Templates > Display Description" option
204
+			echo apply_filters( 'the_content', '' );
205 205
 		}
206 206
 		return ob_get_clean();
207 207
 	}
@@ -248,11 +248,11 @@  discard block
 block discarded – undo
248 248
 					$url = get_term_link( $term, 'espresso_venue_categories' );
249 249
 					if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) {
250 250
 						$category_links[] = '<a href="' . esc_url( $url )
251
-                                            . '" rel="tag"'
252
-                                            . \EED_Events_Archive::link_target()
253
-                                            .'>'
254
-                                            . $term->name
255
-                                            . '</a>';
251
+											. '" rel="tag"'
252
+											. \EED_Events_Archive::link_target()
253
+											.'>'
254
+											. $term->name
255
+											. '</a>';
256 256
 					}
257 257
 				}
258 258
 			}
Please login to merge, or discard this patch.