Completed
Branch master (480e4f)
by
unknown
84:03 queued 76:18
created
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 1 patch
Indentation   +1792 added lines, -1792 removed lines patch added patch discarded remove patch
@@ -15,1796 +15,1796 @@
 block discarded – undo
15 15
 class EED_Single_Page_Checkout extends EED_Module
16 16
 {
17 17
 
18
-    /**
19
-     * $_initialized - has the SPCO controller already been initialized ?
20
-     *
21
-     * @access private
22
-     * @var bool $_initialized
23
-     */
24
-    private static $_initialized = false;
25
-
26
-
27
-    /**
28
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
29
-     *
30
-     * @access private
31
-     * @var bool $_valid_checkout
32
-     */
33
-    private static $_checkout_verified = true;
34
-
35
-    /**
36
-     *    $_reg_steps_array - holds initial array of reg steps
37
-     *
38
-     * @access private
39
-     * @var array $_reg_steps_array
40
-     */
41
-    private static $_reg_steps_array = array();
42
-
43
-    /**
44
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
45
-     *
46
-     * @access public
47
-     * @var EE_Checkout $checkout
48
-     */
49
-    public $checkout;
50
-
51
-
52
-    /**
53
-     * @return EED_Module|EED_Single_Page_Checkout
54
-     */
55
-    public static function instance()
56
-    {
57
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
58
-        return parent::get_instance(__CLASS__);
59
-    }
60
-
61
-
62
-    /**
63
-     * @return EE_CART
64
-     */
65
-    public function cart()
66
-    {
67
-        return $this->checkout->cart;
68
-    }
69
-
70
-
71
-    /**
72
-     * @return EE_Transaction
73
-     */
74
-    public function transaction()
75
-    {
76
-        return $this->checkout->transaction;
77
-    }
78
-
79
-
80
-    /**
81
-     *    set_hooks - for hooking into EE Core, other modules, etc
82
-     *
83
-     * @access    public
84
-     * @return    void
85
-     * @throws EE_Error
86
-     */
87
-    public static function set_hooks()
88
-    {
89
-        EED_Single_Page_Checkout::set_definitions();
90
-    }
91
-
92
-
93
-    /**
94
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
95
-     *
96
-     * @access    public
97
-     * @return    void
98
-     * @throws EE_Error
99
-     */
100
-    public static function set_hooks_admin()
101
-    {
102
-        EED_Single_Page_Checkout::set_definitions();
103
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
104
-            return;
105
-        }
106
-        // going to start an output buffer in case anything gets accidentally output
107
-        // that might disrupt our JSON response
108
-        ob_start();
109
-        EED_Single_Page_Checkout::load_request_handler();
110
-        EED_Single_Page_Checkout::load_reg_steps();
111
-        // set ajax hooks
112
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
113
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
114
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
115
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
116
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
117
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
118
-    }
119
-
120
-
121
-    /**
122
-     *    process ajax request
123
-     *
124
-     * @param string $ajax_action
125
-     * @throws EE_Error
126
-     */
127
-    public static function process_ajax_request($ajax_action)
128
-    {
129
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
130
-        EED_Single_Page_Checkout::instance()->_initialize();
131
-    }
132
-
133
-
134
-    /**
135
-     *    ajax display registration step
136
-     *
137
-     * @throws EE_Error
138
-     */
139
-    public static function display_reg_step()
140
-    {
141
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
142
-    }
143
-
144
-
145
-    /**
146
-     *    ajax process registration step
147
-     *
148
-     * @throws EE_Error
149
-     */
150
-    public static function process_reg_step()
151
-    {
152
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
153
-    }
154
-
155
-
156
-    /**
157
-     *    ajax process registration step
158
-     *
159
-     * @throws EE_Error
160
-     */
161
-    public static function update_reg_step()
162
-    {
163
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
164
-    }
165
-
166
-
167
-    /**
168
-     *   update_checkout
169
-     *
170
-     * @access public
171
-     * @return void
172
-     * @throws EE_Error
173
-     */
174
-    public static function update_checkout()
175
-    {
176
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
177
-    }
178
-
179
-
180
-    /**
181
-     *    load_request_handler
182
-     *
183
-     * @access    public
184
-     * @return    void
185
-     */
186
-    public static function load_request_handler()
187
-    {
188
-        // load core Request_Handler class
189
-        if (EE_Registry::instance()->REQ !== null) {
190
-            EE_Registry::instance()->load_core('Request_Handler');
191
-        }
192
-    }
193
-
194
-
195
-    /**
196
-     *    set_definitions
197
-     *
198
-     * @access    public
199
-     * @return    void
200
-     * @throws EE_Error
201
-     */
202
-    public static function set_definitions()
203
-    {
204
-        if (defined('SPCO_BASE_PATH')) {
205
-            return;
206
-        }
207
-        define(
208
-            'SPCO_BASE_PATH',
209
-            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
210
-        );
211
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css/');
212
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img/');
213
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js/');
214
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc/');
215
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps/');
216
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates/');
217
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
218
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
219
-        );
220
-    }
221
-
222
-
223
-    /**
224
-     * load_reg_steps
225
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
226
-     *
227
-     * @access    private
228
-     * @throws EE_Error
229
-     */
230
-    public static function load_reg_steps()
231
-    {
232
-        static $reg_steps_loaded = false;
233
-        if ($reg_steps_loaded) {
234
-            return;
235
-        }
236
-        // filter list of reg_steps
237
-        $reg_steps_to_load = (array) apply_filters(
238
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
239
-            EED_Single_Page_Checkout::get_reg_steps()
240
-        );
241
-        // sort by key (order)
242
-        ksort($reg_steps_to_load);
243
-        // loop through folders
244
-        foreach ($reg_steps_to_load as $order => $reg_step) {
245
-            // we need a
246
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
247
-                // copy over to the reg_steps_array
248
-                EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
249
-                // register custom key route for each reg step
250
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
251
-                EE_Config::register_route(
252
-                    $reg_step['slug'],
253
-                    'EED_Single_Page_Checkout',
254
-                    'run',
255
-                    'step'
256
-                );
257
-                // add AJAX or other hooks
258
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
259
-                    // setup autoloaders if necessary
260
-                    if (! class_exists($reg_step['class_name'])) {
261
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
262
-                            $reg_step['file_path'],
263
-                            true
264
-                        );
265
-                    }
266
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
267
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
268
-                    }
269
-                }
270
-            }
271
-        }
272
-        $reg_steps_loaded = true;
273
-    }
274
-
275
-
276
-    /**
277
-     *    get_reg_steps
278
-     *
279
-     * @access    public
280
-     * @return    array
281
-     */
282
-    public static function get_reg_steps()
283
-    {
284
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
285
-        if (empty($reg_steps)) {
286
-            $reg_steps = array(
287
-                10  => array(
288
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
289
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
290
-                    'slug'       => 'attendee_information',
291
-                    'has_hooks'  => false,
292
-                ),
293
-                30  => array(
294
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
295
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
296
-                    'slug'       => 'payment_options',
297
-                    'has_hooks'  => true,
298
-                ),
299
-                999 => array(
300
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
301
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
302
-                    'slug'       => 'finalize_registration',
303
-                    'has_hooks'  => false,
304
-                ),
305
-            );
306
-        }
307
-        return $reg_steps;
308
-    }
309
-
310
-
311
-    /**
312
-     *    registration_checkout_for_admin
313
-     *
314
-     * @access    public
315
-     * @return    string
316
-     * @throws EE_Error
317
-     */
318
-    public static function registration_checkout_for_admin()
319
-    {
320
-        EED_Single_Page_Checkout::load_request_handler();
321
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
322
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
323
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
324
-        EED_Single_Page_Checkout::instance()->_initialize();
325
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
326
-        return EE_Registry::instance()->REQ->get_output();
327
-    }
328
-
329
-
330
-    /**
331
-     * process_registration_from_admin
332
-     *
333
-     * @access public
334
-     * @return \EE_Transaction
335
-     * @throws EE_Error
336
-     */
337
-    public static function process_registration_from_admin()
338
-    {
339
-        EED_Single_Page_Checkout::load_request_handler();
340
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
341
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
342
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
343
-        EED_Single_Page_Checkout::instance()->_initialize();
344
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
345
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
346
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
347
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
348
-                if ($final_reg_step->process_reg_step()) {
349
-                    $final_reg_step->set_completed();
350
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
351
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
352
-                }
353
-            }
354
-        }
355
-        return null;
356
-    }
357
-
358
-
359
-    /**
360
-     *    run
361
-     *
362
-     * @access    public
363
-     * @param WP_Query $WP_Query
364
-     * @return    void
365
-     * @throws EE_Error
366
-     */
367
-    public function run($WP_Query)
368
-    {
369
-        if ($WP_Query instanceof WP_Query
370
-            && $WP_Query->is_main_query()
371
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
372
-            && $this->_is_reg_checkout()
373
-        ) {
374
-            $this->_initialize();
375
-        }
376
-    }
377
-
378
-
379
-    /**
380
-     * determines whether current url matches reg page url
381
-     *
382
-     * @return bool
383
-     */
384
-    protected function _is_reg_checkout()
385
-    {
386
-        // get current permalink for reg page without any extra query args
387
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
388
-        // get request URI for current request, but without the scheme or host
389
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
390
-        $current_request_uri = html_entity_decode($current_request_uri);
391
-        // get array of query args from the current request URI
392
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
393
-        // grab page id if it is set
394
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
395
-        // and remove the page id from the query args (we will re-add it later)
396
-        unset($query_args['page_id']);
397
-        // now strip all query args from current request URI
398
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
399
-        // and re-add the page id if it was set
400
-        if ($page_id) {
401
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
402
-        }
403
-        // remove slashes and ?
404
-        $current_request_uri = trim($current_request_uri, '?/');
405
-        // is current request URI part of the known full reg page URL ?
406
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
407
-    }
408
-
409
-
410
-    /**
411
-     * @param WP_Query $wp_query
412
-     * @return    void
413
-     * @throws EE_Error
414
-     */
415
-    public static function init($wp_query)
416
-    {
417
-        EED_Single_Page_Checkout::instance()->run($wp_query);
418
-    }
419
-
420
-
421
-    /**
422
-     *    _initialize - initial module setup
423
-     *
424
-     * @access    private
425
-     * @throws EE_Error
426
-     * @return    void
427
-     */
428
-    private function _initialize()
429
-    {
430
-        // ensure SPCO doesn't run twice
431
-        if (EED_Single_Page_Checkout::$_initialized) {
432
-            return;
433
-        }
434
-        try {
435
-            EED_Single_Page_Checkout::load_reg_steps();
436
-            $this->_verify_session();
437
-            // setup the EE_Checkout object
438
-            $this->checkout = $this->_initialize_checkout();
439
-            // filter checkout
440
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
441
-            // get the $_GET
442
-            $this->_get_request_vars();
443
-            if ($this->_block_bots()) {
444
-                return;
445
-            }
446
-            // filter continue_reg
447
-            $this->checkout->continue_reg = apply_filters(
448
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
449
-                true,
450
-                $this->checkout
451
-            );
452
-            // load the reg steps array
453
-            if (! $this->_load_and_instantiate_reg_steps()) {
454
-                EED_Single_Page_Checkout::$_initialized = true;
455
-                return;
456
-            }
457
-            // set the current step
458
-            $this->checkout->set_current_step($this->checkout->step);
459
-            // and the next step
460
-            $this->checkout->set_next_step();
461
-            // verify that everything has been setup correctly
462
-            if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
463
-                EED_Single_Page_Checkout::$_initialized = true;
464
-                return;
465
-            }
466
-            // lock the transaction
467
-            $this->checkout->transaction->lock();
468
-            // make sure all of our cached objects are added to their respective model entity mappers
469
-            $this->checkout->refresh_all_entities();
470
-            // set amount owing
471
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
472
-            // initialize each reg step, which gives them the chance to potentially alter the process
473
-            $this->_initialize_reg_steps();
474
-            // DEBUG LOG
475
-            // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
476
-            // get reg form
477
-            if (! $this->_check_form_submission()) {
478
-                EED_Single_Page_Checkout::$_initialized = true;
479
-                return;
480
-            }
481
-            // checkout the action!!!
482
-            $this->_process_form_action();
483
-            // add some style and make it dance
484
-            $this->add_styles_and_scripts($this);
485
-            // kk... SPCO has successfully run
486
-            EED_Single_Page_Checkout::$_initialized = true;
487
-            // set no cache headers and constants
488
-            EE_System::do_not_cache();
489
-            // add anchor
490
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
491
-            // remove transaction lock
492
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
493
-        } catch (Exception $e) {
494
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
495
-        }
496
-    }
497
-
498
-
499
-    /**
500
-     *    _verify_session
501
-     * checks that the session is valid and not expired
502
-     *
503
-     * @access    private
504
-     * @throws EE_Error
505
-     */
506
-    private function _verify_session()
507
-    {
508
-        if (! EE_Registry::instance()->SSN instanceof EE_Session) {
509
-            throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso'));
510
-        }
511
-        $clear_session_requested = filter_var(
512
-            EE_Registry::instance()->REQ->get('clear_session', false),
513
-            FILTER_VALIDATE_BOOLEAN
514
-        );
515
-        // is session still valid ?
516
-        if ($clear_session_requested
517
-            || (EE_Registry::instance()->SSN->expired()
518
-                && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
519
-            )
520
-        ) {
521
-            $this->checkout = new EE_Checkout();
522
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
523
-            // EE_Registry::instance()->SSN->reset_cart();
524
-            // EE_Registry::instance()->SSN->reset_checkout();
525
-            // EE_Registry::instance()->SSN->reset_transaction();
526
-            if (! $clear_session_requested) {
527
-                EE_Error::add_attention(
528
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
529
-                    __FILE__,
530
-                    __FUNCTION__,
531
-                    __LINE__
532
-                );
533
-            }
534
-            // EE_Registry::instance()->SSN->reset_expired();
535
-        }
536
-    }
537
-
538
-
539
-    /**
540
-     *    _initialize_checkout
541
-     * loads and instantiates EE_Checkout
542
-     *
543
-     * @access    private
544
-     * @throws EE_Error
545
-     * @return EE_Checkout
546
-     */
547
-    private function _initialize_checkout()
548
-    {
549
-        // look in session for existing checkout
550
-        /** @type EE_Checkout $checkout */
551
-        $checkout = EE_Registry::instance()->SSN->checkout();
552
-        // verify
553
-        if (! $checkout instanceof EE_Checkout) {
554
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
555
-            $checkout = EE_Registry::instance()->load_file(
556
-                SPCO_INC_PATH,
557
-                'EE_Checkout',
558
-                'class',
559
-                array(),
560
-                false
561
-            );
562
-        } else {
563
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
564
-                $this->unlock_transaction();
565
-                wp_safe_redirect($checkout->redirect_url);
566
-                exit();
567
-            }
568
-        }
569
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
570
-        // verify again
571
-        if (! $checkout instanceof EE_Checkout) {
572
-            throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso'));
573
-        }
574
-        // reset anything that needs a clean slate for each request
575
-        $checkout->reset_for_current_request();
576
-        return $checkout;
577
-    }
578
-
579
-
580
-    /**
581
-     *    _get_request_vars
582
-     *
583
-     * @access    private
584
-     * @return    void
585
-     * @throws EE_Error
586
-     */
587
-    private function _get_request_vars()
588
-    {
589
-        // load classes
590
-        EED_Single_Page_Checkout::load_request_handler();
591
-        // make sure this request is marked as belonging to EE
592
-        EE_Registry::instance()->REQ->set_espresso_page(true);
593
-        // which step is being requested ?
594
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
595
-        // which step is being edited ?
596
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
597
-        // and what we're doing on the current step
598
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
599
-        // timestamp
600
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
601
-        // returning to edit ?
602
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
603
-        // add reg url link to registration query params
604
-        if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
605
-            $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
606
-        }
607
-        // or some other kind of revisit ?
608
-        $this->checkout->revisit = filter_var(
609
-            EE_Registry::instance()->REQ->get('revisit', false),
610
-            FILTER_VALIDATE_BOOLEAN
611
-        );
612
-        // and whether or not to generate a reg form for this request
613
-        $this->checkout->generate_reg_form = filter_var(
614
-            EE_Registry::instance()->REQ->get('generate_reg_form', true),
615
-            FILTER_VALIDATE_BOOLEAN
616
-        );
617
-        // and whether or not to process a reg form submission for this request
618
-        $this->checkout->process_form_submission = filter_var(
619
-            EE_Registry::instance()->REQ->get(
620
-                'process_form_submission',
621
-                $this->checkout->action === 'process_reg_step'
622
-            ),
623
-            FILTER_VALIDATE_BOOLEAN
624
-        );
625
-        $this->checkout->process_form_submission = filter_var(
626
-            $this->checkout->action !== 'display_spco_reg_step'
627
-                ? $this->checkout->process_form_submission
628
-                : false,
629
-            FILTER_VALIDATE_BOOLEAN
630
-        );
631
-        // $this->_display_request_vars();
632
-    }
633
-
634
-
635
-    /**
636
-     *  _display_request_vars
637
-     *
638
-     * @access    protected
639
-     * @return    void
640
-     */
641
-    protected function _display_request_vars()
642
-    {
643
-        if (! WP_DEBUG) {
644
-            return;
645
-        }
646
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
647
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
648
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
649
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
650
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
651
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
652
-        EEH_Debug_Tools::printr(
653
-            $this->checkout->generate_reg_form,
654
-            '$this->checkout->generate_reg_form',
655
-            __FILE__,
656
-            __LINE__
657
-        );
658
-        EEH_Debug_Tools::printr(
659
-            $this->checkout->process_form_submission,
660
-            '$this->checkout->process_form_submission',
661
-            __FILE__,
662
-            __LINE__
663
-        );
664
-    }
665
-
666
-
667
-    /**
668
-     * _block_bots
669
-     * checks that the incoming request has either of the following set:
670
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
671
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
672
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
673
-     * then where you coming from man?
674
-     *
675
-     * @return boolean
676
-     */
677
-    private function _block_bots()
678
-    {
679
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
680
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
681
-            return true;
682
-        }
683
-        return false;
684
-    }
685
-
686
-
687
-    /**
688
-     *    _get_first_step
689
-     *  gets slug for first step in $_reg_steps_array
690
-     *
691
-     * @access    private
692
-     * @throws EE_Error
693
-     * @return    string
694
-     */
695
-    private function _get_first_step()
696
-    {
697
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
698
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
699
-    }
700
-
701
-
702
-    /**
703
-     * instantiates each reg step based on the loaded reg_steps array
704
-     *
705
-     * @return    bool
706
-     * @throws EE_Error
707
-     * @throws InvalidArgumentException
708
-     * @throws InvalidDataTypeException
709
-     * @throws InvalidInterfaceException
710
-     */
711
-    private function _load_and_instantiate_reg_steps()
712
-    {
713
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
714
-        // have reg_steps already been instantiated ?
715
-        if (empty($this->checkout->reg_steps)
716
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
717
-        ) {
718
-            // if not, then loop through raw reg steps array
719
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
720
-                if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
721
-                    return false;
722
-                }
723
-            }
724
-            if (isset($this->checkout->reg_steps['registration_confirmation'])) {
725
-                // skip the registration_confirmation page ?
726
-                if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
727
-                    // just remove it from the reg steps array
728
-                    $this->checkout->remove_reg_step('registration_confirmation', false);
729
-                } elseif (EE_Registry::instance()->CFG->registration->reg_confirmation_last
730
-                ) {
731
-                    // set the order to something big like 100
732
-                    $this->checkout->set_reg_step_order('registration_confirmation', 100);
733
-                }
734
-            }
735
-            // filter the array for good luck
736
-            $this->checkout->reg_steps = apply_filters(
737
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
738
-                $this->checkout->reg_steps
739
-            );
740
-            // finally re-sort based on the reg step class order properties
741
-            $this->checkout->sort_reg_steps();
742
-        } else {
743
-            foreach ($this->checkout->reg_steps as $reg_step) {
744
-                // set all current step stati to FALSE
745
-                $reg_step->set_is_current_step(false);
746
-            }
747
-        }
748
-        if (empty($this->checkout->reg_steps)) {
749
-            EE_Error::add_error(
750
-                esc_html__('No Reg Steps were loaded..', 'event_espresso'),
751
-                __FILE__,
752
-                __FUNCTION__,
753
-                __LINE__
754
-            );
755
-            return false;
756
-        }
757
-        // make reg step details available to JS
758
-        $this->checkout->set_reg_step_JSON_info();
759
-        return true;
760
-    }
761
-
762
-
763
-    /**
764
-     *     _load_and_instantiate_reg_step
765
-     *
766
-     * @access    private
767
-     * @param array $reg_step
768
-     * @param int   $order
769
-     * @return bool
770
-     */
771
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
772
-    {
773
-        // we need a file_path, class_name, and slug to add a reg step
774
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
775
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
776
-            if ($this->checkout->reg_url_link
777
-                && $this->checkout->step !== $reg_step['slug']
778
-                && $reg_step['slug'] !== 'finalize_registration'
779
-                // normally at this point we would NOT load the reg step, but this filter can change that
780
-                && apply_filters(
781
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
782
-                    true,
783
-                    $reg_step,
784
-                    $this->checkout
785
-                )
786
-            ) {
787
-                return true;
788
-            }
789
-            // instantiate step class using file path and class name
790
-            $reg_step_obj = EE_Registry::instance()->load_file(
791
-                $reg_step['file_path'],
792
-                $reg_step['class_name'],
793
-                'class',
794
-                $this->checkout,
795
-                false
796
-            );
797
-            // did we gets the goods ?
798
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
799
-                // set reg step order based on config
800
-                $reg_step_obj->set_order($order);
801
-                // add instantiated reg step object to the master reg steps array
802
-                $this->checkout->add_reg_step($reg_step_obj);
803
-            } else {
804
-                EE_Error::add_error(
805
-                    esc_html__('The current step could not be set.', 'event_espresso'),
806
-                    __FILE__,
807
-                    __FUNCTION__,
808
-                    __LINE__
809
-                );
810
-                return false;
811
-            }
812
-        } else {
813
-            if (WP_DEBUG) {
814
-                EE_Error::add_error(
815
-                    sprintf(
816
-                        esc_html__(
817
-                            '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',
818
-                            'event_espresso'
819
-                        ),
820
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
821
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
822
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
823
-                        '<ul>',
824
-                        '<li>',
825
-                        '</li>',
826
-                        '</ul>'
827
-                    ),
828
-                    __FILE__,
829
-                    __FUNCTION__,
830
-                    __LINE__
831
-                );
832
-            }
833
-            return false;
834
-        }
835
-        return true;
836
-    }
837
-
838
-
839
-    /**
840
-     * _verify_transaction_and_get_registrations
841
-     *
842
-     * @access private
843
-     * @return bool
844
-     * @throws InvalidDataTypeException
845
-     * @throws InvalidEntityException
846
-     * @throws EE_Error
847
-     */
848
-    private function _verify_transaction_and_get_registrations()
849
-    {
850
-        // was there already a valid transaction in the checkout from the session ?
851
-        if (! $this->checkout->transaction instanceof EE_Transaction) {
852
-            // get transaction from db or session
853
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
854
-                ? $this->_get_transaction_and_cart_for_previous_visit()
855
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
856
-            if (! $this->checkout->transaction instanceof EE_Transaction) {
857
-                EE_Error::add_error(
858
-                    esc_html__(
859
-                        'Your Registration and Transaction information could not be retrieved from the db.',
860
-                        'event_espresso'
861
-                    ),
862
-                    __FILE__,
863
-                    __FUNCTION__,
864
-                    __LINE__
865
-                );
866
-                $this->checkout->transaction = EE_Transaction::new_instance();
867
-                // add some style and make it dance
868
-                $this->add_styles_and_scripts($this);
869
-                EED_Single_Page_Checkout::$_initialized = true;
870
-                return false;
871
-            }
872
-            // and the registrations for the transaction
873
-            $this->_get_registrations($this->checkout->transaction);
874
-        }
875
-        return true;
876
-    }
877
-
878
-
879
-    /**
880
-     * _get_transaction_and_cart_for_previous_visit
881
-     *
882
-     * @access private
883
-     * @return mixed EE_Transaction|NULL
884
-     */
885
-    private function _get_transaction_and_cart_for_previous_visit()
886
-    {
887
-        /** @var $TXN_model EEM_Transaction */
888
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
889
-        // because the reg_url_link is present in the request,
890
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
891
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
892
-        // verify transaction
893
-        if ($transaction instanceof EE_Transaction) {
894
-            // and get the cart that was used for that transaction
895
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
896
-            return $transaction;
897
-        }
898
-        EE_Error::add_error(
899
-            esc_html__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
900
-            __FILE__,
901
-            __FUNCTION__,
902
-            __LINE__
903
-        );
904
-        return null;
905
-    }
906
-
907
-
908
-    /**
909
-     * _get_cart_for_transaction
910
-     *
911
-     * @access private
912
-     * @param EE_Transaction $transaction
913
-     * @return EE_Cart
914
-     */
915
-    private function _get_cart_for_transaction($transaction)
916
-    {
917
-        return $this->checkout->get_cart_for_transaction($transaction);
918
-    }
919
-
920
-
921
-    /**
922
-     * get_cart_for_transaction
923
-     *
924
-     * @access public
925
-     * @param EE_Transaction $transaction
926
-     * @return EE_Cart
927
-     */
928
-    public function get_cart_for_transaction(EE_Transaction $transaction)
929
-    {
930
-        return $this->checkout->get_cart_for_transaction($transaction);
931
-    }
932
-
933
-
934
-    /**
935
-     * _get_transaction_and_cart_for_current_session
936
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
937
-     *
938
-     * @access private
939
-     * @return EE_Transaction
940
-     * @throws EE_Error
941
-     */
942
-    private function _get_cart_for_current_session_and_setup_new_transaction()
943
-    {
944
-        //  if there's no transaction, then this is the FIRST visit to SPCO
945
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
946
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
947
-        // and then create a new transaction
948
-        $transaction = $this->_initialize_transaction();
949
-        // verify transaction
950
-        if ($transaction instanceof EE_Transaction) {
951
-            // save it so that we have an ID for other objects to use
952
-            $transaction->save();
953
-            // and save TXN data to the cart
954
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
955
-        } else {
956
-            EE_Error::add_error(
957
-                esc_html__('A Valid Transaction could not be initialized.', 'event_espresso'),
958
-                __FILE__,
959
-                __FUNCTION__,
960
-                __LINE__
961
-            );
962
-        }
963
-        return $transaction;
964
-    }
965
-
966
-
967
-    /**
968
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
969
-     *
970
-     * @access private
971
-     * @return mixed EE_Transaction|NULL
972
-     */
973
-    private function _initialize_transaction()
974
-    {
975
-        try {
976
-            // ensure cart totals have been calculated
977
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
978
-            // grab the cart grand total
979
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
980
-            // create new TXN
981
-            $transaction = EE_Transaction::new_instance(
982
-                array(
983
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
984
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
985
-                    'TXN_paid'      => 0,
986
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
987
-                )
988
-            );
989
-            // save it so that we have an ID for other objects to use
990
-            $transaction->save();
991
-            // set cron job for following up on TXNs after their session has expired
992
-            EE_Cron_Tasks::schedule_expired_transaction_check(
993
-                EE_Registry::instance()->SSN->expiration() + 1,
994
-                $transaction->ID()
995
-            );
996
-            return $transaction;
997
-        } catch (Exception $e) {
998
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
999
-        }
1000
-        return null;
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     * _get_registrations
1006
-     *
1007
-     * @access private
1008
-     * @param EE_Transaction $transaction
1009
-     * @return void
1010
-     * @throws InvalidDataTypeException
1011
-     * @throws InvalidEntityException
1012
-     * @throws EE_Error
1013
-     */
1014
-    private function _get_registrations(EE_Transaction $transaction)
1015
-    {
1016
-        // first step: grab the registrants  { : o
1017
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1018
-        $this->checkout->total_ticket_count = count($registrations);
1019
-        // verify registrations have been set
1020
-        if (empty($registrations)) {
1021
-            // if no cached registrations, then check the db
1022
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1023
-            // still nothing ? well as long as this isn't a revisit
1024
-            if (empty($registrations) && ! $this->checkout->revisit) {
1025
-                // generate new registrations from scratch
1026
-                $registrations = $this->_initialize_registrations($transaction);
1027
-            }
1028
-        }
1029
-        // sort by their original registration order
1030
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1031
-        // then loop thru the array
1032
-        foreach ($registrations as $registration) {
1033
-            // verify each registration
1034
-            if ($registration instanceof EE_Registration) {
1035
-                // we display all attendee info for the primary registrant
1036
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
1037
-                    && $registration->is_primary_registrant()
1038
-                ) {
1039
-                    $this->checkout->primary_revisit = true;
1040
-                    break;
1041
-                }
1042
-                if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1043
-                    // but hide info if it doesn't belong to you
1044
-                    $transaction->clear_cache('Registration', $registration->ID());
1045
-                    $this->checkout->total_ticket_count--;
1046
-                }
1047
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1048
-            }
1049
-        }
1050
-    }
1051
-
1052
-
1053
-    /**
1054
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1055
-     *
1056
-     * @access private
1057
-     * @param EE_Transaction $transaction
1058
-     * @return    array
1059
-     * @throws InvalidDataTypeException
1060
-     * @throws InvalidEntityException
1061
-     * @throws EE_Error
1062
-     */
1063
-    private function _initialize_registrations(EE_Transaction $transaction)
1064
-    {
1065
-        $att_nmbr = 0;
1066
-        $registrations = array();
1067
-        if ($transaction instanceof EE_Transaction) {
1068
-            /** @type EE_Registration_Processor $registration_processor */
1069
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1070
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1071
-            // now let's add the cart items to the $transaction
1072
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1073
-                // do the following for each ticket of this type they selected
1074
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1075
-                    $att_nmbr++;
1076
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1077
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1078
-                        'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1079
-                        array(
1080
-                            $transaction,
1081
-                            $line_item,
1082
-                            $att_nmbr,
1083
-                            $this->checkout->total_ticket_count,
1084
-                        )
1085
-                    );
1086
-                    // override capabilities for frontend registrations
1087
-                    if (! is_admin()) {
1088
-                        $CreateRegistrationCommand->setCapCheck(
1089
-                            new PublicCapabilities('', 'create_new_registration')
1090
-                        );
1091
-                    }
1092
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1093
-                    if (! $registration instanceof EE_Registration) {
1094
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1095
-                    }
1096
-                    $registrations[ $registration->ID() ] = $registration;
1097
-                }
1098
-            }
1099
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1100
-        }
1101
-        return $registrations;
1102
-    }
1103
-
1104
-
1105
-    /**
1106
-     * sorts registrations by REG_count
1107
-     *
1108
-     * @access public
1109
-     * @param EE_Registration $reg_A
1110
-     * @param EE_Registration $reg_B
1111
-     * @return int
1112
-     */
1113
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1114
-    {
1115
-        // this shouldn't ever happen within the same TXN, but oh well
1116
-        if ($reg_A->count() === $reg_B->count()) {
1117
-            return 0;
1118
-        }
1119
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1120
-    }
1121
-
1122
-
1123
-    /**
1124
-     *    _final_verifications
1125
-     * just makes sure that everything is set up correctly before proceeding
1126
-     *
1127
-     * @access    private
1128
-     * @return    bool
1129
-     * @throws EE_Error
1130
-     */
1131
-    private function _final_verifications()
1132
-    {
1133
-        // filter checkout
1134
-        $this->checkout = apply_filters(
1135
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1136
-            $this->checkout
1137
-        );
1138
-        // verify that current step is still set correctly
1139
-        if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1140
-            EE_Error::add_error(
1141
-                esc_html__(
1142
-                    '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.',
1143
-                    'event_espresso'
1144
-                ),
1145
-                __FILE__,
1146
-                __FUNCTION__,
1147
-                __LINE__
1148
-            );
1149
-            return false;
1150
-        }
1151
-        // if returning to SPCO, then verify that primary registrant is set
1152
-        if (! empty($this->checkout->reg_url_link)) {
1153
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1154
-            if (! $valid_registrant instanceof EE_Registration) {
1155
-                EE_Error::add_error(
1156
-                    esc_html__(
1157
-                        '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.',
1158
-                        'event_espresso'
1159
-                    ),
1160
-                    __FILE__,
1161
-                    __FUNCTION__,
1162
-                    __LINE__
1163
-                );
1164
-                return false;
1165
-            }
1166
-            $valid_registrant = null;
1167
-            foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1168
-                if ($registration instanceof EE_Registration
1169
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1170
-                ) {
1171
-                    $valid_registrant = $registration;
1172
-                }
1173
-            }
1174
-            if (! $valid_registrant instanceof EE_Registration) {
1175
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1176
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1177
-                    // clear the session, mark the checkout as unverified, and try again
1178
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1179
-                    EED_Single_Page_Checkout::$_initialized = false;
1180
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1181
-                    $this->_initialize();
1182
-                    EE_Error::reset_notices();
1183
-                    return false;
1184
-                }
1185
-                EE_Error::add_error(
1186
-                    esc_html__(
1187
-                        '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.',
1188
-                        'event_espresso'
1189
-                    ),
1190
-                    __FILE__,
1191
-                    __FUNCTION__,
1192
-                    __LINE__
1193
-                );
1194
-                return false;
1195
-            }
1196
-        }
1197
-        // now that things have been kinda sufficiently verified,
1198
-        // let's add the checkout to the session so that it's available to other systems
1199
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1200
-        return true;
1201
-    }
1202
-
1203
-
1204
-    /**
1205
-     *    _initialize_reg_steps
1206
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1207
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1208
-     *
1209
-     * @access    private
1210
-     * @param bool $reinitializing
1211
-     * @throws EE_Error
1212
-     */
1213
-    private function _initialize_reg_steps($reinitializing = false)
1214
-    {
1215
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1216
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1217
-        foreach ($this->checkout->reg_steps as $reg_step) {
1218
-            if (! $reg_step->initialize_reg_step()) {
1219
-                // if not initialized then maybe this step is being removed...
1220
-                if (! $reinitializing && $reg_step->is_current_step()) {
1221
-                    // if it was the current step, then we need to start over here
1222
-                    $this->_initialize_reg_steps(true);
1223
-                    return;
1224
-                }
1225
-                continue;
1226
-            }
1227
-            // add css and JS for current step
1228
-            $this->add_styles_and_scripts($reg_step);
1229
-            if ($reg_step->is_current_step()) {
1230
-                // the text that appears on the reg step form submit button
1231
-                $reg_step->set_submit_button_text();
1232
-            }
1233
-        }
1234
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1235
-        do_action(
1236
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1237
-            $this->checkout->current_step
1238
-        );
1239
-    }
1240
-
1241
-
1242
-    /**
1243
-     * _check_form_submission
1244
-     *
1245
-     * @access private
1246
-     * @return boolean
1247
-     */
1248
-    private function _check_form_submission()
1249
-    {
1250
-        // does this request require the reg form to be generated ?
1251
-        if ($this->checkout->generate_reg_form) {
1252
-            // ever heard that song by Blue Rodeo ?
1253
-            try {
1254
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1255
-                // if not displaying a form, then check for form submission
1256
-                if ($this->checkout->process_form_submission
1257
-                    && $this->checkout->current_step->reg_form->was_submitted()
1258
-                ) {
1259
-                    // clear out any old data in case this step is being run again
1260
-                    $this->checkout->current_step->set_valid_data(array());
1261
-                    // capture submitted form data
1262
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1263
-                        apply_filters(
1264
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1265
-                            EE_Registry::instance()->REQ->params(),
1266
-                            $this->checkout
1267
-                        )
1268
-                    );
1269
-                    // validate submitted form data
1270
-                    if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1271
-                        // thou shall not pass !!!
1272
-                        $this->checkout->continue_reg = false;
1273
-                        // any form validation errors?
1274
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1275
-                            EE_Error::add_error(
1276
-                                $this->checkout->current_step->reg_form->submission_error_message(),
1277
-                                __FILE__,
1278
-                                __FUNCTION__,
1279
-                                __LINE__
1280
-                            );
1281
-                        }
1282
-                        // well not really... what will happen is
1283
-                        // we'll just get redirected back to redo the current step
1284
-                        $this->go_to_next_step();
1285
-                        return false;
1286
-                    }
1287
-                }
1288
-            } catch (EE_Error $e) {
1289
-                $e->get_error();
1290
-            }
1291
-        }
1292
-        return true;
1293
-    }
1294
-
1295
-
1296
-    /**
1297
-     * _process_action
1298
-     *
1299
-     * @access private
1300
-     * @return void
1301
-     * @throws EE_Error
1302
-     */
1303
-    private function _process_form_action()
1304
-    {
1305
-        // what cha wanna do?
1306
-        switch ($this->checkout->action) {
1307
-            // AJAX next step reg form
1308
-            case 'display_spco_reg_step':
1309
-                $this->checkout->redirect = false;
1310
-                if (EE_Registry::instance()->REQ->ajax) {
1311
-                    $this->checkout->json_response->set_reg_step_html(
1312
-                        $this->checkout->current_step->display_reg_form()
1313
-                    );
1314
-                }
1315
-                break;
1316
-            default:
1317
-                // meh... do one of those other steps first
1318
-                if (! empty($this->checkout->action)
1319
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1320
-                ) {
1321
-                    // dynamically creates hook point like:
1322
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1323
-                    do_action(
1324
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1325
-                        $this->checkout->current_step
1326
-                    );
1327
-                    // call action on current step
1328
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1329
-                        // good registrant, you get to proceed
1330
-                        if ($this->checkout->current_step->success_message() !== ''
1331
-                            && apply_filters(
1332
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1333
-                                false
1334
-                            )
1335
-                        ) {
1336
-                            EE_Error::add_success(
1337
-                                $this->checkout->current_step->success_message()
1338
-                                . '<br />' . $this->checkout->next_step->_instructions()
1339
-                            );
1340
-                        }
1341
-                        // pack it up, pack it in...
1342
-                        $this->_setup_redirect();
1343
-                    }
1344
-                    // dynamically creates hook point like:
1345
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1346
-                    do_action(
1347
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1348
-                        $this->checkout->current_step
1349
-                    );
1350
-                } else {
1351
-                    EE_Error::add_error(
1352
-                        sprintf(
1353
-                            esc_html__(
1354
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1355
-                                'event_espresso'
1356
-                            ),
1357
-                            $this->checkout->action,
1358
-                            $this->checkout->current_step->name()
1359
-                        ),
1360
-                        __FILE__,
1361
-                        __FUNCTION__,
1362
-                        __LINE__
1363
-                    );
1364
-                }
1365
-            // end default
1366
-        }
1367
-        // store our progress so far
1368
-        $this->checkout->stash_transaction_and_checkout();
1369
-        // advance to the next step! If you pass GO, collect $200
1370
-        $this->go_to_next_step();
1371
-    }
1372
-
1373
-
1374
-    /**
1375
-     * @param EED_Single_Page_Checkout|EE_SPCO_Reg_Step $target
1376
-     * @param object $target an object with the method `translate_js_strings` and `enqueue_styles_and_scripts`.
1377
-     * @return        void
1378
-     */
1379
-    public function add_styles_and_scripts($target)
1380
-    {
1381
-        // i18n
1382
-        $target->translate_js_strings();
1383
-        if ($this->checkout->admin_request) {
1384
-            add_action('admin_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1385
-        } else {
1386
-            add_action('wp_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1387
-        }
1388
-    }
1389
-
1390
-    /**
1391
-     *        translate_js_strings
1392
-     *
1393
-     * @access        public
1394
-     * @return        void
1395
-     */
1396
-    public function translate_js_strings()
1397
-    {
1398
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1399
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1400
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
1401
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1402
-            'event_espresso'
1403
-        );
1404
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = esc_html__(
1405
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1406
-            'event_espresso'
1407
-        );
1408
-        EE_Registry::$i18n_js_strings['validation_error'] = esc_html__(
1409
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1410
-            'event_espresso'
1411
-        );
1412
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
1413
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1414
-            'event_espresso'
1415
-        );
1416
-        EE_Registry::$i18n_js_strings['reg_step_error'] = esc_html__(
1417
-            'This registration step could not be completed. Please refresh the page and try again.',
1418
-            'event_espresso'
1419
-        );
1420
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = esc_html__(
1421
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1422
-            'event_espresso'
1423
-        );
1424
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1425
-            esc_html__(
1426
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1427
-                'event_espresso'
1428
-            ),
1429
-            '<br/>',
1430
-            '<br/>'
1431
-        );
1432
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1433
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1434
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1435
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1436
-        EE_Registry::$i18n_js_strings['timer_years'] = esc_html__('years', 'event_espresso');
1437
-        EE_Registry::$i18n_js_strings['timer_months'] = esc_html__('months', 'event_espresso');
1438
-        EE_Registry::$i18n_js_strings['timer_weeks'] = esc_html__('weeks', 'event_espresso');
1439
-        EE_Registry::$i18n_js_strings['timer_days'] = esc_html__('days', 'event_espresso');
1440
-        EE_Registry::$i18n_js_strings['timer_hours'] = esc_html__('hours', 'event_espresso');
1441
-        EE_Registry::$i18n_js_strings['timer_minutes'] = esc_html__('minutes', 'event_espresso');
1442
-        EE_Registry::$i18n_js_strings['timer_seconds'] = esc_html__('seconds', 'event_espresso');
1443
-        EE_Registry::$i18n_js_strings['timer_year'] = esc_html__('year', 'event_espresso');
1444
-        EE_Registry::$i18n_js_strings['timer_month'] = esc_html__('month', 'event_espresso');
1445
-        EE_Registry::$i18n_js_strings['timer_week'] = esc_html__('week', 'event_espresso');
1446
-        EE_Registry::$i18n_js_strings['timer_day'] = esc_html__('day', 'event_espresso');
1447
-        EE_Registry::$i18n_js_strings['timer_hour'] = esc_html__('hour', 'event_espresso');
1448
-        EE_Registry::$i18n_js_strings['timer_minute'] = esc_html__('minute', 'event_espresso');
1449
-        EE_Registry::$i18n_js_strings['timer_second'] = esc_html__('second', 'event_espresso');
1450
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
1451
-        );
1452
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1453
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1454
-            true
1455
-        );
1456
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1457
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1458
-        );
1459
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1460
-            'M d, Y H:i:s',
1461
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1462
-        );
1463
-    }
1464
-
1465
-
1466
-    /**
1467
-     *    enqueue_styles_and_scripts
1468
-     *
1469
-     * @access        public
1470
-     * @return        void
1471
-     * @throws EE_Error
1472
-     */
1473
-    public function enqueue_styles_and_scripts()
1474
-    {
1475
-        // load css
1476
-        wp_register_style(
1477
-            'single_page_checkout',
1478
-            SPCO_CSS_URL . 'single_page_checkout.css',
1479
-            array('espresso_default'),
1480
-            EVENT_ESPRESSO_VERSION
1481
-        );
1482
-        wp_enqueue_style('single_page_checkout');
1483
-        // load JS
1484
-        wp_register_script(
1485
-            'jquery_plugin',
1486
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1487
-            array('jquery'),
1488
-            '1.0.1',
1489
-            true
1490
-        );
1491
-        wp_register_script(
1492
-            'jquery_countdown',
1493
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1494
-            array('jquery_plugin'),
1495
-            '2.1.0',
1496
-            true
1497
-        );
1498
-        wp_register_script(
1499
-            'single_page_checkout',
1500
-            SPCO_JS_URL . 'single_page_checkout.js',
1501
-            array('espresso_core', 'underscore', 'ee_form_section_validation'),
1502
-            EVENT_ESPRESSO_VERSION,
1503
-            true
1504
-        );
1505
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1506
-            $this->checkout->registration_form->enqueue_js();
1507
-        }
1508
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1509
-            $this->checkout->current_step->reg_form->enqueue_js();
1510
-        }
1511
-        wp_enqueue_script('single_page_checkout');
1512
-        if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) {
1513
-            wp_enqueue_script('jquery_countdown');
1514
-        }
1515
-        /**
1516
-         * global action hook for enqueueing styles and scripts with
1517
-         * spco calls.
1518
-         */
1519
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1520
-        /**
1521
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1522
-         * The hook will end up being something like:
1523
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1524
-         */
1525
-        do_action(
1526
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1527
-            $this
1528
-        );
1529
-    }
1530
-
1531
-
1532
-    /**
1533
-     *    display the Registration Single Page Checkout Form
1534
-     *
1535
-     * @access    private
1536
-     * @return    void
1537
-     * @throws EE_Error
1538
-     */
1539
-    private function _display_spco_reg_form()
1540
-    {
1541
-        // if registering via the admin, just display the reg form for the current step
1542
-        if ($this->checkout->admin_request) {
1543
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1544
-        } else {
1545
-            // add powered by EE msg
1546
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1547
-            $empty_cart = count($this->checkout->transaction
1548
-                                    ->registrations($this->checkout->reg_cache_where_params)) < 1;
1549
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1550
-            $cookies_not_set_msg = '';
1551
-            if ($empty_cart) {
1552
-                $cookies_not_set_msg = apply_filters(
1553
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1554
-                    sprintf(
1555
-                        esc_html__(
1556
-                            '%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',
1557
-                            'event_espresso'
1558
-                        ),
1559
-                        '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1560
-                        '</div>',
1561
-                        '<h6 class="important-notice">',
1562
-                        '</h6>',
1563
-                        '<p>',
1564
-                        '</p>',
1565
-                        '<br />',
1566
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank" rel="noopener noreferrer">',
1567
-                        '</a>'
1568
-                    )
1569
-                );
1570
-            }
1571
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1572
-                array(
1573
-                    'name'            => 'single-page-checkout',
1574
-                    'html_id'         => 'ee-single-page-checkout-dv',
1575
-                    'layout_strategy' =>
1576
-                        new EE_Template_Layout(
1577
-                            array(
1578
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1579
-                                'template_args'        => array(
1580
-                                    'empty_cart'              => $empty_cart,
1581
-                                    'revisit'                 => $this->checkout->revisit,
1582
-                                    'reg_steps'               => $this->checkout->reg_steps,
1583
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1584
-                                        ? $this->checkout->next_step->slug()
1585
-                                        : '',
1586
-                                    'empty_msg'               => apply_filters(
1587
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1588
-                                        sprintf(
1589
-                                            esc_html__(
1590
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1591
-                                                'event_espresso'
1592
-                                            ),
1593
-                                            '<a href="'
1594
-                                            . get_post_type_archive_link('espresso_events')
1595
-                                            . '" title="',
1596
-                                            '">',
1597
-                                            '</a>'
1598
-                                        )
1599
-                                    ),
1600
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1601
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1602
-                                    'session_expiration'      => gmdate(
1603
-                                        'M d, Y H:i:s',
1604
-                                        EE_Registry::instance()->SSN->expiration()
1605
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1606
-                                    ),
1607
-                                ),
1608
-                            )
1609
-                        ),
1610
-                )
1611
-            );
1612
-            // load template and add to output sent that gets filtered into the_content()
1613
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1614
-        }
1615
-    }
1616
-
1617
-
1618
-    /**
1619
-     *    add_extra_finalize_registration_inputs
1620
-     *
1621
-     * @access    public
1622
-     * @param $next_step
1623
-     * @internal  param string $label
1624
-     * @return void
1625
-     */
1626
-    public function add_extra_finalize_registration_inputs($next_step)
1627
-    {
1628
-        if ($next_step === 'finalize_registration') {
1629
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1630
-        }
1631
-    }
1632
-
1633
-
1634
-    /**
1635
-     *    display_registration_footer
1636
-     *
1637
-     * @access    public
1638
-     * @return    string
1639
-     */
1640
-    public static function display_registration_footer()
1641
-    {
1642
-        if (apply_filters(
1643
-            'FHEE__EE_Front__Controller__show_reg_footer',
1644
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1645
-        )) {
1646
-            add_filter(
1647
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1648
-                function ($url) {
1649
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1650
-                }
1651
-            );
1652
-            echo apply_filters(
1653
-                'FHEE__EE_Front_Controller__display_registration_footer',
1654
-                \EEH_Template::powered_by_event_espresso(
1655
-                    '',
1656
-                    'espresso-registration-footer-dv',
1657
-                    array('utm_content' => 'registration_checkout')
1658
-                )
1659
-            );
1660
-        }
1661
-        return '';
1662
-    }
1663
-
1664
-
1665
-    /**
1666
-     *    unlock_transaction
1667
-     *
1668
-     * @access    public
1669
-     * @return    void
1670
-     * @throws EE_Error
1671
-     */
1672
-    public function unlock_transaction()
1673
-    {
1674
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1675
-            $this->checkout->transaction->unlock();
1676
-        }
1677
-    }
1678
-
1679
-
1680
-    /**
1681
-     *        _setup_redirect
1682
-     *
1683
-     * @access    private
1684
-     * @return void
1685
-     */
1686
-    private function _setup_redirect()
1687
-    {
1688
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1689
-            $this->checkout->redirect = true;
1690
-            if (empty($this->checkout->redirect_url)) {
1691
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1692
-            }
1693
-            $this->checkout->redirect_url = apply_filters(
1694
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1695
-                $this->checkout->redirect_url,
1696
-                $this->checkout
1697
-            );
1698
-        }
1699
-    }
1700
-
1701
-
1702
-    /**
1703
-     *   handle ajax message responses and redirects
1704
-     *
1705
-     * @access public
1706
-     * @return void
1707
-     * @throws EE_Error
1708
-     */
1709
-    public function go_to_next_step()
1710
-    {
1711
-        if (EE_Registry::instance()->REQ->ajax) {
1712
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1713
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1714
-        }
1715
-        $this->unlock_transaction();
1716
-        // just return for these conditions
1717
-        if ($this->checkout->admin_request
1718
-            || $this->checkout->action === 'redirect_form'
1719
-            || $this->checkout->action === 'update_checkout'
1720
-        ) {
1721
-            return;
1722
-        }
1723
-        // AJAX response
1724
-        $this->_handle_json_response();
1725
-        // redirect to next step or the Thank You page
1726
-        $this->_handle_html_redirects();
1727
-        // hmmm... must be something wrong, so let's just display the form again !
1728
-        $this->_display_spco_reg_form();
1729
-    }
1730
-
1731
-
1732
-    /**
1733
-     *   _handle_json_response
1734
-     *
1735
-     * @access protected
1736
-     * @return void
1737
-     */
1738
-    protected function _handle_json_response()
1739
-    {
1740
-        // if this is an ajax request
1741
-        if (EE_Registry::instance()->REQ->ajax) {
1742
-            $this->checkout->json_response->set_registration_time_limit(
1743
-                $this->checkout->get_registration_time_limit()
1744
-            );
1745
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1746
-            // just send the ajax (
1747
-            $json_response = apply_filters(
1748
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1749
-                $this->checkout->json_response
1750
-            );
1751
-            echo $json_response;
1752
-            exit();
1753
-        }
1754
-    }
1755
-
1756
-
1757
-    /**
1758
-     *   _handle_redirects
1759
-     *
1760
-     * @access protected
1761
-     * @return void
1762
-     */
1763
-    protected function _handle_html_redirects()
1764
-    {
1765
-        // going somewhere ?
1766
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1767
-            // store notices in a transient
1768
-            EE_Error::get_notices(false, true, true);
1769
-            wp_safe_redirect($this->checkout->redirect_url);
1770
-            exit();
1771
-        }
1772
-    }
1773
-
1774
-
1775
-    /**
1776
-     *   set_checkout_anchor
1777
-     *
1778
-     * @access public
1779
-     * @return void
1780
-     */
1781
-    public function set_checkout_anchor()
1782
-    {
1783
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1784
-    }
1785
-
1786
-    /**
1787
-     *    getRegistrationExpirationNotice
1788
-     *
1789
-     * @since     4.9.59.p
1790
-     * @access    public
1791
-     * @return    string
1792
-     */
1793
-    public static function getRegistrationExpirationNotice()
1794
-    {
1795
-        return sprintf(
1796
-            esc_html__(
1797
-                '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1798
-                'event_espresso'
1799
-            ),
1800
-            '<h4 class="important-notice">',
1801
-            '</h4>',
1802
-            '<br />',
1803
-            '<p>',
1804
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1805
-            '">',
1806
-            '</a>',
1807
-            '</p>'
1808
-        );
1809
-    }
18
+	/**
19
+	 * $_initialized - has the SPCO controller already been initialized ?
20
+	 *
21
+	 * @access private
22
+	 * @var bool $_initialized
23
+	 */
24
+	private static $_initialized = false;
25
+
26
+
27
+	/**
28
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
29
+	 *
30
+	 * @access private
31
+	 * @var bool $_valid_checkout
32
+	 */
33
+	private static $_checkout_verified = true;
34
+
35
+	/**
36
+	 *    $_reg_steps_array - holds initial array of reg steps
37
+	 *
38
+	 * @access private
39
+	 * @var array $_reg_steps_array
40
+	 */
41
+	private static $_reg_steps_array = array();
42
+
43
+	/**
44
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
45
+	 *
46
+	 * @access public
47
+	 * @var EE_Checkout $checkout
48
+	 */
49
+	public $checkout;
50
+
51
+
52
+	/**
53
+	 * @return EED_Module|EED_Single_Page_Checkout
54
+	 */
55
+	public static function instance()
56
+	{
57
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
58
+		return parent::get_instance(__CLASS__);
59
+	}
60
+
61
+
62
+	/**
63
+	 * @return EE_CART
64
+	 */
65
+	public function cart()
66
+	{
67
+		return $this->checkout->cart;
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return EE_Transaction
73
+	 */
74
+	public function transaction()
75
+	{
76
+		return $this->checkout->transaction;
77
+	}
78
+
79
+
80
+	/**
81
+	 *    set_hooks - for hooking into EE Core, other modules, etc
82
+	 *
83
+	 * @access    public
84
+	 * @return    void
85
+	 * @throws EE_Error
86
+	 */
87
+	public static function set_hooks()
88
+	{
89
+		EED_Single_Page_Checkout::set_definitions();
90
+	}
91
+
92
+
93
+	/**
94
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
95
+	 *
96
+	 * @access    public
97
+	 * @return    void
98
+	 * @throws EE_Error
99
+	 */
100
+	public static function set_hooks_admin()
101
+	{
102
+		EED_Single_Page_Checkout::set_definitions();
103
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
104
+			return;
105
+		}
106
+		// going to start an output buffer in case anything gets accidentally output
107
+		// that might disrupt our JSON response
108
+		ob_start();
109
+		EED_Single_Page_Checkout::load_request_handler();
110
+		EED_Single_Page_Checkout::load_reg_steps();
111
+		// set ajax hooks
112
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
113
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
114
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
115
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
116
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
117
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
118
+	}
119
+
120
+
121
+	/**
122
+	 *    process ajax request
123
+	 *
124
+	 * @param string $ajax_action
125
+	 * @throws EE_Error
126
+	 */
127
+	public static function process_ajax_request($ajax_action)
128
+	{
129
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
130
+		EED_Single_Page_Checkout::instance()->_initialize();
131
+	}
132
+
133
+
134
+	/**
135
+	 *    ajax display registration step
136
+	 *
137
+	 * @throws EE_Error
138
+	 */
139
+	public static function display_reg_step()
140
+	{
141
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
142
+	}
143
+
144
+
145
+	/**
146
+	 *    ajax process registration step
147
+	 *
148
+	 * @throws EE_Error
149
+	 */
150
+	public static function process_reg_step()
151
+	{
152
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
153
+	}
154
+
155
+
156
+	/**
157
+	 *    ajax process registration step
158
+	 *
159
+	 * @throws EE_Error
160
+	 */
161
+	public static function update_reg_step()
162
+	{
163
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
164
+	}
165
+
166
+
167
+	/**
168
+	 *   update_checkout
169
+	 *
170
+	 * @access public
171
+	 * @return void
172
+	 * @throws EE_Error
173
+	 */
174
+	public static function update_checkout()
175
+	{
176
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
177
+	}
178
+
179
+
180
+	/**
181
+	 *    load_request_handler
182
+	 *
183
+	 * @access    public
184
+	 * @return    void
185
+	 */
186
+	public static function load_request_handler()
187
+	{
188
+		// load core Request_Handler class
189
+		if (EE_Registry::instance()->REQ !== null) {
190
+			EE_Registry::instance()->load_core('Request_Handler');
191
+		}
192
+	}
193
+
194
+
195
+	/**
196
+	 *    set_definitions
197
+	 *
198
+	 * @access    public
199
+	 * @return    void
200
+	 * @throws EE_Error
201
+	 */
202
+	public static function set_definitions()
203
+	{
204
+		if (defined('SPCO_BASE_PATH')) {
205
+			return;
206
+		}
207
+		define(
208
+			'SPCO_BASE_PATH',
209
+			rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
210
+		);
211
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css/');
212
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img/');
213
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js/');
214
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc/');
215
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps/');
216
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates/');
217
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
218
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
219
+		);
220
+	}
221
+
222
+
223
+	/**
224
+	 * load_reg_steps
225
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
226
+	 *
227
+	 * @access    private
228
+	 * @throws EE_Error
229
+	 */
230
+	public static function load_reg_steps()
231
+	{
232
+		static $reg_steps_loaded = false;
233
+		if ($reg_steps_loaded) {
234
+			return;
235
+		}
236
+		// filter list of reg_steps
237
+		$reg_steps_to_load = (array) apply_filters(
238
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
239
+			EED_Single_Page_Checkout::get_reg_steps()
240
+		);
241
+		// sort by key (order)
242
+		ksort($reg_steps_to_load);
243
+		// loop through folders
244
+		foreach ($reg_steps_to_load as $order => $reg_step) {
245
+			// we need a
246
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
247
+				// copy over to the reg_steps_array
248
+				EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
249
+				// register custom key route for each reg step
250
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
251
+				EE_Config::register_route(
252
+					$reg_step['slug'],
253
+					'EED_Single_Page_Checkout',
254
+					'run',
255
+					'step'
256
+				);
257
+				// add AJAX or other hooks
258
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
259
+					// setup autoloaders if necessary
260
+					if (! class_exists($reg_step['class_name'])) {
261
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
262
+							$reg_step['file_path'],
263
+							true
264
+						);
265
+					}
266
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
267
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
268
+					}
269
+				}
270
+			}
271
+		}
272
+		$reg_steps_loaded = true;
273
+	}
274
+
275
+
276
+	/**
277
+	 *    get_reg_steps
278
+	 *
279
+	 * @access    public
280
+	 * @return    array
281
+	 */
282
+	public static function get_reg_steps()
283
+	{
284
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
285
+		if (empty($reg_steps)) {
286
+			$reg_steps = array(
287
+				10  => array(
288
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
289
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
290
+					'slug'       => 'attendee_information',
291
+					'has_hooks'  => false,
292
+				),
293
+				30  => array(
294
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
295
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
296
+					'slug'       => 'payment_options',
297
+					'has_hooks'  => true,
298
+				),
299
+				999 => array(
300
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
301
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
302
+					'slug'       => 'finalize_registration',
303
+					'has_hooks'  => false,
304
+				),
305
+			);
306
+		}
307
+		return $reg_steps;
308
+	}
309
+
310
+
311
+	/**
312
+	 *    registration_checkout_for_admin
313
+	 *
314
+	 * @access    public
315
+	 * @return    string
316
+	 * @throws EE_Error
317
+	 */
318
+	public static function registration_checkout_for_admin()
319
+	{
320
+		EED_Single_Page_Checkout::load_request_handler();
321
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
322
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
323
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
324
+		EED_Single_Page_Checkout::instance()->_initialize();
325
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
326
+		return EE_Registry::instance()->REQ->get_output();
327
+	}
328
+
329
+
330
+	/**
331
+	 * process_registration_from_admin
332
+	 *
333
+	 * @access public
334
+	 * @return \EE_Transaction
335
+	 * @throws EE_Error
336
+	 */
337
+	public static function process_registration_from_admin()
338
+	{
339
+		EED_Single_Page_Checkout::load_request_handler();
340
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
341
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
342
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
343
+		EED_Single_Page_Checkout::instance()->_initialize();
344
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
345
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
346
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
347
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
348
+				if ($final_reg_step->process_reg_step()) {
349
+					$final_reg_step->set_completed();
350
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
351
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
352
+				}
353
+			}
354
+		}
355
+		return null;
356
+	}
357
+
358
+
359
+	/**
360
+	 *    run
361
+	 *
362
+	 * @access    public
363
+	 * @param WP_Query $WP_Query
364
+	 * @return    void
365
+	 * @throws EE_Error
366
+	 */
367
+	public function run($WP_Query)
368
+	{
369
+		if ($WP_Query instanceof WP_Query
370
+			&& $WP_Query->is_main_query()
371
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
372
+			&& $this->_is_reg_checkout()
373
+		) {
374
+			$this->_initialize();
375
+		}
376
+	}
377
+
378
+
379
+	/**
380
+	 * determines whether current url matches reg page url
381
+	 *
382
+	 * @return bool
383
+	 */
384
+	protected function _is_reg_checkout()
385
+	{
386
+		// get current permalink for reg page without any extra query args
387
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
388
+		// get request URI for current request, but without the scheme or host
389
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
390
+		$current_request_uri = html_entity_decode($current_request_uri);
391
+		// get array of query args from the current request URI
392
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
393
+		// grab page id if it is set
394
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
395
+		// and remove the page id from the query args (we will re-add it later)
396
+		unset($query_args['page_id']);
397
+		// now strip all query args from current request URI
398
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
399
+		// and re-add the page id if it was set
400
+		if ($page_id) {
401
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
402
+		}
403
+		// remove slashes and ?
404
+		$current_request_uri = trim($current_request_uri, '?/');
405
+		// is current request URI part of the known full reg page URL ?
406
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
407
+	}
408
+
409
+
410
+	/**
411
+	 * @param WP_Query $wp_query
412
+	 * @return    void
413
+	 * @throws EE_Error
414
+	 */
415
+	public static function init($wp_query)
416
+	{
417
+		EED_Single_Page_Checkout::instance()->run($wp_query);
418
+	}
419
+
420
+
421
+	/**
422
+	 *    _initialize - initial module setup
423
+	 *
424
+	 * @access    private
425
+	 * @throws EE_Error
426
+	 * @return    void
427
+	 */
428
+	private function _initialize()
429
+	{
430
+		// ensure SPCO doesn't run twice
431
+		if (EED_Single_Page_Checkout::$_initialized) {
432
+			return;
433
+		}
434
+		try {
435
+			EED_Single_Page_Checkout::load_reg_steps();
436
+			$this->_verify_session();
437
+			// setup the EE_Checkout object
438
+			$this->checkout = $this->_initialize_checkout();
439
+			// filter checkout
440
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
441
+			// get the $_GET
442
+			$this->_get_request_vars();
443
+			if ($this->_block_bots()) {
444
+				return;
445
+			}
446
+			// filter continue_reg
447
+			$this->checkout->continue_reg = apply_filters(
448
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
449
+				true,
450
+				$this->checkout
451
+			);
452
+			// load the reg steps array
453
+			if (! $this->_load_and_instantiate_reg_steps()) {
454
+				EED_Single_Page_Checkout::$_initialized = true;
455
+				return;
456
+			}
457
+			// set the current step
458
+			$this->checkout->set_current_step($this->checkout->step);
459
+			// and the next step
460
+			$this->checkout->set_next_step();
461
+			// verify that everything has been setup correctly
462
+			if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
463
+				EED_Single_Page_Checkout::$_initialized = true;
464
+				return;
465
+			}
466
+			// lock the transaction
467
+			$this->checkout->transaction->lock();
468
+			// make sure all of our cached objects are added to their respective model entity mappers
469
+			$this->checkout->refresh_all_entities();
470
+			// set amount owing
471
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
472
+			// initialize each reg step, which gives them the chance to potentially alter the process
473
+			$this->_initialize_reg_steps();
474
+			// DEBUG LOG
475
+			// $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
476
+			// get reg form
477
+			if (! $this->_check_form_submission()) {
478
+				EED_Single_Page_Checkout::$_initialized = true;
479
+				return;
480
+			}
481
+			// checkout the action!!!
482
+			$this->_process_form_action();
483
+			// add some style and make it dance
484
+			$this->add_styles_and_scripts($this);
485
+			// kk... SPCO has successfully run
486
+			EED_Single_Page_Checkout::$_initialized = true;
487
+			// set no cache headers and constants
488
+			EE_System::do_not_cache();
489
+			// add anchor
490
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
491
+			// remove transaction lock
492
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
493
+		} catch (Exception $e) {
494
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
495
+		}
496
+	}
497
+
498
+
499
+	/**
500
+	 *    _verify_session
501
+	 * checks that the session is valid and not expired
502
+	 *
503
+	 * @access    private
504
+	 * @throws EE_Error
505
+	 */
506
+	private function _verify_session()
507
+	{
508
+		if (! EE_Registry::instance()->SSN instanceof EE_Session) {
509
+			throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso'));
510
+		}
511
+		$clear_session_requested = filter_var(
512
+			EE_Registry::instance()->REQ->get('clear_session', false),
513
+			FILTER_VALIDATE_BOOLEAN
514
+		);
515
+		// is session still valid ?
516
+		if ($clear_session_requested
517
+			|| (EE_Registry::instance()->SSN->expired()
518
+				&& EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
519
+			)
520
+		) {
521
+			$this->checkout = new EE_Checkout();
522
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
523
+			// EE_Registry::instance()->SSN->reset_cart();
524
+			// EE_Registry::instance()->SSN->reset_checkout();
525
+			// EE_Registry::instance()->SSN->reset_transaction();
526
+			if (! $clear_session_requested) {
527
+				EE_Error::add_attention(
528
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
529
+					__FILE__,
530
+					__FUNCTION__,
531
+					__LINE__
532
+				);
533
+			}
534
+			// EE_Registry::instance()->SSN->reset_expired();
535
+		}
536
+	}
537
+
538
+
539
+	/**
540
+	 *    _initialize_checkout
541
+	 * loads and instantiates EE_Checkout
542
+	 *
543
+	 * @access    private
544
+	 * @throws EE_Error
545
+	 * @return EE_Checkout
546
+	 */
547
+	private function _initialize_checkout()
548
+	{
549
+		// look in session for existing checkout
550
+		/** @type EE_Checkout $checkout */
551
+		$checkout = EE_Registry::instance()->SSN->checkout();
552
+		// verify
553
+		if (! $checkout instanceof EE_Checkout) {
554
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
555
+			$checkout = EE_Registry::instance()->load_file(
556
+				SPCO_INC_PATH,
557
+				'EE_Checkout',
558
+				'class',
559
+				array(),
560
+				false
561
+			);
562
+		} else {
563
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
564
+				$this->unlock_transaction();
565
+				wp_safe_redirect($checkout->redirect_url);
566
+				exit();
567
+			}
568
+		}
569
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
570
+		// verify again
571
+		if (! $checkout instanceof EE_Checkout) {
572
+			throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso'));
573
+		}
574
+		// reset anything that needs a clean slate for each request
575
+		$checkout->reset_for_current_request();
576
+		return $checkout;
577
+	}
578
+
579
+
580
+	/**
581
+	 *    _get_request_vars
582
+	 *
583
+	 * @access    private
584
+	 * @return    void
585
+	 * @throws EE_Error
586
+	 */
587
+	private function _get_request_vars()
588
+	{
589
+		// load classes
590
+		EED_Single_Page_Checkout::load_request_handler();
591
+		// make sure this request is marked as belonging to EE
592
+		EE_Registry::instance()->REQ->set_espresso_page(true);
593
+		// which step is being requested ?
594
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
595
+		// which step is being edited ?
596
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
597
+		// and what we're doing on the current step
598
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
599
+		// timestamp
600
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
601
+		// returning to edit ?
602
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
603
+		// add reg url link to registration query params
604
+		if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
605
+			$this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
606
+		}
607
+		// or some other kind of revisit ?
608
+		$this->checkout->revisit = filter_var(
609
+			EE_Registry::instance()->REQ->get('revisit', false),
610
+			FILTER_VALIDATE_BOOLEAN
611
+		);
612
+		// and whether or not to generate a reg form for this request
613
+		$this->checkout->generate_reg_form = filter_var(
614
+			EE_Registry::instance()->REQ->get('generate_reg_form', true),
615
+			FILTER_VALIDATE_BOOLEAN
616
+		);
617
+		// and whether or not to process a reg form submission for this request
618
+		$this->checkout->process_form_submission = filter_var(
619
+			EE_Registry::instance()->REQ->get(
620
+				'process_form_submission',
621
+				$this->checkout->action === 'process_reg_step'
622
+			),
623
+			FILTER_VALIDATE_BOOLEAN
624
+		);
625
+		$this->checkout->process_form_submission = filter_var(
626
+			$this->checkout->action !== 'display_spco_reg_step'
627
+				? $this->checkout->process_form_submission
628
+				: false,
629
+			FILTER_VALIDATE_BOOLEAN
630
+		);
631
+		// $this->_display_request_vars();
632
+	}
633
+
634
+
635
+	/**
636
+	 *  _display_request_vars
637
+	 *
638
+	 * @access    protected
639
+	 * @return    void
640
+	 */
641
+	protected function _display_request_vars()
642
+	{
643
+		if (! WP_DEBUG) {
644
+			return;
645
+		}
646
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
647
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
648
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
649
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
650
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
651
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
652
+		EEH_Debug_Tools::printr(
653
+			$this->checkout->generate_reg_form,
654
+			'$this->checkout->generate_reg_form',
655
+			__FILE__,
656
+			__LINE__
657
+		);
658
+		EEH_Debug_Tools::printr(
659
+			$this->checkout->process_form_submission,
660
+			'$this->checkout->process_form_submission',
661
+			__FILE__,
662
+			__LINE__
663
+		);
664
+	}
665
+
666
+
667
+	/**
668
+	 * _block_bots
669
+	 * checks that the incoming request has either of the following set:
670
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
671
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
672
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
673
+	 * then where you coming from man?
674
+	 *
675
+	 * @return boolean
676
+	 */
677
+	private function _block_bots()
678
+	{
679
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
680
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
681
+			return true;
682
+		}
683
+		return false;
684
+	}
685
+
686
+
687
+	/**
688
+	 *    _get_first_step
689
+	 *  gets slug for first step in $_reg_steps_array
690
+	 *
691
+	 * @access    private
692
+	 * @throws EE_Error
693
+	 * @return    string
694
+	 */
695
+	private function _get_first_step()
696
+	{
697
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
698
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
699
+	}
700
+
701
+
702
+	/**
703
+	 * instantiates each reg step based on the loaded reg_steps array
704
+	 *
705
+	 * @return    bool
706
+	 * @throws EE_Error
707
+	 * @throws InvalidArgumentException
708
+	 * @throws InvalidDataTypeException
709
+	 * @throws InvalidInterfaceException
710
+	 */
711
+	private function _load_and_instantiate_reg_steps()
712
+	{
713
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
714
+		// have reg_steps already been instantiated ?
715
+		if (empty($this->checkout->reg_steps)
716
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
717
+		) {
718
+			// if not, then loop through raw reg steps array
719
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
720
+				if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
721
+					return false;
722
+				}
723
+			}
724
+			if (isset($this->checkout->reg_steps['registration_confirmation'])) {
725
+				// skip the registration_confirmation page ?
726
+				if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
727
+					// just remove it from the reg steps array
728
+					$this->checkout->remove_reg_step('registration_confirmation', false);
729
+				} elseif (EE_Registry::instance()->CFG->registration->reg_confirmation_last
730
+				) {
731
+					// set the order to something big like 100
732
+					$this->checkout->set_reg_step_order('registration_confirmation', 100);
733
+				}
734
+			}
735
+			// filter the array for good luck
736
+			$this->checkout->reg_steps = apply_filters(
737
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
738
+				$this->checkout->reg_steps
739
+			);
740
+			// finally re-sort based on the reg step class order properties
741
+			$this->checkout->sort_reg_steps();
742
+		} else {
743
+			foreach ($this->checkout->reg_steps as $reg_step) {
744
+				// set all current step stati to FALSE
745
+				$reg_step->set_is_current_step(false);
746
+			}
747
+		}
748
+		if (empty($this->checkout->reg_steps)) {
749
+			EE_Error::add_error(
750
+				esc_html__('No Reg Steps were loaded..', 'event_espresso'),
751
+				__FILE__,
752
+				__FUNCTION__,
753
+				__LINE__
754
+			);
755
+			return false;
756
+		}
757
+		// make reg step details available to JS
758
+		$this->checkout->set_reg_step_JSON_info();
759
+		return true;
760
+	}
761
+
762
+
763
+	/**
764
+	 *     _load_and_instantiate_reg_step
765
+	 *
766
+	 * @access    private
767
+	 * @param array $reg_step
768
+	 * @param int   $order
769
+	 * @return bool
770
+	 */
771
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
772
+	{
773
+		// we need a file_path, class_name, and slug to add a reg step
774
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
775
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
776
+			if ($this->checkout->reg_url_link
777
+				&& $this->checkout->step !== $reg_step['slug']
778
+				&& $reg_step['slug'] !== 'finalize_registration'
779
+				// normally at this point we would NOT load the reg step, but this filter can change that
780
+				&& apply_filters(
781
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
782
+					true,
783
+					$reg_step,
784
+					$this->checkout
785
+				)
786
+			) {
787
+				return true;
788
+			}
789
+			// instantiate step class using file path and class name
790
+			$reg_step_obj = EE_Registry::instance()->load_file(
791
+				$reg_step['file_path'],
792
+				$reg_step['class_name'],
793
+				'class',
794
+				$this->checkout,
795
+				false
796
+			);
797
+			// did we gets the goods ?
798
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
799
+				// set reg step order based on config
800
+				$reg_step_obj->set_order($order);
801
+				// add instantiated reg step object to the master reg steps array
802
+				$this->checkout->add_reg_step($reg_step_obj);
803
+			} else {
804
+				EE_Error::add_error(
805
+					esc_html__('The current step could not be set.', 'event_espresso'),
806
+					__FILE__,
807
+					__FUNCTION__,
808
+					__LINE__
809
+				);
810
+				return false;
811
+			}
812
+		} else {
813
+			if (WP_DEBUG) {
814
+				EE_Error::add_error(
815
+					sprintf(
816
+						esc_html__(
817
+							'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',
818
+							'event_espresso'
819
+						),
820
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
821
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
822
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
823
+						'<ul>',
824
+						'<li>',
825
+						'</li>',
826
+						'</ul>'
827
+					),
828
+					__FILE__,
829
+					__FUNCTION__,
830
+					__LINE__
831
+				);
832
+			}
833
+			return false;
834
+		}
835
+		return true;
836
+	}
837
+
838
+
839
+	/**
840
+	 * _verify_transaction_and_get_registrations
841
+	 *
842
+	 * @access private
843
+	 * @return bool
844
+	 * @throws InvalidDataTypeException
845
+	 * @throws InvalidEntityException
846
+	 * @throws EE_Error
847
+	 */
848
+	private function _verify_transaction_and_get_registrations()
849
+	{
850
+		// was there already a valid transaction in the checkout from the session ?
851
+		if (! $this->checkout->transaction instanceof EE_Transaction) {
852
+			// get transaction from db or session
853
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
854
+				? $this->_get_transaction_and_cart_for_previous_visit()
855
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
856
+			if (! $this->checkout->transaction instanceof EE_Transaction) {
857
+				EE_Error::add_error(
858
+					esc_html__(
859
+						'Your Registration and Transaction information could not be retrieved from the db.',
860
+						'event_espresso'
861
+					),
862
+					__FILE__,
863
+					__FUNCTION__,
864
+					__LINE__
865
+				);
866
+				$this->checkout->transaction = EE_Transaction::new_instance();
867
+				// add some style and make it dance
868
+				$this->add_styles_and_scripts($this);
869
+				EED_Single_Page_Checkout::$_initialized = true;
870
+				return false;
871
+			}
872
+			// and the registrations for the transaction
873
+			$this->_get_registrations($this->checkout->transaction);
874
+		}
875
+		return true;
876
+	}
877
+
878
+
879
+	/**
880
+	 * _get_transaction_and_cart_for_previous_visit
881
+	 *
882
+	 * @access private
883
+	 * @return mixed EE_Transaction|NULL
884
+	 */
885
+	private function _get_transaction_and_cart_for_previous_visit()
886
+	{
887
+		/** @var $TXN_model EEM_Transaction */
888
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
889
+		// because the reg_url_link is present in the request,
890
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
891
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
892
+		// verify transaction
893
+		if ($transaction instanceof EE_Transaction) {
894
+			// and get the cart that was used for that transaction
895
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
896
+			return $transaction;
897
+		}
898
+		EE_Error::add_error(
899
+			esc_html__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
900
+			__FILE__,
901
+			__FUNCTION__,
902
+			__LINE__
903
+		);
904
+		return null;
905
+	}
906
+
907
+
908
+	/**
909
+	 * _get_cart_for_transaction
910
+	 *
911
+	 * @access private
912
+	 * @param EE_Transaction $transaction
913
+	 * @return EE_Cart
914
+	 */
915
+	private function _get_cart_for_transaction($transaction)
916
+	{
917
+		return $this->checkout->get_cart_for_transaction($transaction);
918
+	}
919
+
920
+
921
+	/**
922
+	 * get_cart_for_transaction
923
+	 *
924
+	 * @access public
925
+	 * @param EE_Transaction $transaction
926
+	 * @return EE_Cart
927
+	 */
928
+	public function get_cart_for_transaction(EE_Transaction $transaction)
929
+	{
930
+		return $this->checkout->get_cart_for_transaction($transaction);
931
+	}
932
+
933
+
934
+	/**
935
+	 * _get_transaction_and_cart_for_current_session
936
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
937
+	 *
938
+	 * @access private
939
+	 * @return EE_Transaction
940
+	 * @throws EE_Error
941
+	 */
942
+	private function _get_cart_for_current_session_and_setup_new_transaction()
943
+	{
944
+		//  if there's no transaction, then this is the FIRST visit to SPCO
945
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
946
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
947
+		// and then create a new transaction
948
+		$transaction = $this->_initialize_transaction();
949
+		// verify transaction
950
+		if ($transaction instanceof EE_Transaction) {
951
+			// save it so that we have an ID for other objects to use
952
+			$transaction->save();
953
+			// and save TXN data to the cart
954
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
955
+		} else {
956
+			EE_Error::add_error(
957
+				esc_html__('A Valid Transaction could not be initialized.', 'event_espresso'),
958
+				__FILE__,
959
+				__FUNCTION__,
960
+				__LINE__
961
+			);
962
+		}
963
+		return $transaction;
964
+	}
965
+
966
+
967
+	/**
968
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
969
+	 *
970
+	 * @access private
971
+	 * @return mixed EE_Transaction|NULL
972
+	 */
973
+	private function _initialize_transaction()
974
+	{
975
+		try {
976
+			// ensure cart totals have been calculated
977
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
978
+			// grab the cart grand total
979
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
980
+			// create new TXN
981
+			$transaction = EE_Transaction::new_instance(
982
+				array(
983
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
984
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
985
+					'TXN_paid'      => 0,
986
+					'STS_ID'        => EEM_Transaction::failed_status_code,
987
+				)
988
+			);
989
+			// save it so that we have an ID for other objects to use
990
+			$transaction->save();
991
+			// set cron job for following up on TXNs after their session has expired
992
+			EE_Cron_Tasks::schedule_expired_transaction_check(
993
+				EE_Registry::instance()->SSN->expiration() + 1,
994
+				$transaction->ID()
995
+			);
996
+			return $transaction;
997
+		} catch (Exception $e) {
998
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
999
+		}
1000
+		return null;
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 * _get_registrations
1006
+	 *
1007
+	 * @access private
1008
+	 * @param EE_Transaction $transaction
1009
+	 * @return void
1010
+	 * @throws InvalidDataTypeException
1011
+	 * @throws InvalidEntityException
1012
+	 * @throws EE_Error
1013
+	 */
1014
+	private function _get_registrations(EE_Transaction $transaction)
1015
+	{
1016
+		// first step: grab the registrants  { : o
1017
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1018
+		$this->checkout->total_ticket_count = count($registrations);
1019
+		// verify registrations have been set
1020
+		if (empty($registrations)) {
1021
+			// if no cached registrations, then check the db
1022
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1023
+			// still nothing ? well as long as this isn't a revisit
1024
+			if (empty($registrations) && ! $this->checkout->revisit) {
1025
+				// generate new registrations from scratch
1026
+				$registrations = $this->_initialize_registrations($transaction);
1027
+			}
1028
+		}
1029
+		// sort by their original registration order
1030
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1031
+		// then loop thru the array
1032
+		foreach ($registrations as $registration) {
1033
+			// verify each registration
1034
+			if ($registration instanceof EE_Registration) {
1035
+				// we display all attendee info for the primary registrant
1036
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
1037
+					&& $registration->is_primary_registrant()
1038
+				) {
1039
+					$this->checkout->primary_revisit = true;
1040
+					break;
1041
+				}
1042
+				if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1043
+					// but hide info if it doesn't belong to you
1044
+					$transaction->clear_cache('Registration', $registration->ID());
1045
+					$this->checkout->total_ticket_count--;
1046
+				}
1047
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1048
+			}
1049
+		}
1050
+	}
1051
+
1052
+
1053
+	/**
1054
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1055
+	 *
1056
+	 * @access private
1057
+	 * @param EE_Transaction $transaction
1058
+	 * @return    array
1059
+	 * @throws InvalidDataTypeException
1060
+	 * @throws InvalidEntityException
1061
+	 * @throws EE_Error
1062
+	 */
1063
+	private function _initialize_registrations(EE_Transaction $transaction)
1064
+	{
1065
+		$att_nmbr = 0;
1066
+		$registrations = array();
1067
+		if ($transaction instanceof EE_Transaction) {
1068
+			/** @type EE_Registration_Processor $registration_processor */
1069
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1070
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1071
+			// now let's add the cart items to the $transaction
1072
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1073
+				// do the following for each ticket of this type they selected
1074
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1075
+					$att_nmbr++;
1076
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1077
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1078
+						'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1079
+						array(
1080
+							$transaction,
1081
+							$line_item,
1082
+							$att_nmbr,
1083
+							$this->checkout->total_ticket_count,
1084
+						)
1085
+					);
1086
+					// override capabilities for frontend registrations
1087
+					if (! is_admin()) {
1088
+						$CreateRegistrationCommand->setCapCheck(
1089
+							new PublicCapabilities('', 'create_new_registration')
1090
+						);
1091
+					}
1092
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1093
+					if (! $registration instanceof EE_Registration) {
1094
+						throw new InvalidEntityException($registration, 'EE_Registration');
1095
+					}
1096
+					$registrations[ $registration->ID() ] = $registration;
1097
+				}
1098
+			}
1099
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1100
+		}
1101
+		return $registrations;
1102
+	}
1103
+
1104
+
1105
+	/**
1106
+	 * sorts registrations by REG_count
1107
+	 *
1108
+	 * @access public
1109
+	 * @param EE_Registration $reg_A
1110
+	 * @param EE_Registration $reg_B
1111
+	 * @return int
1112
+	 */
1113
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1114
+	{
1115
+		// this shouldn't ever happen within the same TXN, but oh well
1116
+		if ($reg_A->count() === $reg_B->count()) {
1117
+			return 0;
1118
+		}
1119
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1120
+	}
1121
+
1122
+
1123
+	/**
1124
+	 *    _final_verifications
1125
+	 * just makes sure that everything is set up correctly before proceeding
1126
+	 *
1127
+	 * @access    private
1128
+	 * @return    bool
1129
+	 * @throws EE_Error
1130
+	 */
1131
+	private function _final_verifications()
1132
+	{
1133
+		// filter checkout
1134
+		$this->checkout = apply_filters(
1135
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1136
+			$this->checkout
1137
+		);
1138
+		// verify that current step is still set correctly
1139
+		if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1140
+			EE_Error::add_error(
1141
+				esc_html__(
1142
+					'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.',
1143
+					'event_espresso'
1144
+				),
1145
+				__FILE__,
1146
+				__FUNCTION__,
1147
+				__LINE__
1148
+			);
1149
+			return false;
1150
+		}
1151
+		// if returning to SPCO, then verify that primary registrant is set
1152
+		if (! empty($this->checkout->reg_url_link)) {
1153
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1154
+			if (! $valid_registrant instanceof EE_Registration) {
1155
+				EE_Error::add_error(
1156
+					esc_html__(
1157
+						'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.',
1158
+						'event_espresso'
1159
+					),
1160
+					__FILE__,
1161
+					__FUNCTION__,
1162
+					__LINE__
1163
+				);
1164
+				return false;
1165
+			}
1166
+			$valid_registrant = null;
1167
+			foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1168
+				if ($registration instanceof EE_Registration
1169
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1170
+				) {
1171
+					$valid_registrant = $registration;
1172
+				}
1173
+			}
1174
+			if (! $valid_registrant instanceof EE_Registration) {
1175
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1176
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1177
+					// clear the session, mark the checkout as unverified, and try again
1178
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1179
+					EED_Single_Page_Checkout::$_initialized = false;
1180
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1181
+					$this->_initialize();
1182
+					EE_Error::reset_notices();
1183
+					return false;
1184
+				}
1185
+				EE_Error::add_error(
1186
+					esc_html__(
1187
+						'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.',
1188
+						'event_espresso'
1189
+					),
1190
+					__FILE__,
1191
+					__FUNCTION__,
1192
+					__LINE__
1193
+				);
1194
+				return false;
1195
+			}
1196
+		}
1197
+		// now that things have been kinda sufficiently verified,
1198
+		// let's add the checkout to the session so that it's available to other systems
1199
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1200
+		return true;
1201
+	}
1202
+
1203
+
1204
+	/**
1205
+	 *    _initialize_reg_steps
1206
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1207
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1208
+	 *
1209
+	 * @access    private
1210
+	 * @param bool $reinitializing
1211
+	 * @throws EE_Error
1212
+	 */
1213
+	private function _initialize_reg_steps($reinitializing = false)
1214
+	{
1215
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1216
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1217
+		foreach ($this->checkout->reg_steps as $reg_step) {
1218
+			if (! $reg_step->initialize_reg_step()) {
1219
+				// if not initialized then maybe this step is being removed...
1220
+				if (! $reinitializing && $reg_step->is_current_step()) {
1221
+					// if it was the current step, then we need to start over here
1222
+					$this->_initialize_reg_steps(true);
1223
+					return;
1224
+				}
1225
+				continue;
1226
+			}
1227
+			// add css and JS for current step
1228
+			$this->add_styles_and_scripts($reg_step);
1229
+			if ($reg_step->is_current_step()) {
1230
+				// the text that appears on the reg step form submit button
1231
+				$reg_step->set_submit_button_text();
1232
+			}
1233
+		}
1234
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1235
+		do_action(
1236
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1237
+			$this->checkout->current_step
1238
+		);
1239
+	}
1240
+
1241
+
1242
+	/**
1243
+	 * _check_form_submission
1244
+	 *
1245
+	 * @access private
1246
+	 * @return boolean
1247
+	 */
1248
+	private function _check_form_submission()
1249
+	{
1250
+		// does this request require the reg form to be generated ?
1251
+		if ($this->checkout->generate_reg_form) {
1252
+			// ever heard that song by Blue Rodeo ?
1253
+			try {
1254
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1255
+				// if not displaying a form, then check for form submission
1256
+				if ($this->checkout->process_form_submission
1257
+					&& $this->checkout->current_step->reg_form->was_submitted()
1258
+				) {
1259
+					// clear out any old data in case this step is being run again
1260
+					$this->checkout->current_step->set_valid_data(array());
1261
+					// capture submitted form data
1262
+					$this->checkout->current_step->reg_form->receive_form_submission(
1263
+						apply_filters(
1264
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1265
+							EE_Registry::instance()->REQ->params(),
1266
+							$this->checkout
1267
+						)
1268
+					);
1269
+					// validate submitted form data
1270
+					if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1271
+						// thou shall not pass !!!
1272
+						$this->checkout->continue_reg = false;
1273
+						// any form validation errors?
1274
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1275
+							EE_Error::add_error(
1276
+								$this->checkout->current_step->reg_form->submission_error_message(),
1277
+								__FILE__,
1278
+								__FUNCTION__,
1279
+								__LINE__
1280
+							);
1281
+						}
1282
+						// well not really... what will happen is
1283
+						// we'll just get redirected back to redo the current step
1284
+						$this->go_to_next_step();
1285
+						return false;
1286
+					}
1287
+				}
1288
+			} catch (EE_Error $e) {
1289
+				$e->get_error();
1290
+			}
1291
+		}
1292
+		return true;
1293
+	}
1294
+
1295
+
1296
+	/**
1297
+	 * _process_action
1298
+	 *
1299
+	 * @access private
1300
+	 * @return void
1301
+	 * @throws EE_Error
1302
+	 */
1303
+	private function _process_form_action()
1304
+	{
1305
+		// what cha wanna do?
1306
+		switch ($this->checkout->action) {
1307
+			// AJAX next step reg form
1308
+			case 'display_spco_reg_step':
1309
+				$this->checkout->redirect = false;
1310
+				if (EE_Registry::instance()->REQ->ajax) {
1311
+					$this->checkout->json_response->set_reg_step_html(
1312
+						$this->checkout->current_step->display_reg_form()
1313
+					);
1314
+				}
1315
+				break;
1316
+			default:
1317
+				// meh... do one of those other steps first
1318
+				if (! empty($this->checkout->action)
1319
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1320
+				) {
1321
+					// dynamically creates hook point like:
1322
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1323
+					do_action(
1324
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1325
+						$this->checkout->current_step
1326
+					);
1327
+					// call action on current step
1328
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1329
+						// good registrant, you get to proceed
1330
+						if ($this->checkout->current_step->success_message() !== ''
1331
+							&& apply_filters(
1332
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1333
+								false
1334
+							)
1335
+						) {
1336
+							EE_Error::add_success(
1337
+								$this->checkout->current_step->success_message()
1338
+								. '<br />' . $this->checkout->next_step->_instructions()
1339
+							);
1340
+						}
1341
+						// pack it up, pack it in...
1342
+						$this->_setup_redirect();
1343
+					}
1344
+					// dynamically creates hook point like:
1345
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1346
+					do_action(
1347
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1348
+						$this->checkout->current_step
1349
+					);
1350
+				} else {
1351
+					EE_Error::add_error(
1352
+						sprintf(
1353
+							esc_html__(
1354
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1355
+								'event_espresso'
1356
+							),
1357
+							$this->checkout->action,
1358
+							$this->checkout->current_step->name()
1359
+						),
1360
+						__FILE__,
1361
+						__FUNCTION__,
1362
+						__LINE__
1363
+					);
1364
+				}
1365
+			// end default
1366
+		}
1367
+		// store our progress so far
1368
+		$this->checkout->stash_transaction_and_checkout();
1369
+		// advance to the next step! If you pass GO, collect $200
1370
+		$this->go_to_next_step();
1371
+	}
1372
+
1373
+
1374
+	/**
1375
+	 * @param EED_Single_Page_Checkout|EE_SPCO_Reg_Step $target
1376
+	 * @param object $target an object with the method `translate_js_strings` and `enqueue_styles_and_scripts`.
1377
+	 * @return        void
1378
+	 */
1379
+	public function add_styles_and_scripts($target)
1380
+	{
1381
+		// i18n
1382
+		$target->translate_js_strings();
1383
+		if ($this->checkout->admin_request) {
1384
+			add_action('admin_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1385
+		} else {
1386
+			add_action('wp_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1387
+		}
1388
+	}
1389
+
1390
+	/**
1391
+	 *        translate_js_strings
1392
+	 *
1393
+	 * @access        public
1394
+	 * @return        void
1395
+	 */
1396
+	public function translate_js_strings()
1397
+	{
1398
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1399
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1400
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
1401
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1402
+			'event_espresso'
1403
+		);
1404
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = esc_html__(
1405
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1406
+			'event_espresso'
1407
+		);
1408
+		EE_Registry::$i18n_js_strings['validation_error'] = esc_html__(
1409
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1410
+			'event_espresso'
1411
+		);
1412
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
1413
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1414
+			'event_espresso'
1415
+		);
1416
+		EE_Registry::$i18n_js_strings['reg_step_error'] = esc_html__(
1417
+			'This registration step could not be completed. Please refresh the page and try again.',
1418
+			'event_espresso'
1419
+		);
1420
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = esc_html__(
1421
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1422
+			'event_espresso'
1423
+		);
1424
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1425
+			esc_html__(
1426
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1427
+				'event_espresso'
1428
+			),
1429
+			'<br/>',
1430
+			'<br/>'
1431
+		);
1432
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1433
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1434
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1435
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1436
+		EE_Registry::$i18n_js_strings['timer_years'] = esc_html__('years', 'event_espresso');
1437
+		EE_Registry::$i18n_js_strings['timer_months'] = esc_html__('months', 'event_espresso');
1438
+		EE_Registry::$i18n_js_strings['timer_weeks'] = esc_html__('weeks', 'event_espresso');
1439
+		EE_Registry::$i18n_js_strings['timer_days'] = esc_html__('days', 'event_espresso');
1440
+		EE_Registry::$i18n_js_strings['timer_hours'] = esc_html__('hours', 'event_espresso');
1441
+		EE_Registry::$i18n_js_strings['timer_minutes'] = esc_html__('minutes', 'event_espresso');
1442
+		EE_Registry::$i18n_js_strings['timer_seconds'] = esc_html__('seconds', 'event_espresso');
1443
+		EE_Registry::$i18n_js_strings['timer_year'] = esc_html__('year', 'event_espresso');
1444
+		EE_Registry::$i18n_js_strings['timer_month'] = esc_html__('month', 'event_espresso');
1445
+		EE_Registry::$i18n_js_strings['timer_week'] = esc_html__('week', 'event_espresso');
1446
+		EE_Registry::$i18n_js_strings['timer_day'] = esc_html__('day', 'event_espresso');
1447
+		EE_Registry::$i18n_js_strings['timer_hour'] = esc_html__('hour', 'event_espresso');
1448
+		EE_Registry::$i18n_js_strings['timer_minute'] = esc_html__('minute', 'event_espresso');
1449
+		EE_Registry::$i18n_js_strings['timer_second'] = esc_html__('second', 'event_espresso');
1450
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
1451
+		);
1452
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1453
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1454
+			true
1455
+		);
1456
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1457
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1458
+		);
1459
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1460
+			'M d, Y H:i:s',
1461
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1462
+		);
1463
+	}
1464
+
1465
+
1466
+	/**
1467
+	 *    enqueue_styles_and_scripts
1468
+	 *
1469
+	 * @access        public
1470
+	 * @return        void
1471
+	 * @throws EE_Error
1472
+	 */
1473
+	public function enqueue_styles_and_scripts()
1474
+	{
1475
+		// load css
1476
+		wp_register_style(
1477
+			'single_page_checkout',
1478
+			SPCO_CSS_URL . 'single_page_checkout.css',
1479
+			array('espresso_default'),
1480
+			EVENT_ESPRESSO_VERSION
1481
+		);
1482
+		wp_enqueue_style('single_page_checkout');
1483
+		// load JS
1484
+		wp_register_script(
1485
+			'jquery_plugin',
1486
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1487
+			array('jquery'),
1488
+			'1.0.1',
1489
+			true
1490
+		);
1491
+		wp_register_script(
1492
+			'jquery_countdown',
1493
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1494
+			array('jquery_plugin'),
1495
+			'2.1.0',
1496
+			true
1497
+		);
1498
+		wp_register_script(
1499
+			'single_page_checkout',
1500
+			SPCO_JS_URL . 'single_page_checkout.js',
1501
+			array('espresso_core', 'underscore', 'ee_form_section_validation'),
1502
+			EVENT_ESPRESSO_VERSION,
1503
+			true
1504
+		);
1505
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1506
+			$this->checkout->registration_form->enqueue_js();
1507
+		}
1508
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1509
+			$this->checkout->current_step->reg_form->enqueue_js();
1510
+		}
1511
+		wp_enqueue_script('single_page_checkout');
1512
+		if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) {
1513
+			wp_enqueue_script('jquery_countdown');
1514
+		}
1515
+		/**
1516
+		 * global action hook for enqueueing styles and scripts with
1517
+		 * spco calls.
1518
+		 */
1519
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1520
+		/**
1521
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1522
+		 * The hook will end up being something like:
1523
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1524
+		 */
1525
+		do_action(
1526
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1527
+			$this
1528
+		);
1529
+	}
1530
+
1531
+
1532
+	/**
1533
+	 *    display the Registration Single Page Checkout Form
1534
+	 *
1535
+	 * @access    private
1536
+	 * @return    void
1537
+	 * @throws EE_Error
1538
+	 */
1539
+	private function _display_spco_reg_form()
1540
+	{
1541
+		// if registering via the admin, just display the reg form for the current step
1542
+		if ($this->checkout->admin_request) {
1543
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1544
+		} else {
1545
+			// add powered by EE msg
1546
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1547
+			$empty_cart = count($this->checkout->transaction
1548
+									->registrations($this->checkout->reg_cache_where_params)) < 1;
1549
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1550
+			$cookies_not_set_msg = '';
1551
+			if ($empty_cart) {
1552
+				$cookies_not_set_msg = apply_filters(
1553
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1554
+					sprintf(
1555
+						esc_html__(
1556
+							'%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',
1557
+							'event_espresso'
1558
+						),
1559
+						'<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1560
+						'</div>',
1561
+						'<h6 class="important-notice">',
1562
+						'</h6>',
1563
+						'<p>',
1564
+						'</p>',
1565
+						'<br />',
1566
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank" rel="noopener noreferrer">',
1567
+						'</a>'
1568
+					)
1569
+				);
1570
+			}
1571
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1572
+				array(
1573
+					'name'            => 'single-page-checkout',
1574
+					'html_id'         => 'ee-single-page-checkout-dv',
1575
+					'layout_strategy' =>
1576
+						new EE_Template_Layout(
1577
+							array(
1578
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1579
+								'template_args'        => array(
1580
+									'empty_cart'              => $empty_cart,
1581
+									'revisit'                 => $this->checkout->revisit,
1582
+									'reg_steps'               => $this->checkout->reg_steps,
1583
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1584
+										? $this->checkout->next_step->slug()
1585
+										: '',
1586
+									'empty_msg'               => apply_filters(
1587
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1588
+										sprintf(
1589
+											esc_html__(
1590
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1591
+												'event_espresso'
1592
+											),
1593
+											'<a href="'
1594
+											. get_post_type_archive_link('espresso_events')
1595
+											. '" title="',
1596
+											'">',
1597
+											'</a>'
1598
+										)
1599
+									),
1600
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1601
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1602
+									'session_expiration'      => gmdate(
1603
+										'M d, Y H:i:s',
1604
+										EE_Registry::instance()->SSN->expiration()
1605
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1606
+									),
1607
+								),
1608
+							)
1609
+						),
1610
+				)
1611
+			);
1612
+			// load template and add to output sent that gets filtered into the_content()
1613
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1614
+		}
1615
+	}
1616
+
1617
+
1618
+	/**
1619
+	 *    add_extra_finalize_registration_inputs
1620
+	 *
1621
+	 * @access    public
1622
+	 * @param $next_step
1623
+	 * @internal  param string $label
1624
+	 * @return void
1625
+	 */
1626
+	public function add_extra_finalize_registration_inputs($next_step)
1627
+	{
1628
+		if ($next_step === 'finalize_registration') {
1629
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1630
+		}
1631
+	}
1632
+
1633
+
1634
+	/**
1635
+	 *    display_registration_footer
1636
+	 *
1637
+	 * @access    public
1638
+	 * @return    string
1639
+	 */
1640
+	public static function display_registration_footer()
1641
+	{
1642
+		if (apply_filters(
1643
+			'FHEE__EE_Front__Controller__show_reg_footer',
1644
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1645
+		)) {
1646
+			add_filter(
1647
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1648
+				function ($url) {
1649
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1650
+				}
1651
+			);
1652
+			echo apply_filters(
1653
+				'FHEE__EE_Front_Controller__display_registration_footer',
1654
+				\EEH_Template::powered_by_event_espresso(
1655
+					'',
1656
+					'espresso-registration-footer-dv',
1657
+					array('utm_content' => 'registration_checkout')
1658
+				)
1659
+			);
1660
+		}
1661
+		return '';
1662
+	}
1663
+
1664
+
1665
+	/**
1666
+	 *    unlock_transaction
1667
+	 *
1668
+	 * @access    public
1669
+	 * @return    void
1670
+	 * @throws EE_Error
1671
+	 */
1672
+	public function unlock_transaction()
1673
+	{
1674
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1675
+			$this->checkout->transaction->unlock();
1676
+		}
1677
+	}
1678
+
1679
+
1680
+	/**
1681
+	 *        _setup_redirect
1682
+	 *
1683
+	 * @access    private
1684
+	 * @return void
1685
+	 */
1686
+	private function _setup_redirect()
1687
+	{
1688
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1689
+			$this->checkout->redirect = true;
1690
+			if (empty($this->checkout->redirect_url)) {
1691
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1692
+			}
1693
+			$this->checkout->redirect_url = apply_filters(
1694
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1695
+				$this->checkout->redirect_url,
1696
+				$this->checkout
1697
+			);
1698
+		}
1699
+	}
1700
+
1701
+
1702
+	/**
1703
+	 *   handle ajax message responses and redirects
1704
+	 *
1705
+	 * @access public
1706
+	 * @return void
1707
+	 * @throws EE_Error
1708
+	 */
1709
+	public function go_to_next_step()
1710
+	{
1711
+		if (EE_Registry::instance()->REQ->ajax) {
1712
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1713
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1714
+		}
1715
+		$this->unlock_transaction();
1716
+		// just return for these conditions
1717
+		if ($this->checkout->admin_request
1718
+			|| $this->checkout->action === 'redirect_form'
1719
+			|| $this->checkout->action === 'update_checkout'
1720
+		) {
1721
+			return;
1722
+		}
1723
+		// AJAX response
1724
+		$this->_handle_json_response();
1725
+		// redirect to next step or the Thank You page
1726
+		$this->_handle_html_redirects();
1727
+		// hmmm... must be something wrong, so let's just display the form again !
1728
+		$this->_display_spco_reg_form();
1729
+	}
1730
+
1731
+
1732
+	/**
1733
+	 *   _handle_json_response
1734
+	 *
1735
+	 * @access protected
1736
+	 * @return void
1737
+	 */
1738
+	protected function _handle_json_response()
1739
+	{
1740
+		// if this is an ajax request
1741
+		if (EE_Registry::instance()->REQ->ajax) {
1742
+			$this->checkout->json_response->set_registration_time_limit(
1743
+				$this->checkout->get_registration_time_limit()
1744
+			);
1745
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1746
+			// just send the ajax (
1747
+			$json_response = apply_filters(
1748
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1749
+				$this->checkout->json_response
1750
+			);
1751
+			echo $json_response;
1752
+			exit();
1753
+		}
1754
+	}
1755
+
1756
+
1757
+	/**
1758
+	 *   _handle_redirects
1759
+	 *
1760
+	 * @access protected
1761
+	 * @return void
1762
+	 */
1763
+	protected function _handle_html_redirects()
1764
+	{
1765
+		// going somewhere ?
1766
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1767
+			// store notices in a transient
1768
+			EE_Error::get_notices(false, true, true);
1769
+			wp_safe_redirect($this->checkout->redirect_url);
1770
+			exit();
1771
+		}
1772
+	}
1773
+
1774
+
1775
+	/**
1776
+	 *   set_checkout_anchor
1777
+	 *
1778
+	 * @access public
1779
+	 * @return void
1780
+	 */
1781
+	public function set_checkout_anchor()
1782
+	{
1783
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1784
+	}
1785
+
1786
+	/**
1787
+	 *    getRegistrationExpirationNotice
1788
+	 *
1789
+	 * @since     4.9.59.p
1790
+	 * @access    public
1791
+	 * @return    string
1792
+	 */
1793
+	public static function getRegistrationExpirationNotice()
1794
+	{
1795
+		return sprintf(
1796
+			esc_html__(
1797
+				'%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1798
+				'event_espresso'
1799
+			),
1800
+			'<h4 class="important-notice">',
1801
+			'</h4>',
1802
+			'<br />',
1803
+			'<p>',
1804
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1805
+			'">',
1806
+			'</a>',
1807
+			'</p>'
1808
+		);
1809
+	}
1810 1810
 }
Please login to merge, or discard this patch.
data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_shortcodes.dmsstage.php 1 patch
Indentation   +47 added lines, -48 removed lines patch added patch discarded remove patch
@@ -2,58 +2,57 @@
 block discarded – undo
2 2
 
3 3
 /**
4 4
  * Goes through all the posts and pages, and converts old shortcodes to new ones
5
-
6
-*/
5
+ */
7 6
 
8 7
 class EE_DMS_4_1_0_shortcodes extends EE_Data_Migration_Script_Stage
9 8
 {
10
-    public function __construct()
11
-    {
12
-        global $wpdb;
13
-        $this->_pretty_name = __("Shortcodes", "event_espresso");
14
-        $this->_old_table = $wpdb->posts;
15
-        parent::__construct();
16
-    }
17
-    protected function _migrate_old_row($old_row)
18
-    {
19
-        $new_post_content = $this->_change_event_list_shortcode($old_row['post_content']);
20
-        global $wpdb;
21
-        $wpdb->query($wpdb->prepare("UPDATE ".$this->_old_table." SET post_content=%s WHERE ID=%d", $new_post_content, $old_row['ID']));
22
-    }
9
+	public function __construct()
10
+	{
11
+		global $wpdb;
12
+		$this->_pretty_name = __("Shortcodes", "event_espresso");
13
+		$this->_old_table = $wpdb->posts;
14
+		parent::__construct();
15
+	}
16
+	protected function _migrate_old_row($old_row)
17
+	{
18
+		$new_post_content = $this->_change_event_list_shortcode($old_row['post_content']);
19
+		global $wpdb;
20
+		$wpdb->query($wpdb->prepare("UPDATE ".$this->_old_table." SET post_content=%s WHERE ID=%d", $new_post_content, $old_row['ID']));
21
+	}
23 22
 
24
-    /**
25
-     * replaces [EVENT_LIST... with [ESPRESSO_EVENTS...]
26
-     * @param string $old_content
27
-     */
28
-    private function _change_event_list_shortcode($old_content)
29
-    {
30
-        return str_replace("[EVENT_LIST", "[ESPRESSO_EVENTS", $old_content);
31
-    }
23
+	/**
24
+	 * replaces [EVENT_LIST... with [ESPRESSO_EVENTS...]
25
+	 * @param string $old_content
26
+	 */
27
+	private function _change_event_list_shortcode($old_content)
28
+	{
29
+		return str_replace("[EVENT_LIST", "[ESPRESSO_EVENTS", $old_content);
30
+	}
32 31
 
33
-    public function _migration_step($num_items = 50)
34
-    {
35
-        global $wpdb;
36
-        $start_at_record = $this->count_records_migrated();
37
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table {$this->_sql_to_only_select_non_drafts()} LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
38
-        $items_actually_migrated = 0;
39
-        foreach ($rows as $old_row) {
40
-            $this->_migrate_old_row($old_row);
41
-            $items_actually_migrated++;
42
-        }
43
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
44
-            $this->set_completed();
45
-        }
46
-        return $items_actually_migrated;
47
-    }
48
-    public function _count_records_to_migrate()
49
-    {
50
-        global $wpdb;
51
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table.$this->_sql_to_only_select_non_drafts());
52
-        return $count;
53
-    }
32
+	public function _migration_step($num_items = 50)
33
+	{
34
+		global $wpdb;
35
+		$start_at_record = $this->count_records_migrated();
36
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table {$this->_sql_to_only_select_non_drafts()} LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
37
+		$items_actually_migrated = 0;
38
+		foreach ($rows as $old_row) {
39
+			$this->_migrate_old_row($old_row);
40
+			$items_actually_migrated++;
41
+		}
42
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
43
+			$this->set_completed();
44
+		}
45
+		return $items_actually_migrated;
46
+	}
47
+	public function _count_records_to_migrate()
48
+	{
49
+		global $wpdb;
50
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table.$this->_sql_to_only_select_non_drafts());
51
+		return $count;
52
+	}
54 53
 
55
-    private function _sql_to_only_select_non_drafts()
56
-    {
57
-        return " WHERE post_type NOT IN ('revision','auto-draft','attachment','nav_menu_item') ";
58
-    }
54
+	private function _sql_to_only_select_non_drafts()
55
+	{
56
+		return " WHERE post_type NOT IN ('revision','auto-draft','attachment','nav_menu_item') ";
57
+	}
59 58
 }
Please login to merge, or discard this patch.
modules/ticket_sales_monitor/EED_Ticket_Sales_Monitor.module.php 3 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
     /**
334 334
      * @param  EE_Ticket $ticket
335 335
      * @param  int       $quantity
336
-     * @return bool
336
+     * @return integer
337 337
      * @throws EE_Error
338 338
      */
339 339
     protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
@@ -984,6 +984,7 @@  discard block
 block discarded – undo
984 984
      *                       reservations are now invalid. We don't use the list of invalid ticket line items because
985 985
      *                       we don't know which of those have already been taken into account when reducing ticket
986 986
      *                       reservation counts, and which haven't.
987
+     * @param string $source
987 988
      * @return int
988 989
      * @throws UnexpectedEntityException
989 990
      * @throws DomainException
Please login to merge, or discard this patch.
Indentation   +1051 added lines, -1051 removed lines patch added patch discarded remove patch
@@ -20,1056 +20,1056 @@
 block discarded – undo
20 20
 class EED_Ticket_Sales_Monitor extends EED_Module
21 21
 {
22 22
 
23
-    const debug = false;
24
-
25
-    private static $nl = '';
26
-
27
-    /**
28
-     * an array of raw ticket data from EED_Ticket_Selector
29
-     *
30
-     * @var array $ticket_selections
31
-     */
32
-    protected $ticket_selections = array();
33
-
34
-    /**
35
-     * the raw ticket data from EED_Ticket_Selector is organized in rows
36
-     * according to how they are displayed in the actual Ticket_Selector
37
-     * this tracks the current row being processed
38
-     *
39
-     * @var int $current_row
40
-     */
41
-    protected $current_row = 0;
42
-
43
-    /**
44
-     * an array for tracking names of tickets that have sold out
45
-     *
46
-     * @var array $sold_out_tickets
47
-     */
48
-    protected $sold_out_tickets = array();
49
-
50
-    /**
51
-     * an array for tracking names of tickets that have had their quantities reduced
52
-     *
53
-     * @var array $decremented_tickets
54
-     */
55
-    protected $decremented_tickets = array();
56
-
57
-
58
-    /**
59
-     * set_hooks - for hooking into EE Core, other modules, etc
60
-     *
61
-     * @return    void
62
-     */
63
-    public static function set_hooks()
64
-    {
65
-        self::$nl = defined('EE_TESTS_DIR') ? "\n" : '<br />';
66
-        // release tickets for expired carts
67
-        add_action(
68
-            'EED_Ticket_Selector__process_ticket_selections__before',
69
-            array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'),
70
-            1
71
-        );
72
-        // check ticket reserves AFTER MER does it's check (hence priority 20)
73
-        add_filter(
74
-            'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty',
75
-            array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'),
76
-            20,
77
-            3
78
-        );
79
-        // add notices for sold out tickets
80
-        add_action(
81
-            'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
82
-            array('EED_Ticket_Sales_Monitor', 'post_notices'),
83
-            10
84
-        );
85
-
86
-        // handle tickets deleted from cart
87
-        add_action(
88
-            'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart',
89
-            array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'),
90
-            10,
91
-            2
92
-        );
93
-        // handle emptied carts
94
-        add_action(
95
-            'AHEE__EE_Session__reset_cart__before_reset',
96
-            array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
97
-            10,
98
-            1
99
-        );
100
-        add_action(
101
-            'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart',
102
-            array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
103
-            10,
104
-            1
105
-        );
106
-        // handle cancelled registrations
107
-        add_action(
108
-            'AHEE__EE_Session__reset_checkout__before_reset',
109
-            array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'),
110
-            10,
111
-            1
112
-        );
113
-        // cron tasks
114
-        add_action(
115
-            'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
116
-            array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
117
-            10,
118
-            1
119
-        );
120
-        add_action(
121
-            'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
122
-            array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
123
-            10,
124
-            1
125
-        );
126
-        add_action(
127
-            'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
128
-            array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'),
129
-            10,
130
-            1
131
-        );
132
-    }
133
-
134
-
135
-    /**
136
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
137
-     *
138
-     * @return void
139
-     */
140
-    public static function set_hooks_admin()
141
-    {
142
-        EED_Ticket_Sales_Monitor::set_hooks();
143
-    }
144
-
145
-
146
-    /**
147
-     * @return EED_Ticket_Sales_Monitor|EED_Module
148
-     */
149
-    public static function instance()
150
-    {
151
-        return parent::get_instance(__CLASS__);
152
-    }
153
-
154
-
155
-    /**
156
-     * @param WP_Query $WP_Query
157
-     * @return    void
158
-     */
159
-    public function run($WP_Query)
160
-    {
161
-    }
162
-
163
-
164
-
165
-    /********************************** PRE_TICKET_SALES  **********************************/
166
-
167
-
168
-    /**
169
-     * Retrieves grand totals from the line items that have no TXN ID
170
-     * and timestamps less than the current time minus the session lifespan.
171
-     * These are carts that have been abandoned before the "registrant" even attempted to checkout.
172
-     * We're going to release the tickets for these line items before attempting to add more to the cart.
173
-     *
174
-     * @return void
175
-     * @throws DomainException
176
-     * @throws EE_Error
177
-     * @throws InvalidArgumentException
178
-     * @throws InvalidDataTypeException
179
-     * @throws InvalidInterfaceException
180
-     * @throws UnexpectedEntityException
181
-     */
182
-    public static function release_tickets_for_expired_carts()
183
-    {
184
-        if (self::debug) {
185
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()';
186
-        }
187
-        do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin');
188
-        $expired_ticket_IDs = array();
189
-        /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
190
-        $session_lifespan = LoaderFactory::getLoader()->getShared(
191
-            'EventEspresso\core\domain\values\session\SessionLifespan'
192
-        );
193
-        $timestamp = $session_lifespan->expiration();
194
-        $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp);
195
-        if (self::debug) {
196
-            echo self::$nl . ' . time(): ' . time();
197
-            echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a');
198
-            echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration();
199
-            echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration());
200
-            echo self::$nl . ' . timestamp: ' . $timestamp;
201
-            echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items);
202
-        }
203
-        if (! empty($expired_ticket_line_items)) {
204
-            foreach ($expired_ticket_line_items as $expired_ticket_line_item) {
205
-                if (! $expired_ticket_line_item instanceof EE_Line_Item) {
206
-                    continue;
207
-                }
208
-                $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID();
209
-                if (self::debug) {
210
-                    echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID();
211
-                    echo self::$nl . ' . $expired_ticket_line_item->timestamp(): '
212
-                         . date(
213
-                             'Y-m-d h:i a',
214
-                             $expired_ticket_line_item->timestamp(true)
215
-                         );
216
-                }
217
-            }
218
-            if (! empty($expired_ticket_IDs)) {
219
-                EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
220
-                    \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs),
221
-                    array(),
222
-                    __FUNCTION__
223
-                );
224
-                // now  let's get rid of expired line items so that they can't interfere with tracking
225
-                EED_Ticket_Sales_Monitor::clear_expired_line_items_with_no_transaction($timestamp);
226
-            }
227
-        }
228
-        do_action(
229
-            'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end',
230
-            $expired_ticket_IDs,
231
-            $expired_ticket_line_items
232
-        );
233
-    }
234
-
235
-
236
-
237
-    /********************************** VALIDATE_TICKET_SALE  **********************************/
238
-
239
-
240
-    /**
241
-     * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data'
242
-     *
243
-     * @param int       $qty
244
-     * @param EE_Ticket $ticket
245
-     * @return bool
246
-     * @throws UnexpectedEntityException
247
-     * @throws EE_Error
248
-     */
249
-    public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket)
250
-    {
251
-        $qty = absint($qty);
252
-        if ($qty > 0) {
253
-            $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
254
-        }
255
-        if (self::debug) {
256
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()';
257
-            echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>';
258
-        }
259
-        return $qty;
260
-    }
261
-
262
-
263
-    /**
264
-     * checks whether an individual ticket is available for purchase based on datetime, and ticket details
265
-     *
266
-     * @param   EE_Ticket $ticket
267
-     * @param int         $qty
268
-     * @return int
269
-     * @throws UnexpectedEntityException
270
-     * @throws EE_Error
271
-     */
272
-    protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
273
-    {
274
-        if (self::debug) {
275
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
276
-        }
277
-        if (! $ticket instanceof EE_Ticket) {
278
-            return 0;
279
-        }
280
-        if (self::debug) {
281
-            echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>';
282
-            echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved();
283
-        }
284
-        $ticket->refresh_from_db();
285
-        // first let's determine the ticket availability based on sales
286
-        $available = $ticket->qty('saleable');
287
-        if (self::debug) {
288
-            echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty();
289
-            echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold();
290
-            echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved();
291
-            echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
292
-            echo self::$nl . ' . . . available: ' . $available;
293
-        }
294
-        if ($available < 1) {
295
-            $this->_ticket_sold_out($ticket);
296
-            return 0;
297
-        }
298
-        if (self::debug) {
299
-            echo self::$nl . ' . . . qty: ' . $qty;
300
-        }
301
-        if ($available < $qty) {
302
-            $qty = $available;
303
-            if (self::debug) {
304
-                echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty;
305
-            }
306
-            $this->_ticket_quantity_decremented($ticket);
307
-        }
308
-        if ($this->_reserve_ticket($ticket, $qty)) {
309
-            return $qty;
310
-        } else {
311
-            return 0;
312
-        }
313
-    }
314
-
315
-
316
-    /**
317
-     * increments ticket reserved based on quantity passed
318
-     *
319
-     * @param    EE_Ticket $ticket
320
-     * @param int          $quantity
321
-     * @return bool indicating success or failure
322
-     * @throws EE_Error
323
-     */
324
-    protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
325
-    {
326
-        if (self::debug) {
327
-            echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity;
328
-        }
329
-        return $ticket->increaseReserved($quantity, 'TicketSalesMonitor:' . __LINE__);
330
-    }
331
-
332
-
333
-    /**
334
-     * @param  EE_Ticket $ticket
335
-     * @param  int       $quantity
336
-     * @return bool
337
-     * @throws EE_Error
338
-     */
339
-    protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
340
-    {
341
-        if (self::debug) {
342
-            echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID();
343
-            echo self::$nl . ' . . . ticket->reserved before: ' . $ticket->reserved();
344
-        }
345
-        $ticket->decreaseReserved($quantity, true, 'TicketSalesMonitor:' . __LINE__);
346
-        if (self::debug) {
347
-            echo self::$nl . ' . . . ticket->reserved after: ' . $ticket->reserved();
348
-        }
349
-        return $ticket->save() ? 1 : 0;
350
-    }
351
-
352
-
353
-    /**
354
-     * removes quantities within the ticket selector based on zero ticket availability
355
-     *
356
-     * @param    EE_Ticket $ticket
357
-     * @return    void
358
-     * @throws UnexpectedEntityException
359
-     * @throws EE_Error
360
-     */
361
-    protected function _ticket_sold_out(EE_Ticket $ticket)
362
-    {
363
-        if (self::debug) {
364
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
365
-            echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
366
-        }
367
-        $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
368
-    }
369
-
370
-
371
-    /**
372
-     * adjusts quantities within the ticket selector based on decreased ticket availability
373
-     *
374
-     * @param    EE_Ticket $ticket
375
-     * @return void
376
-     * @throws UnexpectedEntityException
377
-     * @throws EE_Error
378
-     */
379
-    protected function _ticket_quantity_decremented(EE_Ticket $ticket)
380
-    {
381
-        if (self::debug) {
382
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
383
-            echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
384
-        }
385
-        $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
386
-    }
387
-
388
-
389
-    /**
390
-     * builds string out of ticket and event name
391
-     *
392
-     * @param    EE_Ticket $ticket
393
-     * @return string
394
-     * @throws UnexpectedEntityException
395
-     * @throws EE_Error
396
-     */
397
-    protected function _get_ticket_and_event_name(EE_Ticket $ticket)
398
-    {
399
-        $event = $ticket->get_related_event();
400
-        if ($event instanceof EE_Event) {
401
-            $ticket_name = sprintf(
402
-                _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'),
403
-                $ticket->name(),
404
-                $event->name()
405
-            );
406
-        } else {
407
-            $ticket_name = $ticket->name();
408
-        }
409
-        return $ticket_name;
410
-    }
411
-
412
-
413
-
414
-    /********************************** EVENT CART  **********************************/
415
-
416
-
417
-    /**
418
-     * releases or reserves ticket(s) based on quantity passed
419
-     *
420
-     * @param  EE_Line_Item $line_item
421
-     * @param  int          $quantity
422
-     * @return void
423
-     * @throws EE_Error
424
-     * @throws InvalidArgumentException
425
-     * @throws InvalidDataTypeException
426
-     * @throws InvalidInterfaceException
427
-     */
428
-    public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1)
429
-    {
430
-        $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID()));
431
-        if ($ticket instanceof EE_Ticket) {
432
-            $ticket->add_extra_meta(
433
-                EE_Ticket::META_KEY_TICKET_RESERVATIONS,
434
-                __LINE__ . ') ' . __METHOD__ . '()'
435
-            );
436
-            if ($quantity > 0) {
437
-                EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity);
438
-            } else {
439
-                EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
440
-            }
441
-        }
442
-    }
443
-
444
-
445
-    /**
446
-     * releases reserved ticket(s) based on quantity passed
447
-     *
448
-     * @param  EE_Ticket $ticket
449
-     * @param  int       $quantity
450
-     * @return void
451
-     * @throws EE_Error
452
-     */
453
-    public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1)
454
-    {
455
-        $ticket->add_extra_meta(
456
-            EE_Ticket::META_KEY_TICKET_RESERVATIONS,
457
-            __LINE__ . ') ' . __METHOD__ . '()'
458
-        );
459
-        EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
460
-    }
461
-
462
-
463
-
464
-    /********************************** POST_NOTICES  **********************************/
465
-
466
-
467
-    /**
468
-     * @return void
469
-     * @throws EE_Error
470
-     * @throws InvalidArgumentException
471
-     * @throws ReflectionException
472
-     * @throws InvalidDataTypeException
473
-     * @throws InvalidInterfaceException
474
-     */
475
-    public static function post_notices()
476
-    {
477
-        EED_Ticket_Sales_Monitor::instance()->_post_notices();
478
-    }
479
-
480
-
481
-    /**
482
-     * @return void
483
-     * @throws EE_Error
484
-     * @throws InvalidArgumentException
485
-     * @throws ReflectionException
486
-     * @throws InvalidDataTypeException
487
-     * @throws InvalidInterfaceException
488
-     */
489
-    protected function _post_notices()
490
-    {
491
-        if (self::debug) {
492
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
493
-        }
494
-        $refresh_msg = '';
495
-        $none_added_msg = '';
496
-        if (defined('DOING_AJAX') && DOING_AJAX) {
497
-            $refresh_msg = __(
498
-                'Please refresh the page to view updated ticket quantities.',
499
-                'event_espresso'
500
-            );
501
-            $none_added_msg = __('No tickets were added for the event.', 'event_espresso');
502
-        }
503
-        if (! empty($this->sold_out_tickets)) {
504
-            EE_Error::add_attention(
505
-                sprintf(
506
-                    apply_filters(
507
-                        'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice',
508
-                        __(
509
-                            'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$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.%1$s%1$s%3$s%1$s%4$s%1$s',
510
-                            'event_espresso'
511
-                        )
512
-                    ),
513
-                    '<br />',
514
-                    implode('<br />', $this->sold_out_tickets),
515
-                    $none_added_msg,
516
-                    $refresh_msg
517
-                )
518
-            );
519
-            // alter code flow in the Ticket Selector for better UX
520
-            add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true');
521
-            add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false');
522
-            $this->sold_out_tickets = array();
523
-            // and reset the cart
524
-            EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN);
525
-        }
526
-        if (! empty($this->decremented_tickets)) {
527
-            EE_Error::add_attention(
528
-                sprintf(
529
-                    apply_filters(
530
-                        'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice',
531
-                        __(
532
-                            'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$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.%1$s%1$s%3$s%1$s%4$s%1$s',
533
-                            'event_espresso'
534
-                        )
535
-                    ),
536
-                    '<br />',
537
-                    implode('<br />', $this->decremented_tickets),
538
-                    $none_added_msg,
539
-                    $refresh_msg
540
-                )
541
-            );
542
-            $this->decremented_tickets = array();
543
-        }
544
-    }
545
-
546
-
547
-
548
-    /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION  **********************************/
549
-
550
-
551
-    /**
552
-     * releases reserved tickets for all registrations of an EE_Transaction
553
-     * by default, will NOT release tickets for finalized transactions
554
-     *
555
-     * @param    EE_Transaction $transaction
556
-     * @return int
557
-     * @throws EE_Error
558
-     * @throws InvalidSessionDataException
559
-     */
560
-    protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
561
-    {
562
-        if (self::debug) {
563
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
564
-            echo self::$nl . ' . transaction->ID: ' . $transaction->ID();
565
-            echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID();
566
-        }
567
-        // check if 'finalize_registration' step has been completed...
568
-        $finalized = $transaction->reg_step_completed('finalize_registration');
569
-        if (self::debug) {
570
-            // DEBUG LOG
571
-            EEH_Debug_Tools::log(
572
-                __CLASS__,
573
-                __FUNCTION__,
574
-                __LINE__,
575
-                array('finalized' => $finalized),
576
-                false,
577
-                'EE_Transaction: ' . $transaction->ID()
578
-            );
579
-        }
580
-        // how many tickets were released
581
-        $count = 0;
582
-        if (self::debug) {
583
-            echo self::$nl . ' . . . TXN finalized: ' . $finalized;
584
-        }
585
-        $release_tickets_with_TXN_status = array(
586
-            EEM_Transaction::failed_status_code,
587
-            EEM_Transaction::abandoned_status_code,
588
-            EEM_Transaction::incomplete_status_code,
589
-        );
590
-        $events = array();
591
-        // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed
592
-        if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
593
-            // cancel any reserved tickets for registrations that were not approved
594
-            $registrations = $transaction->registrations();
595
-            if (self::debug) {
596
-                echo self::$nl . ' . . . # registrations: ' . count($registrations);
597
-                $reg = reset($registrations);
598
-                $ticket = $reg->ticket();
599
-                if ($ticket instanceof EE_Ticket) {
600
-                    $ticket->add_extra_meta(
601
-                        EE_Ticket::META_KEY_TICKET_RESERVATIONS,
602
-                        __LINE__ . ') Release All Tickets TXN:' . $transaction->ID()
603
-                    );
604
-                }
605
-            }
606
-            if (! empty($registrations)) {
607
-                foreach ($registrations as $registration) {
608
-                    if ($registration instanceof EE_Registration
609
-                        && $this->_release_reserved_ticket_for_registration($registration, $transaction)
610
-                    ) {
611
-                        $count++;
612
-                        $events[ $registration->event_ID() ] = $registration->event();
613
-                    }
614
-                }
615
-            }
616
-        }
617
-        if ($events !== array()) {
618
-            foreach ($events as $event) {
619
-                /** @var EE_Event $event */
620
-                $event->perform_sold_out_status_check();
621
-            }
622
-        }
623
-        return $count;
624
-    }
625
-
626
-
627
-    /**
628
-     * releases reserved tickets for an EE_Registration
629
-     * by default, will NOT release tickets for APPROVED registrations
630
-     *
631
-     * @param EE_Registration $registration
632
-     * @param EE_Transaction  $transaction
633
-     * @return int
634
-     * @throws EE_Error
635
-     */
636
-    protected function _release_reserved_ticket_for_registration(
637
-        EE_Registration $registration,
638
-        EE_Transaction $transaction
639
-    ) {
640
-        $STS_ID = $transaction->status_ID();
641
-        if (self::debug) {
642
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
643
-            echo self::$nl . ' . . registration->ID: ' . $registration->ID();
644
-            echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID();
645
-            echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID;
646
-        }
647
-        if (// release Tickets for Failed Transactions and Abandoned Transactions
648
-            $STS_ID === EEM_Transaction::failed_status_code
649
-            || $STS_ID === EEM_Transaction::abandoned_status_code
650
-            || (
651
-                // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved
652
-                $STS_ID === EEM_Transaction::incomplete_status_code
653
-                && $registration->status_ID() !== EEM_Registration::status_id_approved
654
-            )
655
-        ) {
656
-            if (self::debug) {
657
-                echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET';
658
-                $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true);
659
-                echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: ';
660
-                var_dump($rsrvd);
661
-            }
662
-            $registration->release_reserved_ticket(true, 'TicketSalesMonitor:' . __LINE__);
663
-            return 1;
664
-        }
665
-        return 0;
666
-    }
667
-
668
-
669
-
670
-    /********************************** SESSION_CART_RESET  **********************************/
671
-
672
-
673
-    /**
674
-     * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset'
675
-     *
676
-     * @param EE_Session $session
677
-     * @return void
678
-     * @throws EE_Error
679
-     * @throws InvalidArgumentException
680
-     * @throws ReflectionException
681
-     * @throws InvalidDataTypeException
682
-     * @throws InvalidInterfaceException
683
-     */
684
-    public static function session_cart_reset(EE_Session $session)
685
-    {
686
-        // don't release tickets if checkout was already reset
687
-        if (did_action('AHEE__EE_Session__reset_checkout__before_reset')) {
688
-            return;
689
-        }
690
-        if (self::debug) {
691
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
692
-        }
693
-        // first check of the session has a valid Checkout object
694
-        $checkout = $session->checkout();
695
-        if ($checkout instanceof EE_Checkout) {
696
-            // and use that to clear ticket reservations because it will update the associated registration meta data
697
-            EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout);
698
-            return;
699
-        }
700
-        $cart = $session->cart();
701
-        if ($cart instanceof EE_Cart) {
702
-            if (self::debug) {
703
-                echo self::$nl . self::$nl . ' cart instance of EE_Cart: ';
704
-            }
705
-            EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session);
706
-        } else {
707
-            if (self::debug) {
708
-                echo self::$nl . self::$nl . ' invalid EE_Cart: ';
709
-                var_export($cart, true);
710
-            }
711
-        }
712
-    }
713
-
714
-
715
-    /**
716
-     * releases reserved tickets in the EE_Cart
717
-     *
718
-     * @param EE_Cart $cart
719
-     * @return void
720
-     * @throws EE_Error
721
-     * @throws InvalidArgumentException
722
-     * @throws ReflectionException
723
-     * @throws InvalidDataTypeException
724
-     * @throws InvalidInterfaceException
725
-     */
726
-    protected function _session_cart_reset(EE_Cart $cart, EE_Session $session)
727
-    {
728
-        if (self::debug) {
729
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
730
-        }
731
-        $ticket_line_items = $cart->get_tickets();
732
-        if (empty($ticket_line_items)) {
733
-            return;
734
-        }
735
-        if (self::debug) {
736
-            echo '<br /> . ticket_line_item count: ' . count($ticket_line_items);
737
-        }
738
-        foreach ($ticket_line_items as $ticket_line_item) {
739
-            if (self::debug) {
740
-                echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID();
741
-            }
742
-            if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
743
-                if (self::debug) {
744
-                    echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
745
-                }
746
-                $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
747
-                if ($ticket instanceof EE_Ticket) {
748
-                    if (self::debug) {
749
-                        echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID();
750
-                        echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
751
-                    }
752
-                    $ticket->add_extra_meta(
753
-                        EE_Ticket::META_KEY_TICKET_RESERVATIONS,
754
-                        __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id()
755
-                    );
756
-                    $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
757
-                }
758
-            }
759
-        }
760
-        if (self::debug) {
761
-            echo self::$nl . self::$nl . ' RESET COMPLETED ';
762
-        }
763
-    }
764
-
765
-
766
-
767
-    /********************************** SESSION_CHECKOUT_RESET  **********************************/
768
-
769
-
770
-    /**
771
-     * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset'
772
-     *
773
-     * @param EE_Session $session
774
-     * @return void
775
-     * @throws EE_Error
776
-     * @throws InvalidSessionDataException
777
-     */
778
-    public static function session_checkout_reset(EE_Session $session)
779
-    {
780
-        // don't release tickets if cart was already reset
781
-        if (did_action('AHEE__EE_Session__reset_cart__before_reset')) {
782
-            return;
783
-        }
784
-        $checkout = $session->checkout();
785
-        if ($checkout instanceof EE_Checkout) {
786
-            EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout);
787
-        }
788
-    }
789
-
790
-
791
-    /**
792
-     * releases reserved tickets for the EE_Checkout->transaction
793
-     *
794
-     * @param EE_Checkout $checkout
795
-     * @return void
796
-     * @throws EE_Error
797
-     * @throws InvalidSessionDataException
798
-     */
799
-    protected function _session_checkout_reset(EE_Checkout $checkout)
800
-    {
801
-        if (self::debug) {
802
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
803
-        }
804
-        // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
805
-        if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
806
-            return;
807
-        }
808
-        $this->_release_all_reserved_tickets_for_transaction($checkout->transaction);
809
-    }
810
-
811
-
812
-
813
-    /********************************** SESSION_EXPIRED_RESET  **********************************/
814
-
815
-
816
-    /**
817
-     * @param    EE_Session $session
818
-     * @return    void
819
-     */
820
-    public static function session_expired_reset(EE_Session $session)
821
-    {
822
-    }
823
-
824
-
825
-
826
-    /********************************** PROCESS_ABANDONED_TRANSACTIONS  **********************************/
827
-
828
-
829
-    /**
830
-     * releases reserved tickets for all registrations of an ABANDONED EE_Transaction
831
-     * by default, will NOT release tickets for free transactions, or any that have received a payment
832
-     *
833
-     * @param EE_Transaction $transaction
834
-     * @return void
835
-     * @throws EE_Error
836
-     * @throws InvalidSessionDataException
837
-     */
838
-    public static function process_abandoned_transactions(EE_Transaction $transaction)
839
-    {
840
-        // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone
841
-        if ($transaction->is_free() || $transaction->paid() > 0) {
842
-            if (self::debug) {
843
-                // DEBUG LOG
844
-                EEH_Debug_Tools::log(
845
-                    __CLASS__,
846
-                    __FUNCTION__,
847
-                    __LINE__,
848
-                    array($transaction),
849
-                    false,
850
-                    'EE_Transaction: ' . $transaction->ID()
851
-                );
852
-            }
853
-            return;
854
-        }
855
-        // have their been any successful payments made ?
856
-        $payments = $transaction->payments();
857
-        foreach ($payments as $payment) {
858
-            if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) {
859
-                if (self::debug) {
860
-                    // DEBUG LOG
861
-                    EEH_Debug_Tools::log(
862
-                        __CLASS__,
863
-                        __FUNCTION__,
864
-                        __LINE__,
865
-                        array($payment),
866
-                        false,
867
-                        'EE_Transaction: ' . $transaction->ID()
868
-                    );
869
-                }
870
-                return;
871
-            }
872
-        }
873
-        // since you haven't even attempted to pay for your ticket...
874
-        EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
875
-    }
876
-
877
-
878
-
879
-    /********************************** PROCESS_FAILED_TRANSACTIONS  **********************************/
880
-
881
-
882
-    /**
883
-     * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction
884
-     *
885
-     * @param EE_Transaction $transaction
886
-     * @return void
887
-     * @throws EE_Error
888
-     * @throws InvalidSessionDataException
889
-     */
890
-    public static function process_failed_transactions(EE_Transaction $transaction)
891
-    {
892
-        // since you haven't even attempted to pay for your ticket...
893
-        EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
894
-    }
895
-
896
-
897
-
898
-    /********************************** RESET RESERVATION COUNTS  *********************************/
899
-
900
-
901
-    /**
902
-     * Resets the ticket and datetime reserved counts.
903
-     *
904
-     * For all the tickets with reservations, recalculates what their actual reserved counts should be based
905
-     * on the valid transactions.
906
-     *
907
-     * @return int number of tickets whose reservations were released.
908
-     * @throws EE_Error
909
-     * @throws DomainException
910
-     * @throws InvalidDataTypeException
911
-     * @throws InvalidInterfaceException
912
-     * @throws InvalidArgumentException
913
-     * @throws UnexpectedEntityException
914
-     * @throws ReflectionException
915
-     */
916
-    public static function reset_reservation_counts()
917
-    {
918
-        /** @var EE_Line_Item[] $valid_reserved_tickets */
919
-        $valid_reserved_tickets = array();
920
-        /** @var EE_Transaction[] $transactions_in_progress */
921
-        $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress();
922
-        foreach ($transactions_in_progress as $transaction) {
923
-            // if this TXN has been fully completed, then skip it
924
-            if ($transaction->reg_step_completed('finalize_registration')) {
925
-                continue;
926
-            }
927
-            $total_line_item = $transaction->total_line_item();
928
-            // $transaction_in_progress->line
929
-            if (! $total_line_item instanceof EE_Line_Item) {
930
-                throw new DomainException(
931
-                    esc_html__(
932
-                        'Transaction does not have a valid Total Line Item associated with it.',
933
-                        'event_espresso'
934
-                    )
935
-                );
936
-            }
937
-            $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
938
-                $total_line_item
939
-            );
940
-        }
941
-        $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts();
942
-        foreach ($total_line_items as $total_line_item) {
943
-            $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
944
-                $total_line_item
945
-            );
946
-        }
947
-        $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations();
948
-        return EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
949
-            $tickets_with_reservations,
950
-            $valid_reserved_tickets,
951
-            __FUNCTION__
952
-        );
953
-    }
954
-
955
-
956
-    /**
957
-     * @param EE_Line_Item $total_line_item
958
-     * @return EE_Line_Item[]
959
-     */
960
-    private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item)
961
-    {
962
-        /** @var EE_Line_Item[] $valid_reserved_tickets */
963
-        $valid_reserved_tickets = array();
964
-        $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item);
965
-        foreach ($ticket_line_items as $ticket_line_item) {
966
-            if ($ticket_line_item instanceof EE_Line_Item) {
967
-                $valid_reserved_tickets[ $ticket_line_item->ID() ] = $ticket_line_item;
968
-            }
969
-        }
970
-        return $valid_reserved_tickets;
971
-    }
972
-
973
-
974
-    /**
975
-     * Releases ticket and datetime reservations (ie, reduces the number of reserved spots on them).
976
-     *
977
-     * Given the list of tickets which have reserved spots on them, uses the complete list of line items for tickets
978
-     * whose transactions aren't complete and also aren't yet expired (ie, they're incomplete and younger than the
979
-     * session's expiry time) to update the ticket (and their datetimes') reserved counts.
980
-     *
981
-     * @param EE_Ticket[]    $tickets_with_reservations all tickets with TKT_reserved > 0
982
-     * @param EE_Line_Item[] $valid_reserved_ticket_line_items all line items for tickets and incomplete transactions
983
-     *                       whose session has NOT expired. We will use these to determine the number of ticket
984
-     *                       reservations are now invalid. We don't use the list of invalid ticket line items because
985
-     *                       we don't know which of those have already been taken into account when reducing ticket
986
-     *                       reservation counts, and which haven't.
987
-     * @return int
988
-     * @throws UnexpectedEntityException
989
-     * @throws DomainException
990
-     * @throws EE_Error
991
-     */
992
-    protected static function release_reservations_for_tickets(
993
-        array $tickets_with_reservations,
994
-        array $valid_reserved_ticket_line_items = array(),
995
-        $source
996
-    ) {
997
-        $total_tickets_released = 0;
998
-        $sold_out_events = array();
999
-        foreach ($tickets_with_reservations as $ticket_with_reservations) {
1000
-            if (! $ticket_with_reservations instanceof EE_Ticket) {
1001
-                continue;
1002
-            }
1003
-            // The $valid_reserved_ticket_line_items tells us what the reserved count on their tickets (and datetimes)
1004
-            // SHOULD be. Instead of just directly updating the list, we're going to use EE_Ticket::decreaseReserved()
1005
-            // to try to avoid race conditions, so instead of just finding the number to update TO, we're going to find
1006
-            // the number to RELEASE. It's the same end result, just different path.
1007
-            // Begin by assuming we're going to release all the reservations on this ticket.
1008
-            $expired_reservations_count = $ticket_with_reservations->reserved();
1009
-            // Now reduce that number using the list of current valid reservations.
1010
-            foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) {
1011
-                if ($valid_reserved_ticket_line_item instanceof EE_Line_Item
1012
-                    && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID()
1013
-                ) {
1014
-                    $expired_reservations_count -= $valid_reserved_ticket_line_item->quantity();
1015
-                }
1016
-            }
1017
-            // Only bother saving the tickets and datetimes if we're actually going to release some spots.
1018
-            if ($expired_reservations_count > 0) {
1019
-                $ticket_with_reservations->add_extra_meta(
1020
-                    EE_Ticket::META_KEY_TICKET_RESERVATIONS,
1021
-                    __LINE__ . ') ' . $source . '()'
1022
-                );
1023
-                $ticket_with_reservations->decreaseReserved($expired_reservations_count, true, 'TicketSalesMonitor:' . __LINE__);
1024
-                $total_tickets_released += $expired_reservations_count;
1025
-                $event = $ticket_with_reservations->get_related_event();
1026
-                // track sold out events
1027
-                if ($event instanceof EE_Event && $event->is_sold_out()) {
1028
-                    $sold_out_events[] = $event;
1029
-                }
1030
-            }
1031
-        }
1032
-        // Double check whether sold out events should remain sold out after releasing tickets
1033
-        if ($sold_out_events !== array()) {
1034
-            foreach ($sold_out_events as $sold_out_event) {
1035
-                /** @var EE_Event $sold_out_event */
1036
-                $sold_out_event->perform_sold_out_status_check();
1037
-            }
1038
-        }
1039
-        return $total_tickets_released;
1040
-    }
1041
-
1042
-
1043
-
1044
-    /********************************** SHUTDOWN  **********************************/
1045
-
1046
-
1047
-    /**
1048
-     * @param int $timestamp
1049
-     * @return false|int
1050
-     * @throws EE_Error
1051
-     * @throws InvalidArgumentException
1052
-     * @throws InvalidDataTypeException
1053
-     * @throws InvalidInterfaceException
1054
-     */
1055
-    public static function clear_expired_line_items_with_no_transaction($timestamp = 0)
1056
-    {
1057
-        /** @type WPDB $wpdb */
1058
-        global $wpdb;
1059
-        if (! absint($timestamp)) {
1060
-            /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
1061
-            $session_lifespan = LoaderFactory::getLoader()->getShared(
1062
-                'EventEspresso\core\domain\values\session\SessionLifespan'
1063
-            );
1064
-            $timestamp = $session_lifespan->expiration();
1065
-        }
1066
-        return $wpdb->query(
1067
-            $wpdb->prepare(
1068
-                'DELETE FROM ' . EEM_Line_Item::instance()->table() . '
23
+	const debug = false;
24
+
25
+	private static $nl = '';
26
+
27
+	/**
28
+	 * an array of raw ticket data from EED_Ticket_Selector
29
+	 *
30
+	 * @var array $ticket_selections
31
+	 */
32
+	protected $ticket_selections = array();
33
+
34
+	/**
35
+	 * the raw ticket data from EED_Ticket_Selector is organized in rows
36
+	 * according to how they are displayed in the actual Ticket_Selector
37
+	 * this tracks the current row being processed
38
+	 *
39
+	 * @var int $current_row
40
+	 */
41
+	protected $current_row = 0;
42
+
43
+	/**
44
+	 * an array for tracking names of tickets that have sold out
45
+	 *
46
+	 * @var array $sold_out_tickets
47
+	 */
48
+	protected $sold_out_tickets = array();
49
+
50
+	/**
51
+	 * an array for tracking names of tickets that have had their quantities reduced
52
+	 *
53
+	 * @var array $decremented_tickets
54
+	 */
55
+	protected $decremented_tickets = array();
56
+
57
+
58
+	/**
59
+	 * set_hooks - for hooking into EE Core, other modules, etc
60
+	 *
61
+	 * @return    void
62
+	 */
63
+	public static function set_hooks()
64
+	{
65
+		self::$nl = defined('EE_TESTS_DIR') ? "\n" : '<br />';
66
+		// release tickets for expired carts
67
+		add_action(
68
+			'EED_Ticket_Selector__process_ticket_selections__before',
69
+			array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'),
70
+			1
71
+		);
72
+		// check ticket reserves AFTER MER does it's check (hence priority 20)
73
+		add_filter(
74
+			'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty',
75
+			array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'),
76
+			20,
77
+			3
78
+		);
79
+		// add notices for sold out tickets
80
+		add_action(
81
+			'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
82
+			array('EED_Ticket_Sales_Monitor', 'post_notices'),
83
+			10
84
+		);
85
+
86
+		// handle tickets deleted from cart
87
+		add_action(
88
+			'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart',
89
+			array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'),
90
+			10,
91
+			2
92
+		);
93
+		// handle emptied carts
94
+		add_action(
95
+			'AHEE__EE_Session__reset_cart__before_reset',
96
+			array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
97
+			10,
98
+			1
99
+		);
100
+		add_action(
101
+			'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart',
102
+			array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
103
+			10,
104
+			1
105
+		);
106
+		// handle cancelled registrations
107
+		add_action(
108
+			'AHEE__EE_Session__reset_checkout__before_reset',
109
+			array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'),
110
+			10,
111
+			1
112
+		);
113
+		// cron tasks
114
+		add_action(
115
+			'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
116
+			array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
117
+			10,
118
+			1
119
+		);
120
+		add_action(
121
+			'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
122
+			array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
123
+			10,
124
+			1
125
+		);
126
+		add_action(
127
+			'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
128
+			array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'),
129
+			10,
130
+			1
131
+		);
132
+	}
133
+
134
+
135
+	/**
136
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
137
+	 *
138
+	 * @return void
139
+	 */
140
+	public static function set_hooks_admin()
141
+	{
142
+		EED_Ticket_Sales_Monitor::set_hooks();
143
+	}
144
+
145
+
146
+	/**
147
+	 * @return EED_Ticket_Sales_Monitor|EED_Module
148
+	 */
149
+	public static function instance()
150
+	{
151
+		return parent::get_instance(__CLASS__);
152
+	}
153
+
154
+
155
+	/**
156
+	 * @param WP_Query $WP_Query
157
+	 * @return    void
158
+	 */
159
+	public function run($WP_Query)
160
+	{
161
+	}
162
+
163
+
164
+
165
+	/********************************** PRE_TICKET_SALES  **********************************/
166
+
167
+
168
+	/**
169
+	 * Retrieves grand totals from the line items that have no TXN ID
170
+	 * and timestamps less than the current time minus the session lifespan.
171
+	 * These are carts that have been abandoned before the "registrant" even attempted to checkout.
172
+	 * We're going to release the tickets for these line items before attempting to add more to the cart.
173
+	 *
174
+	 * @return void
175
+	 * @throws DomainException
176
+	 * @throws EE_Error
177
+	 * @throws InvalidArgumentException
178
+	 * @throws InvalidDataTypeException
179
+	 * @throws InvalidInterfaceException
180
+	 * @throws UnexpectedEntityException
181
+	 */
182
+	public static function release_tickets_for_expired_carts()
183
+	{
184
+		if (self::debug) {
185
+			echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()';
186
+		}
187
+		do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin');
188
+		$expired_ticket_IDs = array();
189
+		/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
190
+		$session_lifespan = LoaderFactory::getLoader()->getShared(
191
+			'EventEspresso\core\domain\values\session\SessionLifespan'
192
+		);
193
+		$timestamp = $session_lifespan->expiration();
194
+		$expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp);
195
+		if (self::debug) {
196
+			echo self::$nl . ' . time(): ' . time();
197
+			echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a');
198
+			echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration();
199
+			echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration());
200
+			echo self::$nl . ' . timestamp: ' . $timestamp;
201
+			echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items);
202
+		}
203
+		if (! empty($expired_ticket_line_items)) {
204
+			foreach ($expired_ticket_line_items as $expired_ticket_line_item) {
205
+				if (! $expired_ticket_line_item instanceof EE_Line_Item) {
206
+					continue;
207
+				}
208
+				$expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID();
209
+				if (self::debug) {
210
+					echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID();
211
+					echo self::$nl . ' . $expired_ticket_line_item->timestamp(): '
212
+						 . date(
213
+							 'Y-m-d h:i a',
214
+							 $expired_ticket_line_item->timestamp(true)
215
+						 );
216
+				}
217
+			}
218
+			if (! empty($expired_ticket_IDs)) {
219
+				EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
220
+					\EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs),
221
+					array(),
222
+					__FUNCTION__
223
+				);
224
+				// now  let's get rid of expired line items so that they can't interfere with tracking
225
+				EED_Ticket_Sales_Monitor::clear_expired_line_items_with_no_transaction($timestamp);
226
+			}
227
+		}
228
+		do_action(
229
+			'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end',
230
+			$expired_ticket_IDs,
231
+			$expired_ticket_line_items
232
+		);
233
+	}
234
+
235
+
236
+
237
+	/********************************** VALIDATE_TICKET_SALE  **********************************/
238
+
239
+
240
+	/**
241
+	 * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data'
242
+	 *
243
+	 * @param int       $qty
244
+	 * @param EE_Ticket $ticket
245
+	 * @return bool
246
+	 * @throws UnexpectedEntityException
247
+	 * @throws EE_Error
248
+	 */
249
+	public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket)
250
+	{
251
+		$qty = absint($qty);
252
+		if ($qty > 0) {
253
+			$qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
254
+		}
255
+		if (self::debug) {
256
+			echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()';
257
+			echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>';
258
+		}
259
+		return $qty;
260
+	}
261
+
262
+
263
+	/**
264
+	 * checks whether an individual ticket is available for purchase based on datetime, and ticket details
265
+	 *
266
+	 * @param   EE_Ticket $ticket
267
+	 * @param int         $qty
268
+	 * @return int
269
+	 * @throws UnexpectedEntityException
270
+	 * @throws EE_Error
271
+	 */
272
+	protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
273
+	{
274
+		if (self::debug) {
275
+			echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
276
+		}
277
+		if (! $ticket instanceof EE_Ticket) {
278
+			return 0;
279
+		}
280
+		if (self::debug) {
281
+			echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>';
282
+			echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved();
283
+		}
284
+		$ticket->refresh_from_db();
285
+		// first let's determine the ticket availability based on sales
286
+		$available = $ticket->qty('saleable');
287
+		if (self::debug) {
288
+			echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty();
289
+			echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold();
290
+			echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved();
291
+			echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
292
+			echo self::$nl . ' . . . available: ' . $available;
293
+		}
294
+		if ($available < 1) {
295
+			$this->_ticket_sold_out($ticket);
296
+			return 0;
297
+		}
298
+		if (self::debug) {
299
+			echo self::$nl . ' . . . qty: ' . $qty;
300
+		}
301
+		if ($available < $qty) {
302
+			$qty = $available;
303
+			if (self::debug) {
304
+				echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty;
305
+			}
306
+			$this->_ticket_quantity_decremented($ticket);
307
+		}
308
+		if ($this->_reserve_ticket($ticket, $qty)) {
309
+			return $qty;
310
+		} else {
311
+			return 0;
312
+		}
313
+	}
314
+
315
+
316
+	/**
317
+	 * increments ticket reserved based on quantity passed
318
+	 *
319
+	 * @param    EE_Ticket $ticket
320
+	 * @param int          $quantity
321
+	 * @return bool indicating success or failure
322
+	 * @throws EE_Error
323
+	 */
324
+	protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
325
+	{
326
+		if (self::debug) {
327
+			echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity;
328
+		}
329
+		return $ticket->increaseReserved($quantity, 'TicketSalesMonitor:' . __LINE__);
330
+	}
331
+
332
+
333
+	/**
334
+	 * @param  EE_Ticket $ticket
335
+	 * @param  int       $quantity
336
+	 * @return bool
337
+	 * @throws EE_Error
338
+	 */
339
+	protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
340
+	{
341
+		if (self::debug) {
342
+			echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID();
343
+			echo self::$nl . ' . . . ticket->reserved before: ' . $ticket->reserved();
344
+		}
345
+		$ticket->decreaseReserved($quantity, true, 'TicketSalesMonitor:' . __LINE__);
346
+		if (self::debug) {
347
+			echo self::$nl . ' . . . ticket->reserved after: ' . $ticket->reserved();
348
+		}
349
+		return $ticket->save() ? 1 : 0;
350
+	}
351
+
352
+
353
+	/**
354
+	 * removes quantities within the ticket selector based on zero ticket availability
355
+	 *
356
+	 * @param    EE_Ticket $ticket
357
+	 * @return    void
358
+	 * @throws UnexpectedEntityException
359
+	 * @throws EE_Error
360
+	 */
361
+	protected function _ticket_sold_out(EE_Ticket $ticket)
362
+	{
363
+		if (self::debug) {
364
+			echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
365
+			echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
366
+		}
367
+		$this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
368
+	}
369
+
370
+
371
+	/**
372
+	 * adjusts quantities within the ticket selector based on decreased ticket availability
373
+	 *
374
+	 * @param    EE_Ticket $ticket
375
+	 * @return void
376
+	 * @throws UnexpectedEntityException
377
+	 * @throws EE_Error
378
+	 */
379
+	protected function _ticket_quantity_decremented(EE_Ticket $ticket)
380
+	{
381
+		if (self::debug) {
382
+			echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
383
+			echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
384
+		}
385
+		$this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
386
+	}
387
+
388
+
389
+	/**
390
+	 * builds string out of ticket and event name
391
+	 *
392
+	 * @param    EE_Ticket $ticket
393
+	 * @return string
394
+	 * @throws UnexpectedEntityException
395
+	 * @throws EE_Error
396
+	 */
397
+	protected function _get_ticket_and_event_name(EE_Ticket $ticket)
398
+	{
399
+		$event = $ticket->get_related_event();
400
+		if ($event instanceof EE_Event) {
401
+			$ticket_name = sprintf(
402
+				_x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'),
403
+				$ticket->name(),
404
+				$event->name()
405
+			);
406
+		} else {
407
+			$ticket_name = $ticket->name();
408
+		}
409
+		return $ticket_name;
410
+	}
411
+
412
+
413
+
414
+	/********************************** EVENT CART  **********************************/
415
+
416
+
417
+	/**
418
+	 * releases or reserves ticket(s) based on quantity passed
419
+	 *
420
+	 * @param  EE_Line_Item $line_item
421
+	 * @param  int          $quantity
422
+	 * @return void
423
+	 * @throws EE_Error
424
+	 * @throws InvalidArgumentException
425
+	 * @throws InvalidDataTypeException
426
+	 * @throws InvalidInterfaceException
427
+	 */
428
+	public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1)
429
+	{
430
+		$ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID()));
431
+		if ($ticket instanceof EE_Ticket) {
432
+			$ticket->add_extra_meta(
433
+				EE_Ticket::META_KEY_TICKET_RESERVATIONS,
434
+				__LINE__ . ') ' . __METHOD__ . '()'
435
+			);
436
+			if ($quantity > 0) {
437
+				EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity);
438
+			} else {
439
+				EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
440
+			}
441
+		}
442
+	}
443
+
444
+
445
+	/**
446
+	 * releases reserved ticket(s) based on quantity passed
447
+	 *
448
+	 * @param  EE_Ticket $ticket
449
+	 * @param  int       $quantity
450
+	 * @return void
451
+	 * @throws EE_Error
452
+	 */
453
+	public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1)
454
+	{
455
+		$ticket->add_extra_meta(
456
+			EE_Ticket::META_KEY_TICKET_RESERVATIONS,
457
+			__LINE__ . ') ' . __METHOD__ . '()'
458
+		);
459
+		EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
460
+	}
461
+
462
+
463
+
464
+	/********************************** POST_NOTICES  **********************************/
465
+
466
+
467
+	/**
468
+	 * @return void
469
+	 * @throws EE_Error
470
+	 * @throws InvalidArgumentException
471
+	 * @throws ReflectionException
472
+	 * @throws InvalidDataTypeException
473
+	 * @throws InvalidInterfaceException
474
+	 */
475
+	public static function post_notices()
476
+	{
477
+		EED_Ticket_Sales_Monitor::instance()->_post_notices();
478
+	}
479
+
480
+
481
+	/**
482
+	 * @return void
483
+	 * @throws EE_Error
484
+	 * @throws InvalidArgumentException
485
+	 * @throws ReflectionException
486
+	 * @throws InvalidDataTypeException
487
+	 * @throws InvalidInterfaceException
488
+	 */
489
+	protected function _post_notices()
490
+	{
491
+		if (self::debug) {
492
+			echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
493
+		}
494
+		$refresh_msg = '';
495
+		$none_added_msg = '';
496
+		if (defined('DOING_AJAX') && DOING_AJAX) {
497
+			$refresh_msg = __(
498
+				'Please refresh the page to view updated ticket quantities.',
499
+				'event_espresso'
500
+			);
501
+			$none_added_msg = __('No tickets were added for the event.', 'event_espresso');
502
+		}
503
+		if (! empty($this->sold_out_tickets)) {
504
+			EE_Error::add_attention(
505
+				sprintf(
506
+					apply_filters(
507
+						'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice',
508
+						__(
509
+							'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$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.%1$s%1$s%3$s%1$s%4$s%1$s',
510
+							'event_espresso'
511
+						)
512
+					),
513
+					'<br />',
514
+					implode('<br />', $this->sold_out_tickets),
515
+					$none_added_msg,
516
+					$refresh_msg
517
+				)
518
+			);
519
+			// alter code flow in the Ticket Selector for better UX
520
+			add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true');
521
+			add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false');
522
+			$this->sold_out_tickets = array();
523
+			// and reset the cart
524
+			EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN);
525
+		}
526
+		if (! empty($this->decremented_tickets)) {
527
+			EE_Error::add_attention(
528
+				sprintf(
529
+					apply_filters(
530
+						'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice',
531
+						__(
532
+							'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$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.%1$s%1$s%3$s%1$s%4$s%1$s',
533
+							'event_espresso'
534
+						)
535
+					),
536
+					'<br />',
537
+					implode('<br />', $this->decremented_tickets),
538
+					$none_added_msg,
539
+					$refresh_msg
540
+				)
541
+			);
542
+			$this->decremented_tickets = array();
543
+		}
544
+	}
545
+
546
+
547
+
548
+	/********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION  **********************************/
549
+
550
+
551
+	/**
552
+	 * releases reserved tickets for all registrations of an EE_Transaction
553
+	 * by default, will NOT release tickets for finalized transactions
554
+	 *
555
+	 * @param    EE_Transaction $transaction
556
+	 * @return int
557
+	 * @throws EE_Error
558
+	 * @throws InvalidSessionDataException
559
+	 */
560
+	protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
561
+	{
562
+		if (self::debug) {
563
+			echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
564
+			echo self::$nl . ' . transaction->ID: ' . $transaction->ID();
565
+			echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID();
566
+		}
567
+		// check if 'finalize_registration' step has been completed...
568
+		$finalized = $transaction->reg_step_completed('finalize_registration');
569
+		if (self::debug) {
570
+			// DEBUG LOG
571
+			EEH_Debug_Tools::log(
572
+				__CLASS__,
573
+				__FUNCTION__,
574
+				__LINE__,
575
+				array('finalized' => $finalized),
576
+				false,
577
+				'EE_Transaction: ' . $transaction->ID()
578
+			);
579
+		}
580
+		// how many tickets were released
581
+		$count = 0;
582
+		if (self::debug) {
583
+			echo self::$nl . ' . . . TXN finalized: ' . $finalized;
584
+		}
585
+		$release_tickets_with_TXN_status = array(
586
+			EEM_Transaction::failed_status_code,
587
+			EEM_Transaction::abandoned_status_code,
588
+			EEM_Transaction::incomplete_status_code,
589
+		);
590
+		$events = array();
591
+		// if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed
592
+		if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
593
+			// cancel any reserved tickets for registrations that were not approved
594
+			$registrations = $transaction->registrations();
595
+			if (self::debug) {
596
+				echo self::$nl . ' . . . # registrations: ' . count($registrations);
597
+				$reg = reset($registrations);
598
+				$ticket = $reg->ticket();
599
+				if ($ticket instanceof EE_Ticket) {
600
+					$ticket->add_extra_meta(
601
+						EE_Ticket::META_KEY_TICKET_RESERVATIONS,
602
+						__LINE__ . ') Release All Tickets TXN:' . $transaction->ID()
603
+					);
604
+				}
605
+			}
606
+			if (! empty($registrations)) {
607
+				foreach ($registrations as $registration) {
608
+					if ($registration instanceof EE_Registration
609
+						&& $this->_release_reserved_ticket_for_registration($registration, $transaction)
610
+					) {
611
+						$count++;
612
+						$events[ $registration->event_ID() ] = $registration->event();
613
+					}
614
+				}
615
+			}
616
+		}
617
+		if ($events !== array()) {
618
+			foreach ($events as $event) {
619
+				/** @var EE_Event $event */
620
+				$event->perform_sold_out_status_check();
621
+			}
622
+		}
623
+		return $count;
624
+	}
625
+
626
+
627
+	/**
628
+	 * releases reserved tickets for an EE_Registration
629
+	 * by default, will NOT release tickets for APPROVED registrations
630
+	 *
631
+	 * @param EE_Registration $registration
632
+	 * @param EE_Transaction  $transaction
633
+	 * @return int
634
+	 * @throws EE_Error
635
+	 */
636
+	protected function _release_reserved_ticket_for_registration(
637
+		EE_Registration $registration,
638
+		EE_Transaction $transaction
639
+	) {
640
+		$STS_ID = $transaction->status_ID();
641
+		if (self::debug) {
642
+			echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
643
+			echo self::$nl . ' . . registration->ID: ' . $registration->ID();
644
+			echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID();
645
+			echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID;
646
+		}
647
+		if (// release Tickets for Failed Transactions and Abandoned Transactions
648
+			$STS_ID === EEM_Transaction::failed_status_code
649
+			|| $STS_ID === EEM_Transaction::abandoned_status_code
650
+			|| (
651
+				// also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved
652
+				$STS_ID === EEM_Transaction::incomplete_status_code
653
+				&& $registration->status_ID() !== EEM_Registration::status_id_approved
654
+			)
655
+		) {
656
+			if (self::debug) {
657
+				echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET';
658
+				$rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true);
659
+				echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: ';
660
+				var_dump($rsrvd);
661
+			}
662
+			$registration->release_reserved_ticket(true, 'TicketSalesMonitor:' . __LINE__);
663
+			return 1;
664
+		}
665
+		return 0;
666
+	}
667
+
668
+
669
+
670
+	/********************************** SESSION_CART_RESET  **********************************/
671
+
672
+
673
+	/**
674
+	 * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset'
675
+	 *
676
+	 * @param EE_Session $session
677
+	 * @return void
678
+	 * @throws EE_Error
679
+	 * @throws InvalidArgumentException
680
+	 * @throws ReflectionException
681
+	 * @throws InvalidDataTypeException
682
+	 * @throws InvalidInterfaceException
683
+	 */
684
+	public static function session_cart_reset(EE_Session $session)
685
+	{
686
+		// don't release tickets if checkout was already reset
687
+		if (did_action('AHEE__EE_Session__reset_checkout__before_reset')) {
688
+			return;
689
+		}
690
+		if (self::debug) {
691
+			echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
692
+		}
693
+		// first check of the session has a valid Checkout object
694
+		$checkout = $session->checkout();
695
+		if ($checkout instanceof EE_Checkout) {
696
+			// and use that to clear ticket reservations because it will update the associated registration meta data
697
+			EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout);
698
+			return;
699
+		}
700
+		$cart = $session->cart();
701
+		if ($cart instanceof EE_Cart) {
702
+			if (self::debug) {
703
+				echo self::$nl . self::$nl . ' cart instance of EE_Cart: ';
704
+			}
705
+			EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session);
706
+		} else {
707
+			if (self::debug) {
708
+				echo self::$nl . self::$nl . ' invalid EE_Cart: ';
709
+				var_export($cart, true);
710
+			}
711
+		}
712
+	}
713
+
714
+
715
+	/**
716
+	 * releases reserved tickets in the EE_Cart
717
+	 *
718
+	 * @param EE_Cart $cart
719
+	 * @return void
720
+	 * @throws EE_Error
721
+	 * @throws InvalidArgumentException
722
+	 * @throws ReflectionException
723
+	 * @throws InvalidDataTypeException
724
+	 * @throws InvalidInterfaceException
725
+	 */
726
+	protected function _session_cart_reset(EE_Cart $cart, EE_Session $session)
727
+	{
728
+		if (self::debug) {
729
+			echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
730
+		}
731
+		$ticket_line_items = $cart->get_tickets();
732
+		if (empty($ticket_line_items)) {
733
+			return;
734
+		}
735
+		if (self::debug) {
736
+			echo '<br /> . ticket_line_item count: ' . count($ticket_line_items);
737
+		}
738
+		foreach ($ticket_line_items as $ticket_line_item) {
739
+			if (self::debug) {
740
+				echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID();
741
+			}
742
+			if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
743
+				if (self::debug) {
744
+					echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
745
+				}
746
+				$ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
747
+				if ($ticket instanceof EE_Ticket) {
748
+					if (self::debug) {
749
+						echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID();
750
+						echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
751
+					}
752
+					$ticket->add_extra_meta(
753
+						EE_Ticket::META_KEY_TICKET_RESERVATIONS,
754
+						__LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id()
755
+					);
756
+					$this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
757
+				}
758
+			}
759
+		}
760
+		if (self::debug) {
761
+			echo self::$nl . self::$nl . ' RESET COMPLETED ';
762
+		}
763
+	}
764
+
765
+
766
+
767
+	/********************************** SESSION_CHECKOUT_RESET  **********************************/
768
+
769
+
770
+	/**
771
+	 * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset'
772
+	 *
773
+	 * @param EE_Session $session
774
+	 * @return void
775
+	 * @throws EE_Error
776
+	 * @throws InvalidSessionDataException
777
+	 */
778
+	public static function session_checkout_reset(EE_Session $session)
779
+	{
780
+		// don't release tickets if cart was already reset
781
+		if (did_action('AHEE__EE_Session__reset_cart__before_reset')) {
782
+			return;
783
+		}
784
+		$checkout = $session->checkout();
785
+		if ($checkout instanceof EE_Checkout) {
786
+			EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout);
787
+		}
788
+	}
789
+
790
+
791
+	/**
792
+	 * releases reserved tickets for the EE_Checkout->transaction
793
+	 *
794
+	 * @param EE_Checkout $checkout
795
+	 * @return void
796
+	 * @throws EE_Error
797
+	 * @throws InvalidSessionDataException
798
+	 */
799
+	protected function _session_checkout_reset(EE_Checkout $checkout)
800
+	{
801
+		if (self::debug) {
802
+			echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
803
+		}
804
+		// we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
805
+		if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
806
+			return;
807
+		}
808
+		$this->_release_all_reserved_tickets_for_transaction($checkout->transaction);
809
+	}
810
+
811
+
812
+
813
+	/********************************** SESSION_EXPIRED_RESET  **********************************/
814
+
815
+
816
+	/**
817
+	 * @param    EE_Session $session
818
+	 * @return    void
819
+	 */
820
+	public static function session_expired_reset(EE_Session $session)
821
+	{
822
+	}
823
+
824
+
825
+
826
+	/********************************** PROCESS_ABANDONED_TRANSACTIONS  **********************************/
827
+
828
+
829
+	/**
830
+	 * releases reserved tickets for all registrations of an ABANDONED EE_Transaction
831
+	 * by default, will NOT release tickets for free transactions, or any that have received a payment
832
+	 *
833
+	 * @param EE_Transaction $transaction
834
+	 * @return void
835
+	 * @throws EE_Error
836
+	 * @throws InvalidSessionDataException
837
+	 */
838
+	public static function process_abandoned_transactions(EE_Transaction $transaction)
839
+	{
840
+		// is this TXN free or has any money been paid towards this TXN? If so, then leave it alone
841
+		if ($transaction->is_free() || $transaction->paid() > 0) {
842
+			if (self::debug) {
843
+				// DEBUG LOG
844
+				EEH_Debug_Tools::log(
845
+					__CLASS__,
846
+					__FUNCTION__,
847
+					__LINE__,
848
+					array($transaction),
849
+					false,
850
+					'EE_Transaction: ' . $transaction->ID()
851
+				);
852
+			}
853
+			return;
854
+		}
855
+		// have their been any successful payments made ?
856
+		$payments = $transaction->payments();
857
+		foreach ($payments as $payment) {
858
+			if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) {
859
+				if (self::debug) {
860
+					// DEBUG LOG
861
+					EEH_Debug_Tools::log(
862
+						__CLASS__,
863
+						__FUNCTION__,
864
+						__LINE__,
865
+						array($payment),
866
+						false,
867
+						'EE_Transaction: ' . $transaction->ID()
868
+					);
869
+				}
870
+				return;
871
+			}
872
+		}
873
+		// since you haven't even attempted to pay for your ticket...
874
+		EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
875
+	}
876
+
877
+
878
+
879
+	/********************************** PROCESS_FAILED_TRANSACTIONS  **********************************/
880
+
881
+
882
+	/**
883
+	 * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction
884
+	 *
885
+	 * @param EE_Transaction $transaction
886
+	 * @return void
887
+	 * @throws EE_Error
888
+	 * @throws InvalidSessionDataException
889
+	 */
890
+	public static function process_failed_transactions(EE_Transaction $transaction)
891
+	{
892
+		// since you haven't even attempted to pay for your ticket...
893
+		EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
894
+	}
895
+
896
+
897
+
898
+	/********************************** RESET RESERVATION COUNTS  *********************************/
899
+
900
+
901
+	/**
902
+	 * Resets the ticket and datetime reserved counts.
903
+	 *
904
+	 * For all the tickets with reservations, recalculates what their actual reserved counts should be based
905
+	 * on the valid transactions.
906
+	 *
907
+	 * @return int number of tickets whose reservations were released.
908
+	 * @throws EE_Error
909
+	 * @throws DomainException
910
+	 * @throws InvalidDataTypeException
911
+	 * @throws InvalidInterfaceException
912
+	 * @throws InvalidArgumentException
913
+	 * @throws UnexpectedEntityException
914
+	 * @throws ReflectionException
915
+	 */
916
+	public static function reset_reservation_counts()
917
+	{
918
+		/** @var EE_Line_Item[] $valid_reserved_tickets */
919
+		$valid_reserved_tickets = array();
920
+		/** @var EE_Transaction[] $transactions_in_progress */
921
+		$transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress();
922
+		foreach ($transactions_in_progress as $transaction) {
923
+			// if this TXN has been fully completed, then skip it
924
+			if ($transaction->reg_step_completed('finalize_registration')) {
925
+				continue;
926
+			}
927
+			$total_line_item = $transaction->total_line_item();
928
+			// $transaction_in_progress->line
929
+			if (! $total_line_item instanceof EE_Line_Item) {
930
+				throw new DomainException(
931
+					esc_html__(
932
+						'Transaction does not have a valid Total Line Item associated with it.',
933
+						'event_espresso'
934
+					)
935
+				);
936
+			}
937
+			$valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
938
+				$total_line_item
939
+			);
940
+		}
941
+		$total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts();
942
+		foreach ($total_line_items as $total_line_item) {
943
+			$valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
944
+				$total_line_item
945
+			);
946
+		}
947
+		$tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations();
948
+		return EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
949
+			$tickets_with_reservations,
950
+			$valid_reserved_tickets,
951
+			__FUNCTION__
952
+		);
953
+	}
954
+
955
+
956
+	/**
957
+	 * @param EE_Line_Item $total_line_item
958
+	 * @return EE_Line_Item[]
959
+	 */
960
+	private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item)
961
+	{
962
+		/** @var EE_Line_Item[] $valid_reserved_tickets */
963
+		$valid_reserved_tickets = array();
964
+		$ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item);
965
+		foreach ($ticket_line_items as $ticket_line_item) {
966
+			if ($ticket_line_item instanceof EE_Line_Item) {
967
+				$valid_reserved_tickets[ $ticket_line_item->ID() ] = $ticket_line_item;
968
+			}
969
+		}
970
+		return $valid_reserved_tickets;
971
+	}
972
+
973
+
974
+	/**
975
+	 * Releases ticket and datetime reservations (ie, reduces the number of reserved spots on them).
976
+	 *
977
+	 * Given the list of tickets which have reserved spots on them, uses the complete list of line items for tickets
978
+	 * whose transactions aren't complete and also aren't yet expired (ie, they're incomplete and younger than the
979
+	 * session's expiry time) to update the ticket (and their datetimes') reserved counts.
980
+	 *
981
+	 * @param EE_Ticket[]    $tickets_with_reservations all tickets with TKT_reserved > 0
982
+	 * @param EE_Line_Item[] $valid_reserved_ticket_line_items all line items for tickets and incomplete transactions
983
+	 *                       whose session has NOT expired. We will use these to determine the number of ticket
984
+	 *                       reservations are now invalid. We don't use the list of invalid ticket line items because
985
+	 *                       we don't know which of those have already been taken into account when reducing ticket
986
+	 *                       reservation counts, and which haven't.
987
+	 * @return int
988
+	 * @throws UnexpectedEntityException
989
+	 * @throws DomainException
990
+	 * @throws EE_Error
991
+	 */
992
+	protected static function release_reservations_for_tickets(
993
+		array $tickets_with_reservations,
994
+		array $valid_reserved_ticket_line_items = array(),
995
+		$source
996
+	) {
997
+		$total_tickets_released = 0;
998
+		$sold_out_events = array();
999
+		foreach ($tickets_with_reservations as $ticket_with_reservations) {
1000
+			if (! $ticket_with_reservations instanceof EE_Ticket) {
1001
+				continue;
1002
+			}
1003
+			// The $valid_reserved_ticket_line_items tells us what the reserved count on their tickets (and datetimes)
1004
+			// SHOULD be. Instead of just directly updating the list, we're going to use EE_Ticket::decreaseReserved()
1005
+			// to try to avoid race conditions, so instead of just finding the number to update TO, we're going to find
1006
+			// the number to RELEASE. It's the same end result, just different path.
1007
+			// Begin by assuming we're going to release all the reservations on this ticket.
1008
+			$expired_reservations_count = $ticket_with_reservations->reserved();
1009
+			// Now reduce that number using the list of current valid reservations.
1010
+			foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) {
1011
+				if ($valid_reserved_ticket_line_item instanceof EE_Line_Item
1012
+					&& $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID()
1013
+				) {
1014
+					$expired_reservations_count -= $valid_reserved_ticket_line_item->quantity();
1015
+				}
1016
+			}
1017
+			// Only bother saving the tickets and datetimes if we're actually going to release some spots.
1018
+			if ($expired_reservations_count > 0) {
1019
+				$ticket_with_reservations->add_extra_meta(
1020
+					EE_Ticket::META_KEY_TICKET_RESERVATIONS,
1021
+					__LINE__ . ') ' . $source . '()'
1022
+				);
1023
+				$ticket_with_reservations->decreaseReserved($expired_reservations_count, true, 'TicketSalesMonitor:' . __LINE__);
1024
+				$total_tickets_released += $expired_reservations_count;
1025
+				$event = $ticket_with_reservations->get_related_event();
1026
+				// track sold out events
1027
+				if ($event instanceof EE_Event && $event->is_sold_out()) {
1028
+					$sold_out_events[] = $event;
1029
+				}
1030
+			}
1031
+		}
1032
+		// Double check whether sold out events should remain sold out after releasing tickets
1033
+		if ($sold_out_events !== array()) {
1034
+			foreach ($sold_out_events as $sold_out_event) {
1035
+				/** @var EE_Event $sold_out_event */
1036
+				$sold_out_event->perform_sold_out_status_check();
1037
+			}
1038
+		}
1039
+		return $total_tickets_released;
1040
+	}
1041
+
1042
+
1043
+
1044
+	/********************************** SHUTDOWN  **********************************/
1045
+
1046
+
1047
+	/**
1048
+	 * @param int $timestamp
1049
+	 * @return false|int
1050
+	 * @throws EE_Error
1051
+	 * @throws InvalidArgumentException
1052
+	 * @throws InvalidDataTypeException
1053
+	 * @throws InvalidInterfaceException
1054
+	 */
1055
+	public static function clear_expired_line_items_with_no_transaction($timestamp = 0)
1056
+	{
1057
+		/** @type WPDB $wpdb */
1058
+		global $wpdb;
1059
+		if (! absint($timestamp)) {
1060
+			/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
1061
+			$session_lifespan = LoaderFactory::getLoader()->getShared(
1062
+				'EventEspresso\core\domain\values\session\SessionLifespan'
1063
+			);
1064
+			$timestamp = $session_lifespan->expiration();
1065
+		}
1066
+		return $wpdb->query(
1067
+			$wpdb->prepare(
1068
+				'DELETE FROM ' . EEM_Line_Item::instance()->table() . '
1069 1069
                 WHERE TXN_ID = 0 AND LIN_timestamp <= %s',
1070
-                // use GMT time because that's what LIN_timestamps are in
1071
-                date('Y-m-d H:i:s', $timestamp)
1072
-            )
1073
-        );
1074
-    }
1070
+				// use GMT time because that's what LIN_timestamps are in
1071
+				date('Y-m-d H:i:s', $timestamp)
1072
+			)
1073
+		);
1074
+	}
1075 1075
 }
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
     public static function release_tickets_for_expired_carts()
183 183
     {
184 184
         if (self::debug) {
185
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()';
185
+            echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()';
186 186
         }
187 187
         do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin');
188 188
         $expired_ticket_IDs = array();
@@ -193,29 +193,29 @@  discard block
 block discarded – undo
193 193
         $timestamp = $session_lifespan->expiration();
194 194
         $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp);
195 195
         if (self::debug) {
196
-            echo self::$nl . ' . time(): ' . time();
197
-            echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a');
198
-            echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration();
199
-            echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration());
200
-            echo self::$nl . ' . timestamp: ' . $timestamp;
201
-            echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items);
196
+            echo self::$nl.' . time(): '.time();
197
+            echo self::$nl.' . time() as date: '.date('Y-m-d H:i a');
198
+            echo self::$nl.' . session expiration: '.$session_lifespan->expiration();
199
+            echo self::$nl.' . session expiration as date: '.date('Y-m-d H:i a', $session_lifespan->expiration());
200
+            echo self::$nl.' . timestamp: '.$timestamp;
201
+            echo self::$nl.' . $expired_ticket_line_items: '.count($expired_ticket_line_items);
202 202
         }
203
-        if (! empty($expired_ticket_line_items)) {
203
+        if ( ! empty($expired_ticket_line_items)) {
204 204
             foreach ($expired_ticket_line_items as $expired_ticket_line_item) {
205
-                if (! $expired_ticket_line_item instanceof EE_Line_Item) {
205
+                if ( ! $expired_ticket_line_item instanceof EE_Line_Item) {
206 206
                     continue;
207 207
                 }
208
-                $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID();
208
+                $expired_ticket_IDs[$expired_ticket_line_item->OBJ_ID()] = $expired_ticket_line_item->OBJ_ID();
209 209
                 if (self::debug) {
210
-                    echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID();
211
-                    echo self::$nl . ' . $expired_ticket_line_item->timestamp(): '
210
+                    echo self::$nl.' . $expired_ticket_line_item->OBJ_ID(): '.$expired_ticket_line_item->OBJ_ID();
211
+                    echo self::$nl.' . $expired_ticket_line_item->timestamp(): '
212 212
                          . date(
213 213
                              'Y-m-d h:i a',
214 214
                              $expired_ticket_line_item->timestamp(true)
215 215
                          );
216 216
                 }
217 217
             }
218
-            if (! empty($expired_ticket_IDs)) {
218
+            if ( ! empty($expired_ticket_IDs)) {
219 219
                 EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
220 220
                     \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs),
221 221
                     array(),
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
             $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
254 254
         }
255 255
         if (self::debug) {
256
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()';
257
-            echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>';
256
+            echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()';
257
+            echo self::$nl.self::$nl.'<b> RETURNED QTY: '.$qty.'</b>';
258 258
         }
259 259
         return $qty;
260 260
     }
@@ -272,36 +272,36 @@  discard block
 block discarded – undo
272 272
     protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
273 273
     {
274 274
         if (self::debug) {
275
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
275
+            echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() ';
276 276
         }
277
-        if (! $ticket instanceof EE_Ticket) {
277
+        if ( ! $ticket instanceof EE_Ticket) {
278 278
             return 0;
279 279
         }
280 280
         if (self::debug) {
281
-            echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>';
282
-            echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved();
281
+            echo self::$nl.'<b> . ticket->ID: '.$ticket->ID().'</b>';
282
+            echo self::$nl.' . original ticket->reserved: '.$ticket->reserved();
283 283
         }
284 284
         $ticket->refresh_from_db();
285 285
         // first let's determine the ticket availability based on sales
286 286
         $available = $ticket->qty('saleable');
287 287
         if (self::debug) {
288
-            echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty();
289
-            echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold();
290
-            echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved();
291
-            echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
292
-            echo self::$nl . ' . . . available: ' . $available;
288
+            echo self::$nl.' . . . ticket->qty: '.$ticket->qty();
289
+            echo self::$nl.' . . . ticket->sold: '.$ticket->sold();
290
+            echo self::$nl.' . . . ticket->reserved: '.$ticket->reserved();
291
+            echo self::$nl.' . . . ticket->qty(saleable): '.$ticket->qty('saleable');
292
+            echo self::$nl.' . . . available: '.$available;
293 293
         }
294 294
         if ($available < 1) {
295 295
             $this->_ticket_sold_out($ticket);
296 296
             return 0;
297 297
         }
298 298
         if (self::debug) {
299
-            echo self::$nl . ' . . . qty: ' . $qty;
299
+            echo self::$nl.' . . . qty: '.$qty;
300 300
         }
301 301
         if ($available < $qty) {
302 302
             $qty = $available;
303 303
             if (self::debug) {
304
-                echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty;
304
+                echo self::$nl.' . . . QTY ADJUSTED: '.$qty;
305 305
             }
306 306
             $this->_ticket_quantity_decremented($ticket);
307 307
         }
@@ -324,9 +324,9 @@  discard block
 block discarded – undo
324 324
     protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
325 325
     {
326 326
         if (self::debug) {
327
-            echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity;
327
+            echo self::$nl.self::$nl.' . . . INCREASE RESERVED: '.$quantity;
328 328
         }
329
-        return $ticket->increaseReserved($quantity, 'TicketSalesMonitor:' . __LINE__);
329
+        return $ticket->increaseReserved($quantity, 'TicketSalesMonitor:'.__LINE__);
330 330
     }
331 331
 
332 332
 
@@ -339,12 +339,12 @@  discard block
 block discarded – undo
339 339
     protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
340 340
     {
341 341
         if (self::debug) {
342
-            echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID();
343
-            echo self::$nl . ' . . . ticket->reserved before: ' . $ticket->reserved();
342
+            echo self::$nl.' . . . ticket->ID: '.$ticket->ID();
343
+            echo self::$nl.' . . . ticket->reserved before: '.$ticket->reserved();
344 344
         }
345
-        $ticket->decreaseReserved($quantity, true, 'TicketSalesMonitor:' . __LINE__);
345
+        $ticket->decreaseReserved($quantity, true, 'TicketSalesMonitor:'.__LINE__);
346 346
         if (self::debug) {
347
-            echo self::$nl . ' . . . ticket->reserved after: ' . $ticket->reserved();
347
+            echo self::$nl.' . . . ticket->reserved after: '.$ticket->reserved();
348 348
         }
349 349
         return $ticket->save() ? 1 : 0;
350 350
     }
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
     protected function _ticket_sold_out(EE_Ticket $ticket)
362 362
     {
363 363
         if (self::debug) {
364
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
365
-            echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
364
+            echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() ';
365
+            echo self::$nl.' . . ticket->name: '.$this->_get_ticket_and_event_name($ticket);
366 366
         }
367 367
         $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
368 368
     }
@@ -379,8 +379,8 @@  discard block
 block discarded – undo
379 379
     protected function _ticket_quantity_decremented(EE_Ticket $ticket)
380 380
     {
381 381
         if (self::debug) {
382
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
383
-            echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
382
+            echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() ';
383
+            echo self::$nl.' . . ticket->name: '.$this->_get_ticket_and_event_name($ticket);
384 384
         }
385 385
         $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
386 386
     }
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
         if ($ticket instanceof EE_Ticket) {
432 432
             $ticket->add_extra_meta(
433 433
                 EE_Ticket::META_KEY_TICKET_RESERVATIONS,
434
-                __LINE__ . ') ' . __METHOD__ . '()'
434
+                __LINE__.') '.__METHOD__.'()'
435 435
             );
436 436
             if ($quantity > 0) {
437 437
                 EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity);
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
     {
455 455
         $ticket->add_extra_meta(
456 456
             EE_Ticket::META_KEY_TICKET_RESERVATIONS,
457
-            __LINE__ . ') ' . __METHOD__ . '()'
457
+            __LINE__.') '.__METHOD__.'()'
458 458
         );
459 459
         EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
460 460
     }
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
     protected function _post_notices()
490 490
     {
491 491
         if (self::debug) {
492
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
492
+            echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() ';
493 493
         }
494 494
         $refresh_msg = '';
495 495
         $none_added_msg = '';
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
             );
501 501
             $none_added_msg = __('No tickets were added for the event.', 'event_espresso');
502 502
         }
503
-        if (! empty($this->sold_out_tickets)) {
503
+        if ( ! empty($this->sold_out_tickets)) {
504 504
             EE_Error::add_attention(
505 505
                 sprintf(
506 506
                     apply_filters(
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
             // and reset the cart
524 524
             EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN);
525 525
         }
526
-        if (! empty($this->decremented_tickets)) {
526
+        if ( ! empty($this->decremented_tickets)) {
527 527
             EE_Error::add_attention(
528 528
                 sprintf(
529 529
                     apply_filters(
@@ -560,9 +560,9 @@  discard block
 block discarded – undo
560 560
     protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
561 561
     {
562 562
         if (self::debug) {
563
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
564
-            echo self::$nl . ' . transaction->ID: ' . $transaction->ID();
565
-            echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID();
563
+            echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() ';
564
+            echo self::$nl.' . transaction->ID: '.$transaction->ID();
565
+            echo self::$nl.' . TXN status_ID: '.$transaction->status_ID();
566 566
         }
567 567
         // check if 'finalize_registration' step has been completed...
568 568
         $finalized = $transaction->reg_step_completed('finalize_registration');
@@ -574,13 +574,13 @@  discard block
 block discarded – undo
574 574
                 __LINE__,
575 575
                 array('finalized' => $finalized),
576 576
                 false,
577
-                'EE_Transaction: ' . $transaction->ID()
577
+                'EE_Transaction: '.$transaction->ID()
578 578
             );
579 579
         }
580 580
         // how many tickets were released
581 581
         $count = 0;
582 582
         if (self::debug) {
583
-            echo self::$nl . ' . . . TXN finalized: ' . $finalized;
583
+            echo self::$nl.' . . . TXN finalized: '.$finalized;
584 584
         }
585 585
         $release_tickets_with_TXN_status = array(
586 586
             EEM_Transaction::failed_status_code,
@@ -589,27 +589,27 @@  discard block
 block discarded – undo
589 589
         );
590 590
         $events = array();
591 591
         // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed
592
-        if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
592
+        if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
593 593
             // cancel any reserved tickets for registrations that were not approved
594 594
             $registrations = $transaction->registrations();
595 595
             if (self::debug) {
596
-                echo self::$nl . ' . . . # registrations: ' . count($registrations);
596
+                echo self::$nl.' . . . # registrations: '.count($registrations);
597 597
                 $reg = reset($registrations);
598 598
                 $ticket = $reg->ticket();
599 599
                 if ($ticket instanceof EE_Ticket) {
600 600
                     $ticket->add_extra_meta(
601 601
                         EE_Ticket::META_KEY_TICKET_RESERVATIONS,
602
-                        __LINE__ . ') Release All Tickets TXN:' . $transaction->ID()
602
+                        __LINE__.') Release All Tickets TXN:'.$transaction->ID()
603 603
                     );
604 604
                 }
605 605
             }
606
-            if (! empty($registrations)) {
606
+            if ( ! empty($registrations)) {
607 607
                 foreach ($registrations as $registration) {
608 608
                     if ($registration instanceof EE_Registration
609 609
                         && $this->_release_reserved_ticket_for_registration($registration, $transaction)
610 610
                     ) {
611 611
                         $count++;
612
-                        $events[ $registration->event_ID() ] = $registration->event();
612
+                        $events[$registration->event_ID()] = $registration->event();
613 613
                     }
614 614
                 }
615 615
             }
@@ -639,10 +639,10 @@  discard block
 block discarded – undo
639 639
     ) {
640 640
         $STS_ID = $transaction->status_ID();
641 641
         if (self::debug) {
642
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
643
-            echo self::$nl . ' . . registration->ID: ' . $registration->ID();
644
-            echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID();
645
-            echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID;
642
+            echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() ';
643
+            echo self::$nl.' . . registration->ID: '.$registration->ID();
644
+            echo self::$nl.' . . registration->status_ID: '.$registration->status_ID();
645
+            echo self::$nl.' . . transaction->status_ID(): '.$STS_ID;
646 646
         }
647 647
         if (// release Tickets for Failed Transactions and Abandoned Transactions
648 648
             $STS_ID === EEM_Transaction::failed_status_code
@@ -654,12 +654,12 @@  discard block
 block discarded – undo
654 654
             )
655 655
         ) {
656 656
             if (self::debug) {
657
-                echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET';
657
+                echo self::$nl.self::$nl.' . . RELEASE RESERVED TICKET';
658 658
                 $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true);
659
-                echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: ';
659
+                echo self::$nl.' . . . registration HAS_RESERVED_TICKET_KEY: ';
660 660
                 var_dump($rsrvd);
661 661
             }
662
-            $registration->release_reserved_ticket(true, 'TicketSalesMonitor:' . __LINE__);
662
+            $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'.__LINE__);
663 663
             return 1;
664 664
         }
665 665
         return 0;
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
             return;
689 689
         }
690 690
         if (self::debug) {
691
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
691
+            echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() ';
692 692
         }
693 693
         // first check of the session has a valid Checkout object
694 694
         $checkout = $session->checkout();
@@ -700,12 +700,12 @@  discard block
 block discarded – undo
700 700
         $cart = $session->cart();
701 701
         if ($cart instanceof EE_Cart) {
702 702
             if (self::debug) {
703
-                echo self::$nl . self::$nl . ' cart instance of EE_Cart: ';
703
+                echo self::$nl.self::$nl.' cart instance of EE_Cart: ';
704 704
             }
705 705
             EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session);
706 706
         } else {
707 707
             if (self::debug) {
708
-                echo self::$nl . self::$nl . ' invalid EE_Cart: ';
708
+                echo self::$nl.self::$nl.' invalid EE_Cart: ';
709 709
                 var_export($cart, true);
710 710
             }
711 711
         }
@@ -726,39 +726,39 @@  discard block
 block discarded – undo
726 726
     protected function _session_cart_reset(EE_Cart $cart, EE_Session $session)
727 727
     {
728 728
         if (self::debug) {
729
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
729
+            echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() ';
730 730
         }
731 731
         $ticket_line_items = $cart->get_tickets();
732 732
         if (empty($ticket_line_items)) {
733 733
             return;
734 734
         }
735 735
         if (self::debug) {
736
-            echo '<br /> . ticket_line_item count: ' . count($ticket_line_items);
736
+            echo '<br /> . ticket_line_item count: '.count($ticket_line_items);
737 737
         }
738 738
         foreach ($ticket_line_items as $ticket_line_item) {
739 739
             if (self::debug) {
740
-                echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID();
740
+                echo self::$nl.' . ticket_line_item->ID(): '.$ticket_line_item->ID();
741 741
             }
742 742
             if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
743 743
                 if (self::debug) {
744
-                    echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
744
+                    echo self::$nl.' . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID();
745 745
                 }
746 746
                 $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
747 747
                 if ($ticket instanceof EE_Ticket) {
748 748
                     if (self::debug) {
749
-                        echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID();
750
-                        echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
749
+                        echo self::$nl.' . . ticket->ID(): '.$ticket->ID();
750
+                        echo self::$nl.' . . ticket_line_item->quantity(): '.$ticket_line_item->quantity();
751 751
                     }
752 752
                     $ticket->add_extra_meta(
753 753
                         EE_Ticket::META_KEY_TICKET_RESERVATIONS,
754
-                        __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id()
754
+                        __LINE__.') '.__METHOD__.'() SID = '.$session->id()
755 755
                     );
756 756
                     $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
757 757
                 }
758 758
             }
759 759
         }
760 760
         if (self::debug) {
761
-            echo self::$nl . self::$nl . ' RESET COMPLETED ';
761
+            echo self::$nl.self::$nl.' RESET COMPLETED ';
762 762
         }
763 763
     }
764 764
 
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
     protected function _session_checkout_reset(EE_Checkout $checkout)
800 800
     {
801 801
         if (self::debug) {
802
-            echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() ';
802
+            echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() ';
803 803
         }
804 804
         // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
805 805
         if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
                     __LINE__,
848 848
                     array($transaction),
849 849
                     false,
850
-                    'EE_Transaction: ' . $transaction->ID()
850
+                    'EE_Transaction: '.$transaction->ID()
851 851
                 );
852 852
             }
853 853
             return;
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
                         __LINE__,
865 865
                         array($payment),
866 866
                         false,
867
-                        'EE_Transaction: ' . $transaction->ID()
867
+                        'EE_Transaction: '.$transaction->ID()
868 868
                     );
869 869
                 }
870 870
                 return;
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
             }
927 927
             $total_line_item = $transaction->total_line_item();
928 928
             // $transaction_in_progress->line
929
-            if (! $total_line_item instanceof EE_Line_Item) {
929
+            if ( ! $total_line_item instanceof EE_Line_Item) {
930 930
                 throw new DomainException(
931 931
                     esc_html__(
932 932
                         'Transaction does not have a valid Total Line Item associated with it.',
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
         $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item);
965 965
         foreach ($ticket_line_items as $ticket_line_item) {
966 966
             if ($ticket_line_item instanceof EE_Line_Item) {
967
-                $valid_reserved_tickets[ $ticket_line_item->ID() ] = $ticket_line_item;
967
+                $valid_reserved_tickets[$ticket_line_item->ID()] = $ticket_line_item;
968 968
             }
969 969
         }
970 970
         return $valid_reserved_tickets;
@@ -997,7 +997,7 @@  discard block
 block discarded – undo
997 997
         $total_tickets_released = 0;
998 998
         $sold_out_events = array();
999 999
         foreach ($tickets_with_reservations as $ticket_with_reservations) {
1000
-            if (! $ticket_with_reservations instanceof EE_Ticket) {
1000
+            if ( ! $ticket_with_reservations instanceof EE_Ticket) {
1001 1001
                 continue;
1002 1002
             }
1003 1003
             // The $valid_reserved_ticket_line_items tells us what the reserved count on their tickets (and datetimes)
@@ -1018,9 +1018,9 @@  discard block
 block discarded – undo
1018 1018
             if ($expired_reservations_count > 0) {
1019 1019
                 $ticket_with_reservations->add_extra_meta(
1020 1020
                     EE_Ticket::META_KEY_TICKET_RESERVATIONS,
1021
-                    __LINE__ . ') ' . $source . '()'
1021
+                    __LINE__.') '.$source.'()'
1022 1022
                 );
1023
-                $ticket_with_reservations->decreaseReserved($expired_reservations_count, true, 'TicketSalesMonitor:' . __LINE__);
1023
+                $ticket_with_reservations->decreaseReserved($expired_reservations_count, true, 'TicketSalesMonitor:'.__LINE__);
1024 1024
                 $total_tickets_released += $expired_reservations_count;
1025 1025
                 $event = $ticket_with_reservations->get_related_event();
1026 1026
                 // track sold out events
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
     {
1057 1057
         /** @type WPDB $wpdb */
1058 1058
         global $wpdb;
1059
-        if (! absint($timestamp)) {
1059
+        if ( ! absint($timestamp)) {
1060 1060
             /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
1061 1061
             $session_lifespan = LoaderFactory::getLoader()->getShared(
1062 1062
                 'EventEspresso\core\domain\values\session\SessionLifespan'
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
         }
1066 1066
         return $wpdb->query(
1067 1067
             $wpdb->prepare(
1068
-                'DELETE FROM ' . EEM_Line_Item::instance()->table() . '
1068
+                'DELETE FROM '.EEM_Line_Item::instance()->table().'
1069 1069
                 WHERE TXN_ID = 0 AND LIN_timestamp <= %s',
1070 1070
                 // use GMT time because that's what LIN_timestamps are in
1071 1071
                 date('Y-m-d H:i:s', $timestamp)
Please login to merge, or discard this patch.
admin/extend/registrations/Extend_Registrations_Admin_Page.core.php 2 patches
Indentation   +1210 added lines, -1210 removed lines patch added patch discarded remove patch
@@ -16,1267 +16,1267 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * This is used to hold the reports template data which is setup early in the request.
21
-     *
22
-     * @type array
23
-     */
24
-    protected $_reports_template_data = array();
19
+	/**
20
+	 * This is used to hold the reports template data which is setup early in the request.
21
+	 *
22
+	 * @type array
23
+	 */
24
+	protected $_reports_template_data = array();
25 25
 
26 26
 
27
-    /**
28
-     * Extend_Registrations_Admin_Page constructor.
29
-     *
30
-     * @param bool $routing
31
-     */
32
-    public function __construct($routing = true)
33
-    {
34
-        parent::__construct($routing);
35
-        if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
39
-        }
40
-    }
27
+	/**
28
+	 * Extend_Registrations_Admin_Page constructor.
29
+	 *
30
+	 * @param bool $routing
31
+	 */
32
+	public function __construct($routing = true)
33
+	{
34
+		parent::__construct($routing);
35
+		if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
+			define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
+			define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
+			define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
39
+		}
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * Extending page configuration.
45
-     */
46
-    protected function _extend_page_config()
47
-    {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
-            ? $this->_req_data['_REG_ID']
51
-            : 0;
52
-        $new_page_routes = array(
53
-            'reports'                      => array(
54
-                'func'       => '_registration_reports',
55
-                'capability' => 'ee_read_registrations',
56
-            ),
57
-            'registration_checkins'        => array(
58
-                'func'       => '_registration_checkin_list_table',
59
-                'capability' => 'ee_read_checkins',
60
-            ),
61
-            'newsletter_selected_send'     => array(
62
-                'func'       => '_newsletter_selected_send',
63
-                'noheader'   => true,
64
-                'capability' => 'ee_send_message',
65
-            ),
66
-            'delete_checkin_rows'          => array(
67
-                'func'       => '_delete_checkin_rows',
68
-                'noheader'   => true,
69
-                'capability' => 'ee_delete_checkins',
70
-            ),
71
-            'delete_checkin_row'           => array(
72
-                'func'       => '_delete_checkin_row',
73
-                'noheader'   => true,
74
-                'capability' => 'ee_delete_checkin',
75
-                'obj_id'     => $reg_id,
76
-            ),
77
-            'toggle_checkin_status'        => array(
78
-                'func'       => '_toggle_checkin_status',
79
-                'noheader'   => true,
80
-                'capability' => 'ee_edit_checkin',
81
-                'obj_id'     => $reg_id,
82
-            ),
83
-            'toggle_checkin_status_bulk'   => array(
84
-                'func'       => '_toggle_checkin_status',
85
-                'noheader'   => true,
86
-                'capability' => 'ee_edit_checkins',
87
-            ),
88
-            'event_registrations'          => array(
89
-                'func'       => '_event_registrations_list_table',
90
-                'capability' => 'ee_read_checkins',
91
-            ),
92
-            'registrations_checkin_report' => array(
93
-                'func'       => '_registrations_checkin_report',
94
-                'noheader'   => true,
95
-                'capability' => 'ee_read_registrations',
96
-            ),
97
-        );
98
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
99
-        $new_page_config = array(
100
-            'reports'               => array(
101
-                'nav'           => array(
102
-                    'label' => esc_html__('Reports', 'event_espresso'),
103
-                    'order' => 30,
104
-                ),
105
-                'help_tabs'     => array(
106
-                    'registrations_reports_help_tab' => array(
107
-                        'title'    => esc_html__('Registration Reports', 'event_espresso'),
108
-                        'filename' => 'registrations_reports',
109
-                    ),
110
-                ),
111
-                /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
112
-                'require_nonce' => false,
113
-            ),
114
-            'event_registrations'   => array(
115
-                'nav'           => array(
116
-                    'label'      => esc_html__('Event Check-In', 'event_espresso'),
117
-                    'order'      => 10,
118
-                    'persistent' => true,
119
-                ),
120
-                'help_tabs'     => array(
121
-                    'registrations_event_checkin_help_tab'                       => array(
122
-                        'title'    => esc_html__('Registrations Event Check-In', 'event_espresso'),
123
-                        'filename' => 'registrations_event_checkin',
124
-                    ),
125
-                    'registrations_event_checkin_table_column_headings_help_tab' => array(
126
-                        'title'    => esc_html__('Event Check-In Table Column Headings', 'event_espresso'),
127
-                        'filename' => 'registrations_event_checkin_table_column_headings',
128
-                    ),
129
-                    'registrations_event_checkin_filters_help_tab'               => array(
130
-                        'title'    => esc_html__('Event Check-In Filters', 'event_espresso'),
131
-                        'filename' => 'registrations_event_checkin_filters',
132
-                    ),
133
-                    'registrations_event_checkin_views_help_tab'                 => array(
134
-                        'title'    => esc_html__('Event Check-In Views', 'event_espresso'),
135
-                        'filename' => 'registrations_event_checkin_views',
136
-                    ),
137
-                    'registrations_event_checkin_other_help_tab'                 => array(
138
-                        'title'    => esc_html__('Event Check-In Other', 'event_espresso'),
139
-                        'filename' => 'registrations_event_checkin_other',
140
-                    ),
141
-                ),
142
-                'help_tour'     => array('Event_Checkin_Help_Tour'),
143
-                'qtips'         => array('Registration_List_Table_Tips'),
144
-                'list_table'    => 'EE_Event_Registrations_List_Table',
145
-                'metaboxes'     => array(),
146
-                'require_nonce' => false,
147
-            ),
148
-            'registration_checkins' => array(
149
-                'nav'           => array(
150
-                    'label'      => esc_html__('Check-In Records', 'event_espresso'),
151
-                    'order'      => 15,
152
-                    'persistent' => false,
153
-                    'url'        => '',
154
-                ),
155
-                'list_table'    => 'EE_Registration_CheckIn_List_Table',
156
-                // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
157
-                'metaboxes'     => array(),
158
-                'require_nonce' => false,
159
-            ),
160
-        );
161
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
162
-        $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
163
-        $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
164
-    }
43
+	/**
44
+	 * Extending page configuration.
45
+	 */
46
+	protected function _extend_page_config()
47
+	{
48
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
+			? $this->_req_data['_REG_ID']
51
+			: 0;
52
+		$new_page_routes = array(
53
+			'reports'                      => array(
54
+				'func'       => '_registration_reports',
55
+				'capability' => 'ee_read_registrations',
56
+			),
57
+			'registration_checkins'        => array(
58
+				'func'       => '_registration_checkin_list_table',
59
+				'capability' => 'ee_read_checkins',
60
+			),
61
+			'newsletter_selected_send'     => array(
62
+				'func'       => '_newsletter_selected_send',
63
+				'noheader'   => true,
64
+				'capability' => 'ee_send_message',
65
+			),
66
+			'delete_checkin_rows'          => array(
67
+				'func'       => '_delete_checkin_rows',
68
+				'noheader'   => true,
69
+				'capability' => 'ee_delete_checkins',
70
+			),
71
+			'delete_checkin_row'           => array(
72
+				'func'       => '_delete_checkin_row',
73
+				'noheader'   => true,
74
+				'capability' => 'ee_delete_checkin',
75
+				'obj_id'     => $reg_id,
76
+			),
77
+			'toggle_checkin_status'        => array(
78
+				'func'       => '_toggle_checkin_status',
79
+				'noheader'   => true,
80
+				'capability' => 'ee_edit_checkin',
81
+				'obj_id'     => $reg_id,
82
+			),
83
+			'toggle_checkin_status_bulk'   => array(
84
+				'func'       => '_toggle_checkin_status',
85
+				'noheader'   => true,
86
+				'capability' => 'ee_edit_checkins',
87
+			),
88
+			'event_registrations'          => array(
89
+				'func'       => '_event_registrations_list_table',
90
+				'capability' => 'ee_read_checkins',
91
+			),
92
+			'registrations_checkin_report' => array(
93
+				'func'       => '_registrations_checkin_report',
94
+				'noheader'   => true,
95
+				'capability' => 'ee_read_registrations',
96
+			),
97
+		);
98
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
99
+		$new_page_config = array(
100
+			'reports'               => array(
101
+				'nav'           => array(
102
+					'label' => esc_html__('Reports', 'event_espresso'),
103
+					'order' => 30,
104
+				),
105
+				'help_tabs'     => array(
106
+					'registrations_reports_help_tab' => array(
107
+						'title'    => esc_html__('Registration Reports', 'event_espresso'),
108
+						'filename' => 'registrations_reports',
109
+					),
110
+				),
111
+				/*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
112
+				'require_nonce' => false,
113
+			),
114
+			'event_registrations'   => array(
115
+				'nav'           => array(
116
+					'label'      => esc_html__('Event Check-In', 'event_espresso'),
117
+					'order'      => 10,
118
+					'persistent' => true,
119
+				),
120
+				'help_tabs'     => array(
121
+					'registrations_event_checkin_help_tab'                       => array(
122
+						'title'    => esc_html__('Registrations Event Check-In', 'event_espresso'),
123
+						'filename' => 'registrations_event_checkin',
124
+					),
125
+					'registrations_event_checkin_table_column_headings_help_tab' => array(
126
+						'title'    => esc_html__('Event Check-In Table Column Headings', 'event_espresso'),
127
+						'filename' => 'registrations_event_checkin_table_column_headings',
128
+					),
129
+					'registrations_event_checkin_filters_help_tab'               => array(
130
+						'title'    => esc_html__('Event Check-In Filters', 'event_espresso'),
131
+						'filename' => 'registrations_event_checkin_filters',
132
+					),
133
+					'registrations_event_checkin_views_help_tab'                 => array(
134
+						'title'    => esc_html__('Event Check-In Views', 'event_espresso'),
135
+						'filename' => 'registrations_event_checkin_views',
136
+					),
137
+					'registrations_event_checkin_other_help_tab'                 => array(
138
+						'title'    => esc_html__('Event Check-In Other', 'event_espresso'),
139
+						'filename' => 'registrations_event_checkin_other',
140
+					),
141
+				),
142
+				'help_tour'     => array('Event_Checkin_Help_Tour'),
143
+				'qtips'         => array('Registration_List_Table_Tips'),
144
+				'list_table'    => 'EE_Event_Registrations_List_Table',
145
+				'metaboxes'     => array(),
146
+				'require_nonce' => false,
147
+			),
148
+			'registration_checkins' => array(
149
+				'nav'           => array(
150
+					'label'      => esc_html__('Check-In Records', 'event_espresso'),
151
+					'order'      => 15,
152
+					'persistent' => false,
153
+					'url'        => '',
154
+				),
155
+				'list_table'    => 'EE_Registration_CheckIn_List_Table',
156
+				// 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
157
+				'metaboxes'     => array(),
158
+				'require_nonce' => false,
159
+			),
160
+		);
161
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
162
+		$this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
163
+		$this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
164
+	}
165 165
 
166 166
 
167
-    /**
168
-     * Ajax hooks for all routes in this page.
169
-     */
170
-    protected function _ajax_hooks()
171
-    {
172
-        parent::_ajax_hooks();
173
-        add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
174
-    }
167
+	/**
168
+	 * Ajax hooks for all routes in this page.
169
+	 */
170
+	protected function _ajax_hooks()
171
+	{
172
+		parent::_ajax_hooks();
173
+		add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
174
+	}
175 175
 
176 176
 
177
-    /**
178
-     * Global scripts for all routes in this page.
179
-     */
180
-    public function load_scripts_styles()
181
-    {
182
-        parent::load_scripts_styles();
183
-        // if newsletter message type is active then let's add filter and load js for it.
184
-        if (EEH_MSG_Template::is_mt_active('newsletter')) {
185
-            // enqueue newsletter js
186
-            wp_enqueue_script(
187
-                'ee-newsletter-trigger',
188
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
189
-                array('ee-dialog'),
190
-                EVENT_ESPRESSO_VERSION,
191
-                true
192
-            );
193
-            wp_enqueue_style(
194
-                'ee-newsletter-trigger-css',
195
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
196
-                array(),
197
-                EVENT_ESPRESSO_VERSION
198
-            );
199
-            // hook in buttons for newsletter message type trigger.
200
-            add_action(
201
-                'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
202
-                array($this, 'add_newsletter_action_buttons'),
203
-                10
204
-            );
205
-        }
206
-    }
177
+	/**
178
+	 * Global scripts for all routes in this page.
179
+	 */
180
+	public function load_scripts_styles()
181
+	{
182
+		parent::load_scripts_styles();
183
+		// if newsletter message type is active then let's add filter and load js for it.
184
+		if (EEH_MSG_Template::is_mt_active('newsletter')) {
185
+			// enqueue newsletter js
186
+			wp_enqueue_script(
187
+				'ee-newsletter-trigger',
188
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
189
+				array('ee-dialog'),
190
+				EVENT_ESPRESSO_VERSION,
191
+				true
192
+			);
193
+			wp_enqueue_style(
194
+				'ee-newsletter-trigger-css',
195
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
196
+				array(),
197
+				EVENT_ESPRESSO_VERSION
198
+			);
199
+			// hook in buttons for newsletter message type trigger.
200
+			add_action(
201
+				'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
202
+				array($this, 'add_newsletter_action_buttons'),
203
+				10
204
+			);
205
+		}
206
+	}
207 207
 
208 208
 
209
-    /**
210
-     * Scripts and styles for just the reports route.
211
-     */
212
-    public function load_scripts_styles_reports()
213
-    {
214
-        wp_register_script(
215
-            'ee-reg-reports-js',
216
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
217
-            array('google-charts'),
218
-            EVENT_ESPRESSO_VERSION,
219
-            true
220
-        );
221
-        wp_enqueue_script('ee-reg-reports-js');
222
-        $this->_registration_reports_js_setup();
223
-    }
209
+	/**
210
+	 * Scripts and styles for just the reports route.
211
+	 */
212
+	public function load_scripts_styles_reports()
213
+	{
214
+		wp_register_script(
215
+			'ee-reg-reports-js',
216
+			REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
217
+			array('google-charts'),
218
+			EVENT_ESPRESSO_VERSION,
219
+			true
220
+		);
221
+		wp_enqueue_script('ee-reg-reports-js');
222
+		$this->_registration_reports_js_setup();
223
+	}
224 224
 
225 225
 
226
-    /**
227
-     * Register screen options for event_registrations route.
228
-     */
229
-    protected function _add_screen_options_event_registrations()
230
-    {
231
-        $this->_per_page_screen_option();
232
-    }
226
+	/**
227
+	 * Register screen options for event_registrations route.
228
+	 */
229
+	protected function _add_screen_options_event_registrations()
230
+	{
231
+		$this->_per_page_screen_option();
232
+	}
233 233
 
234 234
 
235
-    /**
236
-     * Register screen options for registration_checkins route
237
-     */
238
-    protected function _add_screen_options_registration_checkins()
239
-    {
240
-        $page_title = $this->_admin_page_title;
241
-        $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso');
242
-        $this->_per_page_screen_option();
243
-        $this->_admin_page_title = $page_title;
244
-    }
235
+	/**
236
+	 * Register screen options for registration_checkins route
237
+	 */
238
+	protected function _add_screen_options_registration_checkins()
239
+	{
240
+		$page_title = $this->_admin_page_title;
241
+		$this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso');
242
+		$this->_per_page_screen_option();
243
+		$this->_admin_page_title = $page_title;
244
+	}
245 245
 
246 246
 
247
-    /**
248
-     * Set views property for event_registrations route.
249
-     */
250
-    protected function _set_list_table_views_event_registrations()
251
-    {
252
-        $this->_views = array(
253
-            'all' => array(
254
-                'slug'        => 'all',
255
-                'label'       => esc_html__('All', 'event_espresso'),
256
-                'count'       => 0,
257
-                'bulk_action' => ! isset($this->_req_data['event_id'])
258
-                    ? array()
259
-                    : array(
260
-                        'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'),
261
-                    ),
262
-            ),
263
-        );
264
-    }
247
+	/**
248
+	 * Set views property for event_registrations route.
249
+	 */
250
+	protected function _set_list_table_views_event_registrations()
251
+	{
252
+		$this->_views = array(
253
+			'all' => array(
254
+				'slug'        => 'all',
255
+				'label'       => esc_html__('All', 'event_espresso'),
256
+				'count'       => 0,
257
+				'bulk_action' => ! isset($this->_req_data['event_id'])
258
+					? array()
259
+					: array(
260
+						'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'),
261
+					),
262
+			),
263
+		);
264
+	}
265 265
 
266 266
 
267
-    /**
268
-     * Set views property for registration_checkins route.
269
-     */
270
-    protected function _set_list_table_views_registration_checkins()
271
-    {
272
-        $this->_views = array(
273
-            'all' => array(
274
-                'slug'        => 'all',
275
-                'label'       => esc_html__('All', 'event_espresso'),
276
-                'count'       => 0,
277
-                'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')),
278
-            ),
279
-        );
280
-    }
267
+	/**
268
+	 * Set views property for registration_checkins route.
269
+	 */
270
+	protected function _set_list_table_views_registration_checkins()
271
+	{
272
+		$this->_views = array(
273
+			'all' => array(
274
+				'slug'        => 'all',
275
+				'label'       => esc_html__('All', 'event_espresso'),
276
+				'count'       => 0,
277
+				'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')),
278
+			),
279
+		);
280
+	}
281 281
 
282 282
 
283
-    /**
284
-     * callback for ajax action.
285
-     *
286
-     * @since 4.3.0
287
-     * @return void (JSON)
288
-     * @throws EE_Error
289
-     * @throws InvalidArgumentException
290
-     * @throws InvalidDataTypeException
291
-     * @throws InvalidInterfaceException
292
-     */
293
-    public function get_newsletter_form_content()
294
-    {
295
-        // do a nonce check cause we're not coming in from an normal route here.
296
-        $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
297
-            $this->_req_data['get_newsletter_form_content_nonce']
298
-        ) : '';
299
-        $nonce_ref = 'get_newsletter_form_content_nonce';
300
-        $this->_verify_nonce($nonce, $nonce_ref);
301
-        // let's get the mtp for the incoming MTP_ ID
302
-        if (! isset($this->_req_data['GRP_ID'])) {
303
-            EE_Error::add_error(
304
-                esc_html__(
305
-                    'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
306
-                    'event_espresso'
307
-                ),
308
-                __FILE__,
309
-                __FUNCTION__,
310
-                __LINE__
311
-            );
312
-            $this->_template_args['success'] = false;
313
-            $this->_template_args['error'] = true;
314
-            $this->_return_json();
315
-        }
316
-        $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
317
-        if (! $MTPG instanceof EE_Message_Template_Group) {
318
-            EE_Error::add_error(
319
-                sprintf(
320
-                    esc_html__(
321
-                        'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
322
-                        'event_espresso'
323
-                    ),
324
-                    $this->_req_data['GRP_ID']
325
-                ),
326
-                __FILE__,
327
-                __FUNCTION__,
328
-                __LINE__
329
-            );
330
-            $this->_template_args['success'] = false;
331
-            $this->_template_args['error'] = true;
332
-            $this->_return_json();
333
-        }
334
-        $MTPs = $MTPG->context_templates();
335
-        $MTPs = $MTPs['attendee'];
336
-        $template_fields = array();
337
-        /** @var EE_Message_Template $MTP */
338
-        foreach ($MTPs as $MTP) {
339
-            $field = $MTP->get('MTP_template_field');
340
-            if ($field === 'content') {
341
-                $content = $MTP->get('MTP_content');
342
-                if (! empty($content['newsletter_content'])) {
343
-                    $template_fields['newsletter_content'] = $content['newsletter_content'];
344
-                }
345
-                continue;
346
-            }
347
-            $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
348
-        }
349
-        $this->_template_args['success'] = true;
350
-        $this->_template_args['error'] = false;
351
-        $this->_template_args['data'] = array(
352
-            'batch_message_from'    => isset($template_fields['from'])
353
-                ? $template_fields['from']
354
-                : '',
355
-            'batch_message_subject' => isset($template_fields['subject'])
356
-                ? $template_fields['subject']
357
-                : '',
358
-            'batch_message_content' => isset($template_fields['newsletter_content'])
359
-                ? $template_fields['newsletter_content']
360
-                : '',
361
-        );
362
-        $this->_return_json();
363
-    }
283
+	/**
284
+	 * callback for ajax action.
285
+	 *
286
+	 * @since 4.3.0
287
+	 * @return void (JSON)
288
+	 * @throws EE_Error
289
+	 * @throws InvalidArgumentException
290
+	 * @throws InvalidDataTypeException
291
+	 * @throws InvalidInterfaceException
292
+	 */
293
+	public function get_newsletter_form_content()
294
+	{
295
+		// do a nonce check cause we're not coming in from an normal route here.
296
+		$nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
297
+			$this->_req_data['get_newsletter_form_content_nonce']
298
+		) : '';
299
+		$nonce_ref = 'get_newsletter_form_content_nonce';
300
+		$this->_verify_nonce($nonce, $nonce_ref);
301
+		// let's get the mtp for the incoming MTP_ ID
302
+		if (! isset($this->_req_data['GRP_ID'])) {
303
+			EE_Error::add_error(
304
+				esc_html__(
305
+					'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
306
+					'event_espresso'
307
+				),
308
+				__FILE__,
309
+				__FUNCTION__,
310
+				__LINE__
311
+			);
312
+			$this->_template_args['success'] = false;
313
+			$this->_template_args['error'] = true;
314
+			$this->_return_json();
315
+		}
316
+		$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
317
+		if (! $MTPG instanceof EE_Message_Template_Group) {
318
+			EE_Error::add_error(
319
+				sprintf(
320
+					esc_html__(
321
+						'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
322
+						'event_espresso'
323
+					),
324
+					$this->_req_data['GRP_ID']
325
+				),
326
+				__FILE__,
327
+				__FUNCTION__,
328
+				__LINE__
329
+			);
330
+			$this->_template_args['success'] = false;
331
+			$this->_template_args['error'] = true;
332
+			$this->_return_json();
333
+		}
334
+		$MTPs = $MTPG->context_templates();
335
+		$MTPs = $MTPs['attendee'];
336
+		$template_fields = array();
337
+		/** @var EE_Message_Template $MTP */
338
+		foreach ($MTPs as $MTP) {
339
+			$field = $MTP->get('MTP_template_field');
340
+			if ($field === 'content') {
341
+				$content = $MTP->get('MTP_content');
342
+				if (! empty($content['newsletter_content'])) {
343
+					$template_fields['newsletter_content'] = $content['newsletter_content'];
344
+				}
345
+				continue;
346
+			}
347
+			$template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
348
+		}
349
+		$this->_template_args['success'] = true;
350
+		$this->_template_args['error'] = false;
351
+		$this->_template_args['data'] = array(
352
+			'batch_message_from'    => isset($template_fields['from'])
353
+				? $template_fields['from']
354
+				: '',
355
+			'batch_message_subject' => isset($template_fields['subject'])
356
+				? $template_fields['subject']
357
+				: '',
358
+			'batch_message_content' => isset($template_fields['newsletter_content'])
359
+				? $template_fields['newsletter_content']
360
+				: '',
361
+		);
362
+		$this->_return_json();
363
+	}
364 364
 
365 365
 
366
-    /**
367
-     * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
368
-     *
369
-     * @since 4.3.0
370
-     * @param EE_Admin_List_Table $list_table
371
-     * @return void
372
-     * @throws InvalidArgumentException
373
-     * @throws InvalidDataTypeException
374
-     * @throws InvalidInterfaceException
375
-     */
376
-    public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
377
-    {
378
-        if (! EE_Registry::instance()->CAP->current_user_can(
379
-            'ee_send_message',
380
-            'espresso_registrations_newsletter_selected_send'
381
-        )
382
-        ) {
383
-            return;
384
-        }
385
-        $routes_to_add_to = array(
386
-            'contact_list',
387
-            'event_registrations',
388
-            'default',
389
-        );
390
-        if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
391
-            if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
392
-                || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
393
-            ) {
394
-                echo '';
395
-            } else {
396
-                $button_text = sprintf(
397
-                    esc_html__('Send Batch Message (%s selected)', 'event_espresso'),
398
-                    '<span class="send-selected-newsletter-count">0</span>'
399
-                );
400
-                echo '<button id="selected-batch-send-trigger" class="button secondary-button">'
401
-                     . '<span class="dashicons dashicons-email "></span>'
402
-                     . $button_text
403
-                     . '</button>';
404
-                add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
405
-            }
406
-        }
407
-    }
366
+	/**
367
+	 * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
368
+	 *
369
+	 * @since 4.3.0
370
+	 * @param EE_Admin_List_Table $list_table
371
+	 * @return void
372
+	 * @throws InvalidArgumentException
373
+	 * @throws InvalidDataTypeException
374
+	 * @throws InvalidInterfaceException
375
+	 */
376
+	public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
377
+	{
378
+		if (! EE_Registry::instance()->CAP->current_user_can(
379
+			'ee_send_message',
380
+			'espresso_registrations_newsletter_selected_send'
381
+		)
382
+		) {
383
+			return;
384
+		}
385
+		$routes_to_add_to = array(
386
+			'contact_list',
387
+			'event_registrations',
388
+			'default',
389
+		);
390
+		if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
391
+			if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
392
+				|| (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
393
+			) {
394
+				echo '';
395
+			} else {
396
+				$button_text = sprintf(
397
+					esc_html__('Send Batch Message (%s selected)', 'event_espresso'),
398
+					'<span class="send-selected-newsletter-count">0</span>'
399
+				);
400
+				echo '<button id="selected-batch-send-trigger" class="button secondary-button">'
401
+					 . '<span class="dashicons dashicons-email "></span>'
402
+					 . $button_text
403
+					 . '</button>';
404
+				add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
405
+			}
406
+		}
407
+	}
408 408
 
409 409
 
410
-    /**
411
-     * @throws DomainException
412
-     * @throws EE_Error
413
-     * @throws InvalidArgumentException
414
-     * @throws InvalidDataTypeException
415
-     * @throws InvalidInterfaceException
416
-     */
417
-    public function newsletter_send_form_skeleton()
418
-    {
419
-        $list_table = $this->_list_table_object;
420
-        $codes = array();
421
-        // need to templates for the newsletter message type for the template selector.
422
-        $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0);
423
-        $mtps = EEM_Message_Template_Group::instance()->get_all(
424
-            array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
425
-        );
426
-        foreach ($mtps as $mtp) {
427
-            $name = $mtp->name();
428
-            $values[] = array(
429
-                'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name,
430
-                'id'   => $mtp->ID(),
431
-            );
432
-        }
433
-        // need to get a list of shortcodes that are available for the newsletter message type.
434
-        $shortcodes = EEH_MSG_Template::get_shortcodes(
435
-            'newsletter',
436
-            'email',
437
-            array(),
438
-            'attendee',
439
-            false
440
-        );
441
-        foreach ($shortcodes as $field => $shortcode_array) {
442
-            $available_shortcodes = array();
443
-            foreach ($shortcode_array as $shortcode => $shortcode_details) {
444
-                $field_id = $field === '[NEWSLETTER_CONTENT]'
445
-                    ? 'content'
446
-                    : $field;
447
-                $field_id = 'batch-message-' . strtolower($field_id);
448
-                $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
449
-                                          . $shortcode
450
-                                          . '" data-linked-input-id="' . $field_id . '">'
451
-                                          . $shortcode
452
-                                          . '</span>';
453
-            }
454
-            $codes[ $field ] = implode(', ', $available_shortcodes);
455
-        }
456
-        $shortcodes = $codes;
457
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
458
-        $form_template_args = array(
459
-            'form_action'       => admin_url('admin.php?page=espresso_registrations'),
460
-            'form_route'        => 'newsletter_selected_send',
461
-            'form_nonce_name'   => 'newsletter_selected_send_nonce',
462
-            'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
463
-            'redirect_back_to'  => $this->_req_action,
464
-            'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
465
-            'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
466
-            'shortcodes'        => $shortcodes,
467
-            'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
468
-        );
469
-        EEH_Template::display_template($form_template, $form_template_args);
470
-    }
410
+	/**
411
+	 * @throws DomainException
412
+	 * @throws EE_Error
413
+	 * @throws InvalidArgumentException
414
+	 * @throws InvalidDataTypeException
415
+	 * @throws InvalidInterfaceException
416
+	 */
417
+	public function newsletter_send_form_skeleton()
418
+	{
419
+		$list_table = $this->_list_table_object;
420
+		$codes = array();
421
+		// need to templates for the newsletter message type for the template selector.
422
+		$values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0);
423
+		$mtps = EEM_Message_Template_Group::instance()->get_all(
424
+			array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
425
+		);
426
+		foreach ($mtps as $mtp) {
427
+			$name = $mtp->name();
428
+			$values[] = array(
429
+				'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name,
430
+				'id'   => $mtp->ID(),
431
+			);
432
+		}
433
+		// need to get a list of shortcodes that are available for the newsletter message type.
434
+		$shortcodes = EEH_MSG_Template::get_shortcodes(
435
+			'newsletter',
436
+			'email',
437
+			array(),
438
+			'attendee',
439
+			false
440
+		);
441
+		foreach ($shortcodes as $field => $shortcode_array) {
442
+			$available_shortcodes = array();
443
+			foreach ($shortcode_array as $shortcode => $shortcode_details) {
444
+				$field_id = $field === '[NEWSLETTER_CONTENT]'
445
+					? 'content'
446
+					: $field;
447
+				$field_id = 'batch-message-' . strtolower($field_id);
448
+				$available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
449
+										  . $shortcode
450
+										  . '" data-linked-input-id="' . $field_id . '">'
451
+										  . $shortcode
452
+										  . '</span>';
453
+			}
454
+			$codes[ $field ] = implode(', ', $available_shortcodes);
455
+		}
456
+		$shortcodes = $codes;
457
+		$form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
458
+		$form_template_args = array(
459
+			'form_action'       => admin_url('admin.php?page=espresso_registrations'),
460
+			'form_route'        => 'newsletter_selected_send',
461
+			'form_nonce_name'   => 'newsletter_selected_send_nonce',
462
+			'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
463
+			'redirect_back_to'  => $this->_req_action,
464
+			'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
465
+			'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
466
+			'shortcodes'        => $shortcodes,
467
+			'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
468
+		);
469
+		EEH_Template::display_template($form_template, $form_template_args);
470
+	}
471 471
 
472 472
 
473
-    /**
474
-     * Handles sending selected registrations/contacts a newsletter.
475
-     *
476
-     * @since  4.3.0
477
-     * @return void
478
-     * @throws EE_Error
479
-     * @throws InvalidArgumentException
480
-     * @throws InvalidDataTypeException
481
-     * @throws InvalidInterfaceException
482
-     */
483
-    protected function _newsletter_selected_send()
484
-    {
485
-        $success = true;
486
-        // first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
487
-        if (empty($this->_req_data['newsletter_mtp_selected'])) {
488
-            EE_Error::add_error(
489
-                esc_html__(
490
-                    'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
491
-                    'event_espresso'
492
-                ),
493
-                __FILE__,
494
-                __FUNCTION__,
495
-                __LINE__
496
-            );
497
-            $success = false;
498
-        }
499
-        if ($success) {
500
-            // update Message template in case there are any changes
501
-            $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
502
-                $this->_req_data['newsletter_mtp_selected']
503
-            );
504
-            $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
505
-                ? $Message_Template_Group->context_templates()
506
-                : array();
507
-            if (empty($Message_Templates)) {
508
-                EE_Error::add_error(
509
-                    esc_html__(
510
-                        'Unable to retrieve message template fields from the db. Messages not sent.',
511
-                        'event_espresso'
512
-                    ),
513
-                    __FILE__,
514
-                    __FUNCTION__,
515
-                    __LINE__
516
-                );
517
-            }
518
-            // let's just update the specific fields
519
-            foreach ($Message_Templates['attendee'] as $Message_Template) {
520
-                if ($Message_Template instanceof EE_Message_Template) {
521
-                    $field = $Message_Template->get('MTP_template_field');
522
-                    $content = $Message_Template->get('MTP_content');
523
-                    $new_content = $content;
524
-                    switch ($field) {
525
-                        case 'from':
526
-                            $new_content = ! empty($this->_req_data['batch_message']['from'])
527
-                                ? $this->_req_data['batch_message']['from']
528
-                                : $content;
529
-                            break;
530
-                        case 'subject':
531
-                            $new_content = ! empty($this->_req_data['batch_message']['subject'])
532
-                                ? $this->_req_data['batch_message']['subject']
533
-                                : $content;
534
-                            break;
535
-                        case 'content':
536
-                            $new_content = $content;
537
-                            $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
538
-                                ? $this->_req_data['batch_message']['content']
539
-                                : $content['newsletter_content'];
540
-                            break;
541
-                        default:
542
-                            // continue the foreach loop, we don't want to set $new_content nor save.
543
-                            continue 2;
544
-                    }
545
-                    $Message_Template->set('MTP_content', $new_content);
546
-                    $Message_Template->save();
547
-                }
548
-            }
549
-            // great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
550
-            $id_type = ! empty($this->_req_data['batch_message']['id_type'])
551
-                ? $this->_req_data['batch_message']['id_type']
552
-                : 'registration';
553
-            // id_type will affect how we assemble the ids.
554
-            $ids = ! empty($this->_req_data['batch_message']['ids'])
555
-                ? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
556
-                : array();
557
-            $registrations_used_for_contact_data = array();
558
-            // using switch because eventually we'll have other contexts that will be used for generating messages.
559
-            switch ($id_type) {
560
-                case 'registration':
561
-                    $registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
562
-                        array(
563
-                            array(
564
-                                'REG_ID' => array('IN', $ids),
565
-                            ),
566
-                        )
567
-                    );
568
-                    break;
569
-                case 'contact':
570
-                    $registrations_used_for_contact_data = EEM_Registration::instance()
571
-                                                                           ->get_latest_registration_for_each_of_given_contacts(
572
-                                                                               $ids
573
-                                                                           );
574
-                    break;
575
-            }
576
-            do_action_ref_array(
577
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
578
-                array(
579
-                    $registrations_used_for_contact_data,
580
-                    $Message_Template_Group->ID(),
581
-                )
582
-            );
583
-            // kept for backward compat, internally we no longer use this action.
584
-            // @deprecated 4.8.36.rc.002
585
-            $contacts = $id_type === 'registration'
586
-                ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
587
-                : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
588
-            do_action_ref_array(
589
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
590
-                array(
591
-                    $contacts,
592
-                    $Message_Template_Group->ID(),
593
-                )
594
-            );
595
-        }
596
-        $query_args = array(
597
-            'action' => ! empty($this->_req_data['redirect_back_to'])
598
-                ? $this->_req_data['redirect_back_to']
599
-                : 'default',
600
-        );
601
-        $this->_redirect_after_action(false, '', '', $query_args, true);
602
-    }
473
+	/**
474
+	 * Handles sending selected registrations/contacts a newsletter.
475
+	 *
476
+	 * @since  4.3.0
477
+	 * @return void
478
+	 * @throws EE_Error
479
+	 * @throws InvalidArgumentException
480
+	 * @throws InvalidDataTypeException
481
+	 * @throws InvalidInterfaceException
482
+	 */
483
+	protected function _newsletter_selected_send()
484
+	{
485
+		$success = true;
486
+		// first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
487
+		if (empty($this->_req_data['newsletter_mtp_selected'])) {
488
+			EE_Error::add_error(
489
+				esc_html__(
490
+					'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
491
+					'event_espresso'
492
+				),
493
+				__FILE__,
494
+				__FUNCTION__,
495
+				__LINE__
496
+			);
497
+			$success = false;
498
+		}
499
+		if ($success) {
500
+			// update Message template in case there are any changes
501
+			$Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
502
+				$this->_req_data['newsletter_mtp_selected']
503
+			);
504
+			$Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
505
+				? $Message_Template_Group->context_templates()
506
+				: array();
507
+			if (empty($Message_Templates)) {
508
+				EE_Error::add_error(
509
+					esc_html__(
510
+						'Unable to retrieve message template fields from the db. Messages not sent.',
511
+						'event_espresso'
512
+					),
513
+					__FILE__,
514
+					__FUNCTION__,
515
+					__LINE__
516
+				);
517
+			}
518
+			// let's just update the specific fields
519
+			foreach ($Message_Templates['attendee'] as $Message_Template) {
520
+				if ($Message_Template instanceof EE_Message_Template) {
521
+					$field = $Message_Template->get('MTP_template_field');
522
+					$content = $Message_Template->get('MTP_content');
523
+					$new_content = $content;
524
+					switch ($field) {
525
+						case 'from':
526
+							$new_content = ! empty($this->_req_data['batch_message']['from'])
527
+								? $this->_req_data['batch_message']['from']
528
+								: $content;
529
+							break;
530
+						case 'subject':
531
+							$new_content = ! empty($this->_req_data['batch_message']['subject'])
532
+								? $this->_req_data['batch_message']['subject']
533
+								: $content;
534
+							break;
535
+						case 'content':
536
+							$new_content = $content;
537
+							$new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
538
+								? $this->_req_data['batch_message']['content']
539
+								: $content['newsletter_content'];
540
+							break;
541
+						default:
542
+							// continue the foreach loop, we don't want to set $new_content nor save.
543
+							continue 2;
544
+					}
545
+					$Message_Template->set('MTP_content', $new_content);
546
+					$Message_Template->save();
547
+				}
548
+			}
549
+			// great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
550
+			$id_type = ! empty($this->_req_data['batch_message']['id_type'])
551
+				? $this->_req_data['batch_message']['id_type']
552
+				: 'registration';
553
+			// id_type will affect how we assemble the ids.
554
+			$ids = ! empty($this->_req_data['batch_message']['ids'])
555
+				? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
556
+				: array();
557
+			$registrations_used_for_contact_data = array();
558
+			// using switch because eventually we'll have other contexts that will be used for generating messages.
559
+			switch ($id_type) {
560
+				case 'registration':
561
+					$registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
562
+						array(
563
+							array(
564
+								'REG_ID' => array('IN', $ids),
565
+							),
566
+						)
567
+					);
568
+					break;
569
+				case 'contact':
570
+					$registrations_used_for_contact_data = EEM_Registration::instance()
571
+																		   ->get_latest_registration_for_each_of_given_contacts(
572
+																			   $ids
573
+																		   );
574
+					break;
575
+			}
576
+			do_action_ref_array(
577
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
578
+				array(
579
+					$registrations_used_for_contact_data,
580
+					$Message_Template_Group->ID(),
581
+				)
582
+			);
583
+			// kept for backward compat, internally we no longer use this action.
584
+			// @deprecated 4.8.36.rc.002
585
+			$contacts = $id_type === 'registration'
586
+				? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
587
+				: EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
588
+			do_action_ref_array(
589
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
590
+				array(
591
+					$contacts,
592
+					$Message_Template_Group->ID(),
593
+				)
594
+			);
595
+		}
596
+		$query_args = array(
597
+			'action' => ! empty($this->_req_data['redirect_back_to'])
598
+				? $this->_req_data['redirect_back_to']
599
+				: 'default',
600
+		);
601
+		$this->_redirect_after_action(false, '', '', $query_args, true);
602
+	}
603 603
 
604 604
 
605
-    /**
606
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
607
-     * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
608
-     */
609
-    protected function _registration_reports_js_setup()
610
-    {
611
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
612
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
613
-    }
605
+	/**
606
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
607
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
608
+	 */
609
+	protected function _registration_reports_js_setup()
610
+	{
611
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
612
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
613
+	}
614 614
 
615 615
 
616
-    /**
617
-     *        generates Business Reports regarding Registrations
618
-     *
619
-     * @access protected
620
-     * @return void
621
-     * @throws DomainException
622
-     */
623
-    protected function _registration_reports()
624
-    {
625
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
626
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
627
-            $template_path,
628
-            $this->_reports_template_data,
629
-            true
630
-        );
631
-        // the final template wrapper
632
-        $this->display_admin_page_with_no_sidebar();
633
-    }
616
+	/**
617
+	 *        generates Business Reports regarding Registrations
618
+	 *
619
+	 * @access protected
620
+	 * @return void
621
+	 * @throws DomainException
622
+	 */
623
+	protected function _registration_reports()
624
+	{
625
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
626
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
627
+			$template_path,
628
+			$this->_reports_template_data,
629
+			true
630
+		);
631
+		// the final template wrapper
632
+		$this->display_admin_page_with_no_sidebar();
633
+	}
634 634
 
635 635
 
636
-    /**
637
-     * Generates Business Report showing total registrations per day.
638
-     *
639
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
640
-     * @return string
641
-     * @throws EE_Error
642
-     * @throws InvalidArgumentException
643
-     * @throws InvalidDataTypeException
644
-     * @throws InvalidInterfaceException
645
-     */
646
-    private function _registrations_per_day_report($period = '-1 month')
647
-    {
648
-        $report_ID = 'reg-admin-registrations-per-day-report-dv';
649
-        $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
650
-        $results = (array) $results;
651
-        $regs = array();
652
-        $subtitle = '';
653
-        if ($results) {
654
-            $column_titles = array();
655
-            $tracker = 0;
656
-            foreach ($results as $result) {
657
-                $report_column_values = array();
658
-                foreach ($result as $property_name => $property_value) {
659
-                    $property_value = $property_name === 'Registration_REG_date' ? $property_value
660
-                        : (int) $property_value;
661
-                    $report_column_values[] = $property_value;
662
-                    if ($tracker === 0) {
663
-                        if ($property_name === 'Registration_REG_date') {
664
-                            $column_titles[] = esc_html__(
665
-                                'Date (only days with registrations are shown)',
666
-                                'event_espresso'
667
-                            );
668
-                        } else {
669
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
670
-                        }
671
-                    }
672
-                }
673
-                $tracker++;
674
-                $regs[] = $report_column_values;
675
-            }
676
-            // make sure the column_titles is pushed to the beginning of the array
677
-            array_unshift($regs, $column_titles);
678
-            // setup the date range.
679
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
680
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
681
-            $ending_date = new DateTime("now", $DateTimeZone);
682
-            $subtitle = sprintf(
683
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
684
-                $beginning_date->format('Y-m-d'),
685
-                $ending_date->format('Y-m-d')
686
-            );
687
-        }
688
-        $report_title = esc_html__('Total Registrations per Day', 'event_espresso');
689
-        $report_params = array(
690
-            'title'     => $report_title,
691
-            'subtitle'  => $subtitle,
692
-            'id'        => $report_ID,
693
-            'regs'      => $regs,
694
-            'noResults' => empty($regs),
695
-            'noRegsMsg' => sprintf(
696
-                esc_html__(
697
-                    '%sThere are currently no registration records in the last month for this report.%s',
698
-                    'event_espresso'
699
-                ),
700
-                '<h2>' . $report_title . '</h2><p>',
701
-                '</p>'
702
-            ),
703
-        );
704
-        wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
705
-        return $report_ID;
706
-    }
636
+	/**
637
+	 * Generates Business Report showing total registrations per day.
638
+	 *
639
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
640
+	 * @return string
641
+	 * @throws EE_Error
642
+	 * @throws InvalidArgumentException
643
+	 * @throws InvalidDataTypeException
644
+	 * @throws InvalidInterfaceException
645
+	 */
646
+	private function _registrations_per_day_report($period = '-1 month')
647
+	{
648
+		$report_ID = 'reg-admin-registrations-per-day-report-dv';
649
+		$results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
650
+		$results = (array) $results;
651
+		$regs = array();
652
+		$subtitle = '';
653
+		if ($results) {
654
+			$column_titles = array();
655
+			$tracker = 0;
656
+			foreach ($results as $result) {
657
+				$report_column_values = array();
658
+				foreach ($result as $property_name => $property_value) {
659
+					$property_value = $property_name === 'Registration_REG_date' ? $property_value
660
+						: (int) $property_value;
661
+					$report_column_values[] = $property_value;
662
+					if ($tracker === 0) {
663
+						if ($property_name === 'Registration_REG_date') {
664
+							$column_titles[] = esc_html__(
665
+								'Date (only days with registrations are shown)',
666
+								'event_espresso'
667
+							);
668
+						} else {
669
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
670
+						}
671
+					}
672
+				}
673
+				$tracker++;
674
+				$regs[] = $report_column_values;
675
+			}
676
+			// make sure the column_titles is pushed to the beginning of the array
677
+			array_unshift($regs, $column_titles);
678
+			// setup the date range.
679
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
680
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
681
+			$ending_date = new DateTime("now", $DateTimeZone);
682
+			$subtitle = sprintf(
683
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
684
+				$beginning_date->format('Y-m-d'),
685
+				$ending_date->format('Y-m-d')
686
+			);
687
+		}
688
+		$report_title = esc_html__('Total Registrations per Day', 'event_espresso');
689
+		$report_params = array(
690
+			'title'     => $report_title,
691
+			'subtitle'  => $subtitle,
692
+			'id'        => $report_ID,
693
+			'regs'      => $regs,
694
+			'noResults' => empty($regs),
695
+			'noRegsMsg' => sprintf(
696
+				esc_html__(
697
+					'%sThere are currently no registration records in the last month for this report.%s',
698
+					'event_espresso'
699
+				),
700
+				'<h2>' . $report_title . '</h2><p>',
701
+				'</p>'
702
+			),
703
+		);
704
+		wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
705
+		return $report_ID;
706
+	}
707 707
 
708 708
 
709
-    /**
710
-     * Generates Business Report showing total registrations per event.
711
-     *
712
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
713
-     * @return string
714
-     * @throws EE_Error
715
-     * @throws InvalidArgumentException
716
-     * @throws InvalidDataTypeException
717
-     * @throws InvalidInterfaceException
718
-     */
719
-    private function _registrations_per_event_report($period = '-1 month')
720
-    {
721
-        $report_ID = 'reg-admin-registrations-per-event-report-dv';
722
-        $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
723
-        $results = (array) $results;
724
-        $regs = array();
725
-        $subtitle = '';
726
-        if ($results) {
727
-            $column_titles = array();
728
-            $tracker = 0;
729
-            foreach ($results as $result) {
730
-                $report_column_values = array();
731
-                foreach ($result as $property_name => $property_value) {
732
-                    $property_value = $property_name === 'Registration_Event' ? wp_trim_words(
733
-                        $property_value,
734
-                        4,
735
-                        '...'
736
-                    ) : (int) $property_value;
737
-                    $report_column_values[] = $property_value;
738
-                    if ($tracker === 0) {
739
-                        if ($property_name === 'Registration_Event') {
740
-                            $column_titles[] = esc_html__('Event', 'event_espresso');
741
-                        } else {
742
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
743
-                        }
744
-                    }
745
-                }
746
-                $tracker++;
747
-                $regs[] = $report_column_values;
748
-            }
749
-            // make sure the column_titles is pushed to the beginning of the array
750
-            array_unshift($regs, $column_titles);
751
-            // setup the date range.
752
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
753
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
754
-            $ending_date = new DateTime("now", $DateTimeZone);
755
-            $subtitle = sprintf(
756
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
757
-                $beginning_date->format('Y-m-d'),
758
-                $ending_date->format('Y-m-d')
759
-            );
760
-        }
761
-        $report_title = esc_html__('Total Registrations per Event', 'event_espresso');
762
-        $report_params = array(
763
-            'title'     => $report_title,
764
-            'subtitle'  => $subtitle,
765
-            'id'        => $report_ID,
766
-            'regs'      => $regs,
767
-            'noResults' => empty($regs),
768
-            'noRegsMsg' => sprintf(
769
-                esc_html__(
770
-                    '%sThere are currently no registration records in the last month for this report.%s',
771
-                    'event_espresso'
772
-                ),
773
-                '<h2>' . $report_title . '</h2><p>',
774
-                '</p>'
775
-            ),
776
-        );
777
-        wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
778
-        return $report_ID;
779
-    }
709
+	/**
710
+	 * Generates Business Report showing total registrations per event.
711
+	 *
712
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
713
+	 * @return string
714
+	 * @throws EE_Error
715
+	 * @throws InvalidArgumentException
716
+	 * @throws InvalidDataTypeException
717
+	 * @throws InvalidInterfaceException
718
+	 */
719
+	private function _registrations_per_event_report($period = '-1 month')
720
+	{
721
+		$report_ID = 'reg-admin-registrations-per-event-report-dv';
722
+		$results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
723
+		$results = (array) $results;
724
+		$regs = array();
725
+		$subtitle = '';
726
+		if ($results) {
727
+			$column_titles = array();
728
+			$tracker = 0;
729
+			foreach ($results as $result) {
730
+				$report_column_values = array();
731
+				foreach ($result as $property_name => $property_value) {
732
+					$property_value = $property_name === 'Registration_Event' ? wp_trim_words(
733
+						$property_value,
734
+						4,
735
+						'...'
736
+					) : (int) $property_value;
737
+					$report_column_values[] = $property_value;
738
+					if ($tracker === 0) {
739
+						if ($property_name === 'Registration_Event') {
740
+							$column_titles[] = esc_html__('Event', 'event_espresso');
741
+						} else {
742
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
743
+						}
744
+					}
745
+				}
746
+				$tracker++;
747
+				$regs[] = $report_column_values;
748
+			}
749
+			// make sure the column_titles is pushed to the beginning of the array
750
+			array_unshift($regs, $column_titles);
751
+			// setup the date range.
752
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
753
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
754
+			$ending_date = new DateTime("now", $DateTimeZone);
755
+			$subtitle = sprintf(
756
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
757
+				$beginning_date->format('Y-m-d'),
758
+				$ending_date->format('Y-m-d')
759
+			);
760
+		}
761
+		$report_title = esc_html__('Total Registrations per Event', 'event_espresso');
762
+		$report_params = array(
763
+			'title'     => $report_title,
764
+			'subtitle'  => $subtitle,
765
+			'id'        => $report_ID,
766
+			'regs'      => $regs,
767
+			'noResults' => empty($regs),
768
+			'noRegsMsg' => sprintf(
769
+				esc_html__(
770
+					'%sThere are currently no registration records in the last month for this report.%s',
771
+					'event_espresso'
772
+				),
773
+				'<h2>' . $report_title . '</h2><p>',
774
+				'</p>'
775
+			),
776
+		);
777
+		wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
778
+		return $report_ID;
779
+	}
780 780
 
781 781
 
782
-    /**
783
-     * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
784
-     *
785
-     * @access protected
786
-     * @return void
787
-     * @throws EE_Error
788
-     * @throws InvalidArgumentException
789
-     * @throws InvalidDataTypeException
790
-     * @throws InvalidInterfaceException
791
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
792
-     */
793
-    protected function _registration_checkin_list_table()
794
-    {
795
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
796
-        $reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null;
797
-        /** @var EE_Registration $registration */
798
-        $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
799
-        if (! $registration instanceof EE_Registration) {
800
-            throw new EE_Error(
801
-                sprintf(
802
-                    esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'),
803
-                    $reg_id
804
-                )
805
-            );
806
-        }
807
-        $attendee = $registration->attendee();
808
-        $this->_admin_page_title .= $this->get_action_link_or_button(
809
-            'new_registration',
810
-            'add-registrant',
811
-            array('event_id' => $registration->event_ID()),
812
-            'add-new-h2'
813
-        );
814
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
815
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
816
-        $legend_items = array(
817
-            'checkin'  => array(
818
-                'class' => $checked_in->cssClasses(),
819
-                'desc'  => $checked_in->legendLabel(),
820
-            ),
821
-            'checkout' => array(
822
-                'class' => $checked_out->cssClasses(),
823
-                'desc'  => $checked_out->legendLabel(),
824
-            ),
825
-        );
826
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
827
-        $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
828
-        /** @var EE_Datetime $datetime */
829
-        $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
830
-        $datetime_label = '';
831
-        if ($datetime instanceof EE_Datetime) {
832
-            $datetime_label = $datetime->get_dtt_display_name(true);
833
-            $datetime_label .= ! empty($datetime_label)
834
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
835
-                : $datetime->get_dtt_display_name();
836
-        }
837
-        $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
838
-            ? EE_Admin_Page::add_query_args_and_nonce(
839
-                array(
840
-                    'action'   => 'event_registrations',
841
-                    'event_id' => $registration->event_ID(),
842
-                    'DTT_ID'   => $dtt_id,
843
-                ),
844
-                $this->_admin_base_url
845
-            )
846
-            : '';
847
-        $datetime_link = ! empty($datetime_link)
848
-            ? '<a href="' . $datetime_link . '">'
849
-              . '<span id="checkin-dtt">'
850
-              . $datetime_label
851
-              . '</span></a>'
852
-            : $datetime_label;
853
-        $attendee_name = $attendee instanceof EE_Attendee
854
-            ? $attendee->full_name()
855
-            : '';
856
-        $attendee_link = $attendee instanceof EE_Attendee
857
-            ? $attendee->get_admin_details_link()
858
-            : '';
859
-        $attendee_link = ! empty($attendee_link)
860
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
861
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
862
-              . '<span id="checkin-attendee-name">'
863
-              . $attendee_name
864
-              . '</span></a>'
865
-            : '';
866
-        $event_link = $registration->event() instanceof EE_Event
867
-            ? $registration->event()->get_admin_details_link()
868
-            : '';
869
-        $event_link = ! empty($event_link)
870
-            ? '<a href="' . $event_link . '"'
871
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
872
-              . '<span id="checkin-event-name">'
873
-              . $registration->event_name()
874
-              . '</span>'
875
-              . '</a>'
876
-            : '';
877
-        $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
878
-            ? '<h2>' . sprintf(
879
-                esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
880
-                $attendee_link,
881
-                $datetime_link,
882
-                $event_link
883
-            ) . '</h2>'
884
-            : '';
885
-        $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
886
-            ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
887
-        $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
888
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
889
-        $this->display_admin_list_table_page_with_no_sidebar();
890
-    }
782
+	/**
783
+	 * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
784
+	 *
785
+	 * @access protected
786
+	 * @return void
787
+	 * @throws EE_Error
788
+	 * @throws InvalidArgumentException
789
+	 * @throws InvalidDataTypeException
790
+	 * @throws InvalidInterfaceException
791
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
792
+	 */
793
+	protected function _registration_checkin_list_table()
794
+	{
795
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
796
+		$reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null;
797
+		/** @var EE_Registration $registration */
798
+		$registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
799
+		if (! $registration instanceof EE_Registration) {
800
+			throw new EE_Error(
801
+				sprintf(
802
+					esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'),
803
+					$reg_id
804
+				)
805
+			);
806
+		}
807
+		$attendee = $registration->attendee();
808
+		$this->_admin_page_title .= $this->get_action_link_or_button(
809
+			'new_registration',
810
+			'add-registrant',
811
+			array('event_id' => $registration->event_ID()),
812
+			'add-new-h2'
813
+		);
814
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
815
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
816
+		$legend_items = array(
817
+			'checkin'  => array(
818
+				'class' => $checked_in->cssClasses(),
819
+				'desc'  => $checked_in->legendLabel(),
820
+			),
821
+			'checkout' => array(
822
+				'class' => $checked_out->cssClasses(),
823
+				'desc'  => $checked_out->legendLabel(),
824
+			),
825
+		);
826
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
827
+		$dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
828
+		/** @var EE_Datetime $datetime */
829
+		$datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
830
+		$datetime_label = '';
831
+		if ($datetime instanceof EE_Datetime) {
832
+			$datetime_label = $datetime->get_dtt_display_name(true);
833
+			$datetime_label .= ! empty($datetime_label)
834
+				? ' (' . $datetime->get_dtt_display_name() . ')'
835
+				: $datetime->get_dtt_display_name();
836
+		}
837
+		$datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
838
+			? EE_Admin_Page::add_query_args_and_nonce(
839
+				array(
840
+					'action'   => 'event_registrations',
841
+					'event_id' => $registration->event_ID(),
842
+					'DTT_ID'   => $dtt_id,
843
+				),
844
+				$this->_admin_base_url
845
+			)
846
+			: '';
847
+		$datetime_link = ! empty($datetime_link)
848
+			? '<a href="' . $datetime_link . '">'
849
+			  . '<span id="checkin-dtt">'
850
+			  . $datetime_label
851
+			  . '</span></a>'
852
+			: $datetime_label;
853
+		$attendee_name = $attendee instanceof EE_Attendee
854
+			? $attendee->full_name()
855
+			: '';
856
+		$attendee_link = $attendee instanceof EE_Attendee
857
+			? $attendee->get_admin_details_link()
858
+			: '';
859
+		$attendee_link = ! empty($attendee_link)
860
+			? '<a href="' . $attendee->get_admin_details_link() . '"'
861
+			  . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
862
+			  . '<span id="checkin-attendee-name">'
863
+			  . $attendee_name
864
+			  . '</span></a>'
865
+			: '';
866
+		$event_link = $registration->event() instanceof EE_Event
867
+			? $registration->event()->get_admin_details_link()
868
+			: '';
869
+		$event_link = ! empty($event_link)
870
+			? '<a href="' . $event_link . '"'
871
+			  . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
872
+			  . '<span id="checkin-event-name">'
873
+			  . $registration->event_name()
874
+			  . '</span>'
875
+			  . '</a>'
876
+			: '';
877
+		$this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
878
+			? '<h2>' . sprintf(
879
+				esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
880
+				$attendee_link,
881
+				$datetime_link,
882
+				$event_link
883
+			) . '</h2>'
884
+			: '';
885
+		$this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
886
+			? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
887
+		$this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
888
+			? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
889
+		$this->display_admin_list_table_page_with_no_sidebar();
890
+	}
891 891
 
892 892
 
893
-    /**
894
-     * toggle the Check-in status for the given registration (coming from ajax)
895
-     *
896
-     * @return void (JSON)
897
-     * @throws EE_Error
898
-     * @throws InvalidArgumentException
899
-     * @throws InvalidDataTypeException
900
-     * @throws InvalidInterfaceException
901
-     */
902
-    public function toggle_checkin_status()
903
-    {
904
-        // first make sure we have the necessary data
905
-        if (! isset($this->_req_data['_regid'])) {
906
-            EE_Error::add_error(
907
-                esc_html__(
908
-                    'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
909
-                    'event_espresso'
910
-                ),
911
-                __FILE__,
912
-                __FUNCTION__,
913
-                __LINE__
914
-            );
915
-            $this->_template_args['success'] = false;
916
-            $this->_template_args['error'] = true;
917
-            $this->_return_json();
918
-        };
919
-        // do a nonce check cause we're not coming in from an normal route here.
920
-        $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
921
-            : '';
922
-        $nonce_ref = 'checkin_nonce';
923
-        $this->_verify_nonce($nonce, $nonce_ref);
924
-        // beautiful! Made it this far so let's get the status.
925
-        $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
926
-        // setup new class to return via ajax
927
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
928
-        $this->_template_args['success'] = true;
929
-        $this->_return_json();
930
-    }
893
+	/**
894
+	 * toggle the Check-in status for the given registration (coming from ajax)
895
+	 *
896
+	 * @return void (JSON)
897
+	 * @throws EE_Error
898
+	 * @throws InvalidArgumentException
899
+	 * @throws InvalidDataTypeException
900
+	 * @throws InvalidInterfaceException
901
+	 */
902
+	public function toggle_checkin_status()
903
+	{
904
+		// first make sure we have the necessary data
905
+		if (! isset($this->_req_data['_regid'])) {
906
+			EE_Error::add_error(
907
+				esc_html__(
908
+					'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
909
+					'event_espresso'
910
+				),
911
+				__FILE__,
912
+				__FUNCTION__,
913
+				__LINE__
914
+			);
915
+			$this->_template_args['success'] = false;
916
+			$this->_template_args['error'] = true;
917
+			$this->_return_json();
918
+		};
919
+		// do a nonce check cause we're not coming in from an normal route here.
920
+		$nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
921
+			: '';
922
+		$nonce_ref = 'checkin_nonce';
923
+		$this->_verify_nonce($nonce, $nonce_ref);
924
+		// beautiful! Made it this far so let's get the status.
925
+		$new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
926
+		// setup new class to return via ajax
927
+		$this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
928
+		$this->_template_args['success'] = true;
929
+		$this->_return_json();
930
+	}
931 931
 
932 932
 
933
-    /**
934
-     * handles toggling the checkin status for the registration,
935
-     *
936
-     * @access protected
937
-     * @return int|void
938
-     * @throws EE_Error
939
-     * @throws InvalidArgumentException
940
-     * @throws InvalidDataTypeException
941
-     * @throws InvalidInterfaceException
942
-     */
943
-    protected function _toggle_checkin_status()
944
-    {
945
-        // first let's get the query args out of the way for the redirect
946
-        $query_args = array(
947
-            'action'   => 'event_registrations',
948
-            'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
949
-            'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
950
-        );
951
-        $new_status = false;
952
-        // bulk action check in toggle
953
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
954
-            // cycle thru checkboxes
955
-            while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
956
-                $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
957
-                $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
958
-            }
959
-        } elseif (isset($this->_req_data['_regid'])) {
960
-            // coming from ajax request
961
-            $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
962
-            $query_args['DTT_ID'] = $DTT_ID;
963
-            $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
964
-        } else {
965
-            EE_Error::add_error(
966
-                esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'),
967
-                __FILE__,
968
-                __FUNCTION__,
969
-                __LINE__
970
-            );
971
-        }
972
-        if (defined('DOING_AJAX')) {
973
-            return $new_status;
974
-        }
975
-        $this->_redirect_after_action(false, '', '', $query_args, true);
976
-    }
933
+	/**
934
+	 * handles toggling the checkin status for the registration,
935
+	 *
936
+	 * @access protected
937
+	 * @return int|void
938
+	 * @throws EE_Error
939
+	 * @throws InvalidArgumentException
940
+	 * @throws InvalidDataTypeException
941
+	 * @throws InvalidInterfaceException
942
+	 */
943
+	protected function _toggle_checkin_status()
944
+	{
945
+		// first let's get the query args out of the way for the redirect
946
+		$query_args = array(
947
+			'action'   => 'event_registrations',
948
+			'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
949
+			'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
950
+		);
951
+		$new_status = false;
952
+		// bulk action check in toggle
953
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
954
+			// cycle thru checkboxes
955
+			while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
956
+				$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
957
+				$new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
958
+			}
959
+		} elseif (isset($this->_req_data['_regid'])) {
960
+			// coming from ajax request
961
+			$DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
962
+			$query_args['DTT_ID'] = $DTT_ID;
963
+			$new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
964
+		} else {
965
+			EE_Error::add_error(
966
+				esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'),
967
+				__FILE__,
968
+				__FUNCTION__,
969
+				__LINE__
970
+			);
971
+		}
972
+		if (defined('DOING_AJAX')) {
973
+			return $new_status;
974
+		}
975
+		$this->_redirect_after_action(false, '', '', $query_args, true);
976
+	}
977 977
 
978 978
 
979
-    /**
980
-     * This is toggles a single Check-in for the given registration and datetime.
981
-     *
982
-     * @param  int $REG_ID The registration we're toggling
983
-     * @param  int $DTT_ID The datetime we're toggling
984
-     * @return int The new status toggled to.
985
-     * @throws EE_Error
986
-     * @throws InvalidArgumentException
987
-     * @throws InvalidDataTypeException
988
-     * @throws InvalidInterfaceException
989
-     */
990
-    private function _toggle_checkin($REG_ID, $DTT_ID)
991
-    {
992
-        /** @var EE_Registration $REG */
993
-        $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
994
-        $new_status = $REG->toggle_checkin_status($DTT_ID);
995
-        if ($new_status !== false) {
996
-            EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
997
-        } else {
998
-            EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
999
-            $new_status = false;
1000
-        }
1001
-        return $new_status;
1002
-    }
979
+	/**
980
+	 * This is toggles a single Check-in for the given registration and datetime.
981
+	 *
982
+	 * @param  int $REG_ID The registration we're toggling
983
+	 * @param  int $DTT_ID The datetime we're toggling
984
+	 * @return int The new status toggled to.
985
+	 * @throws EE_Error
986
+	 * @throws InvalidArgumentException
987
+	 * @throws InvalidDataTypeException
988
+	 * @throws InvalidInterfaceException
989
+	 */
990
+	private function _toggle_checkin($REG_ID, $DTT_ID)
991
+	{
992
+		/** @var EE_Registration $REG */
993
+		$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
994
+		$new_status = $REG->toggle_checkin_status($DTT_ID);
995
+		if ($new_status !== false) {
996
+			EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
997
+		} else {
998
+			EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
999
+			$new_status = false;
1000
+		}
1001
+		return $new_status;
1002
+	}
1003 1003
 
1004 1004
 
1005
-    /**
1006
-     * Takes care of deleting multiple EE_Checkin table rows
1007
-     *
1008
-     * @access protected
1009
-     * @return void
1010
-     * @throws EE_Error
1011
-     * @throws InvalidArgumentException
1012
-     * @throws InvalidDataTypeException
1013
-     * @throws InvalidInterfaceException
1014
-     */
1015
-    protected function _delete_checkin_rows()
1016
-    {
1017
-        $query_args = array(
1018
-            'action'  => 'registration_checkins',
1019
-            'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1020
-            '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1021
-        );
1022
-        $errors = 0;
1023
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1024
-            while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1025
-                if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1026
-                    $errors++;
1027
-                }
1028
-            }
1029
-        } else {
1030
-            EE_Error::add_error(
1031
-                esc_html__(
1032
-                    'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
1033
-                    'event_espresso'
1034
-                ),
1035
-                __FILE__,
1036
-                __FUNCTION__,
1037
-                __LINE__
1038
-            );
1039
-            $this->_redirect_after_action(false, '', '', $query_args, true);
1040
-        }
1041
-        if ($errors > 0) {
1042
-            EE_Error::add_error(
1043
-                sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
1044
-                __FILE__,
1045
-                __FUNCTION__,
1046
-                __LINE__
1047
-            );
1048
-        } else {
1049
-            EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
1050
-        }
1051
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1052
-    }
1005
+	/**
1006
+	 * Takes care of deleting multiple EE_Checkin table rows
1007
+	 *
1008
+	 * @access protected
1009
+	 * @return void
1010
+	 * @throws EE_Error
1011
+	 * @throws InvalidArgumentException
1012
+	 * @throws InvalidDataTypeException
1013
+	 * @throws InvalidInterfaceException
1014
+	 */
1015
+	protected function _delete_checkin_rows()
1016
+	{
1017
+		$query_args = array(
1018
+			'action'  => 'registration_checkins',
1019
+			'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1020
+			'_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1021
+		);
1022
+		$errors = 0;
1023
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1024
+			while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1025
+				if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1026
+					$errors++;
1027
+				}
1028
+			}
1029
+		} else {
1030
+			EE_Error::add_error(
1031
+				esc_html__(
1032
+					'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
1033
+					'event_espresso'
1034
+				),
1035
+				__FILE__,
1036
+				__FUNCTION__,
1037
+				__LINE__
1038
+			);
1039
+			$this->_redirect_after_action(false, '', '', $query_args, true);
1040
+		}
1041
+		if ($errors > 0) {
1042
+			EE_Error::add_error(
1043
+				sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
1044
+				__FILE__,
1045
+				__FUNCTION__,
1046
+				__LINE__
1047
+			);
1048
+		} else {
1049
+			EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
1050
+		}
1051
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1052
+	}
1053 1053
 
1054 1054
 
1055
-    /**
1056
-     * Deletes a single EE_Checkin row
1057
-     *
1058
-     * @return void
1059
-     * @throws EE_Error
1060
-     * @throws InvalidArgumentException
1061
-     * @throws InvalidDataTypeException
1062
-     * @throws InvalidInterfaceException
1063
-     */
1064
-    protected function _delete_checkin_row()
1065
-    {
1066
-        $query_args = array(
1067
-            'action'  => 'registration_checkins',
1068
-            'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1069
-            '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1070
-        );
1071
-        if (! empty($this->_req_data['CHK_ID'])) {
1072
-            if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1073
-                EE_Error::add_error(
1074
-                    esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1075
-                    __FILE__,
1076
-                    __FUNCTION__,
1077
-                    __LINE__
1078
-                );
1079
-            } else {
1080
-                EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
1081
-            }
1082
-        } else {
1083
-            EE_Error::add_error(
1084
-                esc_html__(
1085
-                    'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1086
-                    'event_espresso'
1087
-                ),
1088
-                __FILE__,
1089
-                __FUNCTION__,
1090
-                __LINE__
1091
-            );
1092
-        }
1093
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1094
-    }
1055
+	/**
1056
+	 * Deletes a single EE_Checkin row
1057
+	 *
1058
+	 * @return void
1059
+	 * @throws EE_Error
1060
+	 * @throws InvalidArgumentException
1061
+	 * @throws InvalidDataTypeException
1062
+	 * @throws InvalidInterfaceException
1063
+	 */
1064
+	protected function _delete_checkin_row()
1065
+	{
1066
+		$query_args = array(
1067
+			'action'  => 'registration_checkins',
1068
+			'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1069
+			'_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1070
+		);
1071
+		if (! empty($this->_req_data['CHK_ID'])) {
1072
+			if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1073
+				EE_Error::add_error(
1074
+					esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1075
+					__FILE__,
1076
+					__FUNCTION__,
1077
+					__LINE__
1078
+				);
1079
+			} else {
1080
+				EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
1081
+			}
1082
+		} else {
1083
+			EE_Error::add_error(
1084
+				esc_html__(
1085
+					'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1086
+					'event_espresso'
1087
+				),
1088
+				__FILE__,
1089
+				__FUNCTION__,
1090
+				__LINE__
1091
+			);
1092
+		}
1093
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1094
+	}
1095 1095
 
1096 1096
 
1097
-    /**
1098
-     *        generates HTML for the Event Registrations List Table
1099
-     *
1100
-     * @access protected
1101
-     * @return void
1102
-     * @throws EE_Error
1103
-     * @throws InvalidArgumentException
1104
-     * @throws InvalidDataTypeException
1105
-     * @throws InvalidInterfaceException
1106
-     */
1107
-    protected function _event_registrations_list_table()
1108
-    {
1109
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1110
-        $this->_admin_page_title .= isset($this->_req_data['event_id'])
1111
-            ? $this->get_action_link_or_button(
1112
-                'new_registration',
1113
-                'add-registrant',
1114
-                array('event_id' => $this->_req_data['event_id']),
1115
-                'add-new-h2',
1116
-                '',
1117
-                false
1118
-            )
1119
-            : '';
1120
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1121
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1122
-        $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1123
-        $legend_items = array(
1124
-            'star-icon'        => array(
1125
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1126
-                'desc'  => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'),
1127
-            ),
1128
-            'checkin'          => array(
1129
-                'class' => $checked_in->cssClasses(),
1130
-                'desc'  => $checked_in->legendLabel(),
1131
-            ),
1132
-            'checkout'         => array(
1133
-                'class' => $checked_out->cssClasses(),
1134
-                'desc'  => $checked_out->legendLabel(),
1135
-            ),
1136
-            'nocheckinrecord'  => array(
1137
-                'class' => $checked_never->cssClasses(),
1138
-                'desc'  => $checked_never->legendLabel(),
1139
-            ),
1140
-            'approved_status'  => array(
1141
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1142
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1143
-            ),
1144
-            'cancelled_status' => array(
1145
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1146
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1147
-            ),
1148
-            'declined_status'  => array(
1149
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1150
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1151
-            ),
1152
-            'not_approved'     => array(
1153
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1154
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1155
-            ),
1156
-            'pending_status'   => array(
1157
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1158
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1159
-            ),
1160
-            'wait_list'        => array(
1161
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1162
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1163
-            ),
1164
-        );
1165
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1166
-        $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1167
-        /** @var EE_Event $event */
1168
-        $event = EEM_Event::instance()->get_one_by_ID($event_id);
1169
-        $this->_template_args['before_list_table'] = $event instanceof EE_Event
1170
-            ? '<h2>' . sprintf(
1171
-                esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1172
-                EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1173
-            ) . '</h2>'
1174
-            : '';
1175
-        // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1176
-        // the event.
1177
-        $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1178
-        $datetime = null;
1179
-        if ($event instanceof EE_Event) {
1180
-            $datetimes_on_event = $event->datetimes();
1181
-            if (count($datetimes_on_event) === 1) {
1182
-                $datetime = reset($datetimes_on_event);
1183
-            }
1184
-        }
1185
-        $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1186
-        if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1187
-            $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1188
-            $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1189
-            $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1190
-            $this->_template_args['before_list_table'] .= $datetime->name();
1191
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1192
-            $this->_template_args['before_list_table'] .= '</span></h2>';
1193
-        }
1194
-        // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1195
-        // column represents
1196
-        if (! $datetime instanceof EE_Datetime) {
1197
-            $this->_template_args['before_list_table'] .= '<br><p class="description">'
1198
-                                                          . esc_html__(
1199
-                                                              'In this view, the check-in status represents the latest check-in record for the registration in that row.',
1200
-                                                              'event_espresso'
1201
-                                                          )
1202
-                                                          . '</p>';
1203
-        }
1204
-        $this->display_admin_list_table_page_with_no_sidebar();
1205
-    }
1097
+	/**
1098
+	 *        generates HTML for the Event Registrations List Table
1099
+	 *
1100
+	 * @access protected
1101
+	 * @return void
1102
+	 * @throws EE_Error
1103
+	 * @throws InvalidArgumentException
1104
+	 * @throws InvalidDataTypeException
1105
+	 * @throws InvalidInterfaceException
1106
+	 */
1107
+	protected function _event_registrations_list_table()
1108
+	{
1109
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1110
+		$this->_admin_page_title .= isset($this->_req_data['event_id'])
1111
+			? $this->get_action_link_or_button(
1112
+				'new_registration',
1113
+				'add-registrant',
1114
+				array('event_id' => $this->_req_data['event_id']),
1115
+				'add-new-h2',
1116
+				'',
1117
+				false
1118
+			)
1119
+			: '';
1120
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1121
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1122
+		$checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1123
+		$legend_items = array(
1124
+			'star-icon'        => array(
1125
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1126
+				'desc'  => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'),
1127
+			),
1128
+			'checkin'          => array(
1129
+				'class' => $checked_in->cssClasses(),
1130
+				'desc'  => $checked_in->legendLabel(),
1131
+			),
1132
+			'checkout'         => array(
1133
+				'class' => $checked_out->cssClasses(),
1134
+				'desc'  => $checked_out->legendLabel(),
1135
+			),
1136
+			'nocheckinrecord'  => array(
1137
+				'class' => $checked_never->cssClasses(),
1138
+				'desc'  => $checked_never->legendLabel(),
1139
+			),
1140
+			'approved_status'  => array(
1141
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1142
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1143
+			),
1144
+			'cancelled_status' => array(
1145
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1146
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1147
+			),
1148
+			'declined_status'  => array(
1149
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1150
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1151
+			),
1152
+			'not_approved'     => array(
1153
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1154
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1155
+			),
1156
+			'pending_status'   => array(
1157
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1158
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1159
+			),
1160
+			'wait_list'        => array(
1161
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1162
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1163
+			),
1164
+		);
1165
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1166
+		$event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1167
+		/** @var EE_Event $event */
1168
+		$event = EEM_Event::instance()->get_one_by_ID($event_id);
1169
+		$this->_template_args['before_list_table'] = $event instanceof EE_Event
1170
+			? '<h2>' . sprintf(
1171
+				esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1172
+				EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1173
+			) . '</h2>'
1174
+			: '';
1175
+		// need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1176
+		// the event.
1177
+		$DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1178
+		$datetime = null;
1179
+		if ($event instanceof EE_Event) {
1180
+			$datetimes_on_event = $event->datetimes();
1181
+			if (count($datetimes_on_event) === 1) {
1182
+				$datetime = reset($datetimes_on_event);
1183
+			}
1184
+		}
1185
+		$datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1186
+		if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1187
+			$this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1188
+			$this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1189
+			$this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1190
+			$this->_template_args['before_list_table'] .= $datetime->name();
1191
+			$this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1192
+			$this->_template_args['before_list_table'] .= '</span></h2>';
1193
+		}
1194
+		// if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1195
+		// column represents
1196
+		if (! $datetime instanceof EE_Datetime) {
1197
+			$this->_template_args['before_list_table'] .= '<br><p class="description">'
1198
+														  . esc_html__(
1199
+															  'In this view, the check-in status represents the latest check-in record for the registration in that row.',
1200
+															  'event_espresso'
1201
+														  )
1202
+														  . '</p>';
1203
+		}
1204
+		$this->display_admin_list_table_page_with_no_sidebar();
1205
+	}
1206 1206
 
1207
-    /**
1208
-     * Download the registrations check-in report (same as the normal registration report, but with different where
1209
-     * conditions)
1210
-     *
1211
-     * @return void ends the request by a redirect or download
1212
-     */
1213
-    public function _registrations_checkin_report()
1214
-    {
1215
-        $this->_registrations_report_base('_get_checkin_query_params_from_request');
1216
-    }
1207
+	/**
1208
+	 * Download the registrations check-in report (same as the normal registration report, but with different where
1209
+	 * conditions)
1210
+	 *
1211
+	 * @return void ends the request by a redirect or download
1212
+	 */
1213
+	public function _registrations_checkin_report()
1214
+	{
1215
+		$this->_registrations_report_base('_get_checkin_query_params_from_request');
1216
+	}
1217 1217
 
1218
-    /**
1219
-     * Gets the query params from the request, plus adds a where condition for the registration status,
1220
-     * because on the checkin page we only ever want to see approved and pending-approval registrations
1221
-     *
1222
-     * @param array $request
1223
-     * @param int   $per_page
1224
-     * @param bool  $count
1225
-     * @return array
1226
-     * @throws EE_Error
1227
-     */
1228
-    protected function _get_checkin_query_params_from_request(
1229
-        $request,
1230
-        $per_page = 10,
1231
-        $count = false
1232
-    ) {
1233
-        $query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1234
-        // unlike the regular registrations list table,
1235
-        $status_ids_array = apply_filters(
1236
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1237
-            array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1238
-        );
1239
-        $query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1240
-        return $query_params;
1241
-    }
1218
+	/**
1219
+	 * Gets the query params from the request, plus adds a where condition for the registration status,
1220
+	 * because on the checkin page we only ever want to see approved and pending-approval registrations
1221
+	 *
1222
+	 * @param array $request
1223
+	 * @param int   $per_page
1224
+	 * @param bool  $count
1225
+	 * @return array
1226
+	 * @throws EE_Error
1227
+	 */
1228
+	protected function _get_checkin_query_params_from_request(
1229
+		$request,
1230
+		$per_page = 10,
1231
+		$count = false
1232
+	) {
1233
+		$query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1234
+		// unlike the regular registrations list table,
1235
+		$status_ids_array = apply_filters(
1236
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1237
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1238
+		);
1239
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1240
+		return $query_params;
1241
+	}
1242 1242
 
1243 1243
 
1244
-    /**
1245
-     * Gets registrations for an event
1246
-     *
1247
-     * @param int    $per_page
1248
-     * @param bool   $count whether to return count or data.
1249
-     * @param bool   $trash
1250
-     * @param string $orderby
1251
-     * @return EE_Registration[]|int
1252
-     * @throws EE_Error
1253
-     * @throws InvalidArgumentException
1254
-     * @throws InvalidDataTypeException
1255
-     * @throws InvalidInterfaceException
1256
-     */
1257
-    public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1258
-    {
1259
-        // normalize some request params that get setup by the parent `get_registrations` method.
1260
-        $request = $this->_req_data;
1261
-        $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1262
-        $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1263
-        if ($trash) {
1264
-            $request['status'] = 'trash';
1265
-        }
1266
-        $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1267
-        /**
1268
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1269
-         *
1270
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1271
-         * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1272
-         *                             or if you have the development copy of EE you can view this at the path:
1273
-         *                             /docs/G--Model-System/model-query-params.md
1274
-         */
1275
-        $query_params['group_by'] = '';
1244
+	/**
1245
+	 * Gets registrations for an event
1246
+	 *
1247
+	 * @param int    $per_page
1248
+	 * @param bool   $count whether to return count or data.
1249
+	 * @param bool   $trash
1250
+	 * @param string $orderby
1251
+	 * @return EE_Registration[]|int
1252
+	 * @throws EE_Error
1253
+	 * @throws InvalidArgumentException
1254
+	 * @throws InvalidDataTypeException
1255
+	 * @throws InvalidInterfaceException
1256
+	 */
1257
+	public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1258
+	{
1259
+		// normalize some request params that get setup by the parent `get_registrations` method.
1260
+		$request = $this->_req_data;
1261
+		$request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1262
+		$request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1263
+		if ($trash) {
1264
+			$request['status'] = 'trash';
1265
+		}
1266
+		$query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1267
+		/**
1268
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1269
+		 *
1270
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1271
+		 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1272
+		 *                             or if you have the development copy of EE you can view this at the path:
1273
+		 *                             /docs/G--Model-System/model-query-params.md
1274
+		 */
1275
+		$query_params['group_by'] = '';
1276 1276
 
1277
-        return $count
1278
-            ? EEM_Registration::instance()->count($query_params)
1279
-            /** @type EE_Registration[] */
1280
-            : EEM_Registration::instance()->get_all($query_params);
1281
-    }
1277
+		return $count
1278
+			? EEM_Registration::instance()->count($query_params)
1279
+			/** @type EE_Registration[] */
1280
+			: EEM_Registration::instance()->get_all($query_params);
1281
+	}
1282 1282
 }
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
     public function __construct($routing = true)
33 33
     {
34 34
         parent::__construct($routing);
35
-        if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
35
+        if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
36
+            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/');
37
+            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/');
38
+            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/');
39 39
         }
40 40
     }
41 41
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      */
46 46
     protected function _extend_page_config()
47 47
     {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
48
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations';
49 49
         $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50 50
             ? $this->_req_data['_REG_ID']
51 51
             : 0;
@@ -185,14 +185,14 @@  discard block
 block discarded – undo
185 185
             // enqueue newsletter js
186 186
             wp_enqueue_script(
187 187
                 'ee-newsletter-trigger',
188
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
188
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js',
189 189
                 array('ee-dialog'),
190 190
                 EVENT_ESPRESSO_VERSION,
191 191
                 true
192 192
             );
193 193
             wp_enqueue_style(
194 194
                 'ee-newsletter-trigger-css',
195
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
195
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css',
196 196
                 array(),
197 197
                 EVENT_ESPRESSO_VERSION
198 198
             );
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
     {
214 214
         wp_register_script(
215 215
             'ee-reg-reports-js',
216
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
216
+            REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js',
217 217
             array('google-charts'),
218 218
             EVENT_ESPRESSO_VERSION,
219 219
             true
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
         $nonce_ref = 'get_newsletter_form_content_nonce';
300 300
         $this->_verify_nonce($nonce, $nonce_ref);
301 301
         // let's get the mtp for the incoming MTP_ ID
302
-        if (! isset($this->_req_data['GRP_ID'])) {
302
+        if ( ! isset($this->_req_data['GRP_ID'])) {
303 303
             EE_Error::add_error(
304 304
                 esc_html__(
305 305
                     'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
             $this->_return_json();
315 315
         }
316 316
         $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
317
-        if (! $MTPG instanceof EE_Message_Template_Group) {
317
+        if ( ! $MTPG instanceof EE_Message_Template_Group) {
318 318
             EE_Error::add_error(
319 319
                 sprintf(
320 320
                     esc_html__(
@@ -339,12 +339,12 @@  discard block
 block discarded – undo
339 339
             $field = $MTP->get('MTP_template_field');
340 340
             if ($field === 'content') {
341 341
                 $content = $MTP->get('MTP_content');
342
-                if (! empty($content['newsletter_content'])) {
342
+                if ( ! empty($content['newsletter_content'])) {
343 343
                     $template_fields['newsletter_content'] = $content['newsletter_content'];
344 344
                 }
345 345
                 continue;
346 346
             }
347
-            $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
347
+            $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
348 348
         }
349 349
         $this->_template_args['success'] = true;
350 350
         $this->_template_args['error'] = false;
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
      */
376 376
     public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
377 377
     {
378
-        if (! EE_Registry::instance()->CAP->current_user_can(
378
+        if ( ! EE_Registry::instance()->CAP->current_user_can(
379 379
             'ee_send_message',
380 380
             'espresso_registrations_newsletter_selected_send'
381 381
         )
@@ -444,17 +444,17 @@  discard block
 block discarded – undo
444 444
                 $field_id = $field === '[NEWSLETTER_CONTENT]'
445 445
                     ? 'content'
446 446
                     : $field;
447
-                $field_id = 'batch-message-' . strtolower($field_id);
447
+                $field_id = 'batch-message-'.strtolower($field_id);
448 448
                 $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
449 449
                                           . $shortcode
450
-                                          . '" data-linked-input-id="' . $field_id . '">'
450
+                                          . '" data-linked-input-id="'.$field_id.'">'
451 451
                                           . $shortcode
452 452
                                           . '</span>';
453 453
             }
454
-            $codes[ $field ] = implode(', ', $available_shortcodes);
454
+            $codes[$field] = implode(', ', $available_shortcodes);
455 455
         }
456 456
         $shortcodes = $codes;
457
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
457
+        $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php';
458 458
         $form_template_args = array(
459 459
             'form_action'       => admin_url('admin.php?page=espresso_registrations'),
460 460
             'form_route'        => 'newsletter_selected_send',
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
      */
623 623
     protected function _registration_reports()
624 624
     {
625
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
625
+        $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
626 626
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
627 627
             $template_path,
628 628
             $this->_reports_template_data,
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
             array_unshift($regs, $column_titles);
678 678
             // setup the date range.
679 679
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
680
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
680
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
681 681
             $ending_date = new DateTime("now", $DateTimeZone);
682 682
             $subtitle = sprintf(
683 683
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
                     '%sThere are currently no registration records in the last month for this report.%s',
698 698
                     'event_espresso'
699 699
                 ),
700
-                '<h2>' . $report_title . '</h2><p>',
700
+                '<h2>'.$report_title.'</h2><p>',
701 701
                 '</p>'
702 702
             ),
703 703
         );
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
             array_unshift($regs, $column_titles);
751 751
             // setup the date range.
752 752
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
753
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
753
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
754 754
             $ending_date = new DateTime("now", $DateTimeZone);
755 755
             $subtitle = sprintf(
756 756
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
                     '%sThere are currently no registration records in the last month for this report.%s',
771 771
                     'event_espresso'
772 772
                 ),
773
-                '<h2>' . $report_title . '</h2><p>',
773
+                '<h2>'.$report_title.'</h2><p>',
774 774
                 '</p>'
775 775
             ),
776 776
         );
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
         $reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null;
797 797
         /** @var EE_Registration $registration */
798 798
         $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
799
-        if (! $registration instanceof EE_Registration) {
799
+        if ( ! $registration instanceof EE_Registration) {
800 800
             throw new EE_Error(
801 801
                 sprintf(
802 802
                     esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'),
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
         if ($datetime instanceof EE_Datetime) {
832 832
             $datetime_label = $datetime->get_dtt_display_name(true);
833 833
             $datetime_label .= ! empty($datetime_label)
834
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
834
+                ? ' ('.$datetime->get_dtt_display_name().')'
835 835
                 : $datetime->get_dtt_display_name();
836 836
         }
837 837
         $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
@@ -845,7 +845,7 @@  discard block
 block discarded – undo
845 845
             )
846 846
             : '';
847 847
         $datetime_link = ! empty($datetime_link)
848
-            ? '<a href="' . $datetime_link . '">'
848
+            ? '<a href="'.$datetime_link.'">'
849 849
               . '<span id="checkin-dtt">'
850 850
               . $datetime_label
851 851
               . '</span></a>'
@@ -857,8 +857,8 @@  discard block
 block discarded – undo
857 857
             ? $attendee->get_admin_details_link()
858 858
             : '';
859 859
         $attendee_link = ! empty($attendee_link)
860
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
861
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
860
+            ? '<a href="'.$attendee->get_admin_details_link().'"'
861
+              . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">'
862 862
               . '<span id="checkin-attendee-name">'
863 863
               . $attendee_name
864 864
               . '</span></a>'
@@ -867,25 +867,25 @@  discard block
 block discarded – undo
867 867
             ? $registration->event()->get_admin_details_link()
868 868
             : '';
869 869
         $event_link = ! empty($event_link)
870
-            ? '<a href="' . $event_link . '"'
871
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
870
+            ? '<a href="'.$event_link.'"'
871
+              . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">'
872 872
               . '<span id="checkin-event-name">'
873 873
               . $registration->event_name()
874 874
               . '</span>'
875 875
               . '</a>'
876 876
             : '';
877 877
         $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
878
-            ? '<h2>' . sprintf(
878
+            ? '<h2>'.sprintf(
879 879
                 esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
880 880
                 $attendee_link,
881 881
                 $datetime_link,
882 882
                 $event_link
883
-            ) . '</h2>'
883
+            ).'</h2>'
884 884
             : '';
885 885
         $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
886
-            ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
886
+            ? '<input type="hidden" name="_REG_ID" value="'.$reg_id.'">' : '';
887 887
         $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
888
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
888
+            ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : '';
889 889
         $this->display_admin_list_table_page_with_no_sidebar();
890 890
     }
891 891
 
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
     public function toggle_checkin_status()
903 903
     {
904 904
         // first make sure we have the necessary data
905
-        if (! isset($this->_req_data['_regid'])) {
905
+        if ( ! isset($this->_req_data['_regid'])) {
906 906
             EE_Error::add_error(
907 907
                 esc_html__(
908 908
                     'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
         // beautiful! Made it this far so let's get the status.
925 925
         $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
926 926
         // setup new class to return via ajax
927
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
927
+        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin '.$new_status->cssClasses();
928 928
         $this->_template_args['success'] = true;
929 929
         $this->_return_json();
930 930
     }
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
         );
951 951
         $new_status = false;
952 952
         // bulk action check in toggle
953
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
953
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
954 954
             // cycle thru checkboxes
955 955
             while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
956 956
                 $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
@@ -1020,9 +1020,9 @@  discard block
 block discarded – undo
1020 1020
             '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1021 1021
         );
1022 1022
         $errors = 0;
1023
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1023
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1024 1024
             while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1025
-                if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1025
+                if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1026 1026
                     $errors++;
1027 1027
                 }
1028 1028
             }
@@ -1068,8 +1068,8 @@  discard block
 block discarded – undo
1068 1068
             'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1069 1069
             '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1070 1070
         );
1071
-        if (! empty($this->_req_data['CHK_ID'])) {
1072
-            if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1071
+        if ( ! empty($this->_req_data['CHK_ID'])) {
1072
+            if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1073 1073
                 EE_Error::add_error(
1074 1074
                     esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1075 1075
                     __FILE__,
@@ -1138,27 +1138,27 @@  discard block
 block discarded – undo
1138 1138
                 'desc'  => $checked_never->legendLabel(),
1139 1139
             ),
1140 1140
             'approved_status'  => array(
1141
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1141
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
1142 1142
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1143 1143
             ),
1144 1144
             'cancelled_status' => array(
1145
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1145
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1146 1146
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1147 1147
             ),
1148 1148
             'declined_status'  => array(
1149
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1149
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
1150 1150
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1151 1151
             ),
1152 1152
             'not_approved'     => array(
1153
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1153
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
1154 1154
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1155 1155
             ),
1156 1156
             'pending_status'   => array(
1157
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1157
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
1158 1158
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1159 1159
             ),
1160 1160
             'wait_list'        => array(
1161
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1161
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
1162 1162
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1163 1163
             ),
1164 1164
         );
@@ -1167,10 +1167,10 @@  discard block
 block discarded – undo
1167 1167
         /** @var EE_Event $event */
1168 1168
         $event = EEM_Event::instance()->get_one_by_ID($event_id);
1169 1169
         $this->_template_args['before_list_table'] = $event instanceof EE_Event
1170
-            ? '<h2>' . sprintf(
1170
+            ? '<h2>'.sprintf(
1171 1171
                 esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1172 1172
                 EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1173
-            ) . '</h2>'
1173
+            ).'</h2>'
1174 1174
             : '';
1175 1175
         // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1176 1176
         // the event.
@@ -1188,12 +1188,12 @@  discard block
 block discarded – undo
1188 1188
             $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1189 1189
             $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1190 1190
             $this->_template_args['before_list_table'] .= $datetime->name();
1191
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1191
+            $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )';
1192 1192
             $this->_template_args['before_list_table'] .= '</span></h2>';
1193 1193
         }
1194 1194
         // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1195 1195
         // column represents
1196
-        if (! $datetime instanceof EE_Datetime) {
1196
+        if ( ! $datetime instanceof EE_Datetime) {
1197 1197
             $this->_template_args['before_list_table'] .= '<br><p class="description">'
1198 1198
                                                           . esc_html__(
1199 1199
                                                               'In this view, the check-in status represents the latest check-in record for the registration in that row.',
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Event_Shortcodes.lib.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
 
136 136
         // If there is no event objecdt by now then get out.
137
-        if (! $this->_event instanceof EE_Event) {
137
+        if ( ! $this->_event instanceof EE_Event) {
138 138
             return '';
139 139
         }
140 140
 
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
                 $image = $this->_event->feature_image_url(array(600, 300));
188 188
                 // @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned.
189 189
                 return ! empty($image)
190
-                    ? '<img src="' . $image . '" alt="'
190
+                    ? '<img src="'.$image.'" alt="'
191 191
                       . sprintf(
192 192
                           esc_attr__('%s Feature Image', 'event_espresso'),
193 193
                           $this->_event->get('EVT_name')
194
-                      ) . '" />'
194
+                      ).'" />'
195 195
                     : '';
196 196
                 break;
197 197
 
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
             // Add a filter to allow all instances of EVENT_META_* to run through do_shortcode, default to false.
252 252
             // Check if a do_shortcode attribute was set to true and if so run $event_meta through that function.
253 253
             if (apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
254
-                || !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
254
+                || ! empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
255 255
             ) {
256 256
                 return do_shortcode($event_meta);
257 257
             }
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
 
270 270
         if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
271 271
             $attrs = $this->_get_shortcode_attrs($shortcode);
272
-            $width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
273
-            $height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
272
+            $width = empty($attrs['width']) ? '' : ' width="'.$attrs['width'].'"';
273
+            $height = empty($attrs['height']) ? '' : ' height="'.$attrs['height'].'"';
274 274
 
275 275
             // Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
276
-            if (! empty($attrs['size'])) {
276
+            if ( ! empty($attrs['size'])) {
277 277
                 $size = explode(',', $attrs['size']);
278 278
                 if (count($size) === 1) {
279 279
                     $size = $size[0];
@@ -285,11 +285,11 @@  discard block
 block discarded – undo
285 285
             $image = $this->_event->feature_image_url($size);
286 286
 
287 287
             return ! empty($image)
288
-                ? '<img src="' . $image . '" alt="'
288
+                ? '<img src="'.$image.'" alt="'
289 289
                   . sprintf(
290 290
                       esc_attr__('%s Feature Image', 'event_espresso'),
291 291
                       $this->_event->get('EVT_name')
292
-                  ) . '"' . $width . $height . '/>'
292
+                  ).'"'.$width.$height.'/>'
293 293
                 : '';
294 294
         }
295 295
 
@@ -308,6 +308,6 @@  discard block
 block discarded – undo
308 308
     {
309 309
         $url = get_permalink($event->ID());
310 310
 
311
-        return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
311
+        return $full_link ? '<a href="'.$url.'">'.$event->get('EVT_name').'</a>' : $url;
312 312
     }
313 313
 }
Please login to merge, or discard this patch.
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -19,296 +19,296 @@
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * Will hold the EE_Event if available
24
-     *
25
-     * @var EE_Event
26
-     */
27
-    protected $_event;
28
-
29
-
30
-    public function __construct()
31
-    {
32
-        parent::__construct();
33
-    }
34
-
35
-
36
-    protected function _init_props()
37
-    {
38
-        $this->label = __('Event Shortcodes', 'event_espresso');
39
-        $this->description = __('All shortcodes specific to event related data', 'event_espresso');
40
-        $this->_shortcodes = array(
41
-            '[EVENT_ID]'                              => __(
42
-                'Will be replaced by the event ID of an event',
43
-                'event_espresso'
44
-            ),
45
-            '[EVENT]'                                 => __('The name of the event', 'event_espresso'),
46
-            '[EVENT_NAME]'                            => __(
47
-                "This also can be used for the name of the event",
48
-                'event_espresso'
49
-            ),
50
-            '[EVENT_PHONE]'                           => __(
51
-                'The phone number for the event (usually an info number)',
52
-                'event_espresso'
53
-            ),
54
-            '[EVENT_DESCRIPTION]'                     => __('The description of the event', 'event_espresso'),
55
-            '[EVENT_EXCERPT]'                         => __(
56
-                'This gets parsed to the value for the excerpt field in the event or blank if there is no excerpt.',
57
-                'event_espresso'
58
-            ),
59
-            '[EVENT_LINK]'                            => __('A link associated with the event', 'event_espresso'),
60
-            '[EVENT_URL]'                             => __(
61
-                'A link to the event set up on the host site.',
62
-                'event_espresso'
63
-            ),
64
-            '[VIRTUAL_URL]'                           => __(
65
-                'What was used for the "URL of Event" field in the Venue settings',
66
-                'event_espresso'
67
-            ),
68
-            '[VIRTUAL_PHONE]'                         => __(
69
-                'An alternate phone number for the event. Typically used as a "call-in" number',
70
-                'event_espresso'
71
-            ),
72
-            '[EVENT_IMAGE]'                           => __(
73
-                'This will parse to the Feature image for the event.',
74
-                'event_espresso'
75
-            ),
76
-            '[EVENT_IMAGE_*]'                         => sprintf(
77
-                __(
78
-                    'This will parse to the Feature image for the event, %1$ssize%2$s can be set to determine the size of the image loaded by the shortcode. The %1$swidth%2$s and/or %1$sheight%2$s can also be set to determine the width and height of the image when output. By default the shortcode will load the %1$sthumbnail%2$s image size.',
79
-                    'event_espresso'
80
-                ),
81
-                '<code>',
82
-                '</code>'
83
-            ),
84
-            '[EVENT_TOTAL_AVAILABLE_SPACES_*]'        => sprintf(
85
-                __(
86
-                    'This will parse to the total available spaces for an event. Calculating total spaces is approximate because it is dependent on the complexity of limits on your event.  There are two methods of calculation (which can be indicated by the %1$smethod%2$s param on the shortcode).  %1$scurrent%2$s which will do a more accurate calculation of total available spaces based on current sales, and %1$sfull%2$s which will be the maximum total available spaces that is on the event in optimal conditions. The shortcode will default to current.',
87
-                    'event_espresso'
88
-                ),
89
-                '<code>',
90
-                '</code>'
91
-            ),
92
-            '[EVENT_TOTAL_SPOTS_TAKEN]'               => __(
93
-                'This shortcode will parse to the output the total approved registrations for this event',
94
-                'event_espresso'
95
-            ),
96
-            '[EVENT_FACEBOOK_URL]'                    => __(
97
-                'This will return the Facebook URL for the event if you have it set via custom field in your event, otherwise it will use the Facebook URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_facebook</code> and the value as your facebook url.',
98
-                'event_espresso'
99
-            ),
100
-            '[EVENT_TWITTER_URL]'                     => __(
101
-                'This will return the Twitter URL for the event if you have it set via custom field in your event, otherwise it will use the Twitter URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_twitter</code> and the value as your facebook url',
102
-                'event_espresso'
103
-            ),
104
-            '[EVENT_META_*]'                          => sprintf(
105
-                __(
106
-                    'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the event then it will be output in place of this shortcode. If you use shortcodes within your custom fields set %1$sdo_shortcode=true%2$s at the end of the shortcode to run the value through the do_shortcode function. ',
107
-                    'event_espresso'
108
-                ),
109
-                '<code>',
110
-                '</code>'
111
-            ),
112
-            '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]' => __(
113
-                'This parses to the url for the registration list table filtered by registrations for this event.',
114
-                'event_espresso'
115
-            ),
116
-        );
117
-    }
118
-
119
-
120
-    protected function _parser($shortcode)
121
-    {
122
-
123
-
124
-        $this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
125
-
126
-        // if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
127
-        if (empty($this->_event)) {
128
-            $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
129
-            $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
130
-
131
-            $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
132
-                ? $aee->reg_obj->event() : null;
133
-        }
134
-
135
-
136
-        // If there is no event objecdt by now then get out.
137
-        if (! $this->_event instanceof EE_Event) {
138
-            return '';
139
-        }
140
-
141
-        switch ($shortcode) {
142
-            case '[EVENT_ID]':
143
-                return $this->_event->ID();
144
-                break;
145
-
146
-            case '[EVENT]':
147
-            case '[EVENT_NAME]':
148
-                return $this->_event->get('EVT_name');
149
-                break;
150
-
151
-            case '[EVENT_PHONE]':
152
-                return $this->_event->get('EVT_phone');
153
-                break;
154
-
155
-            case '[EVENT_DESCRIPTION]':
156
-                return $this->_event->get('EVT_desc');
157
-                break;
158
-
159
-            case '[EVENT_EXCERPT]':
160
-                return $this->_event->get('EVT_short_desc');
161
-                break;
162
-
163
-            case '[EVENT_LINK]':
164
-                return $this->_get_event_link($this->_event);
165
-                break;
166
-
167
-            case '[EVENT_URL]':
168
-                return $this->_get_event_link($this->_event, false);
169
-                break;
170
-
171
-            case '[VIRTUAL_URL]':
172
-                $venue = $this->_event->get_first_related('Venue');
173
-                if (empty($venue)) {
174
-                    return '';
175
-                }
176
-                return $venue->get('VNU_virtual_url');
177
-
178
-            case '[VIRTUAL_PHONE]':
179
-                $venue = $this->_event->get_first_related('Venue');
180
-                if (empty($venue)) {
181
-                    return '';
182
-                }
183
-                return $venue->get('VNU_virtual_phone');
184
-                break;
185
-
186
-            case '[EVENT_IMAGE]':
187
-                $image = $this->_event->feature_image_url(array(600, 300));
188
-                // @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned.
189
-                return ! empty($image)
190
-                    ? '<img src="' . $image . '" alt="'
191
-                      . sprintf(
192
-                          esc_attr__('%s Feature Image', 'event_espresso'),
193
-                          $this->_event->get('EVT_name')
194
-                      ) . '" />'
195
-                    : '';
196
-                break;
197
-
198
-            case '[EVENT_FACEBOOK_URL]':
199
-                $facebook_url = $this->_event->get_post_meta('event_facebook', true);
200
-                return empty($facebook_url) ? EE_Registry::instance()->CFG->organization->get_pretty('facebook')
201
-                    : $facebook_url;
202
-                break;
203
-
204
-            case '[EVENT_TWITTER_URL]':
205
-                $twitter_url = $this->_event->get_post_meta('event_twitter', true);
206
-                return empty($twitter_url) ? EE_Registry::instance()->CFG->organization->get_pretty('twitter')
207
-                    : $twitter_url;
208
-                break;
209
-
210
-            case '[EVENT_AUTHOR_EMAIL]':
211
-                $author_id = $this->_event->get('EVT_wp_user');
212
-                $user_data = get_userdata((int) $author_id);
213
-                return $user_data->user_email;
214
-                break;
215
-
216
-            case '[EVENT_TOTAL_SPOTS_TAKEN]':
217
-                return EEM_Registration::instance()->count(
218
-                    array(array('EVT_ID' => $this->_event->ID(), 'STS_ID' => EEM_Registration::status_id_approved)),
219
-                    'REG_ID',
220
-                    true
221
-                );
222
-                break;
223
-
224
-            case '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]':
225
-                return EEH_URL::add_query_args_and_nonce(
226
-                    array(
227
-                        'event_id' => $this->_event->ID(),
228
-                        'page'     => 'espresso_registrations',
229
-                        'action'   => 'default',
230
-                    ),
231
-                    admin_url('admin.php'),
232
-                    true
233
-                );
234
-                break;
235
-        }
236
-
237
-        if (strpos($shortcode, '[EVENT_META_*') !== false) {
238
-            // Strip the shortcode itself from $shortcode leaving any attributes set.
239
-            // Removing the * is correct here as _* is used to indiciate a dynamic shortcode.
240
-            $shortcode = str_replace('[EVENT_META_*', '', $shortcode);
241
-            $shortcode = trim(str_replace(']', '', $shortcode));
242
-            // Get any attributes set on this shortcode.
243
-            $attrs = $this->_get_shortcode_attrs($shortcode);
244
-            // The meta_key set on the shortcode should always be the first value in the array.
245
-            $meta_key = $attrs[0];
246
-            // Pull the meta value from the event post.
247
-            $event_meta = $this->_event->get_post_meta($meta_key, true);
248
-            // If we have no event_meta, just return an empty string.
249
-            if (empty($event_meta)) {
250
-                return '';
251
-            }
252
-            // Add a filter to allow all instances of EVENT_META_* to run through do_shortcode, default to false.
253
-            // Check if a do_shortcode attribute was set to true and if so run $event_meta through that function.
254
-            if (apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
255
-                || !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
256
-            ) {
257
-                return do_shortcode($event_meta);
258
-            }
259
-            // Still here? We just need to return the event_meta value as is.
260
-            return $event_meta;
261
-        }
262
-
263
-        if (strpos($shortcode, '[EVENT_TOTAL_AVAILABLE_SPACES_*') !== false) {
264
-            $attrs = $this->_get_shortcode_attrs($shortcode);
265
-            $method = empty($attrs['method']) ? 'current' : $attrs['method'];
266
-            $method = $method === 'current';
267
-            $available = $this->_event->total_available_spaces($method);
268
-            return $available === EE_INF ? '&infin;' : $available;
269
-        }
270
-
271
-        if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
272
-            $attrs = $this->_get_shortcode_attrs($shortcode);
273
-            $width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
274
-            $height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
275
-
276
-            // Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
277
-            if (! empty($attrs['size'])) {
278
-                $size = explode(',', $attrs['size']);
279
-                if (count($size) === 1) {
280
-                    $size = $size[0];
281
-                }
282
-            } else {
283
-                $size = 'thumbnail';
284
-            }
285
-
286
-            $image = $this->_event->feature_image_url($size);
287
-
288
-            return ! empty($image)
289
-                ? '<img src="' . $image . '" alt="'
290
-                  . sprintf(
291
-                      esc_attr__('%s Feature Image', 'event_espresso'),
292
-                      $this->_event->get('EVT_name')
293
-                  ) . '"' . $width . $height . '/>'
294
-                : '';
295
-        }
296
-
297
-        return '';
298
-    }
299
-
300
-
301
-    /**
302
-     * returns the link to the event
303
-     *
304
-     * @param  boolean $full_link if TRUE (default) we return the html for the name of the event linked to the event.
305
-     *                            Otherwise we just return the url of the event.
306
-     * @return string
307
-     */
308
-    private function _get_event_link($event, $full_link = true)
309
-    {
310
-        $url = get_permalink($event->ID());
311
-
312
-        return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
313
-    }
22
+	/**
23
+	 * Will hold the EE_Event if available
24
+	 *
25
+	 * @var EE_Event
26
+	 */
27
+	protected $_event;
28
+
29
+
30
+	public function __construct()
31
+	{
32
+		parent::__construct();
33
+	}
34
+
35
+
36
+	protected function _init_props()
37
+	{
38
+		$this->label = __('Event Shortcodes', 'event_espresso');
39
+		$this->description = __('All shortcodes specific to event related data', 'event_espresso');
40
+		$this->_shortcodes = array(
41
+			'[EVENT_ID]'                              => __(
42
+				'Will be replaced by the event ID of an event',
43
+				'event_espresso'
44
+			),
45
+			'[EVENT]'                                 => __('The name of the event', 'event_espresso'),
46
+			'[EVENT_NAME]'                            => __(
47
+				"This also can be used for the name of the event",
48
+				'event_espresso'
49
+			),
50
+			'[EVENT_PHONE]'                           => __(
51
+				'The phone number for the event (usually an info number)',
52
+				'event_espresso'
53
+			),
54
+			'[EVENT_DESCRIPTION]'                     => __('The description of the event', 'event_espresso'),
55
+			'[EVENT_EXCERPT]'                         => __(
56
+				'This gets parsed to the value for the excerpt field in the event or blank if there is no excerpt.',
57
+				'event_espresso'
58
+			),
59
+			'[EVENT_LINK]'                            => __('A link associated with the event', 'event_espresso'),
60
+			'[EVENT_URL]'                             => __(
61
+				'A link to the event set up on the host site.',
62
+				'event_espresso'
63
+			),
64
+			'[VIRTUAL_URL]'                           => __(
65
+				'What was used for the "URL of Event" field in the Venue settings',
66
+				'event_espresso'
67
+			),
68
+			'[VIRTUAL_PHONE]'                         => __(
69
+				'An alternate phone number for the event. Typically used as a "call-in" number',
70
+				'event_espresso'
71
+			),
72
+			'[EVENT_IMAGE]'                           => __(
73
+				'This will parse to the Feature image for the event.',
74
+				'event_espresso'
75
+			),
76
+			'[EVENT_IMAGE_*]'                         => sprintf(
77
+				__(
78
+					'This will parse to the Feature image for the event, %1$ssize%2$s can be set to determine the size of the image loaded by the shortcode. The %1$swidth%2$s and/or %1$sheight%2$s can also be set to determine the width and height of the image when output. By default the shortcode will load the %1$sthumbnail%2$s image size.',
79
+					'event_espresso'
80
+				),
81
+				'<code>',
82
+				'</code>'
83
+			),
84
+			'[EVENT_TOTAL_AVAILABLE_SPACES_*]'        => sprintf(
85
+				__(
86
+					'This will parse to the total available spaces for an event. Calculating total spaces is approximate because it is dependent on the complexity of limits on your event.  There are two methods of calculation (which can be indicated by the %1$smethod%2$s param on the shortcode).  %1$scurrent%2$s which will do a more accurate calculation of total available spaces based on current sales, and %1$sfull%2$s which will be the maximum total available spaces that is on the event in optimal conditions. The shortcode will default to current.',
87
+					'event_espresso'
88
+				),
89
+				'<code>',
90
+				'</code>'
91
+			),
92
+			'[EVENT_TOTAL_SPOTS_TAKEN]'               => __(
93
+				'This shortcode will parse to the output the total approved registrations for this event',
94
+				'event_espresso'
95
+			),
96
+			'[EVENT_FACEBOOK_URL]'                    => __(
97
+				'This will return the Facebook URL for the event if you have it set via custom field in your event, otherwise it will use the Facebook URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_facebook</code> and the value as your facebook url.',
98
+				'event_espresso'
99
+			),
100
+			'[EVENT_TWITTER_URL]'                     => __(
101
+				'This will return the Twitter URL for the event if you have it set via custom field in your event, otherwise it will use the Twitter URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_twitter</code> and the value as your facebook url',
102
+				'event_espresso'
103
+			),
104
+			'[EVENT_META_*]'                          => sprintf(
105
+				__(
106
+					'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the event then it will be output in place of this shortcode. If you use shortcodes within your custom fields set %1$sdo_shortcode=true%2$s at the end of the shortcode to run the value through the do_shortcode function. ',
107
+					'event_espresso'
108
+				),
109
+				'<code>',
110
+				'</code>'
111
+			),
112
+			'[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]' => __(
113
+				'This parses to the url for the registration list table filtered by registrations for this event.',
114
+				'event_espresso'
115
+			),
116
+		);
117
+	}
118
+
119
+
120
+	protected function _parser($shortcode)
121
+	{
122
+
123
+
124
+		$this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
125
+
126
+		// if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
127
+		if (empty($this->_event)) {
128
+			$aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
129
+			$aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
130
+
131
+			$this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
132
+				? $aee->reg_obj->event() : null;
133
+		}
134
+
135
+
136
+		// If there is no event objecdt by now then get out.
137
+		if (! $this->_event instanceof EE_Event) {
138
+			return '';
139
+		}
140
+
141
+		switch ($shortcode) {
142
+			case '[EVENT_ID]':
143
+				return $this->_event->ID();
144
+				break;
145
+
146
+			case '[EVENT]':
147
+			case '[EVENT_NAME]':
148
+				return $this->_event->get('EVT_name');
149
+				break;
150
+
151
+			case '[EVENT_PHONE]':
152
+				return $this->_event->get('EVT_phone');
153
+				break;
154
+
155
+			case '[EVENT_DESCRIPTION]':
156
+				return $this->_event->get('EVT_desc');
157
+				break;
158
+
159
+			case '[EVENT_EXCERPT]':
160
+				return $this->_event->get('EVT_short_desc');
161
+				break;
162
+
163
+			case '[EVENT_LINK]':
164
+				return $this->_get_event_link($this->_event);
165
+				break;
166
+
167
+			case '[EVENT_URL]':
168
+				return $this->_get_event_link($this->_event, false);
169
+				break;
170
+
171
+			case '[VIRTUAL_URL]':
172
+				$venue = $this->_event->get_first_related('Venue');
173
+				if (empty($venue)) {
174
+					return '';
175
+				}
176
+				return $venue->get('VNU_virtual_url');
177
+
178
+			case '[VIRTUAL_PHONE]':
179
+				$venue = $this->_event->get_first_related('Venue');
180
+				if (empty($venue)) {
181
+					return '';
182
+				}
183
+				return $venue->get('VNU_virtual_phone');
184
+				break;
185
+
186
+			case '[EVENT_IMAGE]':
187
+				$image = $this->_event->feature_image_url(array(600, 300));
188
+				// @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned.
189
+				return ! empty($image)
190
+					? '<img src="' . $image . '" alt="'
191
+					  . sprintf(
192
+						  esc_attr__('%s Feature Image', 'event_espresso'),
193
+						  $this->_event->get('EVT_name')
194
+					  ) . '" />'
195
+					: '';
196
+				break;
197
+
198
+			case '[EVENT_FACEBOOK_URL]':
199
+				$facebook_url = $this->_event->get_post_meta('event_facebook', true);
200
+				return empty($facebook_url) ? EE_Registry::instance()->CFG->organization->get_pretty('facebook')
201
+					: $facebook_url;
202
+				break;
203
+
204
+			case '[EVENT_TWITTER_URL]':
205
+				$twitter_url = $this->_event->get_post_meta('event_twitter', true);
206
+				return empty($twitter_url) ? EE_Registry::instance()->CFG->organization->get_pretty('twitter')
207
+					: $twitter_url;
208
+				break;
209
+
210
+			case '[EVENT_AUTHOR_EMAIL]':
211
+				$author_id = $this->_event->get('EVT_wp_user');
212
+				$user_data = get_userdata((int) $author_id);
213
+				return $user_data->user_email;
214
+				break;
215
+
216
+			case '[EVENT_TOTAL_SPOTS_TAKEN]':
217
+				return EEM_Registration::instance()->count(
218
+					array(array('EVT_ID' => $this->_event->ID(), 'STS_ID' => EEM_Registration::status_id_approved)),
219
+					'REG_ID',
220
+					true
221
+				);
222
+				break;
223
+
224
+			case '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]':
225
+				return EEH_URL::add_query_args_and_nonce(
226
+					array(
227
+						'event_id' => $this->_event->ID(),
228
+						'page'     => 'espresso_registrations',
229
+						'action'   => 'default',
230
+					),
231
+					admin_url('admin.php'),
232
+					true
233
+				);
234
+				break;
235
+		}
236
+
237
+		if (strpos($shortcode, '[EVENT_META_*') !== false) {
238
+			// Strip the shortcode itself from $shortcode leaving any attributes set.
239
+			// Removing the * is correct here as _* is used to indiciate a dynamic shortcode.
240
+			$shortcode = str_replace('[EVENT_META_*', '', $shortcode);
241
+			$shortcode = trim(str_replace(']', '', $shortcode));
242
+			// Get any attributes set on this shortcode.
243
+			$attrs = $this->_get_shortcode_attrs($shortcode);
244
+			// The meta_key set on the shortcode should always be the first value in the array.
245
+			$meta_key = $attrs[0];
246
+			// Pull the meta value from the event post.
247
+			$event_meta = $this->_event->get_post_meta($meta_key, true);
248
+			// If we have no event_meta, just return an empty string.
249
+			if (empty($event_meta)) {
250
+				return '';
251
+			}
252
+			// Add a filter to allow all instances of EVENT_META_* to run through do_shortcode, default to false.
253
+			// Check if a do_shortcode attribute was set to true and if so run $event_meta through that function.
254
+			if (apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
255
+				|| !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
256
+			) {
257
+				return do_shortcode($event_meta);
258
+			}
259
+			// Still here? We just need to return the event_meta value as is.
260
+			return $event_meta;
261
+		}
262
+
263
+		if (strpos($shortcode, '[EVENT_TOTAL_AVAILABLE_SPACES_*') !== false) {
264
+			$attrs = $this->_get_shortcode_attrs($shortcode);
265
+			$method = empty($attrs['method']) ? 'current' : $attrs['method'];
266
+			$method = $method === 'current';
267
+			$available = $this->_event->total_available_spaces($method);
268
+			return $available === EE_INF ? '&infin;' : $available;
269
+		}
270
+
271
+		if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
272
+			$attrs = $this->_get_shortcode_attrs($shortcode);
273
+			$width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
274
+			$height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
275
+
276
+			// Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
277
+			if (! empty($attrs['size'])) {
278
+				$size = explode(',', $attrs['size']);
279
+				if (count($size) === 1) {
280
+					$size = $size[0];
281
+				}
282
+			} else {
283
+				$size = 'thumbnail';
284
+			}
285
+
286
+			$image = $this->_event->feature_image_url($size);
287
+
288
+			return ! empty($image)
289
+				? '<img src="' . $image . '" alt="'
290
+				  . sprintf(
291
+					  esc_attr__('%s Feature Image', 'event_espresso'),
292
+					  $this->_event->get('EVT_name')
293
+				  ) . '"' . $width . $height . '/>'
294
+				: '';
295
+		}
296
+
297
+		return '';
298
+	}
299
+
300
+
301
+	/**
302
+	 * returns the link to the event
303
+	 *
304
+	 * @param  boolean $full_link if TRUE (default) we return the html for the name of the event linked to the event.
305
+	 *                            Otherwise we just return the url of the event.
306
+	 * @return string
307
+	 */
308
+	private function _get_event_link($event, $full_link = true)
309
+	{
310
+		$url = get_permalink($event->ID());
311
+
312
+		return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
313
+	}
314 314
 }
Please login to merge, or discard this patch.
core/EE_Addon.core.php 1 patch
Indentation   +843 added lines, -843 removed lines patch added patch discarded remove patch
@@ -19,797 +19,797 @@  discard block
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * prefix to be added onto an addon's plugin slug to make a wp option name
24
-     * which will be used to store the plugin's activation history
25
-     */
26
-    const ee_addon_version_history_option_prefix = 'ee_version_history_';
27
-
28
-    /**
29
-     * @var $_version
30
-     * @type string
31
-     */
32
-    protected $_version = '';
33
-
34
-    /**
35
-     * @var $_min_core_version
36
-     * @type string
37
-     */
38
-    protected $_min_core_version = '';
39
-
40
-    /**
41
-     * derived from plugin 'main_file_path using plugin_basename()
42
-     *
43
-     * @type string $_plugin_basename
44
-     */
45
-    protected $_plugin_basename = '';
46
-
47
-    /**
48
-     * A non-internationalized name to identify this addon for use in URLs, etc
49
-     *
50
-     * @type string $_plugin_slug
51
-     */
52
-    protected $_plugin_slug = '';
53
-
54
-    /**
55
-     * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/
56
-     *
57
-     * @type string _addon_name
58
-     */
59
-    protected $_addon_name = '';
60
-
61
-    /**
62
-     * one of the EE_System::req_type_* constants
63
-     *
64
-     * @type int $_req_type
65
-     */
66
-    protected $_req_type;
67
-
68
-    /**
69
-     * page slug to be used when generating the "Settings" link on the WP plugin page
70
-     *
71
-     * @type string $_plugin_action_slug
72
-     */
73
-    protected $_plugin_action_slug = '';
74
-
75
-    /**
76
-     * if not empty, inserts a new table row after this plugin's row on the WP Plugins page
77
-     * that can be used for adding upgrading/marketing info
78
-     *
79
-     * @type array $_plugins_page_row
80
-     */
81
-    protected $_plugins_page_row = array();
82
-
83
-
84
-    /**
85
-     *    filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
86
-     *
87
-     * @type string
88
-     */
89
-    protected $_main_plugin_file;
90
-
91
-    /**
92
-     *    This is the slug used to identify this add-on within the plugin update engine.
93
-     *
94
-     * @type string
95
-     */
96
-    protected $pue_slug;
97
-
98
-
99
-    /**
100
-     * @var EE_Dependency_Map $dependency_map
101
-     */
102
-    private $dependency_map;
103
-
104
-
105
-    /**
106
-     * @var DomainInterface $domain
107
-     */
108
-    private $domain;
109
-
110
-
111
-    /**
112
-     * @param EE_Dependency_Map $dependency_map [optional]
113
-     * @param DomainInterface   $domain         [optional]
114
-     */
115
-    public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null)
116
-    {
117
-        if ($dependency_map instanceof EE_Dependency_Map) {
118
-            $this->setDependencyMap($dependency_map);
119
-        }
120
-        if ($domain instanceof DomainInterface) {
121
-            $this->setDomain($domain);
122
-        }
123
-        add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init'));
124
-    }
125
-
126
-
127
-    /**
128
-     * @param EE_Dependency_Map $dependency_map
129
-     */
130
-    public function setDependencyMap($dependency_map)
131
-    {
132
-        $this->dependency_map = $dependency_map;
133
-    }
134
-
135
-
136
-    /**
137
-     * @return EE_Dependency_Map
138
-     */
139
-    public function dependencyMap()
140
-    {
141
-        return $this->dependency_map;
142
-    }
143
-
144
-
145
-    /**
146
-     * @param DomainInterface $domain
147
-     */
148
-    public function setDomain(DomainInterface $domain)
149
-    {
150
-        $this->domain = $domain;
151
-    }
152
-
153
-    /**
154
-     * @return DomainInterface
155
-     */
156
-    public function domain()
157
-    {
158
-        return $this->domain;
159
-    }
160
-
161
-
162
-    /**
163
-     * @param mixed $version
164
-     */
165
-    public function set_version($version = null)
166
-    {
167
-        $this->_version = $version;
168
-    }
169
-
170
-
171
-    /**
172
-     * get__version
173
-     *
174
-     * @return string
175
-     */
176
-    public function version()
177
-    {
178
-        return $this->_version;
179
-    }
180
-
181
-
182
-    /**
183
-     * @param mixed $min_core_version
184
-     */
185
-    public function set_min_core_version($min_core_version = null)
186
-    {
187
-        $this->_min_core_version = $min_core_version;
188
-    }
189
-
190
-
191
-    /**
192
-     * get__min_core_version
193
-     *
194
-     * @return string
195
-     */
196
-    public function min_core_version()
197
-    {
198
-        return $this->_min_core_version;
199
-    }
200
-
201
-
202
-    /**
203
-     * Sets addon_name
204
-     *
205
-     * @param string $addon_name
206
-     * @return boolean
207
-     */
208
-    public function set_name($addon_name)
209
-    {
210
-        return $this->_addon_name = $addon_name;
211
-    }
212
-
213
-
214
-    /**
215
-     * Gets addon_name
216
-     *
217
-     * @return string
218
-     */
219
-    public function name()
220
-    {
221
-        return $this->_addon_name;
222
-    }
223
-
224
-
225
-    /**
226
-     * @return string
227
-     */
228
-    public function plugin_basename()
229
-    {
230
-
231
-        return $this->_plugin_basename;
232
-    }
233
-
234
-
235
-    /**
236
-     * @param string $plugin_basename
237
-     */
238
-    public function set_plugin_basename($plugin_basename)
239
-    {
240
-
241
-        $this->_plugin_basename = $plugin_basename;
242
-    }
243
-
244
-
245
-    /**
246
-     * @return string
247
-     */
248
-    public function plugin_slug()
249
-    {
250
-
251
-        return $this->_plugin_slug;
252
-    }
253
-
254
-
255
-    /**
256
-     * @param string $plugin_slug
257
-     */
258
-    public function set_plugin_slug($plugin_slug)
259
-    {
260
-
261
-        $this->_plugin_slug = $plugin_slug;
262
-    }
263
-
264
-
265
-    /**
266
-     * @return string
267
-     */
268
-    public function plugin_action_slug()
269
-    {
270
-
271
-        return $this->_plugin_action_slug;
272
-    }
273
-
274
-
275
-    /**
276
-     * @param string $plugin_action_slug
277
-     */
278
-    public function set_plugin_action_slug($plugin_action_slug)
279
-    {
280
-
281
-        $this->_plugin_action_slug = $plugin_action_slug;
282
-    }
283
-
284
-
285
-    /**
286
-     * @return array
287
-     */
288
-    public function get_plugins_page_row()
289
-    {
290
-
291
-        return $this->_plugins_page_row;
292
-    }
293
-
294
-
295
-    /**
296
-     * @param array $plugins_page_row
297
-     */
298
-    public function set_plugins_page_row($plugins_page_row = array())
299
-    {
300
-        // sigh.... check for example content that I stupidly merged to master and remove it if found
301
-        if (! is_array($plugins_page_row)
302
-            && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false
303
-        ) {
304
-            $plugins_page_row = array();
305
-        }
306
-        $this->_plugins_page_row = (array) $plugins_page_row;
307
-    }
308
-
309
-
310
-    /**
311
-     * Called when EE core detects this addon has been activated for the first time.
312
-     * If the site isn't in maintenance mode, should setup the addon's database
313
-     *
314
-     * @return void
315
-     */
316
-    public function new_install()
317
-    {
318
-        $classname = get_class($this);
319
-        do_action("AHEE__{$classname}__new_install");
320
-        do_action('AHEE__EE_Addon__new_install', $this);
321
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
322
-        add_action(
323
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
324
-            array($this, 'initialize_db_if_no_migrations_required')
325
-        );
326
-    }
327
-
328
-
329
-    /**
330
-     * Called when EE core detects this addon has been reactivated. When this happens,
331
-     * it's good to just check that your data is still intact
332
-     *
333
-     * @return void
334
-     */
335
-    public function reactivation()
336
-    {
337
-        $classname = get_class($this);
338
-        do_action("AHEE__{$classname}__reactivation");
339
-        do_action('AHEE__EE_Addon__reactivation', $this);
340
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
341
-        add_action(
342
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
343
-            array($this, 'initialize_db_if_no_migrations_required')
344
-        );
345
-    }
346
-
347
-
348
-    /**
349
-     * Called when the registered deactivation hook for this addon fires.
350
-     *
351
-     * @throws EE_Error
352
-     */
353
-    public function deactivation()
354
-    {
355
-        $classname = get_class($this);
356
-        do_action("AHEE__{$classname}__deactivation");
357
-        do_action('AHEE__EE_Addon__deactivation', $this);
358
-        // check if the site no longer needs to be in maintenance mode
359
-        EE_Register_Addon::deregister($this->name());
360
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
361
-    }
362
-
363
-
364
-    /**
365
-     * Takes care of double-checking that we're not in maintenance mode, and then
366
-     * initializing this addon's necessary initial data. This is called by default on new activations
367
-     * and reactivations.
368
-     *
369
-     * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
370
-     *                               This is a resource-intensive job so we prefer to only do it when necessary
371
-     * @return void
372
-     * @throws \EE_Error
373
-     * @throws InvalidInterfaceException
374
-     * @throws InvalidDataTypeException
375
-     * @throws InvalidArgumentException
376
-     */
377
-    public function initialize_db_if_no_migrations_required($verify_schema = true)
378
-    {
379
-        if ($verify_schema === '') {
380
-            // wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
381
-            // (ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
382
-            // calls them with an argument of an empty string (ie ""), which evaluates to false
383
-            // so we need to treat the empty string as if nothing had been passed, and should instead use the default
384
-            $verify_schema = true;
385
-        }
386
-        if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
387
-            if ($verify_schema) {
388
-                $this->initialize_db();
389
-            }
390
-            $this->initialize_default_data();
391
-            // @todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
392
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to(
393
-                array(
394
-                    'slug'    => $this->name(),
395
-                    'version' => $this->version(),
396
-                )
397
-            );
398
-            /* make sure core's data is a-ok
22
+	/**
23
+	 * prefix to be added onto an addon's plugin slug to make a wp option name
24
+	 * which will be used to store the plugin's activation history
25
+	 */
26
+	const ee_addon_version_history_option_prefix = 'ee_version_history_';
27
+
28
+	/**
29
+	 * @var $_version
30
+	 * @type string
31
+	 */
32
+	protected $_version = '';
33
+
34
+	/**
35
+	 * @var $_min_core_version
36
+	 * @type string
37
+	 */
38
+	protected $_min_core_version = '';
39
+
40
+	/**
41
+	 * derived from plugin 'main_file_path using plugin_basename()
42
+	 *
43
+	 * @type string $_plugin_basename
44
+	 */
45
+	protected $_plugin_basename = '';
46
+
47
+	/**
48
+	 * A non-internationalized name to identify this addon for use in URLs, etc
49
+	 *
50
+	 * @type string $_plugin_slug
51
+	 */
52
+	protected $_plugin_slug = '';
53
+
54
+	/**
55
+	 * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/
56
+	 *
57
+	 * @type string _addon_name
58
+	 */
59
+	protected $_addon_name = '';
60
+
61
+	/**
62
+	 * one of the EE_System::req_type_* constants
63
+	 *
64
+	 * @type int $_req_type
65
+	 */
66
+	protected $_req_type;
67
+
68
+	/**
69
+	 * page slug to be used when generating the "Settings" link on the WP plugin page
70
+	 *
71
+	 * @type string $_plugin_action_slug
72
+	 */
73
+	protected $_plugin_action_slug = '';
74
+
75
+	/**
76
+	 * if not empty, inserts a new table row after this plugin's row on the WP Plugins page
77
+	 * that can be used for adding upgrading/marketing info
78
+	 *
79
+	 * @type array $_plugins_page_row
80
+	 */
81
+	protected $_plugins_page_row = array();
82
+
83
+
84
+	/**
85
+	 *    filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
86
+	 *
87
+	 * @type string
88
+	 */
89
+	protected $_main_plugin_file;
90
+
91
+	/**
92
+	 *    This is the slug used to identify this add-on within the plugin update engine.
93
+	 *
94
+	 * @type string
95
+	 */
96
+	protected $pue_slug;
97
+
98
+
99
+	/**
100
+	 * @var EE_Dependency_Map $dependency_map
101
+	 */
102
+	private $dependency_map;
103
+
104
+
105
+	/**
106
+	 * @var DomainInterface $domain
107
+	 */
108
+	private $domain;
109
+
110
+
111
+	/**
112
+	 * @param EE_Dependency_Map $dependency_map [optional]
113
+	 * @param DomainInterface   $domain         [optional]
114
+	 */
115
+	public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null)
116
+	{
117
+		if ($dependency_map instanceof EE_Dependency_Map) {
118
+			$this->setDependencyMap($dependency_map);
119
+		}
120
+		if ($domain instanceof DomainInterface) {
121
+			$this->setDomain($domain);
122
+		}
123
+		add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init'));
124
+	}
125
+
126
+
127
+	/**
128
+	 * @param EE_Dependency_Map $dependency_map
129
+	 */
130
+	public function setDependencyMap($dependency_map)
131
+	{
132
+		$this->dependency_map = $dependency_map;
133
+	}
134
+
135
+
136
+	/**
137
+	 * @return EE_Dependency_Map
138
+	 */
139
+	public function dependencyMap()
140
+	{
141
+		return $this->dependency_map;
142
+	}
143
+
144
+
145
+	/**
146
+	 * @param DomainInterface $domain
147
+	 */
148
+	public function setDomain(DomainInterface $domain)
149
+	{
150
+		$this->domain = $domain;
151
+	}
152
+
153
+	/**
154
+	 * @return DomainInterface
155
+	 */
156
+	public function domain()
157
+	{
158
+		return $this->domain;
159
+	}
160
+
161
+
162
+	/**
163
+	 * @param mixed $version
164
+	 */
165
+	public function set_version($version = null)
166
+	{
167
+		$this->_version = $version;
168
+	}
169
+
170
+
171
+	/**
172
+	 * get__version
173
+	 *
174
+	 * @return string
175
+	 */
176
+	public function version()
177
+	{
178
+		return $this->_version;
179
+	}
180
+
181
+
182
+	/**
183
+	 * @param mixed $min_core_version
184
+	 */
185
+	public function set_min_core_version($min_core_version = null)
186
+	{
187
+		$this->_min_core_version = $min_core_version;
188
+	}
189
+
190
+
191
+	/**
192
+	 * get__min_core_version
193
+	 *
194
+	 * @return string
195
+	 */
196
+	public function min_core_version()
197
+	{
198
+		return $this->_min_core_version;
199
+	}
200
+
201
+
202
+	/**
203
+	 * Sets addon_name
204
+	 *
205
+	 * @param string $addon_name
206
+	 * @return boolean
207
+	 */
208
+	public function set_name($addon_name)
209
+	{
210
+		return $this->_addon_name = $addon_name;
211
+	}
212
+
213
+
214
+	/**
215
+	 * Gets addon_name
216
+	 *
217
+	 * @return string
218
+	 */
219
+	public function name()
220
+	{
221
+		return $this->_addon_name;
222
+	}
223
+
224
+
225
+	/**
226
+	 * @return string
227
+	 */
228
+	public function plugin_basename()
229
+	{
230
+
231
+		return $this->_plugin_basename;
232
+	}
233
+
234
+
235
+	/**
236
+	 * @param string $plugin_basename
237
+	 */
238
+	public function set_plugin_basename($plugin_basename)
239
+	{
240
+
241
+		$this->_plugin_basename = $plugin_basename;
242
+	}
243
+
244
+
245
+	/**
246
+	 * @return string
247
+	 */
248
+	public function plugin_slug()
249
+	{
250
+
251
+		return $this->_plugin_slug;
252
+	}
253
+
254
+
255
+	/**
256
+	 * @param string $plugin_slug
257
+	 */
258
+	public function set_plugin_slug($plugin_slug)
259
+	{
260
+
261
+		$this->_plugin_slug = $plugin_slug;
262
+	}
263
+
264
+
265
+	/**
266
+	 * @return string
267
+	 */
268
+	public function plugin_action_slug()
269
+	{
270
+
271
+		return $this->_plugin_action_slug;
272
+	}
273
+
274
+
275
+	/**
276
+	 * @param string $plugin_action_slug
277
+	 */
278
+	public function set_plugin_action_slug($plugin_action_slug)
279
+	{
280
+
281
+		$this->_plugin_action_slug = $plugin_action_slug;
282
+	}
283
+
284
+
285
+	/**
286
+	 * @return array
287
+	 */
288
+	public function get_plugins_page_row()
289
+	{
290
+
291
+		return $this->_plugins_page_row;
292
+	}
293
+
294
+
295
+	/**
296
+	 * @param array $plugins_page_row
297
+	 */
298
+	public function set_plugins_page_row($plugins_page_row = array())
299
+	{
300
+		// sigh.... check for example content that I stupidly merged to master and remove it if found
301
+		if (! is_array($plugins_page_row)
302
+			&& strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false
303
+		) {
304
+			$plugins_page_row = array();
305
+		}
306
+		$this->_plugins_page_row = (array) $plugins_page_row;
307
+	}
308
+
309
+
310
+	/**
311
+	 * Called when EE core detects this addon has been activated for the first time.
312
+	 * If the site isn't in maintenance mode, should setup the addon's database
313
+	 *
314
+	 * @return void
315
+	 */
316
+	public function new_install()
317
+	{
318
+		$classname = get_class($this);
319
+		do_action("AHEE__{$classname}__new_install");
320
+		do_action('AHEE__EE_Addon__new_install', $this);
321
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
322
+		add_action(
323
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
324
+			array($this, 'initialize_db_if_no_migrations_required')
325
+		);
326
+	}
327
+
328
+
329
+	/**
330
+	 * Called when EE core detects this addon has been reactivated. When this happens,
331
+	 * it's good to just check that your data is still intact
332
+	 *
333
+	 * @return void
334
+	 */
335
+	public function reactivation()
336
+	{
337
+		$classname = get_class($this);
338
+		do_action("AHEE__{$classname}__reactivation");
339
+		do_action('AHEE__EE_Addon__reactivation', $this);
340
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
341
+		add_action(
342
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
343
+			array($this, 'initialize_db_if_no_migrations_required')
344
+		);
345
+	}
346
+
347
+
348
+	/**
349
+	 * Called when the registered deactivation hook for this addon fires.
350
+	 *
351
+	 * @throws EE_Error
352
+	 */
353
+	public function deactivation()
354
+	{
355
+		$classname = get_class($this);
356
+		do_action("AHEE__{$classname}__deactivation");
357
+		do_action('AHEE__EE_Addon__deactivation', $this);
358
+		// check if the site no longer needs to be in maintenance mode
359
+		EE_Register_Addon::deregister($this->name());
360
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
361
+	}
362
+
363
+
364
+	/**
365
+	 * Takes care of double-checking that we're not in maintenance mode, and then
366
+	 * initializing this addon's necessary initial data. This is called by default on new activations
367
+	 * and reactivations.
368
+	 *
369
+	 * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
370
+	 *                               This is a resource-intensive job so we prefer to only do it when necessary
371
+	 * @return void
372
+	 * @throws \EE_Error
373
+	 * @throws InvalidInterfaceException
374
+	 * @throws InvalidDataTypeException
375
+	 * @throws InvalidArgumentException
376
+	 */
377
+	public function initialize_db_if_no_migrations_required($verify_schema = true)
378
+	{
379
+		if ($verify_schema === '') {
380
+			// wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
381
+			// (ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
382
+			// calls them with an argument of an empty string (ie ""), which evaluates to false
383
+			// so we need to treat the empty string as if nothing had been passed, and should instead use the default
384
+			$verify_schema = true;
385
+		}
386
+		if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
387
+			if ($verify_schema) {
388
+				$this->initialize_db();
389
+			}
390
+			$this->initialize_default_data();
391
+			// @todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
392
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to(
393
+				array(
394
+					'slug'    => $this->name(),
395
+					'version' => $this->version(),
396
+				)
397
+			);
398
+			/* make sure core's data is a-ok
399 399
              * (at the time of writing, we especially want to verify all the caps are present
400 400
              * because payment method type capabilities are added dynamically, and it's
401 401
              * possible this addon added a payment method. But it's also possible
402 402
              * other data needs to be verified)
403 403
              */
404
-            EEH_Activation::initialize_db_content();
405
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
406
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
407
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
408
-            );
409
-            $rewrite_rules->flushRewriteRules();
410
-            // in case there are lots of addons being activated at once, let's force garbage collection
411
-            // to help avoid memory limit errors
412
-            // EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
413
-            gc_collect_cycles();
414
-        } else {
415
-            // ask the data migration manager to init this addon's data
416
-            // when migrations are finished because we can't do it now
417
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
418
-        }
419
-    }
420
-
421
-
422
-    /**
423
-     * Used to setup this addon's database tables, but not necessarily any default
424
-     * data in them. The default is to actually use the most up-to-date data migration script
425
-     * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
426
-     * methods to setup the db.
427
-     */
428
-    public function initialize_db()
429
-    {
430
-        // find the migration script that sets the database to be compatible with the code
431
-        $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
432
-        if ($current_dms_name) {
433
-            $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
434
-            $current_data_migration_script->set_migrating(false);
435
-            $current_data_migration_script->schema_changes_before_migration();
436
-            $current_data_migration_script->schema_changes_after_migration();
437
-            if ($current_data_migration_script->get_errors()) {
438
-                foreach ($current_data_migration_script->get_errors() as $error) {
439
-                    EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
440
-                }
441
-            }
442
-        }
443
-        // if not DMS was found that should be ok. This addon just doesn't require any database changes
444
-        EE_Data_Migration_Manager::instance()->update_current_database_state_to(
445
-            array(
446
-                'slug'    => $this->name(),
447
-                'version' => $this->version(),
448
-            )
449
-        );
450
-    }
451
-
452
-
453
-    /**
454
-     * If you want to setup default data for the addon, override this method, and call
455
-     * parent::initialize_default_data() from within it. This is normally called
456
-     * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
457
-     * and should verify default data is present (but this is also called
458
-     * on reactivations and just after migrations, so please verify you actually want
459
-     * to ADD default data, because it may already be present).
460
-     * However, please call this parent (currently it just fires a hook which other
461
-     * addons may be depending on)
462
-     */
463
-    public function initialize_default_data()
464
-    {
465
-        /**
466
-         * Called when an addon is ensuring its default data is set (possibly called
467
-         * on a reactivation, so first check for the absence of other data before setting
468
-         * default data)
469
-         *
470
-         * @param EE_Addon $addon the addon that called this
471
-         */
472
-        do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
473
-        // override to insert default data. It is safe to use the models here
474
-        // because the site should not be in maintenance mode
475
-    }
476
-
477
-
478
-    /**
479
-     * EE Core detected that this addon has been upgraded. We should check if there
480
-     * are any new migration scripts, and if so put the site into maintenance mode until
481
-     * they're ran
482
-     *
483
-     * @return void
484
-     */
485
-    public function upgrade()
486
-    {
487
-        $classname = get_class($this);
488
-        do_action("AHEE__{$classname}__upgrade");
489
-        do_action('AHEE__EE_Addon__upgrade', $this);
490
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
491
-        // also it's possible there is new default data that needs to be added
492
-        add_action(
493
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
494
-            array($this, 'initialize_db_if_no_migrations_required')
495
-        );
496
-    }
497
-
498
-
499
-    /**
500
-     * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
501
-     */
502
-    public function downgrade()
503
-    {
504
-        $classname = get_class($this);
505
-        do_action("AHEE__{$classname}__downgrade");
506
-        do_action('AHEE__EE_Addon__downgrade', $this);
507
-        // it's possible there's old default data that needs to be double-checked
508
-        add_action(
509
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
510
-            array($this, 'initialize_db_if_no_migrations_required')
511
-        );
512
-    }
513
-
514
-
515
-    /**
516
-     * set_db_update_option_name
517
-     * Until we do something better, we'll just check for migration scripts upon
518
-     * plugin activation only. In the future, we'll want to do it on plugin updates too
519
-     *
520
-     * @return bool
521
-     */
522
-    public function set_db_update_option_name()
523
-    {
524
-        EE_Error::doing_it_wrong(
525
-            __FUNCTION__,
526
-            esc_html__(
527
-                'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
528
-                'event_espresso'
529
-            ),
530
-            '4.3.0.alpha.016'
531
-        );
532
-        // let's just handle this on the next request, ok? right now we're just not really ready
533
-        return $this->set_activation_indicator_option();
534
-    }
535
-
536
-
537
-    /**
538
-     * Returns the name of the activation indicator option
539
-     * (an option which is set temporarily to indicate that this addon was just activated)
540
-     *
541
-     * @deprecated since version 4.3.0.alpha.016
542
-     * @return string
543
-     */
544
-    public function get_db_update_option_name()
545
-    {
546
-        EE_Error::doing_it_wrong(
547
-            __FUNCTION__,
548
-            esc_html__(
549
-                'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
550
-                'event_espresso'
551
-            ),
552
-            '4.3.0.alpha.016'
553
-        );
554
-        return $this->get_activation_indicator_option_name();
555
-    }
556
-
557
-
558
-    /**
559
-     * When the addon is activated, this should be called to set a wordpress option that
560
-     * indicates it was activated. This is especially useful for detecting reactivations.
561
-     *
562
-     * @return bool
563
-     */
564
-    public function set_activation_indicator_option()
565
-    {
566
-        // let's just handle this on the next request, ok? right now we're just not really ready
567
-        return update_option($this->get_activation_indicator_option_name(), true);
568
-    }
569
-
570
-
571
-    /**
572
-     * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
573
-     *
574
-     * @return string
575
-     */
576
-    public function get_activation_indicator_option_name()
577
-    {
578
-        return 'ee_activation_' . $this->name();
579
-    }
580
-
581
-
582
-    /**
583
-     * Used by EE_System to set the request type of this addon. Should not be used by addon developers
584
-     *
585
-     * @param int $req_type
586
-     */
587
-    public function set_req_type($req_type)
588
-    {
589
-        $this->_req_type = $req_type;
590
-    }
591
-
592
-
593
-    /**
594
-     * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
595
-     * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
596
-     * EE_System when it is checking for new install or upgrades of addons
597
-     */
598
-    public function detect_req_type()
599
-    {
600
-        if (! $this->_req_type) {
601
-            $this->detect_activation_or_upgrade();
602
-        }
603
-        return $this->_req_type;
604
-    }
605
-
606
-
607
-    /**
608
-     * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
609
-     * Should only be called once per request
610
-     *
611
-     * @return void
612
-     */
613
-    public function detect_activation_or_upgrade()
614
-    {
615
-        $activation_history_for_addon = $this->get_activation_history();
616
-        $request_type = EE_System::detect_req_type_given_activation_history(
617
-            $activation_history_for_addon,
618
-            $this->get_activation_indicator_option_name(),
619
-            $this->version()
620
-        );
621
-        $this->set_req_type($request_type);
622
-        $classname = get_class($this);
623
-        switch ($request_type) {
624
-            case EE_System::req_type_new_activation:
625
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
626
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
627
-                $this->new_install();
628
-                $this->update_list_of_installed_versions($activation_history_for_addon);
629
-                break;
630
-            case EE_System::req_type_reactivation:
631
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
632
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
633
-                $this->reactivation();
634
-                $this->update_list_of_installed_versions($activation_history_for_addon);
635
-                break;
636
-            case EE_System::req_type_upgrade:
637
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
638
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
639
-                $this->upgrade();
640
-                $this->update_list_of_installed_versions($activation_history_for_addon);
641
-                break;
642
-            case EE_System::req_type_downgrade:
643
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
644
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
645
-                $this->downgrade();
646
-                $this->update_list_of_installed_versions($activation_history_for_addon);
647
-                break;
648
-            case EE_System::req_type_normal:
649
-            default:
650
-                break;
651
-        }
652
-
653
-        do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
654
-    }
655
-
656
-    /**
657
-     * Updates the version history for this addon
658
-     *
659
-     * @param array  $version_history
660
-     * @param string $current_version_to_add
661
-     * @return boolean success
662
-     */
663
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
664
-    {
665
-        if (! $version_history) {
666
-            $version_history = $this->get_activation_history();
667
-        }
668
-        if ($current_version_to_add === null) {
669
-            $current_version_to_add = $this->version();
670
-        }
671
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
672
-        // resave
673
-        return update_option($this->get_activation_history_option_name(), $version_history);
674
-    }
675
-
676
-    /**
677
-     * Gets the name of the wp option that stores the activation history
678
-     * of this addon
679
-     *
680
-     * @return string
681
-     */
682
-    public function get_activation_history_option_name()
683
-    {
684
-        return self::ee_addon_version_history_option_prefix . $this->name();
685
-    }
686
-
687
-
688
-    /**
689
-     * Gets the wp option which stores the activation history for this addon
690
-     *
691
-     * @return array
692
-     */
693
-    public function get_activation_history()
694
-    {
695
-        return get_option($this->get_activation_history_option_name(), null);
696
-    }
697
-
698
-
699
-    /**
700
-     * @param string $config_section
701
-     */
702
-    public function set_config_section($config_section = '')
703
-    {
704
-        $this->_config_section = ! empty($config_section) ? $config_section : 'addons';
705
-    }
706
-
707
-    /**
708
-     * Sets the filepath to the main plugin file
709
-     *
710
-     * @param string $filepath
711
-     */
712
-    public function set_main_plugin_file($filepath)
713
-    {
714
-        $this->_main_plugin_file = $filepath;
715
-    }
716
-
717
-    /**
718
-     * gets the filepath to teh main file
719
-     *
720
-     * @return string
721
-     */
722
-    public function get_main_plugin_file()
723
-    {
724
-        return $this->_main_plugin_file;
725
-    }
726
-
727
-    /**
728
-     * Gets the filename (no path) of the main file (the main file loaded
729
-     * by WP)
730
-     *
731
-     * @return string
732
-     */
733
-    public function get_main_plugin_file_basename()
734
-    {
735
-        return plugin_basename($this->get_main_plugin_file());
736
-    }
737
-
738
-    /**
739
-     * Gets the folder name which contains the main plugin file
740
-     *
741
-     * @return string
742
-     */
743
-    public function get_main_plugin_file_dirname()
744
-    {
745
-        return dirname($this->get_main_plugin_file());
746
-    }
747
-
748
-
749
-    /**
750
-     * sets hooks used in the admin
751
-     *
752
-     * @return void
753
-     */
754
-    public function admin_init()
755
-    {
756
-        // is admin and not in M-Mode ?
757
-        if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
758
-            add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
759
-            add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
760
-        }
761
-    }
762
-
763
-
764
-    /**
765
-     * plugin_actions
766
-     * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
767
-     *
768
-     * @param $links
769
-     * @param $file
770
-     * @return array
771
-     */
772
-    public function plugin_action_links($links, $file)
773
-    {
774
-        if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
775
-            // before other links
776
-            array_unshift(
777
-                $links,
778
-                '<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
779
-                . esc_html__('Settings', 'event_espresso')
780
-                . '</a>'
781
-            );
782
-        }
783
-        return $links;
784
-    }
785
-
786
-
787
-    /**
788
-     * after_plugin_row
789
-     * Add additional content to the plugins page plugin row
790
-     * Inserts another row
791
-     *
792
-     * @param $plugin_file
793
-     * @param $plugin_data
794
-     * @param $status
795
-     * @return void
796
-     */
797
-    public function after_plugin_row($plugin_file, $plugin_data, $status)
798
-    {
799
-        $after_plugin_row = '';
800
-        $plugins_page_row = $this->get_plugins_page_row();
801
-        if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
802
-            $class = $status ? 'active' : 'inactive';
803
-            $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
804
-            $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
805
-            $description = isset($plugins_page_row['description'])
806
-                ? $plugins_page_row['description']
807
-                : '';
808
-            if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
809
-                $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
810
-                $after_plugin_row .= '<th class="check-column" scope="row"></th>';
811
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
812
-                $after_plugin_row .= '<style>
404
+			EEH_Activation::initialize_db_content();
405
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
406
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
407
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
408
+			);
409
+			$rewrite_rules->flushRewriteRules();
410
+			// in case there are lots of addons being activated at once, let's force garbage collection
411
+			// to help avoid memory limit errors
412
+			// EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
413
+			gc_collect_cycles();
414
+		} else {
415
+			// ask the data migration manager to init this addon's data
416
+			// when migrations are finished because we can't do it now
417
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
418
+		}
419
+	}
420
+
421
+
422
+	/**
423
+	 * Used to setup this addon's database tables, but not necessarily any default
424
+	 * data in them. The default is to actually use the most up-to-date data migration script
425
+	 * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
426
+	 * methods to setup the db.
427
+	 */
428
+	public function initialize_db()
429
+	{
430
+		// find the migration script that sets the database to be compatible with the code
431
+		$current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
432
+		if ($current_dms_name) {
433
+			$current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
434
+			$current_data_migration_script->set_migrating(false);
435
+			$current_data_migration_script->schema_changes_before_migration();
436
+			$current_data_migration_script->schema_changes_after_migration();
437
+			if ($current_data_migration_script->get_errors()) {
438
+				foreach ($current_data_migration_script->get_errors() as $error) {
439
+					EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
440
+				}
441
+			}
442
+		}
443
+		// if not DMS was found that should be ok. This addon just doesn't require any database changes
444
+		EE_Data_Migration_Manager::instance()->update_current_database_state_to(
445
+			array(
446
+				'slug'    => $this->name(),
447
+				'version' => $this->version(),
448
+			)
449
+		);
450
+	}
451
+
452
+
453
+	/**
454
+	 * If you want to setup default data for the addon, override this method, and call
455
+	 * parent::initialize_default_data() from within it. This is normally called
456
+	 * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
457
+	 * and should verify default data is present (but this is also called
458
+	 * on reactivations and just after migrations, so please verify you actually want
459
+	 * to ADD default data, because it may already be present).
460
+	 * However, please call this parent (currently it just fires a hook which other
461
+	 * addons may be depending on)
462
+	 */
463
+	public function initialize_default_data()
464
+	{
465
+		/**
466
+		 * Called when an addon is ensuring its default data is set (possibly called
467
+		 * on a reactivation, so first check for the absence of other data before setting
468
+		 * default data)
469
+		 *
470
+		 * @param EE_Addon $addon the addon that called this
471
+		 */
472
+		do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
473
+		// override to insert default data. It is safe to use the models here
474
+		// because the site should not be in maintenance mode
475
+	}
476
+
477
+
478
+	/**
479
+	 * EE Core detected that this addon has been upgraded. We should check if there
480
+	 * are any new migration scripts, and if so put the site into maintenance mode until
481
+	 * they're ran
482
+	 *
483
+	 * @return void
484
+	 */
485
+	public function upgrade()
486
+	{
487
+		$classname = get_class($this);
488
+		do_action("AHEE__{$classname}__upgrade");
489
+		do_action('AHEE__EE_Addon__upgrade', $this);
490
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
491
+		// also it's possible there is new default data that needs to be added
492
+		add_action(
493
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
494
+			array($this, 'initialize_db_if_no_migrations_required')
495
+		);
496
+	}
497
+
498
+
499
+	/**
500
+	 * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
501
+	 */
502
+	public function downgrade()
503
+	{
504
+		$classname = get_class($this);
505
+		do_action("AHEE__{$classname}__downgrade");
506
+		do_action('AHEE__EE_Addon__downgrade', $this);
507
+		// it's possible there's old default data that needs to be double-checked
508
+		add_action(
509
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
510
+			array($this, 'initialize_db_if_no_migrations_required')
511
+		);
512
+	}
513
+
514
+
515
+	/**
516
+	 * set_db_update_option_name
517
+	 * Until we do something better, we'll just check for migration scripts upon
518
+	 * plugin activation only. In the future, we'll want to do it on plugin updates too
519
+	 *
520
+	 * @return bool
521
+	 */
522
+	public function set_db_update_option_name()
523
+	{
524
+		EE_Error::doing_it_wrong(
525
+			__FUNCTION__,
526
+			esc_html__(
527
+				'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
528
+				'event_espresso'
529
+			),
530
+			'4.3.0.alpha.016'
531
+		);
532
+		// let's just handle this on the next request, ok? right now we're just not really ready
533
+		return $this->set_activation_indicator_option();
534
+	}
535
+
536
+
537
+	/**
538
+	 * Returns the name of the activation indicator option
539
+	 * (an option which is set temporarily to indicate that this addon was just activated)
540
+	 *
541
+	 * @deprecated since version 4.3.0.alpha.016
542
+	 * @return string
543
+	 */
544
+	public function get_db_update_option_name()
545
+	{
546
+		EE_Error::doing_it_wrong(
547
+			__FUNCTION__,
548
+			esc_html__(
549
+				'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
550
+				'event_espresso'
551
+			),
552
+			'4.3.0.alpha.016'
553
+		);
554
+		return $this->get_activation_indicator_option_name();
555
+	}
556
+
557
+
558
+	/**
559
+	 * When the addon is activated, this should be called to set a wordpress option that
560
+	 * indicates it was activated. This is especially useful for detecting reactivations.
561
+	 *
562
+	 * @return bool
563
+	 */
564
+	public function set_activation_indicator_option()
565
+	{
566
+		// let's just handle this on the next request, ok? right now we're just not really ready
567
+		return update_option($this->get_activation_indicator_option_name(), true);
568
+	}
569
+
570
+
571
+	/**
572
+	 * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
573
+	 *
574
+	 * @return string
575
+	 */
576
+	public function get_activation_indicator_option_name()
577
+	{
578
+		return 'ee_activation_' . $this->name();
579
+	}
580
+
581
+
582
+	/**
583
+	 * Used by EE_System to set the request type of this addon. Should not be used by addon developers
584
+	 *
585
+	 * @param int $req_type
586
+	 */
587
+	public function set_req_type($req_type)
588
+	{
589
+		$this->_req_type = $req_type;
590
+	}
591
+
592
+
593
+	/**
594
+	 * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
595
+	 * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
596
+	 * EE_System when it is checking for new install or upgrades of addons
597
+	 */
598
+	public function detect_req_type()
599
+	{
600
+		if (! $this->_req_type) {
601
+			$this->detect_activation_or_upgrade();
602
+		}
603
+		return $this->_req_type;
604
+	}
605
+
606
+
607
+	/**
608
+	 * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
609
+	 * Should only be called once per request
610
+	 *
611
+	 * @return void
612
+	 */
613
+	public function detect_activation_or_upgrade()
614
+	{
615
+		$activation_history_for_addon = $this->get_activation_history();
616
+		$request_type = EE_System::detect_req_type_given_activation_history(
617
+			$activation_history_for_addon,
618
+			$this->get_activation_indicator_option_name(),
619
+			$this->version()
620
+		);
621
+		$this->set_req_type($request_type);
622
+		$classname = get_class($this);
623
+		switch ($request_type) {
624
+			case EE_System::req_type_new_activation:
625
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
626
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
627
+				$this->new_install();
628
+				$this->update_list_of_installed_versions($activation_history_for_addon);
629
+				break;
630
+			case EE_System::req_type_reactivation:
631
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
632
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
633
+				$this->reactivation();
634
+				$this->update_list_of_installed_versions($activation_history_for_addon);
635
+				break;
636
+			case EE_System::req_type_upgrade:
637
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
638
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
639
+				$this->upgrade();
640
+				$this->update_list_of_installed_versions($activation_history_for_addon);
641
+				break;
642
+			case EE_System::req_type_downgrade:
643
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
644
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
645
+				$this->downgrade();
646
+				$this->update_list_of_installed_versions($activation_history_for_addon);
647
+				break;
648
+			case EE_System::req_type_normal:
649
+			default:
650
+				break;
651
+		}
652
+
653
+		do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
654
+	}
655
+
656
+	/**
657
+	 * Updates the version history for this addon
658
+	 *
659
+	 * @param array  $version_history
660
+	 * @param string $current_version_to_add
661
+	 * @return boolean success
662
+	 */
663
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
664
+	{
665
+		if (! $version_history) {
666
+			$version_history = $this->get_activation_history();
667
+		}
668
+		if ($current_version_to_add === null) {
669
+			$current_version_to_add = $this->version();
670
+		}
671
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
672
+		// resave
673
+		return update_option($this->get_activation_history_option_name(), $version_history);
674
+	}
675
+
676
+	/**
677
+	 * Gets the name of the wp option that stores the activation history
678
+	 * of this addon
679
+	 *
680
+	 * @return string
681
+	 */
682
+	public function get_activation_history_option_name()
683
+	{
684
+		return self::ee_addon_version_history_option_prefix . $this->name();
685
+	}
686
+
687
+
688
+	/**
689
+	 * Gets the wp option which stores the activation history for this addon
690
+	 *
691
+	 * @return array
692
+	 */
693
+	public function get_activation_history()
694
+	{
695
+		return get_option($this->get_activation_history_option_name(), null);
696
+	}
697
+
698
+
699
+	/**
700
+	 * @param string $config_section
701
+	 */
702
+	public function set_config_section($config_section = '')
703
+	{
704
+		$this->_config_section = ! empty($config_section) ? $config_section : 'addons';
705
+	}
706
+
707
+	/**
708
+	 * Sets the filepath to the main plugin file
709
+	 *
710
+	 * @param string $filepath
711
+	 */
712
+	public function set_main_plugin_file($filepath)
713
+	{
714
+		$this->_main_plugin_file = $filepath;
715
+	}
716
+
717
+	/**
718
+	 * gets the filepath to teh main file
719
+	 *
720
+	 * @return string
721
+	 */
722
+	public function get_main_plugin_file()
723
+	{
724
+		return $this->_main_plugin_file;
725
+	}
726
+
727
+	/**
728
+	 * Gets the filename (no path) of the main file (the main file loaded
729
+	 * by WP)
730
+	 *
731
+	 * @return string
732
+	 */
733
+	public function get_main_plugin_file_basename()
734
+	{
735
+		return plugin_basename($this->get_main_plugin_file());
736
+	}
737
+
738
+	/**
739
+	 * Gets the folder name which contains the main plugin file
740
+	 *
741
+	 * @return string
742
+	 */
743
+	public function get_main_plugin_file_dirname()
744
+	{
745
+		return dirname($this->get_main_plugin_file());
746
+	}
747
+
748
+
749
+	/**
750
+	 * sets hooks used in the admin
751
+	 *
752
+	 * @return void
753
+	 */
754
+	public function admin_init()
755
+	{
756
+		// is admin and not in M-Mode ?
757
+		if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
758
+			add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
759
+			add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
760
+		}
761
+	}
762
+
763
+
764
+	/**
765
+	 * plugin_actions
766
+	 * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
767
+	 *
768
+	 * @param $links
769
+	 * @param $file
770
+	 * @return array
771
+	 */
772
+	public function plugin_action_links($links, $file)
773
+	{
774
+		if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
775
+			// before other links
776
+			array_unshift(
777
+				$links,
778
+				'<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
779
+				. esc_html__('Settings', 'event_espresso')
780
+				. '</a>'
781
+			);
782
+		}
783
+		return $links;
784
+	}
785
+
786
+
787
+	/**
788
+	 * after_plugin_row
789
+	 * Add additional content to the plugins page plugin row
790
+	 * Inserts another row
791
+	 *
792
+	 * @param $plugin_file
793
+	 * @param $plugin_data
794
+	 * @param $status
795
+	 * @return void
796
+	 */
797
+	public function after_plugin_row($plugin_file, $plugin_data, $status)
798
+	{
799
+		$after_plugin_row = '';
800
+		$plugins_page_row = $this->get_plugins_page_row();
801
+		if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
802
+			$class = $status ? 'active' : 'inactive';
803
+			$link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
804
+			$link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
805
+			$description = isset($plugins_page_row['description'])
806
+				? $plugins_page_row['description']
807
+				: '';
808
+			if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
809
+				$after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
810
+				$after_plugin_row .= '<th class="check-column" scope="row"></th>';
811
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
812
+				$after_plugin_row .= '<style>
813 813
 .ee-button,
814 814
 .ee-button:active,
815 815
 .ee-button:visited {
@@ -846,64 +846,64 @@  discard block
 block discarded – undo
846 846
 }
847 847
 .ee-button:active { top:0; }
848 848
 </style>';
849
-                $after_plugin_row .= '
849
+				$after_plugin_row .= '
850 850
 <p class="ee-addon-upsell-info-dv">
851 851
 	<a class="ee-button" href="' . $link_url . '">'
852
-                                     . $link_text
853
-                                     . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
854
-                                     . '</a>
852
+									 . $link_text
853
+									 . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
854
+									 . '</a>
855 855
 </p>';
856
-                $after_plugin_row .= '</td>';
857
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
858
-                $after_plugin_row .= $description;
859
-                $after_plugin_row .= '</td>';
860
-                $after_plugin_row .= '</tr>';
861
-            } else {
862
-                $after_plugin_row .= $description;
863
-            }
864
-        }
865
-
866
-        echo $after_plugin_row;
867
-    }
868
-
869
-
870
-    /**
871
-     * A safe space for addons to add additional logic like setting hooks that need to be set early in the request.
872
-     * Child classes that have logic like that to run can override this method declaration.  This was not made abstract
873
-     * for back compat reasons.
874
-     *
875
-     * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999.
876
-     *
877
-     * It is recommended, if client code is `de-registering` an add-on, then do it on the
878
-     * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this
879
-     * callback does not get run/set in that request.
880
-     *
881
-     * Also, keep in mind that if a registered add-on happens to be deactivated via
882
-     * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method
883
-     * (including setting hooks etc) will have executed before the plugin was deactivated.  If you use
884
-     * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's
885
-     * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there.  Just remember
886
-     * to call `parent::deactivation`.
887
-     *
888
-     * @since 4.9.26
889
-     */
890
-    public function after_registration()
891
-    {
892
-        // cricket chirp... cricket chirp...
893
-    }
894
-
895
-    /**
896
-     * @return string
897
-     */
898
-    public function getPueSlug()
899
-    {
900
-        return $this->pue_slug;
901
-    }
902
-    /**
903
-     * @param string $pue_slug
904
-     */
905
-    public function setPueSlug($pue_slug)
906
-    {
907
-        $this->pue_slug = $pue_slug;
908
-    }
856
+				$after_plugin_row .= '</td>';
857
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
858
+				$after_plugin_row .= $description;
859
+				$after_plugin_row .= '</td>';
860
+				$after_plugin_row .= '</tr>';
861
+			} else {
862
+				$after_plugin_row .= $description;
863
+			}
864
+		}
865
+
866
+		echo $after_plugin_row;
867
+	}
868
+
869
+
870
+	/**
871
+	 * A safe space for addons to add additional logic like setting hooks that need to be set early in the request.
872
+	 * Child classes that have logic like that to run can override this method declaration.  This was not made abstract
873
+	 * for back compat reasons.
874
+	 *
875
+	 * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999.
876
+	 *
877
+	 * It is recommended, if client code is `de-registering` an add-on, then do it on the
878
+	 * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this
879
+	 * callback does not get run/set in that request.
880
+	 *
881
+	 * Also, keep in mind that if a registered add-on happens to be deactivated via
882
+	 * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method
883
+	 * (including setting hooks etc) will have executed before the plugin was deactivated.  If you use
884
+	 * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's
885
+	 * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there.  Just remember
886
+	 * to call `parent::deactivation`.
887
+	 *
888
+	 * @since 4.9.26
889
+	 */
890
+	public function after_registration()
891
+	{
892
+		// cricket chirp... cricket chirp...
893
+	}
894
+
895
+	/**
896
+	 * @return string
897
+	 */
898
+	public function getPueSlug()
899
+	{
900
+		return $this->pue_slug;
901
+	}
902
+	/**
903
+	 * @param string $pue_slug
904
+	 */
905
+	public function setPueSlug($pue_slug)
906
+	{
907
+		$this->pue_slug = $pue_slug;
908
+	}
909 909
 }
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/RegistrationsReport.php 1 patch
Indentation   +516 added lines, -516 removed lines patch added patch discarded remove patch
@@ -31,536 +31,536 @@
 block discarded – undo
31 31
  */
32 32
 class RegistrationsReport extends JobHandlerFile
33 33
 {
34
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
35
-    // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
36
-    /**
37
-     * Performs any necessary setup for starting the job. This is also a good
38
-     * place to setup the $job_arguments which will be used for subsequent HTTP requests
39
-     * when continue_job will be called
40
-     *
41
-     * @param JobParameters $job_parameters
42
-     * @throws BatchRequestException
43
-     * @return JobStepResponse
44
-     */
45
-    public function create_job(JobParameters $job_parameters)
46
-    {
47
-        $event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
48
-        if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
49
-            throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
50
-        }
51
-        $filepath = $this->create_file_from_job_with_name(
52
-            $job_parameters->job_id(),
53
-            $this->get_filename($event_id)
54
-        );
55
-        $job_parameters->add_extra_data('filepath', $filepath);
56
-        if ($job_parameters->request_datum('use_filters', false)) {
57
-            $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
58
-        } else {
59
-            $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
60
-                array(
61
-                    'OR'                 => array(
62
-                        // don't include registrations from failed or abandoned transactions...
63
-                        'Transaction.STS_ID' => array(
64
-                            'NOT IN',
65
-                            array(
66
-                                EEM_Transaction::failed_status_code,
67
-                                EEM_Transaction::abandoned_status_code,
68
-                            ),
69
-                        ),
70
-                        // unless the registration is approved, in which case include it regardless of transaction status
71
-                        'STS_ID'             => \EEM_Registration::status_id_approved,
72
-                    ),
73
-                    'Ticket.TKT_deleted' => array('IN', array(true, false)),
74
-                ),
75
-                'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
76
-                'force_join' => array('Transaction', 'Ticket', 'Attendee'),
77
-                'caps'       => \EEM_Base::caps_read_admin,
78
-            ), $event_id);
79
-            if ($event_id) {
80
-                $query_params[0]['EVT_ID'] = $event_id;
81
-            } else {
82
-                $query_params['force_join'][] = 'Event';
83
-            }
84
-        }
85
-        if (! isset($query_params['force_join'])) {
86
-            $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
87
-        }
88
-        $job_parameters->add_extra_data('query_params', $query_params);
89
-        $question_labels = $this->_get_question_labels($query_params);
90
-        $job_parameters->add_extra_data('question_labels', $question_labels);
91
-        $job_parameters->set_job_size(
92
-            \EEM_Registration::instance()->count(
93
-                array_diff_key(
94
-                    $query_params,
95
-                    array_flip(
96
-                        array('limit')
97
-                    )
98
-                )
99
-            )
100
-        );
101
-        // we should also set the header columns
102
-        $csv_data_for_row = $this->get_csv_data_for(
103
-            $event_id,
104
-            0,
105
-            1,
106
-            $job_parameters->extra_datum('question_labels'),
107
-            $job_parameters->extra_datum('query_params')
108
-        );
109
-        EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
110
-        // if we actually processed a row there, record it
111
-        if ($job_parameters->job_size()) {
112
-            $job_parameters->mark_processed(1);
113
-        }
114
-        return new JobStepResponse(
115
-            $job_parameters,
116
-            __('Registrations report started successfully...', 'event_espresso')
117
-        );
118
-    }
34
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
35
+	// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
36
+	/**
37
+	 * Performs any necessary setup for starting the job. This is also a good
38
+	 * place to setup the $job_arguments which will be used for subsequent HTTP requests
39
+	 * when continue_job will be called
40
+	 *
41
+	 * @param JobParameters $job_parameters
42
+	 * @throws BatchRequestException
43
+	 * @return JobStepResponse
44
+	 */
45
+	public function create_job(JobParameters $job_parameters)
46
+	{
47
+		$event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
48
+		if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
49
+			throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
50
+		}
51
+		$filepath = $this->create_file_from_job_with_name(
52
+			$job_parameters->job_id(),
53
+			$this->get_filename($event_id)
54
+		);
55
+		$job_parameters->add_extra_data('filepath', $filepath);
56
+		if ($job_parameters->request_datum('use_filters', false)) {
57
+			$query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
58
+		} else {
59
+			$query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
60
+				array(
61
+					'OR'                 => array(
62
+						// don't include registrations from failed or abandoned transactions...
63
+						'Transaction.STS_ID' => array(
64
+							'NOT IN',
65
+							array(
66
+								EEM_Transaction::failed_status_code,
67
+								EEM_Transaction::abandoned_status_code,
68
+							),
69
+						),
70
+						// unless the registration is approved, in which case include it regardless of transaction status
71
+						'STS_ID'             => \EEM_Registration::status_id_approved,
72
+					),
73
+					'Ticket.TKT_deleted' => array('IN', array(true, false)),
74
+				),
75
+				'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
76
+				'force_join' => array('Transaction', 'Ticket', 'Attendee'),
77
+				'caps'       => \EEM_Base::caps_read_admin,
78
+			), $event_id);
79
+			if ($event_id) {
80
+				$query_params[0]['EVT_ID'] = $event_id;
81
+			} else {
82
+				$query_params['force_join'][] = 'Event';
83
+			}
84
+		}
85
+		if (! isset($query_params['force_join'])) {
86
+			$query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
87
+		}
88
+		$job_parameters->add_extra_data('query_params', $query_params);
89
+		$question_labels = $this->_get_question_labels($query_params);
90
+		$job_parameters->add_extra_data('question_labels', $question_labels);
91
+		$job_parameters->set_job_size(
92
+			\EEM_Registration::instance()->count(
93
+				array_diff_key(
94
+					$query_params,
95
+					array_flip(
96
+						array('limit')
97
+					)
98
+				)
99
+			)
100
+		);
101
+		// we should also set the header columns
102
+		$csv_data_for_row = $this->get_csv_data_for(
103
+			$event_id,
104
+			0,
105
+			1,
106
+			$job_parameters->extra_datum('question_labels'),
107
+			$job_parameters->extra_datum('query_params')
108
+		);
109
+		EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
110
+		// if we actually processed a row there, record it
111
+		if ($job_parameters->job_size()) {
112
+			$job_parameters->mark_processed(1);
113
+		}
114
+		return new JobStepResponse(
115
+			$job_parameters,
116
+			__('Registrations report started successfully...', 'event_espresso')
117
+		);
118
+	}
119 119
 
120 120
 
121
-    /**
122
-     * Gets the filename
123
-     *
124
-     * @return string
125
-     */
126
-    protected function get_filename()
127
-    {
128
-        return apply_filters(
129
-            'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename',
130
-            sprintf(
131
-                "event-espresso-registrations-%s.csv",
132
-                str_replace(array(':', ' '), '-', current_time('mysql'))
133
-            )
134
-        );
135
-    }
121
+	/**
122
+	 * Gets the filename
123
+	 *
124
+	 * @return string
125
+	 */
126
+	protected function get_filename()
127
+	{
128
+		return apply_filters(
129
+			'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename',
130
+			sprintf(
131
+				"event-espresso-registrations-%s.csv",
132
+				str_replace(array(':', ' '), '-', current_time('mysql'))
133
+			)
134
+		);
135
+	}
136 136
 
137 137
 
138
-    /**
139
-     * Gets the questions which are to be used for this report, so they
140
-     * can be remembered for later
141
-     *
142
-     * @param array $registration_query_params
143
-     * @return array question admin labels to be used for this report
144
-     */
145
-    protected function _get_question_labels($registration_query_params)
146
-    {
147
-        $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
148
-        $question_query_params = array();
149
-        if ($where !== null) {
150
-            $question_query_params = array(
151
-                $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
152
-            );
153
-        }
154
-        // Make sure it's not a system question
155
-        $question_query_params[0]['OR*not-system-questions'] = [
156
-            'QST_system' => '',
157
-            'QST_system*null' => ['IS_NULL']
158
-        ];
159
-        if (apply_filters(
160
-            'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
161
-            false,
162
-            $registration_query_params
163
-        )) {
164
-            $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
165
-        }
166
-        $question_query_params['group_by'] = array('QST_ID');
167
-        return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
168
-    }
138
+	/**
139
+	 * Gets the questions which are to be used for this report, so they
140
+	 * can be remembered for later
141
+	 *
142
+	 * @param array $registration_query_params
143
+	 * @return array question admin labels to be used for this report
144
+	 */
145
+	protected function _get_question_labels($registration_query_params)
146
+	{
147
+		$where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
148
+		$question_query_params = array();
149
+		if ($where !== null) {
150
+			$question_query_params = array(
151
+				$this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
152
+			);
153
+		}
154
+		// Make sure it's not a system question
155
+		$question_query_params[0]['OR*not-system-questions'] = [
156
+			'QST_system' => '',
157
+			'QST_system*null' => ['IS_NULL']
158
+		];
159
+		if (apply_filters(
160
+			'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
161
+			false,
162
+			$registration_query_params
163
+		)) {
164
+			$question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
165
+		}
166
+		$question_query_params['group_by'] = array('QST_ID');
167
+		return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
168
+	}
169 169
 
170 170
 
171
-    /**
172
-     * Takes where params meant for registrations and changes them to work for questions
173
-     *
174
-     * @param array $reg_where_params
175
-     * @return array
176
-     */
177
-    protected function _change_registration_where_params_to_question_where_params($reg_where_params)
178
-    {
179
-        $question_where_params = array();
180
-        foreach ($reg_where_params as $key => $val) {
181
-            if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
182
-                $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
183
-            } else {
184
-                // it's a normal where condition
185
-                $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
186
-            }
187
-        }
188
-        return $question_where_params;
189
-    }
171
+	/**
172
+	 * Takes where params meant for registrations and changes them to work for questions
173
+	 *
174
+	 * @param array $reg_where_params
175
+	 * @return array
176
+	 */
177
+	protected function _change_registration_where_params_to_question_where_params($reg_where_params)
178
+	{
179
+		$question_where_params = array();
180
+		foreach ($reg_where_params as $key => $val) {
181
+			if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
182
+				$question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
183
+			} else {
184
+				// it's a normal where condition
185
+				$question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
186
+			}
187
+		}
188
+		return $question_where_params;
189
+	}
190 190
 
191 191
 
192
-    /**
193
-     * Performs another step of the job
194
-     *
195
-     * @param JobParameters $job_parameters
196
-     * @param int           $batch_size
197
-     * @return JobStepResponse
198
-     * @throws \EE_Error
199
-     */
200
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
201
-    {
202
-        if ($job_parameters->units_processed() < $job_parameters->job_size()) {
203
-            $csv_data = $this->get_csv_data_for(
204
-                $job_parameters->request_datum('EVT_ID', '0'),
205
-                $job_parameters->units_processed(),
206
-                $batch_size,
207
-                $job_parameters->extra_datum('question_labels'),
208
-                $job_parameters->extra_datum('query_params')
209
-            );
210
-            EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
211
-            $units_processed = count($csv_data);
212
-        } else {
213
-            $csv_data = array();
214
-            $units_processed = 0;
215
-        }
216
-        $job_parameters->mark_processed($units_processed);
217
-        $extra_response_data = array(
218
-            'file_url' => '',
219
-        );
220
-        if ($units_processed < $batch_size) {
221
-            $job_parameters->set_status(JobParameters::status_complete);
222
-            $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
223
-        }
192
+	/**
193
+	 * Performs another step of the job
194
+	 *
195
+	 * @param JobParameters $job_parameters
196
+	 * @param int           $batch_size
197
+	 * @return JobStepResponse
198
+	 * @throws \EE_Error
199
+	 */
200
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
201
+	{
202
+		if ($job_parameters->units_processed() < $job_parameters->job_size()) {
203
+			$csv_data = $this->get_csv_data_for(
204
+				$job_parameters->request_datum('EVT_ID', '0'),
205
+				$job_parameters->units_processed(),
206
+				$batch_size,
207
+				$job_parameters->extra_datum('question_labels'),
208
+				$job_parameters->extra_datum('query_params')
209
+			);
210
+			EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
211
+			$units_processed = count($csv_data);
212
+		} else {
213
+			$csv_data = array();
214
+			$units_processed = 0;
215
+		}
216
+		$job_parameters->mark_processed($units_processed);
217
+		$extra_response_data = array(
218
+			'file_url' => '',
219
+		);
220
+		if ($units_processed < $batch_size) {
221
+			$job_parameters->set_status(JobParameters::status_complete);
222
+			$extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
223
+		}
224 224
 
225
-        return new JobStepResponse(
226
-            $job_parameters,
227
-            sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)),
228
-            $extra_response_data
229
-        );
230
-    }
225
+		return new JobStepResponse(
226
+			$job_parameters,
227
+			sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)),
228
+			$extra_response_data
229
+		);
230
+	}
231 231
 
232 232
 
233
-    /**
234
-     * Gets the csv data for a batch of registrations
235
-     *
236
-     * @param int|null $event_id
237
-     * @param int $offset
238
-     * @param int $limit
239
-     * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
240
-     * @param array $query_params for using where querying the model
241
-     * @return array top-level keys are numeric, next-level keys are column headers
242
-     * @throws \EE_Error
243
-     */
244
-    public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
245
-    {
246
-        $reg_fields_to_include = array(
247
-            'TXN_ID',
248
-            'ATT_ID',
249
-            'REG_ID',
250
-            'REG_date',
251
-            'REG_code',
252
-            'REG_count',
253
-            'REG_final_price',
254
-        );
255
-        $att_fields_to_include = array(
256
-            'ATT_fname',
257
-            'ATT_lname',
258
-            'ATT_email',
259
-            'ATT_address',
260
-            'ATT_address2',
261
-            'ATT_city',
262
-            'STA_ID',
263
-            'CNT_ISO',
264
-            'ATT_zip',
265
-            'ATT_phone',
266
-        );
267
-        $registrations_csv_ready_array = array();
268
-        $reg_model = EE_Registry::instance()->load_model('Registration');
269
-        $query_params['limit'] = array($offset, $limit);
270
-        $registration_rows = $reg_model->get_all_wpdb_results($query_params);
271
-        $registration_ids = array();
272
-        foreach ($registration_rows as $reg_row) {
273
-            $registration_ids[] = intval($reg_row['Registration.REG_ID']);
274
-        }
275
-        foreach ($registration_rows as $reg_row) {
276
-            if (is_array($reg_row)) {
277
-                $reg_csv_array = array();
278
-                if (! $event_id) {
279
-                    // get the event's name and Id
280
-                    $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf(
281
-                        /* translators: 1: event name, 2: event ID */
282
-                        __('%1$s (%2$s)', 'event_espresso'),
283
-                        EEH_Export::prepare_value_from_db_for_display(
284
-                            EEM_Event::instance(),
285
-                            'EVT_name',
286
-                            $reg_row['Event_CPT.post_title']
287
-                        ),
288
-                        $reg_row['Event_CPT.ID']
289
-                    );
290
-                }
291
-                $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
292
-                /*@var $reg_row EE_Registration */
293
-                foreach ($reg_fields_to_include as $field_name) {
294
-                    $field = $reg_model->field_settings_for($field_name);
295
-                    if ($field_name == 'REG_final_price') {
296
-                        $value = EEH_Export::prepare_value_from_db_for_display(
297
-                            $reg_model,
298
-                            $field_name,
299
-                            $reg_row['Registration.REG_final_price'],
300
-                            'localized_float'
301
-                        );
302
-                    } elseif ($field_name == 'REG_count') {
303
-                        $value = sprintf(
304
-                            /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
305
-                            __('%1$s of %2$s', 'event_espresso'),
306
-                            EEH_Export::prepare_value_from_db_for_display(
307
-                                $reg_model,
308
-                                'REG_count',
309
-                                $reg_row['Registration.REG_count']
310
-                            ),
311
-                            EEH_Export::prepare_value_from_db_for_display(
312
-                                $reg_model,
313
-                                'REG_group_size',
314
-                                $reg_row['Registration.REG_group_size']
315
-                            )
316
-                        );
317
-                    } elseif ($field_name == 'REG_date') {
318
-                        $value = EEH_Export::prepare_value_from_db_for_display(
319
-                            $reg_model,
320
-                            $field_name,
321
-                            $reg_row['Registration.REG_date'],
322
-                            'no_html'
323
-                        );
324
-                    } else {
325
-                        $value = EEH_Export::prepare_value_from_db_for_display(
326
-                            $reg_model,
327
-                            $field_name,
328
-                            $reg_row[ $field->get_qualified_column() ]
329
-                        );
330
-                    }
331
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
332
-                    if ($field_name == 'REG_final_price') {
333
-                        // add a column named Currency after the final price
334
-                        $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
335
-                    }
336
-                }
337
-                // get pretty status
338
-                $stati = EEM_Status::instance()->localized_status(
339
-                    array(
340
-                        $reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
341
-                        $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
342
-                    ),
343
-                    false,
344
-                    'sentence'
345
-                );
346
-                $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
347
-                // get pretty transaction status
348
-                $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
349
-                $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
350
-                    ? EEH_Export::prepare_value_from_db_for_display(
351
-                        EEM_Transaction::instance(),
352
-                        'TXN_total',
353
-                        $reg_row['TransactionTable.TXN_total'],
354
-                        'localized_float'
355
-                    ) : '0.00';
356
-                $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg
357
-                    ? EEH_Export::prepare_value_from_db_for_display(
358
-                        EEM_Transaction::instance(),
359
-                        'TXN_paid',
360
-                        $reg_row['TransactionTable.TXN_paid'],
361
-                        'localized_float'
362
-                    ) : '0.00';
363
-                $payment_methods = array();
364
-                $gateway_txn_ids_etc = array();
365
-                $payment_times = array();
366
-                if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
367
-                    $payments_info = EEM_Payment::instance()->get_all_wpdb_results(
368
-                        array(
369
-                            array(
370
-                                'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
371
-                                'STS_ID' => EEM_Payment::status_id_approved,
372
-                            ),
373
-                            'force_join' => array('Payment_Method'),
374
-                        ),
375
-                        ARRAY_A,
376
-                        'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
377
-                    );
378
-                    foreach ($payments_info as $payment_method_and_gateway_txn_id) {
379
-                        $payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
380
-                            ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
381
-                        $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
382
-                            ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
383
-                        $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
384
-                            ? $payment_method_and_gateway_txn_id['payment_time'] : '';
385
-                    }
386
-                }
387
-                $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
388
-                $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
389
-                $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
390
-                    ',',
391
-                    $gateway_txn_ids_etc
392
-                );
393
-                // get whether or not the user has checked in
394
-                $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
395
-                    $reg_row['Registration.REG_ID'],
396
-                    'Checkin'
397
-                );
398
-                // get ticket of registration and its price
399
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
400
-                if ($reg_row['Ticket.TKT_ID']) {
401
-                    $ticket_name = EEH_Export::prepare_value_from_db_for_display(
402
-                        $ticket_model,
403
-                        'TKT_name',
404
-                        $reg_row['Ticket.TKT_name']
405
-                    );
406
-                    $datetimes_strings = array();
407
-                    foreach (EEM_Datetime::instance()->get_all_wpdb_results(
408
-                        array(
409
-                            array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
410
-                            'order_by'                 => array('DTT_EVT_start' => 'ASC'),
411
-                            'default_where_conditions' => 'none',
412
-                        )
413
-                    ) as $datetime) {
414
-                        $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display(
415
-                            EEM_Datetime::instance(),
416
-                            'DTT_EVT_start',
417
-                            $datetime['Datetime.DTT_EVT_start']
418
-                        );
419
-                    }
420
-                } else {
421
-                    $ticket_name = __('Unknown', 'event_espresso');
422
-                    $datetimes_strings = array(__('Unknown', 'event_espresso'));
423
-                }
424
-                $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
425
-                $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
426
-                // get datetime(s) of registration
427
-                // add attendee columns
428
-                foreach ($att_fields_to_include as $att_field_name) {
429
-                    $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
430
-                    if ($reg_row['Attendee_CPT.ID']) {
431
-                        if ($att_field_name == 'STA_ID') {
432
-                            $value = EEM_State::instance()->get_var(
433
-                                array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
434
-                                'STA_name'
435
-                            );
436
-                        } elseif ($att_field_name == 'CNT_ISO') {
437
-                            $value = EEM_Country::instance()->get_var(
438
-                                array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
439
-                                'CNT_name'
440
-                            );
441
-                        } else {
442
-                            $value = EEH_Export::prepare_value_from_db_for_display(
443
-                                EEM_Attendee::instance(),
444
-                                $att_field_name,
445
-                                $reg_row[ $field_obj->get_qualified_column() ]
446
-                            );
447
-                        }
448
-                    } else {
449
-                        $value = '';
450
-                    }
451
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
452
-                }
453
-                // make sure each registration has the same questions in the same order
454
-                foreach ($question_labels as $question_label) {
455
-                    if (! isset($reg_csv_array[ $question_label ])) {
456
-                        $reg_csv_array[ $question_label ] = null;
457
-                    }
458
-                }
459
-                $answers = EEM_Answer::instance()->get_all_wpdb_results(array(
460
-                    array('REG_ID' => $reg_row['Registration.REG_ID']),
461
-                    'force_join' => array('Question'),
462
-                ));
463
-                // now fill out the questions THEY answered
464
-                foreach ($answers as $answer_row) {
465
-                    if ($answer_row['Question.QST_system']) {
466
-                        // it's an answer to a system question. That was already displayed as part of the attendee
467
-                        // fields, so don't write it out again thanks.
468
-                        continue;
469
-                    }
470
-                    if ($answer_row['Question.QST_ID']) {
471
-                        $question_label = EEH_Export::prepare_value_from_db_for_display(
472
-                            EEM_Question::instance(),
473
-                            'QST_admin_label',
474
-                            $answer_row['Question.QST_admin_label']
475
-                        );
476
-                    } else {
477
-                        $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
478
-                    }
479
-                    if (isset($answer_row['Question.QST_type'])
480
-                        && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
481
-                    ) {
482
-                        $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
483
-                            $answer_row['Answer.ANS_value']
484
-                        );
485
-                    } else {
486
-                        // this isn't for html, so don't show html entities
487
-                        $reg_csv_array[ $question_label ] = html_entity_decode(
488
-                            EEH_Export::prepare_value_from_db_for_display(
489
-                                EEM_Answer::instance(),
490
-                                'ANS_value',
491
-                                $answer_row['Answer.ANS_value']
492
-                            )
493
-                        );
494
-                    }
495
-                }
233
+	/**
234
+	 * Gets the csv data for a batch of registrations
235
+	 *
236
+	 * @param int|null $event_id
237
+	 * @param int $offset
238
+	 * @param int $limit
239
+	 * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
240
+	 * @param array $query_params for using where querying the model
241
+	 * @return array top-level keys are numeric, next-level keys are column headers
242
+	 * @throws \EE_Error
243
+	 */
244
+	public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
245
+	{
246
+		$reg_fields_to_include = array(
247
+			'TXN_ID',
248
+			'ATT_ID',
249
+			'REG_ID',
250
+			'REG_date',
251
+			'REG_code',
252
+			'REG_count',
253
+			'REG_final_price',
254
+		);
255
+		$att_fields_to_include = array(
256
+			'ATT_fname',
257
+			'ATT_lname',
258
+			'ATT_email',
259
+			'ATT_address',
260
+			'ATT_address2',
261
+			'ATT_city',
262
+			'STA_ID',
263
+			'CNT_ISO',
264
+			'ATT_zip',
265
+			'ATT_phone',
266
+		);
267
+		$registrations_csv_ready_array = array();
268
+		$reg_model = EE_Registry::instance()->load_model('Registration');
269
+		$query_params['limit'] = array($offset, $limit);
270
+		$registration_rows = $reg_model->get_all_wpdb_results($query_params);
271
+		$registration_ids = array();
272
+		foreach ($registration_rows as $reg_row) {
273
+			$registration_ids[] = intval($reg_row['Registration.REG_ID']);
274
+		}
275
+		foreach ($registration_rows as $reg_row) {
276
+			if (is_array($reg_row)) {
277
+				$reg_csv_array = array();
278
+				if (! $event_id) {
279
+					// get the event's name and Id
280
+					$reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf(
281
+						/* translators: 1: event name, 2: event ID */
282
+						__('%1$s (%2$s)', 'event_espresso'),
283
+						EEH_Export::prepare_value_from_db_for_display(
284
+							EEM_Event::instance(),
285
+							'EVT_name',
286
+							$reg_row['Event_CPT.post_title']
287
+						),
288
+						$reg_row['Event_CPT.ID']
289
+					);
290
+				}
291
+				$is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
292
+				/*@var $reg_row EE_Registration */
293
+				foreach ($reg_fields_to_include as $field_name) {
294
+					$field = $reg_model->field_settings_for($field_name);
295
+					if ($field_name == 'REG_final_price') {
296
+						$value = EEH_Export::prepare_value_from_db_for_display(
297
+							$reg_model,
298
+							$field_name,
299
+							$reg_row['Registration.REG_final_price'],
300
+							'localized_float'
301
+						);
302
+					} elseif ($field_name == 'REG_count') {
303
+						$value = sprintf(
304
+							/* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
305
+							__('%1$s of %2$s', 'event_espresso'),
306
+							EEH_Export::prepare_value_from_db_for_display(
307
+								$reg_model,
308
+								'REG_count',
309
+								$reg_row['Registration.REG_count']
310
+							),
311
+							EEH_Export::prepare_value_from_db_for_display(
312
+								$reg_model,
313
+								'REG_group_size',
314
+								$reg_row['Registration.REG_group_size']
315
+							)
316
+						);
317
+					} elseif ($field_name == 'REG_date') {
318
+						$value = EEH_Export::prepare_value_from_db_for_display(
319
+							$reg_model,
320
+							$field_name,
321
+							$reg_row['Registration.REG_date'],
322
+							'no_html'
323
+						);
324
+					} else {
325
+						$value = EEH_Export::prepare_value_from_db_for_display(
326
+							$reg_model,
327
+							$field_name,
328
+							$reg_row[ $field->get_qualified_column() ]
329
+						);
330
+					}
331
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
332
+					if ($field_name == 'REG_final_price') {
333
+						// add a column named Currency after the final price
334
+						$reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
335
+					}
336
+				}
337
+				// get pretty status
338
+				$stati = EEM_Status::instance()->localized_status(
339
+					array(
340
+						$reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
341
+						$reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
342
+					),
343
+					false,
344
+					'sentence'
345
+				);
346
+				$reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
347
+				// get pretty transaction status
348
+				$reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
349
+				$reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
350
+					? EEH_Export::prepare_value_from_db_for_display(
351
+						EEM_Transaction::instance(),
352
+						'TXN_total',
353
+						$reg_row['TransactionTable.TXN_total'],
354
+						'localized_float'
355
+					) : '0.00';
356
+				$reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg
357
+					? EEH_Export::prepare_value_from_db_for_display(
358
+						EEM_Transaction::instance(),
359
+						'TXN_paid',
360
+						$reg_row['TransactionTable.TXN_paid'],
361
+						'localized_float'
362
+					) : '0.00';
363
+				$payment_methods = array();
364
+				$gateway_txn_ids_etc = array();
365
+				$payment_times = array();
366
+				if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
367
+					$payments_info = EEM_Payment::instance()->get_all_wpdb_results(
368
+						array(
369
+							array(
370
+								'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
371
+								'STS_ID' => EEM_Payment::status_id_approved,
372
+							),
373
+							'force_join' => array('Payment_Method'),
374
+						),
375
+						ARRAY_A,
376
+						'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
377
+					);
378
+					foreach ($payments_info as $payment_method_and_gateway_txn_id) {
379
+						$payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
380
+							? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
381
+						$gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
382
+							? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
383
+						$payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
384
+							? $payment_method_and_gateway_txn_id['payment_time'] : '';
385
+					}
386
+				}
387
+				$reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
388
+				$reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
389
+				$reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
390
+					',',
391
+					$gateway_txn_ids_etc
392
+				);
393
+				// get whether or not the user has checked in
394
+				$reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
395
+					$reg_row['Registration.REG_ID'],
396
+					'Checkin'
397
+				);
398
+				// get ticket of registration and its price
399
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
400
+				if ($reg_row['Ticket.TKT_ID']) {
401
+					$ticket_name = EEH_Export::prepare_value_from_db_for_display(
402
+						$ticket_model,
403
+						'TKT_name',
404
+						$reg_row['Ticket.TKT_name']
405
+					);
406
+					$datetimes_strings = array();
407
+					foreach (EEM_Datetime::instance()->get_all_wpdb_results(
408
+						array(
409
+							array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
410
+							'order_by'                 => array('DTT_EVT_start' => 'ASC'),
411
+							'default_where_conditions' => 'none',
412
+						)
413
+					) as $datetime) {
414
+						$datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display(
415
+							EEM_Datetime::instance(),
416
+							'DTT_EVT_start',
417
+							$datetime['Datetime.DTT_EVT_start']
418
+						);
419
+					}
420
+				} else {
421
+					$ticket_name = __('Unknown', 'event_espresso');
422
+					$datetimes_strings = array(__('Unknown', 'event_espresso'));
423
+				}
424
+				$reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
425
+				$reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
426
+				// get datetime(s) of registration
427
+				// add attendee columns
428
+				foreach ($att_fields_to_include as $att_field_name) {
429
+					$field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
430
+					if ($reg_row['Attendee_CPT.ID']) {
431
+						if ($att_field_name == 'STA_ID') {
432
+							$value = EEM_State::instance()->get_var(
433
+								array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
434
+								'STA_name'
435
+							);
436
+						} elseif ($att_field_name == 'CNT_ISO') {
437
+							$value = EEM_Country::instance()->get_var(
438
+								array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
439
+								'CNT_name'
440
+							);
441
+						} else {
442
+							$value = EEH_Export::prepare_value_from_db_for_display(
443
+								EEM_Attendee::instance(),
444
+								$att_field_name,
445
+								$reg_row[ $field_obj->get_qualified_column() ]
446
+							);
447
+						}
448
+					} else {
449
+						$value = '';
450
+					}
451
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
452
+				}
453
+				// make sure each registration has the same questions in the same order
454
+				foreach ($question_labels as $question_label) {
455
+					if (! isset($reg_csv_array[ $question_label ])) {
456
+						$reg_csv_array[ $question_label ] = null;
457
+					}
458
+				}
459
+				$answers = EEM_Answer::instance()->get_all_wpdb_results(array(
460
+					array('REG_ID' => $reg_row['Registration.REG_ID']),
461
+					'force_join' => array('Question'),
462
+				));
463
+				// now fill out the questions THEY answered
464
+				foreach ($answers as $answer_row) {
465
+					if ($answer_row['Question.QST_system']) {
466
+						// it's an answer to a system question. That was already displayed as part of the attendee
467
+						// fields, so don't write it out again thanks.
468
+						continue;
469
+					}
470
+					if ($answer_row['Question.QST_ID']) {
471
+						$question_label = EEH_Export::prepare_value_from_db_for_display(
472
+							EEM_Question::instance(),
473
+							'QST_admin_label',
474
+							$answer_row['Question.QST_admin_label']
475
+						);
476
+					} else {
477
+						$question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
478
+					}
479
+					if (isset($answer_row['Question.QST_type'])
480
+						&& $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
481
+					) {
482
+						$reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
483
+							$answer_row['Answer.ANS_value']
484
+						);
485
+					} else {
486
+						// this isn't for html, so don't show html entities
487
+						$reg_csv_array[ $question_label ] = html_entity_decode(
488
+							EEH_Export::prepare_value_from_db_for_display(
489
+								EEM_Answer::instance(),
490
+								'ANS_value',
491
+								$answer_row['Answer.ANS_value']
492
+							)
493
+						);
494
+					}
495
+				}
496 496
 
497
-                /**
498
-                 * Filter to change the contents of each row of the registrations report CSV file.
499
-                 * This can be used to add or remote columns from the CSV file, or change their values.
500
-                 * Note when using: all rows in the CSV should have the same columns.
501
-                 * @param array $reg_csv_array keys are the column names, values are their cell values
502
-                 * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results()
503
-                 */
504
-                $registrations_csv_ready_array[] = apply_filters(
505
-                    'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
506
-                    $reg_csv_array,
507
-                    $reg_row
508
-                );
509
-            }
510
-        }
511
-        // if we couldn't export anything, we want to at least show the column headers
512
-        if (empty($registrations_csv_ready_array)) {
513
-            $reg_csv_array = array();
514
-            $model_and_fields_to_include = array(
515
-                'Registration' => $reg_fields_to_include,
516
-                'Attendee'     => $att_fields_to_include,
517
-            );
518
-            foreach ($model_and_fields_to_include as $model_name => $field_list) {
519
-                $model = EE_Registry::instance()->load_model($model_name);
520
-                foreach ($field_list as $field_name) {
521
-                    $field = $model->field_settings_for($field_name);
522
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
523
-                }
524
-            }
525
-            $registrations_csv_ready_array[] = $reg_csv_array;
526
-        }
527
-        return $registrations_csv_ready_array;
528
-    }
497
+				/**
498
+				 * Filter to change the contents of each row of the registrations report CSV file.
499
+				 * This can be used to add or remote columns from the CSV file, or change their values.
500
+				 * Note when using: all rows in the CSV should have the same columns.
501
+				 * @param array $reg_csv_array keys are the column names, values are their cell values
502
+				 * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results()
503
+				 */
504
+				$registrations_csv_ready_array[] = apply_filters(
505
+					'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
506
+					$reg_csv_array,
507
+					$reg_row
508
+				);
509
+			}
510
+		}
511
+		// if we couldn't export anything, we want to at least show the column headers
512
+		if (empty($registrations_csv_ready_array)) {
513
+			$reg_csv_array = array();
514
+			$model_and_fields_to_include = array(
515
+				'Registration' => $reg_fields_to_include,
516
+				'Attendee'     => $att_fields_to_include,
517
+			);
518
+			foreach ($model_and_fields_to_include as $model_name => $field_list) {
519
+				$model = EE_Registry::instance()->load_model($model_name);
520
+				foreach ($field_list as $field_name) {
521
+					$field = $model->field_settings_for($field_name);
522
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
523
+				}
524
+			}
525
+			$registrations_csv_ready_array[] = $reg_csv_array;
526
+		}
527
+		return $registrations_csv_ready_array;
528
+	}
529 529
 
530 530
 
531
-    /**
532
-     * Counts total unit to process
533
-     *
534
-     * @deprecated since 4.9.19
535
-     * @param int|array $event_id
536
-     * @return int
537
-     */
538
-    public function count_units_to_process($event_id)
539
-    {
540
-        // use the legacy filter
541
-        if ($event_id) {
542
-            $query_params[0]['EVT_ID'] = $event_id;
543
-        } else {
544
-            $query_params['force_join'][] = 'Event';
545
-        }
546
-        return \EEM_Registration::instance()->count($query_params);
547
-    }
531
+	/**
532
+	 * Counts total unit to process
533
+	 *
534
+	 * @deprecated since 4.9.19
535
+	 * @param int|array $event_id
536
+	 * @return int
537
+	 */
538
+	public function count_units_to_process($event_id)
539
+	{
540
+		// use the legacy filter
541
+		if ($event_id) {
542
+			$query_params[0]['EVT_ID'] = $event_id;
543
+		} else {
544
+			$query_params['force_join'][] = 'Event';
545
+		}
546
+		return \EEM_Registration::instance()->count($query_params);
547
+	}
548 548
 
549 549
 
550
-    /**
551
-     * Performs any clean-up logic when we know the job is completed.
552
-     * In this case, we delete the temporary file
553
-     *
554
-     * @param JobParameters $job_parameters
555
-     * @return boolean
556
-     */
557
-    public function cleanup_job(JobParameters $job_parameters)
558
-    {
559
-        $this->_file_helper->delete(
560
-            \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
561
-            true,
562
-            'd'
563
-        );
564
-        return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
565
-    }
550
+	/**
551
+	 * Performs any clean-up logic when we know the job is completed.
552
+	 * In this case, we delete the temporary file
553
+	 *
554
+	 * @param JobParameters $job_parameters
555
+	 * @return boolean
556
+	 */
557
+	public function cleanup_job(JobParameters $job_parameters)
558
+	{
559
+		$this->_file_helper->delete(
560
+			\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
561
+			true,
562
+			'd'
563
+		);
564
+		return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
565
+	}
566 566
 }
Please login to merge, or discard this patch.
reg_steps/attendee_information/attendee_info_single.template.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -6,16 +6,16 @@  discard block
 block discarded – undo
6 6
 <?php if (!is_admin()) : ?>
7 7
     <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text">
8 8
         <?php echo apply_filters(
9
-            'FHEE__registration_page_attendee_information__attendee_information_pg',
10
-            sprintf(
11
-                esc_html__(
12
-                    'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.',
13
-                    'event_espresso'
14
-                ),
15
-                '<br />',
16
-                '<span class="asterisk">*</span>'
17
-            )
18
-        ); ?>
9
+			'FHEE__registration_page_attendee_information__attendee_information_pg',
10
+			sprintf(
11
+				esc_html__(
12
+					'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.',
13
+					'event_espresso'
14
+				),
15
+				'<br />',
16
+				'<span class="asterisk">*</span>'
17
+			)
18
+		); ?>
19 19
 </p>
20 20
 <?php endif; ?>
21 21
 
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
 $prev_ticket = 0;
26 26
 
27 27
 if (count($registrations) > 0) {
28
-    $ticketID = key($template_args['ticket_count']);
29
-    ?>
28
+	$ticketID = key($template_args['ticket_count']);
29
+	?>
30 30
 
31 31
     <div id="spco-attendee-panel-dv-<?php echo $ticketID; ?>"
32 32
         class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $ticketID; ?>">
@@ -41,54 +41,54 @@  discard block
 block discarded – undo
41 41
                     <th scope="col" width="" class="jst-left"><?php esc_html_e('Name and Description', 'event_espresso'); ?></th>
42 42
                     <th scope="col" width="7.5%" class="jst-rght">
43 43
                         <?php esc_html_e(
44
-                            'Qty',
45
-                            'event_espresso'
46
-                        ); ?></th>
44
+							'Qty',
45
+							'event_espresso'
46
+						); ?></th>
47 47
                     <th scope="col" width="17.5%" class="jst-rght">
48 48
                         <?php esc_html_e(
49
-                            'Price',
50
-                            'event_espresso'
51
-                        ); ?></th>
49
+							'Price',
50
+							'event_espresso'
51
+						); ?></th>
52 52
                     <th scope="col" width="17.5%" class="jst-rght">
53 53
                         <?php esc_html_e(
54
-                            'Total',
55
-                            'event_espresso'
56
-                        ); ?></th>
54
+							'Total',
55
+							'event_espresso'
56
+						); ?></th>
57 57
                 </tr>
58 58
                 </thead>
59 59
                 <tbody>
60 60
                 <?php
61
-                // Store previous values to avoid duplicated rows.
62
-                $prev_ticket = 0;
63
-                // Display all tickets inside.
64
-                foreach ($registrations as $registration) {
65
-                    if ($registration instanceof EE_Registration) {
66
-                        if ($registration->ticket()->ID() !== $prev_ticket) {
67
-                            echo $ticket_line_item[ $registration->ticket()->ID() ];
68
-                        }
61
+				// Store previous values to avoid duplicated rows.
62
+				$prev_ticket = 0;
63
+				// Display all tickets inside.
64
+				foreach ($registrations as $registration) {
65
+					if ($registration instanceof EE_Registration) {
66
+						if ($registration->ticket()->ID() !== $prev_ticket) {
67
+							echo $ticket_line_item[ $registration->ticket()->ID() ];
68
+						}
69 69
 
70
-                        $prev_ticket = $registration->ticket()->ID();
71
-                    }
72
-                }
73
-                ?>
70
+						$prev_ticket = $registration->ticket()->ID();
71
+					}
72
+				}
73
+				?>
74 74
                 </tbody>
75 75
             </table>
76 76
         </div><!-- close spco-ticket-info-dv -->
77 77
 
78 78
         <?php
79
-        // Display the forms below the table.
80
-        foreach ($registrations as $registration) {
81
-            if ($registration instanceof EE_Registration) {
82
-                // Attendee Questions.
83
-                $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link());
84
-                echo ${$reg_form};
85
-            } // if ( $registration instanceof EE_Registration )
86
-        } // end foreach ( $registrations as $registration )
79
+		// Display the forms below the table.
80
+		foreach ($registrations as $registration) {
81
+			if ($registration instanceof EE_Registration) {
82
+				// Attendee Questions.
83
+				$reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link());
84
+				echo ${$reg_form};
85
+			} // if ( $registration instanceof EE_Registration )
86
+		} // end foreach ( $registrations as $registration )
87 87
 
88
-        ?>
88
+		?>
89 89
     </div><!-- close spco-attendee-panel-dv -->
90 90
     <?php
91
-    echo $default_hidden_inputs;
91
+	echo $default_hidden_inputs;
92 92
 } // end if ( count( $registrations ) > 0 )
93 93
 
94 94
 ?>
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Addon.lib.php 2 patches
Indentation   +1165 added lines, -1165 removed lines patch added patch discarded remove patch
@@ -22,1229 +22,1229 @@
 block discarded – undo
22 22
 class EE_Register_Addon implements EEI_Plugin_API
23 23
 {
24 24
 
25
-    /**
26
-     * possibly truncated version of the EE core version string
27
-     *
28
-     * @var string
29
-     */
30
-    protected static $_core_version = '';
25
+	/**
26
+	 * possibly truncated version of the EE core version string
27
+	 *
28
+	 * @var string
29
+	 */
30
+	protected static $_core_version = '';
31 31
 
32
-    /**
33
-     * Holds values for registered addons
34
-     *
35
-     * @var array
36
-     */
37
-    protected static $_settings = array();
32
+	/**
33
+	 * Holds values for registered addons
34
+	 *
35
+	 * @var array
36
+	 */
37
+	protected static $_settings = array();
38 38
 
39
-    /**
40
-     * @var  array $_incompatible_addons keys are addon SLUGS
41
-     * (first argument passed to EE_Register_Addon::register()), keys are
42
-     * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
43
-     * Generally this should be used sparingly, as we don't want to muddle up
44
-     * EE core with knowledge of ALL the addons out there.
45
-     * If you want NO versions of an addon to run with a certain version of core,
46
-     * it's usually best to define the addon's "min_core_version" as part of its call
47
-     * to EE_Register_Addon::register(), rather than using this array with a super high value for its
48
-     * minimum plugin version.
49
-     * @access    protected
50
-     */
51
-    protected static $_incompatible_addons = array(
52
-        'Multi_Event_Registration' => '2.0.11.rc.002',
53
-        'Promotions'               => '1.0.0.rc.084',
54
-    );
39
+	/**
40
+	 * @var  array $_incompatible_addons keys are addon SLUGS
41
+	 * (first argument passed to EE_Register_Addon::register()), keys are
42
+	 * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
43
+	 * Generally this should be used sparingly, as we don't want to muddle up
44
+	 * EE core with knowledge of ALL the addons out there.
45
+	 * If you want NO versions of an addon to run with a certain version of core,
46
+	 * it's usually best to define the addon's "min_core_version" as part of its call
47
+	 * to EE_Register_Addon::register(), rather than using this array with a super high value for its
48
+	 * minimum plugin version.
49
+	 * @access    protected
50
+	 */
51
+	protected static $_incompatible_addons = array(
52
+		'Multi_Event_Registration' => '2.0.11.rc.002',
53
+		'Promotions'               => '1.0.0.rc.084',
54
+	);
55 55
 
56 56
 
57
-    /**
58
-     * We should always be comparing core to a version like '4.3.0.rc.000',
59
-     * not just '4.3.0'.
60
-     * So if the addon developer doesn't provide that full version string,
61
-     * fill in the blanks for them
62
-     *
63
-     * @param string $min_core_version
64
-     * @return string always like '4.3.0.rc.000'
65
-     */
66
-    protected static function _effective_version($min_core_version)
67
-    {
68
-        // versions: 4 . 3 . 1 . p . 123
69
-        // offsets:    0 . 1 . 2 . 3 . 4
70
-        $version_parts = explode('.', $min_core_version);
71
-        // check they specified the micro version (after 2nd period)
72
-        if (! isset($version_parts[2])) {
73
-            $version_parts[2] = '0';
74
-        }
75
-        // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
76
-        // soon we can assume that's 'rc', but this current version is 'alpha'
77
-        if (! isset($version_parts[3])) {
78
-            $version_parts[3] = 'dev';
79
-        }
80
-        if (! isset($version_parts[4])) {
81
-            $version_parts[4] = '000';
82
-        }
83
-        return implode('.', $version_parts);
84
-    }
57
+	/**
58
+	 * We should always be comparing core to a version like '4.3.0.rc.000',
59
+	 * not just '4.3.0'.
60
+	 * So if the addon developer doesn't provide that full version string,
61
+	 * fill in the blanks for them
62
+	 *
63
+	 * @param string $min_core_version
64
+	 * @return string always like '4.3.0.rc.000'
65
+	 */
66
+	protected static function _effective_version($min_core_version)
67
+	{
68
+		// versions: 4 . 3 . 1 . p . 123
69
+		// offsets:    0 . 1 . 2 . 3 . 4
70
+		$version_parts = explode('.', $min_core_version);
71
+		// check they specified the micro version (after 2nd period)
72
+		if (! isset($version_parts[2])) {
73
+			$version_parts[2] = '0';
74
+		}
75
+		// if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
76
+		// soon we can assume that's 'rc', but this current version is 'alpha'
77
+		if (! isset($version_parts[3])) {
78
+			$version_parts[3] = 'dev';
79
+		}
80
+		if (! isset($version_parts[4])) {
81
+			$version_parts[4] = '000';
82
+		}
83
+		return implode('.', $version_parts);
84
+	}
85 85
 
86 86
 
87
-    /**
88
-     * Returns whether or not the min core version requirement of the addon is met
89
-     *
90
-     * @param string $min_core_version    the minimum core version required by the addon
91
-     * @param string $actual_core_version the actual core version, optional
92
-     * @return boolean
93
-     */
94
-    public static function _meets_min_core_version_requirement(
95
-        $min_core_version,
96
-        $actual_core_version = EVENT_ESPRESSO_VERSION
97
-    ) {
98
-        return version_compare(
99
-            self::_effective_version($actual_core_version),
100
-            self::_effective_version($min_core_version),
101
-            '>='
102
-        );
103
-    }
87
+	/**
88
+	 * Returns whether or not the min core version requirement of the addon is met
89
+	 *
90
+	 * @param string $min_core_version    the minimum core version required by the addon
91
+	 * @param string $actual_core_version the actual core version, optional
92
+	 * @return boolean
93
+	 */
94
+	public static function _meets_min_core_version_requirement(
95
+		$min_core_version,
96
+		$actual_core_version = EVENT_ESPRESSO_VERSION
97
+	) {
98
+		return version_compare(
99
+			self::_effective_version($actual_core_version),
100
+			self::_effective_version($min_core_version),
101
+			'>='
102
+		);
103
+	}
104 104
 
105 105
 
106
-    /**
107
-     * Method for registering new EE_Addons.
108
-     * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
109
-     * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
110
-     * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
111
-     * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
112
-     * 'activate_plugin', it registers the addon still, but its components are not registered
113
-     * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
114
-     * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
115
-     * (so that we can detect that the addon has activated on the subsequent request)
116
-     *
117
-     * @since    4.3.0
118
-     * @param string                  $addon_name                       [Required] the EE_Addon's name.
119
-     * @param  array                  $setup_args                       {
120
-     *                                                                  An array of arguments provided for registering
121
-     *                                                                  the message type.
122
-     * @type  string                  $class_name                       the addon's main file name.
123
-     *                                                                  If left blank, generated from the addon name,
124
-     *                                                                  changes something like "calendar" to
125
-     *                                                                  "EE_Calendar"
126
-     * @type string                   $min_core_version                 the minimum version of EE Core that the
127
-     *                                                                  addon will work with. eg "4.8.1.rc.084"
128
-     * @type string                   $version                          the "software" version for the addon. eg
129
-     *                                                                  "1.0.0.p" for a first stable release, or
130
-     *                                                                  "1.0.0.rc.043" for a version in progress
131
-     * @type string                   $main_file_path                   the full server path to the main file
132
-     *                                                                  loaded directly by WP
133
-     * @type DomainInterface $domain                                    child class of
134
-     *                                                                  EventEspresso\core\domain\DomainBase
135
-     * @type string                   $domain_fqcn                      Fully Qualified Class Name
136
-     *                                                                  for the addon's Domain class
137
-     *                                                                  (see EventEspresso\core\domain\Domain)
138
-     * @type string                   $admin_path                       full server path to the folder where the
139
-     *                                                                  addon\'s admin files reside
140
-     * @type string                   $admin_callback                   a method to be called when the EE Admin is
141
-     *                                                                  first invoked, can be used for hooking into
142
-     *                                                                  any admin page
143
-     * @type string                   $config_section                   the section name for this addon's
144
-     *                                                                  configuration settings section
145
-     *                                                                  (defaults to "addons")
146
-     * @type string                   $config_class                     the class name for this addon's
147
-     *                                                                  configuration settings object
148
-     * @type string                   $config_name                      the class name for this addon's
149
-     *                                                                  configuration settings object
150
-     * @type string                   $autoloader_paths                 [Required] an array of class names and the full
151
-     *                                                                  server paths to those files.
152
-     * @type string                   $autoloader_folders               an array of  "full server paths" for any
153
-     *                                                                  folders containing classes that might be
154
-     *                                                                  invoked by the addon
155
-     * @type string                   $dms_paths                        [Required] an array of full server paths to
156
-     *                                                                  folders that contain data migration scripts.
157
-     *                                                                  The key should be the EE_Addon class name that
158
-     *                                                                  this set of data migration scripts belongs to.
159
-     *                                                                  If the EE_Addon class is namespaced, then this
160
-     *                                                                  needs to be the Fully Qualified Class Name
161
-     * @type string                   $module_paths                     an array of full server paths to any
162
-     *                                                                  EED_Modules used by the addon
163
-     * @type string                   $shortcode_paths                  an array of full server paths to folders
164
-     *                                                                  that contain EES_Shortcodes
165
-     * @type string                   $widget_paths                     an array of full server paths to folders
166
-     *                                                                  that contain WP_Widgets
167
-     * @type string                   $pue_options
168
-     * @type array                    $capabilities                     an array indexed by role name
169
-     *                                                                  (i.e administrator,author ) and the values
170
-     *                                                                  are an array of caps to add to the role.
171
-     *                                                                  'administrator' => array(
172
-     *                                                                  'read_addon',
173
-     *                                                                  'edit_addon',
174
-     *                                                                  etc.
175
-     *                                                                  ).
176
-     * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
177
-     *                                                                  for any addons that need to register any
178
-     *                                                                  special meta mapped capabilities.  Should
179
-     *                                                                  be indexed where the key is the
180
-     *                                                                  EE_Meta_Capability_Map class name and the
181
-     *                                                                  values are the arguments sent to the class.
182
-     * @type array                    $model_paths                      array of folders containing DB models
183
-     * @see      EE_Register_Model
184
-     * @type array                    $class_paths                      array of folders containing DB classes
185
-     * @see      EE_Register_Model
186
-     * @type array                    $model_extension_paths            array of folders containing DB model
187
-     *                                                                  extensions
188
-     * @see      EE_Register_Model_Extension
189
-     * @type array                    $class_extension_paths            array of folders containing DB class
190
-     *                                                                  extensions
191
-     * @see      EE_Register_Model_Extension
192
-     * @type array message_types {
193
-     *                                                                  An array of message types with the key as
194
-     *                                                                  the message type name and the values as
195
-     *                                                                  below:
196
-     * @type string                   $mtfilename                       [Required] The filename of the message type
197
-     *                                                                  being registered. This will be the main
198
-     *                                                                  EE_{Message Type Name}_message_type class.
199
-     *                                                                  for example:
200
-     *                                                                  EE_Declined_Registration_message_type.class.php
201
-     * @type array                    $autoloadpaths                    [Required] An array of paths to add to the
202
-     *                                                                  messages autoloader for the new message type.
203
-     * @type array                    $messengers_to_activate_with      An array of messengers that this message
204
-     *                                                                  type should activate with. Each value in
205
-     *                                                                  the
206
-     *                                                                  array
207
-     *                                                                  should match the name property of a
208
-     *                                                                  EE_messenger. Optional.
209
-     * @type array                    $messengers_to_validate_with      An array of messengers that this message
210
-     *                                                                  type should validate with. Each value in
211
-     *                                                                  the
212
-     *                                                                  array
213
-     *                                                                  should match the name property of an
214
-     *                                                                  EE_messenger.
215
-     *                                                                  Optional.
216
-     *                                                                  }
217
-     * @type array                    $custom_post_types
218
-     * @type array                    $custom_taxonomies
219
-     * @type array                    $payment_method_paths             each element is the folder containing the
220
-     *                                                                  EE_PMT_Base child class
221
-     *                                                                  (eg,
222
-     *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
223
-     *                                                                  which contains the files
224
-     *                                                                  EE_PMT_Payomatic.pm.php)
225
-     * @type array                    $default_terms
226
-     * @type array                    $namespace                        {
227
-     *                                                                  An array with two items for registering the
228
-     *                                                                  addon's namespace. (If, for some reason, you
229
-     *                                                                  require additional namespaces,
230
-     *                                                                  use
231
-     *                                                                  EventEspresso\core\Psr4Autoloader::addNamespace()
232
-     *                                                                  directly)
233
-     * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
234
-     * @type string                   $FQNS                             the namespace prefix
235
-     * @type string                   $DIR                              a base directory for class files in the
236
-     *                                                                  namespace.
237
-     *                                                                  }
238
-     *                                                                  }
239
-     * @type string                   $privacy_policies                 FQNSs (namespaces, each of which contains only
240
-     *                                                                  privacy policy classes) or FQCNs (specific
241
-     *                                                                  classnames of privacy policy classes)
242
-     * @type string                   $personal_data_exporters          FQNSs (namespaces, each of which contains only
243
-     *                                                                  privacy policy classes) or FQCNs (specific
244
-     *                                                                  classnames of privacy policy classes)
245
-     * @type string                   $personal_data_erasers            FQNSs (namespaces, each of which contains only
246
-     *                                                                  privacy policy classes) or FQCNs (specific
247
-     *                                                                  classnames of privacy policy classes)
248
-     * @return void
249
-     * @throws DomainException
250
-     * @throws EE_Error
251
-     * @throws InvalidArgumentException
252
-     * @throws ReflectionException
253
-     * @throws InvalidDataTypeException
254
-     * @throws InvalidInterfaceException
255
-     */
256
-    public static function register($addon_name = '', $setup_args = array())
257
-    {
258
-        // required fields MUST be present, so let's make sure they are.
259
-        EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
260
-        // get class name for addon
261
-        $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
262
-        // setup $_settings array from incoming values.
263
-        $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
264
-        // setup PUE
265
-        EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
266
-        // does this addon work with this version of core or WordPress ?
267
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
268
-            return;
269
-        }
270
-        // register namespaces
271
-        EE_Register_Addon::_setup_namespaces($addon_settings);
272
-        // check if this is an activation request
273
-        if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
274
-            // dont bother setting up the rest of the addon atm
275
-            return;
276
-        }
277
-        // we need cars
278
-        EE_Register_Addon::_setup_autoloaders($addon_name);
279
-        // register new models and extensions
280
-        EE_Register_Addon::_register_models_and_extensions($addon_name);
281
-        // setup DMS
282
-        EE_Register_Addon::_register_data_migration_scripts($addon_name);
283
-        // if config_class is present let's register config.
284
-        EE_Register_Addon::_register_config($addon_name);
285
-        // register admin pages
286
-        EE_Register_Addon::_register_admin_pages($addon_name);
287
-        // add to list of modules to be registered
288
-        EE_Register_Addon::_register_modules($addon_name);
289
-        // add to list of shortcodes to be registered
290
-        EE_Register_Addon::_register_shortcodes($addon_name);
291
-        // add to list of widgets to be registered
292
-        EE_Register_Addon::_register_widgets($addon_name);
293
-        // register capability related stuff.
294
-        EE_Register_Addon::_register_capabilities($addon_name);
295
-        // any message type to register?
296
-        EE_Register_Addon::_register_message_types($addon_name);
297
-        // any custom post type/ custom capabilities or default terms to register
298
-        EE_Register_Addon::_register_custom_post_types($addon_name);
299
-        // and any payment methods
300
-        EE_Register_Addon::_register_payment_methods($addon_name);
301
-        // and privacy policy generators
302
-        EE_Register_Addon::registerPrivacyPolicies($addon_name);
303
-        // and privacy policy generators
304
-        EE_Register_Addon::registerPersonalDataExporters($addon_name);
305
-        // and privacy policy generators
306
-        EE_Register_Addon::registerPersonalDataErasers($addon_name);
307
-        // load and instantiate main addon class
308
-        $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
309
-        // delay calling after_registration hook on each addon until after all add-ons have been registered.
310
-        add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999);
311
-    }
106
+	/**
107
+	 * Method for registering new EE_Addons.
108
+	 * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
109
+	 * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
110
+	 * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
111
+	 * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
112
+	 * 'activate_plugin', it registers the addon still, but its components are not registered
113
+	 * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
114
+	 * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
115
+	 * (so that we can detect that the addon has activated on the subsequent request)
116
+	 *
117
+	 * @since    4.3.0
118
+	 * @param string                  $addon_name                       [Required] the EE_Addon's name.
119
+	 * @param  array                  $setup_args                       {
120
+	 *                                                                  An array of arguments provided for registering
121
+	 *                                                                  the message type.
122
+	 * @type  string                  $class_name                       the addon's main file name.
123
+	 *                                                                  If left blank, generated from the addon name,
124
+	 *                                                                  changes something like "calendar" to
125
+	 *                                                                  "EE_Calendar"
126
+	 * @type string                   $min_core_version                 the minimum version of EE Core that the
127
+	 *                                                                  addon will work with. eg "4.8.1.rc.084"
128
+	 * @type string                   $version                          the "software" version for the addon. eg
129
+	 *                                                                  "1.0.0.p" for a first stable release, or
130
+	 *                                                                  "1.0.0.rc.043" for a version in progress
131
+	 * @type string                   $main_file_path                   the full server path to the main file
132
+	 *                                                                  loaded directly by WP
133
+	 * @type DomainInterface $domain                                    child class of
134
+	 *                                                                  EventEspresso\core\domain\DomainBase
135
+	 * @type string                   $domain_fqcn                      Fully Qualified Class Name
136
+	 *                                                                  for the addon's Domain class
137
+	 *                                                                  (see EventEspresso\core\domain\Domain)
138
+	 * @type string                   $admin_path                       full server path to the folder where the
139
+	 *                                                                  addon\'s admin files reside
140
+	 * @type string                   $admin_callback                   a method to be called when the EE Admin is
141
+	 *                                                                  first invoked, can be used for hooking into
142
+	 *                                                                  any admin page
143
+	 * @type string                   $config_section                   the section name for this addon's
144
+	 *                                                                  configuration settings section
145
+	 *                                                                  (defaults to "addons")
146
+	 * @type string                   $config_class                     the class name for this addon's
147
+	 *                                                                  configuration settings object
148
+	 * @type string                   $config_name                      the class name for this addon's
149
+	 *                                                                  configuration settings object
150
+	 * @type string                   $autoloader_paths                 [Required] an array of class names and the full
151
+	 *                                                                  server paths to those files.
152
+	 * @type string                   $autoloader_folders               an array of  "full server paths" for any
153
+	 *                                                                  folders containing classes that might be
154
+	 *                                                                  invoked by the addon
155
+	 * @type string                   $dms_paths                        [Required] an array of full server paths to
156
+	 *                                                                  folders that contain data migration scripts.
157
+	 *                                                                  The key should be the EE_Addon class name that
158
+	 *                                                                  this set of data migration scripts belongs to.
159
+	 *                                                                  If the EE_Addon class is namespaced, then this
160
+	 *                                                                  needs to be the Fully Qualified Class Name
161
+	 * @type string                   $module_paths                     an array of full server paths to any
162
+	 *                                                                  EED_Modules used by the addon
163
+	 * @type string                   $shortcode_paths                  an array of full server paths to folders
164
+	 *                                                                  that contain EES_Shortcodes
165
+	 * @type string                   $widget_paths                     an array of full server paths to folders
166
+	 *                                                                  that contain WP_Widgets
167
+	 * @type string                   $pue_options
168
+	 * @type array                    $capabilities                     an array indexed by role name
169
+	 *                                                                  (i.e administrator,author ) and the values
170
+	 *                                                                  are an array of caps to add to the role.
171
+	 *                                                                  'administrator' => array(
172
+	 *                                                                  'read_addon',
173
+	 *                                                                  'edit_addon',
174
+	 *                                                                  etc.
175
+	 *                                                                  ).
176
+	 * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
177
+	 *                                                                  for any addons that need to register any
178
+	 *                                                                  special meta mapped capabilities.  Should
179
+	 *                                                                  be indexed where the key is the
180
+	 *                                                                  EE_Meta_Capability_Map class name and the
181
+	 *                                                                  values are the arguments sent to the class.
182
+	 * @type array                    $model_paths                      array of folders containing DB models
183
+	 * @see      EE_Register_Model
184
+	 * @type array                    $class_paths                      array of folders containing DB classes
185
+	 * @see      EE_Register_Model
186
+	 * @type array                    $model_extension_paths            array of folders containing DB model
187
+	 *                                                                  extensions
188
+	 * @see      EE_Register_Model_Extension
189
+	 * @type array                    $class_extension_paths            array of folders containing DB class
190
+	 *                                                                  extensions
191
+	 * @see      EE_Register_Model_Extension
192
+	 * @type array message_types {
193
+	 *                                                                  An array of message types with the key as
194
+	 *                                                                  the message type name and the values as
195
+	 *                                                                  below:
196
+	 * @type string                   $mtfilename                       [Required] The filename of the message type
197
+	 *                                                                  being registered. This will be the main
198
+	 *                                                                  EE_{Message Type Name}_message_type class.
199
+	 *                                                                  for example:
200
+	 *                                                                  EE_Declined_Registration_message_type.class.php
201
+	 * @type array                    $autoloadpaths                    [Required] An array of paths to add to the
202
+	 *                                                                  messages autoloader for the new message type.
203
+	 * @type array                    $messengers_to_activate_with      An array of messengers that this message
204
+	 *                                                                  type should activate with. Each value in
205
+	 *                                                                  the
206
+	 *                                                                  array
207
+	 *                                                                  should match the name property of a
208
+	 *                                                                  EE_messenger. Optional.
209
+	 * @type array                    $messengers_to_validate_with      An array of messengers that this message
210
+	 *                                                                  type should validate with. Each value in
211
+	 *                                                                  the
212
+	 *                                                                  array
213
+	 *                                                                  should match the name property of an
214
+	 *                                                                  EE_messenger.
215
+	 *                                                                  Optional.
216
+	 *                                                                  }
217
+	 * @type array                    $custom_post_types
218
+	 * @type array                    $custom_taxonomies
219
+	 * @type array                    $payment_method_paths             each element is the folder containing the
220
+	 *                                                                  EE_PMT_Base child class
221
+	 *                                                                  (eg,
222
+	 *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
223
+	 *                                                                  which contains the files
224
+	 *                                                                  EE_PMT_Payomatic.pm.php)
225
+	 * @type array                    $default_terms
226
+	 * @type array                    $namespace                        {
227
+	 *                                                                  An array with two items for registering the
228
+	 *                                                                  addon's namespace. (If, for some reason, you
229
+	 *                                                                  require additional namespaces,
230
+	 *                                                                  use
231
+	 *                                                                  EventEspresso\core\Psr4Autoloader::addNamespace()
232
+	 *                                                                  directly)
233
+	 * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
234
+	 * @type string                   $FQNS                             the namespace prefix
235
+	 * @type string                   $DIR                              a base directory for class files in the
236
+	 *                                                                  namespace.
237
+	 *                                                                  }
238
+	 *                                                                  }
239
+	 * @type string                   $privacy_policies                 FQNSs (namespaces, each of which contains only
240
+	 *                                                                  privacy policy classes) or FQCNs (specific
241
+	 *                                                                  classnames of privacy policy classes)
242
+	 * @type string                   $personal_data_exporters          FQNSs (namespaces, each of which contains only
243
+	 *                                                                  privacy policy classes) or FQCNs (specific
244
+	 *                                                                  classnames of privacy policy classes)
245
+	 * @type string                   $personal_data_erasers            FQNSs (namespaces, each of which contains only
246
+	 *                                                                  privacy policy classes) or FQCNs (specific
247
+	 *                                                                  classnames of privacy policy classes)
248
+	 * @return void
249
+	 * @throws DomainException
250
+	 * @throws EE_Error
251
+	 * @throws InvalidArgumentException
252
+	 * @throws ReflectionException
253
+	 * @throws InvalidDataTypeException
254
+	 * @throws InvalidInterfaceException
255
+	 */
256
+	public static function register($addon_name = '', $setup_args = array())
257
+	{
258
+		// required fields MUST be present, so let's make sure they are.
259
+		EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
260
+		// get class name for addon
261
+		$class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
262
+		// setup $_settings array from incoming values.
263
+		$addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
264
+		// setup PUE
265
+		EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
266
+		// does this addon work with this version of core or WordPress ?
267
+		if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
268
+			return;
269
+		}
270
+		// register namespaces
271
+		EE_Register_Addon::_setup_namespaces($addon_settings);
272
+		// check if this is an activation request
273
+		if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
274
+			// dont bother setting up the rest of the addon atm
275
+			return;
276
+		}
277
+		// we need cars
278
+		EE_Register_Addon::_setup_autoloaders($addon_name);
279
+		// register new models and extensions
280
+		EE_Register_Addon::_register_models_and_extensions($addon_name);
281
+		// setup DMS
282
+		EE_Register_Addon::_register_data_migration_scripts($addon_name);
283
+		// if config_class is present let's register config.
284
+		EE_Register_Addon::_register_config($addon_name);
285
+		// register admin pages
286
+		EE_Register_Addon::_register_admin_pages($addon_name);
287
+		// add to list of modules to be registered
288
+		EE_Register_Addon::_register_modules($addon_name);
289
+		// add to list of shortcodes to be registered
290
+		EE_Register_Addon::_register_shortcodes($addon_name);
291
+		// add to list of widgets to be registered
292
+		EE_Register_Addon::_register_widgets($addon_name);
293
+		// register capability related stuff.
294
+		EE_Register_Addon::_register_capabilities($addon_name);
295
+		// any message type to register?
296
+		EE_Register_Addon::_register_message_types($addon_name);
297
+		// any custom post type/ custom capabilities or default terms to register
298
+		EE_Register_Addon::_register_custom_post_types($addon_name);
299
+		// and any payment methods
300
+		EE_Register_Addon::_register_payment_methods($addon_name);
301
+		// and privacy policy generators
302
+		EE_Register_Addon::registerPrivacyPolicies($addon_name);
303
+		// and privacy policy generators
304
+		EE_Register_Addon::registerPersonalDataExporters($addon_name);
305
+		// and privacy policy generators
306
+		EE_Register_Addon::registerPersonalDataErasers($addon_name);
307
+		// load and instantiate main addon class
308
+		$addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
309
+		// delay calling after_registration hook on each addon until after all add-ons have been registered.
310
+		add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999);
311
+	}
312 312
 
313 313
 
314
-    /**
315
-     * @param string $addon_name
316
-     * @param array  $setup_args
317
-     * @return void
318
-     * @throws EE_Error
319
-     */
320
-    private static function _verify_parameters($addon_name, array $setup_args)
321
-    {
322
-        // required fields MUST be present, so let's make sure they are.
323
-        if (empty($addon_name) || ! is_array($setup_args)) {
324
-            throw new EE_Error(
325
-                __(
326
-                    'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
327
-                    'event_espresso'
328
-                )
329
-            );
330
-        }
331
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
332
-            throw new EE_Error(
333
-                sprintf(
334
-                    __(
335
-                        'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
336
-                        'event_espresso'
337
-                    ),
338
-                    implode(',', array_keys($setup_args))
339
-                )
340
-            );
341
-        }
342
-        // check that addon has not already been registered with that name
343
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
344
-            throw new EE_Error(
345
-                sprintf(
346
-                    __(
347
-                        'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
348
-                        'event_espresso'
349
-                    ),
350
-                    $addon_name
351
-                )
352
-            );
353
-        }
354
-    }
314
+	/**
315
+	 * @param string $addon_name
316
+	 * @param array  $setup_args
317
+	 * @return void
318
+	 * @throws EE_Error
319
+	 */
320
+	private static function _verify_parameters($addon_name, array $setup_args)
321
+	{
322
+		// required fields MUST be present, so let's make sure they are.
323
+		if (empty($addon_name) || ! is_array($setup_args)) {
324
+			throw new EE_Error(
325
+				__(
326
+					'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
327
+					'event_espresso'
328
+				)
329
+			);
330
+		}
331
+		if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
332
+			throw new EE_Error(
333
+				sprintf(
334
+					__(
335
+						'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
336
+						'event_espresso'
337
+					),
338
+					implode(',', array_keys($setup_args))
339
+				)
340
+			);
341
+		}
342
+		// check that addon has not already been registered with that name
343
+		if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
344
+			throw new EE_Error(
345
+				sprintf(
346
+					__(
347
+						'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
348
+						'event_espresso'
349
+					),
350
+					$addon_name
351
+				)
352
+			);
353
+		}
354
+	}
355 355
 
356 356
 
357
-    /**
358
-     * @param string $addon_name
359
-     * @param array  $setup_args
360
-     * @return string
361
-     */
362
-    private static function _parse_class_name($addon_name, array $setup_args)
363
-    {
364
-        if (empty($setup_args['class_name'])) {
365
-            // generate one by first separating name with spaces
366
-            $class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
367
-            // capitalize, then replace spaces with underscores
368
-            $class_name = str_replace(' ', '_', ucwords($class_name));
369
-        } else {
370
-            $class_name = $setup_args['class_name'];
371
-        }
372
-        // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
373
-        return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
374
-            ? $class_name
375
-            : 'EE_' . $class_name;
376
-    }
357
+	/**
358
+	 * @param string $addon_name
359
+	 * @param array  $setup_args
360
+	 * @return string
361
+	 */
362
+	private static function _parse_class_name($addon_name, array $setup_args)
363
+	{
364
+		if (empty($setup_args['class_name'])) {
365
+			// generate one by first separating name with spaces
366
+			$class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
367
+			// capitalize, then replace spaces with underscores
368
+			$class_name = str_replace(' ', '_', ucwords($class_name));
369
+		} else {
370
+			$class_name = $setup_args['class_name'];
371
+		}
372
+		// check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
373
+		return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
374
+			? $class_name
375
+			: 'EE_' . $class_name;
376
+	}
377 377
 
378 378
 
379
-    /**
380
-     * @param string $class_name
381
-     * @param array  $setup_args
382
-     * @return array
383
-     */
384
-    private static function _get_addon_settings($class_name, array $setup_args)
385
-    {
386
-        // setup $_settings array from incoming values.
387
-        $addon_settings = array(
388
-            // generated from the addon name, changes something like "calendar" to "EE_Calendar"
389
-            'class_name'            => $class_name,
390
-            // the addon slug for use in URLs, etc
391
-            'plugin_slug'           => isset($setup_args['plugin_slug'])
392
-                ? (string) $setup_args['plugin_slug']
393
-                : '',
394
-            // page slug to be used when generating the "Settings" link on the WP plugin page
395
-            'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
396
-                ? (string) $setup_args['plugin_action_slug']
397
-                : '',
398
-            // the "software" version for the addon
399
-            'version'               => isset($setup_args['version'])
400
-                ? (string) $setup_args['version']
401
-                : '',
402
-            // the minimum version of EE Core that the addon will work with
403
-            'min_core_version'      => isset($setup_args['min_core_version'])
404
-                ? (string) $setup_args['min_core_version']
405
-                : '',
406
-            // the minimum version of WordPress that the addon will work with
407
-            'min_wp_version'        => isset($setup_args['min_wp_version'])
408
-                ? (string) $setup_args['min_wp_version']
409
-                : EE_MIN_WP_VER_REQUIRED,
410
-            // full server path to main file (file loaded directly by WP)
411
-            'main_file_path'        => isset($setup_args['main_file_path'])
412
-                ? (string) $setup_args['main_file_path']
413
-                : '',
414
-            // instance of \EventEspresso\core\domain\DomainInterface
415
-            'domain'                => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface
416
-                ? $setup_args['domain']
417
-                : null,
418
-            // Fully Qualified Class Name for the addon's Domain class
419
-            'domain_fqcn'           => isset($setup_args['domain_fqcn'])
420
-                ? (string) $setup_args['domain_fqcn']
421
-                : '',
422
-            // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
423
-            'admin_path'            => isset($setup_args['admin_path'])
424
-                ? (string) $setup_args['admin_path'] : '',
425
-            // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
426
-            'admin_callback'        => isset($setup_args['admin_callback'])
427
-                ? (string) $setup_args['admin_callback']
428
-                : '',
429
-            // the section name for this addon's configuration settings section (defaults to "addons")
430
-            'config_section'        => isset($setup_args['config_section'])
431
-                ? (string) $setup_args['config_section']
432
-                : 'addons',
433
-            // the class name for this addon's configuration settings object
434
-            'config_class'          => isset($setup_args['config_class'])
435
-                ? (string) $setup_args['config_class'] : '',
436
-            // the name given to the config for this addons' configuration settings object (optional)
437
-            'config_name'           => isset($setup_args['config_name'])
438
-                ? (string) $setup_args['config_name'] : '',
439
-            // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
440
-            'autoloader_paths'      => isset($setup_args['autoloader_paths'])
441
-                ? (array) $setup_args['autoloader_paths']
442
-                : array(),
443
-            // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
444
-            'autoloader_folders'    => isset($setup_args['autoloader_folders'])
445
-                ? (array) $setup_args['autoloader_folders']
446
-                : array(),
447
-            // array of full server paths to any EE_DMS data migration scripts used by the addon.
448
-            // The key should be the EE_Addon class name that this set of data migration scripts belongs to.
449
-            // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
450
-            'dms_paths'             => isset($setup_args['dms_paths'])
451
-                ? (array) $setup_args['dms_paths']
452
-                : array(),
453
-            // array of full server paths to any EED_Modules used by the addon
454
-            'module_paths'          => isset($setup_args['module_paths'])
455
-                ? (array) $setup_args['module_paths']
456
-                : array(),
457
-            // array of full server paths to any EES_Shortcodes used by the addon
458
-            'shortcode_paths'       => isset($setup_args['shortcode_paths'])
459
-                ? (array) $setup_args['shortcode_paths']
460
-                : array(),
461
-            'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
462
-                ? (array) $setup_args['shortcode_fqcns']
463
-                : array(),
464
-            // array of full server paths to any WP_Widgets used by the addon
465
-            'widget_paths'          => isset($setup_args['widget_paths'])
466
-                ? (array) $setup_args['widget_paths']
467
-                : array(),
468
-            // array of PUE options used by the addon
469
-            'pue_options'           => isset($setup_args['pue_options'])
470
-                ? (array) $setup_args['pue_options']
471
-                : array(),
472
-            'message_types'         => isset($setup_args['message_types'])
473
-                ? (array) $setup_args['message_types']
474
-                : array(),
475
-            'capabilities'          => isset($setup_args['capabilities'])
476
-                ? (array) $setup_args['capabilities']
477
-                : array(),
478
-            'capability_maps'       => isset($setup_args['capability_maps'])
479
-                ? (array) $setup_args['capability_maps']
480
-                : array(),
481
-            'model_paths'           => isset($setup_args['model_paths'])
482
-                ? (array) $setup_args['model_paths']
483
-                : array(),
484
-            'class_paths'           => isset($setup_args['class_paths'])
485
-                ? (array) $setup_args['class_paths']
486
-                : array(),
487
-            'model_extension_paths' => isset($setup_args['model_extension_paths'])
488
-                ? (array) $setup_args['model_extension_paths']
489
-                : array(),
490
-            'class_extension_paths' => isset($setup_args['class_extension_paths'])
491
-                ? (array) $setup_args['class_extension_paths']
492
-                : array(),
493
-            'custom_post_types'     => isset($setup_args['custom_post_types'])
494
-                ? (array) $setup_args['custom_post_types']
495
-                : array(),
496
-            'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
497
-                ? (array) $setup_args['custom_taxonomies']
498
-                : array(),
499
-            'payment_method_paths'  => isset($setup_args['payment_method_paths'])
500
-                ? (array) $setup_args['payment_method_paths']
501
-                : array(),
502
-            'default_terms'         => isset($setup_args['default_terms'])
503
-                ? (array) $setup_args['default_terms']
504
-                : array(),
505
-            // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
506
-            // that can be used for adding upgrading/marketing info
507
-            'plugins_page_row'      => isset($setup_args['plugins_page_row'])
508
-                ? $setup_args['plugins_page_row']
509
-                : '',
510
-            'namespace'             => isset(
511
-                $setup_args['namespace']['FQNS'],
512
-                $setup_args['namespace']['DIR']
513
-            )
514
-                ? (array) $setup_args['namespace']
515
-                : array(),
516
-            'privacy_policies'      => isset($setup_args['privacy_policies'])
517
-                ? (array) $setup_args['privacy_policies']
518
-                : '',
519
-        );
520
-        // if plugin_action_slug is NOT set, but an admin page path IS set,
521
-        // then let's just use the plugin_slug since that will be used for linking to the admin page
522
-        $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
523
-                                                && ! empty($addon_settings['admin_path'])
524
-            ? $addon_settings['plugin_slug']
525
-            : $addon_settings['plugin_action_slug'];
526
-        // full server path to main file (file loaded directly by WP)
527
-        $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
528
-        return $addon_settings;
529
-    }
379
+	/**
380
+	 * @param string $class_name
381
+	 * @param array  $setup_args
382
+	 * @return array
383
+	 */
384
+	private static function _get_addon_settings($class_name, array $setup_args)
385
+	{
386
+		// setup $_settings array from incoming values.
387
+		$addon_settings = array(
388
+			// generated from the addon name, changes something like "calendar" to "EE_Calendar"
389
+			'class_name'            => $class_name,
390
+			// the addon slug for use in URLs, etc
391
+			'plugin_slug'           => isset($setup_args['plugin_slug'])
392
+				? (string) $setup_args['plugin_slug']
393
+				: '',
394
+			// page slug to be used when generating the "Settings" link on the WP plugin page
395
+			'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
396
+				? (string) $setup_args['plugin_action_slug']
397
+				: '',
398
+			// the "software" version for the addon
399
+			'version'               => isset($setup_args['version'])
400
+				? (string) $setup_args['version']
401
+				: '',
402
+			// the minimum version of EE Core that the addon will work with
403
+			'min_core_version'      => isset($setup_args['min_core_version'])
404
+				? (string) $setup_args['min_core_version']
405
+				: '',
406
+			// the minimum version of WordPress that the addon will work with
407
+			'min_wp_version'        => isset($setup_args['min_wp_version'])
408
+				? (string) $setup_args['min_wp_version']
409
+				: EE_MIN_WP_VER_REQUIRED,
410
+			// full server path to main file (file loaded directly by WP)
411
+			'main_file_path'        => isset($setup_args['main_file_path'])
412
+				? (string) $setup_args['main_file_path']
413
+				: '',
414
+			// instance of \EventEspresso\core\domain\DomainInterface
415
+			'domain'                => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface
416
+				? $setup_args['domain']
417
+				: null,
418
+			// Fully Qualified Class Name for the addon's Domain class
419
+			'domain_fqcn'           => isset($setup_args['domain_fqcn'])
420
+				? (string) $setup_args['domain_fqcn']
421
+				: '',
422
+			// path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
423
+			'admin_path'            => isset($setup_args['admin_path'])
424
+				? (string) $setup_args['admin_path'] : '',
425
+			// a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
426
+			'admin_callback'        => isset($setup_args['admin_callback'])
427
+				? (string) $setup_args['admin_callback']
428
+				: '',
429
+			// the section name for this addon's configuration settings section (defaults to "addons")
430
+			'config_section'        => isset($setup_args['config_section'])
431
+				? (string) $setup_args['config_section']
432
+				: 'addons',
433
+			// the class name for this addon's configuration settings object
434
+			'config_class'          => isset($setup_args['config_class'])
435
+				? (string) $setup_args['config_class'] : '',
436
+			// the name given to the config for this addons' configuration settings object (optional)
437
+			'config_name'           => isset($setup_args['config_name'])
438
+				? (string) $setup_args['config_name'] : '',
439
+			// an array of "class names" => "full server paths" for any classes that might be invoked by the addon
440
+			'autoloader_paths'      => isset($setup_args['autoloader_paths'])
441
+				? (array) $setup_args['autoloader_paths']
442
+				: array(),
443
+			// an array of  "full server paths" for any folders containing classes that might be invoked by the addon
444
+			'autoloader_folders'    => isset($setup_args['autoloader_folders'])
445
+				? (array) $setup_args['autoloader_folders']
446
+				: array(),
447
+			// array of full server paths to any EE_DMS data migration scripts used by the addon.
448
+			// The key should be the EE_Addon class name that this set of data migration scripts belongs to.
449
+			// If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
450
+			'dms_paths'             => isset($setup_args['dms_paths'])
451
+				? (array) $setup_args['dms_paths']
452
+				: array(),
453
+			// array of full server paths to any EED_Modules used by the addon
454
+			'module_paths'          => isset($setup_args['module_paths'])
455
+				? (array) $setup_args['module_paths']
456
+				: array(),
457
+			// array of full server paths to any EES_Shortcodes used by the addon
458
+			'shortcode_paths'       => isset($setup_args['shortcode_paths'])
459
+				? (array) $setup_args['shortcode_paths']
460
+				: array(),
461
+			'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
462
+				? (array) $setup_args['shortcode_fqcns']
463
+				: array(),
464
+			// array of full server paths to any WP_Widgets used by the addon
465
+			'widget_paths'          => isset($setup_args['widget_paths'])
466
+				? (array) $setup_args['widget_paths']
467
+				: array(),
468
+			// array of PUE options used by the addon
469
+			'pue_options'           => isset($setup_args['pue_options'])
470
+				? (array) $setup_args['pue_options']
471
+				: array(),
472
+			'message_types'         => isset($setup_args['message_types'])
473
+				? (array) $setup_args['message_types']
474
+				: array(),
475
+			'capabilities'          => isset($setup_args['capabilities'])
476
+				? (array) $setup_args['capabilities']
477
+				: array(),
478
+			'capability_maps'       => isset($setup_args['capability_maps'])
479
+				? (array) $setup_args['capability_maps']
480
+				: array(),
481
+			'model_paths'           => isset($setup_args['model_paths'])
482
+				? (array) $setup_args['model_paths']
483
+				: array(),
484
+			'class_paths'           => isset($setup_args['class_paths'])
485
+				? (array) $setup_args['class_paths']
486
+				: array(),
487
+			'model_extension_paths' => isset($setup_args['model_extension_paths'])
488
+				? (array) $setup_args['model_extension_paths']
489
+				: array(),
490
+			'class_extension_paths' => isset($setup_args['class_extension_paths'])
491
+				? (array) $setup_args['class_extension_paths']
492
+				: array(),
493
+			'custom_post_types'     => isset($setup_args['custom_post_types'])
494
+				? (array) $setup_args['custom_post_types']
495
+				: array(),
496
+			'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
497
+				? (array) $setup_args['custom_taxonomies']
498
+				: array(),
499
+			'payment_method_paths'  => isset($setup_args['payment_method_paths'])
500
+				? (array) $setup_args['payment_method_paths']
501
+				: array(),
502
+			'default_terms'         => isset($setup_args['default_terms'])
503
+				? (array) $setup_args['default_terms']
504
+				: array(),
505
+			// if not empty, inserts a new table row after this plugin's row on the WP Plugins page
506
+			// that can be used for adding upgrading/marketing info
507
+			'plugins_page_row'      => isset($setup_args['plugins_page_row'])
508
+				? $setup_args['plugins_page_row']
509
+				: '',
510
+			'namespace'             => isset(
511
+				$setup_args['namespace']['FQNS'],
512
+				$setup_args['namespace']['DIR']
513
+			)
514
+				? (array) $setup_args['namespace']
515
+				: array(),
516
+			'privacy_policies'      => isset($setup_args['privacy_policies'])
517
+				? (array) $setup_args['privacy_policies']
518
+				: '',
519
+		);
520
+		// if plugin_action_slug is NOT set, but an admin page path IS set,
521
+		// then let's just use the plugin_slug since that will be used for linking to the admin page
522
+		$addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
523
+												&& ! empty($addon_settings['admin_path'])
524
+			? $addon_settings['plugin_slug']
525
+			: $addon_settings['plugin_action_slug'];
526
+		// full server path to main file (file loaded directly by WP)
527
+		$addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
528
+		return $addon_settings;
529
+	}
530 530
 
531 531
 
532
-    /**
533
-     * @param string $addon_name
534
-     * @param array  $addon_settings
535
-     * @return boolean
536
-     */
537
-    private static function _addon_is_compatible($addon_name, array $addon_settings)
538
-    {
539
-        global $wp_version;
540
-        $incompatibility_message = '';
541
-        // check whether this addon version is compatible with EE core
542
-        if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
543
-            && ! self::_meets_min_core_version_requirement(
544
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
545
-                $addon_settings['version']
546
-            )
547
-        ) {
548
-            $incompatibility_message = sprintf(
549
-                __(
550
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.',
551
-                    'event_espresso'
552
-                ),
553
-                $addon_name,
554
-                '<br />',
555
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
556
-                '<span style="font-weight: bold; color: #D54E21;">',
557
-                '</span><br />'
558
-            );
559
-        } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
560
-        ) {
561
-            $incompatibility_message = sprintf(
562
-                __(
563
-                    '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
564
-                    'event_espresso'
565
-                ),
566
-                $addon_name,
567
-                self::_effective_version($addon_settings['min_core_version']),
568
-                self::_effective_version(espresso_version()),
569
-                '<br />',
570
-                '<span style="font-weight: bold; color: #D54E21;">',
571
-                '</span><br />'
572
-            );
573
-        } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
574
-            $incompatibility_message = sprintf(
575
-                __(
576
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
577
-                    'event_espresso'
578
-                ),
579
-                $addon_name,
580
-                $addon_settings['min_wp_version'],
581
-                '<br />',
582
-                '<span style="font-weight: bold; color: #D54E21;">',
583
-                '</span><br />'
584
-            );
585
-        }
586
-        if (! empty($incompatibility_message)) {
587
-            // remove 'activate' from the REQUEST
588
-            // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
589
-            unset($_GET['activate'], $_REQUEST['activate']);
590
-            if (current_user_can('activate_plugins')) {
591
-                // show an error message indicating the plugin didn't activate properly
592
-                EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
593
-            }
594
-            // BAIL FROM THE ADDON REGISTRATION PROCESS
595
-            return false;
596
-        }
597
-        // addon IS compatible
598
-        return true;
599
-    }
532
+	/**
533
+	 * @param string $addon_name
534
+	 * @param array  $addon_settings
535
+	 * @return boolean
536
+	 */
537
+	private static function _addon_is_compatible($addon_name, array $addon_settings)
538
+	{
539
+		global $wp_version;
540
+		$incompatibility_message = '';
541
+		// check whether this addon version is compatible with EE core
542
+		if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
543
+			&& ! self::_meets_min_core_version_requirement(
544
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
545
+				$addon_settings['version']
546
+			)
547
+		) {
548
+			$incompatibility_message = sprintf(
549
+				__(
550
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.',
551
+					'event_espresso'
552
+				),
553
+				$addon_name,
554
+				'<br />',
555
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
556
+				'<span style="font-weight: bold; color: #D54E21;">',
557
+				'</span><br />'
558
+			);
559
+		} elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
560
+		) {
561
+			$incompatibility_message = sprintf(
562
+				__(
563
+					'%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
564
+					'event_espresso'
565
+				),
566
+				$addon_name,
567
+				self::_effective_version($addon_settings['min_core_version']),
568
+				self::_effective_version(espresso_version()),
569
+				'<br />',
570
+				'<span style="font-weight: bold; color: #D54E21;">',
571
+				'</span><br />'
572
+			);
573
+		} elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
574
+			$incompatibility_message = sprintf(
575
+				__(
576
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
577
+					'event_espresso'
578
+				),
579
+				$addon_name,
580
+				$addon_settings['min_wp_version'],
581
+				'<br />',
582
+				'<span style="font-weight: bold; color: #D54E21;">',
583
+				'</span><br />'
584
+			);
585
+		}
586
+		if (! empty($incompatibility_message)) {
587
+			// remove 'activate' from the REQUEST
588
+			// so WP doesn't erroneously tell the user the plugin activated fine when it didn't
589
+			unset($_GET['activate'], $_REQUEST['activate']);
590
+			if (current_user_can('activate_plugins')) {
591
+				// show an error message indicating the plugin didn't activate properly
592
+				EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
593
+			}
594
+			// BAIL FROM THE ADDON REGISTRATION PROCESS
595
+			return false;
596
+		}
597
+		// addon IS compatible
598
+		return true;
599
+	}
600 600
 
601 601
 
602
-    /**
603
-     * if plugin update engine is being used for auto-updates,
604
-     * then let's set that up now before going any further so that ALL addons can be updated
605
-     * (not needed if PUE is not being used)
606
-     *
607
-     * @param string $addon_name
608
-     * @param string $class_name
609
-     * @param array  $setup_args
610
-     * @return void
611
-     */
612
-    private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
613
-    {
614
-        if (! empty($setup_args['pue_options'])) {
615
-            self::$_settings[ $addon_name ]['pue_options'] = array(
616
-                'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
617
-                    ? (string) $setup_args['pue_options']['pue_plugin_slug']
618
-                    : 'espresso_' . strtolower($class_name),
619
-                'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
620
-                    ? (string) $setup_args['pue_options']['plugin_basename']
621
-                    : plugin_basename($setup_args['main_file_path']),
622
-                'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
623
-                    ? (string) $setup_args['pue_options']['checkPeriod']
624
-                    : '24',
625
-                'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
626
-                    ? (string) $setup_args['pue_options']['use_wp_update']
627
-                    : false,
628
-            );
629
-            add_action(
630
-                'AHEE__EE_System__brew_espresso__after_pue_init',
631
-                array('EE_Register_Addon', 'load_pue_update')
632
-            );
633
-        }
634
-    }
602
+	/**
603
+	 * if plugin update engine is being used for auto-updates,
604
+	 * then let's set that up now before going any further so that ALL addons can be updated
605
+	 * (not needed if PUE is not being used)
606
+	 *
607
+	 * @param string $addon_name
608
+	 * @param string $class_name
609
+	 * @param array  $setup_args
610
+	 * @return void
611
+	 */
612
+	private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
613
+	{
614
+		if (! empty($setup_args['pue_options'])) {
615
+			self::$_settings[ $addon_name ]['pue_options'] = array(
616
+				'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
617
+					? (string) $setup_args['pue_options']['pue_plugin_slug']
618
+					: 'espresso_' . strtolower($class_name),
619
+				'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
620
+					? (string) $setup_args['pue_options']['plugin_basename']
621
+					: plugin_basename($setup_args['main_file_path']),
622
+				'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
623
+					? (string) $setup_args['pue_options']['checkPeriod']
624
+					: '24',
625
+				'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
626
+					? (string) $setup_args['pue_options']['use_wp_update']
627
+					: false,
628
+			);
629
+			add_action(
630
+				'AHEE__EE_System__brew_espresso__after_pue_init',
631
+				array('EE_Register_Addon', 'load_pue_update')
632
+			);
633
+		}
634
+	}
635 635
 
636 636
 
637
-    /**
638
-     * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
639
-     *
640
-     * @param array $addon_settings
641
-     * @return void
642
-     */
643
-    private static function _setup_namespaces(array $addon_settings)
644
-    {
645
-        //
646
-        if (isset(
647
-            $addon_settings['namespace']['FQNS'],
648
-            $addon_settings['namespace']['DIR']
649
-        )) {
650
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
651
-                $addon_settings['namespace']['FQNS'],
652
-                $addon_settings['namespace']['DIR']
653
-            );
654
-        }
655
-    }
637
+	/**
638
+	 * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
639
+	 *
640
+	 * @param array $addon_settings
641
+	 * @return void
642
+	 */
643
+	private static function _setup_namespaces(array $addon_settings)
644
+	{
645
+		//
646
+		if (isset(
647
+			$addon_settings['namespace']['FQNS'],
648
+			$addon_settings['namespace']['DIR']
649
+		)) {
650
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
651
+				$addon_settings['namespace']['FQNS'],
652
+				$addon_settings['namespace']['DIR']
653
+			);
654
+		}
655
+	}
656 656
 
657 657
 
658
-    /**
659
-     * @param string $addon_name
660
-     * @param array  $addon_settings
661
-     * @return bool
662
-     * @throws EE_Error
663
-     * @throws InvalidArgumentException
664
-     * @throws ReflectionException
665
-     * @throws InvalidDataTypeException
666
-     * @throws InvalidInterfaceException
667
-     */
668
-    private static function _addon_activation($addon_name, array $addon_settings)
669
-    {
670
-        // this is an activation request
671
-        if (did_action(
672
-            'activate_plugin'
673
-        )) {// to find if THIS is the addon that was activated, just check if we have already registered it or not
674
-            // (as the newly-activated addon wasn't around the first time addons were registered).
675
-            // Note: the presence of pue_options in the addon registration options will initialize the $_settings
676
-            // property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
677
-            if (! isset(self::$_settings[ $addon_name ])
678
-                || (isset(self::$_settings[ $addon_name ])
679
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
680
-                )
681
-            ) {
682
-                self::$_settings[ $addon_name ] = $addon_settings;
683
-                $addon = self::_load_and_init_addon_class($addon_name);
684
-                $addon->set_activation_indicator_option();
685
-                // dont bother setting up the rest of the addon.
686
-                // we know it was just activated and the request will end soon
687
-            }
688
-            return true;
689
-        }
690
-        // make sure this was called in the right place!
691
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
692
-            || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
693
-        ) {
694
-            EE_Error::doing_it_wrong(
695
-                __METHOD__,
696
-                sprintf(
697
-                    __(
698
-                        'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
699
-                        'event_espresso'
700
-                    ),
701
-                    $addon_name
702
-                ),
703
-                '4.3.0'
704
-            );
705
-        }
706
-        // make sure addon settings are set correctly without overwriting anything existing
707
-        if (isset(self::$_settings[ $addon_name ])) {
708
-            self::$_settings[ $addon_name ] += $addon_settings;
709
-        } else {
710
-            self::$_settings[ $addon_name ] = $addon_settings;
711
-        }
712
-        return false;
713
-    }
658
+	/**
659
+	 * @param string $addon_name
660
+	 * @param array  $addon_settings
661
+	 * @return bool
662
+	 * @throws EE_Error
663
+	 * @throws InvalidArgumentException
664
+	 * @throws ReflectionException
665
+	 * @throws InvalidDataTypeException
666
+	 * @throws InvalidInterfaceException
667
+	 */
668
+	private static function _addon_activation($addon_name, array $addon_settings)
669
+	{
670
+		// this is an activation request
671
+		if (did_action(
672
+			'activate_plugin'
673
+		)) {// to find if THIS is the addon that was activated, just check if we have already registered it or not
674
+			// (as the newly-activated addon wasn't around the first time addons were registered).
675
+			// Note: the presence of pue_options in the addon registration options will initialize the $_settings
676
+			// property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
677
+			if (! isset(self::$_settings[ $addon_name ])
678
+				|| (isset(self::$_settings[ $addon_name ])
679
+					&& ! isset(self::$_settings[ $addon_name ]['class_name'])
680
+				)
681
+			) {
682
+				self::$_settings[ $addon_name ] = $addon_settings;
683
+				$addon = self::_load_and_init_addon_class($addon_name);
684
+				$addon->set_activation_indicator_option();
685
+				// dont bother setting up the rest of the addon.
686
+				// we know it was just activated and the request will end soon
687
+			}
688
+			return true;
689
+		}
690
+		// make sure this was called in the right place!
691
+		if (! did_action('AHEE__EE_System__load_espresso_addons')
692
+			|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
693
+		) {
694
+			EE_Error::doing_it_wrong(
695
+				__METHOD__,
696
+				sprintf(
697
+					__(
698
+						'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
699
+						'event_espresso'
700
+					),
701
+					$addon_name
702
+				),
703
+				'4.3.0'
704
+			);
705
+		}
706
+		// make sure addon settings are set correctly without overwriting anything existing
707
+		if (isset(self::$_settings[ $addon_name ])) {
708
+			self::$_settings[ $addon_name ] += $addon_settings;
709
+		} else {
710
+			self::$_settings[ $addon_name ] = $addon_settings;
711
+		}
712
+		return false;
713
+	}
714 714
 
715 715
 
716
-    /**
717
-     * @param string $addon_name
718
-     * @return void
719
-     * @throws EE_Error
720
-     */
721
-    private static function _setup_autoloaders($addon_name)
722
-    {
723
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
724
-            // setup autoloader for single file
725
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
726
-        }
727
-        // setup autoloaders for folders
728
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
729
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
730
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
731
-            }
732
-        }
733
-    }
716
+	/**
717
+	 * @param string $addon_name
718
+	 * @return void
719
+	 * @throws EE_Error
720
+	 */
721
+	private static function _setup_autoloaders($addon_name)
722
+	{
723
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
724
+			// setup autoloader for single file
725
+			EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
726
+		}
727
+		// setup autoloaders for folders
728
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
729
+			foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
730
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
731
+			}
732
+		}
733
+	}
734 734
 
735 735
 
736
-    /**
737
-     * register new models and extensions
738
-     *
739
-     * @param string $addon_name
740
-     * @return void
741
-     * @throws EE_Error
742
-     */
743
-    private static function _register_models_and_extensions($addon_name)
744
-    {
745
-        // register new models
746
-        if (! empty(self::$_settings[ $addon_name ]['model_paths'])
747
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
748
-        ) {
749
-            EE_Register_Model::register(
750
-                $addon_name,
751
-                array(
752
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
753
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
754
-                )
755
-            );
756
-        }
757
-        // register model extensions
758
-        if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
759
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
760
-        ) {
761
-            EE_Register_Model_Extensions::register(
762
-                $addon_name,
763
-                array(
764
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
765
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
766
-                )
767
-            );
768
-        }
769
-    }
736
+	/**
737
+	 * register new models and extensions
738
+	 *
739
+	 * @param string $addon_name
740
+	 * @return void
741
+	 * @throws EE_Error
742
+	 */
743
+	private static function _register_models_and_extensions($addon_name)
744
+	{
745
+		// register new models
746
+		if (! empty(self::$_settings[ $addon_name ]['model_paths'])
747
+			|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
748
+		) {
749
+			EE_Register_Model::register(
750
+				$addon_name,
751
+				array(
752
+					'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
753
+					'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
754
+				)
755
+			);
756
+		}
757
+		// register model extensions
758
+		if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
759
+			|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
760
+		) {
761
+			EE_Register_Model_Extensions::register(
762
+				$addon_name,
763
+				array(
764
+					'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
765
+					'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
766
+				)
767
+			);
768
+		}
769
+	}
770 770
 
771 771
 
772
-    /**
773
-     * @param string $addon_name
774
-     * @return void
775
-     * @throws EE_Error
776
-     */
777
-    private static function _register_data_migration_scripts($addon_name)
778
-    {
779
-        // setup DMS
780
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
781
-            EE_Register_Data_Migration_Scripts::register(
782
-                $addon_name,
783
-                array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
784
-            );
785
-        }
786
-    }
772
+	/**
773
+	 * @param string $addon_name
774
+	 * @return void
775
+	 * @throws EE_Error
776
+	 */
777
+	private static function _register_data_migration_scripts($addon_name)
778
+	{
779
+		// setup DMS
780
+		if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
781
+			EE_Register_Data_Migration_Scripts::register(
782
+				$addon_name,
783
+				array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
784
+			);
785
+		}
786
+	}
787 787
 
788 788
 
789
-    /**
790
-     * @param string $addon_name
791
-     * @return void
792
-     * @throws EE_Error
793
-     */
794
-    private static function _register_config($addon_name)
795
-    {
796
-        // if config_class is present let's register config.
797
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
798
-            EE_Register_Config::register(
799
-                self::$_settings[ $addon_name ]['config_class'],
800
-                array(
801
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
802
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
803
-                )
804
-            );
805
-        }
806
-    }
789
+	/**
790
+	 * @param string $addon_name
791
+	 * @return void
792
+	 * @throws EE_Error
793
+	 */
794
+	private static function _register_config($addon_name)
795
+	{
796
+		// if config_class is present let's register config.
797
+		if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
798
+			EE_Register_Config::register(
799
+				self::$_settings[ $addon_name ]['config_class'],
800
+				array(
801
+					'config_section' => self::$_settings[ $addon_name ]['config_section'],
802
+					'config_name'    => self::$_settings[ $addon_name ]['config_name'],
803
+				)
804
+			);
805
+		}
806
+	}
807 807
 
808 808
 
809
-    /**
810
-     * @param string $addon_name
811
-     * @return void
812
-     * @throws EE_Error
813
-     */
814
-    private static function _register_admin_pages($addon_name)
815
-    {
816
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
817
-            EE_Register_Admin_Page::register(
818
-                $addon_name,
819
-                array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
820
-            );
821
-        }
822
-    }
809
+	/**
810
+	 * @param string $addon_name
811
+	 * @return void
812
+	 * @throws EE_Error
813
+	 */
814
+	private static function _register_admin_pages($addon_name)
815
+	{
816
+		if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
817
+			EE_Register_Admin_Page::register(
818
+				$addon_name,
819
+				array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
820
+			);
821
+		}
822
+	}
823 823
 
824 824
 
825
-    /**
826
-     * @param string $addon_name
827
-     * @return void
828
-     * @throws EE_Error
829
-     */
830
-    private static function _register_modules($addon_name)
831
-    {
832
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
833
-            EE_Register_Module::register(
834
-                $addon_name,
835
-                array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
836
-            );
837
-        }
838
-    }
825
+	/**
826
+	 * @param string $addon_name
827
+	 * @return void
828
+	 * @throws EE_Error
829
+	 */
830
+	private static function _register_modules($addon_name)
831
+	{
832
+		if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
833
+			EE_Register_Module::register(
834
+				$addon_name,
835
+				array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
836
+			);
837
+		}
838
+	}
839 839
 
840 840
 
841
-    /**
842
-     * @param string $addon_name
843
-     * @return void
844
-     * @throws EE_Error
845
-     */
846
-    private static function _register_shortcodes($addon_name)
847
-    {
848
-        if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
849
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
850
-        ) {
851
-            EE_Register_Shortcode::register(
852
-                $addon_name,
853
-                array(
854
-                    'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
855
-                        ? self::$_settings[ $addon_name ]['shortcode_paths']
856
-                        : array(),
857
-                    'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
858
-                        ? self::$_settings[ $addon_name ]['shortcode_fqcns']
859
-                        : array(),
860
-                )
861
-            );
862
-        }
863
-    }
841
+	/**
842
+	 * @param string $addon_name
843
+	 * @return void
844
+	 * @throws EE_Error
845
+	 */
846
+	private static function _register_shortcodes($addon_name)
847
+	{
848
+		if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
849
+			|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
850
+		) {
851
+			EE_Register_Shortcode::register(
852
+				$addon_name,
853
+				array(
854
+					'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
855
+						? self::$_settings[ $addon_name ]['shortcode_paths']
856
+						: array(),
857
+					'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
858
+						? self::$_settings[ $addon_name ]['shortcode_fqcns']
859
+						: array(),
860
+				)
861
+			);
862
+		}
863
+	}
864 864
 
865 865
 
866
-    /**
867
-     * @param string $addon_name
868
-     * @return void
869
-     * @throws EE_Error
870
-     */
871
-    private static function _register_widgets($addon_name)
872
-    {
873
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
874
-            EE_Register_Widget::register(
875
-                $addon_name,
876
-                array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
877
-            );
878
-        }
879
-    }
866
+	/**
867
+	 * @param string $addon_name
868
+	 * @return void
869
+	 * @throws EE_Error
870
+	 */
871
+	private static function _register_widgets($addon_name)
872
+	{
873
+		if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
874
+			EE_Register_Widget::register(
875
+				$addon_name,
876
+				array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
877
+			);
878
+		}
879
+	}
880 880
 
881 881
 
882
-    /**
883
-     * @param string $addon_name
884
-     * @return void
885
-     * @throws EE_Error
886
-     */
887
-    private static function _register_capabilities($addon_name)
888
-    {
889
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
890
-            EE_Register_Capabilities::register(
891
-                $addon_name,
892
-                array(
893
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
894
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
895
-                )
896
-            );
897
-        }
898
-    }
882
+	/**
883
+	 * @param string $addon_name
884
+	 * @return void
885
+	 * @throws EE_Error
886
+	 */
887
+	private static function _register_capabilities($addon_name)
888
+	{
889
+		if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
890
+			EE_Register_Capabilities::register(
891
+				$addon_name,
892
+				array(
893
+					'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
894
+					'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
895
+				)
896
+			);
897
+		}
898
+	}
899 899
 
900 900
 
901
-    /**
902
-     * @param string $addon_name
903
-     * @return void
904
-     * @throws EE_Error
905
-     */
906
-    private static function _register_message_types($addon_name)
907
-    {
908
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
909
-            add_action(
910
-                'EE_Brewing_Regular___messages_caf',
911
-                array('EE_Register_Addon', 'register_message_types')
912
-            );
913
-        }
914
-    }
901
+	/**
902
+	 * @param string $addon_name
903
+	 * @return void
904
+	 * @throws EE_Error
905
+	 */
906
+	private static function _register_message_types($addon_name)
907
+	{
908
+		if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
909
+			add_action(
910
+				'EE_Brewing_Regular___messages_caf',
911
+				array('EE_Register_Addon', 'register_message_types')
912
+			);
913
+		}
914
+	}
915 915
 
916 916
 
917
-    /**
918
-     * @param string $addon_name
919
-     * @return void
920
-     * @throws EE_Error
921
-     */
922
-    private static function _register_custom_post_types($addon_name)
923
-    {
924
-        if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])
925
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
926
-        ) {
927
-            EE_Register_CPT::register(
928
-                $addon_name,
929
-                array(
930
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
931
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
932
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
933
-                )
934
-            );
935
-        }
936
-    }
917
+	/**
918
+	 * @param string $addon_name
919
+	 * @return void
920
+	 * @throws EE_Error
921
+	 */
922
+	private static function _register_custom_post_types($addon_name)
923
+	{
924
+		if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])
925
+			|| ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
926
+		) {
927
+			EE_Register_CPT::register(
928
+				$addon_name,
929
+				array(
930
+					'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
931
+					'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
932
+					'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
933
+				)
934
+			);
935
+		}
936
+	}
937 937
 
938 938
 
939
-    /**
940
-     * @param string $addon_name
941
-     * @return void
942
-     * @throws InvalidArgumentException
943
-     * @throws InvalidInterfaceException
944
-     * @throws InvalidDataTypeException
945
-     * @throws DomainException
946
-     * @throws EE_Error
947
-     */
948
-    private static function _register_payment_methods($addon_name)
949
-    {
950
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
951
-            EE_Register_Payment_Method::register(
952
-                $addon_name,
953
-                array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
954
-            );
955
-        }
956
-    }
939
+	/**
940
+	 * @param string $addon_name
941
+	 * @return void
942
+	 * @throws InvalidArgumentException
943
+	 * @throws InvalidInterfaceException
944
+	 * @throws InvalidDataTypeException
945
+	 * @throws DomainException
946
+	 * @throws EE_Error
947
+	 */
948
+	private static function _register_payment_methods($addon_name)
949
+	{
950
+		if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
951
+			EE_Register_Payment_Method::register(
952
+				$addon_name,
953
+				array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
954
+			);
955
+		}
956
+	}
957 957
 
958 958
 
959
-    /**
960
-     * @param string $addon_name
961
-     * @return void
962
-     * @throws InvalidArgumentException
963
-     * @throws InvalidInterfaceException
964
-     * @throws InvalidDataTypeException
965
-     * @throws DomainException
966
-     * @throws EE_Error
967
-     */
968
-    private static function registerPrivacyPolicies($addon_name)
969
-    {
970
-        if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
971
-            EE_Register_Privacy_Policy::register(
972
-                $addon_name,
973
-                self::$_settings[ $addon_name ]['privacy_policies']
974
-            );
975
-        }
976
-    }
959
+	/**
960
+	 * @param string $addon_name
961
+	 * @return void
962
+	 * @throws InvalidArgumentException
963
+	 * @throws InvalidInterfaceException
964
+	 * @throws InvalidDataTypeException
965
+	 * @throws DomainException
966
+	 * @throws EE_Error
967
+	 */
968
+	private static function registerPrivacyPolicies($addon_name)
969
+	{
970
+		if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
971
+			EE_Register_Privacy_Policy::register(
972
+				$addon_name,
973
+				self::$_settings[ $addon_name ]['privacy_policies']
974
+			);
975
+		}
976
+	}
977 977
 
978 978
 
979
-    /**
980
-     * @param string $addon_name
981
-     * @return void
982
-     */
983
-    private static function registerPersonalDataExporters($addon_name)
984
-    {
985
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
986
-            EE_Register_Personal_Data_Eraser::register(
987
-                $addon_name,
988
-                self::$_settings[ $addon_name ]['personal_data_exporters']
989
-            );
990
-        }
991
-    }
979
+	/**
980
+	 * @param string $addon_name
981
+	 * @return void
982
+	 */
983
+	private static function registerPersonalDataExporters($addon_name)
984
+	{
985
+		if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
986
+			EE_Register_Personal_Data_Eraser::register(
987
+				$addon_name,
988
+				self::$_settings[ $addon_name ]['personal_data_exporters']
989
+			);
990
+		}
991
+	}
992 992
 
993 993
 
994
-    /**
995
-     * @param string $addon_name
996
-     * @return void
997
-     */
998
-    private static function registerPersonalDataErasers($addon_name)
999
-    {
1000
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
1001
-            EE_Register_Personal_Data_Eraser::register(
1002
-                $addon_name,
1003
-                self::$_settings[ $addon_name ]['personal_data_erasers']
1004
-            );
1005
-        }
1006
-    }
994
+	/**
995
+	 * @param string $addon_name
996
+	 * @return void
997
+	 */
998
+	private static function registerPersonalDataErasers($addon_name)
999
+	{
1000
+		if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
1001
+			EE_Register_Personal_Data_Eraser::register(
1002
+				$addon_name,
1003
+				self::$_settings[ $addon_name ]['personal_data_erasers']
1004
+			);
1005
+		}
1006
+	}
1007 1007
 
1008 1008
 
1009
-    /**
1010
-     * Loads and instantiates the EE_Addon class and adds it onto the registry
1011
-     *
1012
-     * @param string $addon_name
1013
-     * @return EE_Addon
1014
-     * @throws InvalidArgumentException
1015
-     * @throws InvalidInterfaceException
1016
-     * @throws InvalidDataTypeException
1017
-     * @throws ReflectionException
1018
-     * @throws EE_Error
1019
-     */
1020
-    private static function _load_and_init_addon_class($addon_name)
1021
-    {
1022
-        $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader();
1023
-        $addon = $loader->getShared(
1024
-            self::$_settings[ $addon_name ]['class_name'],
1025
-            array('EE_Registry::create(addon)' => true)
1026
-        );
1027
-        // setter inject dep map if required
1028
-        if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) {
1029
-            $addon->setDependencyMap($loader->getShared('EE_Dependency_Map'));
1030
-        }
1031
-        // setter inject domain if required
1032
-        if ($addon instanceof RequiresDomainInterface
1033
-            && $addon->domain() === null
1034
-        ) {
1035
-            // using supplied Domain object
1036
-            $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1037
-                ? self::$_settings[ $addon_name ]['domain']
1038
-                : null;
1039
-            // or construct one using Domain FQCN
1040
-            if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1041
-                $domain = $loader->getShared(
1042
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
1043
-                    array(
1044
-                        new EventEspresso\core\domain\values\FilePath(
1045
-                            self::$_settings[ $addon_name ]['main_file_path']
1046
-                        ),
1047
-                        EventEspresso\core\domain\values\Version::fromString(
1048
-                            self::$_settings[ $addon_name ]['version']
1049
-                        ),
1050
-                    )
1051
-                );
1052
-            }
1053
-            if ($domain instanceof DomainInterface) {
1054
-                $addon->setDomain($domain);
1055
-            }
1056
-        }
1057
-        $addon->set_name($addon_name);
1058
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1059
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1060
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1061
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1062
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1063
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
1064
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1065
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1066
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1067
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1068
-        // setup the add-on's pue_slug if we have one.
1069
-        if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) {
1070
-            $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']);
1071
-        }
1072
-        // unfortunately this can't be hooked in upon construction, because we don't have
1073
-        // the plugin mainfile's path upon construction.
1074
-        register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
1075
-        // call any additional admin_callback functions during load_admin_controller hook
1076
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1077
-            add_action(
1078
-                'AHEE__EE_System__load_controllers__load_admin_controllers',
1079
-                array($addon, self::$_settings[ $addon_name ]['admin_callback'])
1080
-            );
1081
-        }
1082
-        return $addon;
1083
-    }
1009
+	/**
1010
+	 * Loads and instantiates the EE_Addon class and adds it onto the registry
1011
+	 *
1012
+	 * @param string $addon_name
1013
+	 * @return EE_Addon
1014
+	 * @throws InvalidArgumentException
1015
+	 * @throws InvalidInterfaceException
1016
+	 * @throws InvalidDataTypeException
1017
+	 * @throws ReflectionException
1018
+	 * @throws EE_Error
1019
+	 */
1020
+	private static function _load_and_init_addon_class($addon_name)
1021
+	{
1022
+		$loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader();
1023
+		$addon = $loader->getShared(
1024
+			self::$_settings[ $addon_name ]['class_name'],
1025
+			array('EE_Registry::create(addon)' => true)
1026
+		);
1027
+		// setter inject dep map if required
1028
+		if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) {
1029
+			$addon->setDependencyMap($loader->getShared('EE_Dependency_Map'));
1030
+		}
1031
+		// setter inject domain if required
1032
+		if ($addon instanceof RequiresDomainInterface
1033
+			&& $addon->domain() === null
1034
+		) {
1035
+			// using supplied Domain object
1036
+			$domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1037
+				? self::$_settings[ $addon_name ]['domain']
1038
+				: null;
1039
+			// or construct one using Domain FQCN
1040
+			if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1041
+				$domain = $loader->getShared(
1042
+					self::$_settings[ $addon_name ]['domain_fqcn'],
1043
+					array(
1044
+						new EventEspresso\core\domain\values\FilePath(
1045
+							self::$_settings[ $addon_name ]['main_file_path']
1046
+						),
1047
+						EventEspresso\core\domain\values\Version::fromString(
1048
+							self::$_settings[ $addon_name ]['version']
1049
+						),
1050
+					)
1051
+				);
1052
+			}
1053
+			if ($domain instanceof DomainInterface) {
1054
+				$addon->setDomain($domain);
1055
+			}
1056
+		}
1057
+		$addon->set_name($addon_name);
1058
+		$addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1059
+		$addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1060
+		$addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1061
+		$addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1062
+		$addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1063
+		$addon->set_version(self::$_settings[ $addon_name ]['version']);
1064
+		$addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1065
+		$addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1066
+		$addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1067
+		$addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1068
+		// setup the add-on's pue_slug if we have one.
1069
+		if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) {
1070
+			$addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']);
1071
+		}
1072
+		// unfortunately this can't be hooked in upon construction, because we don't have
1073
+		// the plugin mainfile's path upon construction.
1074
+		register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
1075
+		// call any additional admin_callback functions during load_admin_controller hook
1076
+		if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1077
+			add_action(
1078
+				'AHEE__EE_System__load_controllers__load_admin_controllers',
1079
+				array($addon, self::$_settings[ $addon_name ]['admin_callback'])
1080
+			);
1081
+		}
1082
+		return $addon;
1083
+	}
1084 1084
 
1085 1085
 
1086
-    /**
1087
-     *    load_pue_update - Update notifications
1088
-     *
1089
-     * @return void
1090
-     * @throws InvalidArgumentException
1091
-     * @throws InvalidDataTypeException
1092
-     * @throws InvalidInterfaceException
1093
-     */
1094
-    public static function load_pue_update()
1095
-    {
1096
-        // load PUE client
1097
-        require_once EE_THIRD_PARTY . 'pue/pue-client.php';
1098
-        $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
1099
-        // cycle thru settings
1100
-        foreach (self::$_settings as $settings) {
1101
-            if (! empty($settings['pue_options'])) {
1102
-                // initiate the class and start the plugin update engine!
1103
-                new PluginUpdateEngineChecker(
1104
-                    // host file URL
1105
-                    $license_server,
1106
-                    // plugin slug(s)
1107
-                    array(
1108
-                        'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1109
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1110
-                    ),
1111
-                    // options
1112
-                    array(
1113
-                        'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
1114
-                        'lang_domain'       => 'event_espresso',
1115
-                        'checkPeriod'       => $settings['pue_options']['checkPeriod'],
1116
-                        'option_key'        => 'ee_site_license_key',
1117
-                        'options_page_slug' => 'event_espresso',
1118
-                        'plugin_basename'   => $settings['pue_options']['plugin_basename'],
1119
-                        // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
1120
-                        'use_wp_update'     => $settings['pue_options']['use_wp_update'],
1121
-                    )
1122
-                );
1123
-            }
1124
-        }
1125
-    }
1086
+	/**
1087
+	 *    load_pue_update - Update notifications
1088
+	 *
1089
+	 * @return void
1090
+	 * @throws InvalidArgumentException
1091
+	 * @throws InvalidDataTypeException
1092
+	 * @throws InvalidInterfaceException
1093
+	 */
1094
+	public static function load_pue_update()
1095
+	{
1096
+		// load PUE client
1097
+		require_once EE_THIRD_PARTY . 'pue/pue-client.php';
1098
+		$license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
1099
+		// cycle thru settings
1100
+		foreach (self::$_settings as $settings) {
1101
+			if (! empty($settings['pue_options'])) {
1102
+				// initiate the class and start the plugin update engine!
1103
+				new PluginUpdateEngineChecker(
1104
+					// host file URL
1105
+					$license_server,
1106
+					// plugin slug(s)
1107
+					array(
1108
+						'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1109
+						'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1110
+					),
1111
+					// options
1112
+					array(
1113
+						'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
1114
+						'lang_domain'       => 'event_espresso',
1115
+						'checkPeriod'       => $settings['pue_options']['checkPeriod'],
1116
+						'option_key'        => 'ee_site_license_key',
1117
+						'options_page_slug' => 'event_espresso',
1118
+						'plugin_basename'   => $settings['pue_options']['plugin_basename'],
1119
+						// if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
1120
+						'use_wp_update'     => $settings['pue_options']['use_wp_update'],
1121
+					)
1122
+				);
1123
+			}
1124
+		}
1125
+	}
1126 1126
 
1127 1127
 
1128
-    /**
1129
-     * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1130
-     *
1131
-     * @since 4.4.0
1132
-     * @return void
1133
-     * @throws EE_Error
1134
-     */
1135
-    public static function register_message_types()
1136
-    {
1137
-        foreach (self::$_settings as $addon_name => $settings) {
1138
-            if (! empty($settings['message_types'])) {
1139
-                foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1140
-                    EE_Register_Message_Type::register($message_type, $message_type_settings);
1141
-                }
1142
-            }
1143
-        }
1144
-    }
1128
+	/**
1129
+	 * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1130
+	 *
1131
+	 * @since 4.4.0
1132
+	 * @return void
1133
+	 * @throws EE_Error
1134
+	 */
1135
+	public static function register_message_types()
1136
+	{
1137
+		foreach (self::$_settings as $addon_name => $settings) {
1138
+			if (! empty($settings['message_types'])) {
1139
+				foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1140
+					EE_Register_Message_Type::register($message_type, $message_type_settings);
1141
+				}
1142
+			}
1143
+		}
1144
+	}
1145 1145
 
1146 1146
 
1147
-    /**
1148
-     * This deregisters an addon that was previously registered with a specific addon_name.
1149
-     *
1150
-     * @since    4.3.0
1151
-     * @param string $addon_name the name for the addon that was previously registered
1152
-     * @throws DomainException
1153
-     * @throws EE_Error
1154
-     * @throws InvalidArgumentException
1155
-     * @throws InvalidDataTypeException
1156
-     * @throws InvalidInterfaceException
1157
-     */
1158
-    public static function deregister($addon_name = null)
1159
-    {
1160
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1161
-            try {
1162
-                do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1163
-                $class_name = self::$_settings[ $addon_name ]['class_name'];
1164
-                if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1165
-                    // setup DMS
1166
-                    EE_Register_Data_Migration_Scripts::deregister($addon_name);
1167
-                }
1168
-                if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1169
-                    // register admin page
1170
-                    EE_Register_Admin_Page::deregister($addon_name);
1171
-                }
1172
-                if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1173
-                    // add to list of modules to be registered
1174
-                    EE_Register_Module::deregister($addon_name);
1175
-                }
1176
-                if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1177
-                    || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1178
-                ) {
1179
-                    // add to list of shortcodes to be registered
1180
-                    EE_Register_Shortcode::deregister($addon_name);
1181
-                }
1182
-                if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1183
-                    // if config_class present let's register config.
1184
-                    EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1185
-                }
1186
-                if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1187
-                    // add to list of widgets to be registered
1188
-                    EE_Register_Widget::deregister($addon_name);
1189
-                }
1190
-                if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1191
-                    || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1192
-                ) {
1193
-                    // add to list of shortcodes to be registered
1194
-                    EE_Register_Model::deregister($addon_name);
1195
-                }
1196
-                if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1197
-                    || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1198
-                ) {
1199
-                    // add to list of shortcodes to be registered
1200
-                    EE_Register_Model_Extensions::deregister($addon_name);
1201
-                }
1202
-                if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1203
-                    foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1204
-                        EE_Register_Message_Type::deregister($message_type);
1205
-                    }
1206
-                }
1207
-                // deregister capabilities for addon
1208
-                if (! empty(self::$_settings[ $addon_name ]['capabilities'])
1209
-                    || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1210
-                ) {
1211
-                    EE_Register_Capabilities::deregister($addon_name);
1212
-                }
1213
-                // deregister custom_post_types for addon
1214
-                if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1215
-                    EE_Register_CPT::deregister($addon_name);
1216
-                }
1217
-                if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1218
-                    EE_Register_Payment_Method::deregister($addon_name);
1219
-                }
1220
-                $addon = EE_Registry::instance()->getAddon($class_name);
1221
-                if ($addon instanceof EE_Addon) {
1222
-                    remove_action(
1223
-                        'deactivate_' . $addon->get_main_plugin_file_basename(),
1224
-                        array($addon, 'deactivation')
1225
-                    );
1226
-                    remove_action(
1227
-                        'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1228
-                        array($addon, 'initialize_db_if_no_migrations_required')
1229
-                    );
1230
-                    // remove `after_registration` call
1231
-                    remove_action(
1232
-                        'AHEE__EE_System__load_espresso_addons__complete',
1233
-                        array($addon, 'after_registration'),
1234
-                        999
1235
-                    );
1236
-                }
1237
-                EE_Registry::instance()->removeAddon($class_name);
1238
-            } catch (OutOfBoundsException $addon_not_yet_registered_exception) {
1239
-                // the add-on was not yet registered in the registry,
1240
-                // so RegistryContainer::__get() throws this exception.
1241
-                // also no need to worry about this or log it,
1242
-                // it's ok to deregister an add-on before its registered in the registry
1243
-            } catch (Exception $e) {
1244
-                new ExceptionLogger($e);
1245
-            }
1246
-            unset(self::$_settings[ $addon_name ]);
1247
-            do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1248
-        }
1249
-    }
1147
+	/**
1148
+	 * This deregisters an addon that was previously registered with a specific addon_name.
1149
+	 *
1150
+	 * @since    4.3.0
1151
+	 * @param string $addon_name the name for the addon that was previously registered
1152
+	 * @throws DomainException
1153
+	 * @throws EE_Error
1154
+	 * @throws InvalidArgumentException
1155
+	 * @throws InvalidDataTypeException
1156
+	 * @throws InvalidInterfaceException
1157
+	 */
1158
+	public static function deregister($addon_name = null)
1159
+	{
1160
+		if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1161
+			try {
1162
+				do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1163
+				$class_name = self::$_settings[ $addon_name ]['class_name'];
1164
+				if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1165
+					// setup DMS
1166
+					EE_Register_Data_Migration_Scripts::deregister($addon_name);
1167
+				}
1168
+				if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1169
+					// register admin page
1170
+					EE_Register_Admin_Page::deregister($addon_name);
1171
+				}
1172
+				if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1173
+					// add to list of modules to be registered
1174
+					EE_Register_Module::deregister($addon_name);
1175
+				}
1176
+				if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1177
+					|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1178
+				) {
1179
+					// add to list of shortcodes to be registered
1180
+					EE_Register_Shortcode::deregister($addon_name);
1181
+				}
1182
+				if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1183
+					// if config_class present let's register config.
1184
+					EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1185
+				}
1186
+				if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1187
+					// add to list of widgets to be registered
1188
+					EE_Register_Widget::deregister($addon_name);
1189
+				}
1190
+				if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1191
+					|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
1192
+				) {
1193
+					// add to list of shortcodes to be registered
1194
+					EE_Register_Model::deregister($addon_name);
1195
+				}
1196
+				if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1197
+					|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1198
+				) {
1199
+					// add to list of shortcodes to be registered
1200
+					EE_Register_Model_Extensions::deregister($addon_name);
1201
+				}
1202
+				if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1203
+					foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1204
+						EE_Register_Message_Type::deregister($message_type);
1205
+					}
1206
+				}
1207
+				// deregister capabilities for addon
1208
+				if (! empty(self::$_settings[ $addon_name ]['capabilities'])
1209
+					|| ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1210
+				) {
1211
+					EE_Register_Capabilities::deregister($addon_name);
1212
+				}
1213
+				// deregister custom_post_types for addon
1214
+				if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1215
+					EE_Register_CPT::deregister($addon_name);
1216
+				}
1217
+				if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1218
+					EE_Register_Payment_Method::deregister($addon_name);
1219
+				}
1220
+				$addon = EE_Registry::instance()->getAddon($class_name);
1221
+				if ($addon instanceof EE_Addon) {
1222
+					remove_action(
1223
+						'deactivate_' . $addon->get_main_plugin_file_basename(),
1224
+						array($addon, 'deactivation')
1225
+					);
1226
+					remove_action(
1227
+						'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1228
+						array($addon, 'initialize_db_if_no_migrations_required')
1229
+					);
1230
+					// remove `after_registration` call
1231
+					remove_action(
1232
+						'AHEE__EE_System__load_espresso_addons__complete',
1233
+						array($addon, 'after_registration'),
1234
+						999
1235
+					);
1236
+				}
1237
+				EE_Registry::instance()->removeAddon($class_name);
1238
+			} catch (OutOfBoundsException $addon_not_yet_registered_exception) {
1239
+				// the add-on was not yet registered in the registry,
1240
+				// so RegistryContainer::__get() throws this exception.
1241
+				// also no need to worry about this or log it,
1242
+				// it's ok to deregister an add-on before its registered in the registry
1243
+			} catch (Exception $e) {
1244
+				new ExceptionLogger($e);
1245
+			}
1246
+			unset(self::$_settings[ $addon_name ]);
1247
+			do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1248
+		}
1249
+	}
1250 1250
 }
Please login to merge, or discard this patch.
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -69,15 +69,15 @@  discard block
 block discarded – undo
69 69
         // offsets:    0 . 1 . 2 . 3 . 4
70 70
         $version_parts = explode('.', $min_core_version);
71 71
         // check they specified the micro version (after 2nd period)
72
-        if (! isset($version_parts[2])) {
72
+        if ( ! isset($version_parts[2])) {
73 73
             $version_parts[2] = '0';
74 74
         }
75 75
         // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
76 76
         // soon we can assume that's 'rc', but this current version is 'alpha'
77
-        if (! isset($version_parts[3])) {
77
+        if ( ! isset($version_parts[3])) {
78 78
             $version_parts[3] = 'dev';
79 79
         }
80
-        if (! isset($version_parts[4])) {
80
+        if ( ! isset($version_parts[4])) {
81 81
             $version_parts[4] = '000';
82 82
         }
83 83
         return implode('.', $version_parts);
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
         // setup PUE
265 265
         EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
266 266
         // does this addon work with this version of core or WordPress ?
267
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
267
+        if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
268 268
             return;
269 269
         }
270 270
         // register namespaces
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
                 )
329 329
             );
330 330
         }
331
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
331
+        if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
332 332
             throw new EE_Error(
333 333
                 sprintf(
334 334
                     __(
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
             );
341 341
         }
342 342
         // check that addon has not already been registered with that name
343
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
343
+        if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
344 344
             throw new EE_Error(
345 345
                 sprintf(
346 346
                     __(
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
         // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
373 373
         return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
374 374
             ? $class_name
375
-            : 'EE_' . $class_name;
375
+            : 'EE_'.$class_name;
376 376
     }
377 377
 
378 378
 
@@ -539,9 +539,9 @@  discard block
 block discarded – undo
539 539
         global $wp_version;
540 540
         $incompatibility_message = '';
541 541
         // check whether this addon version is compatible with EE core
542
-        if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
542
+        if (isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
543 543
             && ! self::_meets_min_core_version_requirement(
544
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
544
+                EE_Register_Addon::$_incompatible_addons[$addon_name],
545 545
                 $addon_settings['version']
546 546
             )
547 547
         ) {
@@ -552,11 +552,11 @@  discard block
 block discarded – undo
552 552
                 ),
553 553
                 $addon_name,
554 554
                 '<br />',
555
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
555
+                EE_Register_Addon::$_incompatible_addons[$addon_name],
556 556
                 '<span style="font-weight: bold; color: #D54E21;">',
557 557
                 '</span><br />'
558 558
             );
559
-        } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
559
+        } elseif ( ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
560 560
         ) {
561 561
             $incompatibility_message = sprintf(
562 562
                 __(
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
                 '</span><br />'
584 584
             );
585 585
         }
586
-        if (! empty($incompatibility_message)) {
586
+        if ( ! empty($incompatibility_message)) {
587 587
             // remove 'activate' from the REQUEST
588 588
             // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
589 589
             unset($_GET['activate'], $_REQUEST['activate']);
@@ -611,11 +611,11 @@  discard block
 block discarded – undo
611 611
      */
612 612
     private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
613 613
     {
614
-        if (! empty($setup_args['pue_options'])) {
615
-            self::$_settings[ $addon_name ]['pue_options'] = array(
614
+        if ( ! empty($setup_args['pue_options'])) {
615
+            self::$_settings[$addon_name]['pue_options'] = array(
616 616
                 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
617 617
                     ? (string) $setup_args['pue_options']['pue_plugin_slug']
618
-                    : 'espresso_' . strtolower($class_name),
618
+                    : 'espresso_'.strtolower($class_name),
619 619
                 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
620 620
                     ? (string) $setup_args['pue_options']['plugin_basename']
621 621
                     : plugin_basename($setup_args['main_file_path']),
@@ -674,12 +674,12 @@  discard block
 block discarded – undo
674 674
             // (as the newly-activated addon wasn't around the first time addons were registered).
675 675
             // Note: the presence of pue_options in the addon registration options will initialize the $_settings
676 676
             // property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
677
-            if (! isset(self::$_settings[ $addon_name ])
678
-                || (isset(self::$_settings[ $addon_name ])
679
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
677
+            if ( ! isset(self::$_settings[$addon_name])
678
+                || (isset(self::$_settings[$addon_name])
679
+                    && ! isset(self::$_settings[$addon_name]['class_name'])
680 680
                 )
681 681
             ) {
682
-                self::$_settings[ $addon_name ] = $addon_settings;
682
+                self::$_settings[$addon_name] = $addon_settings;
683 683
                 $addon = self::_load_and_init_addon_class($addon_name);
684 684
                 $addon->set_activation_indicator_option();
685 685
                 // dont bother setting up the rest of the addon.
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
             return true;
689 689
         }
690 690
         // make sure this was called in the right place!
691
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
691
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons')
692 692
             || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
693 693
         ) {
694 694
             EE_Error::doing_it_wrong(
@@ -704,10 +704,10 @@  discard block
 block discarded – undo
704 704
             );
705 705
         }
706 706
         // make sure addon settings are set correctly without overwriting anything existing
707
-        if (isset(self::$_settings[ $addon_name ])) {
708
-            self::$_settings[ $addon_name ] += $addon_settings;
707
+        if (isset(self::$_settings[$addon_name])) {
708
+            self::$_settings[$addon_name] += $addon_settings;
709 709
         } else {
710
-            self::$_settings[ $addon_name ] = $addon_settings;
710
+            self::$_settings[$addon_name] = $addon_settings;
711 711
         }
712 712
         return false;
713 713
     }
@@ -720,13 +720,13 @@  discard block
 block discarded – undo
720 720
      */
721 721
     private static function _setup_autoloaders($addon_name)
722 722
     {
723
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
723
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
724 724
             // setup autoloader for single file
725
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
725
+            EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
726 726
         }
727 727
         // setup autoloaders for folders
728
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
729
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
728
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
729
+            foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
730 730
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
731 731
             }
732 732
         }
@@ -743,26 +743,26 @@  discard block
 block discarded – undo
743 743
     private static function _register_models_and_extensions($addon_name)
744 744
     {
745 745
         // register new models
746
-        if (! empty(self::$_settings[ $addon_name ]['model_paths'])
747
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
746
+        if ( ! empty(self::$_settings[$addon_name]['model_paths'])
747
+            || ! empty(self::$_settings[$addon_name]['class_paths'])
748 748
         ) {
749 749
             EE_Register_Model::register(
750 750
                 $addon_name,
751 751
                 array(
752
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
753
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
752
+                    'model_paths' => self::$_settings[$addon_name]['model_paths'],
753
+                    'class_paths' => self::$_settings[$addon_name]['class_paths'],
754 754
                 )
755 755
             );
756 756
         }
757 757
         // register model extensions
758
-        if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
759
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
758
+        if ( ! empty(self::$_settings[$addon_name]['model_extension_paths'])
759
+            || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
760 760
         ) {
761 761
             EE_Register_Model_Extensions::register(
762 762
                 $addon_name,
763 763
                 array(
764
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
765
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
764
+                    'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
765
+                    'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
766 766
                 )
767 767
             );
768 768
         }
@@ -777,10 +777,10 @@  discard block
 block discarded – undo
777 777
     private static function _register_data_migration_scripts($addon_name)
778 778
     {
779 779
         // setup DMS
780
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
780
+        if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
781 781
             EE_Register_Data_Migration_Scripts::register(
782 782
                 $addon_name,
783
-                array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
783
+                array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
784 784
             );
785 785
         }
786 786
     }
@@ -794,12 +794,12 @@  discard block
 block discarded – undo
794 794
     private static function _register_config($addon_name)
795 795
     {
796 796
         // if config_class is present let's register config.
797
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
797
+        if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
798 798
             EE_Register_Config::register(
799
-                self::$_settings[ $addon_name ]['config_class'],
799
+                self::$_settings[$addon_name]['config_class'],
800 800
                 array(
801
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
802
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
801
+                    'config_section' => self::$_settings[$addon_name]['config_section'],
802
+                    'config_name'    => self::$_settings[$addon_name]['config_name'],
803 803
                 )
804 804
             );
805 805
         }
@@ -813,10 +813,10 @@  discard block
 block discarded – undo
813 813
      */
814 814
     private static function _register_admin_pages($addon_name)
815 815
     {
816
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
816
+        if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
817 817
             EE_Register_Admin_Page::register(
818 818
                 $addon_name,
819
-                array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
819
+                array('page_path' => self::$_settings[$addon_name]['admin_path'])
820 820
             );
821 821
         }
822 822
     }
@@ -829,10 +829,10 @@  discard block
 block discarded – undo
829 829
      */
830 830
     private static function _register_modules($addon_name)
831 831
     {
832
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
832
+        if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
833 833
             EE_Register_Module::register(
834 834
                 $addon_name,
835
-                array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
835
+                array('module_paths' => self::$_settings[$addon_name]['module_paths'])
836 836
             );
837 837
         }
838 838
     }
@@ -845,17 +845,17 @@  discard block
 block discarded – undo
845 845
      */
846 846
     private static function _register_shortcodes($addon_name)
847 847
     {
848
-        if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
849
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
848
+        if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])
849
+            || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
850 850
         ) {
851 851
             EE_Register_Shortcode::register(
852 852
                 $addon_name,
853 853
                 array(
854
-                    'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
855
-                        ? self::$_settings[ $addon_name ]['shortcode_paths']
854
+                    'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths'])
855
+                        ? self::$_settings[$addon_name]['shortcode_paths']
856 856
                         : array(),
857
-                    'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
858
-                        ? self::$_settings[ $addon_name ]['shortcode_fqcns']
857
+                    'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns'])
858
+                        ? self::$_settings[$addon_name]['shortcode_fqcns']
859 859
                         : array(),
860 860
                 )
861 861
             );
@@ -870,10 +870,10 @@  discard block
 block discarded – undo
870 870
      */
871 871
     private static function _register_widgets($addon_name)
872 872
     {
873
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
873
+        if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
874 874
             EE_Register_Widget::register(
875 875
                 $addon_name,
876
-                array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
876
+                array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
877 877
             );
878 878
         }
879 879
     }
@@ -886,12 +886,12 @@  discard block
 block discarded – undo
886 886
      */
887 887
     private static function _register_capabilities($addon_name)
888 888
     {
889
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
889
+        if ( ! empty(self::$_settings[$addon_name]['capabilities'])) {
890 890
             EE_Register_Capabilities::register(
891 891
                 $addon_name,
892 892
                 array(
893
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
894
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
893
+                    'capabilities'    => self::$_settings[$addon_name]['capabilities'],
894
+                    'capability_maps' => self::$_settings[$addon_name]['capability_maps'],
895 895
                 )
896 896
             );
897 897
         }
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
      */
906 906
     private static function _register_message_types($addon_name)
907 907
     {
908
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
908
+        if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
909 909
             add_action(
910 910
                 'EE_Brewing_Regular___messages_caf',
911 911
                 array('EE_Register_Addon', 'register_message_types')
@@ -921,15 +921,15 @@  discard block
 block discarded – undo
921 921
      */
922 922
     private static function _register_custom_post_types($addon_name)
923 923
     {
924
-        if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])
925
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
924
+        if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])
925
+            || ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
926 926
         ) {
927 927
             EE_Register_CPT::register(
928 928
                 $addon_name,
929 929
                 array(
930
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
931
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
932
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
930
+                    'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
931
+                    'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
932
+                    'default_terms' => self::$_settings[$addon_name]['default_terms'],
933 933
                 )
934 934
             );
935 935
         }
@@ -947,10 +947,10 @@  discard block
 block discarded – undo
947 947
      */
948 948
     private static function _register_payment_methods($addon_name)
949 949
     {
950
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
950
+        if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
951 951
             EE_Register_Payment_Method::register(
952 952
                 $addon_name,
953
-                array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
953
+                array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
954 954
             );
955 955
         }
956 956
     }
@@ -967,10 +967,10 @@  discard block
 block discarded – undo
967 967
      */
968 968
     private static function registerPrivacyPolicies($addon_name)
969 969
     {
970
-        if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
970
+        if ( ! empty(self::$_settings[$addon_name]['privacy_policies'])) {
971 971
             EE_Register_Privacy_Policy::register(
972 972
                 $addon_name,
973
-                self::$_settings[ $addon_name ]['privacy_policies']
973
+                self::$_settings[$addon_name]['privacy_policies']
974 974
             );
975 975
         }
976 976
     }
@@ -982,10 +982,10 @@  discard block
 block discarded – undo
982 982
      */
983 983
     private static function registerPersonalDataExporters($addon_name)
984 984
     {
985
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
985
+        if ( ! empty(self::$_settings[$addon_name]['personal_data_exporters'])) {
986 986
             EE_Register_Personal_Data_Eraser::register(
987 987
                 $addon_name,
988
-                self::$_settings[ $addon_name ]['personal_data_exporters']
988
+                self::$_settings[$addon_name]['personal_data_exporters']
989 989
             );
990 990
         }
991 991
     }
@@ -997,10 +997,10 @@  discard block
 block discarded – undo
997 997
      */
998 998
     private static function registerPersonalDataErasers($addon_name)
999 999
     {
1000
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
1000
+        if ( ! empty(self::$_settings[$addon_name]['personal_data_erasers'])) {
1001 1001
             EE_Register_Personal_Data_Eraser::register(
1002 1002
                 $addon_name,
1003
-                self::$_settings[ $addon_name ]['personal_data_erasers']
1003
+                self::$_settings[$addon_name]['personal_data_erasers']
1004 1004
             );
1005 1005
         }
1006 1006
     }
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
     {
1022 1022
         $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader();
1023 1023
         $addon = $loader->getShared(
1024
-            self::$_settings[ $addon_name ]['class_name'],
1024
+            self::$_settings[$addon_name]['class_name'],
1025 1025
             array('EE_Registry::create(addon)' => true)
1026 1026
         );
1027 1027
         // setter inject dep map if required
@@ -1033,19 +1033,19 @@  discard block
 block discarded – undo
1033 1033
             && $addon->domain() === null
1034 1034
         ) {
1035 1035
             // using supplied Domain object
1036
-            $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1037
-                ? self::$_settings[ $addon_name ]['domain']
1036
+            $domain = self::$_settings[$addon_name]['domain'] instanceof DomainInterface
1037
+                ? self::$_settings[$addon_name]['domain']
1038 1038
                 : null;
1039 1039
             // or construct one using Domain FQCN
1040
-            if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1040
+            if ($domain === null && self::$_settings[$addon_name]['domain_fqcn'] !== '') {
1041 1041
                 $domain = $loader->getShared(
1042
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
1042
+                    self::$_settings[$addon_name]['domain_fqcn'],
1043 1043
                     array(
1044 1044
                         new EventEspresso\core\domain\values\FilePath(
1045
-                            self::$_settings[ $addon_name ]['main_file_path']
1045
+                            self::$_settings[$addon_name]['main_file_path']
1046 1046
                         ),
1047 1047
                         EventEspresso\core\domain\values\Version::fromString(
1048
-                            self::$_settings[ $addon_name ]['version']
1048
+                            self::$_settings[$addon_name]['version']
1049 1049
                         ),
1050 1050
                     )
1051 1051
                 );
@@ -1055,28 +1055,28 @@  discard block
 block discarded – undo
1055 1055
             }
1056 1056
         }
1057 1057
         $addon->set_name($addon_name);
1058
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1059
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1060
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1061
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1062
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1063
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
1064
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1065
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1066
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1067
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1058
+        $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']);
1059
+        $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']);
1060
+        $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']);
1061
+        $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']);
1062
+        $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']);
1063
+        $addon->set_version(self::$_settings[$addon_name]['version']);
1064
+        $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version']));
1065
+        $addon->set_config_section(self::$_settings[$addon_name]['config_section']);
1066
+        $addon->set_config_class(self::$_settings[$addon_name]['config_class']);
1067
+        $addon->set_config_name(self::$_settings[$addon_name]['config_name']);
1068 1068
         // setup the add-on's pue_slug if we have one.
1069
-        if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) {
1070
-            $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']);
1069
+        if ( ! empty(self::$_settings[$addon_name]['pue_options']['pue_plugin_slug'])) {
1070
+            $addon->setPueSlug(self::$_settings[$addon_name]['pue_options']['pue_plugin_slug']);
1071 1071
         }
1072 1072
         // unfortunately this can't be hooked in upon construction, because we don't have
1073 1073
         // the plugin mainfile's path upon construction.
1074 1074
         register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
1075 1075
         // call any additional admin_callback functions during load_admin_controller hook
1076
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1076
+        if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) {
1077 1077
             add_action(
1078 1078
                 'AHEE__EE_System__load_controllers__load_admin_controllers',
1079
-                array($addon, self::$_settings[ $addon_name ]['admin_callback'])
1079
+                array($addon, self::$_settings[$addon_name]['admin_callback'])
1080 1080
             );
1081 1081
         }
1082 1082
         return $addon;
@@ -1094,11 +1094,11 @@  discard block
 block discarded – undo
1094 1094
     public static function load_pue_update()
1095 1095
     {
1096 1096
         // load PUE client
1097
-        require_once EE_THIRD_PARTY . 'pue/pue-client.php';
1097
+        require_once EE_THIRD_PARTY.'pue/pue-client.php';
1098 1098
         $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
1099 1099
         // cycle thru settings
1100 1100
         foreach (self::$_settings as $settings) {
1101
-            if (! empty($settings['pue_options'])) {
1101
+            if ( ! empty($settings['pue_options'])) {
1102 1102
                 // initiate the class and start the plugin update engine!
1103 1103
                 new PluginUpdateEngineChecker(
1104 1104
                     // host file URL
@@ -1106,7 +1106,7 @@  discard block
 block discarded – undo
1106 1106
                     // plugin slug(s)
1107 1107
                     array(
1108 1108
                         'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1109
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1109
+                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'),
1110 1110
                     ),
1111 1111
                     // options
1112 1112
                     array(
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
     public static function register_message_types()
1136 1136
     {
1137 1137
         foreach (self::$_settings as $addon_name => $settings) {
1138
-            if (! empty($settings['message_types'])) {
1138
+            if ( ! empty($settings['message_types'])) {
1139 1139
                 foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1140 1140
                     EE_Register_Message_Type::register($message_type, $message_type_settings);
1141 1141
                 }
@@ -1157,70 +1157,70 @@  discard block
 block discarded – undo
1157 1157
      */
1158 1158
     public static function deregister($addon_name = null)
1159 1159
     {
1160
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1160
+        if (isset(self::$_settings[$addon_name]['class_name'])) {
1161 1161
             try {
1162 1162
                 do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1163
-                $class_name = self::$_settings[ $addon_name ]['class_name'];
1164
-                if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1163
+                $class_name = self::$_settings[$addon_name]['class_name'];
1164
+                if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
1165 1165
                     // setup DMS
1166 1166
                     EE_Register_Data_Migration_Scripts::deregister($addon_name);
1167 1167
                 }
1168
-                if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1168
+                if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
1169 1169
                     // register admin page
1170 1170
                     EE_Register_Admin_Page::deregister($addon_name);
1171 1171
                 }
1172
-                if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1172
+                if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
1173 1173
                     // add to list of modules to be registered
1174 1174
                     EE_Register_Module::deregister($addon_name);
1175 1175
                 }
1176
-                if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1177
-                    || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1176
+                if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])
1177
+                    || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
1178 1178
                 ) {
1179 1179
                     // add to list of shortcodes to be registered
1180 1180
                     EE_Register_Shortcode::deregister($addon_name);
1181 1181
                 }
1182
-                if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1182
+                if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
1183 1183
                     // if config_class present let's register config.
1184
-                    EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1184
+                    EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1185 1185
                 }
1186
-                if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1186
+                if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
1187 1187
                     // add to list of widgets to be registered
1188 1188
                     EE_Register_Widget::deregister($addon_name);
1189 1189
                 }
1190
-                if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1191
-                    || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1190
+                if ( ! empty(self::$_settings[$addon_name]['model_paths'])
1191
+                    || ! empty(self::$_settings[$addon_name]['class_paths'])
1192 1192
                 ) {
1193 1193
                     // add to list of shortcodes to be registered
1194 1194
                     EE_Register_Model::deregister($addon_name);
1195 1195
                 }
1196
-                if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1197
-                    || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1196
+                if ( ! empty(self::$_settings[$addon_name]['model_extension_paths'])
1197
+                    || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
1198 1198
                 ) {
1199 1199
                     // add to list of shortcodes to be registered
1200 1200
                     EE_Register_Model_Extensions::deregister($addon_name);
1201 1201
                 }
1202
-                if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1203
-                    foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1202
+                if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
1203
+                    foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1204 1204
                         EE_Register_Message_Type::deregister($message_type);
1205 1205
                     }
1206 1206
                 }
1207 1207
                 // deregister capabilities for addon
1208
-                if (! empty(self::$_settings[ $addon_name ]['capabilities'])
1209
-                    || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1208
+                if ( ! empty(self::$_settings[$addon_name]['capabilities'])
1209
+                    || ! empty(self::$_settings[$addon_name]['capability_maps'])
1210 1210
                 ) {
1211 1211
                     EE_Register_Capabilities::deregister($addon_name);
1212 1212
                 }
1213 1213
                 // deregister custom_post_types for addon
1214
-                if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1214
+                if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1215 1215
                     EE_Register_CPT::deregister($addon_name);
1216 1216
                 }
1217
-                if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1217
+                if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1218 1218
                     EE_Register_Payment_Method::deregister($addon_name);
1219 1219
                 }
1220 1220
                 $addon = EE_Registry::instance()->getAddon($class_name);
1221 1221
                 if ($addon instanceof EE_Addon) {
1222 1222
                     remove_action(
1223
-                        'deactivate_' . $addon->get_main_plugin_file_basename(),
1223
+                        'deactivate_'.$addon->get_main_plugin_file_basename(),
1224 1224
                         array($addon, 'deactivation')
1225 1225
                     );
1226 1226
                     remove_action(
@@ -1243,7 +1243,7 @@  discard block
 block discarded – undo
1243 1243
             } catch (Exception $e) {
1244 1244
                 new ExceptionLogger($e);
1245 1245
             }
1246
-            unset(self::$_settings[ $addon_name ]);
1246
+            unset(self::$_settings[$addon_name]);
1247 1247
             do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1248 1248
         }
1249 1249
     }
Please login to merge, or discard this patch.