Completed
Branch EDTR/admin-options-and-conditi... (0210e3)
by
unknown
36:28 queued 27:24
created
core/EE_Config.core.php 1 patch
Indentation   +3224 added lines, -3224 removed lines patch added patch discarded remove patch
@@ -14,1489 +14,1489 @@  discard block
 block discarded – undo
14 14
 final class EE_Config implements ResettableInterface
15 15
 {
16 16
 
17
-    const OPTION_NAME = 'ee_config';
18
-
19
-    const LOG_NAME = 'ee_config_log';
20
-
21
-    const LOG_LENGTH = 100;
22
-
23
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
24
-
25
-    /**
26
-     *    instance of the EE_Config object
27
-     *
28
-     * @var    EE_Config $_instance
29
-     * @access    private
30
-     */
31
-    private static $_instance;
32
-
33
-    /**
34
-     * @var boolean $_logging_enabled
35
-     */
36
-    private static $_logging_enabled = false;
37
-
38
-    /**
39
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
40
-     */
41
-    private $legacy_shortcodes_manager;
42
-
43
-    /**
44
-     * An StdClass whose property names are addon slugs,
45
-     * and values are their config classes
46
-     *
47
-     * @var StdClass
48
-     */
49
-    public $addons;
50
-
51
-    /**
52
-     * @var EE_Admin_Config
53
-     */
54
-    public $admin;
55
-
56
-    /**
57
-     * @var EE_Core_Config
58
-     */
59
-    public $core;
60
-
61
-    /**
62
-     * @var EE_Currency_Config
63
-     */
64
-    public $currency;
65
-
66
-    /**
67
-     * @var EE_Organization_Config
68
-     */
69
-    public $organization;
70
-
71
-    /**
72
-     * @var EE_Registration_Config
73
-     */
74
-    public $registration;
75
-
76
-    /**
77
-     * @var EE_Template_Config
78
-     */
79
-    public $template_settings;
80
-
81
-    /**
82
-     * Holds EE environment values.
83
-     *
84
-     * @var EE_Environment_Config
85
-     */
86
-    public $environment;
87
-
88
-    /**
89
-     * settings pertaining to Google maps
90
-     *
91
-     * @var EE_Map_Config
92
-     */
93
-    public $map_settings;
94
-
95
-    /**
96
-     * settings pertaining to Taxes
97
-     *
98
-     * @var EE_Tax_Config
99
-     */
100
-    public $tax_settings;
101
-
102
-    /**
103
-     * Settings pertaining to global messages settings.
104
-     *
105
-     * @var EE_Messages_Config
106
-     */
107
-    public $messages;
108
-
109
-    /**
110
-     * @deprecated
111
-     * @var EE_Gateway_Config
112
-     */
113
-    public $gateway;
114
-
115
-    /**
116
-     * @var    array $_addon_option_names
117
-     * @access    private
118
-     */
119
-    private $_addon_option_names = array();
120
-
121
-    /**
122
-     * @var    array $_module_route_map
123
-     * @access    private
124
-     */
125
-    private static $_module_route_map = array();
126
-
127
-    /**
128
-     * @var    array $_module_forward_map
129
-     * @access    private
130
-     */
131
-    private static $_module_forward_map = array();
132
-
133
-    /**
134
-     * @var    array $_module_view_map
135
-     * @access    private
136
-     */
137
-    private static $_module_view_map = array();
138
-
139
-
140
-    /**
141
-     * @singleton method used to instantiate class object
142
-     * @access    public
143
-     * @return EE_Config instance
144
-     */
145
-    public static function instance()
146
-    {
147
-        // check if class object is instantiated, and instantiated properly
148
-        if (! self::$_instance instanceof EE_Config) {
149
-            self::$_instance = new self();
150
-        }
151
-        return self::$_instance;
152
-    }
153
-
154
-
155
-    /**
156
-     * Resets the config
157
-     *
158
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
159
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
160
-     *                               reflect its state in the database
161
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
162
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
163
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
164
-     *                               site was put into maintenance mode)
165
-     * @return EE_Config
166
-     */
167
-    public static function reset($hard_reset = false, $reinstantiate = true)
168
-    {
169
-        if (self::$_instance instanceof EE_Config) {
170
-            if ($hard_reset) {
171
-                self::$_instance->legacy_shortcodes_manager = null;
172
-                self::$_instance->_addon_option_names = array();
173
-                self::$_instance->_initialize_config();
174
-                self::$_instance->update_espresso_config();
175
-            }
176
-            self::$_instance->update_addon_option_names();
177
-        }
178
-        self::$_instance = null;
179
-        // we don't need to reset the static properties imo because those should
180
-        // only change when a module is added or removed. Currently we don't
181
-        // support removing a module during a request when it previously existed
182
-        if ($reinstantiate) {
183
-            return self::instance();
184
-        } else {
185
-            return null;
186
-        }
187
-    }
188
-
189
-
190
-    /**
191
-     *    class constructor
192
-     *
193
-     * @access    private
194
-     */
195
-    private function __construct()
196
-    {
197
-        do_action('AHEE__EE_Config__construct__begin', $this);
198
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
199
-        // setup empty config classes
200
-        $this->_initialize_config();
201
-        // load existing EE site settings
202
-        $this->_load_core_config();
203
-        // confirm everything loaded correctly and set filtered defaults if not
204
-        $this->_verify_config();
205
-        //  register shortcodes and modules
206
-        add_action(
207
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
208
-            array($this, 'register_shortcodes_and_modules'),
209
-            999
210
-        );
211
-        //  initialize shortcodes and modules
212
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
213
-        // register widgets
214
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
215
-        // shutdown
216
-        add_action('shutdown', array($this, 'shutdown'), 10);
217
-        // construct__end hook
218
-        do_action('AHEE__EE_Config__construct__end', $this);
219
-        // hardcoded hack
220
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
221
-    }
222
-
223
-
224
-    /**
225
-     * @return boolean
226
-     */
227
-    public static function logging_enabled()
228
-    {
229
-        return self::$_logging_enabled;
230
-    }
231
-
232
-
233
-    /**
234
-     * use to get the current theme if needed from static context
235
-     *
236
-     * @return string current theme set.
237
-     */
238
-    public static function get_current_theme()
239
-    {
240
-        return isset(self::$_instance->template_settings->current_espresso_theme)
241
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
242
-    }
243
-
244
-
245
-    /**
246
-     *        _initialize_config
247
-     *
248
-     * @access private
249
-     * @return void
250
-     */
251
-    private function _initialize_config()
252
-    {
253
-        EE_Config::trim_log();
254
-        // set defaults
255
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
256
-        $this->addons = new stdClass();
257
-        // set _module_route_map
258
-        EE_Config::$_module_route_map = array();
259
-        // set _module_forward_map
260
-        EE_Config::$_module_forward_map = array();
261
-        // set _module_view_map
262
-        EE_Config::$_module_view_map = array();
263
-    }
264
-
265
-
266
-    /**
267
-     *        load core plugin configuration
268
-     *
269
-     * @access private
270
-     * @return void
271
-     */
272
-    private function _load_core_config()
273
-    {
274
-        // load_core_config__start hook
275
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
276
-        $espresso_config = $this->get_espresso_config();
277
-        foreach ($espresso_config as $config => $settings) {
278
-            // load_core_config__start hook
279
-            $settings = apply_filters(
280
-                'FHEE__EE_Config___load_core_config__config_settings',
281
-                $settings,
282
-                $config,
283
-                $this
284
-            );
285
-            if (is_object($settings) && property_exists($this, $config)) {
286
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
287
-                // call configs populate method to ensure any defaults are set for empty values.
288
-                if (method_exists($settings, 'populate')) {
289
-                    $this->{$config}->populate();
290
-                }
291
-                if (method_exists($settings, 'do_hooks')) {
292
-                    $this->{$config}->do_hooks();
293
-                }
294
-            }
295
-        }
296
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
297
-            $this->update_espresso_config();
298
-        }
299
-        // load_core_config__end hook
300
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
301
-    }
302
-
303
-
304
-    /**
305
-     *    _verify_config
306
-     *
307
-     * @access    protected
308
-     * @return    void
309
-     */
310
-    protected function _verify_config()
311
-    {
312
-        $this->core = $this->core instanceof EE_Core_Config
313
-            ? $this->core
314
-            : new EE_Core_Config();
315
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
316
-        $this->organization = $this->organization instanceof EE_Organization_Config
317
-            ? $this->organization
318
-            : new EE_Organization_Config();
319
-        $this->organization = apply_filters(
320
-            'FHEE__EE_Config___initialize_config__organization',
321
-            $this->organization
322
-        );
323
-        $this->currency = $this->currency instanceof EE_Currency_Config
324
-            ? $this->currency
325
-            : new EE_Currency_Config();
326
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
327
-        $this->registration = $this->registration instanceof EE_Registration_Config
328
-            ? $this->registration
329
-            : new EE_Registration_Config();
330
-        $this->registration = apply_filters(
331
-            'FHEE__EE_Config___initialize_config__registration',
332
-            $this->registration
333
-        );
334
-        $this->admin = $this->admin instanceof EE_Admin_Config
335
-            ? $this->admin
336
-            : new EE_Admin_Config();
337
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
338
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
339
-            ? $this->template_settings
340
-            : new EE_Template_Config();
341
-        $this->template_settings = apply_filters(
342
-            'FHEE__EE_Config___initialize_config__template_settings',
343
-            $this->template_settings
344
-        );
345
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
346
-            ? $this->map_settings
347
-            : new EE_Map_Config();
348
-        $this->map_settings = apply_filters(
349
-            'FHEE__EE_Config___initialize_config__map_settings',
350
-            $this->map_settings
351
-        );
352
-        $this->environment = $this->environment instanceof EE_Environment_Config
353
-            ? $this->environment
354
-            : new EE_Environment_Config();
355
-        $this->environment = apply_filters(
356
-            'FHEE__EE_Config___initialize_config__environment',
357
-            $this->environment
358
-        );
359
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
360
-            ? $this->tax_settings
361
-            : new EE_Tax_Config();
362
-        $this->tax_settings = apply_filters(
363
-            'FHEE__EE_Config___initialize_config__tax_settings',
364
-            $this->tax_settings
365
-        );
366
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
367
-        $this->messages = $this->messages instanceof EE_Messages_Config
368
-            ? $this->messages
369
-            : new EE_Messages_Config();
370
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
371
-            ? $this->gateway
372
-            : new EE_Gateway_Config();
373
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
374
-        $this->legacy_shortcodes_manager = null;
375
-    }
376
-
377
-
378
-    /**
379
-     *    get_espresso_config
380
-     *
381
-     * @access    public
382
-     * @return    array of espresso config stuff
383
-     */
384
-    public function get_espresso_config()
385
-    {
386
-        // grab espresso configuration
387
-        return apply_filters(
388
-            'FHEE__EE_Config__get_espresso_config__CFG',
389
-            get_option(EE_Config::OPTION_NAME, array())
390
-        );
391
-    }
392
-
393
-
394
-    /**
395
-     *    double_check_config_comparison
396
-     *
397
-     * @access    public
398
-     * @param string $option
399
-     * @param        $old_value
400
-     * @param        $value
401
-     */
402
-    public function double_check_config_comparison($option = '', $old_value, $value)
403
-    {
404
-        // make sure we're checking the ee config
405
-        if ($option === EE_Config::OPTION_NAME) {
406
-            // run a loose comparison of the old value against the new value for type and properties,
407
-            // but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
408
-            if ($value != $old_value) {
409
-                // if they are NOT the same, then remove the hook,
410
-                // which means the subsequent update results will be based solely on the update query results
411
-                // the reason we do this is because, as stated above,
412
-                // WP update_option performs an exact instance comparison (===) on any update values passed to it
413
-                // this happens PRIOR to serialization and any subsequent update.
414
-                // If values are found to match their previous old value,
415
-                // then WP bails before performing any update.
416
-                // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
417
-                // it just pulled from the db, with the one being passed to it (which will not match).
418
-                // HOWEVER, once the object is serialized and passed off to MySQL to update,
419
-                // MySQL MAY ALSO NOT perform the update because
420
-                // the string it sees in the db looks the same as the new one it has been passed!!!
421
-                // This results in the query returning an "affected rows" value of ZERO,
422
-                // which gets returned immediately by WP update_option and looks like an error.
423
-                remove_action('update_option', array($this, 'check_config_updated'));
424
-            }
425
-        }
426
-    }
427
-
428
-
429
-    /**
430
-     *    update_espresso_config
431
-     *
432
-     * @access   public
433
-     */
434
-    protected function _reset_espresso_addon_config()
435
-    {
436
-        $this->_addon_option_names = array();
437
-        foreach ($this->addons as $addon_name => $addon_config_obj) {
438
-            $addon_config_obj = maybe_unserialize($addon_config_obj);
439
-            if ($addon_config_obj instanceof EE_Config_Base) {
440
-                $this->update_config('addons', $addon_name, $addon_config_obj, false);
441
-            }
442
-            $this->addons->{$addon_name} = null;
443
-        }
444
-    }
445
-
446
-
447
-    /**
448
-     *    update_espresso_config
449
-     *
450
-     * @access   public
451
-     * @param   bool $add_success
452
-     * @param   bool $add_error
453
-     * @return   bool
454
-     */
455
-    public function update_espresso_config($add_success = false, $add_error = true)
456
-    {
457
-        // don't allow config updates during WP heartbeats
458
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
459
-            return false;
460
-        }
461
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
462
-        // $clone = clone( self::$_instance );
463
-        // self::$_instance = NULL;
464
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
465
-        $this->_reset_espresso_addon_config();
466
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
467
-        // but BEFORE the actual update occurs
468
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
469
-        // don't want to persist legacy_shortcodes_manager, but don't want to lose it either
470
-        $legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
471
-        $this->legacy_shortcodes_manager = null;
472
-        // now update "ee_config"
473
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
474
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
475
-        EE_Config::log(EE_Config::OPTION_NAME);
476
-        // if not saved... check if the hook we just added still exists;
477
-        // if it does, it means one of two things:
478
-        // that update_option bailed at the($value === $old_value) conditional,
479
-        // or...
480
-        // the db update query returned 0 rows affected
481
-        // (probably because the data  value was the same from it's perspective)
482
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
483
-        // but just means no update occurred, so don't display an error to the user.
484
-        // BUT... if update_option returns FALSE, AND the hook is missing,
485
-        // then it means that something truly went wrong
486
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
487
-        // remove our action since we don't want it in the system anymore
488
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
489
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
490
-        // self::$_instance = $clone;
491
-        // unset( $clone );
492
-        // if config remains the same or was updated successfully
493
-        if ($saved) {
494
-            if ($add_success) {
495
-                EE_Error::add_success(
496
-                    __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
497
-                    __FILE__,
498
-                    __FUNCTION__,
499
-                    __LINE__
500
-                );
501
-            }
502
-            return true;
503
-        } else {
504
-            if ($add_error) {
505
-                EE_Error::add_error(
506
-                    __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
507
-                    __FILE__,
508
-                    __FUNCTION__,
509
-                    __LINE__
510
-                );
511
-            }
512
-            return false;
513
-        }
514
-    }
515
-
516
-
517
-    /**
518
-     *    _verify_config_params
519
-     *
520
-     * @access    private
521
-     * @param    string         $section
522
-     * @param    string         $name
523
-     * @param    string         $config_class
524
-     * @param    EE_Config_Base $config_obj
525
-     * @param    array          $tests_to_run
526
-     * @param    bool           $display_errors
527
-     * @return    bool    TRUE on success, FALSE on fail
528
-     */
529
-    private function _verify_config_params(
530
-        $section = '',
531
-        $name = '',
532
-        $config_class = '',
533
-        $config_obj = null,
534
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
535
-        $display_errors = true
536
-    ) {
537
-        try {
538
-            foreach ($tests_to_run as $test) {
539
-                switch ($test) {
540
-                    // TEST #1 : check that section was set
541
-                    case 1:
542
-                        if (empty($section)) {
543
-                            if ($display_errors) {
544
-                                throw new EE_Error(
545
-                                    sprintf(
546
-                                        __(
547
-                                            'No configuration section has been provided while attempting to save "%s".',
548
-                                            'event_espresso'
549
-                                        ),
550
-                                        $config_class
551
-                                    )
552
-                                );
553
-                            }
554
-                            return false;
555
-                        }
556
-                        break;
557
-                    // TEST #2 : check that settings section exists
558
-                    case 2:
559
-                        if (! isset($this->{$section})) {
560
-                            if ($display_errors) {
561
-                                throw new EE_Error(
562
-                                    sprintf(
563
-                                        __('The "%s" configuration section does not exist.', 'event_espresso'),
564
-                                        $section
565
-                                    )
566
-                                );
567
-                            }
568
-                            return false;
569
-                        }
570
-                        break;
571
-                    // TEST #3 : check that section is the proper format
572
-                    case 3:
573
-                        if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
574
-                        ) {
575
-                            if ($display_errors) {
576
-                                throw new EE_Error(
577
-                                    sprintf(
578
-                                        __(
579
-                                            'The "%s" configuration settings have not been formatted correctly.',
580
-                                            'event_espresso'
581
-                                        ),
582
-                                        $section
583
-                                    )
584
-                                );
585
-                            }
586
-                            return false;
587
-                        }
588
-                        break;
589
-                    // TEST #4 : check that config section name has been set
590
-                    case 4:
591
-                        if (empty($name)) {
592
-                            if ($display_errors) {
593
-                                throw new EE_Error(
594
-                                    __(
595
-                                        'No name has been provided for the specific configuration section.',
596
-                                        'event_espresso'
597
-                                    )
598
-                                );
599
-                            }
600
-                            return false;
601
-                        }
602
-                        break;
603
-                    // TEST #5 : check that a config class name has been set
604
-                    case 5:
605
-                        if (empty($config_class)) {
606
-                            if ($display_errors) {
607
-                                throw new EE_Error(
608
-                                    __(
609
-                                        'No class name has been provided for the specific configuration section.',
610
-                                        'event_espresso'
611
-                                    )
612
-                                );
613
-                            }
614
-                            return false;
615
-                        }
616
-                        break;
617
-                    // TEST #6 : verify config class is accessible
618
-                    case 6:
619
-                        if (! class_exists($config_class)) {
620
-                            if ($display_errors) {
621
-                                throw new EE_Error(
622
-                                    sprintf(
623
-                                        __(
624
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
625
-                                            'event_espresso'
626
-                                        ),
627
-                                        $config_class
628
-                                    )
629
-                                );
630
-                            }
631
-                            return false;
632
-                        }
633
-                        break;
634
-                    // TEST #7 : check that config has even been set
635
-                    case 7:
636
-                        if (! isset($this->{$section}->{$name})) {
637
-                            if ($display_errors) {
638
-                                throw new EE_Error(
639
-                                    sprintf(
640
-                                        __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
641
-                                        $section,
642
-                                        $name
643
-                                    )
644
-                                );
645
-                            }
646
-                            return false;
647
-                        } else {
648
-                            // and make sure it's not serialized
649
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
650
-                        }
651
-                        break;
652
-                    // TEST #8 : check that config is the requested type
653
-                    case 8:
654
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
655
-                            if ($display_errors) {
656
-                                throw new EE_Error(
657
-                                    sprintf(
658
-                                        __(
659
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
660
-                                            'event_espresso'
661
-                                        ),
662
-                                        $section,
663
-                                        $name,
664
-                                        $config_class
665
-                                    )
666
-                                );
667
-                            }
668
-                            return false;
669
-                        }
670
-                        break;
671
-                    // TEST #9 : verify config object
672
-                    case 9:
673
-                        if (! $config_obj instanceof EE_Config_Base) {
674
-                            if ($display_errors) {
675
-                                throw new EE_Error(
676
-                                    sprintf(
677
-                                        __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
678
-                                        print_r($config_obj, true)
679
-                                    )
680
-                                );
681
-                            }
682
-                            return false;
683
-                        }
684
-                        break;
685
-                }
686
-            }
687
-        } catch (EE_Error $e) {
688
-            $e->get_error();
689
-        }
690
-        // you have successfully run the gauntlet
691
-        return true;
692
-    }
693
-
694
-
695
-    /**
696
-     *    _generate_config_option_name
697
-     *
698
-     * @access        protected
699
-     * @param        string $section
700
-     * @param        string $name
701
-     * @return        string
702
-     */
703
-    private function _generate_config_option_name($section = '', $name = '')
704
-    {
705
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
706
-    }
707
-
708
-
709
-    /**
710
-     *    _set_config_class
711
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
712
-     *
713
-     * @access    private
714
-     * @param    string $config_class
715
-     * @param    string $name
716
-     * @return    string
717
-     */
718
-    private function _set_config_class($config_class = '', $name = '')
719
-    {
720
-        return ! empty($config_class)
721
-            ? $config_class
722
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
723
-    }
724
-
725
-
726
-    /**
727
-     *    set_config
728
-     *
729
-     * @access    protected
730
-     * @param    string         $section
731
-     * @param    string         $name
732
-     * @param    string         $config_class
733
-     * @param    EE_Config_Base $config_obj
734
-     * @return    EE_Config_Base
735
-     */
736
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
737
-    {
738
-        // ensure config class is set to something
739
-        $config_class = $this->_set_config_class($config_class, $name);
740
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
741
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
742
-            return null;
743
-        }
744
-        $config_option_name = $this->_generate_config_option_name($section, $name);
745
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
746
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
747
-            $this->_addon_option_names[ $config_option_name ] = $config_class;
748
-            $this->update_addon_option_names();
749
-        }
750
-        // verify the incoming config object but suppress errors
751
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
752
-            $config_obj = new $config_class();
753
-        }
754
-        if (get_option($config_option_name)) {
755
-            EE_Config::log($config_option_name);
756
-            update_option($config_option_name, $config_obj);
757
-            $this->{$section}->{$name} = $config_obj;
758
-            return $this->{$section}->{$name};
759
-        } else {
760
-            // create a wp-option for this config
761
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
762
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
763
-                return $this->{$section}->{$name};
764
-            } else {
765
-                EE_Error::add_error(
766
-                    sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
767
-                    __FILE__,
768
-                    __FUNCTION__,
769
-                    __LINE__
770
-                );
771
-                return null;
772
-            }
773
-        }
774
-    }
775
-
776
-
777
-    /**
778
-     *    update_config
779
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
780
-     *
781
-     * @access    public
782
-     * @param    string                $section
783
-     * @param    string                $name
784
-     * @param    EE_Config_Base|string $config_obj
785
-     * @param    bool                  $throw_errors
786
-     * @return    bool
787
-     */
788
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
789
-    {
790
-        // don't allow config updates during WP heartbeats
791
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
792
-            return false;
793
-        }
794
-        $config_obj = maybe_unserialize($config_obj);
795
-        // get class name of the incoming object
796
-        $config_class = get_class($config_obj);
797
-        // run tests 1-5 and 9 to verify config
798
-        if (! $this->_verify_config_params(
799
-            $section,
800
-            $name,
801
-            $config_class,
802
-            $config_obj,
803
-            array(1, 2, 3, 4, 7, 9)
804
-        )
805
-        ) {
806
-            return false;
807
-        }
808
-        $config_option_name = $this->_generate_config_option_name($section, $name);
809
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
810
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
811
-            // save new config to db
812
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
813
-                return true;
814
-            }
815
-        } else {
816
-            // first check if the record already exists
817
-            $existing_config = get_option($config_option_name);
818
-            $config_obj = serialize($config_obj);
819
-            // just return if db record is already up to date (NOT type safe comparison)
820
-            if ($existing_config == $config_obj) {
821
-                $this->{$section}->{$name} = $config_obj;
822
-                return true;
823
-            } elseif (update_option($config_option_name, $config_obj)) {
824
-                EE_Config::log($config_option_name);
825
-                // update wp-option for this config class
826
-                $this->{$section}->{$name} = $config_obj;
827
-                return true;
828
-            } elseif ($throw_errors) {
829
-                EE_Error::add_error(
830
-                    sprintf(
831
-                        __(
832
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
833
-                            'event_espresso'
834
-                        ),
835
-                        $config_class,
836
-                        'EE_Config->' . $section . '->' . $name
837
-                    ),
838
-                    __FILE__,
839
-                    __FUNCTION__,
840
-                    __LINE__
841
-                );
842
-            }
843
-        }
844
-        return false;
845
-    }
846
-
847
-
848
-    /**
849
-     *    get_config
850
-     *
851
-     * @access    public
852
-     * @param    string $section
853
-     * @param    string $name
854
-     * @param    string $config_class
855
-     * @return    mixed EE_Config_Base | NULL
856
-     */
857
-    public function get_config($section = '', $name = '', $config_class = '')
858
-    {
859
-        // ensure config class is set to something
860
-        $config_class = $this->_set_config_class($config_class, $name);
861
-        // run tests 1-4, 6 and 7 to verify that all params have been set
862
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
863
-            return null;
864
-        }
865
-        // now test if the requested config object exists, but suppress errors
866
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
867
-            // config already exists, so pass it back
868
-            return $this->{$section}->{$name};
869
-        }
870
-        // load config option from db if it exists
871
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
872
-        // verify the newly retrieved config object, but suppress errors
873
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
874
-            // config is good, so set it and pass it back
875
-            $this->{$section}->{$name} = $config_obj;
876
-            return $this->{$section}->{$name};
877
-        }
878
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
879
-        $config_obj = $this->set_config($section, $name, $config_class);
880
-        // verify the newly created config object
881
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
882
-            return $this->{$section}->{$name};
883
-        } else {
884
-            EE_Error::add_error(
885
-                sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
886
-                __FILE__,
887
-                __FUNCTION__,
888
-                __LINE__
889
-            );
890
-        }
891
-        return null;
892
-    }
893
-
894
-
895
-    /**
896
-     *    get_config_option
897
-     *
898
-     * @access    public
899
-     * @param    string $config_option_name
900
-     * @return    mixed EE_Config_Base | FALSE
901
-     */
902
-    public function get_config_option($config_option_name = '')
903
-    {
904
-        // retrieve the wp-option for this config class.
905
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
906
-        if (empty($config_option)) {
907
-            EE_Config::log($config_option_name . '-NOT-FOUND');
908
-        }
909
-        return $config_option;
910
-    }
911
-
912
-
913
-    /**
914
-     * log
915
-     *
916
-     * @param string $config_option_name
917
-     */
918
-    public static function log($config_option_name = '')
919
-    {
920
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
921
-            $config_log = get_option(EE_Config::LOG_NAME, array());
922
-            // copy incoming $_REQUEST and sanitize it so we can save it
923
-            $_request = $_REQUEST;
924
-            array_walk_recursive($_request, 'sanitize_text_field');
925
-            $config_log[ (string) microtime(true) ] = array(
926
-                'config_name' => $config_option_name,
927
-                'request'     => $_request,
928
-            );
929
-            update_option(EE_Config::LOG_NAME, $config_log);
930
-        }
931
-    }
932
-
933
-
934
-    /**
935
-     * trim_log
936
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
937
-     */
938
-    public static function trim_log()
939
-    {
940
-        if (! EE_Config::logging_enabled()) {
941
-            return;
942
-        }
943
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
944
-        $log_length = count($config_log);
945
-        if ($log_length > EE_Config::LOG_LENGTH) {
946
-            ksort($config_log);
947
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
948
-            update_option(EE_Config::LOG_NAME, $config_log);
949
-        }
950
-    }
951
-
952
-
953
-    /**
954
-     *    get_page_for_posts
955
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
956
-     *    wp-option "page_for_posts", or "posts" if no page is selected
957
-     *
958
-     * @access    public
959
-     * @return    string
960
-     */
961
-    public static function get_page_for_posts()
962
-    {
963
-        $page_for_posts = get_option('page_for_posts');
964
-        if (! $page_for_posts) {
965
-            return 'posts';
966
-        }
967
-        /** @type WPDB $wpdb */
968
-        global $wpdb;
969
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
970
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
971
-    }
972
-
973
-
974
-    /**
975
-     *    register_shortcodes_and_modules.
976
-     *    At this point, it's too early to tell if we're maintenance mode or not.
977
-     *    In fact, this is where we give modules a chance to let core know they exist
978
-     *    so they can help trigger maintenance mode if it's needed
979
-     *
980
-     * @access    public
981
-     * @return    void
982
-     */
983
-    public function register_shortcodes_and_modules()
984
-    {
985
-        // allow modules to set hooks for the rest of the system
986
-        EE_Registry::instance()->modules = $this->_register_modules();
987
-    }
988
-
989
-
990
-    /**
991
-     *    initialize_shortcodes_and_modules
992
-     *    meaning they can start adding their hooks to get stuff done
993
-     *
994
-     * @access    public
995
-     * @return    void
996
-     */
997
-    public function initialize_shortcodes_and_modules()
998
-    {
999
-        // allow modules to set hooks for the rest of the system
1000
-        $this->_initialize_modules();
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     *    widgets_init
1006
-     *
1007
-     * @access private
1008
-     * @return void
1009
-     */
1010
-    public function widgets_init()
1011
-    {
1012
-        // only init widgets on admin pages when not in complete maintenance, and
1013
-        // on frontend when not in any maintenance mode
1014
-        if (! EE_Maintenance_Mode::instance()->level()
1015
-            || (
1016
-                is_admin()
1017
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1018
-            )
1019
-        ) {
1020
-            // grab list of installed widgets
1021
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1022
-            // filter list of modules to register
1023
-            $widgets_to_register = apply_filters(
1024
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1025
-                $widgets_to_register
1026
-            );
1027
-            if (! empty($widgets_to_register)) {
1028
-                // cycle thru widget folders
1029
-                foreach ($widgets_to_register as $widget_path) {
1030
-                    // add to list of installed widget modules
1031
-                    EE_Config::register_ee_widget($widget_path);
1032
-                }
1033
-            }
1034
-            // filter list of installed modules
1035
-            EE_Registry::instance()->widgets = apply_filters(
1036
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1037
-                EE_Registry::instance()->widgets
1038
-            );
1039
-        }
1040
-    }
1041
-
1042
-
1043
-    /**
1044
-     *    register_ee_widget - makes core aware of this widget
1045
-     *
1046
-     * @access    public
1047
-     * @param    string $widget_path - full path up to and including widget folder
1048
-     * @return    void
1049
-     */
1050
-    public static function register_ee_widget($widget_path = null)
1051
-    {
1052
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1053
-        $widget_ext = '.widget.php';
1054
-        // make all separators match
1055
-        $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1056
-        // does the file path INCLUDE the actual file name as part of the path ?
1057
-        if (strpos($widget_path, $widget_ext) !== false) {
1058
-            // grab and shortcode file name from directory name and break apart at dots
1059
-            $file_name = explode('.', basename($widget_path));
1060
-            // take first segment from file name pieces and remove class prefix if it exists
1061
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1062
-            // sanitize shortcode directory name
1063
-            $widget = sanitize_key($widget);
1064
-            // now we need to rebuild the shortcode path
1065
-            $widget_path = explode(DS, $widget_path);
1066
-            // remove last segment
1067
-            array_pop($widget_path);
1068
-            // glue it back together
1069
-            $widget_path = implode(DS, $widget_path);
1070
-        } else {
1071
-            // grab and sanitize widget directory name
1072
-            $widget = sanitize_key(basename($widget_path));
1073
-        }
1074
-        // create classname from widget directory name
1075
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1076
-        // add class prefix
1077
-        $widget_class = 'EEW_' . $widget;
1078
-        // does the widget exist ?
1079
-        if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1080
-            $msg = sprintf(
1081
-                __(
1082
-                    'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1083
-                    'event_espresso'
1084
-                ),
1085
-                $widget_class,
1086
-                $widget_path . DS . $widget_class . $widget_ext
1087
-            );
1088
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1089
-            return;
1090
-        }
1091
-        // load the widget class file
1092
-        require_once($widget_path . DS . $widget_class . $widget_ext);
1093
-        // verify that class exists
1094
-        if (! class_exists($widget_class)) {
1095
-            $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1096
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1097
-            return;
1098
-        }
1099
-        register_widget($widget_class);
1100
-        // add to array of registered widgets
1101
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1102
-    }
1103
-
1104
-
1105
-    /**
1106
-     *        _register_modules
1107
-     *
1108
-     * @access private
1109
-     * @return array
1110
-     */
1111
-    private function _register_modules()
1112
-    {
1113
-        // grab list of installed modules
1114
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1115
-        // filter list of modules to register
1116
-        $modules_to_register = apply_filters(
1117
-            'FHEE__EE_Config__register_modules__modules_to_register',
1118
-            $modules_to_register
1119
-        );
1120
-        if (! empty($modules_to_register)) {
1121
-            // loop through folders
1122
-            foreach ($modules_to_register as $module_path) {
1123
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1124
-                if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1125
-                    && $module_path !== EE_MODULES . 'gateways'
1126
-                ) {
1127
-                    // add to list of installed modules
1128
-                    EE_Config::register_module($module_path);
1129
-                }
1130
-            }
1131
-        }
1132
-        // filter list of installed modules
1133
-        return apply_filters(
1134
-            'FHEE__EE_Config___register_modules__installed_modules',
1135
-            EE_Registry::instance()->modules
1136
-        );
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     *    register_module - makes core aware of this module
1142
-     *
1143
-     * @access    public
1144
-     * @param    string $module_path - full path up to and including module folder
1145
-     * @return    bool
1146
-     */
1147
-    public static function register_module($module_path = null)
1148
-    {
1149
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1150
-        $module_ext = '.module.php';
1151
-        // make all separators match
1152
-        $module_path = str_replace(array('\\', '/'), DS, $module_path);
1153
-        // does the file path INCLUDE the actual file name as part of the path ?
1154
-        if (strpos($module_path, $module_ext) !== false) {
1155
-            // grab and shortcode file name from directory name and break apart at dots
1156
-            $module_file = explode('.', basename($module_path));
1157
-            // now we need to rebuild the shortcode path
1158
-            $module_path = explode(DS, $module_path);
1159
-            // remove last segment
1160
-            array_pop($module_path);
1161
-            // glue it back together
1162
-            $module_path = implode(DS, $module_path) . DS;
1163
-            // take first segment from file name pieces and sanitize it
1164
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1165
-            // ensure class prefix is added
1166
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1167
-        } else {
1168
-            // we need to generate the filename based off of the folder name
1169
-            // grab and sanitize module name
1170
-            $module = strtolower(basename($module_path));
1171
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1172
-            // like trailingslashit()
1173
-            $module_path = rtrim($module_path, DS) . DS;
1174
-            // create classname from module directory name
1175
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1176
-            // add class prefix
1177
-            $module_class = 'EED_' . $module;
1178
-        }
1179
-        // does the module exist ?
1180
-        if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1181
-            $msg = sprintf(
1182
-                __(
1183
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1184
-                    'event_espresso'
1185
-                ),
1186
-                $module
1187
-            );
1188
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1189
-            return false;
1190
-        }
1191
-        // load the module class file
1192
-        require_once($module_path . $module_class . $module_ext);
1193
-        // verify that class exists
1194
-        if (! class_exists($module_class)) {
1195
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1196
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1197
-            return false;
1198
-        }
1199
-        // add to array of registered modules
1200
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1201
-        do_action(
1202
-            'AHEE__EE_Config__register_module__complete',
1203
-            $module_class,
1204
-            EE_Registry::instance()->modules->{$module_class}
1205
-        );
1206
-        return true;
1207
-    }
1208
-
1209
-
1210
-    /**
1211
-     *    _initialize_modules
1212
-     *    allow modules to set hooks for the rest of the system
1213
-     *
1214
-     * @access private
1215
-     * @return void
1216
-     */
1217
-    private function _initialize_modules()
1218
-    {
1219
-        // cycle thru shortcode folders
1220
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1221
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1222
-            // which set hooks ?
1223
-            if (is_admin()) {
1224
-                // fire immediately
1225
-                call_user_func(array($module_class, 'set_hooks_admin'));
1226
-            } else {
1227
-                // delay until other systems are online
1228
-                add_action(
1229
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1230
-                    array($module_class, 'set_hooks')
1231
-                );
1232
-            }
1233
-        }
1234
-    }
1235
-
1236
-
1237
-    /**
1238
-     *    register_route - adds module method routes to route_map
1239
-     *
1240
-     * @access    public
1241
-     * @param    string $route       - "pretty" public alias for module method
1242
-     * @param    string $module      - module name (classname without EED_ prefix)
1243
-     * @param    string $method_name - the actual module method to be routed to
1244
-     * @param    string $key         - url param key indicating a route is being called
1245
-     * @return    bool
1246
-     */
1247
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1248
-    {
1249
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1250
-        $module = str_replace('EED_', '', $module);
1251
-        $module_class = 'EED_' . $module;
1252
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1253
-            $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1254
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1255
-            return false;
1256
-        }
1257
-        if (empty($route)) {
1258
-            $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1259
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1260
-            return false;
1261
-        }
1262
-        if (! method_exists('EED_' . $module, $method_name)) {
1263
-            $msg = sprintf(
1264
-                __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1265
-                $route
1266
-            );
1267
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1268
-            return false;
1269
-        }
1270
-        EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1271
-        return true;
1272
-    }
1273
-
1274
-
1275
-    /**
1276
-     *    get_route - get module method route
1277
-     *
1278
-     * @access    public
1279
-     * @param    string $route - "pretty" public alias for module method
1280
-     * @param    string $key   - url param key indicating a route is being called
1281
-     * @return    string
1282
-     */
1283
-    public static function get_route($route = null, $key = 'ee')
1284
-    {
1285
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1286
-        $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1287
-        if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1288
-            return EE_Config::$_module_route_map[ $key ][ $route ];
1289
-        }
1290
-        return null;
1291
-    }
1292
-
1293
-
1294
-    /**
1295
-     *    get_routes - get ALL module method routes
1296
-     *
1297
-     * @access    public
1298
-     * @return    array
1299
-     */
1300
-    public static function get_routes()
1301
-    {
1302
-        return EE_Config::$_module_route_map;
1303
-    }
1304
-
1305
-
1306
-    /**
1307
-     *    register_forward - allows modules to forward request to another module for further processing
1308
-     *
1309
-     * @access    public
1310
-     * @param    string       $route   - "pretty" public alias for module method
1311
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1312
-     *                                 class, allows different forwards to be served based on status
1313
-     * @param    array|string $forward - function name or array( class, method )
1314
-     * @param    string       $key     - url param key indicating a route is being called
1315
-     * @return    bool
1316
-     */
1317
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1318
-    {
1319
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1320
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1321
-            $msg = sprintf(
1322
-                __('The module route %s for this forward has not been registered.', 'event_espresso'),
1323
-                $route
1324
-            );
1325
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1326
-            return false;
1327
-        }
1328
-        if (empty($forward)) {
1329
-            $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1330
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1331
-            return false;
1332
-        }
1333
-        if (is_array($forward)) {
1334
-            if (! isset($forward[1])) {
1335
-                $msg = sprintf(
1336
-                    __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1337
-                    $route
1338
-                );
1339
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1340
-                return false;
1341
-            }
1342
-            if (! method_exists($forward[0], $forward[1])) {
1343
-                $msg = sprintf(
1344
-                    __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1345
-                    $forward[1],
1346
-                    $route
1347
-                );
1348
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1349
-                return false;
1350
-            }
1351
-        } elseif (! function_exists($forward)) {
1352
-            $msg = sprintf(
1353
-                __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1354
-                $forward,
1355
-                $route
1356
-            );
1357
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1358
-            return false;
1359
-        }
1360
-        EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1361
-        return true;
1362
-    }
1363
-
1364
-
1365
-    /**
1366
-     *    get_forward - get forwarding route
1367
-     *
1368
-     * @access    public
1369
-     * @param    string  $route  - "pretty" public alias for module method
1370
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1371
-     *                           allows different forwards to be served based on status
1372
-     * @param    string  $key    - url param key indicating a route is being called
1373
-     * @return    string
1374
-     */
1375
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1376
-    {
1377
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1378
-        if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1379
-            return apply_filters(
1380
-                'FHEE__EE_Config__get_forward',
1381
-                EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1382
-                $route,
1383
-                $status
1384
-            );
1385
-        }
1386
-        return null;
1387
-    }
1388
-
1389
-
1390
-    /**
1391
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1392
-     *    results
1393
-     *
1394
-     * @access    public
1395
-     * @param    string  $route  - "pretty" public alias for module method
1396
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1397
-     *                           allows different views to be served based on status
1398
-     * @param    string  $view
1399
-     * @param    string  $key    - url param key indicating a route is being called
1400
-     * @return    bool
1401
-     */
1402
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1403
-    {
1404
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1405
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1406
-            $msg = sprintf(
1407
-                __('The module route %s for this view has not been registered.', 'event_espresso'),
1408
-                $route
1409
-            );
1410
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1411
-            return false;
1412
-        }
1413
-        if (! is_readable($view)) {
1414
-            $msg = sprintf(
1415
-                __(
1416
-                    'The %s view file could not be found or is not readable due to file permissions.',
1417
-                    'event_espresso'
1418
-                ),
1419
-                $view
1420
-            );
1421
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1422
-            return false;
1423
-        }
1424
-        EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1425
-        return true;
1426
-    }
1427
-
1428
-
1429
-    /**
1430
-     *    get_view - get view for route and status
1431
-     *
1432
-     * @access    public
1433
-     * @param    string  $route  - "pretty" public alias for module method
1434
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1435
-     *                           allows different views to be served based on status
1436
-     * @param    string  $key    - url param key indicating a route is being called
1437
-     * @return    string
1438
-     */
1439
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1440
-    {
1441
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1442
-        if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1443
-            return apply_filters(
1444
-                'FHEE__EE_Config__get_view',
1445
-                EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1446
-                $route,
1447
-                $status
1448
-            );
1449
-        }
1450
-        return null;
1451
-    }
1452
-
1453
-
1454
-    public function update_addon_option_names()
1455
-    {
1456
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1457
-    }
1458
-
1459
-
1460
-    public function shutdown()
1461
-    {
1462
-        $this->update_addon_option_names();
1463
-    }
1464
-
1465
-
1466
-    /**
1467
-     * @return LegacyShortcodesManager
1468
-     */
1469
-    public static function getLegacyShortcodesManager()
1470
-    {
1471
-
1472
-        if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1473
-            EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1474
-                EE_Registry::instance()
1475
-            );
1476
-        }
1477
-        return EE_Config::instance()->legacy_shortcodes_manager;
1478
-    }
1479
-
1480
-
1481
-    /**
1482
-     * register_shortcode - makes core aware of this shortcode
1483
-     *
1484
-     * @deprecated 4.9.26
1485
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1486
-     * @return    bool
1487
-     */
1488
-    public static function register_shortcode($shortcode_path = null)
1489
-    {
1490
-        EE_Error::doing_it_wrong(
1491
-            __METHOD__,
1492
-            __(
1493
-                'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1494
-                'event_espresso'
1495
-            ),
1496
-            '4.9.26'
1497
-        );
1498
-        return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1499
-    }
17
+	const OPTION_NAME = 'ee_config';
18
+
19
+	const LOG_NAME = 'ee_config_log';
20
+
21
+	const LOG_LENGTH = 100;
22
+
23
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
24
+
25
+	/**
26
+	 *    instance of the EE_Config object
27
+	 *
28
+	 * @var    EE_Config $_instance
29
+	 * @access    private
30
+	 */
31
+	private static $_instance;
32
+
33
+	/**
34
+	 * @var boolean $_logging_enabled
35
+	 */
36
+	private static $_logging_enabled = false;
37
+
38
+	/**
39
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
40
+	 */
41
+	private $legacy_shortcodes_manager;
42
+
43
+	/**
44
+	 * An StdClass whose property names are addon slugs,
45
+	 * and values are their config classes
46
+	 *
47
+	 * @var StdClass
48
+	 */
49
+	public $addons;
50
+
51
+	/**
52
+	 * @var EE_Admin_Config
53
+	 */
54
+	public $admin;
55
+
56
+	/**
57
+	 * @var EE_Core_Config
58
+	 */
59
+	public $core;
60
+
61
+	/**
62
+	 * @var EE_Currency_Config
63
+	 */
64
+	public $currency;
65
+
66
+	/**
67
+	 * @var EE_Organization_Config
68
+	 */
69
+	public $organization;
70
+
71
+	/**
72
+	 * @var EE_Registration_Config
73
+	 */
74
+	public $registration;
75
+
76
+	/**
77
+	 * @var EE_Template_Config
78
+	 */
79
+	public $template_settings;
80
+
81
+	/**
82
+	 * Holds EE environment values.
83
+	 *
84
+	 * @var EE_Environment_Config
85
+	 */
86
+	public $environment;
87
+
88
+	/**
89
+	 * settings pertaining to Google maps
90
+	 *
91
+	 * @var EE_Map_Config
92
+	 */
93
+	public $map_settings;
94
+
95
+	/**
96
+	 * settings pertaining to Taxes
97
+	 *
98
+	 * @var EE_Tax_Config
99
+	 */
100
+	public $tax_settings;
101
+
102
+	/**
103
+	 * Settings pertaining to global messages settings.
104
+	 *
105
+	 * @var EE_Messages_Config
106
+	 */
107
+	public $messages;
108
+
109
+	/**
110
+	 * @deprecated
111
+	 * @var EE_Gateway_Config
112
+	 */
113
+	public $gateway;
114
+
115
+	/**
116
+	 * @var    array $_addon_option_names
117
+	 * @access    private
118
+	 */
119
+	private $_addon_option_names = array();
120
+
121
+	/**
122
+	 * @var    array $_module_route_map
123
+	 * @access    private
124
+	 */
125
+	private static $_module_route_map = array();
126
+
127
+	/**
128
+	 * @var    array $_module_forward_map
129
+	 * @access    private
130
+	 */
131
+	private static $_module_forward_map = array();
132
+
133
+	/**
134
+	 * @var    array $_module_view_map
135
+	 * @access    private
136
+	 */
137
+	private static $_module_view_map = array();
138
+
139
+
140
+	/**
141
+	 * @singleton method used to instantiate class object
142
+	 * @access    public
143
+	 * @return EE_Config instance
144
+	 */
145
+	public static function instance()
146
+	{
147
+		// check if class object is instantiated, and instantiated properly
148
+		if (! self::$_instance instanceof EE_Config) {
149
+			self::$_instance = new self();
150
+		}
151
+		return self::$_instance;
152
+	}
153
+
154
+
155
+	/**
156
+	 * Resets the config
157
+	 *
158
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
159
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
160
+	 *                               reflect its state in the database
161
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
162
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
163
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
164
+	 *                               site was put into maintenance mode)
165
+	 * @return EE_Config
166
+	 */
167
+	public static function reset($hard_reset = false, $reinstantiate = true)
168
+	{
169
+		if (self::$_instance instanceof EE_Config) {
170
+			if ($hard_reset) {
171
+				self::$_instance->legacy_shortcodes_manager = null;
172
+				self::$_instance->_addon_option_names = array();
173
+				self::$_instance->_initialize_config();
174
+				self::$_instance->update_espresso_config();
175
+			}
176
+			self::$_instance->update_addon_option_names();
177
+		}
178
+		self::$_instance = null;
179
+		// we don't need to reset the static properties imo because those should
180
+		// only change when a module is added or removed. Currently we don't
181
+		// support removing a module during a request when it previously existed
182
+		if ($reinstantiate) {
183
+			return self::instance();
184
+		} else {
185
+			return null;
186
+		}
187
+	}
188
+
189
+
190
+	/**
191
+	 *    class constructor
192
+	 *
193
+	 * @access    private
194
+	 */
195
+	private function __construct()
196
+	{
197
+		do_action('AHEE__EE_Config__construct__begin', $this);
198
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
199
+		// setup empty config classes
200
+		$this->_initialize_config();
201
+		// load existing EE site settings
202
+		$this->_load_core_config();
203
+		// confirm everything loaded correctly and set filtered defaults if not
204
+		$this->_verify_config();
205
+		//  register shortcodes and modules
206
+		add_action(
207
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
208
+			array($this, 'register_shortcodes_and_modules'),
209
+			999
210
+		);
211
+		//  initialize shortcodes and modules
212
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
213
+		// register widgets
214
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
215
+		// shutdown
216
+		add_action('shutdown', array($this, 'shutdown'), 10);
217
+		// construct__end hook
218
+		do_action('AHEE__EE_Config__construct__end', $this);
219
+		// hardcoded hack
220
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
221
+	}
222
+
223
+
224
+	/**
225
+	 * @return boolean
226
+	 */
227
+	public static function logging_enabled()
228
+	{
229
+		return self::$_logging_enabled;
230
+	}
231
+
232
+
233
+	/**
234
+	 * use to get the current theme if needed from static context
235
+	 *
236
+	 * @return string current theme set.
237
+	 */
238
+	public static function get_current_theme()
239
+	{
240
+		return isset(self::$_instance->template_settings->current_espresso_theme)
241
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
242
+	}
243
+
244
+
245
+	/**
246
+	 *        _initialize_config
247
+	 *
248
+	 * @access private
249
+	 * @return void
250
+	 */
251
+	private function _initialize_config()
252
+	{
253
+		EE_Config::trim_log();
254
+		// set defaults
255
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
256
+		$this->addons = new stdClass();
257
+		// set _module_route_map
258
+		EE_Config::$_module_route_map = array();
259
+		// set _module_forward_map
260
+		EE_Config::$_module_forward_map = array();
261
+		// set _module_view_map
262
+		EE_Config::$_module_view_map = array();
263
+	}
264
+
265
+
266
+	/**
267
+	 *        load core plugin configuration
268
+	 *
269
+	 * @access private
270
+	 * @return void
271
+	 */
272
+	private function _load_core_config()
273
+	{
274
+		// load_core_config__start hook
275
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
276
+		$espresso_config = $this->get_espresso_config();
277
+		foreach ($espresso_config as $config => $settings) {
278
+			// load_core_config__start hook
279
+			$settings = apply_filters(
280
+				'FHEE__EE_Config___load_core_config__config_settings',
281
+				$settings,
282
+				$config,
283
+				$this
284
+			);
285
+			if (is_object($settings) && property_exists($this, $config)) {
286
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
287
+				// call configs populate method to ensure any defaults are set for empty values.
288
+				if (method_exists($settings, 'populate')) {
289
+					$this->{$config}->populate();
290
+				}
291
+				if (method_exists($settings, 'do_hooks')) {
292
+					$this->{$config}->do_hooks();
293
+				}
294
+			}
295
+		}
296
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
297
+			$this->update_espresso_config();
298
+		}
299
+		// load_core_config__end hook
300
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
301
+	}
302
+
303
+
304
+	/**
305
+	 *    _verify_config
306
+	 *
307
+	 * @access    protected
308
+	 * @return    void
309
+	 */
310
+	protected function _verify_config()
311
+	{
312
+		$this->core = $this->core instanceof EE_Core_Config
313
+			? $this->core
314
+			: new EE_Core_Config();
315
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
316
+		$this->organization = $this->organization instanceof EE_Organization_Config
317
+			? $this->organization
318
+			: new EE_Organization_Config();
319
+		$this->organization = apply_filters(
320
+			'FHEE__EE_Config___initialize_config__organization',
321
+			$this->organization
322
+		);
323
+		$this->currency = $this->currency instanceof EE_Currency_Config
324
+			? $this->currency
325
+			: new EE_Currency_Config();
326
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
327
+		$this->registration = $this->registration instanceof EE_Registration_Config
328
+			? $this->registration
329
+			: new EE_Registration_Config();
330
+		$this->registration = apply_filters(
331
+			'FHEE__EE_Config___initialize_config__registration',
332
+			$this->registration
333
+		);
334
+		$this->admin = $this->admin instanceof EE_Admin_Config
335
+			? $this->admin
336
+			: new EE_Admin_Config();
337
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
338
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
339
+			? $this->template_settings
340
+			: new EE_Template_Config();
341
+		$this->template_settings = apply_filters(
342
+			'FHEE__EE_Config___initialize_config__template_settings',
343
+			$this->template_settings
344
+		);
345
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
346
+			? $this->map_settings
347
+			: new EE_Map_Config();
348
+		$this->map_settings = apply_filters(
349
+			'FHEE__EE_Config___initialize_config__map_settings',
350
+			$this->map_settings
351
+		);
352
+		$this->environment = $this->environment instanceof EE_Environment_Config
353
+			? $this->environment
354
+			: new EE_Environment_Config();
355
+		$this->environment = apply_filters(
356
+			'FHEE__EE_Config___initialize_config__environment',
357
+			$this->environment
358
+		);
359
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
360
+			? $this->tax_settings
361
+			: new EE_Tax_Config();
362
+		$this->tax_settings = apply_filters(
363
+			'FHEE__EE_Config___initialize_config__tax_settings',
364
+			$this->tax_settings
365
+		);
366
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
367
+		$this->messages = $this->messages instanceof EE_Messages_Config
368
+			? $this->messages
369
+			: new EE_Messages_Config();
370
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
371
+			? $this->gateway
372
+			: new EE_Gateway_Config();
373
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
374
+		$this->legacy_shortcodes_manager = null;
375
+	}
376
+
377
+
378
+	/**
379
+	 *    get_espresso_config
380
+	 *
381
+	 * @access    public
382
+	 * @return    array of espresso config stuff
383
+	 */
384
+	public function get_espresso_config()
385
+	{
386
+		// grab espresso configuration
387
+		return apply_filters(
388
+			'FHEE__EE_Config__get_espresso_config__CFG',
389
+			get_option(EE_Config::OPTION_NAME, array())
390
+		);
391
+	}
392
+
393
+
394
+	/**
395
+	 *    double_check_config_comparison
396
+	 *
397
+	 * @access    public
398
+	 * @param string $option
399
+	 * @param        $old_value
400
+	 * @param        $value
401
+	 */
402
+	public function double_check_config_comparison($option = '', $old_value, $value)
403
+	{
404
+		// make sure we're checking the ee config
405
+		if ($option === EE_Config::OPTION_NAME) {
406
+			// run a loose comparison of the old value against the new value for type and properties,
407
+			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
408
+			if ($value != $old_value) {
409
+				// if they are NOT the same, then remove the hook,
410
+				// which means the subsequent update results will be based solely on the update query results
411
+				// the reason we do this is because, as stated above,
412
+				// WP update_option performs an exact instance comparison (===) on any update values passed to it
413
+				// this happens PRIOR to serialization and any subsequent update.
414
+				// If values are found to match their previous old value,
415
+				// then WP bails before performing any update.
416
+				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
417
+				// it just pulled from the db, with the one being passed to it (which will not match).
418
+				// HOWEVER, once the object is serialized and passed off to MySQL to update,
419
+				// MySQL MAY ALSO NOT perform the update because
420
+				// the string it sees in the db looks the same as the new one it has been passed!!!
421
+				// This results in the query returning an "affected rows" value of ZERO,
422
+				// which gets returned immediately by WP update_option and looks like an error.
423
+				remove_action('update_option', array($this, 'check_config_updated'));
424
+			}
425
+		}
426
+	}
427
+
428
+
429
+	/**
430
+	 *    update_espresso_config
431
+	 *
432
+	 * @access   public
433
+	 */
434
+	protected function _reset_espresso_addon_config()
435
+	{
436
+		$this->_addon_option_names = array();
437
+		foreach ($this->addons as $addon_name => $addon_config_obj) {
438
+			$addon_config_obj = maybe_unserialize($addon_config_obj);
439
+			if ($addon_config_obj instanceof EE_Config_Base) {
440
+				$this->update_config('addons', $addon_name, $addon_config_obj, false);
441
+			}
442
+			$this->addons->{$addon_name} = null;
443
+		}
444
+	}
445
+
446
+
447
+	/**
448
+	 *    update_espresso_config
449
+	 *
450
+	 * @access   public
451
+	 * @param   bool $add_success
452
+	 * @param   bool $add_error
453
+	 * @return   bool
454
+	 */
455
+	public function update_espresso_config($add_success = false, $add_error = true)
456
+	{
457
+		// don't allow config updates during WP heartbeats
458
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
459
+			return false;
460
+		}
461
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
462
+		// $clone = clone( self::$_instance );
463
+		// self::$_instance = NULL;
464
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
465
+		$this->_reset_espresso_addon_config();
466
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
467
+		// but BEFORE the actual update occurs
468
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
469
+		// don't want to persist legacy_shortcodes_manager, but don't want to lose it either
470
+		$legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
471
+		$this->legacy_shortcodes_manager = null;
472
+		// now update "ee_config"
473
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
474
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
475
+		EE_Config::log(EE_Config::OPTION_NAME);
476
+		// if not saved... check if the hook we just added still exists;
477
+		// if it does, it means one of two things:
478
+		// that update_option bailed at the($value === $old_value) conditional,
479
+		// or...
480
+		// the db update query returned 0 rows affected
481
+		// (probably because the data  value was the same from it's perspective)
482
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
483
+		// but just means no update occurred, so don't display an error to the user.
484
+		// BUT... if update_option returns FALSE, AND the hook is missing,
485
+		// then it means that something truly went wrong
486
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
487
+		// remove our action since we don't want it in the system anymore
488
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
489
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
490
+		// self::$_instance = $clone;
491
+		// unset( $clone );
492
+		// if config remains the same or was updated successfully
493
+		if ($saved) {
494
+			if ($add_success) {
495
+				EE_Error::add_success(
496
+					__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
497
+					__FILE__,
498
+					__FUNCTION__,
499
+					__LINE__
500
+				);
501
+			}
502
+			return true;
503
+		} else {
504
+			if ($add_error) {
505
+				EE_Error::add_error(
506
+					__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
507
+					__FILE__,
508
+					__FUNCTION__,
509
+					__LINE__
510
+				);
511
+			}
512
+			return false;
513
+		}
514
+	}
515
+
516
+
517
+	/**
518
+	 *    _verify_config_params
519
+	 *
520
+	 * @access    private
521
+	 * @param    string         $section
522
+	 * @param    string         $name
523
+	 * @param    string         $config_class
524
+	 * @param    EE_Config_Base $config_obj
525
+	 * @param    array          $tests_to_run
526
+	 * @param    bool           $display_errors
527
+	 * @return    bool    TRUE on success, FALSE on fail
528
+	 */
529
+	private function _verify_config_params(
530
+		$section = '',
531
+		$name = '',
532
+		$config_class = '',
533
+		$config_obj = null,
534
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
535
+		$display_errors = true
536
+	) {
537
+		try {
538
+			foreach ($tests_to_run as $test) {
539
+				switch ($test) {
540
+					// TEST #1 : check that section was set
541
+					case 1:
542
+						if (empty($section)) {
543
+							if ($display_errors) {
544
+								throw new EE_Error(
545
+									sprintf(
546
+										__(
547
+											'No configuration section has been provided while attempting to save "%s".',
548
+											'event_espresso'
549
+										),
550
+										$config_class
551
+									)
552
+								);
553
+							}
554
+							return false;
555
+						}
556
+						break;
557
+					// TEST #2 : check that settings section exists
558
+					case 2:
559
+						if (! isset($this->{$section})) {
560
+							if ($display_errors) {
561
+								throw new EE_Error(
562
+									sprintf(
563
+										__('The "%s" configuration section does not exist.', 'event_espresso'),
564
+										$section
565
+									)
566
+								);
567
+							}
568
+							return false;
569
+						}
570
+						break;
571
+					// TEST #3 : check that section is the proper format
572
+					case 3:
573
+						if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
574
+						) {
575
+							if ($display_errors) {
576
+								throw new EE_Error(
577
+									sprintf(
578
+										__(
579
+											'The "%s" configuration settings have not been formatted correctly.',
580
+											'event_espresso'
581
+										),
582
+										$section
583
+									)
584
+								);
585
+							}
586
+							return false;
587
+						}
588
+						break;
589
+					// TEST #4 : check that config section name has been set
590
+					case 4:
591
+						if (empty($name)) {
592
+							if ($display_errors) {
593
+								throw new EE_Error(
594
+									__(
595
+										'No name has been provided for the specific configuration section.',
596
+										'event_espresso'
597
+									)
598
+								);
599
+							}
600
+							return false;
601
+						}
602
+						break;
603
+					// TEST #5 : check that a config class name has been set
604
+					case 5:
605
+						if (empty($config_class)) {
606
+							if ($display_errors) {
607
+								throw new EE_Error(
608
+									__(
609
+										'No class name has been provided for the specific configuration section.',
610
+										'event_espresso'
611
+									)
612
+								);
613
+							}
614
+							return false;
615
+						}
616
+						break;
617
+					// TEST #6 : verify config class is accessible
618
+					case 6:
619
+						if (! class_exists($config_class)) {
620
+							if ($display_errors) {
621
+								throw new EE_Error(
622
+									sprintf(
623
+										__(
624
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
625
+											'event_espresso'
626
+										),
627
+										$config_class
628
+									)
629
+								);
630
+							}
631
+							return false;
632
+						}
633
+						break;
634
+					// TEST #7 : check that config has even been set
635
+					case 7:
636
+						if (! isset($this->{$section}->{$name})) {
637
+							if ($display_errors) {
638
+								throw new EE_Error(
639
+									sprintf(
640
+										__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
641
+										$section,
642
+										$name
643
+									)
644
+								);
645
+							}
646
+							return false;
647
+						} else {
648
+							// and make sure it's not serialized
649
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
650
+						}
651
+						break;
652
+					// TEST #8 : check that config is the requested type
653
+					case 8:
654
+						if (! $this->{$section}->{$name} instanceof $config_class) {
655
+							if ($display_errors) {
656
+								throw new EE_Error(
657
+									sprintf(
658
+										__(
659
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
660
+											'event_espresso'
661
+										),
662
+										$section,
663
+										$name,
664
+										$config_class
665
+									)
666
+								);
667
+							}
668
+							return false;
669
+						}
670
+						break;
671
+					// TEST #9 : verify config object
672
+					case 9:
673
+						if (! $config_obj instanceof EE_Config_Base) {
674
+							if ($display_errors) {
675
+								throw new EE_Error(
676
+									sprintf(
677
+										__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
678
+										print_r($config_obj, true)
679
+									)
680
+								);
681
+							}
682
+							return false;
683
+						}
684
+						break;
685
+				}
686
+			}
687
+		} catch (EE_Error $e) {
688
+			$e->get_error();
689
+		}
690
+		// you have successfully run the gauntlet
691
+		return true;
692
+	}
693
+
694
+
695
+	/**
696
+	 *    _generate_config_option_name
697
+	 *
698
+	 * @access        protected
699
+	 * @param        string $section
700
+	 * @param        string $name
701
+	 * @return        string
702
+	 */
703
+	private function _generate_config_option_name($section = '', $name = '')
704
+	{
705
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
706
+	}
707
+
708
+
709
+	/**
710
+	 *    _set_config_class
711
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
712
+	 *
713
+	 * @access    private
714
+	 * @param    string $config_class
715
+	 * @param    string $name
716
+	 * @return    string
717
+	 */
718
+	private function _set_config_class($config_class = '', $name = '')
719
+	{
720
+		return ! empty($config_class)
721
+			? $config_class
722
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
723
+	}
724
+
725
+
726
+	/**
727
+	 *    set_config
728
+	 *
729
+	 * @access    protected
730
+	 * @param    string         $section
731
+	 * @param    string         $name
732
+	 * @param    string         $config_class
733
+	 * @param    EE_Config_Base $config_obj
734
+	 * @return    EE_Config_Base
735
+	 */
736
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
737
+	{
738
+		// ensure config class is set to something
739
+		$config_class = $this->_set_config_class($config_class, $name);
740
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
741
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
742
+			return null;
743
+		}
744
+		$config_option_name = $this->_generate_config_option_name($section, $name);
745
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
746
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
747
+			$this->_addon_option_names[ $config_option_name ] = $config_class;
748
+			$this->update_addon_option_names();
749
+		}
750
+		// verify the incoming config object but suppress errors
751
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
752
+			$config_obj = new $config_class();
753
+		}
754
+		if (get_option($config_option_name)) {
755
+			EE_Config::log($config_option_name);
756
+			update_option($config_option_name, $config_obj);
757
+			$this->{$section}->{$name} = $config_obj;
758
+			return $this->{$section}->{$name};
759
+		} else {
760
+			// create a wp-option for this config
761
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
762
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
763
+				return $this->{$section}->{$name};
764
+			} else {
765
+				EE_Error::add_error(
766
+					sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
767
+					__FILE__,
768
+					__FUNCTION__,
769
+					__LINE__
770
+				);
771
+				return null;
772
+			}
773
+		}
774
+	}
775
+
776
+
777
+	/**
778
+	 *    update_config
779
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
780
+	 *
781
+	 * @access    public
782
+	 * @param    string                $section
783
+	 * @param    string                $name
784
+	 * @param    EE_Config_Base|string $config_obj
785
+	 * @param    bool                  $throw_errors
786
+	 * @return    bool
787
+	 */
788
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
789
+	{
790
+		// don't allow config updates during WP heartbeats
791
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
792
+			return false;
793
+		}
794
+		$config_obj = maybe_unserialize($config_obj);
795
+		// get class name of the incoming object
796
+		$config_class = get_class($config_obj);
797
+		// run tests 1-5 and 9 to verify config
798
+		if (! $this->_verify_config_params(
799
+			$section,
800
+			$name,
801
+			$config_class,
802
+			$config_obj,
803
+			array(1, 2, 3, 4, 7, 9)
804
+		)
805
+		) {
806
+			return false;
807
+		}
808
+		$config_option_name = $this->_generate_config_option_name($section, $name);
809
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
810
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
811
+			// save new config to db
812
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
813
+				return true;
814
+			}
815
+		} else {
816
+			// first check if the record already exists
817
+			$existing_config = get_option($config_option_name);
818
+			$config_obj = serialize($config_obj);
819
+			// just return if db record is already up to date (NOT type safe comparison)
820
+			if ($existing_config == $config_obj) {
821
+				$this->{$section}->{$name} = $config_obj;
822
+				return true;
823
+			} elseif (update_option($config_option_name, $config_obj)) {
824
+				EE_Config::log($config_option_name);
825
+				// update wp-option for this config class
826
+				$this->{$section}->{$name} = $config_obj;
827
+				return true;
828
+			} elseif ($throw_errors) {
829
+				EE_Error::add_error(
830
+					sprintf(
831
+						__(
832
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
833
+							'event_espresso'
834
+						),
835
+						$config_class,
836
+						'EE_Config->' . $section . '->' . $name
837
+					),
838
+					__FILE__,
839
+					__FUNCTION__,
840
+					__LINE__
841
+				);
842
+			}
843
+		}
844
+		return false;
845
+	}
846
+
847
+
848
+	/**
849
+	 *    get_config
850
+	 *
851
+	 * @access    public
852
+	 * @param    string $section
853
+	 * @param    string $name
854
+	 * @param    string $config_class
855
+	 * @return    mixed EE_Config_Base | NULL
856
+	 */
857
+	public function get_config($section = '', $name = '', $config_class = '')
858
+	{
859
+		// ensure config class is set to something
860
+		$config_class = $this->_set_config_class($config_class, $name);
861
+		// run tests 1-4, 6 and 7 to verify that all params have been set
862
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
863
+			return null;
864
+		}
865
+		// now test if the requested config object exists, but suppress errors
866
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
867
+			// config already exists, so pass it back
868
+			return $this->{$section}->{$name};
869
+		}
870
+		// load config option from db if it exists
871
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
872
+		// verify the newly retrieved config object, but suppress errors
873
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
874
+			// config is good, so set it and pass it back
875
+			$this->{$section}->{$name} = $config_obj;
876
+			return $this->{$section}->{$name};
877
+		}
878
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
879
+		$config_obj = $this->set_config($section, $name, $config_class);
880
+		// verify the newly created config object
881
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
882
+			return $this->{$section}->{$name};
883
+		} else {
884
+			EE_Error::add_error(
885
+				sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
886
+				__FILE__,
887
+				__FUNCTION__,
888
+				__LINE__
889
+			);
890
+		}
891
+		return null;
892
+	}
893
+
894
+
895
+	/**
896
+	 *    get_config_option
897
+	 *
898
+	 * @access    public
899
+	 * @param    string $config_option_name
900
+	 * @return    mixed EE_Config_Base | FALSE
901
+	 */
902
+	public function get_config_option($config_option_name = '')
903
+	{
904
+		// retrieve the wp-option for this config class.
905
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
906
+		if (empty($config_option)) {
907
+			EE_Config::log($config_option_name . '-NOT-FOUND');
908
+		}
909
+		return $config_option;
910
+	}
911
+
912
+
913
+	/**
914
+	 * log
915
+	 *
916
+	 * @param string $config_option_name
917
+	 */
918
+	public static function log($config_option_name = '')
919
+	{
920
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
921
+			$config_log = get_option(EE_Config::LOG_NAME, array());
922
+			// copy incoming $_REQUEST and sanitize it so we can save it
923
+			$_request = $_REQUEST;
924
+			array_walk_recursive($_request, 'sanitize_text_field');
925
+			$config_log[ (string) microtime(true) ] = array(
926
+				'config_name' => $config_option_name,
927
+				'request'     => $_request,
928
+			);
929
+			update_option(EE_Config::LOG_NAME, $config_log);
930
+		}
931
+	}
932
+
933
+
934
+	/**
935
+	 * trim_log
936
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
937
+	 */
938
+	public static function trim_log()
939
+	{
940
+		if (! EE_Config::logging_enabled()) {
941
+			return;
942
+		}
943
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
944
+		$log_length = count($config_log);
945
+		if ($log_length > EE_Config::LOG_LENGTH) {
946
+			ksort($config_log);
947
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
948
+			update_option(EE_Config::LOG_NAME, $config_log);
949
+		}
950
+	}
951
+
952
+
953
+	/**
954
+	 *    get_page_for_posts
955
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
956
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
957
+	 *
958
+	 * @access    public
959
+	 * @return    string
960
+	 */
961
+	public static function get_page_for_posts()
962
+	{
963
+		$page_for_posts = get_option('page_for_posts');
964
+		if (! $page_for_posts) {
965
+			return 'posts';
966
+		}
967
+		/** @type WPDB $wpdb */
968
+		global $wpdb;
969
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
970
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
971
+	}
972
+
973
+
974
+	/**
975
+	 *    register_shortcodes_and_modules.
976
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
977
+	 *    In fact, this is where we give modules a chance to let core know they exist
978
+	 *    so they can help trigger maintenance mode if it's needed
979
+	 *
980
+	 * @access    public
981
+	 * @return    void
982
+	 */
983
+	public function register_shortcodes_and_modules()
984
+	{
985
+		// allow modules to set hooks for the rest of the system
986
+		EE_Registry::instance()->modules = $this->_register_modules();
987
+	}
988
+
989
+
990
+	/**
991
+	 *    initialize_shortcodes_and_modules
992
+	 *    meaning they can start adding their hooks to get stuff done
993
+	 *
994
+	 * @access    public
995
+	 * @return    void
996
+	 */
997
+	public function initialize_shortcodes_and_modules()
998
+	{
999
+		// allow modules to set hooks for the rest of the system
1000
+		$this->_initialize_modules();
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 *    widgets_init
1006
+	 *
1007
+	 * @access private
1008
+	 * @return void
1009
+	 */
1010
+	public function widgets_init()
1011
+	{
1012
+		// only init widgets on admin pages when not in complete maintenance, and
1013
+		// on frontend when not in any maintenance mode
1014
+		if (! EE_Maintenance_Mode::instance()->level()
1015
+			|| (
1016
+				is_admin()
1017
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1018
+			)
1019
+		) {
1020
+			// grab list of installed widgets
1021
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1022
+			// filter list of modules to register
1023
+			$widgets_to_register = apply_filters(
1024
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1025
+				$widgets_to_register
1026
+			);
1027
+			if (! empty($widgets_to_register)) {
1028
+				// cycle thru widget folders
1029
+				foreach ($widgets_to_register as $widget_path) {
1030
+					// add to list of installed widget modules
1031
+					EE_Config::register_ee_widget($widget_path);
1032
+				}
1033
+			}
1034
+			// filter list of installed modules
1035
+			EE_Registry::instance()->widgets = apply_filters(
1036
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1037
+				EE_Registry::instance()->widgets
1038
+			);
1039
+		}
1040
+	}
1041
+
1042
+
1043
+	/**
1044
+	 *    register_ee_widget - makes core aware of this widget
1045
+	 *
1046
+	 * @access    public
1047
+	 * @param    string $widget_path - full path up to and including widget folder
1048
+	 * @return    void
1049
+	 */
1050
+	public static function register_ee_widget($widget_path = null)
1051
+	{
1052
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1053
+		$widget_ext = '.widget.php';
1054
+		// make all separators match
1055
+		$widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1056
+		// does the file path INCLUDE the actual file name as part of the path ?
1057
+		if (strpos($widget_path, $widget_ext) !== false) {
1058
+			// grab and shortcode file name from directory name and break apart at dots
1059
+			$file_name = explode('.', basename($widget_path));
1060
+			// take first segment from file name pieces and remove class prefix if it exists
1061
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1062
+			// sanitize shortcode directory name
1063
+			$widget = sanitize_key($widget);
1064
+			// now we need to rebuild the shortcode path
1065
+			$widget_path = explode(DS, $widget_path);
1066
+			// remove last segment
1067
+			array_pop($widget_path);
1068
+			// glue it back together
1069
+			$widget_path = implode(DS, $widget_path);
1070
+		} else {
1071
+			// grab and sanitize widget directory name
1072
+			$widget = sanitize_key(basename($widget_path));
1073
+		}
1074
+		// create classname from widget directory name
1075
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1076
+		// add class prefix
1077
+		$widget_class = 'EEW_' . $widget;
1078
+		// does the widget exist ?
1079
+		if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1080
+			$msg = sprintf(
1081
+				__(
1082
+					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1083
+					'event_espresso'
1084
+				),
1085
+				$widget_class,
1086
+				$widget_path . DS . $widget_class . $widget_ext
1087
+			);
1088
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1089
+			return;
1090
+		}
1091
+		// load the widget class file
1092
+		require_once($widget_path . DS . $widget_class . $widget_ext);
1093
+		// verify that class exists
1094
+		if (! class_exists($widget_class)) {
1095
+			$msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1096
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1097
+			return;
1098
+		}
1099
+		register_widget($widget_class);
1100
+		// add to array of registered widgets
1101
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1102
+	}
1103
+
1104
+
1105
+	/**
1106
+	 *        _register_modules
1107
+	 *
1108
+	 * @access private
1109
+	 * @return array
1110
+	 */
1111
+	private function _register_modules()
1112
+	{
1113
+		// grab list of installed modules
1114
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1115
+		// filter list of modules to register
1116
+		$modules_to_register = apply_filters(
1117
+			'FHEE__EE_Config__register_modules__modules_to_register',
1118
+			$modules_to_register
1119
+		);
1120
+		if (! empty($modules_to_register)) {
1121
+			// loop through folders
1122
+			foreach ($modules_to_register as $module_path) {
1123
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1124
+				if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1125
+					&& $module_path !== EE_MODULES . 'gateways'
1126
+				) {
1127
+					// add to list of installed modules
1128
+					EE_Config::register_module($module_path);
1129
+				}
1130
+			}
1131
+		}
1132
+		// filter list of installed modules
1133
+		return apply_filters(
1134
+			'FHEE__EE_Config___register_modules__installed_modules',
1135
+			EE_Registry::instance()->modules
1136
+		);
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 *    register_module - makes core aware of this module
1142
+	 *
1143
+	 * @access    public
1144
+	 * @param    string $module_path - full path up to and including module folder
1145
+	 * @return    bool
1146
+	 */
1147
+	public static function register_module($module_path = null)
1148
+	{
1149
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1150
+		$module_ext = '.module.php';
1151
+		// make all separators match
1152
+		$module_path = str_replace(array('\\', '/'), DS, $module_path);
1153
+		// does the file path INCLUDE the actual file name as part of the path ?
1154
+		if (strpos($module_path, $module_ext) !== false) {
1155
+			// grab and shortcode file name from directory name and break apart at dots
1156
+			$module_file = explode('.', basename($module_path));
1157
+			// now we need to rebuild the shortcode path
1158
+			$module_path = explode(DS, $module_path);
1159
+			// remove last segment
1160
+			array_pop($module_path);
1161
+			// glue it back together
1162
+			$module_path = implode(DS, $module_path) . DS;
1163
+			// take first segment from file name pieces and sanitize it
1164
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1165
+			// ensure class prefix is added
1166
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1167
+		} else {
1168
+			// we need to generate the filename based off of the folder name
1169
+			// grab and sanitize module name
1170
+			$module = strtolower(basename($module_path));
1171
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1172
+			// like trailingslashit()
1173
+			$module_path = rtrim($module_path, DS) . DS;
1174
+			// create classname from module directory name
1175
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1176
+			// add class prefix
1177
+			$module_class = 'EED_' . $module;
1178
+		}
1179
+		// does the module exist ?
1180
+		if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1181
+			$msg = sprintf(
1182
+				__(
1183
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1184
+					'event_espresso'
1185
+				),
1186
+				$module
1187
+			);
1188
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1189
+			return false;
1190
+		}
1191
+		// load the module class file
1192
+		require_once($module_path . $module_class . $module_ext);
1193
+		// verify that class exists
1194
+		if (! class_exists($module_class)) {
1195
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1196
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1197
+			return false;
1198
+		}
1199
+		// add to array of registered modules
1200
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1201
+		do_action(
1202
+			'AHEE__EE_Config__register_module__complete',
1203
+			$module_class,
1204
+			EE_Registry::instance()->modules->{$module_class}
1205
+		);
1206
+		return true;
1207
+	}
1208
+
1209
+
1210
+	/**
1211
+	 *    _initialize_modules
1212
+	 *    allow modules to set hooks for the rest of the system
1213
+	 *
1214
+	 * @access private
1215
+	 * @return void
1216
+	 */
1217
+	private function _initialize_modules()
1218
+	{
1219
+		// cycle thru shortcode folders
1220
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1221
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1222
+			// which set hooks ?
1223
+			if (is_admin()) {
1224
+				// fire immediately
1225
+				call_user_func(array($module_class, 'set_hooks_admin'));
1226
+			} else {
1227
+				// delay until other systems are online
1228
+				add_action(
1229
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1230
+					array($module_class, 'set_hooks')
1231
+				);
1232
+			}
1233
+		}
1234
+	}
1235
+
1236
+
1237
+	/**
1238
+	 *    register_route - adds module method routes to route_map
1239
+	 *
1240
+	 * @access    public
1241
+	 * @param    string $route       - "pretty" public alias for module method
1242
+	 * @param    string $module      - module name (classname without EED_ prefix)
1243
+	 * @param    string $method_name - the actual module method to be routed to
1244
+	 * @param    string $key         - url param key indicating a route is being called
1245
+	 * @return    bool
1246
+	 */
1247
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1248
+	{
1249
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1250
+		$module = str_replace('EED_', '', $module);
1251
+		$module_class = 'EED_' . $module;
1252
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1253
+			$msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1254
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1255
+			return false;
1256
+		}
1257
+		if (empty($route)) {
1258
+			$msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1259
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1260
+			return false;
1261
+		}
1262
+		if (! method_exists('EED_' . $module, $method_name)) {
1263
+			$msg = sprintf(
1264
+				__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1265
+				$route
1266
+			);
1267
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1268
+			return false;
1269
+		}
1270
+		EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1271
+		return true;
1272
+	}
1273
+
1274
+
1275
+	/**
1276
+	 *    get_route - get module method route
1277
+	 *
1278
+	 * @access    public
1279
+	 * @param    string $route - "pretty" public alias for module method
1280
+	 * @param    string $key   - url param key indicating a route is being called
1281
+	 * @return    string
1282
+	 */
1283
+	public static function get_route($route = null, $key = 'ee')
1284
+	{
1285
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1286
+		$route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1287
+		if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1288
+			return EE_Config::$_module_route_map[ $key ][ $route ];
1289
+		}
1290
+		return null;
1291
+	}
1292
+
1293
+
1294
+	/**
1295
+	 *    get_routes - get ALL module method routes
1296
+	 *
1297
+	 * @access    public
1298
+	 * @return    array
1299
+	 */
1300
+	public static function get_routes()
1301
+	{
1302
+		return EE_Config::$_module_route_map;
1303
+	}
1304
+
1305
+
1306
+	/**
1307
+	 *    register_forward - allows modules to forward request to another module for further processing
1308
+	 *
1309
+	 * @access    public
1310
+	 * @param    string       $route   - "pretty" public alias for module method
1311
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1312
+	 *                                 class, allows different forwards to be served based on status
1313
+	 * @param    array|string $forward - function name or array( class, method )
1314
+	 * @param    string       $key     - url param key indicating a route is being called
1315
+	 * @return    bool
1316
+	 */
1317
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1318
+	{
1319
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1320
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1321
+			$msg = sprintf(
1322
+				__('The module route %s for this forward has not been registered.', 'event_espresso'),
1323
+				$route
1324
+			);
1325
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1326
+			return false;
1327
+		}
1328
+		if (empty($forward)) {
1329
+			$msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1330
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1331
+			return false;
1332
+		}
1333
+		if (is_array($forward)) {
1334
+			if (! isset($forward[1])) {
1335
+				$msg = sprintf(
1336
+					__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1337
+					$route
1338
+				);
1339
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1340
+				return false;
1341
+			}
1342
+			if (! method_exists($forward[0], $forward[1])) {
1343
+				$msg = sprintf(
1344
+					__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1345
+					$forward[1],
1346
+					$route
1347
+				);
1348
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1349
+				return false;
1350
+			}
1351
+		} elseif (! function_exists($forward)) {
1352
+			$msg = sprintf(
1353
+				__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1354
+				$forward,
1355
+				$route
1356
+			);
1357
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1358
+			return false;
1359
+		}
1360
+		EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1361
+		return true;
1362
+	}
1363
+
1364
+
1365
+	/**
1366
+	 *    get_forward - get forwarding route
1367
+	 *
1368
+	 * @access    public
1369
+	 * @param    string  $route  - "pretty" public alias for module method
1370
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1371
+	 *                           allows different forwards to be served based on status
1372
+	 * @param    string  $key    - url param key indicating a route is being called
1373
+	 * @return    string
1374
+	 */
1375
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1376
+	{
1377
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1378
+		if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1379
+			return apply_filters(
1380
+				'FHEE__EE_Config__get_forward',
1381
+				EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1382
+				$route,
1383
+				$status
1384
+			);
1385
+		}
1386
+		return null;
1387
+	}
1388
+
1389
+
1390
+	/**
1391
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1392
+	 *    results
1393
+	 *
1394
+	 * @access    public
1395
+	 * @param    string  $route  - "pretty" public alias for module method
1396
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1397
+	 *                           allows different views to be served based on status
1398
+	 * @param    string  $view
1399
+	 * @param    string  $key    - url param key indicating a route is being called
1400
+	 * @return    bool
1401
+	 */
1402
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1403
+	{
1404
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1405
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1406
+			$msg = sprintf(
1407
+				__('The module route %s for this view has not been registered.', 'event_espresso'),
1408
+				$route
1409
+			);
1410
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1411
+			return false;
1412
+		}
1413
+		if (! is_readable($view)) {
1414
+			$msg = sprintf(
1415
+				__(
1416
+					'The %s view file could not be found or is not readable due to file permissions.',
1417
+					'event_espresso'
1418
+				),
1419
+				$view
1420
+			);
1421
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1422
+			return false;
1423
+		}
1424
+		EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1425
+		return true;
1426
+	}
1427
+
1428
+
1429
+	/**
1430
+	 *    get_view - get view for route and status
1431
+	 *
1432
+	 * @access    public
1433
+	 * @param    string  $route  - "pretty" public alias for module method
1434
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1435
+	 *                           allows different views to be served based on status
1436
+	 * @param    string  $key    - url param key indicating a route is being called
1437
+	 * @return    string
1438
+	 */
1439
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1440
+	{
1441
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1442
+		if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1443
+			return apply_filters(
1444
+				'FHEE__EE_Config__get_view',
1445
+				EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1446
+				$route,
1447
+				$status
1448
+			);
1449
+		}
1450
+		return null;
1451
+	}
1452
+
1453
+
1454
+	public function update_addon_option_names()
1455
+	{
1456
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1457
+	}
1458
+
1459
+
1460
+	public function shutdown()
1461
+	{
1462
+		$this->update_addon_option_names();
1463
+	}
1464
+
1465
+
1466
+	/**
1467
+	 * @return LegacyShortcodesManager
1468
+	 */
1469
+	public static function getLegacyShortcodesManager()
1470
+	{
1471
+
1472
+		if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1473
+			EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1474
+				EE_Registry::instance()
1475
+			);
1476
+		}
1477
+		return EE_Config::instance()->legacy_shortcodes_manager;
1478
+	}
1479
+
1480
+
1481
+	/**
1482
+	 * register_shortcode - makes core aware of this shortcode
1483
+	 *
1484
+	 * @deprecated 4.9.26
1485
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1486
+	 * @return    bool
1487
+	 */
1488
+	public static function register_shortcode($shortcode_path = null)
1489
+	{
1490
+		EE_Error::doing_it_wrong(
1491
+			__METHOD__,
1492
+			__(
1493
+				'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1494
+				'event_espresso'
1495
+			),
1496
+			'4.9.26'
1497
+		);
1498
+		return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1499
+	}
1500 1500
 }
1501 1501
 
1502 1502
 /**
@@ -1505,1018 +1505,1018 @@  discard block
 block discarded – undo
1505 1505
  * basically, they should just be well-defined stdClasses
1506 1506
  */
1507 1507
 class EE_Config_Base
1508
-{
1509
-
1510
-    /**
1511
-     * Utility function for escaping the value of a property and returning.
1512
-     *
1513
-     * @param string $property property name (checks to see if exists).
1514
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1515
-     * @throws \EE_Error
1516
-     */
1517
-    public function get_pretty($property)
1518
-    {
1519
-        if (! property_exists($this, $property)) {
1520
-            throw new EE_Error(
1521
-                sprintf(
1522
-                    __(
1523
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1524
-                        'event_espresso'
1525
-                    ),
1526
-                    get_class($this),
1527
-                    $property
1528
-                )
1529
-            );
1530
-        }
1531
-        // just handling escaping of strings for now.
1532
-        if (is_string($this->{$property})) {
1533
-            return stripslashes($this->{$property});
1534
-        }
1535
-        return $this->{$property};
1536
-    }
1537
-
1538
-
1539
-    public function populate()
1540
-    {
1541
-        // grab defaults via a new instance of this class.
1542
-        $class_name = get_class($this);
1543
-        $defaults = new $class_name;
1544
-        // loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1545
-        // default from our $defaults object.
1546
-        foreach (get_object_vars($defaults) as $property => $value) {
1547
-            if ($this->{$property} === null) {
1548
-                $this->{$property} = $value;
1549
-            }
1550
-        }
1551
-        // cleanup
1552
-        unset($defaults);
1553
-    }
1554
-
1555
-
1556
-    /**
1557
-     *        __isset
1558
-     *
1559
-     * @param $a
1560
-     * @return bool
1561
-     */
1562
-    public function __isset($a)
1563
-    {
1564
-        return false;
1565
-    }
1566
-
1567
-
1568
-    /**
1569
-     *        __unset
1570
-     *
1571
-     * @param $a
1572
-     * @return bool
1573
-     */
1574
-    public function __unset($a)
1575
-    {
1576
-        return false;
1577
-    }
1578
-
1579
-
1580
-    /**
1581
-     *        __clone
1582
-     */
1583
-    public function __clone()
1584
-    {
1585
-    }
1586
-
1587
-
1588
-    /**
1589
-     *        __wakeup
1590
-     */
1591
-    public function __wakeup()
1592
-    {
1593
-    }
1594
-
1595
-
1596
-    /**
1597
-     *        __destruct
1598
-     */
1599
-    public function __destruct()
1600
-    {
1601
-    }
1602
-}
1603
-
1604
-/**
1605
- * Class for defining what's in the EE_Config relating to registration settings
1606
- */
1607
-class EE_Core_Config extends EE_Config_Base
1608
-{
1609
-
1610
-    const OPTION_NAME_UXIP = 'ee_ueip_optin';
1611
-
1612
-
1613
-    public $current_blog_id;
1614
-
1615
-    public $ee_ueip_optin;
1616
-
1617
-    public $ee_ueip_has_notified;
1618
-
1619
-    /**
1620
-     * Not to be confused with the 4 critical page variables (See
1621
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1622
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1623
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1624
-     *
1625
-     * @var array
1626
-     */
1627
-    public $post_shortcodes;
1628
-
1629
-    public $module_route_map;
1630
-
1631
-    public $module_forward_map;
1632
-
1633
-    public $module_view_map;
1634
-
1635
-    /**
1636
-     * The next 4 vars are the IDs of critical EE pages.
1637
-     *
1638
-     * @var int
1639
-     */
1640
-    public $reg_page_id;
1641
-
1642
-    public $txn_page_id;
1643
-
1644
-    public $thank_you_page_id;
1645
-
1646
-    public $cancel_page_id;
1647
-
1648
-    /**
1649
-     * The next 4 vars are the URLs of critical EE pages.
1650
-     *
1651
-     * @var int
1652
-     */
1653
-    public $reg_page_url;
1654
-
1655
-    public $txn_page_url;
1656
-
1657
-    public $thank_you_page_url;
1658
-
1659
-    public $cancel_page_url;
1660
-
1661
-    /**
1662
-     * The next vars relate to the custom slugs for EE CPT routes
1663
-     */
1664
-    public $event_cpt_slug;
1665
-
1666
-    /**
1667
-     * This caches the _ee_ueip_option in case this config is reset in the same
1668
-     * request across blog switches in a multisite context.
1669
-     * Avoids extra queries to the db for this option.
1670
-     *
1671
-     * @var bool
1672
-     */
1673
-    public static $ee_ueip_option;
1674
-
1675
-
1676
-    /**
1677
-     *    class constructor
1678
-     *
1679
-     * @access    public
1680
-     */
1681
-    public function __construct()
1682
-    {
1683
-        // set default organization settings
1684
-        $this->current_blog_id = get_current_blog_id();
1685
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1686
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1687
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1688
-        $this->post_shortcodes = array();
1689
-        $this->module_route_map = array();
1690
-        $this->module_forward_map = array();
1691
-        $this->module_view_map = array();
1692
-        // critical EE page IDs
1693
-        $this->reg_page_id = 0;
1694
-        $this->txn_page_id = 0;
1695
-        $this->thank_you_page_id = 0;
1696
-        $this->cancel_page_id = 0;
1697
-        // critical EE page URLs
1698
-        $this->reg_page_url = '';
1699
-        $this->txn_page_url = '';
1700
-        $this->thank_you_page_url = '';
1701
-        $this->cancel_page_url = '';
1702
-        // cpt slugs
1703
-        $this->event_cpt_slug = __('events', 'event_espresso');
1704
-        // ueip constant check
1705
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1706
-            $this->ee_ueip_optin = false;
1707
-            $this->ee_ueip_has_notified = true;
1708
-        }
1709
-    }
1710
-
1711
-
1712
-    /**
1713
-     * @return array
1714
-     */
1715
-    public function get_critical_pages_array()
1716
-    {
1717
-        return array(
1718
-            $this->reg_page_id,
1719
-            $this->txn_page_id,
1720
-            $this->thank_you_page_id,
1721
-            $this->cancel_page_id,
1722
-        );
1723
-    }
1724
-
1725
-
1726
-    /**
1727
-     * @return array
1728
-     */
1729
-    public function get_critical_pages_shortcodes_array()
1730
-    {
1731
-        return array(
1732
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1733
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1734
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1735
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1736
-        );
1737
-    }
1738
-
1739
-
1740
-    /**
1741
-     *  gets/returns URL for EE reg_page
1742
-     *
1743
-     * @access    public
1744
-     * @return    string
1745
-     */
1746
-    public function reg_page_url()
1747
-    {
1748
-        if (! $this->reg_page_url) {
1749
-            $this->reg_page_url = add_query_arg(
1750
-                array('uts' => time()),
1751
-                get_permalink($this->reg_page_id)
1752
-            ) . '#checkout';
1753
-        }
1754
-        return $this->reg_page_url;
1755
-    }
1756
-
1757
-
1758
-    /**
1759
-     *  gets/returns URL for EE txn_page
1760
-     *
1761
-     * @param array $query_args like what gets passed to
1762
-     *                          add_query_arg() as the first argument
1763
-     * @access    public
1764
-     * @return    string
1765
-     */
1766
-    public function txn_page_url($query_args = array())
1767
-    {
1768
-        if (! $this->txn_page_url) {
1769
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1770
-        }
1771
-        if ($query_args) {
1772
-            return add_query_arg($query_args, $this->txn_page_url);
1773
-        } else {
1774
-            return $this->txn_page_url;
1775
-        }
1776
-    }
1777
-
1778
-
1779
-    /**
1780
-     *  gets/returns URL for EE thank_you_page
1781
-     *
1782
-     * @param array $query_args like what gets passed to
1783
-     *                          add_query_arg() as the first argument
1784
-     * @access    public
1785
-     * @return    string
1786
-     */
1787
-    public function thank_you_page_url($query_args = array())
1788
-    {
1789
-        if (! $this->thank_you_page_url) {
1790
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1791
-        }
1792
-        if ($query_args) {
1793
-            return add_query_arg($query_args, $this->thank_you_page_url);
1794
-        } else {
1795
-            return $this->thank_you_page_url;
1796
-        }
1797
-    }
1798
-
1799
-
1800
-    /**
1801
-     *  gets/returns URL for EE cancel_page
1802
-     *
1803
-     * @access    public
1804
-     * @return    string
1805
-     */
1806
-    public function cancel_page_url()
1807
-    {
1808
-        if (! $this->cancel_page_url) {
1809
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1810
-        }
1811
-        return $this->cancel_page_url;
1812
-    }
1813
-
1814
-
1815
-    /**
1816
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1817
-     *
1818
-     * @since 4.7.5
1819
-     */
1820
-    protected function _reset_urls()
1821
-    {
1822
-        $this->reg_page_url = '';
1823
-        $this->txn_page_url = '';
1824
-        $this->cancel_page_url = '';
1825
-        $this->thank_you_page_url = '';
1826
-    }
1827
-
1828
-
1829
-    /**
1830
-     * Used to return what the optin value is set for the EE User Experience Program.
1831
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1832
-     * on the main site only.
1833
-     *
1834
-     * @return bool
1835
-     */
1836
-    protected function _get_main_ee_ueip_optin()
1837
-    {
1838
-        // if this is the main site then we can just bypass our direct query.
1839
-        if (is_main_site()) {
1840
-            return get_option(self::OPTION_NAME_UXIP, false);
1841
-        }
1842
-        // is this already cached for this request?  If so use it.
1843
-        if (EE_Core_Config::$ee_ueip_option !== null) {
1844
-            return EE_Core_Config::$ee_ueip_option;
1845
-        }
1846
-        global $wpdb;
1847
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
1848
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1849
-        $option = self::OPTION_NAME_UXIP;
1850
-        // set correct table for query
1851
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1852
-        // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1853
-        // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1854
-        // re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1855
-        // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1856
-        // for the purpose of caching.
1857
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1858
-        if (false !== $pre) {
1859
-            EE_Core_Config::$ee_ueip_option = $pre;
1860
-            return EE_Core_Config::$ee_ueip_option;
1861
-        }
1862
-        $row = $wpdb->get_row(
1863
-            $wpdb->prepare(
1864
-                "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1865
-                $option
1866
-            )
1867
-        );
1868
-        if (is_object($row)) {
1869
-            $value = $row->option_value;
1870
-        } else { // option does not exist so use default.
1871
-            EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1872
-            return EE_Core_Config::$ee_ueip_option;
1873
-        }
1874
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1875
-        return EE_Core_Config::$ee_ueip_option;
1876
-    }
1877
-
1878
-
1879
-    /**
1880
-     * Utility function for escaping the value of a property and returning.
1881
-     *
1882
-     * @param string $property property name (checks to see if exists).
1883
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1884
-     * @throws \EE_Error
1885
-     */
1886
-    public function get_pretty($property)
1887
-    {
1888
-        if ($property === self::OPTION_NAME_UXIP) {
1889
-            return $this->ee_ueip_optin ? 'yes' : 'no';
1890
-        }
1891
-        return parent::get_pretty($property);
1892
-    }
1893
-
1894
-
1895
-    /**
1896
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1897
-     * on the object.
1898
-     *
1899
-     * @return array
1900
-     */
1901
-    public function __sleep()
1902
-    {
1903
-        // reset all url properties
1904
-        $this->_reset_urls();
1905
-        // return what to save to db
1906
-        return array_keys(get_object_vars($this));
1907
-    }
1908
-}
1909
-
1910
-/**
1911
- * Config class for storing info on the Organization
1912
- */
1913
-class EE_Organization_Config extends EE_Config_Base
1914
-{
1915
-
1916
-    /**
1917
-     * @var string $name
1918
-     * eg EE4.1
1919
-     */
1920
-    public $name;
1921
-
1922
-    /**
1923
-     * @var string $address_1
1924
-     * eg 123 Onna Road
1925
-     */
1926
-    public $address_1 = '';
1927
-
1928
-    /**
1929
-     * @var string $address_2
1930
-     * eg PO Box 123
1931
-     */
1932
-    public $address_2 = '';
1933
-
1934
-    /**
1935
-     * @var string $city
1936
-     * eg Inna City
1937
-     */
1938
-    public $city = '';
1939
-
1940
-    /**
1941
-     * @var int $STA_ID
1942
-     * eg 4
1943
-     */
1944
-    public $STA_ID = 0;
1945
-
1946
-    /**
1947
-     * @var string $CNT_ISO
1948
-     * eg US
1949
-     */
1950
-    public $CNT_ISO = '';
1951
-
1952
-    /**
1953
-     * @var string $zip
1954
-     * eg 12345  or V1A 2B3
1955
-     */
1956
-    public $zip = '';
1957
-
1958
-    /**
1959
-     * @var string $email
1960
-     * eg [email protected]
1961
-     */
1962
-    public $email;
1963
-
1964
-    /**
1965
-     * @var string $phone
1966
-     * eg. 111-111-1111
1967
-     */
1968
-    public $phone = '';
1969
-
1970
-    /**
1971
-     * @var string $vat
1972
-     * VAT/Tax Number
1973
-     */
1974
-    public $vat = '';
1975
-
1976
-    /**
1977
-     * @var string $logo_url
1978
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1979
-     */
1980
-    public $logo_url = '';
1981
-
1982
-    /**
1983
-     * The below are all various properties for holding links to organization social network profiles
1984
-     *
1985
-     * @var string
1986
-     */
1987
-    /**
1988
-     * facebook (facebook.com/profile.name)
1989
-     *
1990
-     * @var string
1991
-     */
1992
-    public $facebook = '';
1993
-
1994
-    /**
1995
-     * twitter (twitter.com/twitter_handle)
1996
-     *
1997
-     * @var string
1998
-     */
1999
-    public $twitter = '';
2000
-
2001
-    /**
2002
-     * linkedin (linkedin.com/in/profile_name)
2003
-     *
2004
-     * @var string
2005
-     */
2006
-    public $linkedin = '';
2007
-
2008
-    /**
2009
-     * pinterest (www.pinterest.com/profile_name)
2010
-     *
2011
-     * @var string
2012
-     */
2013
-    public $pinterest = '';
2014
-
2015
-    /**
2016
-     * google+ (google.com/+profileName)
2017
-     *
2018
-     * @var string
2019
-     */
2020
-    public $google = '';
2021
-
2022
-    /**
2023
-     * instagram (instagram.com/handle)
2024
-     *
2025
-     * @var string
2026
-     */
2027
-    public $instagram = '';
2028
-
2029
-
2030
-    /**
2031
-     *    class constructor
2032
-     *
2033
-     * @access    public
2034
-     */
2035
-    public function __construct()
2036
-    {
2037
-        // set default organization settings
2038
-        // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2039
-        $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2040
-        $this->email = get_bloginfo('admin_email');
2041
-    }
2042
-}
2043
-
2044
-/**
2045
- * Class for defining what's in the EE_Config relating to currency
2046
- */
2047
-class EE_Currency_Config extends EE_Config_Base
2048
-{
2049
-
2050
-    /**
2051
-     * @var string $code
2052
-     * eg 'US'
2053
-     */
2054
-    public $code;
2055
-
2056
-    /**
2057
-     * @var string $name
2058
-     * eg 'Dollar'
2059
-     */
2060
-    public $name;
2061
-
2062
-    /**
2063
-     * plural name
2064
-     *
2065
-     * @var string $plural
2066
-     * eg 'Dollars'
2067
-     */
2068
-    public $plural;
2069
-
2070
-    /**
2071
-     * currency sign
2072
-     *
2073
-     * @var string $sign
2074
-     * eg '$'
2075
-     */
2076
-    public $sign;
2077
-
2078
-    /**
2079
-     * Whether the currency sign should come before the number or not
2080
-     *
2081
-     * @var boolean $sign_b4
2082
-     */
2083
-    public $sign_b4;
2084
-
2085
-    /**
2086
-     * How many digits should come after the decimal place
2087
-     *
2088
-     * @var int $dec_plc
2089
-     */
2090
-    public $dec_plc;
2091
-
2092
-    /**
2093
-     * Symbol to use for decimal mark
2094
-     *
2095
-     * @var string $dec_mrk
2096
-     * eg '.'
2097
-     */
2098
-    public $dec_mrk;
2099
-
2100
-    /**
2101
-     * Symbol to use for thousands
2102
-     *
2103
-     * @var string $thsnds
2104
-     * eg ','
2105
-     */
2106
-    public $thsnds;
2107
-
2108
-
2109
-    /**
2110
-     *    class constructor
2111
-     *
2112
-     * @access    public
2113
-     * @param string $CNT_ISO
2114
-     * @throws \EE_Error
2115
-     */
2116
-    public function __construct($CNT_ISO = '')
2117
-    {
2118
-        /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2119
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2120
-        // get country code from organization settings or use default
2121
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2122
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2123
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2124
-            : '';
2125
-        // but override if requested
2126
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2127
-        // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2128
-        if (! empty($CNT_ISO)
2129
-            && EE_Maintenance_Mode::instance()->models_can_query()
2130
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2131
-        ) {
2132
-            // retrieve the country settings from the db, just in case they have been customized
2133
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2134
-            if ($country instanceof EE_Country) {
2135
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2136
-                $this->name = $country->currency_name_single();    // Dollar
2137
-                $this->plural = $country->currency_name_plural();    // Dollars
2138
-                $this->sign = $country->currency_sign();            // currency sign: $
2139
-                $this->sign_b4 = $country->currency_sign_before(
2140
-                );        // currency sign before or after: $TRUE  or  FALSE$
2141
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2142
-                $this->dec_mrk = $country->currency_decimal_mark(
2143
-                );    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2144
-                $this->thsnds = $country->currency_thousands_separator(
2145
-                );    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2146
-            }
2147
-        }
2148
-        // fallback to hardcoded defaults, in case the above failed
2149
-        if (empty($this->code)) {
2150
-            // set default currency settings
2151
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2152
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2153
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2154
-            $this->sign = '$';    // currency sign: $
2155
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2156
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2157
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2158
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2159
-        }
2160
-    }
2161
-}
2162
-
2163
-/**
2164
- * Class for defining what's in the EE_Config relating to registration settings
2165
- */
2166
-class EE_Registration_Config extends EE_Config_Base
2167
-{
2168
-
2169
-    /**
2170
-     * Default registration status
2171
-     *
2172
-     * @var string $default_STS_ID
2173
-     * eg 'RPP'
2174
-     */
2175
-    public $default_STS_ID;
2176
-
2177
-    /**
2178
-     * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2179
-     * registrations)
2180
-     *
2181
-     * @var int
2182
-     */
2183
-    public $default_maximum_number_of_tickets;
2184
-
2185
-    /**
2186
-     * level of validation to apply to email addresses
2187
-     *
2188
-     * @var string $email_validation_level
2189
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2190
-     */
2191
-    public $email_validation_level;
2192
-
2193
-    /**
2194
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2195
-     *
2196
-     * @var boolean $show_pending_payment_options
2197
-     */
2198
-    public $show_pending_payment_options;
2199
-
2200
-    /**
2201
-     * Whether to skip the registration confirmation page
2202
-     *
2203
-     * @var boolean $skip_reg_confirmation
2204
-     */
2205
-    public $skip_reg_confirmation;
2206
-
2207
-    /**
2208
-     * an array of SPCO reg steps where:
2209
-     *        the keys denotes the reg step order
2210
-     *        each element consists of an array with the following elements:
2211
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2212
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2213
-     *            "slug" => the URL param used to trigger the reg step
2214
-     *
2215
-     * @var array $reg_steps
2216
-     */
2217
-    public $reg_steps;
2218
-
2219
-    /**
2220
-     * Whether registration confirmation should be the last page of SPCO
2221
-     *
2222
-     * @var boolean $reg_confirmation_last
2223
-     */
2224
-    public $reg_confirmation_last;
2225
-
2226
-    /**
2227
-     * Whether or not to enable the EE Bot Trap
2228
-     *
2229
-     * @var boolean $use_bot_trap
2230
-     */
2231
-    public $use_bot_trap;
2232
-
2233
-    /**
2234
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2235
-     *
2236
-     * @var boolean $use_encryption
2237
-     */
2238
-    public $use_encryption;
2239
-
2240
-    /**
2241
-     * Whether or not to use ReCaptcha
2242
-     *
2243
-     * @var boolean $use_captcha
2244
-     */
2245
-    public $use_captcha;
2246
-
2247
-    /**
2248
-     * ReCaptcha Theme
2249
-     *
2250
-     * @var string $recaptcha_theme
2251
-     *    options: 'dark', 'light', 'invisible'
2252
-     */
2253
-    public $recaptcha_theme;
2254
-
2255
-    /**
2256
-     * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2257
-     *
2258
-     * @var string $recaptcha_badge
2259
-     *    options: 'bottomright', 'bottomleft', 'inline'
2260
-     */
2261
-    public $recaptcha_badge;
2262
-
2263
-    /**
2264
-     * ReCaptcha Type
2265
-     *
2266
-     * @var string $recaptcha_type
2267
-     *    options: 'audio', 'image'
2268
-     */
2269
-    public $recaptcha_type;
1508
+{
2270 1509
 
2271
-    /**
2272
-     * ReCaptcha language
2273
-     *
2274
-     * @var string $recaptcha_language
2275
-     * eg 'en'
2276
-     */
2277
-    public $recaptcha_language;
1510
+	/**
1511
+	 * Utility function for escaping the value of a property and returning.
1512
+	 *
1513
+	 * @param string $property property name (checks to see if exists).
1514
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1515
+	 * @throws \EE_Error
1516
+	 */
1517
+	public function get_pretty($property)
1518
+	{
1519
+		if (! property_exists($this, $property)) {
1520
+			throw new EE_Error(
1521
+				sprintf(
1522
+					__(
1523
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1524
+						'event_espresso'
1525
+					),
1526
+					get_class($this),
1527
+					$property
1528
+				)
1529
+			);
1530
+		}
1531
+		// just handling escaping of strings for now.
1532
+		if (is_string($this->{$property})) {
1533
+			return stripslashes($this->{$property});
1534
+		}
1535
+		return $this->{$property};
1536
+	}
1537
+
1538
+
1539
+	public function populate()
1540
+	{
1541
+		// grab defaults via a new instance of this class.
1542
+		$class_name = get_class($this);
1543
+		$defaults = new $class_name;
1544
+		// loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1545
+		// default from our $defaults object.
1546
+		foreach (get_object_vars($defaults) as $property => $value) {
1547
+			if ($this->{$property} === null) {
1548
+				$this->{$property} = $value;
1549
+			}
1550
+		}
1551
+		// cleanup
1552
+		unset($defaults);
1553
+	}
1554
+
1555
+
1556
+	/**
1557
+	 *        __isset
1558
+	 *
1559
+	 * @param $a
1560
+	 * @return bool
1561
+	 */
1562
+	public function __isset($a)
1563
+	{
1564
+		return false;
1565
+	}
1566
+
1567
+
1568
+	/**
1569
+	 *        __unset
1570
+	 *
1571
+	 * @param $a
1572
+	 * @return bool
1573
+	 */
1574
+	public function __unset($a)
1575
+	{
1576
+		return false;
1577
+	}
1578
+
1579
+
1580
+	/**
1581
+	 *        __clone
1582
+	 */
1583
+	public function __clone()
1584
+	{
1585
+	}
1586
+
1587
+
1588
+	/**
1589
+	 *        __wakeup
1590
+	 */
1591
+	public function __wakeup()
1592
+	{
1593
+	}
1594
+
1595
+
1596
+	/**
1597
+	 *        __destruct
1598
+	 */
1599
+	public function __destruct()
1600
+	{
1601
+	}
1602
+}
2278 1603
 
2279
-    /**
2280
-     * ReCaptcha public key
2281
-     *
2282
-     * @var string $recaptcha_publickey
2283
-     */
2284
-    public $recaptcha_publickey;
1604
+/**
1605
+ * Class for defining what's in the EE_Config relating to registration settings
1606
+ */
1607
+class EE_Core_Config extends EE_Config_Base
1608
+{
2285 1609
 
2286
-    /**
2287
-     * ReCaptcha private key
2288
-     *
2289
-     * @var string $recaptcha_privatekey
2290
-     */
2291
-    public $recaptcha_privatekey;
1610
+	const OPTION_NAME_UXIP = 'ee_ueip_optin';
1611
+
1612
+
1613
+	public $current_blog_id;
1614
+
1615
+	public $ee_ueip_optin;
1616
+
1617
+	public $ee_ueip_has_notified;
1618
+
1619
+	/**
1620
+	 * Not to be confused with the 4 critical page variables (See
1621
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1622
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1623
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1624
+	 *
1625
+	 * @var array
1626
+	 */
1627
+	public $post_shortcodes;
1628
+
1629
+	public $module_route_map;
1630
+
1631
+	public $module_forward_map;
1632
+
1633
+	public $module_view_map;
1634
+
1635
+	/**
1636
+	 * The next 4 vars are the IDs of critical EE pages.
1637
+	 *
1638
+	 * @var int
1639
+	 */
1640
+	public $reg_page_id;
1641
+
1642
+	public $txn_page_id;
1643
+
1644
+	public $thank_you_page_id;
1645
+
1646
+	public $cancel_page_id;
1647
+
1648
+	/**
1649
+	 * The next 4 vars are the URLs of critical EE pages.
1650
+	 *
1651
+	 * @var int
1652
+	 */
1653
+	public $reg_page_url;
1654
+
1655
+	public $txn_page_url;
1656
+
1657
+	public $thank_you_page_url;
1658
+
1659
+	public $cancel_page_url;
1660
+
1661
+	/**
1662
+	 * The next vars relate to the custom slugs for EE CPT routes
1663
+	 */
1664
+	public $event_cpt_slug;
1665
+
1666
+	/**
1667
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1668
+	 * request across blog switches in a multisite context.
1669
+	 * Avoids extra queries to the db for this option.
1670
+	 *
1671
+	 * @var bool
1672
+	 */
1673
+	public static $ee_ueip_option;
1674
+
1675
+
1676
+	/**
1677
+	 *    class constructor
1678
+	 *
1679
+	 * @access    public
1680
+	 */
1681
+	public function __construct()
1682
+	{
1683
+		// set default organization settings
1684
+		$this->current_blog_id = get_current_blog_id();
1685
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1686
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1687
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1688
+		$this->post_shortcodes = array();
1689
+		$this->module_route_map = array();
1690
+		$this->module_forward_map = array();
1691
+		$this->module_view_map = array();
1692
+		// critical EE page IDs
1693
+		$this->reg_page_id = 0;
1694
+		$this->txn_page_id = 0;
1695
+		$this->thank_you_page_id = 0;
1696
+		$this->cancel_page_id = 0;
1697
+		// critical EE page URLs
1698
+		$this->reg_page_url = '';
1699
+		$this->txn_page_url = '';
1700
+		$this->thank_you_page_url = '';
1701
+		$this->cancel_page_url = '';
1702
+		// cpt slugs
1703
+		$this->event_cpt_slug = __('events', 'event_espresso');
1704
+		// ueip constant check
1705
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1706
+			$this->ee_ueip_optin = false;
1707
+			$this->ee_ueip_has_notified = true;
1708
+		}
1709
+	}
1710
+
1711
+
1712
+	/**
1713
+	 * @return array
1714
+	 */
1715
+	public function get_critical_pages_array()
1716
+	{
1717
+		return array(
1718
+			$this->reg_page_id,
1719
+			$this->txn_page_id,
1720
+			$this->thank_you_page_id,
1721
+			$this->cancel_page_id,
1722
+		);
1723
+	}
1724
+
1725
+
1726
+	/**
1727
+	 * @return array
1728
+	 */
1729
+	public function get_critical_pages_shortcodes_array()
1730
+	{
1731
+		return array(
1732
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1733
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1734
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1735
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1736
+		);
1737
+	}
1738
+
1739
+
1740
+	/**
1741
+	 *  gets/returns URL for EE reg_page
1742
+	 *
1743
+	 * @access    public
1744
+	 * @return    string
1745
+	 */
1746
+	public function reg_page_url()
1747
+	{
1748
+		if (! $this->reg_page_url) {
1749
+			$this->reg_page_url = add_query_arg(
1750
+				array('uts' => time()),
1751
+				get_permalink($this->reg_page_id)
1752
+			) . '#checkout';
1753
+		}
1754
+		return $this->reg_page_url;
1755
+	}
1756
+
1757
+
1758
+	/**
1759
+	 *  gets/returns URL for EE txn_page
1760
+	 *
1761
+	 * @param array $query_args like what gets passed to
1762
+	 *                          add_query_arg() as the first argument
1763
+	 * @access    public
1764
+	 * @return    string
1765
+	 */
1766
+	public function txn_page_url($query_args = array())
1767
+	{
1768
+		if (! $this->txn_page_url) {
1769
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1770
+		}
1771
+		if ($query_args) {
1772
+			return add_query_arg($query_args, $this->txn_page_url);
1773
+		} else {
1774
+			return $this->txn_page_url;
1775
+		}
1776
+	}
1777
+
1778
+
1779
+	/**
1780
+	 *  gets/returns URL for EE thank_you_page
1781
+	 *
1782
+	 * @param array $query_args like what gets passed to
1783
+	 *                          add_query_arg() as the first argument
1784
+	 * @access    public
1785
+	 * @return    string
1786
+	 */
1787
+	public function thank_you_page_url($query_args = array())
1788
+	{
1789
+		if (! $this->thank_you_page_url) {
1790
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1791
+		}
1792
+		if ($query_args) {
1793
+			return add_query_arg($query_args, $this->thank_you_page_url);
1794
+		} else {
1795
+			return $this->thank_you_page_url;
1796
+		}
1797
+	}
1798
+
1799
+
1800
+	/**
1801
+	 *  gets/returns URL for EE cancel_page
1802
+	 *
1803
+	 * @access    public
1804
+	 * @return    string
1805
+	 */
1806
+	public function cancel_page_url()
1807
+	{
1808
+		if (! $this->cancel_page_url) {
1809
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1810
+		}
1811
+		return $this->cancel_page_url;
1812
+	}
1813
+
1814
+
1815
+	/**
1816
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1817
+	 *
1818
+	 * @since 4.7.5
1819
+	 */
1820
+	protected function _reset_urls()
1821
+	{
1822
+		$this->reg_page_url = '';
1823
+		$this->txn_page_url = '';
1824
+		$this->cancel_page_url = '';
1825
+		$this->thank_you_page_url = '';
1826
+	}
1827
+
1828
+
1829
+	/**
1830
+	 * Used to return what the optin value is set for the EE User Experience Program.
1831
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1832
+	 * on the main site only.
1833
+	 *
1834
+	 * @return bool
1835
+	 */
1836
+	protected function _get_main_ee_ueip_optin()
1837
+	{
1838
+		// if this is the main site then we can just bypass our direct query.
1839
+		if (is_main_site()) {
1840
+			return get_option(self::OPTION_NAME_UXIP, false);
1841
+		}
1842
+		// is this already cached for this request?  If so use it.
1843
+		if (EE_Core_Config::$ee_ueip_option !== null) {
1844
+			return EE_Core_Config::$ee_ueip_option;
1845
+		}
1846
+		global $wpdb;
1847
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
1848
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1849
+		$option = self::OPTION_NAME_UXIP;
1850
+		// set correct table for query
1851
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1852
+		// rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1853
+		// get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1854
+		// re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1855
+		// this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1856
+		// for the purpose of caching.
1857
+		$pre = apply_filters('pre_option_' . $option, false, $option);
1858
+		if (false !== $pre) {
1859
+			EE_Core_Config::$ee_ueip_option = $pre;
1860
+			return EE_Core_Config::$ee_ueip_option;
1861
+		}
1862
+		$row = $wpdb->get_row(
1863
+			$wpdb->prepare(
1864
+				"SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1865
+				$option
1866
+			)
1867
+		);
1868
+		if (is_object($row)) {
1869
+			$value = $row->option_value;
1870
+		} else { // option does not exist so use default.
1871
+			EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1872
+			return EE_Core_Config::$ee_ueip_option;
1873
+		}
1874
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1875
+		return EE_Core_Config::$ee_ueip_option;
1876
+	}
1877
+
1878
+
1879
+	/**
1880
+	 * Utility function for escaping the value of a property and returning.
1881
+	 *
1882
+	 * @param string $property property name (checks to see if exists).
1883
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1884
+	 * @throws \EE_Error
1885
+	 */
1886
+	public function get_pretty($property)
1887
+	{
1888
+		if ($property === self::OPTION_NAME_UXIP) {
1889
+			return $this->ee_ueip_optin ? 'yes' : 'no';
1890
+		}
1891
+		return parent::get_pretty($property);
1892
+	}
1893
+
1894
+
1895
+	/**
1896
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1897
+	 * on the object.
1898
+	 *
1899
+	 * @return array
1900
+	 */
1901
+	public function __sleep()
1902
+	{
1903
+		// reset all url properties
1904
+		$this->_reset_urls();
1905
+		// return what to save to db
1906
+		return array_keys(get_object_vars($this));
1907
+	}
1908
+}
2292 1909
 
2293
-    /**
2294
-     * array of form names protected by ReCaptcha
2295
-     *
2296
-     * @var array $recaptcha_protected_forms
2297
-     */
2298
-    public $recaptcha_protected_forms;
1910
+/**
1911
+ * Config class for storing info on the Organization
1912
+ */
1913
+class EE_Organization_Config extends EE_Config_Base
1914
+{
2299 1915
 
2300
-    /**
2301
-     * ReCaptcha width
2302
-     *
2303
-     * @var int $recaptcha_width
2304
-     * @deprecated
2305
-     */
2306
-    public $recaptcha_width;
1916
+	/**
1917
+	 * @var string $name
1918
+	 * eg EE4.1
1919
+	 */
1920
+	public $name;
1921
+
1922
+	/**
1923
+	 * @var string $address_1
1924
+	 * eg 123 Onna Road
1925
+	 */
1926
+	public $address_1 = '';
1927
+
1928
+	/**
1929
+	 * @var string $address_2
1930
+	 * eg PO Box 123
1931
+	 */
1932
+	public $address_2 = '';
1933
+
1934
+	/**
1935
+	 * @var string $city
1936
+	 * eg Inna City
1937
+	 */
1938
+	public $city = '';
1939
+
1940
+	/**
1941
+	 * @var int $STA_ID
1942
+	 * eg 4
1943
+	 */
1944
+	public $STA_ID = 0;
1945
+
1946
+	/**
1947
+	 * @var string $CNT_ISO
1948
+	 * eg US
1949
+	 */
1950
+	public $CNT_ISO = '';
1951
+
1952
+	/**
1953
+	 * @var string $zip
1954
+	 * eg 12345  or V1A 2B3
1955
+	 */
1956
+	public $zip = '';
1957
+
1958
+	/**
1959
+	 * @var string $email
1960
+	 * eg [email protected]
1961
+	 */
1962
+	public $email;
1963
+
1964
+	/**
1965
+	 * @var string $phone
1966
+	 * eg. 111-111-1111
1967
+	 */
1968
+	public $phone = '';
1969
+
1970
+	/**
1971
+	 * @var string $vat
1972
+	 * VAT/Tax Number
1973
+	 */
1974
+	public $vat = '';
1975
+
1976
+	/**
1977
+	 * @var string $logo_url
1978
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1979
+	 */
1980
+	public $logo_url = '';
1981
+
1982
+	/**
1983
+	 * The below are all various properties for holding links to organization social network profiles
1984
+	 *
1985
+	 * @var string
1986
+	 */
1987
+	/**
1988
+	 * facebook (facebook.com/profile.name)
1989
+	 *
1990
+	 * @var string
1991
+	 */
1992
+	public $facebook = '';
1993
+
1994
+	/**
1995
+	 * twitter (twitter.com/twitter_handle)
1996
+	 *
1997
+	 * @var string
1998
+	 */
1999
+	public $twitter = '';
2000
+
2001
+	/**
2002
+	 * linkedin (linkedin.com/in/profile_name)
2003
+	 *
2004
+	 * @var string
2005
+	 */
2006
+	public $linkedin = '';
2007
+
2008
+	/**
2009
+	 * pinterest (www.pinterest.com/profile_name)
2010
+	 *
2011
+	 * @var string
2012
+	 */
2013
+	public $pinterest = '';
2014
+
2015
+	/**
2016
+	 * google+ (google.com/+profileName)
2017
+	 *
2018
+	 * @var string
2019
+	 */
2020
+	public $google = '';
2021
+
2022
+	/**
2023
+	 * instagram (instagram.com/handle)
2024
+	 *
2025
+	 * @var string
2026
+	 */
2027
+	public $instagram = '';
2028
+
2029
+
2030
+	/**
2031
+	 *    class constructor
2032
+	 *
2033
+	 * @access    public
2034
+	 */
2035
+	public function __construct()
2036
+	{
2037
+		// set default organization settings
2038
+		// decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2039
+		$this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2040
+		$this->email = get_bloginfo('admin_email');
2041
+	}
2042
+}
2307 2043
 
2308
-    /**
2309
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2310
-     *
2311
-     * @var boolean $track_invalid_checkout_access
2312
-     */
2313
-    protected $track_invalid_checkout_access = true;
2044
+/**
2045
+ * Class for defining what's in the EE_Config relating to currency
2046
+ */
2047
+class EE_Currency_Config extends EE_Config_Base
2048
+{
2314 2049
 
2315
-    /**
2316
-     * Whether or not to show the privacy policy consent checkbox
2317
-     *
2318
-     * @var bool
2319
-     */
2320
-    public $consent_checkbox_enabled;
2050
+	/**
2051
+	 * @var string $code
2052
+	 * eg 'US'
2053
+	 */
2054
+	public $code;
2055
+
2056
+	/**
2057
+	 * @var string $name
2058
+	 * eg 'Dollar'
2059
+	 */
2060
+	public $name;
2061
+
2062
+	/**
2063
+	 * plural name
2064
+	 *
2065
+	 * @var string $plural
2066
+	 * eg 'Dollars'
2067
+	 */
2068
+	public $plural;
2069
+
2070
+	/**
2071
+	 * currency sign
2072
+	 *
2073
+	 * @var string $sign
2074
+	 * eg '$'
2075
+	 */
2076
+	public $sign;
2077
+
2078
+	/**
2079
+	 * Whether the currency sign should come before the number or not
2080
+	 *
2081
+	 * @var boolean $sign_b4
2082
+	 */
2083
+	public $sign_b4;
2084
+
2085
+	/**
2086
+	 * How many digits should come after the decimal place
2087
+	 *
2088
+	 * @var int $dec_plc
2089
+	 */
2090
+	public $dec_plc;
2091
+
2092
+	/**
2093
+	 * Symbol to use for decimal mark
2094
+	 *
2095
+	 * @var string $dec_mrk
2096
+	 * eg '.'
2097
+	 */
2098
+	public $dec_mrk;
2099
+
2100
+	/**
2101
+	 * Symbol to use for thousands
2102
+	 *
2103
+	 * @var string $thsnds
2104
+	 * eg ','
2105
+	 */
2106
+	public $thsnds;
2107
+
2108
+
2109
+	/**
2110
+	 *    class constructor
2111
+	 *
2112
+	 * @access    public
2113
+	 * @param string $CNT_ISO
2114
+	 * @throws \EE_Error
2115
+	 */
2116
+	public function __construct($CNT_ISO = '')
2117
+	{
2118
+		/** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2119
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2120
+		// get country code from organization settings or use default
2121
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2122
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2123
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2124
+			: '';
2125
+		// but override if requested
2126
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2127
+		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2128
+		if (! empty($CNT_ISO)
2129
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2130
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2131
+		) {
2132
+			// retrieve the country settings from the db, just in case they have been customized
2133
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2134
+			if ($country instanceof EE_Country) {
2135
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2136
+				$this->name = $country->currency_name_single();    // Dollar
2137
+				$this->plural = $country->currency_name_plural();    // Dollars
2138
+				$this->sign = $country->currency_sign();            // currency sign: $
2139
+				$this->sign_b4 = $country->currency_sign_before(
2140
+				);        // currency sign before or after: $TRUE  or  FALSE$
2141
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2142
+				$this->dec_mrk = $country->currency_decimal_mark(
2143
+				);    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2144
+				$this->thsnds = $country->currency_thousands_separator(
2145
+				);    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2146
+			}
2147
+		}
2148
+		// fallback to hardcoded defaults, in case the above failed
2149
+		if (empty($this->code)) {
2150
+			// set default currency settings
2151
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2152
+			$this->name = __('Dollar', 'event_espresso');    // Dollar
2153
+			$this->plural = __('Dollars', 'event_espresso');    // Dollars
2154
+			$this->sign = '$';    // currency sign: $
2155
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2156
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2157
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2158
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2159
+		}
2160
+	}
2161
+}
2321 2162
 
2322
-    /**
2323
-     * Label text to show on the checkbox
2324
-     *
2325
-     * @var string
2326
-     */
2327
-    public $consent_checkbox_label_text;
2163
+/**
2164
+ * Class for defining what's in the EE_Config relating to registration settings
2165
+ */
2166
+class EE_Registration_Config extends EE_Config_Base
2167
+{
2328 2168
 
2329
-    /*
2169
+	/**
2170
+	 * Default registration status
2171
+	 *
2172
+	 * @var string $default_STS_ID
2173
+	 * eg 'RPP'
2174
+	 */
2175
+	public $default_STS_ID;
2176
+
2177
+	/**
2178
+	 * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2179
+	 * registrations)
2180
+	 *
2181
+	 * @var int
2182
+	 */
2183
+	public $default_maximum_number_of_tickets;
2184
+
2185
+	/**
2186
+	 * level of validation to apply to email addresses
2187
+	 *
2188
+	 * @var string $email_validation_level
2189
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2190
+	 */
2191
+	public $email_validation_level;
2192
+
2193
+	/**
2194
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2195
+	 *
2196
+	 * @var boolean $show_pending_payment_options
2197
+	 */
2198
+	public $show_pending_payment_options;
2199
+
2200
+	/**
2201
+	 * Whether to skip the registration confirmation page
2202
+	 *
2203
+	 * @var boolean $skip_reg_confirmation
2204
+	 */
2205
+	public $skip_reg_confirmation;
2206
+
2207
+	/**
2208
+	 * an array of SPCO reg steps where:
2209
+	 *        the keys denotes the reg step order
2210
+	 *        each element consists of an array with the following elements:
2211
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2212
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2213
+	 *            "slug" => the URL param used to trigger the reg step
2214
+	 *
2215
+	 * @var array $reg_steps
2216
+	 */
2217
+	public $reg_steps;
2218
+
2219
+	/**
2220
+	 * Whether registration confirmation should be the last page of SPCO
2221
+	 *
2222
+	 * @var boolean $reg_confirmation_last
2223
+	 */
2224
+	public $reg_confirmation_last;
2225
+
2226
+	/**
2227
+	 * Whether or not to enable the EE Bot Trap
2228
+	 *
2229
+	 * @var boolean $use_bot_trap
2230
+	 */
2231
+	public $use_bot_trap;
2232
+
2233
+	/**
2234
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2235
+	 *
2236
+	 * @var boolean $use_encryption
2237
+	 */
2238
+	public $use_encryption;
2239
+
2240
+	/**
2241
+	 * Whether or not to use ReCaptcha
2242
+	 *
2243
+	 * @var boolean $use_captcha
2244
+	 */
2245
+	public $use_captcha;
2246
+
2247
+	/**
2248
+	 * ReCaptcha Theme
2249
+	 *
2250
+	 * @var string $recaptcha_theme
2251
+	 *    options: 'dark', 'light', 'invisible'
2252
+	 */
2253
+	public $recaptcha_theme;
2254
+
2255
+	/**
2256
+	 * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2257
+	 *
2258
+	 * @var string $recaptcha_badge
2259
+	 *    options: 'bottomright', 'bottomleft', 'inline'
2260
+	 */
2261
+	public $recaptcha_badge;
2262
+
2263
+	/**
2264
+	 * ReCaptcha Type
2265
+	 *
2266
+	 * @var string $recaptcha_type
2267
+	 *    options: 'audio', 'image'
2268
+	 */
2269
+	public $recaptcha_type;
2270
+
2271
+	/**
2272
+	 * ReCaptcha language
2273
+	 *
2274
+	 * @var string $recaptcha_language
2275
+	 * eg 'en'
2276
+	 */
2277
+	public $recaptcha_language;
2278
+
2279
+	/**
2280
+	 * ReCaptcha public key
2281
+	 *
2282
+	 * @var string $recaptcha_publickey
2283
+	 */
2284
+	public $recaptcha_publickey;
2285
+
2286
+	/**
2287
+	 * ReCaptcha private key
2288
+	 *
2289
+	 * @var string $recaptcha_privatekey
2290
+	 */
2291
+	public $recaptcha_privatekey;
2292
+
2293
+	/**
2294
+	 * array of form names protected by ReCaptcha
2295
+	 *
2296
+	 * @var array $recaptcha_protected_forms
2297
+	 */
2298
+	public $recaptcha_protected_forms;
2299
+
2300
+	/**
2301
+	 * ReCaptcha width
2302
+	 *
2303
+	 * @var int $recaptcha_width
2304
+	 * @deprecated
2305
+	 */
2306
+	public $recaptcha_width;
2307
+
2308
+	/**
2309
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2310
+	 *
2311
+	 * @var boolean $track_invalid_checkout_access
2312
+	 */
2313
+	protected $track_invalid_checkout_access = true;
2314
+
2315
+	/**
2316
+	 * Whether or not to show the privacy policy consent checkbox
2317
+	 *
2318
+	 * @var bool
2319
+	 */
2320
+	public $consent_checkbox_enabled;
2321
+
2322
+	/**
2323
+	 * Label text to show on the checkbox
2324
+	 *
2325
+	 * @var string
2326
+	 */
2327
+	public $consent_checkbox_label_text;
2328
+
2329
+	/*
2330 2330
      * String describing how long to keep payment logs. Passed into DateTime constructor
2331 2331
      * @var string
2332 2332
      */
2333
-    public $gateway_log_lifespan = '1 week';
2334
-
2335
-
2336
-    /**
2337
-     *    class constructor
2338
-     *
2339
-     * @access    public
2340
-     */
2341
-    public function __construct()
2342
-    {
2343
-        // set default registration settings
2344
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2345
-        $this->email_validation_level = 'wp_default';
2346
-        $this->show_pending_payment_options = true;
2347
-        $this->skip_reg_confirmation = true;
2348
-        $this->reg_steps = array();
2349
-        $this->reg_confirmation_last = false;
2350
-        $this->use_bot_trap = true;
2351
-        $this->use_encryption = true;
2352
-        $this->use_captcha = false;
2353
-        $this->recaptcha_theme = 'light';
2354
-        $this->recaptcha_badge = 'bottomleft';
2355
-        $this->recaptcha_type = 'image';
2356
-        $this->recaptcha_language = 'en';
2357
-        $this->recaptcha_publickey = null;
2358
-        $this->recaptcha_privatekey = null;
2359
-        $this->recaptcha_protected_forms = array();
2360
-        $this->recaptcha_width = 500;
2361
-        $this->default_maximum_number_of_tickets = 10;
2362
-        $this->consent_checkbox_enabled = false;
2363
-        $this->consent_checkbox_label_text = '';
2364
-        $this->gateway_log_lifespan = '7 days';
2365
-    }
2366
-
2367
-
2368
-    /**
2369
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2370
-     *
2371
-     * @since 4.8.8.rc.019
2372
-     */
2373
-    public function do_hooks()
2374
-    {
2375
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2376
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2377
-        add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2378
-    }
2379
-
2380
-
2381
-    /**
2382
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2383
-     * EVT_default_registration_status field matches the config setting for default_STS_ID.
2384
-     */
2385
-    public function set_default_reg_status_on_EEM_Event()
2386
-    {
2387
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2388
-    }
2389
-
2390
-
2391
-    /**
2392
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2393
-     * for Events matches the config setting for default_maximum_number_of_tickets
2394
-     */
2395
-    public function set_default_max_ticket_on_EEM_Event()
2396
-    {
2397
-        EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2398
-    }
2399
-
2400
-
2401
-    /**
2402
-     * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2403
-     * constructed because that happens before we can get the privacy policy page's permalink.
2404
-     *
2405
-     * @throws InvalidArgumentException
2406
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2407
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2408
-     */
2409
-    public function setDefaultCheckboxLabelText()
2410
-    {
2411
-        if ($this->getConsentCheckboxLabelText() === null
2412
-            || $this->getConsentCheckboxLabelText() === '') {
2413
-            $opening_a_tag = '';
2414
-            $closing_a_tag = '';
2415
-            if (function_exists('get_privacy_policy_url')) {
2416
-                $privacy_page_url = get_privacy_policy_url();
2417
-                if (! empty($privacy_page_url)) {
2418
-                    $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2419
-                    $closing_a_tag = '</a>';
2420
-                }
2421
-            }
2422
-            $loader = LoaderFactory::getLoader();
2423
-            $org_config = $loader->getShared('EE_Organization_Config');
2424
-            /**
2425
-             * @var $org_config EE_Organization_Config
2426
-             */
2427
-
2428
-            $this->setConsentCheckboxLabelText(
2429
-                sprintf(
2430
-                    esc_html__(
2431
-                        'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2432
-                        'event_espresso'
2433
-                    ),
2434
-                    $org_config->name,
2435
-                    $opening_a_tag,
2436
-                    $closing_a_tag
2437
-                )
2438
-            );
2439
-        }
2440
-    }
2441
-
2442
-
2443
-    /**
2444
-     * @return boolean
2445
-     */
2446
-    public function track_invalid_checkout_access()
2447
-    {
2448
-        return $this->track_invalid_checkout_access;
2449
-    }
2450
-
2451
-
2452
-    /**
2453
-     * @param boolean $track_invalid_checkout_access
2454
-     */
2455
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2456
-    {
2457
-        $this->track_invalid_checkout_access = filter_var(
2458
-            $track_invalid_checkout_access,
2459
-            FILTER_VALIDATE_BOOLEAN
2460
-        );
2461
-    }
2462
-
2463
-
2464
-    /**
2465
-     * Gets the options to make availalbe for the gateway log lifespan
2466
-     * @return array
2467
-     */
2468
-    public function gatewayLogLifespanOptions()
2469
-    {
2470
-        return (array) apply_filters(
2471
-            'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2472
-            array(
2473
-                '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2474
-                '1 day' => esc_html__('1 Day', 'event_espresso'),
2475
-                '7 days' => esc_html__('7 Days', 'event_espresso'),
2476
-                '14 days' => esc_html__('14 Days', 'event_espresso'),
2477
-                '30 days' => esc_html__('30 Days', 'event_espresso')
2478
-            )
2479
-        );
2480
-    }
2481
-
2482
-
2483
-    /**
2484
-     * @return bool
2485
-     */
2486
-    public function isConsentCheckboxEnabled()
2487
-    {
2488
-        return $this->consent_checkbox_enabled;
2489
-    }
2490
-
2491
-
2492
-    /**
2493
-     * @param bool $consent_checkbox_enabled
2494
-     */
2495
-    public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2496
-    {
2497
-        $this->consent_checkbox_enabled = filter_var(
2498
-            $consent_checkbox_enabled,
2499
-            FILTER_VALIDATE_BOOLEAN
2500
-        );
2501
-    }
2502
-
2503
-
2504
-    /**
2505
-     * @return string
2506
-     */
2507
-    public function getConsentCheckboxLabelText()
2508
-    {
2509
-        return $this->consent_checkbox_label_text;
2510
-    }
2511
-
2512
-
2513
-    /**
2514
-     * @param string $consent_checkbox_label_text
2515
-     */
2516
-    public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2517
-    {
2518
-        $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2519
-    }
2333
+	public $gateway_log_lifespan = '1 week';
2334
+
2335
+
2336
+	/**
2337
+	 *    class constructor
2338
+	 *
2339
+	 * @access    public
2340
+	 */
2341
+	public function __construct()
2342
+	{
2343
+		// set default registration settings
2344
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2345
+		$this->email_validation_level = 'wp_default';
2346
+		$this->show_pending_payment_options = true;
2347
+		$this->skip_reg_confirmation = true;
2348
+		$this->reg_steps = array();
2349
+		$this->reg_confirmation_last = false;
2350
+		$this->use_bot_trap = true;
2351
+		$this->use_encryption = true;
2352
+		$this->use_captcha = false;
2353
+		$this->recaptcha_theme = 'light';
2354
+		$this->recaptcha_badge = 'bottomleft';
2355
+		$this->recaptcha_type = 'image';
2356
+		$this->recaptcha_language = 'en';
2357
+		$this->recaptcha_publickey = null;
2358
+		$this->recaptcha_privatekey = null;
2359
+		$this->recaptcha_protected_forms = array();
2360
+		$this->recaptcha_width = 500;
2361
+		$this->default_maximum_number_of_tickets = 10;
2362
+		$this->consent_checkbox_enabled = false;
2363
+		$this->consent_checkbox_label_text = '';
2364
+		$this->gateway_log_lifespan = '7 days';
2365
+	}
2366
+
2367
+
2368
+	/**
2369
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2370
+	 *
2371
+	 * @since 4.8.8.rc.019
2372
+	 */
2373
+	public function do_hooks()
2374
+	{
2375
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2376
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2377
+		add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2378
+	}
2379
+
2380
+
2381
+	/**
2382
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2383
+	 * EVT_default_registration_status field matches the config setting for default_STS_ID.
2384
+	 */
2385
+	public function set_default_reg_status_on_EEM_Event()
2386
+	{
2387
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2388
+	}
2389
+
2390
+
2391
+	/**
2392
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2393
+	 * for Events matches the config setting for default_maximum_number_of_tickets
2394
+	 */
2395
+	public function set_default_max_ticket_on_EEM_Event()
2396
+	{
2397
+		EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2398
+	}
2399
+
2400
+
2401
+	/**
2402
+	 * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2403
+	 * constructed because that happens before we can get the privacy policy page's permalink.
2404
+	 *
2405
+	 * @throws InvalidArgumentException
2406
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2407
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2408
+	 */
2409
+	public function setDefaultCheckboxLabelText()
2410
+	{
2411
+		if ($this->getConsentCheckboxLabelText() === null
2412
+			|| $this->getConsentCheckboxLabelText() === '') {
2413
+			$opening_a_tag = '';
2414
+			$closing_a_tag = '';
2415
+			if (function_exists('get_privacy_policy_url')) {
2416
+				$privacy_page_url = get_privacy_policy_url();
2417
+				if (! empty($privacy_page_url)) {
2418
+					$opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2419
+					$closing_a_tag = '</a>';
2420
+				}
2421
+			}
2422
+			$loader = LoaderFactory::getLoader();
2423
+			$org_config = $loader->getShared('EE_Organization_Config');
2424
+			/**
2425
+			 * @var $org_config EE_Organization_Config
2426
+			 */
2427
+
2428
+			$this->setConsentCheckboxLabelText(
2429
+				sprintf(
2430
+					esc_html__(
2431
+						'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2432
+						'event_espresso'
2433
+					),
2434
+					$org_config->name,
2435
+					$opening_a_tag,
2436
+					$closing_a_tag
2437
+				)
2438
+			);
2439
+		}
2440
+	}
2441
+
2442
+
2443
+	/**
2444
+	 * @return boolean
2445
+	 */
2446
+	public function track_invalid_checkout_access()
2447
+	{
2448
+		return $this->track_invalid_checkout_access;
2449
+	}
2450
+
2451
+
2452
+	/**
2453
+	 * @param boolean $track_invalid_checkout_access
2454
+	 */
2455
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2456
+	{
2457
+		$this->track_invalid_checkout_access = filter_var(
2458
+			$track_invalid_checkout_access,
2459
+			FILTER_VALIDATE_BOOLEAN
2460
+		);
2461
+	}
2462
+
2463
+
2464
+	/**
2465
+	 * Gets the options to make availalbe for the gateway log lifespan
2466
+	 * @return array
2467
+	 */
2468
+	public function gatewayLogLifespanOptions()
2469
+	{
2470
+		return (array) apply_filters(
2471
+			'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2472
+			array(
2473
+				'1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2474
+				'1 day' => esc_html__('1 Day', 'event_espresso'),
2475
+				'7 days' => esc_html__('7 Days', 'event_espresso'),
2476
+				'14 days' => esc_html__('14 Days', 'event_espresso'),
2477
+				'30 days' => esc_html__('30 Days', 'event_espresso')
2478
+			)
2479
+		);
2480
+	}
2481
+
2482
+
2483
+	/**
2484
+	 * @return bool
2485
+	 */
2486
+	public function isConsentCheckboxEnabled()
2487
+	{
2488
+		return $this->consent_checkbox_enabled;
2489
+	}
2490
+
2491
+
2492
+	/**
2493
+	 * @param bool $consent_checkbox_enabled
2494
+	 */
2495
+	public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2496
+	{
2497
+		$this->consent_checkbox_enabled = filter_var(
2498
+			$consent_checkbox_enabled,
2499
+			FILTER_VALIDATE_BOOLEAN
2500
+		);
2501
+	}
2502
+
2503
+
2504
+	/**
2505
+	 * @return string
2506
+	 */
2507
+	public function getConsentCheckboxLabelText()
2508
+	{
2509
+		return $this->consent_checkbox_label_text;
2510
+	}
2511
+
2512
+
2513
+	/**
2514
+	 * @param string $consent_checkbox_label_text
2515
+	 */
2516
+	public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2517
+	{
2518
+		$this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2519
+	}
2520 2520
 }
2521 2521
 
2522 2522
 /**
@@ -2525,234 +2525,234 @@  discard block
 block discarded – undo
2525 2525
 class EE_Admin_Config extends EE_Config_Base
2526 2526
 {
2527 2527
 
2528
-    /**
2529
-     * @var boolean $useAdvancedEditor
2530
-     */
2531
-    private $useAdvancedEditor;
2532
-
2533
-    /**
2534
-     * @var string $advancedEditorView
2535
-     */
2536
-    private $advancedEditorView;
2537
-
2538
-    /**
2539
-     * @var integer $advancedEditorPerPage
2540
-     */
2541
-    private $advancedEditorPerPage;
2542
-
2543
-    /**
2544
-     * @var boolean $use_personnel_manager
2545
-     */
2546
-    public $use_personnel_manager;
2547
-
2548
-    /**
2549
-     * @var boolean $use_dashboard_widget
2550
-     */
2551
-    public $use_dashboard_widget;
2552
-
2553
-    /**
2554
-     * @var int $events_in_dashboard
2555
-     */
2556
-    public $events_in_dashboard;
2557
-
2558
-    /**
2559
-     * @var boolean $use_event_timezones
2560
-     */
2561
-    public $use_event_timezones;
2562
-
2563
-    /**
2564
-     * @var boolean $use_full_logging
2565
-     */
2566
-    public $use_full_logging;
2567
-
2568
-    /**
2569
-     * @var string $log_file_name
2570
-     */
2571
-    public $log_file_name;
2572
-
2573
-    /**
2574
-     * @var string $debug_file_name
2575
-     */
2576
-    public $debug_file_name;
2577
-
2578
-    /**
2579
-     * @var boolean $use_remote_logging
2580
-     */
2581
-    public $use_remote_logging;
2582
-
2583
-    /**
2584
-     * @var string $remote_logging_url
2585
-     */
2586
-    public $remote_logging_url;
2587
-
2588
-    /**
2589
-     * @var boolean $show_reg_footer
2590
-     */
2591
-    public $show_reg_footer;
2592
-
2593
-    /**
2594
-     * @var string $affiliate_id
2595
-     */
2596
-    public $affiliate_id;
2597
-
2598
-    /**
2599
-     * help tours on or off (global setting)
2600
-     *
2601
-     * @var boolean
2602
-     */
2603
-    public $help_tour_activation;
2604
-
2605
-    /**
2606
-     * adds extra layer of encoding to session data to prevent serialization errors
2607
-     * but is incompatible with some server configuration errors
2608
-     * if you get "500 internal server errors" during registration, try turning this on
2609
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2610
-     *
2611
-     * @var boolean $encode_session_data
2612
-     */
2613
-    private $encode_session_data = false;
2614
-
2615
-
2616
-    /**
2617
-     *    class constructor
2618
-     *
2619
-     * @access    public
2620
-     */
2621
-    public function __construct()
2622
-    {
2623
-        // set default general admin settings
2624
-        $this->useAdvancedEditor = false;
2625
-        $this->advancedEditorView = 'grid';
2626
-        $this->advancedEditorPerPage = 6;
2627
-        $this->use_personnel_manager = true;
2628
-        $this->use_dashboard_widget = true;
2629
-        $this->events_in_dashboard = 30;
2630
-        $this->use_event_timezones = false;
2631
-        $this->use_full_logging = false;
2632
-        $this->use_remote_logging = false;
2633
-        $this->remote_logging_url = null;
2634
-        $this->show_reg_footer = apply_filters(
2635
-            'FHEE__EE_Admin_Config__show_reg_footer__default',
2636
-            false
2637
-        );
2638
-        $this->affiliate_id = 'default';
2639
-        $this->help_tour_activation = true;
2640
-        $this->encode_session_data = false;
2641
-    }
2642
-
2643
-
2644
-    /**
2645
-     * @param bool $reset
2646
-     * @return string
2647
-     */
2648
-    public function log_file_name($reset = false)
2649
-    {
2650
-        if (empty($this->log_file_name) || $reset) {
2651
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2652
-            EE_Config::instance()->update_espresso_config(false, false);
2653
-        }
2654
-        return $this->log_file_name;
2655
-    }
2656
-
2657
-
2658
-    /**
2659
-     * @param bool $reset
2660
-     * @return string
2661
-     */
2662
-    public function debug_file_name($reset = false)
2663
-    {
2664
-        if (empty($this->debug_file_name) || $reset) {
2665
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2666
-            EE_Config::instance()->update_espresso_config(false, false);
2667
-        }
2668
-        return $this->debug_file_name;
2669
-    }
2670
-
2671
-
2672
-    /**
2673
-     * @return string
2674
-     */
2675
-    public function affiliate_id()
2676
-    {
2677
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2678
-    }
2679
-
2680
-
2681
-    /**
2682
-     * @return boolean
2683
-     */
2684
-    public function encode_session_data()
2685
-    {
2686
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2687
-    }
2688
-
2689
-
2690
-    /**
2691
-     * @param boolean $encode_session_data
2692
-     */
2693
-    public function set_encode_session_data($encode_session_data)
2694
-    {
2695
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2696
-    }
2697
-
2698
-    /**
2699
-     * @return boolean
2700
-     */
2701
-    public function useAdvancedEditor()
2702
-    {
2703
-        return $this->useAdvancedEditor;
2704
-    }
2705
-
2706
-    /**
2707
-     * @param boolean $use_advanced_editor
2708
-     */
2709
-    public function setUseAdvancedEditor($use_advanced_editor = true)
2710
-    {
2711
-        $this->useAdvancedEditor = filter_var(
2712
-            apply_filters(
2713
-                'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor',
2714
-                $use_advanced_editor
2715
-            ),
2716
-            FILTER_VALIDATE_BOOLEAN
2717
-        );
2718
-    }
2719
-
2720
-
2721
-    /**
2722
-     * @return string
2723
-     */
2724
-    public function advancedEditorView()
2725
-    {
2726
-        return $this->advancedEditorView;
2727
-    }
2728
-
2729
-
2730
-    /**
2731
-     * @param string $view
2732
-     */
2733
-    public function setAdvancedEditorView($view)
2734
-    {
2735
-        $this->advancedEditorView = $view === 'list' ? 'list' : 'grid';
2736
-    }
2737
-
2738
-
2739
-    /**
2740
-     * @return int
2741
-     */
2742
-    public function advancedEditorPerPage()
2743
-    {
2744
-        return $this->advancedEditorPerPage;
2745
-    }
2746
-
2747
-
2748
-    /**
2749
-     * @param int $perPage
2750
-     */
2751
-    public function setAdvancedEditorPerPage($perPage)
2752
-    {
2753
-        $perPage = absint($perPage);
2754
-        $this->advancedEditorPerPage = in_array($perPage, [2, 6, 12, 24, 48], true) ? $perPage : 6;
2755
-    }
2528
+	/**
2529
+	 * @var boolean $useAdvancedEditor
2530
+	 */
2531
+	private $useAdvancedEditor;
2532
+
2533
+	/**
2534
+	 * @var string $advancedEditorView
2535
+	 */
2536
+	private $advancedEditorView;
2537
+
2538
+	/**
2539
+	 * @var integer $advancedEditorPerPage
2540
+	 */
2541
+	private $advancedEditorPerPage;
2542
+
2543
+	/**
2544
+	 * @var boolean $use_personnel_manager
2545
+	 */
2546
+	public $use_personnel_manager;
2547
+
2548
+	/**
2549
+	 * @var boolean $use_dashboard_widget
2550
+	 */
2551
+	public $use_dashboard_widget;
2552
+
2553
+	/**
2554
+	 * @var int $events_in_dashboard
2555
+	 */
2556
+	public $events_in_dashboard;
2557
+
2558
+	/**
2559
+	 * @var boolean $use_event_timezones
2560
+	 */
2561
+	public $use_event_timezones;
2562
+
2563
+	/**
2564
+	 * @var boolean $use_full_logging
2565
+	 */
2566
+	public $use_full_logging;
2567
+
2568
+	/**
2569
+	 * @var string $log_file_name
2570
+	 */
2571
+	public $log_file_name;
2572
+
2573
+	/**
2574
+	 * @var string $debug_file_name
2575
+	 */
2576
+	public $debug_file_name;
2577
+
2578
+	/**
2579
+	 * @var boolean $use_remote_logging
2580
+	 */
2581
+	public $use_remote_logging;
2582
+
2583
+	/**
2584
+	 * @var string $remote_logging_url
2585
+	 */
2586
+	public $remote_logging_url;
2587
+
2588
+	/**
2589
+	 * @var boolean $show_reg_footer
2590
+	 */
2591
+	public $show_reg_footer;
2592
+
2593
+	/**
2594
+	 * @var string $affiliate_id
2595
+	 */
2596
+	public $affiliate_id;
2597
+
2598
+	/**
2599
+	 * help tours on or off (global setting)
2600
+	 *
2601
+	 * @var boolean
2602
+	 */
2603
+	public $help_tour_activation;
2604
+
2605
+	/**
2606
+	 * adds extra layer of encoding to session data to prevent serialization errors
2607
+	 * but is incompatible with some server configuration errors
2608
+	 * if you get "500 internal server errors" during registration, try turning this on
2609
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2610
+	 *
2611
+	 * @var boolean $encode_session_data
2612
+	 */
2613
+	private $encode_session_data = false;
2614
+
2615
+
2616
+	/**
2617
+	 *    class constructor
2618
+	 *
2619
+	 * @access    public
2620
+	 */
2621
+	public function __construct()
2622
+	{
2623
+		// set default general admin settings
2624
+		$this->useAdvancedEditor = false;
2625
+		$this->advancedEditorView = 'grid';
2626
+		$this->advancedEditorPerPage = 6;
2627
+		$this->use_personnel_manager = true;
2628
+		$this->use_dashboard_widget = true;
2629
+		$this->events_in_dashboard = 30;
2630
+		$this->use_event_timezones = false;
2631
+		$this->use_full_logging = false;
2632
+		$this->use_remote_logging = false;
2633
+		$this->remote_logging_url = null;
2634
+		$this->show_reg_footer = apply_filters(
2635
+			'FHEE__EE_Admin_Config__show_reg_footer__default',
2636
+			false
2637
+		);
2638
+		$this->affiliate_id = 'default';
2639
+		$this->help_tour_activation = true;
2640
+		$this->encode_session_data = false;
2641
+	}
2642
+
2643
+
2644
+	/**
2645
+	 * @param bool $reset
2646
+	 * @return string
2647
+	 */
2648
+	public function log_file_name($reset = false)
2649
+	{
2650
+		if (empty($this->log_file_name) || $reset) {
2651
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2652
+			EE_Config::instance()->update_espresso_config(false, false);
2653
+		}
2654
+		return $this->log_file_name;
2655
+	}
2656
+
2657
+
2658
+	/**
2659
+	 * @param bool $reset
2660
+	 * @return string
2661
+	 */
2662
+	public function debug_file_name($reset = false)
2663
+	{
2664
+		if (empty($this->debug_file_name) || $reset) {
2665
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2666
+			EE_Config::instance()->update_espresso_config(false, false);
2667
+		}
2668
+		return $this->debug_file_name;
2669
+	}
2670
+
2671
+
2672
+	/**
2673
+	 * @return string
2674
+	 */
2675
+	public function affiliate_id()
2676
+	{
2677
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2678
+	}
2679
+
2680
+
2681
+	/**
2682
+	 * @return boolean
2683
+	 */
2684
+	public function encode_session_data()
2685
+	{
2686
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2687
+	}
2688
+
2689
+
2690
+	/**
2691
+	 * @param boolean $encode_session_data
2692
+	 */
2693
+	public function set_encode_session_data($encode_session_data)
2694
+	{
2695
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2696
+	}
2697
+
2698
+	/**
2699
+	 * @return boolean
2700
+	 */
2701
+	public function useAdvancedEditor()
2702
+	{
2703
+		return $this->useAdvancedEditor;
2704
+	}
2705
+
2706
+	/**
2707
+	 * @param boolean $use_advanced_editor
2708
+	 */
2709
+	public function setUseAdvancedEditor($use_advanced_editor = true)
2710
+	{
2711
+		$this->useAdvancedEditor = filter_var(
2712
+			apply_filters(
2713
+				'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor',
2714
+				$use_advanced_editor
2715
+			),
2716
+			FILTER_VALIDATE_BOOLEAN
2717
+		);
2718
+	}
2719
+
2720
+
2721
+	/**
2722
+	 * @return string
2723
+	 */
2724
+	public function advancedEditorView()
2725
+	{
2726
+		return $this->advancedEditorView;
2727
+	}
2728
+
2729
+
2730
+	/**
2731
+	 * @param string $view
2732
+	 */
2733
+	public function setAdvancedEditorView($view)
2734
+	{
2735
+		$this->advancedEditorView = $view === 'list' ? 'list' : 'grid';
2736
+	}
2737
+
2738
+
2739
+	/**
2740
+	 * @return int
2741
+	 */
2742
+	public function advancedEditorPerPage()
2743
+	{
2744
+		return $this->advancedEditorPerPage;
2745
+	}
2746
+
2747
+
2748
+	/**
2749
+	 * @param int $perPage
2750
+	 */
2751
+	public function setAdvancedEditorPerPage($perPage)
2752
+	{
2753
+		$perPage = absint($perPage);
2754
+		$this->advancedEditorPerPage = in_array($perPage, [2, 6, 12, 24, 48], true) ? $perPage : 6;
2755
+	}
2756 2756
 }
2757 2757
 
2758 2758
 /**
@@ -2761,70 +2761,70 @@  discard block
 block discarded – undo
2761 2761
 class EE_Template_Config extends EE_Config_Base
2762 2762
 {
2763 2763
 
2764
-    /**
2765
-     * @var boolean $enable_default_style
2766
-     */
2767
-    public $enable_default_style;
2768
-
2769
-    /**
2770
-     * @var string $custom_style_sheet
2771
-     */
2772
-    public $custom_style_sheet;
2773
-
2774
-    /**
2775
-     * @var boolean $display_address_in_regform
2776
-     */
2777
-    public $display_address_in_regform;
2778
-
2779
-    /**
2780
-     * @var int $display_description_on_multi_reg_page
2781
-     */
2782
-    public $display_description_on_multi_reg_page;
2783
-
2784
-    /**
2785
-     * @var boolean $use_custom_templates
2786
-     */
2787
-    public $use_custom_templates;
2788
-
2789
-    /**
2790
-     * @var string $current_espresso_theme
2791
-     */
2792
-    public $current_espresso_theme;
2793
-
2794
-    /**
2795
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2796
-     */
2797
-    public $EED_Ticket_Selector;
2798
-
2799
-    /**
2800
-     * @var EE_Event_Single_Config $EED_Event_Single
2801
-     */
2802
-    public $EED_Event_Single;
2803
-
2804
-    /**
2805
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2806
-     */
2807
-    public $EED_Events_Archive;
2808
-
2809
-
2810
-    /**
2811
-     *    class constructor
2812
-     *
2813
-     * @access    public
2814
-     */
2815
-    public function __construct()
2816
-    {
2817
-        // set default template settings
2818
-        $this->enable_default_style = true;
2819
-        $this->custom_style_sheet = null;
2820
-        $this->display_address_in_regform = true;
2821
-        $this->display_description_on_multi_reg_page = false;
2822
-        $this->use_custom_templates = false;
2823
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2824
-        $this->EED_Event_Single = null;
2825
-        $this->EED_Events_Archive = null;
2826
-        $this->EED_Ticket_Selector = null;
2827
-    }
2764
+	/**
2765
+	 * @var boolean $enable_default_style
2766
+	 */
2767
+	public $enable_default_style;
2768
+
2769
+	/**
2770
+	 * @var string $custom_style_sheet
2771
+	 */
2772
+	public $custom_style_sheet;
2773
+
2774
+	/**
2775
+	 * @var boolean $display_address_in_regform
2776
+	 */
2777
+	public $display_address_in_regform;
2778
+
2779
+	/**
2780
+	 * @var int $display_description_on_multi_reg_page
2781
+	 */
2782
+	public $display_description_on_multi_reg_page;
2783
+
2784
+	/**
2785
+	 * @var boolean $use_custom_templates
2786
+	 */
2787
+	public $use_custom_templates;
2788
+
2789
+	/**
2790
+	 * @var string $current_espresso_theme
2791
+	 */
2792
+	public $current_espresso_theme;
2793
+
2794
+	/**
2795
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2796
+	 */
2797
+	public $EED_Ticket_Selector;
2798
+
2799
+	/**
2800
+	 * @var EE_Event_Single_Config $EED_Event_Single
2801
+	 */
2802
+	public $EED_Event_Single;
2803
+
2804
+	/**
2805
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2806
+	 */
2807
+	public $EED_Events_Archive;
2808
+
2809
+
2810
+	/**
2811
+	 *    class constructor
2812
+	 *
2813
+	 * @access    public
2814
+	 */
2815
+	public function __construct()
2816
+	{
2817
+		// set default template settings
2818
+		$this->enable_default_style = true;
2819
+		$this->custom_style_sheet = null;
2820
+		$this->display_address_in_regform = true;
2821
+		$this->display_description_on_multi_reg_page = false;
2822
+		$this->use_custom_templates = false;
2823
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2824
+		$this->EED_Event_Single = null;
2825
+		$this->EED_Events_Archive = null;
2826
+		$this->EED_Ticket_Selector = null;
2827
+	}
2828 2828
 }
2829 2829
 
2830 2830
 /**
@@ -2833,114 +2833,114 @@  discard block
 block discarded – undo
2833 2833
 class EE_Map_Config extends EE_Config_Base
2834 2834
 {
2835 2835
 
2836
-    /**
2837
-     * @var boolean $use_google_maps
2838
-     */
2839
-    public $use_google_maps;
2840
-
2841
-    /**
2842
-     * @var string $api_key
2843
-     */
2844
-    public $google_map_api_key;
2845
-
2846
-    /**
2847
-     * @var int $event_details_map_width
2848
-     */
2849
-    public $event_details_map_width;
2850
-
2851
-    /**
2852
-     * @var int $event_details_map_height
2853
-     */
2854
-    public $event_details_map_height;
2855
-
2856
-    /**
2857
-     * @var int $event_details_map_zoom
2858
-     */
2859
-    public $event_details_map_zoom;
2860
-
2861
-    /**
2862
-     * @var boolean $event_details_display_nav
2863
-     */
2864
-    public $event_details_display_nav;
2865
-
2866
-    /**
2867
-     * @var boolean $event_details_nav_size
2868
-     */
2869
-    public $event_details_nav_size;
2870
-
2871
-    /**
2872
-     * @var string $event_details_control_type
2873
-     */
2874
-    public $event_details_control_type;
2875
-
2876
-    /**
2877
-     * @var string $event_details_map_align
2878
-     */
2879
-    public $event_details_map_align;
2880
-
2881
-    /**
2882
-     * @var int $event_list_map_width
2883
-     */
2884
-    public $event_list_map_width;
2885
-
2886
-    /**
2887
-     * @var int $event_list_map_height
2888
-     */
2889
-    public $event_list_map_height;
2890
-
2891
-    /**
2892
-     * @var int $event_list_map_zoom
2893
-     */
2894
-    public $event_list_map_zoom;
2895
-
2896
-    /**
2897
-     * @var boolean $event_list_display_nav
2898
-     */
2899
-    public $event_list_display_nav;
2900
-
2901
-    /**
2902
-     * @var boolean $event_list_nav_size
2903
-     */
2904
-    public $event_list_nav_size;
2905
-
2906
-    /**
2907
-     * @var string $event_list_control_type
2908
-     */
2909
-    public $event_list_control_type;
2910
-
2911
-    /**
2912
-     * @var string $event_list_map_align
2913
-     */
2914
-    public $event_list_map_align;
2915
-
2916
-
2917
-    /**
2918
-     *    class constructor
2919
-     *
2920
-     * @access    public
2921
-     */
2922
-    public function __construct()
2923
-    {
2924
-        // set default map settings
2925
-        $this->use_google_maps = true;
2926
-        $this->google_map_api_key = '';
2927
-        // for event details pages (reg page)
2928
-        $this->event_details_map_width = 585;            // ee_map_width_single
2929
-        $this->event_details_map_height = 362;            // ee_map_height_single
2930
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2931
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2932
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2933
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2934
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2935
-        // for event list pages
2936
-        $this->event_list_map_width = 300;            // ee_map_width
2937
-        $this->event_list_map_height = 185;        // ee_map_height
2938
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2939
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2940
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2941
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2942
-        $this->event_list_map_align = 'center';            // ee_map_align
2943
-    }
2836
+	/**
2837
+	 * @var boolean $use_google_maps
2838
+	 */
2839
+	public $use_google_maps;
2840
+
2841
+	/**
2842
+	 * @var string $api_key
2843
+	 */
2844
+	public $google_map_api_key;
2845
+
2846
+	/**
2847
+	 * @var int $event_details_map_width
2848
+	 */
2849
+	public $event_details_map_width;
2850
+
2851
+	/**
2852
+	 * @var int $event_details_map_height
2853
+	 */
2854
+	public $event_details_map_height;
2855
+
2856
+	/**
2857
+	 * @var int $event_details_map_zoom
2858
+	 */
2859
+	public $event_details_map_zoom;
2860
+
2861
+	/**
2862
+	 * @var boolean $event_details_display_nav
2863
+	 */
2864
+	public $event_details_display_nav;
2865
+
2866
+	/**
2867
+	 * @var boolean $event_details_nav_size
2868
+	 */
2869
+	public $event_details_nav_size;
2870
+
2871
+	/**
2872
+	 * @var string $event_details_control_type
2873
+	 */
2874
+	public $event_details_control_type;
2875
+
2876
+	/**
2877
+	 * @var string $event_details_map_align
2878
+	 */
2879
+	public $event_details_map_align;
2880
+
2881
+	/**
2882
+	 * @var int $event_list_map_width
2883
+	 */
2884
+	public $event_list_map_width;
2885
+
2886
+	/**
2887
+	 * @var int $event_list_map_height
2888
+	 */
2889
+	public $event_list_map_height;
2890
+
2891
+	/**
2892
+	 * @var int $event_list_map_zoom
2893
+	 */
2894
+	public $event_list_map_zoom;
2895
+
2896
+	/**
2897
+	 * @var boolean $event_list_display_nav
2898
+	 */
2899
+	public $event_list_display_nav;
2900
+
2901
+	/**
2902
+	 * @var boolean $event_list_nav_size
2903
+	 */
2904
+	public $event_list_nav_size;
2905
+
2906
+	/**
2907
+	 * @var string $event_list_control_type
2908
+	 */
2909
+	public $event_list_control_type;
2910
+
2911
+	/**
2912
+	 * @var string $event_list_map_align
2913
+	 */
2914
+	public $event_list_map_align;
2915
+
2916
+
2917
+	/**
2918
+	 *    class constructor
2919
+	 *
2920
+	 * @access    public
2921
+	 */
2922
+	public function __construct()
2923
+	{
2924
+		// set default map settings
2925
+		$this->use_google_maps = true;
2926
+		$this->google_map_api_key = '';
2927
+		// for event details pages (reg page)
2928
+		$this->event_details_map_width = 585;            // ee_map_width_single
2929
+		$this->event_details_map_height = 362;            // ee_map_height_single
2930
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2931
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2932
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2933
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2934
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2935
+		// for event list pages
2936
+		$this->event_list_map_width = 300;            // ee_map_width
2937
+		$this->event_list_map_height = 185;        // ee_map_height
2938
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2939
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2940
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2941
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2942
+		$this->event_list_map_align = 'center';            // ee_map_align
2943
+	}
2944 2944
 }
2945 2945
 
2946 2946
 /**
@@ -2949,46 +2949,46 @@  discard block
 block discarded – undo
2949 2949
 class EE_Events_Archive_Config extends EE_Config_Base
2950 2950
 {
2951 2951
 
2952
-    public $display_status_banner;
2952
+	public $display_status_banner;
2953 2953
 
2954
-    public $display_description;
2954
+	public $display_description;
2955 2955
 
2956
-    public $display_ticket_selector;
2956
+	public $display_ticket_selector;
2957 2957
 
2958
-    public $display_datetimes;
2958
+	public $display_datetimes;
2959 2959
 
2960
-    public $display_venue;
2960
+	public $display_venue;
2961 2961
 
2962
-    public $display_expired_events;
2962
+	public $display_expired_events;
2963 2963
 
2964
-    public $use_sortable_display_order;
2964
+	public $use_sortable_display_order;
2965 2965
 
2966
-    public $display_order_tickets;
2966
+	public $display_order_tickets;
2967 2967
 
2968
-    public $display_order_datetimes;
2968
+	public $display_order_datetimes;
2969 2969
 
2970
-    public $display_order_event;
2970
+	public $display_order_event;
2971 2971
 
2972
-    public $display_order_venue;
2972
+	public $display_order_venue;
2973 2973
 
2974 2974
 
2975
-    /**
2976
-     *    class constructor
2977
-     */
2978
-    public function __construct()
2979
-    {
2980
-        $this->display_status_banner = 0;
2981
-        $this->display_description = 1;
2982
-        $this->display_ticket_selector = 0;
2983
-        $this->display_datetimes = 1;
2984
-        $this->display_venue = 0;
2985
-        $this->display_expired_events = 0;
2986
-        $this->use_sortable_display_order = false;
2987
-        $this->display_order_tickets = 100;
2988
-        $this->display_order_datetimes = 110;
2989
-        $this->display_order_event = 120;
2990
-        $this->display_order_venue = 130;
2991
-    }
2975
+	/**
2976
+	 *    class constructor
2977
+	 */
2978
+	public function __construct()
2979
+	{
2980
+		$this->display_status_banner = 0;
2981
+		$this->display_description = 1;
2982
+		$this->display_ticket_selector = 0;
2983
+		$this->display_datetimes = 1;
2984
+		$this->display_venue = 0;
2985
+		$this->display_expired_events = 0;
2986
+		$this->use_sortable_display_order = false;
2987
+		$this->display_order_tickets = 100;
2988
+		$this->display_order_datetimes = 110;
2989
+		$this->display_order_event = 120;
2990
+		$this->display_order_venue = 130;
2991
+	}
2992 2992
 }
2993 2993
 
2994 2994
 /**
@@ -2997,34 +2997,34 @@  discard block
 block discarded – undo
2997 2997
 class EE_Event_Single_Config extends EE_Config_Base
2998 2998
 {
2999 2999
 
3000
-    public $display_status_banner_single;
3000
+	public $display_status_banner_single;
3001 3001
 
3002
-    public $display_venue;
3002
+	public $display_venue;
3003 3003
 
3004
-    public $use_sortable_display_order;
3004
+	public $use_sortable_display_order;
3005 3005
 
3006
-    public $display_order_tickets;
3006
+	public $display_order_tickets;
3007 3007
 
3008
-    public $display_order_datetimes;
3008
+	public $display_order_datetimes;
3009 3009
 
3010
-    public $display_order_event;
3010
+	public $display_order_event;
3011 3011
 
3012
-    public $display_order_venue;
3012
+	public $display_order_venue;
3013 3013
 
3014 3014
 
3015
-    /**
3016
-     *    class constructor
3017
-     */
3018
-    public function __construct()
3019
-    {
3020
-        $this->display_status_banner_single = 0;
3021
-        $this->display_venue = 1;
3022
-        $this->use_sortable_display_order = false;
3023
-        $this->display_order_tickets = 100;
3024
-        $this->display_order_datetimes = 110;
3025
-        $this->display_order_event = 120;
3026
-        $this->display_order_venue = 130;
3027
-    }
3015
+	/**
3016
+	 *    class constructor
3017
+	 */
3018
+	public function __construct()
3019
+	{
3020
+		$this->display_status_banner_single = 0;
3021
+		$this->display_venue = 1;
3022
+		$this->use_sortable_display_order = false;
3023
+		$this->display_order_tickets = 100;
3024
+		$this->display_order_datetimes = 110;
3025
+		$this->display_order_event = 120;
3026
+		$this->display_order_venue = 130;
3027
+	}
3028 3028
 }
3029 3029
 
3030 3030
 /**
@@ -3033,172 +3033,172 @@  discard block
 block discarded – undo
3033 3033
 class EE_Ticket_Selector_Config extends EE_Config_Base
3034 3034
 {
3035 3035
 
3036
-    /**
3037
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
3038
-     */
3039
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
3040
-
3041
-    /**
3042
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
3043
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
3044
-     */
3045
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
3046
-
3047
-    /**
3048
-     * @var boolean $show_ticket_sale_columns
3049
-     */
3050
-    public $show_ticket_sale_columns;
3051
-
3052
-    /**
3053
-     * @var boolean $show_ticket_details
3054
-     */
3055
-    public $show_ticket_details;
3056
-
3057
-    /**
3058
-     * @var boolean $show_expired_tickets
3059
-     */
3060
-    public $show_expired_tickets;
3061
-
3062
-    /**
3063
-     * whether or not to display a dropdown box populated with event datetimes
3064
-     * that toggles which tickets are displayed for a ticket selector.
3065
-     * uses one of the *_DATETIME_SELECTOR constants defined above
3066
-     *
3067
-     * @var string $show_datetime_selector
3068
-     */
3069
-    private $show_datetime_selector = 'no_datetime_selector';
3070
-
3071
-    /**
3072
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
3073
-     *
3074
-     * @var int $datetime_selector_threshold
3075
-     */
3076
-    private $datetime_selector_threshold = 3;
3077
-
3078
-    /**
3079
-     * determines the maximum number of "checked" dates in the date and time filter
3080
-     *
3081
-     * @var int $datetime_selector_checked
3082
-     */
3083
-    private $datetime_selector_max_checked = 10;
3084
-
3085
-
3086
-    /**
3087
-     *    class constructor
3088
-     */
3089
-    public function __construct()
3090
-    {
3091
-        $this->show_ticket_sale_columns = true;
3092
-        $this->show_ticket_details = true;
3093
-        $this->show_expired_tickets = true;
3094
-        $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3095
-        $this->datetime_selector_threshold = 3;
3096
-        $this->datetime_selector_max_checked = 10;
3097
-    }
3098
-
3099
-
3100
-    /**
3101
-     * returns true if a datetime selector should be displayed
3102
-     *
3103
-     * @param array $datetimes
3104
-     * @return bool
3105
-     */
3106
-    public function showDatetimeSelector(array $datetimes)
3107
-    {
3108
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
3109
-        return ! (
3110
-            $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3111
-            || (
3112
-                $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3113
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
3114
-            )
3115
-        );
3116
-    }
3117
-
3118
-
3119
-    /**
3120
-     * @return string
3121
-     */
3122
-    public function getShowDatetimeSelector()
3123
-    {
3124
-        return $this->show_datetime_selector;
3125
-    }
3126
-
3127
-
3128
-    /**
3129
-     * @param bool $keys_only
3130
-     * @return array
3131
-     */
3132
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3133
-    {
3134
-        return $keys_only
3135
-            ? array(
3136
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3137
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3138
-            )
3139
-            : array(
3140
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3141
-                    'Do not show date & time filter',
3142
-                    'event_espresso'
3143
-                ),
3144
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3145
-                    'Maybe show date & time filter',
3146
-                    'event_espresso'
3147
-                ),
3148
-            );
3149
-    }
3150
-
3151
-
3152
-    /**
3153
-     * @param string $show_datetime_selector
3154
-     */
3155
-    public function setShowDatetimeSelector($show_datetime_selector)
3156
-    {
3157
-        $this->show_datetime_selector = in_array(
3158
-            $show_datetime_selector,
3159
-            $this->getShowDatetimeSelectorOptions(),
3160
-            true
3161
-        )
3162
-            ? $show_datetime_selector
3163
-            : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3164
-    }
3165
-
3166
-
3167
-    /**
3168
-     * @return int
3169
-     */
3170
-    public function getDatetimeSelectorThreshold()
3171
-    {
3172
-        return $this->datetime_selector_threshold;
3173
-    }
3174
-
3175
-
3176
-    /**
3177
-     * @param int $datetime_selector_threshold
3178
-     */
3179
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3180
-    {
3181
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3182
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3183
-    }
3184
-
3185
-
3186
-    /**
3187
-     * @return int
3188
-     */
3189
-    public function getDatetimeSelectorMaxChecked()
3190
-    {
3191
-        return $this->datetime_selector_max_checked;
3192
-    }
3193
-
3194
-
3195
-    /**
3196
-     * @param int $datetime_selector_max_checked
3197
-     */
3198
-    public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3199
-    {
3200
-        $this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3201
-    }
3036
+	/**
3037
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
3038
+	 */
3039
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
3040
+
3041
+	/**
3042
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
3043
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
3044
+	 */
3045
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
3046
+
3047
+	/**
3048
+	 * @var boolean $show_ticket_sale_columns
3049
+	 */
3050
+	public $show_ticket_sale_columns;
3051
+
3052
+	/**
3053
+	 * @var boolean $show_ticket_details
3054
+	 */
3055
+	public $show_ticket_details;
3056
+
3057
+	/**
3058
+	 * @var boolean $show_expired_tickets
3059
+	 */
3060
+	public $show_expired_tickets;
3061
+
3062
+	/**
3063
+	 * whether or not to display a dropdown box populated with event datetimes
3064
+	 * that toggles which tickets are displayed for a ticket selector.
3065
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
3066
+	 *
3067
+	 * @var string $show_datetime_selector
3068
+	 */
3069
+	private $show_datetime_selector = 'no_datetime_selector';
3070
+
3071
+	/**
3072
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
3073
+	 *
3074
+	 * @var int $datetime_selector_threshold
3075
+	 */
3076
+	private $datetime_selector_threshold = 3;
3077
+
3078
+	/**
3079
+	 * determines the maximum number of "checked" dates in the date and time filter
3080
+	 *
3081
+	 * @var int $datetime_selector_checked
3082
+	 */
3083
+	private $datetime_selector_max_checked = 10;
3084
+
3085
+
3086
+	/**
3087
+	 *    class constructor
3088
+	 */
3089
+	public function __construct()
3090
+	{
3091
+		$this->show_ticket_sale_columns = true;
3092
+		$this->show_ticket_details = true;
3093
+		$this->show_expired_tickets = true;
3094
+		$this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3095
+		$this->datetime_selector_threshold = 3;
3096
+		$this->datetime_selector_max_checked = 10;
3097
+	}
3098
+
3099
+
3100
+	/**
3101
+	 * returns true if a datetime selector should be displayed
3102
+	 *
3103
+	 * @param array $datetimes
3104
+	 * @return bool
3105
+	 */
3106
+	public function showDatetimeSelector(array $datetimes)
3107
+	{
3108
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
3109
+		return ! (
3110
+			$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3111
+			|| (
3112
+				$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3113
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
3114
+			)
3115
+		);
3116
+	}
3117
+
3118
+
3119
+	/**
3120
+	 * @return string
3121
+	 */
3122
+	public function getShowDatetimeSelector()
3123
+	{
3124
+		return $this->show_datetime_selector;
3125
+	}
3126
+
3127
+
3128
+	/**
3129
+	 * @param bool $keys_only
3130
+	 * @return array
3131
+	 */
3132
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3133
+	{
3134
+		return $keys_only
3135
+			? array(
3136
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3137
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3138
+			)
3139
+			: array(
3140
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3141
+					'Do not show date & time filter',
3142
+					'event_espresso'
3143
+				),
3144
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3145
+					'Maybe show date & time filter',
3146
+					'event_espresso'
3147
+				),
3148
+			);
3149
+	}
3150
+
3151
+
3152
+	/**
3153
+	 * @param string $show_datetime_selector
3154
+	 */
3155
+	public function setShowDatetimeSelector($show_datetime_selector)
3156
+	{
3157
+		$this->show_datetime_selector = in_array(
3158
+			$show_datetime_selector,
3159
+			$this->getShowDatetimeSelectorOptions(),
3160
+			true
3161
+		)
3162
+			? $show_datetime_selector
3163
+			: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3164
+	}
3165
+
3166
+
3167
+	/**
3168
+	 * @return int
3169
+	 */
3170
+	public function getDatetimeSelectorThreshold()
3171
+	{
3172
+		return $this->datetime_selector_threshold;
3173
+	}
3174
+
3175
+
3176
+	/**
3177
+	 * @param int $datetime_selector_threshold
3178
+	 */
3179
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3180
+	{
3181
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3182
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3183
+	}
3184
+
3185
+
3186
+	/**
3187
+	 * @return int
3188
+	 */
3189
+	public function getDatetimeSelectorMaxChecked()
3190
+	{
3191
+		return $this->datetime_selector_max_checked;
3192
+	}
3193
+
3194
+
3195
+	/**
3196
+	 * @param int $datetime_selector_max_checked
3197
+	 */
3198
+	public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3199
+	{
3200
+		$this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3201
+	}
3202 3202
 }
3203 3203
 
3204 3204
 /**
@@ -3211,86 +3211,86 @@  discard block
 block discarded – undo
3211 3211
 class EE_Environment_Config extends EE_Config_Base
3212 3212
 {
3213 3213
 
3214
-    /**
3215
-     * Hold any php environment variables that we want to track.
3216
-     *
3217
-     * @var stdClass;
3218
-     */
3219
-    public $php;
3220
-
3221
-
3222
-    /**
3223
-     *    constructor
3224
-     */
3225
-    public function __construct()
3226
-    {
3227
-        $this->php = new stdClass();
3228
-        $this->_set_php_values();
3229
-    }
3230
-
3231
-
3232
-    /**
3233
-     * This sets the php environment variables.
3234
-     *
3235
-     * @since 4.4.0
3236
-     * @return void
3237
-     */
3238
-    protected function _set_php_values()
3239
-    {
3240
-        $this->php->max_input_vars = ini_get('max_input_vars');
3241
-        $this->php->version = phpversion();
3242
-    }
3243
-
3244
-
3245
-    /**
3246
-     * helper method for determining whether input_count is
3247
-     * reaching the potential maximum the server can handle
3248
-     * according to max_input_vars
3249
-     *
3250
-     * @param int   $input_count the count of input vars.
3251
-     * @return array {
3252
-     *                           An array that represents whether available space and if no available space the error
3253
-     *                           message.
3254
-     * @type bool   $has_space   whether more inputs can be added.
3255
-     * @type string $msg         Any message to be displayed.
3256
-     *                           }
3257
-     */
3258
-    public function max_input_vars_limit_check($input_count = 0)
3259
-    {
3260
-        if (! empty($this->php->max_input_vars)
3261
-            && ($input_count >= $this->php->max_input_vars)
3262
-        ) {
3263
-            // check the server setting because the config value could be stale
3264
-            $max_input_vars = ini_get('max_input_vars');
3265
-            if ($input_count >= $max_input_vars) {
3266
-                return sprintf(
3267
-                    esc_html__(
3268
-                        'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3269
-                        'event_espresso'
3270
-                    ),
3271
-                    '<br>',
3272
-                    $input_count,
3273
-                    $max_input_vars
3274
-                );
3275
-            } else {
3276
-                return '';
3277
-            }
3278
-        } else {
3279
-            return '';
3280
-        }
3281
-    }
3282
-
3283
-
3284
-    /**
3285
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3286
-     *
3287
-     * @since 4.4.1
3288
-     * @return void
3289
-     */
3290
-    public function recheck_values()
3291
-    {
3292
-        $this->_set_php_values();
3293
-    }
3214
+	/**
3215
+	 * Hold any php environment variables that we want to track.
3216
+	 *
3217
+	 * @var stdClass;
3218
+	 */
3219
+	public $php;
3220
+
3221
+
3222
+	/**
3223
+	 *    constructor
3224
+	 */
3225
+	public function __construct()
3226
+	{
3227
+		$this->php = new stdClass();
3228
+		$this->_set_php_values();
3229
+	}
3230
+
3231
+
3232
+	/**
3233
+	 * This sets the php environment variables.
3234
+	 *
3235
+	 * @since 4.4.0
3236
+	 * @return void
3237
+	 */
3238
+	protected function _set_php_values()
3239
+	{
3240
+		$this->php->max_input_vars = ini_get('max_input_vars');
3241
+		$this->php->version = phpversion();
3242
+	}
3243
+
3244
+
3245
+	/**
3246
+	 * helper method for determining whether input_count is
3247
+	 * reaching the potential maximum the server can handle
3248
+	 * according to max_input_vars
3249
+	 *
3250
+	 * @param int   $input_count the count of input vars.
3251
+	 * @return array {
3252
+	 *                           An array that represents whether available space and if no available space the error
3253
+	 *                           message.
3254
+	 * @type bool   $has_space   whether more inputs can be added.
3255
+	 * @type string $msg         Any message to be displayed.
3256
+	 *                           }
3257
+	 */
3258
+	public function max_input_vars_limit_check($input_count = 0)
3259
+	{
3260
+		if (! empty($this->php->max_input_vars)
3261
+			&& ($input_count >= $this->php->max_input_vars)
3262
+		) {
3263
+			// check the server setting because the config value could be stale
3264
+			$max_input_vars = ini_get('max_input_vars');
3265
+			if ($input_count >= $max_input_vars) {
3266
+				return sprintf(
3267
+					esc_html__(
3268
+						'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3269
+						'event_espresso'
3270
+					),
3271
+					'<br>',
3272
+					$input_count,
3273
+					$max_input_vars
3274
+				);
3275
+			} else {
3276
+				return '';
3277
+			}
3278
+		} else {
3279
+			return '';
3280
+		}
3281
+	}
3282
+
3283
+
3284
+	/**
3285
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3286
+	 *
3287
+	 * @since 4.4.1
3288
+	 * @return void
3289
+	 */
3290
+	public function recheck_values()
3291
+	{
3292
+		$this->_set_php_values();
3293
+	}
3294 3294
 }
3295 3295
 
3296 3296
 /**
@@ -3303,21 +3303,21 @@  discard block
 block discarded – undo
3303 3303
 class EE_Tax_Config extends EE_Config_Base
3304 3304
 {
3305 3305
 
3306
-    /*
3306
+	/*
3307 3307
      * flag to indicate whether or not to display ticket prices with the taxes included
3308 3308
      *
3309 3309
      * @var boolean $prices_displayed_including_taxes
3310 3310
      */
3311
-    public $prices_displayed_including_taxes;
3311
+	public $prices_displayed_including_taxes;
3312 3312
 
3313 3313
 
3314
-    /**
3315
-     *    class constructor
3316
-     */
3317
-    public function __construct()
3318
-    {
3319
-        $this->prices_displayed_including_taxes = true;
3320
-    }
3314
+	/**
3315
+	 *    class constructor
3316
+	 */
3317
+	public function __construct()
3318
+	{
3319
+		$this->prices_displayed_including_taxes = true;
3320
+	}
3321 3321
 }
3322 3322
 
3323 3323
 /**
@@ -3331,19 +3331,19 @@  discard block
 block discarded – undo
3331 3331
 class EE_Messages_Config extends EE_Config_Base
3332 3332
 {
3333 3333
 
3334
-    /**
3335
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3336
-     * A value of 0 represents never deleting.  Default is 0.
3337
-     *
3338
-     * @var integer
3339
-     */
3340
-    public $delete_threshold;
3334
+	/**
3335
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3336
+	 * A value of 0 represents never deleting.  Default is 0.
3337
+	 *
3338
+	 * @var integer
3339
+	 */
3340
+	public $delete_threshold;
3341 3341
 
3342 3342
 
3343
-    public function __construct()
3344
-    {
3345
-        $this->delete_threshold = 0;
3346
-    }
3343
+	public function __construct()
3344
+	{
3345
+		$this->delete_threshold = 0;
3346
+	}
3347 3347
 }
3348 3348
 
3349 3349
 /**
@@ -3354,31 +3354,31 @@  discard block
 block discarded – undo
3354 3354
 class EE_Gateway_Config extends EE_Config_Base
3355 3355
 {
3356 3356
 
3357
-    /**
3358
-     * Array with keys that are payment gateways slugs, and values are arrays
3359
-     * with any config info the gateway wants to store
3360
-     *
3361
-     * @var array
3362
-     */
3363
-    public $payment_settings;
3364
-
3365
-    /**
3366
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3367
-     * the gateway is stored in the uploads directory
3368
-     *
3369
-     * @var array
3370
-     */
3371
-    public $active_gateways;
3372
-
3373
-
3374
-    /**
3375
-     *    class constructor
3376
-     *
3377
-     * @deprecated
3378
-     */
3379
-    public function __construct()
3380
-    {
3381
-        $this->payment_settings = array();
3382
-        $this->active_gateways = array('Invoice' => false);
3383
-    }
3357
+	/**
3358
+	 * Array with keys that are payment gateways slugs, and values are arrays
3359
+	 * with any config info the gateway wants to store
3360
+	 *
3361
+	 * @var array
3362
+	 */
3363
+	public $payment_settings;
3364
+
3365
+	/**
3366
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3367
+	 * the gateway is stored in the uploads directory
3368
+	 *
3369
+	 * @var array
3370
+	 */
3371
+	public $active_gateways;
3372
+
3373
+
3374
+	/**
3375
+	 *    class constructor
3376
+	 *
3377
+	 * @deprecated
3378
+	 */
3379
+	public function __construct()
3380
+	{
3381
+		$this->payment_settings = array();
3382
+		$this->active_gateways = array('Invoice' => false);
3383
+	}
3384 3384
 }
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 2 patches
Indentation   +1394 added lines, -1394 removed lines patch added patch discarded remove patch
@@ -15,1401 +15,1401 @@
 block discarded – undo
15 15
 class Extend_Events_Admin_Page extends Events_Admin_Page
16 16
 {
17 17
 
18
-    /**
19
-     * @var EE_Admin_Config
20
-     */
21
-    protected $admin_config;
22
-
23
-
24
-    /**
25
-     * Extend_Events_Admin_Page constructor.
26
-     *
27
-     * @param bool $routing
28
-     */
29
-    public function __construct($routing = true)
30
-    {
31
-        parent::__construct($routing);
32
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
33
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
34
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
35
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
36
-        }
37
-    }
38
-
39
-
40
-    /**
41
-     * Sets routes.
42
-     */
43
-    protected function _extend_page_config()
44
-    {
45
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
46
-        // is there a evt_id in the request?
47
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
48
-            ? $this->_req_data['EVT_ID']
49
-            : 0;
50
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
51
-        // tkt_id?
52
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
53
-            ? $this->_req_data['TKT_ID']
54
-            : 0;
55
-        $new_page_routes = array(
56
-            'duplicate_event'          => array(
57
-                'func'       => '_duplicate_event',
58
-                'capability' => 'ee_edit_event',
59
-                'obj_id'     => $evt_id,
60
-                'noheader'   => true,
61
-            ),
62
-            'ticket_list_table'        => array(
63
-                'func'       => '_tickets_overview_list_table',
64
-                'capability' => 'ee_read_default_tickets',
65
-            ),
66
-            'trash_ticket'             => array(
67
-                'func'       => '_trash_or_restore_ticket',
68
-                'capability' => 'ee_delete_default_ticket',
69
-                'obj_id'     => $tkt_id,
70
-                'noheader'   => true,
71
-                'args'       => array('trash' => true),
72
-            ),
73
-            'trash_tickets'            => array(
74
-                'func'       => '_trash_or_restore_ticket',
75
-                'capability' => 'ee_delete_default_tickets',
76
-                'noheader'   => true,
77
-                'args'       => array('trash' => true),
78
-            ),
79
-            'restore_ticket'           => array(
80
-                'func'       => '_trash_or_restore_ticket',
81
-                'capability' => 'ee_delete_default_ticket',
82
-                'obj_id'     => $tkt_id,
83
-                'noheader'   => true,
84
-            ),
85
-            'restore_tickets'          => array(
86
-                'func'       => '_trash_or_restore_ticket',
87
-                'capability' => 'ee_delete_default_tickets',
88
-                'noheader'   => true,
89
-            ),
90
-            'delete_ticket'            => array(
91
-                'func'       => '_delete_ticket',
92
-                'capability' => 'ee_delete_default_ticket',
93
-                'obj_id'     => $tkt_id,
94
-                'noheader'   => true,
95
-            ),
96
-            'delete_tickets'           => array(
97
-                'func'       => '_delete_ticket',
98
-                'capability' => 'ee_delete_default_tickets',
99
-                'noheader'   => true,
100
-            ),
101
-            'import_page'              => array(
102
-                'func'       => '_import_page',
103
-                'capability' => 'import',
104
-            ),
105
-            'import'                   => array(
106
-                'func'       => '_import_events',
107
-                'capability' => 'import',
108
-                'noheader'   => true,
109
-            ),
110
-            'import_events'            => array(
111
-                'func'       => '_import_events',
112
-                'capability' => 'import',
113
-                'noheader'   => true,
114
-            ),
115
-            'export_events'            => array(
116
-                'func'       => '_events_export',
117
-                'capability' => 'export',
118
-                'noheader'   => true,
119
-            ),
120
-            'export_categories'        => array(
121
-                'func'       => '_categories_export',
122
-                'capability' => 'export',
123
-                'noheader'   => true,
124
-            ),
125
-            'sample_export_file'       => array(
126
-                'func'       => '_sample_export_file',
127
-                'capability' => 'export',
128
-                'noheader'   => true,
129
-            ),
130
-            'update_template_settings' => array(
131
-                'func'       => '_update_template_settings',
132
-                'capability' => 'manage_options',
133
-                'noheader'   => true,
134
-            ),
135
-        );
136
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
137
-        // partial route/config override
138
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
139
-        $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
140
-        $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
141
-        $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
142
-        $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
143
-        $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
144
-        // add tickets tab but only if there are more than one default ticket!
145
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
146
-            array(array('TKT_is_default' => 1)),
147
-            'TKT_ID',
148
-            true
149
-        );
150
-        if ($tkt_count > 1) {
151
-            $new_page_config = array(
152
-                'ticket_list_table' => array(
153
-                    'nav'           => array(
154
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
155
-                        'order' => 60,
156
-                    ),
157
-                    'list_table'    => 'Tickets_List_Table',
158
-                    'require_nonce' => false,
159
-                ),
160
-            );
161
-        }
162
-        // template settings
163
-        $new_page_config['template_settings'] = array(
164
-            'nav'           => array(
165
-                'label' => esc_html__('Templates', 'event_espresso'),
166
-                'order' => 30,
167
-            ),
168
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
169
-            'help_tabs'     => array(
170
-                'general_settings_templates_help_tab' => array(
171
-                    'title'    => esc_html__('Templates', 'event_espresso'),
172
-                    'filename' => 'general_settings_templates',
173
-                ),
174
-            ),
175
-            'help_tour'     => array('Templates_Help_Tour'),
176
-            'require_nonce' => false,
177
-        );
178
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
179
-        // add filters and actions
180
-        // modifying _views
181
-        add_filter(
182
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
183
-            array($this, 'add_additional_datetime_button'),
184
-            10,
185
-            2
186
-        );
187
-        add_filter(
188
-            'FHEE_event_datetime_metabox_clone_button_template',
189
-            array($this, 'add_datetime_clone_button'),
190
-            10,
191
-            2
192
-        );
193
-        add_filter(
194
-            'FHEE_event_datetime_metabox_timezones_template',
195
-            array($this, 'datetime_timezones_template'),
196
-            10,
197
-            2
198
-        );
199
-        // filters for event list table
200
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
201
-        add_filter(
202
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
203
-            array($this, 'extra_list_table_actions'),
204
-            10,
205
-            2
206
-        );
207
-        // legend item
208
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
209
-        add_action('admin_init', array($this, 'admin_init'));
210
-        $this->admin_config = EE_Registry::instance()->CFG->admin;
211
-        add_filter(
212
-            'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
213
-            [$this, 'advancedEditorAdminFormSection']
214
-        );
215
-        add_action(
216
-            'AHEE__Events_Admin_Page___update_default_event_settings',
217
-            [$this, 'updateAdvancedEditorAdminFormSettings'],
218
-            10,
219
-            2
220
-        );
221
-    }
222
-
223
-
224
-    /**
225
-     * admin_init
226
-     */
227
-    public function admin_init()
228
-    {
229
-        EE_Registry::$i18n_js_strings = array_merge(
230
-            EE_Registry::$i18n_js_strings,
231
-            array(
232
-                'image_confirm'          => esc_html__(
233
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
234
-                    'event_espresso'
235
-                ),
236
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
237
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
238
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
239
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
240
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
241
-            )
242
-        );
243
-    }
244
-
245
-
246
-    /**
247
-     * Add per page screen options to the default ticket list table view.
248
-     */
249
-    protected function _add_screen_options_ticket_list_table()
250
-    {
251
-        $this->_per_page_screen_option();
252
-    }
253
-
254
-
255
-    /**
256
-     * @param string $return
257
-     * @param int    $id
258
-     * @param string $new_title
259
-     * @param string $new_slug
260
-     * @return string
261
-     */
262
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
263
-    {
264
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
265
-        // make sure this is only when editing
266
-        if (! empty($id)) {
267
-            $href = EE_Admin_Page::add_query_args_and_nonce(
268
-                array('action' => 'duplicate_event', 'EVT_ID' => $id),
269
-                $this->_admin_base_url
270
-            );
271
-            $title = esc_attr__('Duplicate Event', 'event_espresso');
272
-            $return .= '<a href="'
273
-                       . $href
274
-                       . '" title="'
275
-                       . $title
276
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
277
-                       . $title
278
-                       . '</a>';
279
-        }
280
-        return $return;
281
-    }
282
-
283
-
284
-    /**
285
-     * Set the list table views for the default ticket list table view.
286
-     */
287
-    public function _set_list_table_views_ticket_list_table()
288
-    {
289
-        $this->_views = array(
290
-            'all'     => array(
291
-                'slug'        => 'all',
292
-                'label'       => esc_html__('All', 'event_espresso'),
293
-                'count'       => 0,
294
-                'bulk_action' => array(
295
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
296
-                ),
297
-            ),
298
-            'trashed' => array(
299
-                'slug'        => 'trashed',
300
-                'label'       => esc_html__('Trash', 'event_espresso'),
301
-                'count'       => 0,
302
-                'bulk_action' => array(
303
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
304
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
305
-                ),
306
-            ),
307
-        );
308
-    }
309
-
310
-
311
-    /**
312
-     * Enqueue scripts and styles for the event editor.
313
-     */
314
-    public function load_scripts_styles_edit()
315
-    {
316
-        wp_register_script(
317
-            'ee-event-editor-heartbeat',
318
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
319
-            array('ee_admin_js', 'heartbeat'),
320
-            EVENT_ESPRESSO_VERSION,
321
-            true
322
-        );
323
-        wp_enqueue_script('ee-accounting');
324
-        // styles
325
-        wp_enqueue_style('espresso-ui-theme');
326
-        wp_enqueue_script('event_editor_js');
327
-        wp_enqueue_script('ee-event-editor-heartbeat');
328
-        if ($this->admin_config->useAdvancedEditor()) {
329
-            add_action(
330
-                'admin_footer',
331
-                function () {
332
-                    $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
333
-                    if ($eventId) {
334
-                        $view = $this->admin_config->advancedEditorView();
335
-                        $perPage = $this->admin_config->advancedEditorPerPage();
336
-                        echo '
18
+	/**
19
+	 * @var EE_Admin_Config
20
+	 */
21
+	protected $admin_config;
22
+
23
+
24
+	/**
25
+	 * Extend_Events_Admin_Page constructor.
26
+	 *
27
+	 * @param bool $routing
28
+	 */
29
+	public function __construct($routing = true)
30
+	{
31
+		parent::__construct($routing);
32
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
33
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
34
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
35
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
36
+		}
37
+	}
38
+
39
+
40
+	/**
41
+	 * Sets routes.
42
+	 */
43
+	protected function _extend_page_config()
44
+	{
45
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
46
+		// is there a evt_id in the request?
47
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
48
+			? $this->_req_data['EVT_ID']
49
+			: 0;
50
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
51
+		// tkt_id?
52
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
53
+			? $this->_req_data['TKT_ID']
54
+			: 0;
55
+		$new_page_routes = array(
56
+			'duplicate_event'          => array(
57
+				'func'       => '_duplicate_event',
58
+				'capability' => 'ee_edit_event',
59
+				'obj_id'     => $evt_id,
60
+				'noheader'   => true,
61
+			),
62
+			'ticket_list_table'        => array(
63
+				'func'       => '_tickets_overview_list_table',
64
+				'capability' => 'ee_read_default_tickets',
65
+			),
66
+			'trash_ticket'             => array(
67
+				'func'       => '_trash_or_restore_ticket',
68
+				'capability' => 'ee_delete_default_ticket',
69
+				'obj_id'     => $tkt_id,
70
+				'noheader'   => true,
71
+				'args'       => array('trash' => true),
72
+			),
73
+			'trash_tickets'            => array(
74
+				'func'       => '_trash_or_restore_ticket',
75
+				'capability' => 'ee_delete_default_tickets',
76
+				'noheader'   => true,
77
+				'args'       => array('trash' => true),
78
+			),
79
+			'restore_ticket'           => array(
80
+				'func'       => '_trash_or_restore_ticket',
81
+				'capability' => 'ee_delete_default_ticket',
82
+				'obj_id'     => $tkt_id,
83
+				'noheader'   => true,
84
+			),
85
+			'restore_tickets'          => array(
86
+				'func'       => '_trash_or_restore_ticket',
87
+				'capability' => 'ee_delete_default_tickets',
88
+				'noheader'   => true,
89
+			),
90
+			'delete_ticket'            => array(
91
+				'func'       => '_delete_ticket',
92
+				'capability' => 'ee_delete_default_ticket',
93
+				'obj_id'     => $tkt_id,
94
+				'noheader'   => true,
95
+			),
96
+			'delete_tickets'           => array(
97
+				'func'       => '_delete_ticket',
98
+				'capability' => 'ee_delete_default_tickets',
99
+				'noheader'   => true,
100
+			),
101
+			'import_page'              => array(
102
+				'func'       => '_import_page',
103
+				'capability' => 'import',
104
+			),
105
+			'import'                   => array(
106
+				'func'       => '_import_events',
107
+				'capability' => 'import',
108
+				'noheader'   => true,
109
+			),
110
+			'import_events'            => array(
111
+				'func'       => '_import_events',
112
+				'capability' => 'import',
113
+				'noheader'   => true,
114
+			),
115
+			'export_events'            => array(
116
+				'func'       => '_events_export',
117
+				'capability' => 'export',
118
+				'noheader'   => true,
119
+			),
120
+			'export_categories'        => array(
121
+				'func'       => '_categories_export',
122
+				'capability' => 'export',
123
+				'noheader'   => true,
124
+			),
125
+			'sample_export_file'       => array(
126
+				'func'       => '_sample_export_file',
127
+				'capability' => 'export',
128
+				'noheader'   => true,
129
+			),
130
+			'update_template_settings' => array(
131
+				'func'       => '_update_template_settings',
132
+				'capability' => 'manage_options',
133
+				'noheader'   => true,
134
+			),
135
+		);
136
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
137
+		// partial route/config override
138
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
139
+		$this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
140
+		$this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
141
+		$this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
142
+		$this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
143
+		$this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
144
+		// add tickets tab but only if there are more than one default ticket!
145
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
146
+			array(array('TKT_is_default' => 1)),
147
+			'TKT_ID',
148
+			true
149
+		);
150
+		if ($tkt_count > 1) {
151
+			$new_page_config = array(
152
+				'ticket_list_table' => array(
153
+					'nav'           => array(
154
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
155
+						'order' => 60,
156
+					),
157
+					'list_table'    => 'Tickets_List_Table',
158
+					'require_nonce' => false,
159
+				),
160
+			);
161
+		}
162
+		// template settings
163
+		$new_page_config['template_settings'] = array(
164
+			'nav'           => array(
165
+				'label' => esc_html__('Templates', 'event_espresso'),
166
+				'order' => 30,
167
+			),
168
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
169
+			'help_tabs'     => array(
170
+				'general_settings_templates_help_tab' => array(
171
+					'title'    => esc_html__('Templates', 'event_espresso'),
172
+					'filename' => 'general_settings_templates',
173
+				),
174
+			),
175
+			'help_tour'     => array('Templates_Help_Tour'),
176
+			'require_nonce' => false,
177
+		);
178
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
179
+		// add filters and actions
180
+		// modifying _views
181
+		add_filter(
182
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
183
+			array($this, 'add_additional_datetime_button'),
184
+			10,
185
+			2
186
+		);
187
+		add_filter(
188
+			'FHEE_event_datetime_metabox_clone_button_template',
189
+			array($this, 'add_datetime_clone_button'),
190
+			10,
191
+			2
192
+		);
193
+		add_filter(
194
+			'FHEE_event_datetime_metabox_timezones_template',
195
+			array($this, 'datetime_timezones_template'),
196
+			10,
197
+			2
198
+		);
199
+		// filters for event list table
200
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
201
+		add_filter(
202
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
203
+			array($this, 'extra_list_table_actions'),
204
+			10,
205
+			2
206
+		);
207
+		// legend item
208
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
209
+		add_action('admin_init', array($this, 'admin_init'));
210
+		$this->admin_config = EE_Registry::instance()->CFG->admin;
211
+		add_filter(
212
+			'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
213
+			[$this, 'advancedEditorAdminFormSection']
214
+		);
215
+		add_action(
216
+			'AHEE__Events_Admin_Page___update_default_event_settings',
217
+			[$this, 'updateAdvancedEditorAdminFormSettings'],
218
+			10,
219
+			2
220
+		);
221
+	}
222
+
223
+
224
+	/**
225
+	 * admin_init
226
+	 */
227
+	public function admin_init()
228
+	{
229
+		EE_Registry::$i18n_js_strings = array_merge(
230
+			EE_Registry::$i18n_js_strings,
231
+			array(
232
+				'image_confirm'          => esc_html__(
233
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
234
+					'event_espresso'
235
+				),
236
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
237
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
238
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
239
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
240
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
241
+			)
242
+		);
243
+	}
244
+
245
+
246
+	/**
247
+	 * Add per page screen options to the default ticket list table view.
248
+	 */
249
+	protected function _add_screen_options_ticket_list_table()
250
+	{
251
+		$this->_per_page_screen_option();
252
+	}
253
+
254
+
255
+	/**
256
+	 * @param string $return
257
+	 * @param int    $id
258
+	 * @param string $new_title
259
+	 * @param string $new_slug
260
+	 * @return string
261
+	 */
262
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
263
+	{
264
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
265
+		// make sure this is only when editing
266
+		if (! empty($id)) {
267
+			$href = EE_Admin_Page::add_query_args_and_nonce(
268
+				array('action' => 'duplicate_event', 'EVT_ID' => $id),
269
+				$this->_admin_base_url
270
+			);
271
+			$title = esc_attr__('Duplicate Event', 'event_espresso');
272
+			$return .= '<a href="'
273
+					   . $href
274
+					   . '" title="'
275
+					   . $title
276
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
277
+					   . $title
278
+					   . '</a>';
279
+		}
280
+		return $return;
281
+	}
282
+
283
+
284
+	/**
285
+	 * Set the list table views for the default ticket list table view.
286
+	 */
287
+	public function _set_list_table_views_ticket_list_table()
288
+	{
289
+		$this->_views = array(
290
+			'all'     => array(
291
+				'slug'        => 'all',
292
+				'label'       => esc_html__('All', 'event_espresso'),
293
+				'count'       => 0,
294
+				'bulk_action' => array(
295
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
296
+				),
297
+			),
298
+			'trashed' => array(
299
+				'slug'        => 'trashed',
300
+				'label'       => esc_html__('Trash', 'event_espresso'),
301
+				'count'       => 0,
302
+				'bulk_action' => array(
303
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
304
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
305
+				),
306
+			),
307
+		);
308
+	}
309
+
310
+
311
+	/**
312
+	 * Enqueue scripts and styles for the event editor.
313
+	 */
314
+	public function load_scripts_styles_edit()
315
+	{
316
+		wp_register_script(
317
+			'ee-event-editor-heartbeat',
318
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
319
+			array('ee_admin_js', 'heartbeat'),
320
+			EVENT_ESPRESSO_VERSION,
321
+			true
322
+		);
323
+		wp_enqueue_script('ee-accounting');
324
+		// styles
325
+		wp_enqueue_style('espresso-ui-theme');
326
+		wp_enqueue_script('event_editor_js');
327
+		wp_enqueue_script('ee-event-editor-heartbeat');
328
+		if ($this->admin_config->useAdvancedEditor()) {
329
+			add_action(
330
+				'admin_footer',
331
+				function () {
332
+					$eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
333
+					if ($eventId) {
334
+						$view = $this->admin_config->advancedEditorView();
335
+						$perPage = $this->admin_config->advancedEditorPerPage();
336
+						echo '
337 337
         <script type="text/javascript">
338 338
             /* <![CDATA[ */ var eeEditorEventId = ' . $eventId . '; var eeEditorListView = "' . $view . '"; var eeEditorPerPage = ' . $perPage . '; /* ]]> */
339 339
         </script>';
340
-                    }
341
-                }
342
-            );
343
-        }
344
-    }
345
-
346
-
347
-    /**
348
-     * Returns template for the additional datetime.
349
-     *
350
-     * @param $template
351
-     * @param $template_args
352
-     * @return mixed
353
-     * @throws DomainException
354
-     */
355
-    public function add_additional_datetime_button($template, $template_args)
356
-    {
357
-        return EEH_Template::display_template(
358
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
359
-            $template_args,
360
-            true
361
-        );
362
-    }
363
-
364
-
365
-    /**
366
-     * Returns the template for cloning a datetime.
367
-     *
368
-     * @param $template
369
-     * @param $template_args
370
-     * @return mixed
371
-     * @throws DomainException
372
-     */
373
-    public function add_datetime_clone_button($template, $template_args)
374
-    {
375
-        return EEH_Template::display_template(
376
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
377
-            $template_args,
378
-            true
379
-        );
380
-    }
381
-
382
-
383
-    /**
384
-     * Returns the template for datetime timezones.
385
-     *
386
-     * @param $template
387
-     * @param $template_args
388
-     * @return mixed
389
-     * @throws DomainException
390
-     */
391
-    public function datetime_timezones_template($template, $template_args)
392
-    {
393
-        return EEH_Template::display_template(
394
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
395
-            $template_args,
396
-            true
397
-        );
398
-    }
399
-
400
-
401
-    /**
402
-     * Sets the views for the default list table view.
403
-     */
404
-    protected function _set_list_table_views_default()
405
-    {
406
-        parent::_set_list_table_views_default();
407
-        $new_views = array(
408
-            'today' => array(
409
-                'slug'        => 'today',
410
-                'label'       => esc_html__('Today', 'event_espresso'),
411
-                'count'       => $this->total_events_today(),
412
-                'bulk_action' => array(
413
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
414
-                ),
415
-            ),
416
-            'month' => array(
417
-                'slug'        => 'month',
418
-                'label'       => esc_html__('This Month', 'event_espresso'),
419
-                'count'       => $this->total_events_this_month(),
420
-                'bulk_action' => array(
421
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
422
-                ),
423
-            ),
424
-        );
425
-        $this->_views = array_merge($this->_views, $new_views);
426
-    }
427
-
428
-
429
-    /**
430
-     * Returns the extra action links for the default list table view.
431
-     *
432
-     * @param array     $action_links
433
-     * @param \EE_Event $event
434
-     * @return array
435
-     * @throws EE_Error
436
-     */
437
-    public function extra_list_table_actions(array $action_links, \EE_Event $event)
438
-    {
439
-        if (EE_Registry::instance()->CAP->current_user_can(
440
-            'ee_read_registrations',
441
-            'espresso_registrations_reports',
442
-            $event->ID()
443
-        )
444
-        ) {
445
-            $reports_query_args = array(
446
-                'action' => 'reports',
447
-                'EVT_ID' => $event->ID(),
448
-            );
449
-            $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
450
-            $action_links[] = '<a href="'
451
-                              . $reports_link
452
-                              . '" title="'
453
-                              . esc_attr__('View Report', 'event_espresso')
454
-                              . '"><div class="dashicons dashicons-chart-bar"></div></a>'
455
-                              . "\n\t";
456
-        }
457
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
458
-            EE_Registry::instance()->load_helper('MSG_Template');
459
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
460
-                'see_notifications_for',
461
-                null,
462
-                array('EVT_ID' => $event->ID())
463
-            );
464
-        }
465
-        return $action_links;
466
-    }
467
-
468
-
469
-    /**
470
-     * @param $items
471
-     * @return mixed
472
-     */
473
-    public function additional_legend_items($items)
474
-    {
475
-        if (EE_Registry::instance()->CAP->current_user_can(
476
-            'ee_read_registrations',
477
-            'espresso_registrations_reports'
478
-        )
479
-        ) {
480
-            $items['reports'] = array(
481
-                'class' => 'dashicons dashicons-chart-bar',
482
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
483
-            );
484
-        }
485
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
486
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
487
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
488
-                $items['view_related_messages'] = array(
489
-                    'class' => $related_for_icon['css_class'],
490
-                    'desc'  => $related_for_icon['label'],
491
-                );
492
-            }
493
-        }
494
-        return $items;
495
-    }
496
-
497
-
498
-    /**
499
-     * This is the callback method for the duplicate event route
500
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
501
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
502
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
503
-     * After duplication the redirect is to the new event edit page.
504
-     *
505
-     * @return void
506
-     * @access protected
507
-     * @throws EE_Error If EE_Event is not available with given ID
508
-     */
509
-    protected function _duplicate_event()
510
-    {
511
-        // first make sure the ID for the event is in the request.
512
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
513
-        if (! isset($this->_req_data['EVT_ID'])) {
514
-            EE_Error::add_error(
515
-                esc_html__(
516
-                    'In order to duplicate an event an Event ID is required.  None was given.',
517
-                    'event_espresso'
518
-                ),
519
-                __FILE__,
520
-                __FUNCTION__,
521
-                __LINE__
522
-            );
523
-            $this->_redirect_after_action(false, '', '', array(), true);
524
-            return;
525
-        }
526
-        // k we've got EVT_ID so let's use that to get the event we'll duplicate
527
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
528
-        if (! $orig_event instanceof EE_Event) {
529
-            throw new EE_Error(
530
-                sprintf(
531
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
532
-                    $this->_req_data['EVT_ID']
533
-                )
534
-            );
535
-        }
536
-        // k now let's clone the $orig_event before getting relations
537
-        $new_event = clone $orig_event;
538
-        // original datetimes
539
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
540
-        // other original relations
541
-        $orig_ven = $orig_event->get_many_related('Venue');
542
-        // reset the ID and modify other details to make it clear this is a dupe
543
-        $new_event->set('EVT_ID', 0);
544
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
545
-        $new_event->set('EVT_name', $new_name);
546
-        $new_event->set(
547
-            'EVT_slug',
548
-            wp_unique_post_slug(
549
-                sanitize_title($orig_event->name()),
550
-                0,
551
-                'publish',
552
-                'espresso_events',
553
-                0
554
-            )
555
-        );
556
-        $new_event->set('status', 'draft');
557
-        // duplicate discussion settings
558
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
559
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
560
-        // save the new event
561
-        $new_event->save();
562
-        // venues
563
-        foreach ($orig_ven as $ven) {
564
-            $new_event->_add_relation_to($ven, 'Venue');
565
-        }
566
-        $new_event->save();
567
-        // now we need to get the question group relations and handle that
568
-        // first primary question groups
569
-        $orig_primary_qgs = $orig_event->get_many_related(
570
-            'Question_Group',
571
-            array(array('Event_Question_Group.EQG_primary' => 1))
572
-        );
573
-        if (! empty($orig_primary_qgs)) {
574
-            foreach ($orig_primary_qgs as $id => $obj) {
575
-                if ($obj instanceof EE_Question_Group) {
576
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
577
-                }
578
-            }
579
-        }
580
-        // next additional attendee question groups
581
-        $orig_additional_qgs = $orig_event->get_many_related(
582
-            'Question_Group',
583
-            array(array('Event_Question_Group.EQG_primary' => 0))
584
-        );
585
-        if (! empty($orig_additional_qgs)) {
586
-            foreach ($orig_additional_qgs as $id => $obj) {
587
-                if ($obj instanceof EE_Question_Group) {
588
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
589
-                }
590
-            }
591
-        }
592
-
593
-        $new_event->save();
594
-
595
-        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
596
-        $cloned_tickets = array();
597
-        foreach ($orig_datetimes as $orig_dtt) {
598
-            if (! $orig_dtt instanceof EE_Datetime) {
599
-                continue;
600
-            }
601
-            $new_dtt = clone $orig_dtt;
602
-            $orig_tkts = $orig_dtt->tickets();
603
-            // save new dtt then add to event
604
-            $new_dtt->set('DTT_ID', 0);
605
-            $new_dtt->set('DTT_sold', 0);
606
-            $new_dtt->set_reserved(0);
607
-            $new_dtt->save();
608
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
609
-            $new_event->save();
610
-            // now let's get the ticket relations setup.
611
-            foreach ((array) $orig_tkts as $orig_tkt) {
612
-                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
613
-                if (! $orig_tkt instanceof EE_Ticket) {
614
-                    continue;
615
-                }
616
-                // is this ticket archived?  If it is then let's skip
617
-                if ($orig_tkt->get('TKT_deleted')) {
618
-                    continue;
619
-                }
620
-                // does this original ticket already exist in the clone_tickets cache?
621
-                //  If so we'll just use the new ticket from it.
622
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
623
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
624
-                } else {
625
-                    $new_tkt = clone $orig_tkt;
626
-                    // get relations on the $orig_tkt that we need to setup.
627
-                    $orig_prices = $orig_tkt->prices();
628
-                    $new_tkt->set('TKT_ID', 0);
629
-                    $new_tkt->set('TKT_sold', 0);
630
-                    $new_tkt->set('TKT_reserved', 0);
631
-                    $new_tkt->save(); // make sure new ticket has ID.
632
-                    // price relations on new ticket need to be setup.
633
-                    foreach ($orig_prices as $orig_price) {
634
-                        $new_price = clone $orig_price;
635
-                        $new_price->set('PRC_ID', 0);
636
-                        $new_price->save();
637
-                        $new_tkt->_add_relation_to($new_price, 'Price');
638
-                        $new_tkt->save();
639
-                    }
640
-
641
-                    do_action(
642
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
643
-                        $orig_tkt,
644
-                        $new_tkt,
645
-                        $orig_prices,
646
-                        $orig_event,
647
-                        $orig_dtt,
648
-                        $new_dtt
649
-                    );
650
-                }
651
-                // k now we can add the new ticket as a relation to the new datetime
652
-                // and make sure its added to our cached $cloned_tickets array
653
-                // for use with later datetimes that have the same ticket.
654
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
655
-                $new_dtt->save();
656
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
657
-            }
658
-        }
659
-        // clone taxonomy information
660
-        $taxonomies_to_clone_with = apply_filters(
661
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
662
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
663
-        );
664
-        // get terms for original event (notice)
665
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
666
-        // loop through terms and add them to new event.
667
-        foreach ($orig_terms as $term) {
668
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
669
-        }
670
-
671
-        // duplicate other core WP_Post items for this event.
672
-        // post thumbnail (feature image).
673
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
674
-        if ($feature_image_id) {
675
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
676
-        }
677
-
678
-        // duplicate page_template setting
679
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
680
-        if ($page_template) {
681
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
682
-        }
683
-
684
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
685
-        // now let's redirect to the edit page for this duplicated event if we have a new event id.
686
-        if ($new_event->ID()) {
687
-            $redirect_args = array(
688
-                'post'   => $new_event->ID(),
689
-                'action' => 'edit',
690
-            );
691
-            EE_Error::add_success(
692
-                esc_html__(
693
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
694
-                    'event_espresso'
695
-                )
696
-            );
697
-        } else {
698
-            $redirect_args = array(
699
-                'action' => 'default',
700
-            );
701
-            EE_Error::add_error(
702
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
703
-                __FILE__,
704
-                __FUNCTION__,
705
-                __LINE__
706
-            );
707
-        }
708
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
709
-    }
710
-
711
-
712
-    /**
713
-     * Generates output for the import page.
714
-     *
715
-     * @throws DomainException
716
-     */
717
-    protected function _import_page()
718
-    {
719
-        $title = esc_html__('Import', 'event_espresso');
720
-        $intro = esc_html__(
721
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
722
-            'event_espresso'
723
-        );
724
-        $form_url = EVENTS_ADMIN_URL;
725
-        $action = 'import_events';
726
-        $type = 'csv';
727
-        $this->_template_args['form'] = EE_Import::instance()->upload_form(
728
-            $title,
729
-            $intro,
730
-            $form_url,
731
-            $action,
732
-            $type
733
-        );
734
-        $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
735
-            array('action' => 'sample_export_file'),
736
-            $this->_admin_base_url
737
-        );
738
-        $content = EEH_Template::display_template(
739
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
740
-            $this->_template_args,
741
-            true
742
-        );
743
-        $this->_template_args['admin_page_content'] = $content;
744
-        $this->display_admin_page_with_sidebar();
745
-    }
746
-
747
-
748
-    /**
749
-     * _import_events
750
-     * This handles displaying the screen and running imports for importing events.
751
-     *
752
-     * @return void
753
-     */
754
-    protected function _import_events()
755
-    {
756
-        require_once(EE_CLASSES . 'EE_Import.class.php');
757
-        $success = EE_Import::instance()->import();
758
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
759
-    }
760
-
761
-
762
-    /**
763
-     * _events_export
764
-     * Will export all (or just the given event) to a Excel compatible file.
765
-     *
766
-     * @access protected
767
-     * @return void
768
-     */
769
-    protected function _events_export()
770
-    {
771
-        if (isset($this->_req_data['EVT_ID'])) {
772
-            $event_ids = $this->_req_data['EVT_ID'];
773
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
774
-            $event_ids = $this->_req_data['EVT_IDs'];
775
-        } else {
776
-            $event_ids = null;
777
-        }
778
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
779
-        $new_request_args = array(
780
-            'export' => 'report',
781
-            'action' => 'all_event_data',
782
-            'EVT_ID' => $event_ids,
783
-        );
784
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
785
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
786
-            require_once(EE_CLASSES . 'EE_Export.class.php');
787
-            $EE_Export = EE_Export::instance($this->_req_data);
788
-            $EE_Export->export();
789
-        }
790
-    }
791
-
792
-
793
-    /**
794
-     * handle category exports()
795
-     *
796
-     * @return void
797
-     */
798
-    protected function _categories_export()
799
-    {
800
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
801
-        $new_request_args = array(
802
-            'export'       => 'report',
803
-            'action'       => 'categories',
804
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
805
-        );
806
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
807
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
808
-            require_once(EE_CLASSES . 'EE_Export.class.php');
809
-            $EE_Export = EE_Export::instance($this->_req_data);
810
-            $EE_Export->export();
811
-        }
812
-    }
813
-
814
-
815
-    /**
816
-     * Creates a sample CSV file for importing
817
-     */
818
-    protected function _sample_export_file()
819
-    {
820
-        // require_once(EE_CLASSES . 'EE_Export.class.php');
821
-        EE_Export::instance()->export_sample();
822
-    }
823
-
824
-
825
-    /*************        Template Settings        *************/
826
-    /**
827
-     * Generates template settings page output
828
-     *
829
-     * @throws DomainException
830
-     * @throws EE_Error
831
-     */
832
-    protected function _template_settings()
833
-    {
834
-        $this->_template_args['values'] = $this->_yes_no_values;
835
-        /**
836
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
837
-         * from General_Settings_Admin_Page to here.
838
-         */
839
-        $this->_template_args = apply_filters(
840
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
841
-            $this->_template_args
842
-        );
843
-        $this->_set_add_edit_form_tags('update_template_settings');
844
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
845
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
846
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
847
-            $this->_template_args,
848
-            true
849
-        );
850
-        $this->display_admin_page_with_sidebar();
851
-    }
852
-
853
-
854
-    /**
855
-     * Handler for updating template settings.
856
-     *
857
-     * @throws InvalidInterfaceException
858
-     * @throws InvalidDataTypeException
859
-     * @throws InvalidArgumentException
860
-     */
861
-    protected function _update_template_settings()
862
-    {
863
-        /**
864
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
865
-         * from General_Settings_Admin_Page to here.
866
-         */
867
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
868
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
869
-            EE_Registry::instance()->CFG->template_settings,
870
-            $this->_req_data
871
-        );
872
-        // update custom post type slugs and detect if we need to flush rewrite rules
873
-        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
874
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
875
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
876
-            : EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
877
-        $what = 'Template Settings';
878
-        $success = $this->_update_espresso_configuration(
879
-            $what,
880
-            EE_Registry::instance()->CFG->template_settings,
881
-            __FILE__,
882
-            __FUNCTION__,
883
-            __LINE__
884
-        );
885
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
886
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
887
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
888
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
889
-            );
890
-            $rewrite_rules->flush();
891
-        }
892
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
893
-    }
894
-
895
-
896
-    /**
897
-     * _premium_event_editor_meta_boxes
898
-     * add all metaboxes related to the event_editor
899
-     *
900
-     * @access protected
901
-     * @return void
902
-     * @throws EE_Error
903
-     */
904
-    protected function _premium_event_editor_meta_boxes()
905
-    {
906
-        $this->verify_cpt_object();
907
-        add_meta_box(
908
-            'espresso_event_editor_event_options',
909
-            esc_html__('Event Registration Options', 'event_espresso'),
910
-            array($this, 'registration_options_meta_box'),
911
-            $this->page_slug,
912
-            'side',
913
-            'core'
914
-        );
915
-    }
916
-
917
-
918
-    /**
919
-     * override caf metabox
920
-     *
921
-     * @return void
922
-     * @throws DomainException
923
-     */
924
-    public function registration_options_meta_box()
925
-    {
926
-        $yes_no_values = array(
927
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
928
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
929
-        );
930
-        $default_reg_status_values = EEM_Registration::reg_status_array(
931
-            array(
932
-                EEM_Registration::status_id_cancelled,
933
-                EEM_Registration::status_id_declined,
934
-                EEM_Registration::status_id_incomplete,
935
-                EEM_Registration::status_id_wait_list,
936
-            ),
937
-            true
938
-        );
939
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
940
-        $template_args['_event'] = $this->_cpt_model_obj;
941
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
942
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
943
-            'default_reg_status',
944
-            $default_reg_status_values,
945
-            $this->_cpt_model_obj->default_registration_status()
946
-        );
947
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
948
-            'display_desc',
949
-            $yes_no_values,
950
-            $this->_cpt_model_obj->display_description()
951
-        );
952
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
953
-            'display_ticket_selector',
954
-            $yes_no_values,
955
-            $this->_cpt_model_obj->display_ticket_selector(),
956
-            '',
957
-            '',
958
-            false
959
-        );
960
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
961
-            'EVT_default_registration_status',
962
-            $default_reg_status_values,
963
-            $this->_cpt_model_obj->default_registration_status()
964
-        );
965
-        $template_args['additional_registration_options'] = apply_filters(
966
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
967
-            '',
968
-            $template_args,
969
-            $yes_no_values,
970
-            $default_reg_status_values
971
-        );
972
-        EEH_Template::display_template(
973
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
974
-            $template_args
975
-        );
976
-    }
977
-
978
-
979
-
980
-    /**
981
-     * wp_list_table_mods for caf
982
-     * ============================
983
-     */
984
-    /**
985
-     * hook into list table filters and provide filters for caffeinated list table
986
-     *
987
-     * @param  array $old_filters    any existing filters present
988
-     * @param  array $list_table_obj the list table object
989
-     * @return array                  new filters
990
-     */
991
-    public function list_table_filters($old_filters, $list_table_obj)
992
-    {
993
-        $filters = array();
994
-        // first month/year filters
995
-        $filters[] = $this->espresso_event_months_dropdown();
996
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
997
-        // active status dropdown
998
-        if ($status !== 'draft') {
999
-            $filters[] = $this->active_status_dropdown(
1000
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
1001
-            );
1002
-        }
1003
-        // category filter
1004
-        $filters[] = $this->category_dropdown();
1005
-        return array_merge($old_filters, $filters);
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * espresso_event_months_dropdown
1011
-     *
1012
-     * @access public
1013
-     * @return string                dropdown listing month/year selections for events.
1014
-     */
1015
-    public function espresso_event_months_dropdown()
1016
-    {
1017
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
1018
-        // Note we need to include any other filters that are set!
1019
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1020
-        // categories?
1021
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1022
-            ? $this->_req_data['EVT_CAT']
1023
-            : null;
1024
-        // active status?
1025
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1026
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1027
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1028
-    }
1029
-
1030
-
1031
-    /**
1032
-     * returns a list of "active" statuses on the event
1033
-     *
1034
-     * @param  string $current_value whatever the current active status is
1035
-     * @return string
1036
-     */
1037
-    public function active_status_dropdown($current_value = '')
1038
-    {
1039
-        $select_name = 'active_status';
1040
-        $values = array(
1041
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1042
-            'active'   => esc_html__('Active', 'event_espresso'),
1043
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1044
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1045
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1046
-        );
1047
-        $id = 'id="espresso-active-status-dropdown-filter"';
1048
-        $class = 'wide';
1049
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1050
-    }
1051
-
1052
-
1053
-    /**
1054
-     * output a dropdown of the categories for the category filter on the event admin list table
1055
-     *
1056
-     * @access  public
1057
-     * @return string html
1058
-     */
1059
-    public function category_dropdown()
1060
-    {
1061
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1062
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1063
-    }
1064
-
1065
-
1066
-    /**
1067
-     * get total number of events today
1068
-     *
1069
-     * @access public
1070
-     * @return int
1071
-     * @throws EE_Error
1072
-     */
1073
-    public function total_events_today()
1074
-    {
1075
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1076
-            'DTT_EVT_start',
1077
-            date('Y-m-d') . ' 00:00:00',
1078
-            'Y-m-d H:i:s',
1079
-            'UTC'
1080
-        );
1081
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1082
-            'DTT_EVT_start',
1083
-            date('Y-m-d') . ' 23:59:59',
1084
-            'Y-m-d H:i:s',
1085
-            'UTC'
1086
-        );
1087
-        $where = array(
1088
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1089
-        );
1090
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1091
-        return $count;
1092
-    }
1093
-
1094
-
1095
-    /**
1096
-     * get total number of events this month
1097
-     *
1098
-     * @access public
1099
-     * @return int
1100
-     * @throws EE_Error
1101
-     */
1102
-    public function total_events_this_month()
1103
-    {
1104
-        // Dates
1105
-        $this_year_r = date('Y');
1106
-        $this_month_r = date('m');
1107
-        $days_this_month = date('t');
1108
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1109
-            'DTT_EVT_start',
1110
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1111
-            'Y-m-d H:i:s',
1112
-            'UTC'
1113
-        );
1114
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1115
-            'DTT_EVT_start',
1116
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1117
-            'Y-m-d H:i:s',
1118
-            'UTC'
1119
-        );
1120
-        $where = array(
1121
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1122
-        );
1123
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1124
-        return $count;
1125
-    }
1126
-
1127
-
1128
-    /** DEFAULT TICKETS STUFF **/
1129
-
1130
-    /**
1131
-     * Output default tickets list table view.
1132
-     */
1133
-    public function _tickets_overview_list_table()
1134
-    {
1135
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1136
-        $this->display_admin_list_table_page_with_no_sidebar();
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     * @param int  $per_page
1142
-     * @param bool $count
1143
-     * @param bool $trashed
1144
-     * @return \EE_Soft_Delete_Base_Class[]|int
1145
-     */
1146
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1147
-    {
1148
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1149
-        $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1150
-        switch ($orderby) {
1151
-            case 'TKT_name':
1152
-                $orderby = array('TKT_name' => $order);
1153
-                break;
1154
-            case 'TKT_price':
1155
-                $orderby = array('TKT_price' => $order);
1156
-                break;
1157
-            case 'TKT_uses':
1158
-                $orderby = array('TKT_uses' => $order);
1159
-                break;
1160
-            case 'TKT_min':
1161
-                $orderby = array('TKT_min' => $order);
1162
-                break;
1163
-            case 'TKT_max':
1164
-                $orderby = array('TKT_max' => $order);
1165
-                break;
1166
-            case 'TKT_qty':
1167
-                $orderby = array('TKT_qty' => $order);
1168
-                break;
1169
-        }
1170
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1171
-            ? $this->_req_data['paged']
1172
-            : 1;
1173
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1174
-            ? $this->_req_data['perpage']
1175
-            : $per_page;
1176
-        $_where = array(
1177
-            'TKT_is_default' => 1,
1178
-            'TKT_deleted'    => $trashed,
1179
-        );
1180
-        $offset = ($current_page - 1) * $per_page;
1181
-        $limit = array($offset, $per_page);
1182
-        if (isset($this->_req_data['s'])) {
1183
-            $sstr = '%' . $this->_req_data['s'] . '%';
1184
-            $_where['OR'] = array(
1185
-                'TKT_name'        => array('LIKE', $sstr),
1186
-                'TKT_description' => array('LIKE', $sstr),
1187
-            );
1188
-        }
1189
-        $query_params = array(
1190
-            $_where,
1191
-            'order_by' => $orderby,
1192
-            'limit'    => $limit,
1193
-            'group_by' => 'TKT_ID',
1194
-        );
1195
-        if ($count) {
1196
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1197
-        } else {
1198
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1199
-        }
1200
-    }
1201
-
1202
-
1203
-    /**
1204
-     * @param bool $trash
1205
-     * @throws EE_Error
1206
-     */
1207
-    protected function _trash_or_restore_ticket($trash = false)
1208
-    {
1209
-        $success = 1;
1210
-        $TKT = EEM_Ticket::instance();
1211
-        // checkboxes?
1212
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1213
-            // if array has more than one element then success message should be plural
1214
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1215
-            // cycle thru the boxes
1216
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1217
-                if ($trash) {
1218
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1219
-                        $success = 0;
1220
-                    }
1221
-                } else {
1222
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1223
-                        $success = 0;
1224
-                    }
1225
-                }
1226
-            }
1227
-        } else {
1228
-            // grab single id and trash
1229
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1230
-            if ($trash) {
1231
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1232
-                    $success = 0;
1233
-                }
1234
-            } else {
1235
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1236
-                    $success = 0;
1237
-                }
1238
-            }
1239
-        }
1240
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1241
-        $query_args = array(
1242
-            'action' => 'ticket_list_table',
1243
-            'status' => $trash ? '' : 'trashed',
1244
-        );
1245
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1246
-    }
1247
-
1248
-
1249
-    /**
1250
-     * Handles trashing default ticket.
1251
-     */
1252
-    protected function _delete_ticket()
1253
-    {
1254
-        $success = 1;
1255
-        // checkboxes?
1256
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1257
-            // if array has more than one element then success message should be plural
1258
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1259
-            // cycle thru the boxes
1260
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1261
-                // delete
1262
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1263
-                    $success = 0;
1264
-                }
1265
-            }
1266
-        } else {
1267
-            // grab single id and trash
1268
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1269
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1270
-                $success = 0;
1271
-            }
1272
-        }
1273
-        $action_desc = 'deleted';
1274
-        $query_args = array(
1275
-            'action' => 'ticket_list_table',
1276
-            'status' => 'trashed',
1277
-        );
1278
-        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1279
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1280
-            array(array('TKT_is_default' => 1)),
1281
-            'TKT_ID',
1282
-            true
1283
-        )
1284
-        ) {
1285
-            $query_args = array();
1286
-        }
1287
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1288
-    }
1289
-
1290
-
1291
-    /**
1292
-     * @param int $TKT_ID
1293
-     * @return bool|int
1294
-     * @throws EE_Error
1295
-     */
1296
-    protected function _delete_the_ticket($TKT_ID)
1297
-    {
1298
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1299
-        $tkt->_remove_relations('Datetime');
1300
-        // delete all related prices first
1301
-        $tkt->delete_related_permanently('Price');
1302
-        return $tkt->delete_permanently();
1303
-    }
1304
-
1305
-
1306
-    /**
1307
-     * @param array $default_event_settings_form_subsections
1308
-     * @return array
1309
-     * @since $VID:$
1310
-     */
1311
-    public function advancedEditorAdminFormSection(array $default_event_settings_form_subsections)
1312
-    {
1313
-        return [
1314
-            'advanced_editor_header' => new EE_Form_Section_HTML(
1315
-                EEH_HTML::div(
1316
-                    EEH_HTML::div(
1317
-                        EEH_HTML::h2(
1318
-                            esc_html__('New Feature', 'event_espresso'),
1319
-                            '',
1320
-                            'ee-admin-settings-hdr ee-new-flag'
1321
-                        ),
1322
-                        '',
1323
-                        'ee-new-flag-wrap'
1324
-                    ),
1325
-                    '',
1326
-                    'ee-new-flag-shadow',
1327
-                    'margin: -25px 0 10px;'
1328
-                )
1329
-            ),
1330
-            'use_advanced_editor'         => new EE_Select_Input(
1331
-                apply_filters(
1332
-                    'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_options',
1333
-                    [
1334
-                        esc_html__('Legacy Editor', 'event_espresso'),
1335
-                        esc_html__('Advanced Editor', 'event_espresso'),
1336
-                    ]
1337
-                ),
1338
-                [
1339
-                    'default'         => $this->admin_config->useAdvancedEditor(),
1340
-                    'html_label_text' => esc_html__('Activate Advanced Editor?', 'event_espresso'),
1341
-                    'html_help_text'  => sprintf(
1342
-                        esc_html__(
1343
-                            'Controls whether the Event Espresso Event Editor continues to use the existing legacy editor that functions like the typical older WordPress admin you are used to,%1$sor uses the new Advanced Editor with a more powerful and easier to use interface. This may be automatically turned on in order to utilize advanced features from new addons.',
1344
-                            'event_espresso'
1345
-                        ),
1346
-                        '<br />'
1347
-                    ),
1348
-                ]
1349
-            ),
1350
-            'advanced_editor_view' => new EE_Select_Input(
1351
-                [
1352
-                    'list' => esc_html__('List View', 'event_espresso'),
1353
-                    'grid' => esc_html__('Grid View', 'event_espresso'),
1354
-                ],
1355
-                [
1356
-                    'default'         => $this->admin_config->advancedEditorView(),
1357
-                    'html_label_text' => esc_html__('Default Editor View', 'event_espresso'),
1358
-                    'html_help_text'  => sprintf(
1359
-                        esc_html__(
1360
-                            'Controls how the new Advanced Editor displays Event Dates and Available Tickets.%1$s"List View" is a traditional table like view with data organized in rows and columns.%1$s"Grid View" displays the data in stylized blocks with with data organized in logical groupings that make it easier to understand at a glance.',
1361
-                            'event_espresso'
1362
-                        ),
1363
-                        '<br />'
1364
-                    ),
1365
-                ]
1366
-            ),
1367
-            'advanced_editor_per_page' => new EE_Select_Input(
1368
-                [ 2 => 2, 6 => 6, 12 => 12, 24 => 24, 48 => 48 ],
1369
-                [
1370
-                    'default'         => $this->admin_config->advancedEditorPerPage(),
1371
-                    'html_label_text' => esc_html__('Default Items Per Page', 'event_espresso'),
1372
-                    'html_help_text'  => sprintf(
1373
-                        esc_html__(
1374
-                            'The new Advanced Editor has filters that allow you to control the display of Event Dates and Available Tickets and includes pagination for long lists of data.%1$sThis option sets the default number of items to appear in paginated lists.',
1375
-                            'event_espresso'
1376
-                        ),
1377
-                        '<br />'
1378
-                    ),
1379
-                ]
1380
-            ),
1381
-            'defaults_section_header' => new EE_Form_Section_HTML(
1382
-                EEH_HTML::h2(
1383
-                    esc_html__('Default Settings', 'event_espresso'),
1384
-                    '',
1385
-                    'ee-admin-settings-hdr'
1386
-                )
1387
-            ),
1388
-        ] + $default_event_settings_form_subsections;
1389
-    }
1390
-
1391
-
1392
-    /**
1393
-     * @param array     $valid_data
1394
-     * @param EE_Config $config
1395
-     * @since $VID:$
1396
-     */
1397
-    public function updateAdvancedEditorAdminFormSettings(array $valid_data, EE_Config $config)
1398
-    {
1399
-        $config->admin->setUseAdvancedEditor(
1400
-            isset($valid_data['use_advanced_editor'])
1401
-                ? $valid_data['use_advanced_editor']
1402
-                : false
1403
-        );
1404
-        $config->admin->setAdvancedEditorView(
1405
-            isset($valid_data['advanced_editor_view'])
1406
-                ? $valid_data['advanced_editor_view']
1407
-                : 'grid'
1408
-        );
1409
-        $config->admin->setAdvancedEditorPerPage(
1410
-            isset($valid_data['advanced_editor_per_page'])
1411
-                ? $valid_data['advanced_editor_per_page']
1412
-                : 6
1413
-        );
1414
-    }
340
+					}
341
+				}
342
+			);
343
+		}
344
+	}
345
+
346
+
347
+	/**
348
+	 * Returns template for the additional datetime.
349
+	 *
350
+	 * @param $template
351
+	 * @param $template_args
352
+	 * @return mixed
353
+	 * @throws DomainException
354
+	 */
355
+	public function add_additional_datetime_button($template, $template_args)
356
+	{
357
+		return EEH_Template::display_template(
358
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
359
+			$template_args,
360
+			true
361
+		);
362
+	}
363
+
364
+
365
+	/**
366
+	 * Returns the template for cloning a datetime.
367
+	 *
368
+	 * @param $template
369
+	 * @param $template_args
370
+	 * @return mixed
371
+	 * @throws DomainException
372
+	 */
373
+	public function add_datetime_clone_button($template, $template_args)
374
+	{
375
+		return EEH_Template::display_template(
376
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
377
+			$template_args,
378
+			true
379
+		);
380
+	}
381
+
382
+
383
+	/**
384
+	 * Returns the template for datetime timezones.
385
+	 *
386
+	 * @param $template
387
+	 * @param $template_args
388
+	 * @return mixed
389
+	 * @throws DomainException
390
+	 */
391
+	public function datetime_timezones_template($template, $template_args)
392
+	{
393
+		return EEH_Template::display_template(
394
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
395
+			$template_args,
396
+			true
397
+		);
398
+	}
399
+
400
+
401
+	/**
402
+	 * Sets the views for the default list table view.
403
+	 */
404
+	protected function _set_list_table_views_default()
405
+	{
406
+		parent::_set_list_table_views_default();
407
+		$new_views = array(
408
+			'today' => array(
409
+				'slug'        => 'today',
410
+				'label'       => esc_html__('Today', 'event_espresso'),
411
+				'count'       => $this->total_events_today(),
412
+				'bulk_action' => array(
413
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
414
+				),
415
+			),
416
+			'month' => array(
417
+				'slug'        => 'month',
418
+				'label'       => esc_html__('This Month', 'event_espresso'),
419
+				'count'       => $this->total_events_this_month(),
420
+				'bulk_action' => array(
421
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
422
+				),
423
+			),
424
+		);
425
+		$this->_views = array_merge($this->_views, $new_views);
426
+	}
427
+
428
+
429
+	/**
430
+	 * Returns the extra action links for the default list table view.
431
+	 *
432
+	 * @param array     $action_links
433
+	 * @param \EE_Event $event
434
+	 * @return array
435
+	 * @throws EE_Error
436
+	 */
437
+	public function extra_list_table_actions(array $action_links, \EE_Event $event)
438
+	{
439
+		if (EE_Registry::instance()->CAP->current_user_can(
440
+			'ee_read_registrations',
441
+			'espresso_registrations_reports',
442
+			$event->ID()
443
+		)
444
+		) {
445
+			$reports_query_args = array(
446
+				'action' => 'reports',
447
+				'EVT_ID' => $event->ID(),
448
+			);
449
+			$reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
450
+			$action_links[] = '<a href="'
451
+							  . $reports_link
452
+							  . '" title="'
453
+							  . esc_attr__('View Report', 'event_espresso')
454
+							  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
455
+							  . "\n\t";
456
+		}
457
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
458
+			EE_Registry::instance()->load_helper('MSG_Template');
459
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
460
+				'see_notifications_for',
461
+				null,
462
+				array('EVT_ID' => $event->ID())
463
+			);
464
+		}
465
+		return $action_links;
466
+	}
467
+
468
+
469
+	/**
470
+	 * @param $items
471
+	 * @return mixed
472
+	 */
473
+	public function additional_legend_items($items)
474
+	{
475
+		if (EE_Registry::instance()->CAP->current_user_can(
476
+			'ee_read_registrations',
477
+			'espresso_registrations_reports'
478
+		)
479
+		) {
480
+			$items['reports'] = array(
481
+				'class' => 'dashicons dashicons-chart-bar',
482
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
483
+			);
484
+		}
485
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
486
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
487
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
488
+				$items['view_related_messages'] = array(
489
+					'class' => $related_for_icon['css_class'],
490
+					'desc'  => $related_for_icon['label'],
491
+				);
492
+			}
493
+		}
494
+		return $items;
495
+	}
496
+
497
+
498
+	/**
499
+	 * This is the callback method for the duplicate event route
500
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
501
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
502
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
503
+	 * After duplication the redirect is to the new event edit page.
504
+	 *
505
+	 * @return void
506
+	 * @access protected
507
+	 * @throws EE_Error If EE_Event is not available with given ID
508
+	 */
509
+	protected function _duplicate_event()
510
+	{
511
+		// first make sure the ID for the event is in the request.
512
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
513
+		if (! isset($this->_req_data['EVT_ID'])) {
514
+			EE_Error::add_error(
515
+				esc_html__(
516
+					'In order to duplicate an event an Event ID is required.  None was given.',
517
+					'event_espresso'
518
+				),
519
+				__FILE__,
520
+				__FUNCTION__,
521
+				__LINE__
522
+			);
523
+			$this->_redirect_after_action(false, '', '', array(), true);
524
+			return;
525
+		}
526
+		// k we've got EVT_ID so let's use that to get the event we'll duplicate
527
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
528
+		if (! $orig_event instanceof EE_Event) {
529
+			throw new EE_Error(
530
+				sprintf(
531
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
532
+					$this->_req_data['EVT_ID']
533
+				)
534
+			);
535
+		}
536
+		// k now let's clone the $orig_event before getting relations
537
+		$new_event = clone $orig_event;
538
+		// original datetimes
539
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
540
+		// other original relations
541
+		$orig_ven = $orig_event->get_many_related('Venue');
542
+		// reset the ID and modify other details to make it clear this is a dupe
543
+		$new_event->set('EVT_ID', 0);
544
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
545
+		$new_event->set('EVT_name', $new_name);
546
+		$new_event->set(
547
+			'EVT_slug',
548
+			wp_unique_post_slug(
549
+				sanitize_title($orig_event->name()),
550
+				0,
551
+				'publish',
552
+				'espresso_events',
553
+				0
554
+			)
555
+		);
556
+		$new_event->set('status', 'draft');
557
+		// duplicate discussion settings
558
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
559
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
560
+		// save the new event
561
+		$new_event->save();
562
+		// venues
563
+		foreach ($orig_ven as $ven) {
564
+			$new_event->_add_relation_to($ven, 'Venue');
565
+		}
566
+		$new_event->save();
567
+		// now we need to get the question group relations and handle that
568
+		// first primary question groups
569
+		$orig_primary_qgs = $orig_event->get_many_related(
570
+			'Question_Group',
571
+			array(array('Event_Question_Group.EQG_primary' => 1))
572
+		);
573
+		if (! empty($orig_primary_qgs)) {
574
+			foreach ($orig_primary_qgs as $id => $obj) {
575
+				if ($obj instanceof EE_Question_Group) {
576
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
577
+				}
578
+			}
579
+		}
580
+		// next additional attendee question groups
581
+		$orig_additional_qgs = $orig_event->get_many_related(
582
+			'Question_Group',
583
+			array(array('Event_Question_Group.EQG_primary' => 0))
584
+		);
585
+		if (! empty($orig_additional_qgs)) {
586
+			foreach ($orig_additional_qgs as $id => $obj) {
587
+				if ($obj instanceof EE_Question_Group) {
588
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
589
+				}
590
+			}
591
+		}
592
+
593
+		$new_event->save();
594
+
595
+		// k now that we have the new event saved we can loop through the datetimes and start adding relations.
596
+		$cloned_tickets = array();
597
+		foreach ($orig_datetimes as $orig_dtt) {
598
+			if (! $orig_dtt instanceof EE_Datetime) {
599
+				continue;
600
+			}
601
+			$new_dtt = clone $orig_dtt;
602
+			$orig_tkts = $orig_dtt->tickets();
603
+			// save new dtt then add to event
604
+			$new_dtt->set('DTT_ID', 0);
605
+			$new_dtt->set('DTT_sold', 0);
606
+			$new_dtt->set_reserved(0);
607
+			$new_dtt->save();
608
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
609
+			$new_event->save();
610
+			// now let's get the ticket relations setup.
611
+			foreach ((array) $orig_tkts as $orig_tkt) {
612
+				// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
613
+				if (! $orig_tkt instanceof EE_Ticket) {
614
+					continue;
615
+				}
616
+				// is this ticket archived?  If it is then let's skip
617
+				if ($orig_tkt->get('TKT_deleted')) {
618
+					continue;
619
+				}
620
+				// does this original ticket already exist in the clone_tickets cache?
621
+				//  If so we'll just use the new ticket from it.
622
+				if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
623
+					$new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
624
+				} else {
625
+					$new_tkt = clone $orig_tkt;
626
+					// get relations on the $orig_tkt that we need to setup.
627
+					$orig_prices = $orig_tkt->prices();
628
+					$new_tkt->set('TKT_ID', 0);
629
+					$new_tkt->set('TKT_sold', 0);
630
+					$new_tkt->set('TKT_reserved', 0);
631
+					$new_tkt->save(); // make sure new ticket has ID.
632
+					// price relations on new ticket need to be setup.
633
+					foreach ($orig_prices as $orig_price) {
634
+						$new_price = clone $orig_price;
635
+						$new_price->set('PRC_ID', 0);
636
+						$new_price->save();
637
+						$new_tkt->_add_relation_to($new_price, 'Price');
638
+						$new_tkt->save();
639
+					}
640
+
641
+					do_action(
642
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
643
+						$orig_tkt,
644
+						$new_tkt,
645
+						$orig_prices,
646
+						$orig_event,
647
+						$orig_dtt,
648
+						$new_dtt
649
+					);
650
+				}
651
+				// k now we can add the new ticket as a relation to the new datetime
652
+				// and make sure its added to our cached $cloned_tickets array
653
+				// for use with later datetimes that have the same ticket.
654
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
655
+				$new_dtt->save();
656
+				$cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
657
+			}
658
+		}
659
+		// clone taxonomy information
660
+		$taxonomies_to_clone_with = apply_filters(
661
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
662
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
663
+		);
664
+		// get terms for original event (notice)
665
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
666
+		// loop through terms and add them to new event.
667
+		foreach ($orig_terms as $term) {
668
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
669
+		}
670
+
671
+		// duplicate other core WP_Post items for this event.
672
+		// post thumbnail (feature image).
673
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
674
+		if ($feature_image_id) {
675
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
676
+		}
677
+
678
+		// duplicate page_template setting
679
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
680
+		if ($page_template) {
681
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
682
+		}
683
+
684
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
685
+		// now let's redirect to the edit page for this duplicated event if we have a new event id.
686
+		if ($new_event->ID()) {
687
+			$redirect_args = array(
688
+				'post'   => $new_event->ID(),
689
+				'action' => 'edit',
690
+			);
691
+			EE_Error::add_success(
692
+				esc_html__(
693
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
694
+					'event_espresso'
695
+				)
696
+			);
697
+		} else {
698
+			$redirect_args = array(
699
+				'action' => 'default',
700
+			);
701
+			EE_Error::add_error(
702
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
703
+				__FILE__,
704
+				__FUNCTION__,
705
+				__LINE__
706
+			);
707
+		}
708
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
709
+	}
710
+
711
+
712
+	/**
713
+	 * Generates output for the import page.
714
+	 *
715
+	 * @throws DomainException
716
+	 */
717
+	protected function _import_page()
718
+	{
719
+		$title = esc_html__('Import', 'event_espresso');
720
+		$intro = esc_html__(
721
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
722
+			'event_espresso'
723
+		);
724
+		$form_url = EVENTS_ADMIN_URL;
725
+		$action = 'import_events';
726
+		$type = 'csv';
727
+		$this->_template_args['form'] = EE_Import::instance()->upload_form(
728
+			$title,
729
+			$intro,
730
+			$form_url,
731
+			$action,
732
+			$type
733
+		);
734
+		$this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
735
+			array('action' => 'sample_export_file'),
736
+			$this->_admin_base_url
737
+		);
738
+		$content = EEH_Template::display_template(
739
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
740
+			$this->_template_args,
741
+			true
742
+		);
743
+		$this->_template_args['admin_page_content'] = $content;
744
+		$this->display_admin_page_with_sidebar();
745
+	}
746
+
747
+
748
+	/**
749
+	 * _import_events
750
+	 * This handles displaying the screen and running imports for importing events.
751
+	 *
752
+	 * @return void
753
+	 */
754
+	protected function _import_events()
755
+	{
756
+		require_once(EE_CLASSES . 'EE_Import.class.php');
757
+		$success = EE_Import::instance()->import();
758
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
759
+	}
760
+
761
+
762
+	/**
763
+	 * _events_export
764
+	 * Will export all (or just the given event) to a Excel compatible file.
765
+	 *
766
+	 * @access protected
767
+	 * @return void
768
+	 */
769
+	protected function _events_export()
770
+	{
771
+		if (isset($this->_req_data['EVT_ID'])) {
772
+			$event_ids = $this->_req_data['EVT_ID'];
773
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
774
+			$event_ids = $this->_req_data['EVT_IDs'];
775
+		} else {
776
+			$event_ids = null;
777
+		}
778
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
779
+		$new_request_args = array(
780
+			'export' => 'report',
781
+			'action' => 'all_event_data',
782
+			'EVT_ID' => $event_ids,
783
+		);
784
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
785
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
786
+			require_once(EE_CLASSES . 'EE_Export.class.php');
787
+			$EE_Export = EE_Export::instance($this->_req_data);
788
+			$EE_Export->export();
789
+		}
790
+	}
791
+
792
+
793
+	/**
794
+	 * handle category exports()
795
+	 *
796
+	 * @return void
797
+	 */
798
+	protected function _categories_export()
799
+	{
800
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
801
+		$new_request_args = array(
802
+			'export'       => 'report',
803
+			'action'       => 'categories',
804
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
805
+		);
806
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
807
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
808
+			require_once(EE_CLASSES . 'EE_Export.class.php');
809
+			$EE_Export = EE_Export::instance($this->_req_data);
810
+			$EE_Export->export();
811
+		}
812
+	}
813
+
814
+
815
+	/**
816
+	 * Creates a sample CSV file for importing
817
+	 */
818
+	protected function _sample_export_file()
819
+	{
820
+		// require_once(EE_CLASSES . 'EE_Export.class.php');
821
+		EE_Export::instance()->export_sample();
822
+	}
823
+
824
+
825
+	/*************        Template Settings        *************/
826
+	/**
827
+	 * Generates template settings page output
828
+	 *
829
+	 * @throws DomainException
830
+	 * @throws EE_Error
831
+	 */
832
+	protected function _template_settings()
833
+	{
834
+		$this->_template_args['values'] = $this->_yes_no_values;
835
+		/**
836
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
837
+		 * from General_Settings_Admin_Page to here.
838
+		 */
839
+		$this->_template_args = apply_filters(
840
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
841
+			$this->_template_args
842
+		);
843
+		$this->_set_add_edit_form_tags('update_template_settings');
844
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
845
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
846
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
847
+			$this->_template_args,
848
+			true
849
+		);
850
+		$this->display_admin_page_with_sidebar();
851
+	}
852
+
853
+
854
+	/**
855
+	 * Handler for updating template settings.
856
+	 *
857
+	 * @throws InvalidInterfaceException
858
+	 * @throws InvalidDataTypeException
859
+	 * @throws InvalidArgumentException
860
+	 */
861
+	protected function _update_template_settings()
862
+	{
863
+		/**
864
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
865
+		 * from General_Settings_Admin_Page to here.
866
+		 */
867
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
868
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
869
+			EE_Registry::instance()->CFG->template_settings,
870
+			$this->_req_data
871
+		);
872
+		// update custom post type slugs and detect if we need to flush rewrite rules
873
+		$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
874
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
875
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
876
+			: EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
877
+		$what = 'Template Settings';
878
+		$success = $this->_update_espresso_configuration(
879
+			$what,
880
+			EE_Registry::instance()->CFG->template_settings,
881
+			__FILE__,
882
+			__FUNCTION__,
883
+			__LINE__
884
+		);
885
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
886
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
887
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
888
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
889
+			);
890
+			$rewrite_rules->flush();
891
+		}
892
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
893
+	}
894
+
895
+
896
+	/**
897
+	 * _premium_event_editor_meta_boxes
898
+	 * add all metaboxes related to the event_editor
899
+	 *
900
+	 * @access protected
901
+	 * @return void
902
+	 * @throws EE_Error
903
+	 */
904
+	protected function _premium_event_editor_meta_boxes()
905
+	{
906
+		$this->verify_cpt_object();
907
+		add_meta_box(
908
+			'espresso_event_editor_event_options',
909
+			esc_html__('Event Registration Options', 'event_espresso'),
910
+			array($this, 'registration_options_meta_box'),
911
+			$this->page_slug,
912
+			'side',
913
+			'core'
914
+		);
915
+	}
916
+
917
+
918
+	/**
919
+	 * override caf metabox
920
+	 *
921
+	 * @return void
922
+	 * @throws DomainException
923
+	 */
924
+	public function registration_options_meta_box()
925
+	{
926
+		$yes_no_values = array(
927
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
928
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
929
+		);
930
+		$default_reg_status_values = EEM_Registration::reg_status_array(
931
+			array(
932
+				EEM_Registration::status_id_cancelled,
933
+				EEM_Registration::status_id_declined,
934
+				EEM_Registration::status_id_incomplete,
935
+				EEM_Registration::status_id_wait_list,
936
+			),
937
+			true
938
+		);
939
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
940
+		$template_args['_event'] = $this->_cpt_model_obj;
941
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
942
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
943
+			'default_reg_status',
944
+			$default_reg_status_values,
945
+			$this->_cpt_model_obj->default_registration_status()
946
+		);
947
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
948
+			'display_desc',
949
+			$yes_no_values,
950
+			$this->_cpt_model_obj->display_description()
951
+		);
952
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
953
+			'display_ticket_selector',
954
+			$yes_no_values,
955
+			$this->_cpt_model_obj->display_ticket_selector(),
956
+			'',
957
+			'',
958
+			false
959
+		);
960
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
961
+			'EVT_default_registration_status',
962
+			$default_reg_status_values,
963
+			$this->_cpt_model_obj->default_registration_status()
964
+		);
965
+		$template_args['additional_registration_options'] = apply_filters(
966
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
967
+			'',
968
+			$template_args,
969
+			$yes_no_values,
970
+			$default_reg_status_values
971
+		);
972
+		EEH_Template::display_template(
973
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
974
+			$template_args
975
+		);
976
+	}
977
+
978
+
979
+
980
+	/**
981
+	 * wp_list_table_mods for caf
982
+	 * ============================
983
+	 */
984
+	/**
985
+	 * hook into list table filters and provide filters for caffeinated list table
986
+	 *
987
+	 * @param  array $old_filters    any existing filters present
988
+	 * @param  array $list_table_obj the list table object
989
+	 * @return array                  new filters
990
+	 */
991
+	public function list_table_filters($old_filters, $list_table_obj)
992
+	{
993
+		$filters = array();
994
+		// first month/year filters
995
+		$filters[] = $this->espresso_event_months_dropdown();
996
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
997
+		// active status dropdown
998
+		if ($status !== 'draft') {
999
+			$filters[] = $this->active_status_dropdown(
1000
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
1001
+			);
1002
+		}
1003
+		// category filter
1004
+		$filters[] = $this->category_dropdown();
1005
+		return array_merge($old_filters, $filters);
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * espresso_event_months_dropdown
1011
+	 *
1012
+	 * @access public
1013
+	 * @return string                dropdown listing month/year selections for events.
1014
+	 */
1015
+	public function espresso_event_months_dropdown()
1016
+	{
1017
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
1018
+		// Note we need to include any other filters that are set!
1019
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1020
+		// categories?
1021
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1022
+			? $this->_req_data['EVT_CAT']
1023
+			: null;
1024
+		// active status?
1025
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1026
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1027
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1028
+	}
1029
+
1030
+
1031
+	/**
1032
+	 * returns a list of "active" statuses on the event
1033
+	 *
1034
+	 * @param  string $current_value whatever the current active status is
1035
+	 * @return string
1036
+	 */
1037
+	public function active_status_dropdown($current_value = '')
1038
+	{
1039
+		$select_name = 'active_status';
1040
+		$values = array(
1041
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1042
+			'active'   => esc_html__('Active', 'event_espresso'),
1043
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1044
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1045
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1046
+		);
1047
+		$id = 'id="espresso-active-status-dropdown-filter"';
1048
+		$class = 'wide';
1049
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1050
+	}
1051
+
1052
+
1053
+	/**
1054
+	 * output a dropdown of the categories for the category filter on the event admin list table
1055
+	 *
1056
+	 * @access  public
1057
+	 * @return string html
1058
+	 */
1059
+	public function category_dropdown()
1060
+	{
1061
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1062
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1063
+	}
1064
+
1065
+
1066
+	/**
1067
+	 * get total number of events today
1068
+	 *
1069
+	 * @access public
1070
+	 * @return int
1071
+	 * @throws EE_Error
1072
+	 */
1073
+	public function total_events_today()
1074
+	{
1075
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1076
+			'DTT_EVT_start',
1077
+			date('Y-m-d') . ' 00:00:00',
1078
+			'Y-m-d H:i:s',
1079
+			'UTC'
1080
+		);
1081
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1082
+			'DTT_EVT_start',
1083
+			date('Y-m-d') . ' 23:59:59',
1084
+			'Y-m-d H:i:s',
1085
+			'UTC'
1086
+		);
1087
+		$where = array(
1088
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1089
+		);
1090
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1091
+		return $count;
1092
+	}
1093
+
1094
+
1095
+	/**
1096
+	 * get total number of events this month
1097
+	 *
1098
+	 * @access public
1099
+	 * @return int
1100
+	 * @throws EE_Error
1101
+	 */
1102
+	public function total_events_this_month()
1103
+	{
1104
+		// Dates
1105
+		$this_year_r = date('Y');
1106
+		$this_month_r = date('m');
1107
+		$days_this_month = date('t');
1108
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1109
+			'DTT_EVT_start',
1110
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1111
+			'Y-m-d H:i:s',
1112
+			'UTC'
1113
+		);
1114
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1115
+			'DTT_EVT_start',
1116
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1117
+			'Y-m-d H:i:s',
1118
+			'UTC'
1119
+		);
1120
+		$where = array(
1121
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1122
+		);
1123
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1124
+		return $count;
1125
+	}
1126
+
1127
+
1128
+	/** DEFAULT TICKETS STUFF **/
1129
+
1130
+	/**
1131
+	 * Output default tickets list table view.
1132
+	 */
1133
+	public function _tickets_overview_list_table()
1134
+	{
1135
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1136
+		$this->display_admin_list_table_page_with_no_sidebar();
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 * @param int  $per_page
1142
+	 * @param bool $count
1143
+	 * @param bool $trashed
1144
+	 * @return \EE_Soft_Delete_Base_Class[]|int
1145
+	 */
1146
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1147
+	{
1148
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1149
+		$order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1150
+		switch ($orderby) {
1151
+			case 'TKT_name':
1152
+				$orderby = array('TKT_name' => $order);
1153
+				break;
1154
+			case 'TKT_price':
1155
+				$orderby = array('TKT_price' => $order);
1156
+				break;
1157
+			case 'TKT_uses':
1158
+				$orderby = array('TKT_uses' => $order);
1159
+				break;
1160
+			case 'TKT_min':
1161
+				$orderby = array('TKT_min' => $order);
1162
+				break;
1163
+			case 'TKT_max':
1164
+				$orderby = array('TKT_max' => $order);
1165
+				break;
1166
+			case 'TKT_qty':
1167
+				$orderby = array('TKT_qty' => $order);
1168
+				break;
1169
+		}
1170
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1171
+			? $this->_req_data['paged']
1172
+			: 1;
1173
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1174
+			? $this->_req_data['perpage']
1175
+			: $per_page;
1176
+		$_where = array(
1177
+			'TKT_is_default' => 1,
1178
+			'TKT_deleted'    => $trashed,
1179
+		);
1180
+		$offset = ($current_page - 1) * $per_page;
1181
+		$limit = array($offset, $per_page);
1182
+		if (isset($this->_req_data['s'])) {
1183
+			$sstr = '%' . $this->_req_data['s'] . '%';
1184
+			$_where['OR'] = array(
1185
+				'TKT_name'        => array('LIKE', $sstr),
1186
+				'TKT_description' => array('LIKE', $sstr),
1187
+			);
1188
+		}
1189
+		$query_params = array(
1190
+			$_where,
1191
+			'order_by' => $orderby,
1192
+			'limit'    => $limit,
1193
+			'group_by' => 'TKT_ID',
1194
+		);
1195
+		if ($count) {
1196
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1197
+		} else {
1198
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1199
+		}
1200
+	}
1201
+
1202
+
1203
+	/**
1204
+	 * @param bool $trash
1205
+	 * @throws EE_Error
1206
+	 */
1207
+	protected function _trash_or_restore_ticket($trash = false)
1208
+	{
1209
+		$success = 1;
1210
+		$TKT = EEM_Ticket::instance();
1211
+		// checkboxes?
1212
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1213
+			// if array has more than one element then success message should be plural
1214
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1215
+			// cycle thru the boxes
1216
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1217
+				if ($trash) {
1218
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1219
+						$success = 0;
1220
+					}
1221
+				} else {
1222
+					if (! $TKT->restore_by_ID($TKT_ID)) {
1223
+						$success = 0;
1224
+					}
1225
+				}
1226
+			}
1227
+		} else {
1228
+			// grab single id and trash
1229
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1230
+			if ($trash) {
1231
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1232
+					$success = 0;
1233
+				}
1234
+			} else {
1235
+				if (! $TKT->restore_by_ID($TKT_ID)) {
1236
+					$success = 0;
1237
+				}
1238
+			}
1239
+		}
1240
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1241
+		$query_args = array(
1242
+			'action' => 'ticket_list_table',
1243
+			'status' => $trash ? '' : 'trashed',
1244
+		);
1245
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1246
+	}
1247
+
1248
+
1249
+	/**
1250
+	 * Handles trashing default ticket.
1251
+	 */
1252
+	protected function _delete_ticket()
1253
+	{
1254
+		$success = 1;
1255
+		// checkboxes?
1256
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1257
+			// if array has more than one element then success message should be plural
1258
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1259
+			// cycle thru the boxes
1260
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1261
+				// delete
1262
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1263
+					$success = 0;
1264
+				}
1265
+			}
1266
+		} else {
1267
+			// grab single id and trash
1268
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1269
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1270
+				$success = 0;
1271
+			}
1272
+		}
1273
+		$action_desc = 'deleted';
1274
+		$query_args = array(
1275
+			'action' => 'ticket_list_table',
1276
+			'status' => 'trashed',
1277
+		);
1278
+		// fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1279
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1280
+			array(array('TKT_is_default' => 1)),
1281
+			'TKT_ID',
1282
+			true
1283
+		)
1284
+		) {
1285
+			$query_args = array();
1286
+		}
1287
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1288
+	}
1289
+
1290
+
1291
+	/**
1292
+	 * @param int $TKT_ID
1293
+	 * @return bool|int
1294
+	 * @throws EE_Error
1295
+	 */
1296
+	protected function _delete_the_ticket($TKT_ID)
1297
+	{
1298
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1299
+		$tkt->_remove_relations('Datetime');
1300
+		// delete all related prices first
1301
+		$tkt->delete_related_permanently('Price');
1302
+		return $tkt->delete_permanently();
1303
+	}
1304
+
1305
+
1306
+	/**
1307
+	 * @param array $default_event_settings_form_subsections
1308
+	 * @return array
1309
+	 * @since $VID:$
1310
+	 */
1311
+	public function advancedEditorAdminFormSection(array $default_event_settings_form_subsections)
1312
+	{
1313
+		return [
1314
+			'advanced_editor_header' => new EE_Form_Section_HTML(
1315
+				EEH_HTML::div(
1316
+					EEH_HTML::div(
1317
+						EEH_HTML::h2(
1318
+							esc_html__('New Feature', 'event_espresso'),
1319
+							'',
1320
+							'ee-admin-settings-hdr ee-new-flag'
1321
+						),
1322
+						'',
1323
+						'ee-new-flag-wrap'
1324
+					),
1325
+					'',
1326
+					'ee-new-flag-shadow',
1327
+					'margin: -25px 0 10px;'
1328
+				)
1329
+			),
1330
+			'use_advanced_editor'         => new EE_Select_Input(
1331
+				apply_filters(
1332
+					'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_options',
1333
+					[
1334
+						esc_html__('Legacy Editor', 'event_espresso'),
1335
+						esc_html__('Advanced Editor', 'event_espresso'),
1336
+					]
1337
+				),
1338
+				[
1339
+					'default'         => $this->admin_config->useAdvancedEditor(),
1340
+					'html_label_text' => esc_html__('Activate Advanced Editor?', 'event_espresso'),
1341
+					'html_help_text'  => sprintf(
1342
+						esc_html__(
1343
+							'Controls whether the Event Espresso Event Editor continues to use the existing legacy editor that functions like the typical older WordPress admin you are used to,%1$sor uses the new Advanced Editor with a more powerful and easier to use interface. This may be automatically turned on in order to utilize advanced features from new addons.',
1344
+							'event_espresso'
1345
+						),
1346
+						'<br />'
1347
+					),
1348
+				]
1349
+			),
1350
+			'advanced_editor_view' => new EE_Select_Input(
1351
+				[
1352
+					'list' => esc_html__('List View', 'event_espresso'),
1353
+					'grid' => esc_html__('Grid View', 'event_espresso'),
1354
+				],
1355
+				[
1356
+					'default'         => $this->admin_config->advancedEditorView(),
1357
+					'html_label_text' => esc_html__('Default Editor View', 'event_espresso'),
1358
+					'html_help_text'  => sprintf(
1359
+						esc_html__(
1360
+							'Controls how the new Advanced Editor displays Event Dates and Available Tickets.%1$s"List View" is a traditional table like view with data organized in rows and columns.%1$s"Grid View" displays the data in stylized blocks with with data organized in logical groupings that make it easier to understand at a glance.',
1361
+							'event_espresso'
1362
+						),
1363
+						'<br />'
1364
+					),
1365
+				]
1366
+			),
1367
+			'advanced_editor_per_page' => new EE_Select_Input(
1368
+				[ 2 => 2, 6 => 6, 12 => 12, 24 => 24, 48 => 48 ],
1369
+				[
1370
+					'default'         => $this->admin_config->advancedEditorPerPage(),
1371
+					'html_label_text' => esc_html__('Default Items Per Page', 'event_espresso'),
1372
+					'html_help_text'  => sprintf(
1373
+						esc_html__(
1374
+							'The new Advanced Editor has filters that allow you to control the display of Event Dates and Available Tickets and includes pagination for long lists of data.%1$sThis option sets the default number of items to appear in paginated lists.',
1375
+							'event_espresso'
1376
+						),
1377
+						'<br />'
1378
+					),
1379
+				]
1380
+			),
1381
+			'defaults_section_header' => new EE_Form_Section_HTML(
1382
+				EEH_HTML::h2(
1383
+					esc_html__('Default Settings', 'event_espresso'),
1384
+					'',
1385
+					'ee-admin-settings-hdr'
1386
+				)
1387
+			),
1388
+		] + $default_event_settings_form_subsections;
1389
+	}
1390
+
1391
+
1392
+	/**
1393
+	 * @param array     $valid_data
1394
+	 * @param EE_Config $config
1395
+	 * @since $VID:$
1396
+	 */
1397
+	public function updateAdvancedEditorAdminFormSettings(array $valid_data, EE_Config $config)
1398
+	{
1399
+		$config->admin->setUseAdvancedEditor(
1400
+			isset($valid_data['use_advanced_editor'])
1401
+				? $valid_data['use_advanced_editor']
1402
+				: false
1403
+		);
1404
+		$config->admin->setAdvancedEditorView(
1405
+			isset($valid_data['advanced_editor_view'])
1406
+				? $valid_data['advanced_editor_view']
1407
+				: 'grid'
1408
+		);
1409
+		$config->admin->setAdvancedEditorPerPage(
1410
+			isset($valid_data['advanced_editor_per_page'])
1411
+				? $valid_data['advanced_editor_per_page']
1412
+				: 6
1413
+		);
1414
+	}
1415 1415
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
     public function __construct($routing = true)
30 30
     {
31 31
         parent::__construct($routing);
32
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
33
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
34
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
35
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
32
+        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
33
+            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/');
34
+            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/');
35
+            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/');
36 36
         }
37 37
     }
38 38
 
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     protected function _extend_page_config()
44 44
     {
45
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
45
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events';
46 46
         // is there a evt_id in the request?
47 47
         $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
48 48
             ? $this->_req_data['EVT_ID']
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
     {
264 264
         $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
265 265
         // make sure this is only when editing
266
-        if (! empty($id)) {
266
+        if ( ! empty($id)) {
267 267
             $href = EE_Admin_Page::add_query_args_and_nonce(
268 268
                 array('action' => 'duplicate_event', 'EVT_ID' => $id),
269 269
                 $this->_admin_base_url
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
     {
316 316
         wp_register_script(
317 317
             'ee-event-editor-heartbeat',
318
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
318
+            EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js',
319 319
             array('ee_admin_js', 'heartbeat'),
320 320
             EVENT_ESPRESSO_VERSION,
321 321
             true
@@ -328,14 +328,14 @@  discard block
 block discarded – undo
328 328
         if ($this->admin_config->useAdvancedEditor()) {
329 329
             add_action(
330 330
                 'admin_footer',
331
-                function () {
331
+                function() {
332 332
                     $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
333 333
                     if ($eventId) {
334 334
                         $view = $this->admin_config->advancedEditorView();
335 335
                         $perPage = $this->admin_config->advancedEditorPerPage();
336 336
                         echo '
337 337
         <script type="text/javascript">
338
-            /* <![CDATA[ */ var eeEditorEventId = ' . $eventId . '; var eeEditorListView = "' . $view . '"; var eeEditorPerPage = ' . $perPage . '; /* ]]> */
338
+            /* <![CDATA[ */ var eeEditorEventId = ' . $eventId.'; var eeEditorListView = "'.$view.'"; var eeEditorPerPage = '.$perPage.'; /* ]]> */
339 339
         </script>';
340 340
                     }
341 341
                 }
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
     public function add_additional_datetime_button($template, $template_args)
356 356
     {
357 357
         return EEH_Template::display_template(
358
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
358
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php',
359 359
             $template_args,
360 360
             true
361 361
         );
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
     public function add_datetime_clone_button($template, $template_args)
374 374
     {
375 375
         return EEH_Template::display_template(
376
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
376
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php',
377 377
             $template_args,
378 378
             true
379 379
         );
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
     public function datetime_timezones_template($template, $template_args)
392 392
     {
393 393
         return EEH_Template::display_template(
394
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
394
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php',
395 395
             $template_args,
396 396
             true
397 397
         );
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
     {
511 511
         // first make sure the ID for the event is in the request.
512 512
         //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
513
-        if (! isset($this->_req_data['EVT_ID'])) {
513
+        if ( ! isset($this->_req_data['EVT_ID'])) {
514 514
             EE_Error::add_error(
515 515
                 esc_html__(
516 516
                     'In order to duplicate an event an Event ID is required.  None was given.',
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
         }
526 526
         // k we've got EVT_ID so let's use that to get the event we'll duplicate
527 527
         $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
528
-        if (! $orig_event instanceof EE_Event) {
528
+        if ( ! $orig_event instanceof EE_Event) {
529 529
             throw new EE_Error(
530 530
                 sprintf(
531 531
                     esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
         $orig_ven = $orig_event->get_many_related('Venue');
542 542
         // reset the ID and modify other details to make it clear this is a dupe
543 543
         $new_event->set('EVT_ID', 0);
544
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
544
+        $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso');
545 545
         $new_event->set('EVT_name', $new_name);
546 546
         $new_event->set(
547 547
             'EVT_slug',
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
             'Question_Group',
571 571
             array(array('Event_Question_Group.EQG_primary' => 1))
572 572
         );
573
-        if (! empty($orig_primary_qgs)) {
573
+        if ( ! empty($orig_primary_qgs)) {
574 574
             foreach ($orig_primary_qgs as $id => $obj) {
575 575
                 if ($obj instanceof EE_Question_Group) {
576 576
                     $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
             'Question_Group',
583 583
             array(array('Event_Question_Group.EQG_primary' => 0))
584 584
         );
585
-        if (! empty($orig_additional_qgs)) {
585
+        if ( ! empty($orig_additional_qgs)) {
586 586
             foreach ($orig_additional_qgs as $id => $obj) {
587 587
                 if ($obj instanceof EE_Question_Group) {
588 588
                     $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
         // k now that we have the new event saved we can loop through the datetimes and start adding relations.
596 596
         $cloned_tickets = array();
597 597
         foreach ($orig_datetimes as $orig_dtt) {
598
-            if (! $orig_dtt instanceof EE_Datetime) {
598
+            if ( ! $orig_dtt instanceof EE_Datetime) {
599 599
                 continue;
600 600
             }
601 601
             $new_dtt = clone $orig_dtt;
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
             // now let's get the ticket relations setup.
611 611
             foreach ((array) $orig_tkts as $orig_tkt) {
612 612
                 // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
613
-                if (! $orig_tkt instanceof EE_Ticket) {
613
+                if ( ! $orig_tkt instanceof EE_Ticket) {
614 614
                     continue;
615 615
                 }
616 616
                 // is this ticket archived?  If it is then let's skip
@@ -619,8 +619,8 @@  discard block
 block discarded – undo
619 619
                 }
620 620
                 // does this original ticket already exist in the clone_tickets cache?
621 621
                 //  If so we'll just use the new ticket from it.
622
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
623
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
622
+                if (isset($cloned_tickets[$orig_tkt->ID()])) {
623
+                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
624 624
                 } else {
625 625
                     $new_tkt = clone $orig_tkt;
626 626
                     // get relations on the $orig_tkt that we need to setup.
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
                 // for use with later datetimes that have the same ticket.
654 654
                 $new_dtt->_add_relation_to($new_tkt, 'Ticket');
655 655
                 $new_dtt->save();
656
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
656
+                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
657 657
             }
658 658
         }
659 659
         // clone taxonomy information
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
             $this->_admin_base_url
737 737
         );
738 738
         $content = EEH_Template::display_template(
739
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
739
+            EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php',
740 740
             $this->_template_args,
741 741
             true
742 742
         );
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
      */
754 754
     protected function _import_events()
755 755
     {
756
-        require_once(EE_CLASSES . 'EE_Import.class.php');
756
+        require_once(EE_CLASSES.'EE_Import.class.php');
757 757
         $success = EE_Import::instance()->import();
758 758
         $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
759 759
     }
@@ -782,8 +782,8 @@  discard block
 block discarded – undo
782 782
             'EVT_ID' => $event_ids,
783 783
         );
784 784
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
785
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
786
-            require_once(EE_CLASSES . 'EE_Export.class.php');
785
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
786
+            require_once(EE_CLASSES.'EE_Export.class.php');
787 787
             $EE_Export = EE_Export::instance($this->_req_data);
788 788
             $EE_Export->export();
789 789
         }
@@ -804,8 +804,8 @@  discard block
 block discarded – undo
804 804
             'category_ids' => $this->_req_data['EVT_CAT_ID'],
805 805
         );
806 806
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
807
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
808
-            require_once(EE_CLASSES . 'EE_Export.class.php');
807
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
808
+            require_once(EE_CLASSES.'EE_Export.class.php');
809 809
             $EE_Export = EE_Export::instance($this->_req_data);
810 810
             $EE_Export->export();
811 811
         }
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
         $this->_set_add_edit_form_tags('update_template_settings');
844 844
         $this->_set_publish_post_box_vars(null, false, false, null, false);
845 845
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
846
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
846
+            EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php',
847 847
             $this->_template_args,
848 848
             true
849 849
         );
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
             $default_reg_status_values
971 971
         );
972 972
         EEH_Template::display_template(
973
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
973
+            EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php',
974 974
             $template_args
975 975
         );
976 976
     }
@@ -1074,13 +1074,13 @@  discard block
 block discarded – undo
1074 1074
     {
1075 1075
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1076 1076
             'DTT_EVT_start',
1077
-            date('Y-m-d') . ' 00:00:00',
1077
+            date('Y-m-d').' 00:00:00',
1078 1078
             'Y-m-d H:i:s',
1079 1079
             'UTC'
1080 1080
         );
1081 1081
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1082 1082
             'DTT_EVT_start',
1083
-            date('Y-m-d') . ' 23:59:59',
1083
+            date('Y-m-d').' 23:59:59',
1084 1084
             'Y-m-d H:i:s',
1085 1085
             'UTC'
1086 1086
         );
@@ -1107,13 +1107,13 @@  discard block
 block discarded – undo
1107 1107
         $days_this_month = date('t');
1108 1108
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1109 1109
             'DTT_EVT_start',
1110
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1110
+            $this_year_r.'-'.$this_month_r.'-01 00:00:00',
1111 1111
             'Y-m-d H:i:s',
1112 1112
             'UTC'
1113 1113
         );
1114 1114
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1115 1115
             'DTT_EVT_start',
1116
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1116
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59',
1117 1117
             'Y-m-d H:i:s',
1118 1118
             'UTC'
1119 1119
         );
@@ -1180,7 +1180,7 @@  discard block
 block discarded – undo
1180 1180
         $offset = ($current_page - 1) * $per_page;
1181 1181
         $limit = array($offset, $per_page);
1182 1182
         if (isset($this->_req_data['s'])) {
1183
-            $sstr = '%' . $this->_req_data['s'] . '%';
1183
+            $sstr = '%'.$this->_req_data['s'].'%';
1184 1184
             $_where['OR'] = array(
1185 1185
                 'TKT_name'        => array('LIKE', $sstr),
1186 1186
                 'TKT_description' => array('LIKE', $sstr),
@@ -1209,17 +1209,17 @@  discard block
 block discarded – undo
1209 1209
         $success = 1;
1210 1210
         $TKT = EEM_Ticket::instance();
1211 1211
         // checkboxes?
1212
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1212
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1213 1213
             // if array has more than one element then success message should be plural
1214 1214
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1215 1215
             // cycle thru the boxes
1216 1216
             while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1217 1217
                 if ($trash) {
1218
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1218
+                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1219 1219
                         $success = 0;
1220 1220
                     }
1221 1221
                 } else {
1222
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1222
+                    if ( ! $TKT->restore_by_ID($TKT_ID)) {
1223 1223
                         $success = 0;
1224 1224
                     }
1225 1225
                 }
@@ -1228,11 +1228,11 @@  discard block
 block discarded – undo
1228 1228
             // grab single id and trash
1229 1229
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1230 1230
             if ($trash) {
1231
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1231
+                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1232 1232
                     $success = 0;
1233 1233
                 }
1234 1234
             } else {
1235
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1235
+                if ( ! $TKT->restore_by_ID($TKT_ID)) {
1236 1236
                     $success = 0;
1237 1237
                 }
1238 1238
             }
@@ -1253,20 +1253,20 @@  discard block
 block discarded – undo
1253 1253
     {
1254 1254
         $success = 1;
1255 1255
         // checkboxes?
1256
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1256
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1257 1257
             // if array has more than one element then success message should be plural
1258 1258
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1259 1259
             // cycle thru the boxes
1260 1260
             while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1261 1261
                 // delete
1262
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1262
+                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1263 1263
                     $success = 0;
1264 1264
                 }
1265 1265
             }
1266 1266
         } else {
1267 1267
             // grab single id and trash
1268 1268
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1269
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1269
+            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1270 1270
                 $success = 0;
1271 1271
             }
1272 1272
         }
@@ -1365,7 +1365,7 @@  discard block
 block discarded – undo
1365 1365
                 ]
1366 1366
             ),
1367 1367
             'advanced_editor_per_page' => new EE_Select_Input(
1368
-                [ 2 => 2, 6 => 6, 12 => 12, 24 => 24, 48 => 48 ],
1368
+                [2 => 2, 6 => 6, 12 => 12, 24 => 24, 48 => 48],
1369 1369
                 [
1370 1370
                     'default'         => $this->admin_config->advancedEditorPerPage(),
1371 1371
                     'html_label_text' => esc_html__('Default Items Per Page', 'event_espresso'),
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 1 patch
Indentation   +2136 added lines, -2136 removed lines patch added patch discarded remove patch
@@ -15,2196 +15,2196 @@
 block discarded – undo
15 15
 class espresso_events_Pricing_Hooks extends EE_Admin_Hooks
16 16
 {
17 17
 
18
-    /**
19
-     * This property is just used to hold the status of whether an event is currently being
20
-     * created (true) or edited (false)
21
-     *
22
-     * @access protected
23
-     * @var bool
24
-     */
25
-    protected $_is_creating_event;
18
+	/**
19
+	 * This property is just used to hold the status of whether an event is currently being
20
+	 * created (true) or edited (false)
21
+	 *
22
+	 * @access protected
23
+	 * @var bool
24
+	 */
25
+	protected $_is_creating_event;
26 26
 
27
-    /**
28
-     * Used to contain the format strings for date and time that will be used for php date and
29
-     * time.
30
-     * Is set in the _set_hooks_properties() method.
31
-     *
32
-     * @var array
33
-     */
34
-    protected $_date_format_strings;
27
+	/**
28
+	 * Used to contain the format strings for date and time that will be used for php date and
29
+	 * time.
30
+	 * Is set in the _set_hooks_properties() method.
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected $_date_format_strings;
35 35
 
36
-    /**
37
-     * @var string $_date_time_format
38
-     */
39
-    protected $_date_time_format;
36
+	/**
37
+	 * @var string $_date_time_format
38
+	 */
39
+	protected $_date_time_format;
40 40
 
41 41
 
42
-    /**
43
-     * @throws InvalidArgumentException
44
-     * @throws InvalidInterfaceException
45
-     * @throws InvalidDataTypeException
46
-     */
47
-    protected function _set_hooks_properties()
48
-    {
49
-        $this->_name = 'pricing';
50
-        // capability check
51
-        if (EE_Registry::instance()->CFG->admin->useAdvancedEditor() ||
52
-            ! EE_Registry::instance()->CAP->current_user_can(
53
-                'ee_read_default_prices',
54
-                'advanced_ticket_datetime_metabox'
55
-            )
56
-        ) {
57
-            return;
58
-        }
59
-        $this->_setup_metaboxes();
60
-        $this->_set_date_time_formats();
61
-        $this->_validate_format_strings();
62
-        $this->_set_scripts_styles();
63
-        // commented out temporarily until logic is implemented in callback
64
-        // add_action(
65
-        //     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
66
-        //     array($this, 'autosave_handling')
67
-        // );
68
-        add_filter(
69
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
70
-            array($this, 'caf_updates')
71
-        );
72
-    }
42
+	/**
43
+	 * @throws InvalidArgumentException
44
+	 * @throws InvalidInterfaceException
45
+	 * @throws InvalidDataTypeException
46
+	 */
47
+	protected function _set_hooks_properties()
48
+	{
49
+		$this->_name = 'pricing';
50
+		// capability check
51
+		if (EE_Registry::instance()->CFG->admin->useAdvancedEditor() ||
52
+			! EE_Registry::instance()->CAP->current_user_can(
53
+				'ee_read_default_prices',
54
+				'advanced_ticket_datetime_metabox'
55
+			)
56
+		) {
57
+			return;
58
+		}
59
+		$this->_setup_metaboxes();
60
+		$this->_set_date_time_formats();
61
+		$this->_validate_format_strings();
62
+		$this->_set_scripts_styles();
63
+		// commented out temporarily until logic is implemented in callback
64
+		// add_action(
65
+		//     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
66
+		//     array($this, 'autosave_handling')
67
+		// );
68
+		add_filter(
69
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
70
+			array($this, 'caf_updates')
71
+		);
72
+	}
73 73
 
74 74
 
75
-    /**
76
-     * @return void
77
-     */
78
-    protected function _setup_metaboxes()
79
-    {
80
-        // if we were going to add our own metaboxes we'd use the below.
81
-        $this->_metaboxes = array(
82
-            0 => array(
83
-                'page_route' => array('edit', 'create_new'),
84
-                'func'       => 'pricing_metabox',
85
-                'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
86
-                'priority'   => 'high',
87
-                'context'    => 'normal',
88
-            ),
89
-        );
90
-        $this->_remove_metaboxes = array(
91
-            0 => array(
92
-                'page_route' => array('edit', 'create_new'),
93
-                'id'         => 'espresso_event_editor_tickets',
94
-                'context'    => 'normal',
95
-            ),
96
-        );
97
-    }
75
+	/**
76
+	 * @return void
77
+	 */
78
+	protected function _setup_metaboxes()
79
+	{
80
+		// if we were going to add our own metaboxes we'd use the below.
81
+		$this->_metaboxes = array(
82
+			0 => array(
83
+				'page_route' => array('edit', 'create_new'),
84
+				'func'       => 'pricing_metabox',
85
+				'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
86
+				'priority'   => 'high',
87
+				'context'    => 'normal',
88
+			),
89
+		);
90
+		$this->_remove_metaboxes = array(
91
+			0 => array(
92
+				'page_route' => array('edit', 'create_new'),
93
+				'id'         => 'espresso_event_editor_tickets',
94
+				'context'    => 'normal',
95
+			),
96
+		);
97
+	}
98 98
 
99 99
 
100
-    /**
101
-     * @return void
102
-     */
103
-    protected function _set_date_time_formats()
104
-    {
105
-        /**
106
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
107
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
108
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
109
-         *
110
-         * @since 4.6.7
111
-         * @var array  Expected an array returned with 'date' and 'time' keys.
112
-         */
113
-        $this->_date_format_strings = apply_filters(
114
-            'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
115
-            array(
116
-                'date' => 'Y-m-d',
117
-                'time' => 'h:i a',
118
-            )
119
-        );
120
-        // validate
121
-        $this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
122
-            ? $this->_date_format_strings['date']
123
-            : null;
124
-        $this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
125
-            ? $this->_date_format_strings['time']
126
-            : null;
127
-        $this->_date_time_format = $this->_date_format_strings['date']
128
-                                   . ' '
129
-                                   . $this->_date_format_strings['time'];
130
-    }
100
+	/**
101
+	 * @return void
102
+	 */
103
+	protected function _set_date_time_formats()
104
+	{
105
+		/**
106
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
107
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
108
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
109
+		 *
110
+		 * @since 4.6.7
111
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
112
+		 */
113
+		$this->_date_format_strings = apply_filters(
114
+			'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
115
+			array(
116
+				'date' => 'Y-m-d',
117
+				'time' => 'h:i a',
118
+			)
119
+		);
120
+		// validate
121
+		$this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
122
+			? $this->_date_format_strings['date']
123
+			: null;
124
+		$this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
125
+			? $this->_date_format_strings['time']
126
+			: null;
127
+		$this->_date_time_format = $this->_date_format_strings['date']
128
+								   . ' '
129
+								   . $this->_date_format_strings['time'];
130
+	}
131 131
 
132 132
 
133
-    /**
134
-     * @return void
135
-     */
136
-    protected function _validate_format_strings()
137
-    {
138
-        // validate format strings
139
-        $format_validation = EEH_DTT_Helper::validate_format_string(
140
-            $this->_date_time_format
141
-        );
142
-        if (is_array($format_validation)) {
143
-            $msg = '<p>';
144
-            $msg .= sprintf(
145
-                esc_html__(
146
-                    'The format "%s" was likely added via a filter and is invalid for the following reasons:',
147
-                    'event_espresso'
148
-                ),
149
-                $this->_date_time_format
150
-            );
151
-            $msg .= '</p><ul>';
152
-            foreach ($format_validation as $error) {
153
-                $msg .= '<li>' . $error . '</li>';
154
-            }
155
-            $msg .= '</ul><p>';
156
-            $msg .= sprintf(
157
-                esc_html__(
158
-                    '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
159
-                    'event_espresso'
160
-                ),
161
-                '<span style="color:#D54E21;">',
162
-                '</span>'
163
-            );
164
-            $msg .= '</p>';
165
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
166
-            $this->_date_format_strings = array(
167
-                'date' => 'Y-m-d',
168
-                'time' => 'h:i a',
169
-            );
170
-        }
171
-    }
133
+	/**
134
+	 * @return void
135
+	 */
136
+	protected function _validate_format_strings()
137
+	{
138
+		// validate format strings
139
+		$format_validation = EEH_DTT_Helper::validate_format_string(
140
+			$this->_date_time_format
141
+		);
142
+		if (is_array($format_validation)) {
143
+			$msg = '<p>';
144
+			$msg .= sprintf(
145
+				esc_html__(
146
+					'The format "%s" was likely added via a filter and is invalid for the following reasons:',
147
+					'event_espresso'
148
+				),
149
+				$this->_date_time_format
150
+			);
151
+			$msg .= '</p><ul>';
152
+			foreach ($format_validation as $error) {
153
+				$msg .= '<li>' . $error . '</li>';
154
+			}
155
+			$msg .= '</ul><p>';
156
+			$msg .= sprintf(
157
+				esc_html__(
158
+					'%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
159
+					'event_espresso'
160
+				),
161
+				'<span style="color:#D54E21;">',
162
+				'</span>'
163
+			);
164
+			$msg .= '</p>';
165
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
166
+			$this->_date_format_strings = array(
167
+				'date' => 'Y-m-d',
168
+				'time' => 'h:i a',
169
+			);
170
+		}
171
+	}
172 172
 
173 173
 
174
-    /**
175
-     * @return void
176
-     */
177
-    protected function _set_scripts_styles()
178
-    {
179
-        $this->_scripts_styles = array(
180
-            'registers'   => array(
181
-                'ee-tickets-datetimes-css' => array(
182
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
183
-                    'type' => 'css',
184
-                ),
185
-                'ee-dtt-ticket-metabox'    => array(
186
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
187
-                    'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
188
-                ),
189
-            ),
190
-            'deregisters' => array(
191
-                'event-editor-css'       => array('type' => 'css'),
192
-                'event-datetime-metabox' => array('type' => 'js'),
193
-            ),
194
-            'enqueues'    => array(
195
-                'ee-tickets-datetimes-css' => array('edit', 'create_new'),
196
-                'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
197
-            ),
198
-            'localize'    => array(
199
-                'ee-dtt-ticket-metabox' => array(
200
-                    'DTT_TRASH_BLOCK'       => array(
201
-                        'main_warning'            => esc_html__(
202
-                            'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
203
-                            'event_espresso'
204
-                        ),
205
-                        'after_warning'           => esc_html__(
206
-                            'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
207
-                            'event_espresso'
208
-                        ),
209
-                        'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
210
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
211
-                        'close_button'            => '<button class="button-secondary ee-modal-cancel">'
212
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
213
-                        'single_warning_from_tkt' => esc_html__(
214
-                            'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
215
-                            'event_espresso'
216
-                        ),
217
-                        'single_warning_from_dtt' => esc_html__(
218
-                            'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
219
-                            'event_espresso'
220
-                        ),
221
-                        'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
222
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
223
-                    ),
224
-                    'DTT_ERROR_MSG'         => array(
225
-                        'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
226
-                        'dismiss_button' => '<div class="save-cancel-button-container">'
227
-                                            . '<button class="button-secondary ee-modal-cancel">'
228
-                                            . esc_html__('Dismiss', 'event_espresso')
229
-                                            . '</button></div>',
230
-                    ),
231
-                    'DTT_OVERSELL_WARNING'  => array(
232
-                        'datetime_ticket' => esc_html__(
233
-                            'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
234
-                            'event_espresso'
235
-                        ),
236
-                        'ticket_datetime' => esc_html__(
237
-                            'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
238
-                            'event_espresso'
239
-                        ),
240
-                    ),
241
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
242
-                        $this->_date_format_strings['date'],
243
-                        $this->_date_format_strings['time']
244
-                    ),
245
-                    'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
246
-                ),
247
-            ),
248
-        );
249
-    }
174
+	/**
175
+	 * @return void
176
+	 */
177
+	protected function _set_scripts_styles()
178
+	{
179
+		$this->_scripts_styles = array(
180
+			'registers'   => array(
181
+				'ee-tickets-datetimes-css' => array(
182
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
183
+					'type' => 'css',
184
+				),
185
+				'ee-dtt-ticket-metabox'    => array(
186
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
187
+					'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
188
+				),
189
+			),
190
+			'deregisters' => array(
191
+				'event-editor-css'       => array('type' => 'css'),
192
+				'event-datetime-metabox' => array('type' => 'js'),
193
+			),
194
+			'enqueues'    => array(
195
+				'ee-tickets-datetimes-css' => array('edit', 'create_new'),
196
+				'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
197
+			),
198
+			'localize'    => array(
199
+				'ee-dtt-ticket-metabox' => array(
200
+					'DTT_TRASH_BLOCK'       => array(
201
+						'main_warning'            => esc_html__(
202
+							'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
203
+							'event_espresso'
204
+						),
205
+						'after_warning'           => esc_html__(
206
+							'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
207
+							'event_espresso'
208
+						),
209
+						'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
210
+													 . esc_html__('Cancel', 'event_espresso') . '</button>',
211
+						'close_button'            => '<button class="button-secondary ee-modal-cancel">'
212
+													 . esc_html__('Close', 'event_espresso') . '</button>',
213
+						'single_warning_from_tkt' => esc_html__(
214
+							'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
215
+							'event_espresso'
216
+						),
217
+						'single_warning_from_dtt' => esc_html__(
218
+							'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
219
+							'event_espresso'
220
+						),
221
+						'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
222
+													 . esc_html__('Dismiss', 'event_espresso') . '</button>',
223
+					),
224
+					'DTT_ERROR_MSG'         => array(
225
+						'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
226
+						'dismiss_button' => '<div class="save-cancel-button-container">'
227
+											. '<button class="button-secondary ee-modal-cancel">'
228
+											. esc_html__('Dismiss', 'event_espresso')
229
+											. '</button></div>',
230
+					),
231
+					'DTT_OVERSELL_WARNING'  => array(
232
+						'datetime_ticket' => esc_html__(
233
+							'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
234
+							'event_espresso'
235
+						),
236
+						'ticket_datetime' => esc_html__(
237
+							'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
238
+							'event_espresso'
239
+						),
240
+					),
241
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
242
+						$this->_date_format_strings['date'],
243
+						$this->_date_format_strings['time']
244
+					),
245
+					'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
246
+				),
247
+			),
248
+		);
249
+	}
250 250
 
251 251
 
252
-    /**
253
-     * @param array $update_callbacks
254
-     * @return array
255
-     */
256
-    public function caf_updates(array $update_callbacks)
257
-    {
258
-        foreach ($update_callbacks as $key => $callback) {
259
-            if ($callback[1] === '_default_tickets_update') {
260
-                unset($update_callbacks[ $key ]);
261
-            }
262
-        }
263
-        $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
264
-        return $update_callbacks;
265
-    }
252
+	/**
253
+	 * @param array $update_callbacks
254
+	 * @return array
255
+	 */
256
+	public function caf_updates(array $update_callbacks)
257
+	{
258
+		foreach ($update_callbacks as $key => $callback) {
259
+			if ($callback[1] === '_default_tickets_update') {
260
+				unset($update_callbacks[ $key ]);
261
+			}
262
+		}
263
+		$update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
264
+		return $update_callbacks;
265
+	}
266 266
 
267 267
 
268
-    /**
269
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
270
-     *
271
-     * @param  EE_Event $event The Event object we're attaching data to
272
-     * @param  array    $data  The request data from the form
273
-     * @throws ReflectionException
274
-     * @throws Exception
275
-     * @throws InvalidInterfaceException
276
-     * @throws InvalidDataTypeException
277
-     * @throws EE_Error
278
-     * @throws InvalidArgumentException
279
-     */
280
-    public function datetime_and_tickets_caf_update($event, $data)
281
-    {
282
-        // first we need to start with datetimes cause they are the "root" items attached to events.
283
-        $saved_datetimes = $this->_update_datetimes($event, $data);
284
-        // next tackle the tickets (and prices?)
285
-        $this->_update_tickets($event, $saved_datetimes, $data);
286
-    }
268
+	/**
269
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
270
+	 *
271
+	 * @param  EE_Event $event The Event object we're attaching data to
272
+	 * @param  array    $data  The request data from the form
273
+	 * @throws ReflectionException
274
+	 * @throws Exception
275
+	 * @throws InvalidInterfaceException
276
+	 * @throws InvalidDataTypeException
277
+	 * @throws EE_Error
278
+	 * @throws InvalidArgumentException
279
+	 */
280
+	public function datetime_and_tickets_caf_update($event, $data)
281
+	{
282
+		// first we need to start with datetimes cause they are the "root" items attached to events.
283
+		$saved_datetimes = $this->_update_datetimes($event, $data);
284
+		// next tackle the tickets (and prices?)
285
+		$this->_update_tickets($event, $saved_datetimes, $data);
286
+	}
287 287
 
288 288
 
289
-    /**
290
-     * update event_datetimes
291
-     *
292
-     * @param  EE_Event $event Event being updated
293
-     * @param  array    $data  the request data from the form
294
-     * @return EE_Datetime[]
295
-     * @throws Exception
296
-     * @throws ReflectionException
297
-     * @throws InvalidInterfaceException
298
-     * @throws InvalidDataTypeException
299
-     * @throws InvalidArgumentException
300
-     * @throws EE_Error
301
-     */
302
-    protected function _update_datetimes($event, $data)
303
-    {
304
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
305
-        $saved_dtt_ids = array();
306
-        $saved_dtt_objs = array();
307
-        if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
308
-            throw new InvalidArgumentException(
309
-                esc_html__(
310
-                    'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
311
-                    'event_espresso'
312
-                )
313
-            );
314
-        }
315
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
316
-            // trim all values to ensure any excess whitespace is removed.
317
-            $datetime_data = array_map(
318
-                function ($datetime_data) {
319
-                    return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
320
-                },
321
-                $datetime_data
322
-            );
323
-            $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
324
-                                            && ! empty($datetime_data['DTT_EVT_end'])
325
-                ? $datetime_data['DTT_EVT_end']
326
-                : $datetime_data['DTT_EVT_start'];
327
-            $datetime_values = array(
328
-                'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
329
-                    ? $datetime_data['DTT_ID']
330
-                    : null,
331
-                'DTT_name'        => ! empty($datetime_data['DTT_name'])
332
-                    ? $datetime_data['DTT_name']
333
-                    : '',
334
-                'DTT_description' => ! empty($datetime_data['DTT_description'])
335
-                    ? $datetime_data['DTT_description']
336
-                    : '',
337
-                'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
338
-                'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
339
-                'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
340
-                    ? EE_INF
341
-                    : $datetime_data['DTT_reg_limit'],
342
-                'DTT_order'       => ! isset($datetime_data['DTT_order'])
343
-                    ? $row
344
-                    : $datetime_data['DTT_order'],
345
-            );
346
-            // if we have an id then let's get existing object first and then set the new values.
347
-            // Otherwise we instantiate a new object for save.
348
-            if (! empty($datetime_data['DTT_ID'])) {
349
-                $datetime = EE_Registry::instance()
350
-                                       ->load_model('Datetime', array($timezone))
351
-                                       ->get_one_by_ID($datetime_data['DTT_ID']);
352
-                // set date and time format according to what is set in this class.
353
-                $datetime->set_date_format($this->_date_format_strings['date']);
354
-                $datetime->set_time_format($this->_date_format_strings['time']);
355
-                foreach ($datetime_values as $field => $value) {
356
-                    $datetime->set($field, $value);
357
-                }
358
-                // make sure the $dtt_id here is saved just in case
359
-                // after the add_relation_to() the autosave replaces it.
360
-                // We need to do this so we dont' TRASH the parent DTT.
361
-                // (save the ID for both key and value to avoid duplications)
362
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
363
-            } else {
364
-                $datetime = EE_Registry::instance()->load_class(
365
-                    'Datetime',
366
-                    array(
367
-                        $datetime_values,
368
-                        $timezone,
369
-                        array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
370
-                    ),
371
-                    false,
372
-                    false
373
-                );
374
-                foreach ($datetime_values as $field => $value) {
375
-                    $datetime->set($field, $value);
376
-                }
377
-            }
378
-            $datetime->save();
379
-            $datetime = $event->_add_relation_to($datetime, 'Datetime');
380
-            // before going any further make sure our dates are setup correctly
381
-            // so that the end date is always equal or greater than the start date.
382
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
383
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
384
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
385
-                $datetime->save();
386
-            }
387
-            // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
388
-            // because it is possible there was a new one created for the autosave.
389
-            // (save the ID for both key and value to avoid duplications)
390
-            $DTT_ID = $datetime->ID();
391
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
392
-            $saved_dtt_objs[ $row ] = $datetime;
393
-            // @todo if ANY of these updates fail then we want the appropriate global error message.
394
-        }
395
-        $event->save();
396
-        // now we need to REMOVE any datetimes that got deleted.
397
-        // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
398
-        // So its safe to permanently delete at this point.
399
-        $old_datetimes = explode(',', $data['datetime_IDs']);
400
-        $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
401
-        if (is_array($old_datetimes)) {
402
-            $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
403
-            foreach ($datetimes_to_delete as $id) {
404
-                $id = absint($id);
405
-                if (empty($id)) {
406
-                    continue;
407
-                }
408
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
409
-                // remove tkt relationships.
410
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
411
-                foreach ($related_tickets as $tkt) {
412
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
413
-                }
414
-                $event->_remove_relation_to($id, 'Datetime');
415
-                $dtt_to_remove->refresh_cache_of_related_objects();
416
-            }
417
-        }
418
-        return $saved_dtt_objs;
419
-    }
289
+	/**
290
+	 * update event_datetimes
291
+	 *
292
+	 * @param  EE_Event $event Event being updated
293
+	 * @param  array    $data  the request data from the form
294
+	 * @return EE_Datetime[]
295
+	 * @throws Exception
296
+	 * @throws ReflectionException
297
+	 * @throws InvalidInterfaceException
298
+	 * @throws InvalidDataTypeException
299
+	 * @throws InvalidArgumentException
300
+	 * @throws EE_Error
301
+	 */
302
+	protected function _update_datetimes($event, $data)
303
+	{
304
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
305
+		$saved_dtt_ids = array();
306
+		$saved_dtt_objs = array();
307
+		if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
308
+			throw new InvalidArgumentException(
309
+				esc_html__(
310
+					'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
311
+					'event_espresso'
312
+				)
313
+			);
314
+		}
315
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
316
+			// trim all values to ensure any excess whitespace is removed.
317
+			$datetime_data = array_map(
318
+				function ($datetime_data) {
319
+					return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
320
+				},
321
+				$datetime_data
322
+			);
323
+			$datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
324
+											&& ! empty($datetime_data['DTT_EVT_end'])
325
+				? $datetime_data['DTT_EVT_end']
326
+				: $datetime_data['DTT_EVT_start'];
327
+			$datetime_values = array(
328
+				'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
329
+					? $datetime_data['DTT_ID']
330
+					: null,
331
+				'DTT_name'        => ! empty($datetime_data['DTT_name'])
332
+					? $datetime_data['DTT_name']
333
+					: '',
334
+				'DTT_description' => ! empty($datetime_data['DTT_description'])
335
+					? $datetime_data['DTT_description']
336
+					: '',
337
+				'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
338
+				'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
339
+				'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
340
+					? EE_INF
341
+					: $datetime_data['DTT_reg_limit'],
342
+				'DTT_order'       => ! isset($datetime_data['DTT_order'])
343
+					? $row
344
+					: $datetime_data['DTT_order'],
345
+			);
346
+			// if we have an id then let's get existing object first and then set the new values.
347
+			// Otherwise we instantiate a new object for save.
348
+			if (! empty($datetime_data['DTT_ID'])) {
349
+				$datetime = EE_Registry::instance()
350
+									   ->load_model('Datetime', array($timezone))
351
+									   ->get_one_by_ID($datetime_data['DTT_ID']);
352
+				// set date and time format according to what is set in this class.
353
+				$datetime->set_date_format($this->_date_format_strings['date']);
354
+				$datetime->set_time_format($this->_date_format_strings['time']);
355
+				foreach ($datetime_values as $field => $value) {
356
+					$datetime->set($field, $value);
357
+				}
358
+				// make sure the $dtt_id here is saved just in case
359
+				// after the add_relation_to() the autosave replaces it.
360
+				// We need to do this so we dont' TRASH the parent DTT.
361
+				// (save the ID for both key and value to avoid duplications)
362
+				$saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
363
+			} else {
364
+				$datetime = EE_Registry::instance()->load_class(
365
+					'Datetime',
366
+					array(
367
+						$datetime_values,
368
+						$timezone,
369
+						array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
370
+					),
371
+					false,
372
+					false
373
+				);
374
+				foreach ($datetime_values as $field => $value) {
375
+					$datetime->set($field, $value);
376
+				}
377
+			}
378
+			$datetime->save();
379
+			$datetime = $event->_add_relation_to($datetime, 'Datetime');
380
+			// before going any further make sure our dates are setup correctly
381
+			// so that the end date is always equal or greater than the start date.
382
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
383
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
384
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
385
+				$datetime->save();
386
+			}
387
+			// now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
388
+			// because it is possible there was a new one created for the autosave.
389
+			// (save the ID for both key and value to avoid duplications)
390
+			$DTT_ID = $datetime->ID();
391
+			$saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
392
+			$saved_dtt_objs[ $row ] = $datetime;
393
+			// @todo if ANY of these updates fail then we want the appropriate global error message.
394
+		}
395
+		$event->save();
396
+		// now we need to REMOVE any datetimes that got deleted.
397
+		// Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
398
+		// So its safe to permanently delete at this point.
399
+		$old_datetimes = explode(',', $data['datetime_IDs']);
400
+		$old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
401
+		if (is_array($old_datetimes)) {
402
+			$datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
403
+			foreach ($datetimes_to_delete as $id) {
404
+				$id = absint($id);
405
+				if (empty($id)) {
406
+					continue;
407
+				}
408
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
409
+				// remove tkt relationships.
410
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
411
+				foreach ($related_tickets as $tkt) {
412
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
413
+				}
414
+				$event->_remove_relation_to($id, 'Datetime');
415
+				$dtt_to_remove->refresh_cache_of_related_objects();
416
+			}
417
+		}
418
+		return $saved_dtt_objs;
419
+	}
420 420
 
421 421
 
422
-    /**
423
-     * update tickets
424
-     *
425
-     * @param  EE_Event      $event           Event object being updated
426
-     * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
427
-     * @param  array         $data            incoming request data
428
-     * @return EE_Ticket[]
429
-     * @throws Exception
430
-     * @throws ReflectionException
431
-     * @throws InvalidInterfaceException
432
-     * @throws InvalidDataTypeException
433
-     * @throws InvalidArgumentException
434
-     * @throws EE_Error
435
-     */
436
-    protected function _update_tickets($event, $saved_datetimes, $data)
437
-    {
438
-        $new_tkt = null;
439
-        $new_default = null;
440
-        // stripslashes because WP filtered the $_POST ($data) array to add slashes
441
-        $data = stripslashes_deep($data);
442
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
443
-        $saved_tickets = $datetimes_on_existing = array();
444
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
445
-        if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
446
-            throw new InvalidArgumentException(
447
-                esc_html__(
448
-                    'The "edit_tickets" array is invalid therefore the event can not be updated.',
449
-                    'event_espresso'
450
-                )
451
-            );
452
-        }
453
-        foreach ($data['edit_tickets'] as $row => $tkt) {
454
-            $update_prices = $create_new_TKT = false;
455
-            // figure out what datetimes were added to the ticket
456
-            // and what datetimes were removed from the ticket in the session.
457
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
458
-            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
459
-            $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
460
-            $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
461
-            // trim inputs to ensure any excess whitespace is removed.
462
-            $tkt = array_map(
463
-                function ($ticket_data) {
464
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
465
-                },
466
-                $tkt
467
-            );
468
-            // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
469
-            // because we're doing calculations prior to using the models.
470
-            // note incoming ['TKT_price'] value is already in standard notation (via js).
471
-            $ticket_price = isset($tkt['TKT_price'])
472
-                ? round((float) $tkt['TKT_price'], 3)
473
-                : 0;
474
-            // note incoming base price needs converted from localized value.
475
-            $base_price = isset($tkt['TKT_base_price'])
476
-                ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
477
-                : 0;
478
-            // if ticket price == 0 and $base_price != 0 then ticket price == base_price
479
-            $ticket_price = $ticket_price === 0 && $base_price !== 0
480
-                ? $base_price
481
-                : $ticket_price;
482
-            $base_price_id = isset($tkt['TKT_base_price_ID'])
483
-                ? $tkt['TKT_base_price_ID']
484
-                : 0;
485
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
486
-                ? $data['edit_prices'][ $row ]
487
-                : array();
488
-            $now = null;
489
-            if (empty($tkt['TKT_start_date'])) {
490
-                // lets' use now in the set timezone.
491
-                $now = new DateTime('now', new DateTimeZone($event->get_timezone()));
492
-                $tkt['TKT_start_date'] = $now->format($this->_date_time_format);
493
-            }
494
-            if (empty($tkt['TKT_end_date'])) {
495
-                /**
496
-                 * set the TKT_end_date to the first datetime attached to the ticket.
497
-                 */
498
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
499
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
500
-            }
501
-            $TKT_values = array(
502
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
503
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
504
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
505
-                'TKT_description' => ! empty($tkt['TKT_description'])
506
-                                     && $tkt['TKT_description'] !== esc_html__(
507
-                                         'You can modify this description',
508
-                                         'event_espresso'
509
-                                     )
510
-                    ? $tkt['TKT_description']
511
-                    : '',
512
-                'TKT_start_date'  => $tkt['TKT_start_date'],
513
-                'TKT_end_date'    => $tkt['TKT_end_date'],
514
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
515
-                    ? EE_INF
516
-                    : $tkt['TKT_qty'],
517
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
518
-                    ? EE_INF
519
-                    : $tkt['TKT_uses'],
520
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
521
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
522
-                'TKT_row'         => $row,
523
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
524
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
525
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
526
-                'TKT_price'       => $ticket_price,
527
-            );
528
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
529
-            // which means in turn that the prices will become new prices as well.
530
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
531
-                $TKT_values['TKT_ID'] = 0;
532
-                $TKT_values['TKT_is_default'] = 0;
533
-                $update_prices = true;
534
-            }
535
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
536
-            // we actually do our saves ahead of doing any add_relations to
537
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
538
-            // but DID have it's items modified.
539
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
540
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
541
-            if (absint($TKT_values['TKT_ID'])) {
542
-                $ticket = EE_Registry::instance()
543
-                                     ->load_model('Ticket', array($timezone))
544
-                                     ->get_one_by_ID($tkt['TKT_ID']);
545
-                if ($ticket instanceof EE_Ticket) {
546
-                    $ticket = $this->_update_ticket_datetimes(
547
-                        $ticket,
548
-                        $saved_datetimes,
549
-                        $datetimes_added,
550
-                        $datetimes_removed
551
-                    );
552
-                    // are there any registrations using this ticket ?
553
-                    $tickets_sold = $ticket->count_related(
554
-                        'Registration',
555
-                        array(
556
-                            array(
557
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
558
-                            ),
559
-                        )
560
-                    );
561
-                    // set ticket formats
562
-                    $ticket->set_date_format($this->_date_format_strings['date']);
563
-                    $ticket->set_time_format($this->_date_format_strings['time']);
564
-                    // let's just check the total price for the existing ticket
565
-                    // and determine if it matches the new total price.
566
-                    // if they are different then we create a new ticket (if tickets sold)
567
-                    // if they aren't different then we go ahead and modify existing ticket.
568
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
569
-                    // set new values
570
-                    foreach ($TKT_values as $field => $value) {
571
-                        if ($field === 'TKT_qty') {
572
-                            $ticket->set_qty($value);
573
-                        } else {
574
-                            $ticket->set($field, $value);
575
-                        }
576
-                    }
577
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
578
-                    // Otherwise we have to create a new ticket.
579
-                    if ($create_new_TKT) {
580
-                        $new_tkt = $this->_duplicate_ticket(
581
-                            $ticket,
582
-                            $price_rows,
583
-                            $ticket_price,
584
-                            $base_price,
585
-                            $base_price_id
586
-                        );
587
-                    }
588
-                }
589
-            } else {
590
-                // no TKT_id so a new TKT
591
-                $ticket = EE_Ticket::new_instance(
592
-                    $TKT_values,
593
-                    $timezone,
594
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
595
-                );
596
-                if ($ticket instanceof EE_Ticket) {
597
-                    // make sure ticket has an ID of setting relations won't work
598
-                    $ticket->save();
599
-                    $ticket = $this->_update_ticket_datetimes(
600
-                        $ticket,
601
-                        $saved_datetimes,
602
-                        $datetimes_added,
603
-                        $datetimes_removed
604
-                    );
605
-                    $update_prices = true;
606
-                }
607
-            }
608
-            // make sure any current values have been saved.
609
-            // $ticket->save();
610
-            // before going any further make sure our dates are setup correctly
611
-            // so that the end date is always equal or greater than the start date.
612
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
613
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
614
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
615
-            }
616
-            // let's make sure the base price is handled
617
-            $ticket = ! $create_new_TKT
618
-                ? $this->_add_prices_to_ticket(
619
-                    array(),
620
-                    $ticket,
621
-                    $update_prices,
622
-                    $base_price,
623
-                    $base_price_id
624
-                )
625
-                : $ticket;
626
-            // add/update price_modifiers
627
-            $ticket = ! $create_new_TKT
628
-                ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
629
-                : $ticket;
630
-            // need to make sue that the TKT_price is accurate after saving the prices.
631
-            $ticket->ensure_TKT_Price_correct();
632
-            // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
633
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
634
-                $update_prices = true;
635
-                $new_default = clone $ticket;
636
-                $new_default->set('TKT_ID', 0);
637
-                $new_default->set('TKT_is_default', 1);
638
-                $new_default->set('TKT_row', 1);
639
-                $new_default->set('TKT_price', $ticket_price);
640
-                // remove any dtt relations cause we DON'T want dtt relations attached
641
-                // (note this is just removing the cached relations in the object)
642
-                $new_default->_remove_relations('Datetime');
643
-                // @todo we need to add the current attached prices as new prices to the new default ticket.
644
-                $new_default = $this->_add_prices_to_ticket(
645
-                    $price_rows,
646
-                    $new_default,
647
-                    $update_prices
648
-                );
649
-                // don't forget the base price!
650
-                $new_default = $this->_add_prices_to_ticket(
651
-                    array(),
652
-                    $new_default,
653
-                    $update_prices,
654
-                    $base_price,
655
-                    $base_price_id
656
-                );
657
-                $new_default->save();
658
-                do_action(
659
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
660
-                    $new_default,
661
-                    $row,
662
-                    $ticket,
663
-                    $data
664
-                );
665
-            }
666
-            // DO ALL dtt relationships for both current tickets and any archived tickets
667
-            // for the given dtt that are related to the current ticket.
668
-            // TODO... not sure exactly how we're going to do this considering we don't know
669
-            // what current ticket the archived tickets are related to
670
-            // (and TKT_parent is used for autosaves so that's not a field we can reliably use).
671
-            // let's assign any tickets that have been setup to the saved_tickets tracker
672
-            // save existing TKT
673
-            $ticket->save();
674
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
675
-                // save new TKT
676
-                $new_tkt->save();
677
-                // add new ticket to array
678
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
679
-                do_action(
680
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
681
-                    $new_tkt,
682
-                    $row,
683
-                    $tkt,
684
-                    $data
685
-                );
686
-            } else {
687
-                // add tkt to saved tkts
688
-                $saved_tickets[ $ticket->ID() ] = $ticket;
689
-                do_action(
690
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
691
-                    $ticket,
692
-                    $row,
693
-                    $tkt,
694
-                    $data
695
-                );
696
-            }
697
-        }
698
-        // now we need to handle tickets actually "deleted permanently".
699
-        // There are cases where we'd want this to happen
700
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
701
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
702
-        // No sense in keeping all the related data in the db!
703
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
704
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
705
-        foreach ($tickets_removed as $id) {
706
-            $id = absint($id);
707
-            // get the ticket for this id
708
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
709
-            // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
710
-            if ($tkt_to_remove->get('TKT_is_default')) {
711
-                continue;
712
-            }
713
-            // if this tkt has any registrations attached so then we just ARCHIVE
714
-            // because we don't actually permanently delete these tickets.
715
-            if ($tkt_to_remove->count_related('Registration') > 0) {
716
-                $tkt_to_remove->delete();
717
-                continue;
718
-            }
719
-            // need to get all the related datetimes on this ticket and remove from every single one of them
720
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
721
-            $datetimes = $tkt_to_remove->get_many_related('Datetime');
722
-            foreach ($datetimes as $datetime) {
723
-                $tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
724
-            }
725
-            // need to do the same for prices (except these prices can also be deleted because again,
726
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
727
-            $tkt_to_remove->delete_related_permanently('Price');
728
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
729
-            // finally let's delete this ticket
730
-            // (which should not be blocked at this point b/c we've removed all our relationships)
731
-            $tkt_to_remove->delete_permanently();
732
-        }
733
-        return $saved_tickets;
734
-    }
422
+	/**
423
+	 * update tickets
424
+	 *
425
+	 * @param  EE_Event      $event           Event object being updated
426
+	 * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
427
+	 * @param  array         $data            incoming request data
428
+	 * @return EE_Ticket[]
429
+	 * @throws Exception
430
+	 * @throws ReflectionException
431
+	 * @throws InvalidInterfaceException
432
+	 * @throws InvalidDataTypeException
433
+	 * @throws InvalidArgumentException
434
+	 * @throws EE_Error
435
+	 */
436
+	protected function _update_tickets($event, $saved_datetimes, $data)
437
+	{
438
+		$new_tkt = null;
439
+		$new_default = null;
440
+		// stripslashes because WP filtered the $_POST ($data) array to add slashes
441
+		$data = stripslashes_deep($data);
442
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
443
+		$saved_tickets = $datetimes_on_existing = array();
444
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
445
+		if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
446
+			throw new InvalidArgumentException(
447
+				esc_html__(
448
+					'The "edit_tickets" array is invalid therefore the event can not be updated.',
449
+					'event_espresso'
450
+				)
451
+			);
452
+		}
453
+		foreach ($data['edit_tickets'] as $row => $tkt) {
454
+			$update_prices = $create_new_TKT = false;
455
+			// figure out what datetimes were added to the ticket
456
+			// and what datetimes were removed from the ticket in the session.
457
+			$starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
458
+			$tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
459
+			$datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
460
+			$datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
461
+			// trim inputs to ensure any excess whitespace is removed.
462
+			$tkt = array_map(
463
+				function ($ticket_data) {
464
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
465
+				},
466
+				$tkt
467
+			);
468
+			// note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
469
+			// because we're doing calculations prior to using the models.
470
+			// note incoming ['TKT_price'] value is already in standard notation (via js).
471
+			$ticket_price = isset($tkt['TKT_price'])
472
+				? round((float) $tkt['TKT_price'], 3)
473
+				: 0;
474
+			// note incoming base price needs converted from localized value.
475
+			$base_price = isset($tkt['TKT_base_price'])
476
+				? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
477
+				: 0;
478
+			// if ticket price == 0 and $base_price != 0 then ticket price == base_price
479
+			$ticket_price = $ticket_price === 0 && $base_price !== 0
480
+				? $base_price
481
+				: $ticket_price;
482
+			$base_price_id = isset($tkt['TKT_base_price_ID'])
483
+				? $tkt['TKT_base_price_ID']
484
+				: 0;
485
+			$price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
486
+				? $data['edit_prices'][ $row ]
487
+				: array();
488
+			$now = null;
489
+			if (empty($tkt['TKT_start_date'])) {
490
+				// lets' use now in the set timezone.
491
+				$now = new DateTime('now', new DateTimeZone($event->get_timezone()));
492
+				$tkt['TKT_start_date'] = $now->format($this->_date_time_format);
493
+			}
494
+			if (empty($tkt['TKT_end_date'])) {
495
+				/**
496
+				 * set the TKT_end_date to the first datetime attached to the ticket.
497
+				 */
498
+				$first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
499
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
500
+			}
501
+			$TKT_values = array(
502
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
503
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
504
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
505
+				'TKT_description' => ! empty($tkt['TKT_description'])
506
+									 && $tkt['TKT_description'] !== esc_html__(
507
+										 'You can modify this description',
508
+										 'event_espresso'
509
+									 )
510
+					? $tkt['TKT_description']
511
+					: '',
512
+				'TKT_start_date'  => $tkt['TKT_start_date'],
513
+				'TKT_end_date'    => $tkt['TKT_end_date'],
514
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
515
+					? EE_INF
516
+					: $tkt['TKT_qty'],
517
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
518
+					? EE_INF
519
+					: $tkt['TKT_uses'],
520
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
521
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
522
+				'TKT_row'         => $row,
523
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
524
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
525
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
526
+				'TKT_price'       => $ticket_price,
527
+			);
528
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
529
+			// which means in turn that the prices will become new prices as well.
530
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
531
+				$TKT_values['TKT_ID'] = 0;
532
+				$TKT_values['TKT_is_default'] = 0;
533
+				$update_prices = true;
534
+			}
535
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
536
+			// we actually do our saves ahead of doing any add_relations to
537
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
538
+			// but DID have it's items modified.
539
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
540
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
541
+			if (absint($TKT_values['TKT_ID'])) {
542
+				$ticket = EE_Registry::instance()
543
+									 ->load_model('Ticket', array($timezone))
544
+									 ->get_one_by_ID($tkt['TKT_ID']);
545
+				if ($ticket instanceof EE_Ticket) {
546
+					$ticket = $this->_update_ticket_datetimes(
547
+						$ticket,
548
+						$saved_datetimes,
549
+						$datetimes_added,
550
+						$datetimes_removed
551
+					);
552
+					// are there any registrations using this ticket ?
553
+					$tickets_sold = $ticket->count_related(
554
+						'Registration',
555
+						array(
556
+							array(
557
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
558
+							),
559
+						)
560
+					);
561
+					// set ticket formats
562
+					$ticket->set_date_format($this->_date_format_strings['date']);
563
+					$ticket->set_time_format($this->_date_format_strings['time']);
564
+					// let's just check the total price for the existing ticket
565
+					// and determine if it matches the new total price.
566
+					// if they are different then we create a new ticket (if tickets sold)
567
+					// if they aren't different then we go ahead and modify existing ticket.
568
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
569
+					// set new values
570
+					foreach ($TKT_values as $field => $value) {
571
+						if ($field === 'TKT_qty') {
572
+							$ticket->set_qty($value);
573
+						} else {
574
+							$ticket->set($field, $value);
575
+						}
576
+					}
577
+					// if $create_new_TKT is false then we can safely update the existing ticket.
578
+					// Otherwise we have to create a new ticket.
579
+					if ($create_new_TKT) {
580
+						$new_tkt = $this->_duplicate_ticket(
581
+							$ticket,
582
+							$price_rows,
583
+							$ticket_price,
584
+							$base_price,
585
+							$base_price_id
586
+						);
587
+					}
588
+				}
589
+			} else {
590
+				// no TKT_id so a new TKT
591
+				$ticket = EE_Ticket::new_instance(
592
+					$TKT_values,
593
+					$timezone,
594
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
595
+				);
596
+				if ($ticket instanceof EE_Ticket) {
597
+					// make sure ticket has an ID of setting relations won't work
598
+					$ticket->save();
599
+					$ticket = $this->_update_ticket_datetimes(
600
+						$ticket,
601
+						$saved_datetimes,
602
+						$datetimes_added,
603
+						$datetimes_removed
604
+					);
605
+					$update_prices = true;
606
+				}
607
+			}
608
+			// make sure any current values have been saved.
609
+			// $ticket->save();
610
+			// before going any further make sure our dates are setup correctly
611
+			// so that the end date is always equal or greater than the start date.
612
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
613
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
614
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
615
+			}
616
+			// let's make sure the base price is handled
617
+			$ticket = ! $create_new_TKT
618
+				? $this->_add_prices_to_ticket(
619
+					array(),
620
+					$ticket,
621
+					$update_prices,
622
+					$base_price,
623
+					$base_price_id
624
+				)
625
+				: $ticket;
626
+			// add/update price_modifiers
627
+			$ticket = ! $create_new_TKT
628
+				? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
629
+				: $ticket;
630
+			// need to make sue that the TKT_price is accurate after saving the prices.
631
+			$ticket->ensure_TKT_Price_correct();
632
+			// handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
633
+			if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
634
+				$update_prices = true;
635
+				$new_default = clone $ticket;
636
+				$new_default->set('TKT_ID', 0);
637
+				$new_default->set('TKT_is_default', 1);
638
+				$new_default->set('TKT_row', 1);
639
+				$new_default->set('TKT_price', $ticket_price);
640
+				// remove any dtt relations cause we DON'T want dtt relations attached
641
+				// (note this is just removing the cached relations in the object)
642
+				$new_default->_remove_relations('Datetime');
643
+				// @todo we need to add the current attached prices as new prices to the new default ticket.
644
+				$new_default = $this->_add_prices_to_ticket(
645
+					$price_rows,
646
+					$new_default,
647
+					$update_prices
648
+				);
649
+				// don't forget the base price!
650
+				$new_default = $this->_add_prices_to_ticket(
651
+					array(),
652
+					$new_default,
653
+					$update_prices,
654
+					$base_price,
655
+					$base_price_id
656
+				);
657
+				$new_default->save();
658
+				do_action(
659
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
660
+					$new_default,
661
+					$row,
662
+					$ticket,
663
+					$data
664
+				);
665
+			}
666
+			// DO ALL dtt relationships for both current tickets and any archived tickets
667
+			// for the given dtt that are related to the current ticket.
668
+			// TODO... not sure exactly how we're going to do this considering we don't know
669
+			// what current ticket the archived tickets are related to
670
+			// (and TKT_parent is used for autosaves so that's not a field we can reliably use).
671
+			// let's assign any tickets that have been setup to the saved_tickets tracker
672
+			// save existing TKT
673
+			$ticket->save();
674
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
675
+				// save new TKT
676
+				$new_tkt->save();
677
+				// add new ticket to array
678
+				$saved_tickets[ $new_tkt->ID() ] = $new_tkt;
679
+				do_action(
680
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
681
+					$new_tkt,
682
+					$row,
683
+					$tkt,
684
+					$data
685
+				);
686
+			} else {
687
+				// add tkt to saved tkts
688
+				$saved_tickets[ $ticket->ID() ] = $ticket;
689
+				do_action(
690
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
691
+					$ticket,
692
+					$row,
693
+					$tkt,
694
+					$data
695
+				);
696
+			}
697
+		}
698
+		// now we need to handle tickets actually "deleted permanently".
699
+		// There are cases where we'd want this to happen
700
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
701
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
702
+		// No sense in keeping all the related data in the db!
703
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
704
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
705
+		foreach ($tickets_removed as $id) {
706
+			$id = absint($id);
707
+			// get the ticket for this id
708
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
709
+			// if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
710
+			if ($tkt_to_remove->get('TKT_is_default')) {
711
+				continue;
712
+			}
713
+			// if this tkt has any registrations attached so then we just ARCHIVE
714
+			// because we don't actually permanently delete these tickets.
715
+			if ($tkt_to_remove->count_related('Registration') > 0) {
716
+				$tkt_to_remove->delete();
717
+				continue;
718
+			}
719
+			// need to get all the related datetimes on this ticket and remove from every single one of them
720
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
721
+			$datetimes = $tkt_to_remove->get_many_related('Datetime');
722
+			foreach ($datetimes as $datetime) {
723
+				$tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
724
+			}
725
+			// need to do the same for prices (except these prices can also be deleted because again,
726
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
727
+			$tkt_to_remove->delete_related_permanently('Price');
728
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
729
+			// finally let's delete this ticket
730
+			// (which should not be blocked at this point b/c we've removed all our relationships)
731
+			$tkt_to_remove->delete_permanently();
732
+		}
733
+		return $saved_tickets;
734
+	}
735 735
 
736 736
 
737
-    /**
738
-     * @access  protected
739
-     * @param EE_Ticket      $ticket
740
-     * @param \EE_Datetime[] $saved_datetimes
741
-     * @param \EE_Datetime[] $added_datetimes
742
-     * @param \EE_Datetime[] $removed_datetimes
743
-     * @return EE_Ticket
744
-     * @throws EE_Error
745
-     */
746
-    protected function _update_ticket_datetimes(
747
-        EE_Ticket $ticket,
748
-        $saved_datetimes = array(),
749
-        $added_datetimes = array(),
750
-        $removed_datetimes = array()
751
-    ) {
752
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
753
-        // and removing the ticket from datetimes it got removed from.
754
-        // first let's add datetimes
755
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
756
-            foreach ($added_datetimes as $row_id) {
757
-                $row_id = (int) $row_id;
758
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
759
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
760
-                    // Is this an existing ticket (has an ID) and does it have any sold?
761
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
762
-                    if ($ticket->ID() && $ticket->sold() > 0) {
763
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
764
-                    }
765
-                }
766
-            }
767
-        }
768
-        // then remove datetimes
769
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
770
-            foreach ($removed_datetimes as $row_id) {
771
-                $row_id = (int) $row_id;
772
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
773
-                // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
774
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
775
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
776
-                    // Is this an existing ticket (has an ID) and does it have any sold?
777
-                    // If so, then we need to remove it's sold from the DTT_sold.
778
-                    if ($ticket->ID() && $ticket->sold() > 0) {
779
-                        $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
780
-                    }
781
-                }
782
-            }
783
-        }
784
-        // cap ticket qty by datetime reg limits
785
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
786
-        return $ticket;
787
-    }
737
+	/**
738
+	 * @access  protected
739
+	 * @param EE_Ticket      $ticket
740
+	 * @param \EE_Datetime[] $saved_datetimes
741
+	 * @param \EE_Datetime[] $added_datetimes
742
+	 * @param \EE_Datetime[] $removed_datetimes
743
+	 * @return EE_Ticket
744
+	 * @throws EE_Error
745
+	 */
746
+	protected function _update_ticket_datetimes(
747
+		EE_Ticket $ticket,
748
+		$saved_datetimes = array(),
749
+		$added_datetimes = array(),
750
+		$removed_datetimes = array()
751
+	) {
752
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
753
+		// and removing the ticket from datetimes it got removed from.
754
+		// first let's add datetimes
755
+		if (! empty($added_datetimes) && is_array($added_datetimes)) {
756
+			foreach ($added_datetimes as $row_id) {
757
+				$row_id = (int) $row_id;
758
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
759
+					$ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
760
+					// Is this an existing ticket (has an ID) and does it have any sold?
761
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
762
+					if ($ticket->ID() && $ticket->sold() > 0) {
763
+						$saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
764
+					}
765
+				}
766
+			}
767
+		}
768
+		// then remove datetimes
769
+		if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
770
+			foreach ($removed_datetimes as $row_id) {
771
+				$row_id = (int) $row_id;
772
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
773
+				// So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
774
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
775
+					$ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
776
+					// Is this an existing ticket (has an ID) and does it have any sold?
777
+					// If so, then we need to remove it's sold from the DTT_sold.
778
+					if ($ticket->ID() && $ticket->sold() > 0) {
779
+						$saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
780
+					}
781
+				}
782
+			}
783
+		}
784
+		// cap ticket qty by datetime reg limits
785
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
786
+		return $ticket;
787
+	}
788 788
 
789 789
 
790
-    /**
791
-     * @access  protected
792
-     * @param EE_Ticket $ticket
793
-     * @param array     $price_rows
794
-     * @param int       $ticket_price
795
-     * @param int       $base_price
796
-     * @param int       $base_price_id
797
-     * @return EE_Ticket
798
-     * @throws ReflectionException
799
-     * @throws InvalidArgumentException
800
-     * @throws InvalidInterfaceException
801
-     * @throws InvalidDataTypeException
802
-     * @throws EE_Error
803
-     */
804
-    protected function _duplicate_ticket(
805
-        EE_Ticket $ticket,
806
-        $price_rows = array(),
807
-        $ticket_price = 0,
808
-        $base_price = 0,
809
-        $base_price_id = 0
810
-    ) {
811
-        // create new ticket that's a copy of the existing
812
-        // except a new id of course (and not archived)
813
-        // AND has the new TKT_price associated with it.
814
-        $new_ticket = clone $ticket;
815
-        $new_ticket->set('TKT_ID', 0);
816
-        $new_ticket->set_deleted(0);
817
-        $new_ticket->set_price($ticket_price);
818
-        $new_ticket->set_sold(0);
819
-        // let's get a new ID for this ticket
820
-        $new_ticket->save();
821
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
822
-        $datetimes_on_existing = $ticket->datetimes();
823
-        $new_ticket = $this->_update_ticket_datetimes(
824
-            $new_ticket,
825
-            $datetimes_on_existing,
826
-            array_keys($datetimes_on_existing)
827
-        );
828
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
829
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
830
-        // available.
831
-        if ($ticket->sold() > 0) {
832
-            $new_qty = $ticket->qty() - $ticket->sold();
833
-            $new_ticket->set_qty($new_qty);
834
-        }
835
-        // now we update the prices just for this ticket
836
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
837
-        // and we update the base price
838
-        $new_ticket = $this->_add_prices_to_ticket(
839
-            array(),
840
-            $new_ticket,
841
-            true,
842
-            $base_price,
843
-            $base_price_id
844
-        );
845
-        return $new_ticket;
846
-    }
790
+	/**
791
+	 * @access  protected
792
+	 * @param EE_Ticket $ticket
793
+	 * @param array     $price_rows
794
+	 * @param int       $ticket_price
795
+	 * @param int       $base_price
796
+	 * @param int       $base_price_id
797
+	 * @return EE_Ticket
798
+	 * @throws ReflectionException
799
+	 * @throws InvalidArgumentException
800
+	 * @throws InvalidInterfaceException
801
+	 * @throws InvalidDataTypeException
802
+	 * @throws EE_Error
803
+	 */
804
+	protected function _duplicate_ticket(
805
+		EE_Ticket $ticket,
806
+		$price_rows = array(),
807
+		$ticket_price = 0,
808
+		$base_price = 0,
809
+		$base_price_id = 0
810
+	) {
811
+		// create new ticket that's a copy of the existing
812
+		// except a new id of course (and not archived)
813
+		// AND has the new TKT_price associated with it.
814
+		$new_ticket = clone $ticket;
815
+		$new_ticket->set('TKT_ID', 0);
816
+		$new_ticket->set_deleted(0);
817
+		$new_ticket->set_price($ticket_price);
818
+		$new_ticket->set_sold(0);
819
+		// let's get a new ID for this ticket
820
+		$new_ticket->save();
821
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
822
+		$datetimes_on_existing = $ticket->datetimes();
823
+		$new_ticket = $this->_update_ticket_datetimes(
824
+			$new_ticket,
825
+			$datetimes_on_existing,
826
+			array_keys($datetimes_on_existing)
827
+		);
828
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
829
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
830
+		// available.
831
+		if ($ticket->sold() > 0) {
832
+			$new_qty = $ticket->qty() - $ticket->sold();
833
+			$new_ticket->set_qty($new_qty);
834
+		}
835
+		// now we update the prices just for this ticket
836
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
837
+		// and we update the base price
838
+		$new_ticket = $this->_add_prices_to_ticket(
839
+			array(),
840
+			$new_ticket,
841
+			true,
842
+			$base_price,
843
+			$base_price_id
844
+		);
845
+		return $new_ticket;
846
+	}
847 847
 
848 848
 
849
-    /**
850
-     * This attaches a list of given prices to a ticket.
851
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
852
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
853
-     * price info and prices are automatically "archived" via the ticket.
854
-     *
855
-     * @access  private
856
-     * @param array     $prices        Array of prices from the form.
857
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
858
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
859
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
860
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
861
-     * @return EE_Ticket
862
-     * @throws ReflectionException
863
-     * @throws InvalidArgumentException
864
-     * @throws InvalidInterfaceException
865
-     * @throws InvalidDataTypeException
866
-     * @throws EE_Error
867
-     */
868
-    protected function _add_prices_to_ticket(
869
-        $prices = array(),
870
-        EE_Ticket $ticket,
871
-        $new_prices = false,
872
-        $base_price = false,
873
-        $base_price_id = false
874
-    ) {
875
-        // let's just get any current prices that may exist on the given ticket
876
-        // so we can remove any prices that got trashed in this session.
877
-        $current_prices_on_ticket = $base_price !== false
878
-            ? $ticket->base_price(true)
879
-            : $ticket->price_modifiers();
880
-        $updated_prices = array();
881
-        // if $base_price ! FALSE then updating a base price.
882
-        if ($base_price !== false) {
883
-            $prices[1] = array(
884
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
885
-                'PRT_ID'     => 1,
886
-                'PRC_amount' => $base_price,
887
-                'PRC_name'   => $ticket->get('TKT_name'),
888
-                'PRC_desc'   => $ticket->get('TKT_description'),
889
-            );
890
-        }
891
-        // possibly need to save tkt
892
-        if (! $ticket->ID()) {
893
-            $ticket->save();
894
-        }
895
-        foreach ($prices as $row => $prc) {
896
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
897
-            if (empty($prt_id)) {
898
-                continue;
899
-            } //prices MUST have a price type id.
900
-            $PRC_values = array(
901
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
902
-                'PRT_ID'         => $prt_id,
903
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
904
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
905
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
906
-                'PRC_is_default' => false,
907
-                // make sure we set PRC_is_default to false for all ticket saves from event_editor
908
-                'PRC_order'      => $row,
909
-            );
910
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
911
-                $PRC_values['PRC_ID'] = 0;
912
-                $price = EE_Registry::instance()->load_class(
913
-                    'Price',
914
-                    array($PRC_values),
915
-                    false,
916
-                    false
917
-                );
918
-            } else {
919
-                $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
920
-                // update this price with new values
921
-                foreach ($PRC_values as $field => $value) {
922
-                    $price->set($field, $value);
923
-                }
924
-            }
925
-            $price->save();
926
-            $updated_prices[ $price->ID() ] = $price;
927
-            $ticket->_add_relation_to($price, 'Price');
928
-        }
929
-        // now let's remove any prices that got removed from the ticket
930
-        if (! empty($current_prices_on_ticket)) {
931
-            $current = array_keys($current_prices_on_ticket);
932
-            $updated = array_keys($updated_prices);
933
-            $prices_to_remove = array_diff($current, $updated);
934
-            if (! empty($prices_to_remove)) {
935
-                foreach ($prices_to_remove as $prc_id) {
936
-                    $p = $current_prices_on_ticket[ $prc_id ];
937
-                    $ticket->_remove_relation_to($p, 'Price');
938
-                    // delete permanently the price
939
-                    $p->delete_permanently();
940
-                }
941
-            }
942
-        }
943
-        return $ticket;
944
-    }
849
+	/**
850
+	 * This attaches a list of given prices to a ticket.
851
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
852
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
853
+	 * price info and prices are automatically "archived" via the ticket.
854
+	 *
855
+	 * @access  private
856
+	 * @param array     $prices        Array of prices from the form.
857
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
858
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
859
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
860
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
861
+	 * @return EE_Ticket
862
+	 * @throws ReflectionException
863
+	 * @throws InvalidArgumentException
864
+	 * @throws InvalidInterfaceException
865
+	 * @throws InvalidDataTypeException
866
+	 * @throws EE_Error
867
+	 */
868
+	protected function _add_prices_to_ticket(
869
+		$prices = array(),
870
+		EE_Ticket $ticket,
871
+		$new_prices = false,
872
+		$base_price = false,
873
+		$base_price_id = false
874
+	) {
875
+		// let's just get any current prices that may exist on the given ticket
876
+		// so we can remove any prices that got trashed in this session.
877
+		$current_prices_on_ticket = $base_price !== false
878
+			? $ticket->base_price(true)
879
+			: $ticket->price_modifiers();
880
+		$updated_prices = array();
881
+		// if $base_price ! FALSE then updating a base price.
882
+		if ($base_price !== false) {
883
+			$prices[1] = array(
884
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
885
+				'PRT_ID'     => 1,
886
+				'PRC_amount' => $base_price,
887
+				'PRC_name'   => $ticket->get('TKT_name'),
888
+				'PRC_desc'   => $ticket->get('TKT_description'),
889
+			);
890
+		}
891
+		// possibly need to save tkt
892
+		if (! $ticket->ID()) {
893
+			$ticket->save();
894
+		}
895
+		foreach ($prices as $row => $prc) {
896
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
897
+			if (empty($prt_id)) {
898
+				continue;
899
+			} //prices MUST have a price type id.
900
+			$PRC_values = array(
901
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
902
+				'PRT_ID'         => $prt_id,
903
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
904
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
905
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
906
+				'PRC_is_default' => false,
907
+				// make sure we set PRC_is_default to false for all ticket saves from event_editor
908
+				'PRC_order'      => $row,
909
+			);
910
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
911
+				$PRC_values['PRC_ID'] = 0;
912
+				$price = EE_Registry::instance()->load_class(
913
+					'Price',
914
+					array($PRC_values),
915
+					false,
916
+					false
917
+				);
918
+			} else {
919
+				$price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
920
+				// update this price with new values
921
+				foreach ($PRC_values as $field => $value) {
922
+					$price->set($field, $value);
923
+				}
924
+			}
925
+			$price->save();
926
+			$updated_prices[ $price->ID() ] = $price;
927
+			$ticket->_add_relation_to($price, 'Price');
928
+		}
929
+		// now let's remove any prices that got removed from the ticket
930
+		if (! empty($current_prices_on_ticket)) {
931
+			$current = array_keys($current_prices_on_ticket);
932
+			$updated = array_keys($updated_prices);
933
+			$prices_to_remove = array_diff($current, $updated);
934
+			if (! empty($prices_to_remove)) {
935
+				foreach ($prices_to_remove as $prc_id) {
936
+					$p = $current_prices_on_ticket[ $prc_id ];
937
+					$ticket->_remove_relation_to($p, 'Price');
938
+					// delete permanently the price
939
+					$p->delete_permanently();
940
+				}
941
+			}
942
+		}
943
+		return $ticket;
944
+	}
945 945
 
946 946
 
947
-    /**
948
-     * @param Events_Admin_Page $event_admin_obj
949
-     * @return Events_Admin_Page
950
-     */
951
-    public function autosave_handling(Events_Admin_Page $event_admin_obj)
952
-    {
953
-        return $event_admin_obj;
954
-        // doing nothing for the moment.
955
-        // todo when I get to this remember that I need to set the template args on the $event_admin_obj
956
-        // (use the set_template_args() method)
957
-        /**
958
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
959
-         * 1. TKT_is_default_selector (visible)
960
-         * 2. TKT_is_default (hidden)
961
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
962
-         * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
963
-         * this ticket to be saved as a default.
964
-         * The tricky part is, on an initial display on create or edit (or after manually updating),
965
-         * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
966
-         * if this is a create.  However, after an autosave, users will want some sort of indicator that
967
-         * the TKT HAS been saved as a default..
968
-         * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
969
-         * On Autosave:
970
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
971
-         * then set the TKT_is_default to false.
972
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
973
-         *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
974
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
975
-         */
976
-    }
947
+	/**
948
+	 * @param Events_Admin_Page $event_admin_obj
949
+	 * @return Events_Admin_Page
950
+	 */
951
+	public function autosave_handling(Events_Admin_Page $event_admin_obj)
952
+	{
953
+		return $event_admin_obj;
954
+		// doing nothing for the moment.
955
+		// todo when I get to this remember that I need to set the template args on the $event_admin_obj
956
+		// (use the set_template_args() method)
957
+		/**
958
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
959
+		 * 1. TKT_is_default_selector (visible)
960
+		 * 2. TKT_is_default (hidden)
961
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
962
+		 * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
963
+		 * this ticket to be saved as a default.
964
+		 * The tricky part is, on an initial display on create or edit (or after manually updating),
965
+		 * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
966
+		 * if this is a create.  However, after an autosave, users will want some sort of indicator that
967
+		 * the TKT HAS been saved as a default..
968
+		 * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
969
+		 * On Autosave:
970
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
971
+		 * then set the TKT_is_default to false.
972
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
973
+		 *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
974
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
975
+		 */
976
+	}
977 977
 
978 978
 
979
-    /**
980
-     * @throws ReflectionException
981
-     * @throws InvalidArgumentException
982
-     * @throws InvalidInterfaceException
983
-     * @throws InvalidDataTypeException
984
-     * @throws DomainException
985
-     * @throws EE_Error
986
-     */
987
-    public function pricing_metabox()
988
-    {
989
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
990
-        $event = $this->_adminpage_obj->get_cpt_model_obj();
991
-        // set is_creating_event property.
992
-        $EVT_ID = $event->ID();
993
-        $this->_is_creating_event = empty($this->_req_data['post']);
994
-        // default main template args
995
-        $main_template_args = array(
996
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link(
997
-                'event_editor_event_datetimes_help_tab',
998
-                $this->_adminpage_obj->page_slug,
999
-                $this->_adminpage_obj->get_req_action(),
1000
-                false,
1001
-                false
1002
-            ),
1003
-            // todo need to add a filter to the template for the help text
1004
-            // in the Events_Admin_Page core file so we can add further help
1005
-            'existing_datetime_ids'    => '',
1006
-            'total_dtt_rows'           => 1,
1007
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1008
-                'add_new_dtt_info',
1009
-                $this->_adminpage_obj->page_slug,
1010
-                $this->_adminpage_obj->get_req_action(),
1011
-                false,
1012
-                false
1013
-            ),
1014
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1015
-            'datetime_rows'            => '',
1016
-            'show_tickets_container'   => '',
1017
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1018
-            'ticket_rows'              => '',
1019
-            'existing_ticket_ids'      => '',
1020
-            'total_ticket_rows'        => 1,
1021
-            'ticket_js_structure'      => '',
1022
-            'ee_collapsible_status'    => ' ee-collapsible-open'
1023
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1024
-        );
1025
-        $timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1026
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1027
-        /**
1028
-         * 1. Start with retrieving Datetimes
1029
-         * 2. For each datetime get related tickets
1030
-         * 3. For each ticket get related prices
1031
-         */
1032
-        /** @var EEM_Datetime $datetime_model */
1033
-        $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1034
-        $datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1035
-        $main_template_args['total_dtt_rows'] = count($datetimes);
1036
-        /**
1037
-         * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1038
-         * for why we are counting $datetime_row and then setting that on the Datetime object
1039
-         */
1040
-        $datetime_row = 1;
1041
-        foreach ($datetimes as $datetime) {
1042
-            $DTT_ID = $datetime->get('DTT_ID');
1043
-            $datetime->set('DTT_order', $datetime_row);
1044
-            $existing_datetime_ids[] = $DTT_ID;
1045
-            // tickets attached
1046
-            $related_tickets = $datetime->ID() > 0
1047
-                ? $datetime->get_many_related(
1048
-                    'Ticket',
1049
-                    array(
1050
-                        array(
1051
-                            'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1052
-                        ),
1053
-                        'default_where_conditions' => 'none',
1054
-                        'order_by'                 => array('TKT_order' => 'ASC'),
1055
-                    )
1056
-                )
1057
-                : array();
1058
-            // if there are no related tickets this is likely a new event OR autodraft
1059
-            // event so we need to generate the default tickets because datetimes
1060
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1061
-            // datetime on the event.
1062
-            if (empty($related_tickets) && count($datetimes) < 2) {
1063
-                /** @var EEM_Ticket $ticket_model */
1064
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
1065
-                $related_tickets = $ticket_model->get_all_default_tickets();
1066
-                // this should be ordered by TKT_ID, so let's grab the first default ticket
1067
-                // (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1068
-                $default_prices = EEM_Price::instance()->get_all_default_prices();
1069
-                $main_default_ticket = reset($related_tickets);
1070
-                if ($main_default_ticket instanceof EE_Ticket) {
1071
-                    foreach ($default_prices as $default_price) {
1072
-                        if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1073
-                            continue;
1074
-                        }
1075
-                        $main_default_ticket->cache('Price', $default_price);
1076
-                    }
1077
-                }
1078
-            }
1079
-            // we can't actually setup rows in this loop yet cause we don't know all
1080
-            // the unique tickets for this event yet (tickets are linked through all datetimes).
1081
-            // So we're going to temporarily cache some of that information.
1082
-            // loop through and setup the ticket rows and make sure the order is set.
1083
-            foreach ($related_tickets as $ticket) {
1084
-                $TKT_ID = $ticket->get('TKT_ID');
1085
-                $ticket_row = $ticket->get('TKT_row');
1086
-                // we only want unique tickets in our final display!!
1087
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1088
-                    $existing_ticket_ids[] = $TKT_ID;
1089
-                    $all_tickets[] = $ticket;
1090
-                }
1091
-                // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1092
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1093
-                // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1094
-                if (! isset($ticket_datetimes[ $TKT_ID ])
1095
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1096
-                ) {
1097
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1098
-                }
1099
-            }
1100
-            $datetime_row++;
1101
-        }
1102
-        $main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1103
-        $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1104
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1105
-        // sort $all_tickets by order
1106
-        usort(
1107
-            $all_tickets,
1108
-            function (EE_Ticket $a, EE_Ticket $b) {
1109
-                $a_order = (int) $a->get('TKT_order');
1110
-                $b_order = (int) $b->get('TKT_order');
1111
-                if ($a_order === $b_order) {
1112
-                    return 0;
1113
-                }
1114
-                return ($a_order < $b_order) ? -1 : 1;
1115
-            }
1116
-        );
1117
-        // k NOW we have all the data we need for setting up the dtt rows
1118
-        // and ticket rows so we start our dtt loop again.
1119
-        $datetime_row = 1;
1120
-        foreach ($datetimes as $datetime) {
1121
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1122
-                $datetime_row,
1123
-                $datetime,
1124
-                $datetime_tickets,
1125
-                $all_tickets,
1126
-                false,
1127
-                $datetimes
1128
-            );
1129
-            $datetime_row++;
1130
-        }
1131
-        // then loop through all tickets for the ticket rows.
1132
-        $ticket_row = 1;
1133
-        foreach ($all_tickets as $ticket) {
1134
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1135
-                $ticket_row,
1136
-                $ticket,
1137
-                $ticket_datetimes,
1138
-                $datetimes,
1139
-                false,
1140
-                $all_tickets
1141
-            );
1142
-            $ticket_row++;
1143
-        }
1144
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1145
-        EEH_Template::display_template(
1146
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1147
-            $main_template_args
1148
-        );
1149
-    }
979
+	/**
980
+	 * @throws ReflectionException
981
+	 * @throws InvalidArgumentException
982
+	 * @throws InvalidInterfaceException
983
+	 * @throws InvalidDataTypeException
984
+	 * @throws DomainException
985
+	 * @throws EE_Error
986
+	 */
987
+	public function pricing_metabox()
988
+	{
989
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
990
+		$event = $this->_adminpage_obj->get_cpt_model_obj();
991
+		// set is_creating_event property.
992
+		$EVT_ID = $event->ID();
993
+		$this->_is_creating_event = empty($this->_req_data['post']);
994
+		// default main template args
995
+		$main_template_args = array(
996
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link(
997
+				'event_editor_event_datetimes_help_tab',
998
+				$this->_adminpage_obj->page_slug,
999
+				$this->_adminpage_obj->get_req_action(),
1000
+				false,
1001
+				false
1002
+			),
1003
+			// todo need to add a filter to the template for the help text
1004
+			// in the Events_Admin_Page core file so we can add further help
1005
+			'existing_datetime_ids'    => '',
1006
+			'total_dtt_rows'           => 1,
1007
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1008
+				'add_new_dtt_info',
1009
+				$this->_adminpage_obj->page_slug,
1010
+				$this->_adminpage_obj->get_req_action(),
1011
+				false,
1012
+				false
1013
+			),
1014
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1015
+			'datetime_rows'            => '',
1016
+			'show_tickets_container'   => '',
1017
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1018
+			'ticket_rows'              => '',
1019
+			'existing_ticket_ids'      => '',
1020
+			'total_ticket_rows'        => 1,
1021
+			'ticket_js_structure'      => '',
1022
+			'ee_collapsible_status'    => ' ee-collapsible-open'
1023
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1024
+		);
1025
+		$timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1026
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1027
+		/**
1028
+		 * 1. Start with retrieving Datetimes
1029
+		 * 2. For each datetime get related tickets
1030
+		 * 3. For each ticket get related prices
1031
+		 */
1032
+		/** @var EEM_Datetime $datetime_model */
1033
+		$datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1034
+		$datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1035
+		$main_template_args['total_dtt_rows'] = count($datetimes);
1036
+		/**
1037
+		 * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1038
+		 * for why we are counting $datetime_row and then setting that on the Datetime object
1039
+		 */
1040
+		$datetime_row = 1;
1041
+		foreach ($datetimes as $datetime) {
1042
+			$DTT_ID = $datetime->get('DTT_ID');
1043
+			$datetime->set('DTT_order', $datetime_row);
1044
+			$existing_datetime_ids[] = $DTT_ID;
1045
+			// tickets attached
1046
+			$related_tickets = $datetime->ID() > 0
1047
+				? $datetime->get_many_related(
1048
+					'Ticket',
1049
+					array(
1050
+						array(
1051
+							'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1052
+						),
1053
+						'default_where_conditions' => 'none',
1054
+						'order_by'                 => array('TKT_order' => 'ASC'),
1055
+					)
1056
+				)
1057
+				: array();
1058
+			// if there are no related tickets this is likely a new event OR autodraft
1059
+			// event so we need to generate the default tickets because datetimes
1060
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1061
+			// datetime on the event.
1062
+			if (empty($related_tickets) && count($datetimes) < 2) {
1063
+				/** @var EEM_Ticket $ticket_model */
1064
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
1065
+				$related_tickets = $ticket_model->get_all_default_tickets();
1066
+				// this should be ordered by TKT_ID, so let's grab the first default ticket
1067
+				// (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1068
+				$default_prices = EEM_Price::instance()->get_all_default_prices();
1069
+				$main_default_ticket = reset($related_tickets);
1070
+				if ($main_default_ticket instanceof EE_Ticket) {
1071
+					foreach ($default_prices as $default_price) {
1072
+						if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1073
+							continue;
1074
+						}
1075
+						$main_default_ticket->cache('Price', $default_price);
1076
+					}
1077
+				}
1078
+			}
1079
+			// we can't actually setup rows in this loop yet cause we don't know all
1080
+			// the unique tickets for this event yet (tickets are linked through all datetimes).
1081
+			// So we're going to temporarily cache some of that information.
1082
+			// loop through and setup the ticket rows and make sure the order is set.
1083
+			foreach ($related_tickets as $ticket) {
1084
+				$TKT_ID = $ticket->get('TKT_ID');
1085
+				$ticket_row = $ticket->get('TKT_row');
1086
+				// we only want unique tickets in our final display!!
1087
+				if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1088
+					$existing_ticket_ids[] = $TKT_ID;
1089
+					$all_tickets[] = $ticket;
1090
+				}
1091
+				// temporary cache of this ticket info for this datetime for later processing of datetime rows.
1092
+				$datetime_tickets[ $DTT_ID ][] = $ticket_row;
1093
+				// temporary cache of this datetime info for this ticket for later processing of ticket rows.
1094
+				if (! isset($ticket_datetimes[ $TKT_ID ])
1095
+					|| ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1096
+				) {
1097
+					$ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1098
+				}
1099
+			}
1100
+			$datetime_row++;
1101
+		}
1102
+		$main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1103
+		$main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1104
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1105
+		// sort $all_tickets by order
1106
+		usort(
1107
+			$all_tickets,
1108
+			function (EE_Ticket $a, EE_Ticket $b) {
1109
+				$a_order = (int) $a->get('TKT_order');
1110
+				$b_order = (int) $b->get('TKT_order');
1111
+				if ($a_order === $b_order) {
1112
+					return 0;
1113
+				}
1114
+				return ($a_order < $b_order) ? -1 : 1;
1115
+			}
1116
+		);
1117
+		// k NOW we have all the data we need for setting up the dtt rows
1118
+		// and ticket rows so we start our dtt loop again.
1119
+		$datetime_row = 1;
1120
+		foreach ($datetimes as $datetime) {
1121
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1122
+				$datetime_row,
1123
+				$datetime,
1124
+				$datetime_tickets,
1125
+				$all_tickets,
1126
+				false,
1127
+				$datetimes
1128
+			);
1129
+			$datetime_row++;
1130
+		}
1131
+		// then loop through all tickets for the ticket rows.
1132
+		$ticket_row = 1;
1133
+		foreach ($all_tickets as $ticket) {
1134
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1135
+				$ticket_row,
1136
+				$ticket,
1137
+				$ticket_datetimes,
1138
+				$datetimes,
1139
+				false,
1140
+				$all_tickets
1141
+			);
1142
+			$ticket_row++;
1143
+		}
1144
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1145
+		EEH_Template::display_template(
1146
+			PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1147
+			$main_template_args
1148
+		);
1149
+	}
1150 1150
 
1151 1151
 
1152
-    /**
1153
-     * @param int         $datetime_row
1154
-     * @param EE_Datetime $datetime
1155
-     * @param array       $datetime_tickets
1156
-     * @param array       $all_tickets
1157
-     * @param bool        $default
1158
-     * @param array       $all_datetimes
1159
-     * @return mixed
1160
-     * @throws DomainException
1161
-     * @throws EE_Error
1162
-     */
1163
-    protected function _get_datetime_row(
1164
-        $datetime_row,
1165
-        EE_Datetime $datetime,
1166
-        $datetime_tickets = array(),
1167
-        $all_tickets = array(),
1168
-        $default = false,
1169
-        $all_datetimes = array()
1170
-    ) {
1171
-        $dtt_display_template_args = array(
1172
-            'dtt_edit_row'             => $this->_get_dtt_edit_row(
1173
-                $datetime_row,
1174
-                $datetime,
1175
-                $default,
1176
-                $all_datetimes
1177
-            ),
1178
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1179
-                $datetime_row,
1180
-                $datetime,
1181
-                $datetime_tickets,
1182
-                $all_tickets,
1183
-                $default
1184
-            ),
1185
-            'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1186
-        );
1187
-        return EEH_Template::display_template(
1188
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1189
-            $dtt_display_template_args,
1190
-            true
1191
-        );
1192
-    }
1152
+	/**
1153
+	 * @param int         $datetime_row
1154
+	 * @param EE_Datetime $datetime
1155
+	 * @param array       $datetime_tickets
1156
+	 * @param array       $all_tickets
1157
+	 * @param bool        $default
1158
+	 * @param array       $all_datetimes
1159
+	 * @return mixed
1160
+	 * @throws DomainException
1161
+	 * @throws EE_Error
1162
+	 */
1163
+	protected function _get_datetime_row(
1164
+		$datetime_row,
1165
+		EE_Datetime $datetime,
1166
+		$datetime_tickets = array(),
1167
+		$all_tickets = array(),
1168
+		$default = false,
1169
+		$all_datetimes = array()
1170
+	) {
1171
+		$dtt_display_template_args = array(
1172
+			'dtt_edit_row'             => $this->_get_dtt_edit_row(
1173
+				$datetime_row,
1174
+				$datetime,
1175
+				$default,
1176
+				$all_datetimes
1177
+			),
1178
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1179
+				$datetime_row,
1180
+				$datetime,
1181
+				$datetime_tickets,
1182
+				$all_tickets,
1183
+				$default
1184
+			),
1185
+			'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1186
+		);
1187
+		return EEH_Template::display_template(
1188
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1189
+			$dtt_display_template_args,
1190
+			true
1191
+		);
1192
+	}
1193 1193
 
1194 1194
 
1195
-    /**
1196
-     * This method is used to generate a dtt fields  edit row.
1197
-     * The same row is used to generate a row with valid DTT objects
1198
-     * and the default row that is used as the skeleton by the js.
1199
-     *
1200
-     * @param int           $datetime_row  The row number for the row being generated.
1201
-     * @param EE_Datetime   $datetime
1202
-     * @param bool          $default       Whether a default row is being generated or not.
1203
-     * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1204
-     * @return string
1205
-     * @throws DomainException
1206
-     * @throws EE_Error
1207
-     */
1208
-    protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1209
-    {
1210
-        // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1211
-        $default = ! $datetime instanceof EE_Datetime ? true : $default;
1212
-        $template_args = array(
1213
-            'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1214
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1215
-            'edit_dtt_expanded'    => '',
1216
-            'DTT_ID'               => $default ? '' : $datetime->ID(),
1217
-            'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1218
-            'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1219
-            'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1220
-            'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1221
-            'DTT_reg_limit'        => $default
1222
-                ? ''
1223
-                : $datetime->get_pretty(
1224
-                    'DTT_reg_limit',
1225
-                    'input'
1226
-                ),
1227
-            'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1228
-            'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1229
-            'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1230
-            'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1231
-                ? ''
1232
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1233
-            'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1234
-                ? 'ee-lock-icon'
1235
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1236
-            'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1237
-                ? ''
1238
-                : EE_Admin_Page::add_query_args_and_nonce(
1239
-                    array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1240
-                    REG_ADMIN_URL
1241
-                ),
1242
-        );
1243
-        $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1244
-            ? ' style="display:none"'
1245
-            : '';
1246
-        // allow filtering of template args at this point.
1247
-        $template_args = apply_filters(
1248
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1249
-            $template_args,
1250
-            $datetime_row,
1251
-            $datetime,
1252
-            $default,
1253
-            $all_datetimes,
1254
-            $this->_is_creating_event
1255
-        );
1256
-        return EEH_Template::display_template(
1257
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1258
-            $template_args,
1259
-            true
1260
-        );
1261
-    }
1195
+	/**
1196
+	 * This method is used to generate a dtt fields  edit row.
1197
+	 * The same row is used to generate a row with valid DTT objects
1198
+	 * and the default row that is used as the skeleton by the js.
1199
+	 *
1200
+	 * @param int           $datetime_row  The row number for the row being generated.
1201
+	 * @param EE_Datetime   $datetime
1202
+	 * @param bool          $default       Whether a default row is being generated or not.
1203
+	 * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1204
+	 * @return string
1205
+	 * @throws DomainException
1206
+	 * @throws EE_Error
1207
+	 */
1208
+	protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1209
+	{
1210
+		// if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1211
+		$default = ! $datetime instanceof EE_Datetime ? true : $default;
1212
+		$template_args = array(
1213
+			'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1214
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1215
+			'edit_dtt_expanded'    => '',
1216
+			'DTT_ID'               => $default ? '' : $datetime->ID(),
1217
+			'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1218
+			'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1219
+			'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1220
+			'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1221
+			'DTT_reg_limit'        => $default
1222
+				? ''
1223
+				: $datetime->get_pretty(
1224
+					'DTT_reg_limit',
1225
+					'input'
1226
+				),
1227
+			'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1228
+			'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1229
+			'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1230
+			'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1231
+				? ''
1232
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1233
+			'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1234
+				? 'ee-lock-icon'
1235
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1236
+			'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1237
+				? ''
1238
+				: EE_Admin_Page::add_query_args_and_nonce(
1239
+					array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1240
+					REG_ADMIN_URL
1241
+				),
1242
+		);
1243
+		$template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1244
+			? ' style="display:none"'
1245
+			: '';
1246
+		// allow filtering of template args at this point.
1247
+		$template_args = apply_filters(
1248
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1249
+			$template_args,
1250
+			$datetime_row,
1251
+			$datetime,
1252
+			$default,
1253
+			$all_datetimes,
1254
+			$this->_is_creating_event
1255
+		);
1256
+		return EEH_Template::display_template(
1257
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1258
+			$template_args,
1259
+			true
1260
+		);
1261
+	}
1262 1262
 
1263 1263
 
1264
-    /**
1265
-     * @param int         $datetime_row
1266
-     * @param EE_Datetime $datetime
1267
-     * @param array       $datetime_tickets
1268
-     * @param array       $all_tickets
1269
-     * @param bool        $default
1270
-     * @return mixed
1271
-     * @throws DomainException
1272
-     * @throws EE_Error
1273
-     */
1274
-    protected function _get_dtt_attached_tickets_row(
1275
-        $datetime_row,
1276
-        $datetime,
1277
-        $datetime_tickets = array(),
1278
-        $all_tickets = array(),
1279
-        $default
1280
-    ) {
1281
-        $template_args = array(
1282
-            'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1283
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1284
-            'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1285
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1286
-            'show_tickets_row'                  => ' style="display:none;"',
1287
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1288
-                'add_new_ticket_via_datetime',
1289
-                $this->_adminpage_obj->page_slug,
1290
-                $this->_adminpage_obj->get_req_action(),
1291
-                false,
1292
-                false
1293
-            ),
1294
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1295
-            'DTT_ID'                            => $default ? '' : $datetime->ID(),
1296
-        );
1297
-        // need to setup the list items (but only if this isn't a default skeleton setup)
1298
-        if (! $default) {
1299
-            $ticket_row = 1;
1300
-            foreach ($all_tickets as $ticket) {
1301
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1302
-                    $datetime_row,
1303
-                    $ticket_row,
1304
-                    $datetime,
1305
-                    $ticket,
1306
-                    $datetime_tickets,
1307
-                    $default
1308
-                );
1309
-                $ticket_row++;
1310
-            }
1311
-        }
1312
-        // filter template args at this point
1313
-        $template_args = apply_filters(
1314
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1315
-            $template_args,
1316
-            $datetime_row,
1317
-            $datetime,
1318
-            $datetime_tickets,
1319
-            $all_tickets,
1320
-            $default,
1321
-            $this->_is_creating_event
1322
-        );
1323
-        return EEH_Template::display_template(
1324
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1325
-            $template_args,
1326
-            true
1327
-        );
1328
-    }
1264
+	/**
1265
+	 * @param int         $datetime_row
1266
+	 * @param EE_Datetime $datetime
1267
+	 * @param array       $datetime_tickets
1268
+	 * @param array       $all_tickets
1269
+	 * @param bool        $default
1270
+	 * @return mixed
1271
+	 * @throws DomainException
1272
+	 * @throws EE_Error
1273
+	 */
1274
+	protected function _get_dtt_attached_tickets_row(
1275
+		$datetime_row,
1276
+		$datetime,
1277
+		$datetime_tickets = array(),
1278
+		$all_tickets = array(),
1279
+		$default
1280
+	) {
1281
+		$template_args = array(
1282
+			'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1283
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1284
+			'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1285
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1286
+			'show_tickets_row'                  => ' style="display:none;"',
1287
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1288
+				'add_new_ticket_via_datetime',
1289
+				$this->_adminpage_obj->page_slug,
1290
+				$this->_adminpage_obj->get_req_action(),
1291
+				false,
1292
+				false
1293
+			),
1294
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1295
+			'DTT_ID'                            => $default ? '' : $datetime->ID(),
1296
+		);
1297
+		// need to setup the list items (but only if this isn't a default skeleton setup)
1298
+		if (! $default) {
1299
+			$ticket_row = 1;
1300
+			foreach ($all_tickets as $ticket) {
1301
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1302
+					$datetime_row,
1303
+					$ticket_row,
1304
+					$datetime,
1305
+					$ticket,
1306
+					$datetime_tickets,
1307
+					$default
1308
+				);
1309
+				$ticket_row++;
1310
+			}
1311
+		}
1312
+		// filter template args at this point
1313
+		$template_args = apply_filters(
1314
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1315
+			$template_args,
1316
+			$datetime_row,
1317
+			$datetime,
1318
+			$datetime_tickets,
1319
+			$all_tickets,
1320
+			$default,
1321
+			$this->_is_creating_event
1322
+		);
1323
+		return EEH_Template::display_template(
1324
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1325
+			$template_args,
1326
+			true
1327
+		);
1328
+	}
1329 1329
 
1330 1330
 
1331
-    /**
1332
-     * @param int         $datetime_row
1333
-     * @param int         $ticket_row
1334
-     * @param EE_Datetime $datetime
1335
-     * @param EE_Ticket   $ticket
1336
-     * @param array       $datetime_tickets
1337
-     * @param bool        $default
1338
-     * @return mixed
1339
-     * @throws DomainException
1340
-     * @throws EE_Error
1341
-     */
1342
-    protected function _get_datetime_tickets_list_item(
1343
-        $datetime_row,
1344
-        $ticket_row,
1345
-        $datetime,
1346
-        $ticket,
1347
-        $datetime_tickets = array(),
1348
-        $default
1349
-    ) {
1350
-        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1351
-            ? $datetime_tickets[ $datetime->ID() ]
1352
-            : array();
1353
-        $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1354
-        $no_ticket = $default && empty($ticket);
1355
-        $template_args = array(
1356
-            'dtt_row'                 => $default
1357
-                ? 'DTTNUM'
1358
-                : $datetime_row,
1359
-            'tkt_row'                 => $no_ticket
1360
-                ? 'TICKETNUM'
1361
-                : $ticket_row,
1362
-            'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1363
-                ? ' checked="checked"'
1364
-                : '',
1365
-            'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1366
-                ? ' ticket-selected'
1367
-                : '',
1368
-            'TKT_name'                => $no_ticket
1369
-                ? 'TKTNAME'
1370
-                : $ticket->get('TKT_name'),
1371
-            'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1372
-                ? ' tkt-status-' . EE_Ticket::onsale
1373
-                : ' tkt-status-' . $ticket->ticket_status(),
1374
-        );
1375
-        // filter template args
1376
-        $template_args = apply_filters(
1377
-            'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1378
-            $template_args,
1379
-            $datetime_row,
1380
-            $ticket_row,
1381
-            $datetime,
1382
-            $ticket,
1383
-            $datetime_tickets,
1384
-            $default,
1385
-            $this->_is_creating_event
1386
-        );
1387
-        return EEH_Template::display_template(
1388
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1389
-            $template_args,
1390
-            true
1391
-        );
1392
-    }
1331
+	/**
1332
+	 * @param int         $datetime_row
1333
+	 * @param int         $ticket_row
1334
+	 * @param EE_Datetime $datetime
1335
+	 * @param EE_Ticket   $ticket
1336
+	 * @param array       $datetime_tickets
1337
+	 * @param bool        $default
1338
+	 * @return mixed
1339
+	 * @throws DomainException
1340
+	 * @throws EE_Error
1341
+	 */
1342
+	protected function _get_datetime_tickets_list_item(
1343
+		$datetime_row,
1344
+		$ticket_row,
1345
+		$datetime,
1346
+		$ticket,
1347
+		$datetime_tickets = array(),
1348
+		$default
1349
+	) {
1350
+		$dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1351
+			? $datetime_tickets[ $datetime->ID() ]
1352
+			: array();
1353
+		$display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1354
+		$no_ticket = $default && empty($ticket);
1355
+		$template_args = array(
1356
+			'dtt_row'                 => $default
1357
+				? 'DTTNUM'
1358
+				: $datetime_row,
1359
+			'tkt_row'                 => $no_ticket
1360
+				? 'TICKETNUM'
1361
+				: $ticket_row,
1362
+			'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1363
+				? ' checked="checked"'
1364
+				: '',
1365
+			'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1366
+				? ' ticket-selected'
1367
+				: '',
1368
+			'TKT_name'                => $no_ticket
1369
+				? 'TKTNAME'
1370
+				: $ticket->get('TKT_name'),
1371
+			'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1372
+				? ' tkt-status-' . EE_Ticket::onsale
1373
+				: ' tkt-status-' . $ticket->ticket_status(),
1374
+		);
1375
+		// filter template args
1376
+		$template_args = apply_filters(
1377
+			'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1378
+			$template_args,
1379
+			$datetime_row,
1380
+			$ticket_row,
1381
+			$datetime,
1382
+			$ticket,
1383
+			$datetime_tickets,
1384
+			$default,
1385
+			$this->_is_creating_event
1386
+		);
1387
+		return EEH_Template::display_template(
1388
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1389
+			$template_args,
1390
+			true
1391
+		);
1392
+	}
1393 1393
 
1394 1394
 
1395
-    /**
1396
-     * This generates the ticket row for tickets.
1397
-     * This same method is used to generate both the actual rows and the js skeleton row
1398
-     * (when default === true)
1399
-     *
1400
-     * @param int           $ticket_row       Represents the row number being generated.
1401
-     * @param               $ticket
1402
-     * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1403
-     *                                        or empty for default
1404
-     * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1405
-     * @param bool          $default          Whether default row being generated or not.
1406
-     * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1407
-     *                                        (or empty in the case of defaults)
1408
-     * @return mixed
1409
-     * @throws InvalidArgumentException
1410
-     * @throws InvalidInterfaceException
1411
-     * @throws InvalidDataTypeException
1412
-     * @throws DomainException
1413
-     * @throws EE_Error
1414
-     * @throws ReflectionException
1415
-     */
1416
-    protected function _get_ticket_row(
1417
-        $ticket_row,
1418
-        $ticket,
1419
-        $ticket_datetimes,
1420
-        $all_datetimes,
1421
-        $default = false,
1422
-        $all_tickets = array()
1423
-    ) {
1424
-        // if $ticket is not an instance of EE_Ticket then force default to true.
1425
-        $default = ! $ticket instanceof EE_Ticket ? true : $default;
1426
-        $prices = ! empty($ticket) && ! $default
1427
-            ? $ticket->get_many_related(
1428
-                'Price',
1429
-                array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1430
-            )
1431
-            : array();
1432
-        // if there is only one price (which would be the base price)
1433
-        // or NO prices and this ticket is a default ticket,
1434
-        // let's just make sure there are no cached default prices on the object.
1435
-        // This is done by not including any query_params.
1436
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1437
-            $prices = $ticket->prices();
1438
-        }
1439
-        // check if we're dealing with a default ticket in which case
1440
-        // we don't want any starting_ticket_datetime_row values set
1441
-        // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1442
-        // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1443
-        $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1444
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1445
-            ? $ticket_datetimes[ $ticket->ID() ]
1446
-            : array();
1447
-        $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1448
-        $base_price = $default ? null : $ticket->base_price();
1449
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1450
-        // breaking out complicated condition for ticket_status
1451
-        if ($default) {
1452
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1453
-        } else {
1454
-            $ticket_status_class = $ticket->is_default()
1455
-                ? ' tkt-status-' . EE_Ticket::onsale
1456
-                : ' tkt-status-' . $ticket->ticket_status();
1457
-        }
1458
-        // breaking out complicated condition for TKT_taxable
1459
-        if ($default) {
1460
-            $TKT_taxable = '';
1461
-        } else {
1462
-            $TKT_taxable = $ticket->taxable()
1463
-                ? ' checked="checked"'
1464
-                : '';
1465
-        }
1466
-        if ($default) {
1467
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1468
-        } elseif ($ticket->is_default()) {
1469
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1470
-        } else {
1471
-            $TKT_status = $ticket->ticket_status(true);
1472
-        }
1473
-        if ($default) {
1474
-            $TKT_min = '';
1475
-        } else {
1476
-            $TKT_min = $ticket->min();
1477
-            if ($TKT_min === -1 || $TKT_min === 0) {
1478
-                $TKT_min = '';
1479
-            }
1480
-        }
1481
-        $template_args = array(
1482
-            'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1483
-            'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1484
-            // on initial page load this will always be the correct order.
1485
-            'tkt_status_class'              => $ticket_status_class,
1486
-            'display_edit_tkt_row'          => ' style="display:none;"',
1487
-            'edit_tkt_expanded'             => '',
1488
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1489
-            'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1490
-            'TKT_start_date'                => $default
1491
-                ? ''
1492
-                : $ticket->get_date('TKT_start_date', $this->_date_time_format),
1493
-            'TKT_end_date'                  => $default
1494
-                ? ''
1495
-                : $ticket->get_date('TKT_end_date', $this->_date_time_format),
1496
-            'TKT_status'                    => $TKT_status,
1497
-            'TKT_price'                     => $default
1498
-                ? ''
1499
-                : EEH_Template::format_currency(
1500
-                    $ticket->get_ticket_total_with_taxes(),
1501
-                    false,
1502
-                    false
1503
-                ),
1504
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1505
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1506
-            'TKT_qty'                       => $default
1507
-                ? ''
1508
-                : $ticket->get_pretty('TKT_qty', 'symbol'),
1509
-            'TKT_qty_for_input'             => $default
1510
-                ? ''
1511
-                : $ticket->get_pretty('TKT_qty', 'input'),
1512
-            'TKT_uses'                      => $default
1513
-                ? ''
1514
-                : $ticket->get_pretty('TKT_uses', 'input'),
1515
-            'TKT_min'                       => $TKT_min,
1516
-            'TKT_max'                       => $default
1517
-                ? ''
1518
-                : $ticket->get_pretty('TKT_max', 'input'),
1519
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1520
-            'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1521
-            'TKT_registrations'             => $default
1522
-                ? 0
1523
-                : $ticket->count_registrations(
1524
-                    array(
1525
-                        array(
1526
-                            'STS_ID' => array(
1527
-                                '!=',
1528
-                                EEM_Registration::status_id_incomplete,
1529
-                            ),
1530
-                        ),
1531
-                    )
1532
-                ),
1533
-            'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1534
-            'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1535
-            'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1536
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1537
-            'TKT_is_default_selector'       => '',
1538
-            'ticket_price_rows'             => '',
1539
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1540
-                ? ''
1541
-                : $base_price->get_pretty('PRC_amount', 'localized_float'),
1542
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1543
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1544
-                ? ''
1545
-                : ' style="display:none;"',
1546
-            'show_price_mod_button'         => count($prices) > 1
1547
-                                               || ($default && $count_price_mods > 0)
1548
-                                               || (! $default && $ticket->deleted())
1549
-                ? ' style="display:none;"'
1550
-                : '',
1551
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1552
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1553
-            'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1554
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1555
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1556
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1557
-            'TKT_taxable'                   => $TKT_taxable,
1558
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1559
-                ? ''
1560
-                : ' style="display:none"',
1561
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1562
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1563
-                $ticket_subtotal,
1564
-                false,
1565
-                false
1566
-            ),
1567
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1568
-            'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1569
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1570
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1571
-                ? ' ticket-archived'
1572
-                : '',
1573
-            'trash_icon'                    => $ticket instanceof EE_Ticket
1574
-                                               && $ticket->deleted()
1575
-                                               && ! $ticket->is_permanently_deleteable()
1576
-                ? 'ee-lock-icon '
1577
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1578
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1579
-                ? ''
1580
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1581
-        );
1582
-        $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1583
-            ? ' style="display:none"'
1584
-            : '';
1585
-        // handle rows that should NOT be empty
1586
-        if (empty($template_args['TKT_start_date'])) {
1587
-            // if empty then the start date will be now.
1588
-            $template_args['TKT_start_date'] = date(
1589
-                $this->_date_time_format,
1590
-                current_time('timestamp')
1591
-            );
1592
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1593
-        }
1594
-        if (empty($template_args['TKT_end_date'])) {
1595
-            // get the earliest datetime (if present);
1596
-            $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1597
-                ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1598
-                    'Datetime',
1599
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1600
-                )
1601
-                : null;
1602
-            if (! empty($earliest_dtt)) {
1603
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1604
-                    'DTT_EVT_start',
1605
-                    $this->_date_time_format
1606
-                );
1607
-            } else {
1608
-                // default so let's just use what's been set for the default date-time which is 30 days from now.
1609
-                $template_args['TKT_end_date'] = date(
1610
-                    $this->_date_time_format,
1611
-                    mktime(
1612
-                        24,
1613
-                        0,
1614
-                        0,
1615
-                        date('m'),
1616
-                        date('d') + 29,
1617
-                        date('Y')
1618
-                    )
1619
-                );
1620
-            }
1621
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1622
-        }
1623
-        // generate ticket_datetime items
1624
-        if (! $default) {
1625
-            $datetime_row = 1;
1626
-            foreach ($all_datetimes as $datetime) {
1627
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1628
-                    $datetime_row,
1629
-                    $ticket_row,
1630
-                    $datetime,
1631
-                    $ticket,
1632
-                    $ticket_datetimes,
1633
-                    $default
1634
-                );
1635
-                $datetime_row++;
1636
-            }
1637
-        }
1638
-        $price_row = 1;
1639
-        foreach ($prices as $price) {
1640
-            if (! $price instanceof EE_Price) {
1641
-                continue;
1642
-            }
1643
-            if ($price->is_base_price()) {
1644
-                $price_row++;
1645
-                continue;
1646
-            }
1647
-            $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1648
-            $show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1649
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1650
-                $ticket_row,
1651
-                $price_row,
1652
-                $price,
1653
-                $default,
1654
-                $ticket,
1655
-                $show_trash,
1656
-                $show_create
1657
-            );
1658
-            $price_row++;
1659
-        }
1660
-        // filter $template_args
1661
-        $template_args = apply_filters(
1662
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1663
-            $template_args,
1664
-            $ticket_row,
1665
-            $ticket,
1666
-            $ticket_datetimes,
1667
-            $all_datetimes,
1668
-            $default,
1669
-            $all_tickets,
1670
-            $this->_is_creating_event
1671
-        );
1672
-        return EEH_Template::display_template(
1673
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1674
-            $template_args,
1675
-            true
1676
-        );
1677
-    }
1395
+	/**
1396
+	 * This generates the ticket row for tickets.
1397
+	 * This same method is used to generate both the actual rows and the js skeleton row
1398
+	 * (when default === true)
1399
+	 *
1400
+	 * @param int           $ticket_row       Represents the row number being generated.
1401
+	 * @param               $ticket
1402
+	 * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1403
+	 *                                        or empty for default
1404
+	 * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1405
+	 * @param bool          $default          Whether default row being generated or not.
1406
+	 * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1407
+	 *                                        (or empty in the case of defaults)
1408
+	 * @return mixed
1409
+	 * @throws InvalidArgumentException
1410
+	 * @throws InvalidInterfaceException
1411
+	 * @throws InvalidDataTypeException
1412
+	 * @throws DomainException
1413
+	 * @throws EE_Error
1414
+	 * @throws ReflectionException
1415
+	 */
1416
+	protected function _get_ticket_row(
1417
+		$ticket_row,
1418
+		$ticket,
1419
+		$ticket_datetimes,
1420
+		$all_datetimes,
1421
+		$default = false,
1422
+		$all_tickets = array()
1423
+	) {
1424
+		// if $ticket is not an instance of EE_Ticket then force default to true.
1425
+		$default = ! $ticket instanceof EE_Ticket ? true : $default;
1426
+		$prices = ! empty($ticket) && ! $default
1427
+			? $ticket->get_many_related(
1428
+				'Price',
1429
+				array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1430
+			)
1431
+			: array();
1432
+		// if there is only one price (which would be the base price)
1433
+		// or NO prices and this ticket is a default ticket,
1434
+		// let's just make sure there are no cached default prices on the object.
1435
+		// This is done by not including any query_params.
1436
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1437
+			$prices = $ticket->prices();
1438
+		}
1439
+		// check if we're dealing with a default ticket in which case
1440
+		// we don't want any starting_ticket_datetime_row values set
1441
+		// (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1442
+		// This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1443
+		$default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1444
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1445
+			? $ticket_datetimes[ $ticket->ID() ]
1446
+			: array();
1447
+		$ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1448
+		$base_price = $default ? null : $ticket->base_price();
1449
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1450
+		// breaking out complicated condition for ticket_status
1451
+		if ($default) {
1452
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1453
+		} else {
1454
+			$ticket_status_class = $ticket->is_default()
1455
+				? ' tkt-status-' . EE_Ticket::onsale
1456
+				: ' tkt-status-' . $ticket->ticket_status();
1457
+		}
1458
+		// breaking out complicated condition for TKT_taxable
1459
+		if ($default) {
1460
+			$TKT_taxable = '';
1461
+		} else {
1462
+			$TKT_taxable = $ticket->taxable()
1463
+				? ' checked="checked"'
1464
+				: '';
1465
+		}
1466
+		if ($default) {
1467
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1468
+		} elseif ($ticket->is_default()) {
1469
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1470
+		} else {
1471
+			$TKT_status = $ticket->ticket_status(true);
1472
+		}
1473
+		if ($default) {
1474
+			$TKT_min = '';
1475
+		} else {
1476
+			$TKT_min = $ticket->min();
1477
+			if ($TKT_min === -1 || $TKT_min === 0) {
1478
+				$TKT_min = '';
1479
+			}
1480
+		}
1481
+		$template_args = array(
1482
+			'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1483
+			'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1484
+			// on initial page load this will always be the correct order.
1485
+			'tkt_status_class'              => $ticket_status_class,
1486
+			'display_edit_tkt_row'          => ' style="display:none;"',
1487
+			'edit_tkt_expanded'             => '',
1488
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1489
+			'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1490
+			'TKT_start_date'                => $default
1491
+				? ''
1492
+				: $ticket->get_date('TKT_start_date', $this->_date_time_format),
1493
+			'TKT_end_date'                  => $default
1494
+				? ''
1495
+				: $ticket->get_date('TKT_end_date', $this->_date_time_format),
1496
+			'TKT_status'                    => $TKT_status,
1497
+			'TKT_price'                     => $default
1498
+				? ''
1499
+				: EEH_Template::format_currency(
1500
+					$ticket->get_ticket_total_with_taxes(),
1501
+					false,
1502
+					false
1503
+				),
1504
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1505
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1506
+			'TKT_qty'                       => $default
1507
+				? ''
1508
+				: $ticket->get_pretty('TKT_qty', 'symbol'),
1509
+			'TKT_qty_for_input'             => $default
1510
+				? ''
1511
+				: $ticket->get_pretty('TKT_qty', 'input'),
1512
+			'TKT_uses'                      => $default
1513
+				? ''
1514
+				: $ticket->get_pretty('TKT_uses', 'input'),
1515
+			'TKT_min'                       => $TKT_min,
1516
+			'TKT_max'                       => $default
1517
+				? ''
1518
+				: $ticket->get_pretty('TKT_max', 'input'),
1519
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1520
+			'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1521
+			'TKT_registrations'             => $default
1522
+				? 0
1523
+				: $ticket->count_registrations(
1524
+					array(
1525
+						array(
1526
+							'STS_ID' => array(
1527
+								'!=',
1528
+								EEM_Registration::status_id_incomplete,
1529
+							),
1530
+						),
1531
+					)
1532
+				),
1533
+			'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1534
+			'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1535
+			'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1536
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1537
+			'TKT_is_default_selector'       => '',
1538
+			'ticket_price_rows'             => '',
1539
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1540
+				? ''
1541
+				: $base_price->get_pretty('PRC_amount', 'localized_float'),
1542
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1543
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1544
+				? ''
1545
+				: ' style="display:none;"',
1546
+			'show_price_mod_button'         => count($prices) > 1
1547
+											   || ($default && $count_price_mods > 0)
1548
+											   || (! $default && $ticket->deleted())
1549
+				? ' style="display:none;"'
1550
+				: '',
1551
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1552
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1553
+			'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1554
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1555
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1556
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1557
+			'TKT_taxable'                   => $TKT_taxable,
1558
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1559
+				? ''
1560
+				: ' style="display:none"',
1561
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1562
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1563
+				$ticket_subtotal,
1564
+				false,
1565
+				false
1566
+			),
1567
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1568
+			'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1569
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1570
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1571
+				? ' ticket-archived'
1572
+				: '',
1573
+			'trash_icon'                    => $ticket instanceof EE_Ticket
1574
+											   && $ticket->deleted()
1575
+											   && ! $ticket->is_permanently_deleteable()
1576
+				? 'ee-lock-icon '
1577
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1578
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1579
+				? ''
1580
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1581
+		);
1582
+		$template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1583
+			? ' style="display:none"'
1584
+			: '';
1585
+		// handle rows that should NOT be empty
1586
+		if (empty($template_args['TKT_start_date'])) {
1587
+			// if empty then the start date will be now.
1588
+			$template_args['TKT_start_date'] = date(
1589
+				$this->_date_time_format,
1590
+				current_time('timestamp')
1591
+			);
1592
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1593
+		}
1594
+		if (empty($template_args['TKT_end_date'])) {
1595
+			// get the earliest datetime (if present);
1596
+			$earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1597
+				? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1598
+					'Datetime',
1599
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1600
+				)
1601
+				: null;
1602
+			if (! empty($earliest_dtt)) {
1603
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1604
+					'DTT_EVT_start',
1605
+					$this->_date_time_format
1606
+				);
1607
+			} else {
1608
+				// default so let's just use what's been set for the default date-time which is 30 days from now.
1609
+				$template_args['TKT_end_date'] = date(
1610
+					$this->_date_time_format,
1611
+					mktime(
1612
+						24,
1613
+						0,
1614
+						0,
1615
+						date('m'),
1616
+						date('d') + 29,
1617
+						date('Y')
1618
+					)
1619
+				);
1620
+			}
1621
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1622
+		}
1623
+		// generate ticket_datetime items
1624
+		if (! $default) {
1625
+			$datetime_row = 1;
1626
+			foreach ($all_datetimes as $datetime) {
1627
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1628
+					$datetime_row,
1629
+					$ticket_row,
1630
+					$datetime,
1631
+					$ticket,
1632
+					$ticket_datetimes,
1633
+					$default
1634
+				);
1635
+				$datetime_row++;
1636
+			}
1637
+		}
1638
+		$price_row = 1;
1639
+		foreach ($prices as $price) {
1640
+			if (! $price instanceof EE_Price) {
1641
+				continue;
1642
+			}
1643
+			if ($price->is_base_price()) {
1644
+				$price_row++;
1645
+				continue;
1646
+			}
1647
+			$show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1648
+			$show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1649
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1650
+				$ticket_row,
1651
+				$price_row,
1652
+				$price,
1653
+				$default,
1654
+				$ticket,
1655
+				$show_trash,
1656
+				$show_create
1657
+			);
1658
+			$price_row++;
1659
+		}
1660
+		// filter $template_args
1661
+		$template_args = apply_filters(
1662
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1663
+			$template_args,
1664
+			$ticket_row,
1665
+			$ticket,
1666
+			$ticket_datetimes,
1667
+			$all_datetimes,
1668
+			$default,
1669
+			$all_tickets,
1670
+			$this->_is_creating_event
1671
+		);
1672
+		return EEH_Template::display_template(
1673
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1674
+			$template_args,
1675
+			true
1676
+		);
1677
+	}
1678 1678
 
1679 1679
 
1680
-    /**
1681
-     * @param int            $ticket_row
1682
-     * @param EE_Ticket|null $ticket
1683
-     * @return string
1684
-     * @throws DomainException
1685
-     * @throws EE_Error
1686
-     */
1687
-    protected function _get_tax_rows($ticket_row, $ticket)
1688
-    {
1689
-        $tax_rows = '';
1690
-        /** @var EE_Price[] $taxes */
1691
-        $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1692
-        foreach ($taxes as $tax) {
1693
-            $tax_added = $this->_get_tax_added($tax, $ticket);
1694
-            $template_args = array(
1695
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1696
-                    ? ''
1697
-                    : ' style="display:none;"',
1698
-                'tax_id'            => $tax->ID(),
1699
-                'tkt_row'           => $ticket_row,
1700
-                'tax_label'         => $tax->get('PRC_name'),
1701
-                'tax_added'         => $tax_added,
1702
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1703
-                'tax_amount'        => $tax->get('PRC_amount'),
1704
-            );
1705
-            $template_args = apply_filters(
1706
-                'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1707
-                $template_args,
1708
-                $ticket_row,
1709
-                $ticket,
1710
-                $this->_is_creating_event
1711
-            );
1712
-            $tax_rows .= EEH_Template::display_template(
1713
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1714
-                $template_args,
1715
-                true
1716
-            );
1717
-        }
1718
-        return $tax_rows;
1719
-    }
1680
+	/**
1681
+	 * @param int            $ticket_row
1682
+	 * @param EE_Ticket|null $ticket
1683
+	 * @return string
1684
+	 * @throws DomainException
1685
+	 * @throws EE_Error
1686
+	 */
1687
+	protected function _get_tax_rows($ticket_row, $ticket)
1688
+	{
1689
+		$tax_rows = '';
1690
+		/** @var EE_Price[] $taxes */
1691
+		$taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1692
+		foreach ($taxes as $tax) {
1693
+			$tax_added = $this->_get_tax_added($tax, $ticket);
1694
+			$template_args = array(
1695
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1696
+					? ''
1697
+					: ' style="display:none;"',
1698
+				'tax_id'            => $tax->ID(),
1699
+				'tkt_row'           => $ticket_row,
1700
+				'tax_label'         => $tax->get('PRC_name'),
1701
+				'tax_added'         => $tax_added,
1702
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1703
+				'tax_amount'        => $tax->get('PRC_amount'),
1704
+			);
1705
+			$template_args = apply_filters(
1706
+				'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1707
+				$template_args,
1708
+				$ticket_row,
1709
+				$ticket,
1710
+				$this->_is_creating_event
1711
+			);
1712
+			$tax_rows .= EEH_Template::display_template(
1713
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1714
+				$template_args,
1715
+				true
1716
+			);
1717
+		}
1718
+		return $tax_rows;
1719
+	}
1720 1720
 
1721 1721
 
1722
-    /**
1723
-     * @param EE_Price       $tax
1724
-     * @param EE_Ticket|null $ticket
1725
-     * @return float|int
1726
-     * @throws EE_Error
1727
-     */
1728
-    protected function _get_tax_added(EE_Price $tax, $ticket)
1729
-    {
1730
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1731
-        return $subtotal * $tax->get('PRC_amount') / 100;
1732
-    }
1722
+	/**
1723
+	 * @param EE_Price       $tax
1724
+	 * @param EE_Ticket|null $ticket
1725
+	 * @return float|int
1726
+	 * @throws EE_Error
1727
+	 */
1728
+	protected function _get_tax_added(EE_Price $tax, $ticket)
1729
+	{
1730
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1731
+		return $subtotal * $tax->get('PRC_amount') / 100;
1732
+	}
1733 1733
 
1734 1734
 
1735
-    /**
1736
-     * @param int            $ticket_row
1737
-     * @param int            $price_row
1738
-     * @param EE_Price|null  $price
1739
-     * @param bool           $default
1740
-     * @param EE_Ticket|null $ticket
1741
-     * @param bool           $show_trash
1742
-     * @param bool           $show_create
1743
-     * @return mixed
1744
-     * @throws InvalidArgumentException
1745
-     * @throws InvalidInterfaceException
1746
-     * @throws InvalidDataTypeException
1747
-     * @throws DomainException
1748
-     * @throws EE_Error
1749
-     * @throws ReflectionException
1750
-     */
1751
-    protected function _get_ticket_price_row(
1752
-        $ticket_row,
1753
-        $price_row,
1754
-        $price,
1755
-        $default,
1756
-        $ticket,
1757
-        $show_trash = true,
1758
-        $show_create = true
1759
-    ) {
1760
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1761
-        $template_args = array(
1762
-            'tkt_row'               => $default && empty($ticket)
1763
-                ? 'TICKETNUM'
1764
-                : $ticket_row,
1765
-            'PRC_order'             => $default && empty($price)
1766
-                ? 'PRICENUM'
1767
-                : $price_row,
1768
-            'edit_prices_name'      => $default && empty($price)
1769
-                ? 'PRICENAMEATTR'
1770
-                : 'edit_prices',
1771
-            'price_type_selector'   => $default && empty($price)
1772
-                ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1773
-                : $this->_get_price_type_selector(
1774
-                    $ticket_row,
1775
-                    $price_row,
1776
-                    $price,
1777
-                    $default,
1778
-                    $send_disabled
1779
-                ),
1780
-            'PRC_ID'                => $default && empty($price)
1781
-                ? 0
1782
-                : $price->ID(),
1783
-            'PRC_is_default'        => $default && empty($price)
1784
-                ? 0
1785
-                : $price->get('PRC_is_default'),
1786
-            'PRC_name'              => $default && empty($price)
1787
-                ? ''
1788
-                : $price->get('PRC_name'),
1789
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1790
-            'show_plus_or_minus'    => $default && empty($price)
1791
-                ? ''
1792
-                : ' style="display:none;"',
1793
-            'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1794
-                ? ' style="display:none;"'
1795
-                : '',
1796
-            'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1797
-                ? ' style="display:none;"'
1798
-                : '',
1799
-            'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1800
-                ? ' style="display:none"'
1801
-                : '',
1802
-            'PRC_amount'            => $default && empty($price)
1803
-                ? 0
1804
-                : $price->get_pretty('PRC_amount', 'localized_float'),
1805
-            'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1806
-                ? ' style="display:none;"'
1807
-                : '',
1808
-            'show_trash_icon'       => $show_trash
1809
-                ? ''
1810
-                : ' style="display:none;"',
1811
-            'show_create_button'    => $show_create
1812
-                ? ''
1813
-                : ' style="display:none;"',
1814
-            'PRC_desc'              => $default && empty($price)
1815
-                ? ''
1816
-                : $price->get('PRC_desc'),
1817
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1818
-        );
1819
-        $template_args = apply_filters(
1820
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1821
-            $template_args,
1822
-            $ticket_row,
1823
-            $price_row,
1824
-            $price,
1825
-            $default,
1826
-            $ticket,
1827
-            $show_trash,
1828
-            $show_create,
1829
-            $this->_is_creating_event
1830
-        );
1831
-        return EEH_Template::display_template(
1832
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1833
-            $template_args,
1834
-            true
1835
-        );
1836
-    }
1735
+	/**
1736
+	 * @param int            $ticket_row
1737
+	 * @param int            $price_row
1738
+	 * @param EE_Price|null  $price
1739
+	 * @param bool           $default
1740
+	 * @param EE_Ticket|null $ticket
1741
+	 * @param bool           $show_trash
1742
+	 * @param bool           $show_create
1743
+	 * @return mixed
1744
+	 * @throws InvalidArgumentException
1745
+	 * @throws InvalidInterfaceException
1746
+	 * @throws InvalidDataTypeException
1747
+	 * @throws DomainException
1748
+	 * @throws EE_Error
1749
+	 * @throws ReflectionException
1750
+	 */
1751
+	protected function _get_ticket_price_row(
1752
+		$ticket_row,
1753
+		$price_row,
1754
+		$price,
1755
+		$default,
1756
+		$ticket,
1757
+		$show_trash = true,
1758
+		$show_create = true
1759
+	) {
1760
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1761
+		$template_args = array(
1762
+			'tkt_row'               => $default && empty($ticket)
1763
+				? 'TICKETNUM'
1764
+				: $ticket_row,
1765
+			'PRC_order'             => $default && empty($price)
1766
+				? 'PRICENUM'
1767
+				: $price_row,
1768
+			'edit_prices_name'      => $default && empty($price)
1769
+				? 'PRICENAMEATTR'
1770
+				: 'edit_prices',
1771
+			'price_type_selector'   => $default && empty($price)
1772
+				? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1773
+				: $this->_get_price_type_selector(
1774
+					$ticket_row,
1775
+					$price_row,
1776
+					$price,
1777
+					$default,
1778
+					$send_disabled
1779
+				),
1780
+			'PRC_ID'                => $default && empty($price)
1781
+				? 0
1782
+				: $price->ID(),
1783
+			'PRC_is_default'        => $default && empty($price)
1784
+				? 0
1785
+				: $price->get('PRC_is_default'),
1786
+			'PRC_name'              => $default && empty($price)
1787
+				? ''
1788
+				: $price->get('PRC_name'),
1789
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1790
+			'show_plus_or_minus'    => $default && empty($price)
1791
+				? ''
1792
+				: ' style="display:none;"',
1793
+			'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1794
+				? ' style="display:none;"'
1795
+				: '',
1796
+			'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1797
+				? ' style="display:none;"'
1798
+				: '',
1799
+			'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1800
+				? ' style="display:none"'
1801
+				: '',
1802
+			'PRC_amount'            => $default && empty($price)
1803
+				? 0
1804
+				: $price->get_pretty('PRC_amount', 'localized_float'),
1805
+			'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1806
+				? ' style="display:none;"'
1807
+				: '',
1808
+			'show_trash_icon'       => $show_trash
1809
+				? ''
1810
+				: ' style="display:none;"',
1811
+			'show_create_button'    => $show_create
1812
+				? ''
1813
+				: ' style="display:none;"',
1814
+			'PRC_desc'              => $default && empty($price)
1815
+				? ''
1816
+				: $price->get('PRC_desc'),
1817
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1818
+		);
1819
+		$template_args = apply_filters(
1820
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1821
+			$template_args,
1822
+			$ticket_row,
1823
+			$price_row,
1824
+			$price,
1825
+			$default,
1826
+			$ticket,
1827
+			$show_trash,
1828
+			$show_create,
1829
+			$this->_is_creating_event
1830
+		);
1831
+		return EEH_Template::display_template(
1832
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1833
+			$template_args,
1834
+			true
1835
+		);
1836
+	}
1837 1837
 
1838 1838
 
1839
-    /**
1840
-     * @param int      $ticket_row
1841
-     * @param int      $price_row
1842
-     * @param EE_Price $price
1843
-     * @param bool     $default
1844
-     * @param bool     $disabled
1845
-     * @return mixed
1846
-     * @throws ReflectionException
1847
-     * @throws InvalidArgumentException
1848
-     * @throws InvalidInterfaceException
1849
-     * @throws InvalidDataTypeException
1850
-     * @throws DomainException
1851
-     * @throws EE_Error
1852
-     */
1853
-    protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1854
-    {
1855
-        if ($price->is_base_price()) {
1856
-            return $this->_get_base_price_template(
1857
-                $ticket_row,
1858
-                $price_row,
1859
-                $price,
1860
-                $default
1861
-            );
1862
-        }
1863
-        return $this->_get_price_modifier_template(
1864
-            $ticket_row,
1865
-            $price_row,
1866
-            $price,
1867
-            $default,
1868
-            $disabled
1869
-        );
1870
-    }
1839
+	/**
1840
+	 * @param int      $ticket_row
1841
+	 * @param int      $price_row
1842
+	 * @param EE_Price $price
1843
+	 * @param bool     $default
1844
+	 * @param bool     $disabled
1845
+	 * @return mixed
1846
+	 * @throws ReflectionException
1847
+	 * @throws InvalidArgumentException
1848
+	 * @throws InvalidInterfaceException
1849
+	 * @throws InvalidDataTypeException
1850
+	 * @throws DomainException
1851
+	 * @throws EE_Error
1852
+	 */
1853
+	protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1854
+	{
1855
+		if ($price->is_base_price()) {
1856
+			return $this->_get_base_price_template(
1857
+				$ticket_row,
1858
+				$price_row,
1859
+				$price,
1860
+				$default
1861
+			);
1862
+		}
1863
+		return $this->_get_price_modifier_template(
1864
+			$ticket_row,
1865
+			$price_row,
1866
+			$price,
1867
+			$default,
1868
+			$disabled
1869
+		);
1870
+	}
1871 1871
 
1872 1872
 
1873
-    /**
1874
-     * @param int      $ticket_row
1875
-     * @param int      $price_row
1876
-     * @param EE_Price $price
1877
-     * @param bool     $default
1878
-     * @return mixed
1879
-     * @throws DomainException
1880
-     * @throws EE_Error
1881
-     */
1882
-    protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1883
-    {
1884
-        $template_args = array(
1885
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1886
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1887
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1888
-            'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1889
-            'price_selected_operator'   => '+',
1890
-            'price_selected_is_percent' => 0,
1891
-        );
1892
-        $template_args = apply_filters(
1893
-            'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1894
-            $template_args,
1895
-            $ticket_row,
1896
-            $price_row,
1897
-            $price,
1898
-            $default,
1899
-            $this->_is_creating_event
1900
-        );
1901
-        return EEH_Template::display_template(
1902
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1903
-            $template_args,
1904
-            true
1905
-        );
1906
-    }
1873
+	/**
1874
+	 * @param int      $ticket_row
1875
+	 * @param int      $price_row
1876
+	 * @param EE_Price $price
1877
+	 * @param bool     $default
1878
+	 * @return mixed
1879
+	 * @throws DomainException
1880
+	 * @throws EE_Error
1881
+	 */
1882
+	protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1883
+	{
1884
+		$template_args = array(
1885
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1886
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1887
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1888
+			'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1889
+			'price_selected_operator'   => '+',
1890
+			'price_selected_is_percent' => 0,
1891
+		);
1892
+		$template_args = apply_filters(
1893
+			'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1894
+			$template_args,
1895
+			$ticket_row,
1896
+			$price_row,
1897
+			$price,
1898
+			$default,
1899
+			$this->_is_creating_event
1900
+		);
1901
+		return EEH_Template::display_template(
1902
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1903
+			$template_args,
1904
+			true
1905
+		);
1906
+	}
1907 1907
 
1908 1908
 
1909
-    /**
1910
-     * @param int      $ticket_row
1911
-     * @param int      $price_row
1912
-     * @param EE_Price $price
1913
-     * @param bool     $default
1914
-     * @param bool     $disabled
1915
-     * @return mixed
1916
-     * @throws ReflectionException
1917
-     * @throws InvalidArgumentException
1918
-     * @throws InvalidInterfaceException
1919
-     * @throws InvalidDataTypeException
1920
-     * @throws DomainException
1921
-     * @throws EE_Error
1922
-     */
1923
-    protected function _get_price_modifier_template(
1924
-        $ticket_row,
1925
-        $price_row,
1926
-        $price,
1927
-        $default,
1928
-        $disabled = false
1929
-    ) {
1930
-        $select_name = $default && ! $price instanceof EE_Price
1931
-            ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1932
-            : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1933
-        /** @var EEM_Price_Type $price_type_model */
1934
-        $price_type_model = EE_Registry::instance()->load_model('Price_Type');
1935
-        $price_types = $price_type_model->get_all(array(
1936
-            array(
1937
-                'OR' => array(
1938
-                    'PBT_ID'  => '2',
1939
-                    'PBT_ID*' => '3',
1940
-                ),
1941
-            ),
1942
-        ));
1943
-        $all_price_types = $default && ! $price instanceof EE_Price
1944
-            ? array(esc_html__('Select Modifier', 'event_espresso'))
1945
-            : array();
1946
-        $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1947
-        $price_option_spans = '';
1948
-        // setup price types for selector
1949
-        foreach ($price_types as $price_type) {
1950
-            if (! $price_type instanceof EE_Price_Type) {
1951
-                continue;
1952
-            }
1953
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1954
-            // while we're in the loop let's setup the option spans used by js
1955
-            $span_args = array(
1956
-                'PRT_ID'         => $price_type->ID(),
1957
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1958
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1959
-            );
1960
-            $price_option_spans .= EEH_Template::display_template(
1961
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1962
-                $span_args,
1963
-                true
1964
-            );
1965
-        }
1966
-        $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1967
-            : $select_name;
1968
-        $select_input = new EE_Select_Input(
1969
-            $all_price_types,
1970
-            array(
1971
-                'default'               => $selected_price_type_id,
1972
-                'html_name'             => $select_name,
1973
-                'html_class'            => 'edit-price-PRT_ID',
1974
-                'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1975
-            )
1976
-        );
1977
-        $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1978
-        $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1979
-        $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1980
-        $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1981
-        $template_args = array(
1982
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1983
-            'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1984
-            'price_modifier_selector'   => $select_input->get_html_for_input(),
1985
-            'main_name'                 => $select_name,
1986
-            'selected_price_type_id'    => $selected_price_type_id,
1987
-            'price_option_spans'        => $price_option_spans,
1988
-            'price_selected_operator'   => $price_selected_operator,
1989
-            'price_selected_is_percent' => $price_selected_is_percent,
1990
-            'disabled'                  => $disabled,
1991
-        );
1992
-        $template_args = apply_filters(
1993
-            'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1994
-            $template_args,
1995
-            $ticket_row,
1996
-            $price_row,
1997
-            $price,
1998
-            $default,
1999
-            $disabled,
2000
-            $this->_is_creating_event
2001
-        );
2002
-        return EEH_Template::display_template(
2003
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2004
-            $template_args,
2005
-            true
2006
-        );
2007
-    }
1909
+	/**
1910
+	 * @param int      $ticket_row
1911
+	 * @param int      $price_row
1912
+	 * @param EE_Price $price
1913
+	 * @param bool     $default
1914
+	 * @param bool     $disabled
1915
+	 * @return mixed
1916
+	 * @throws ReflectionException
1917
+	 * @throws InvalidArgumentException
1918
+	 * @throws InvalidInterfaceException
1919
+	 * @throws InvalidDataTypeException
1920
+	 * @throws DomainException
1921
+	 * @throws EE_Error
1922
+	 */
1923
+	protected function _get_price_modifier_template(
1924
+		$ticket_row,
1925
+		$price_row,
1926
+		$price,
1927
+		$default,
1928
+		$disabled = false
1929
+	) {
1930
+		$select_name = $default && ! $price instanceof EE_Price
1931
+			? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1932
+			: 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1933
+		/** @var EEM_Price_Type $price_type_model */
1934
+		$price_type_model = EE_Registry::instance()->load_model('Price_Type');
1935
+		$price_types = $price_type_model->get_all(array(
1936
+			array(
1937
+				'OR' => array(
1938
+					'PBT_ID'  => '2',
1939
+					'PBT_ID*' => '3',
1940
+				),
1941
+			),
1942
+		));
1943
+		$all_price_types = $default && ! $price instanceof EE_Price
1944
+			? array(esc_html__('Select Modifier', 'event_espresso'))
1945
+			: array();
1946
+		$selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1947
+		$price_option_spans = '';
1948
+		// setup price types for selector
1949
+		foreach ($price_types as $price_type) {
1950
+			if (! $price_type instanceof EE_Price_Type) {
1951
+				continue;
1952
+			}
1953
+			$all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1954
+			// while we're in the loop let's setup the option spans used by js
1955
+			$span_args = array(
1956
+				'PRT_ID'         => $price_type->ID(),
1957
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1958
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1959
+			);
1960
+			$price_option_spans .= EEH_Template::display_template(
1961
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1962
+				$span_args,
1963
+				true
1964
+			);
1965
+		}
1966
+		$select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1967
+			: $select_name;
1968
+		$select_input = new EE_Select_Input(
1969
+			$all_price_types,
1970
+			array(
1971
+				'default'               => $selected_price_type_id,
1972
+				'html_name'             => $select_name,
1973
+				'html_class'            => 'edit-price-PRT_ID',
1974
+				'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1975
+			)
1976
+		);
1977
+		$price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1978
+		$price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1979
+		$price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1980
+		$price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1981
+		$template_args = array(
1982
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1983
+			'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1984
+			'price_modifier_selector'   => $select_input->get_html_for_input(),
1985
+			'main_name'                 => $select_name,
1986
+			'selected_price_type_id'    => $selected_price_type_id,
1987
+			'price_option_spans'        => $price_option_spans,
1988
+			'price_selected_operator'   => $price_selected_operator,
1989
+			'price_selected_is_percent' => $price_selected_is_percent,
1990
+			'disabled'                  => $disabled,
1991
+		);
1992
+		$template_args = apply_filters(
1993
+			'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1994
+			$template_args,
1995
+			$ticket_row,
1996
+			$price_row,
1997
+			$price,
1998
+			$default,
1999
+			$disabled,
2000
+			$this->_is_creating_event
2001
+		);
2002
+		return EEH_Template::display_template(
2003
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2004
+			$template_args,
2005
+			true
2006
+		);
2007
+	}
2008 2008
 
2009 2009
 
2010
-    /**
2011
-     * @param int              $datetime_row
2012
-     * @param int              $ticket_row
2013
-     * @param EE_Datetime|null $datetime
2014
-     * @param EE_Ticket|null   $ticket
2015
-     * @param array            $ticket_datetimes
2016
-     * @param bool             $default
2017
-     * @return mixed
2018
-     * @throws DomainException
2019
-     * @throws EE_Error
2020
-     */
2021
-    protected function _get_ticket_datetime_list_item(
2022
-        $datetime_row,
2023
-        $ticket_row,
2024
-        $datetime,
2025
-        $ticket,
2026
-        $ticket_datetimes = array(),
2027
-        $default
2028
-    ) {
2029
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2030
-            ? $ticket_datetimes[ $ticket->ID() ]
2031
-            : array();
2032
-        $template_args = array(
2033
-            'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2034
-                ? 'DTTNUM'
2035
-                : $datetime_row,
2036
-            'tkt_row'                  => $default
2037
-                ? 'TICKETNUM'
2038
-                : $ticket_row,
2039
-            'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2040
-                ? ' ticket-selected'
2041
-                : '',
2042
-            'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2043
-                ? ' checked="checked"'
2044
-                : '',
2045
-            'DTT_name'                 => $default && empty($datetime)
2046
-                ? 'DTTNAME'
2047
-                : $datetime->get_dtt_display_name(true),
2048
-            'tkt_status_class'         => '',
2049
-        );
2050
-        $template_args = apply_filters(
2051
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2052
-            $template_args,
2053
-            $datetime_row,
2054
-            $ticket_row,
2055
-            $datetime,
2056
-            $ticket,
2057
-            $ticket_datetimes,
2058
-            $default,
2059
-            $this->_is_creating_event
2060
-        );
2061
-        return EEH_Template::display_template(
2062
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2063
-            $template_args,
2064
-            true
2065
-        );
2066
-    }
2010
+	/**
2011
+	 * @param int              $datetime_row
2012
+	 * @param int              $ticket_row
2013
+	 * @param EE_Datetime|null $datetime
2014
+	 * @param EE_Ticket|null   $ticket
2015
+	 * @param array            $ticket_datetimes
2016
+	 * @param bool             $default
2017
+	 * @return mixed
2018
+	 * @throws DomainException
2019
+	 * @throws EE_Error
2020
+	 */
2021
+	protected function _get_ticket_datetime_list_item(
2022
+		$datetime_row,
2023
+		$ticket_row,
2024
+		$datetime,
2025
+		$ticket,
2026
+		$ticket_datetimes = array(),
2027
+		$default
2028
+	) {
2029
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2030
+			? $ticket_datetimes[ $ticket->ID() ]
2031
+			: array();
2032
+		$template_args = array(
2033
+			'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2034
+				? 'DTTNUM'
2035
+				: $datetime_row,
2036
+			'tkt_row'                  => $default
2037
+				? 'TICKETNUM'
2038
+				: $ticket_row,
2039
+			'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2040
+				? ' ticket-selected'
2041
+				: '',
2042
+			'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2043
+				? ' checked="checked"'
2044
+				: '',
2045
+			'DTT_name'                 => $default && empty($datetime)
2046
+				? 'DTTNAME'
2047
+				: $datetime->get_dtt_display_name(true),
2048
+			'tkt_status_class'         => '',
2049
+		);
2050
+		$template_args = apply_filters(
2051
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2052
+			$template_args,
2053
+			$datetime_row,
2054
+			$ticket_row,
2055
+			$datetime,
2056
+			$ticket,
2057
+			$ticket_datetimes,
2058
+			$default,
2059
+			$this->_is_creating_event
2060
+		);
2061
+		return EEH_Template::display_template(
2062
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2063
+			$template_args,
2064
+			true
2065
+		);
2066
+	}
2067 2067
 
2068 2068
 
2069
-    /**
2070
-     * @param array $all_datetimes
2071
-     * @param array $all_tickets
2072
-     * @return mixed
2073
-     * @throws ReflectionException
2074
-     * @throws InvalidArgumentException
2075
-     * @throws InvalidInterfaceException
2076
-     * @throws InvalidDataTypeException
2077
-     * @throws DomainException
2078
-     * @throws EE_Error
2079
-     */
2080
-    protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2081
-    {
2082
-        $template_args = array(
2083
-            'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2084
-                'DTTNUM',
2085
-                null,
2086
-                true,
2087
-                $all_datetimes
2088
-            ),
2089
-            'default_ticket_row'                       => $this->_get_ticket_row(
2090
-                'TICKETNUM',
2091
-                null,
2092
-                array(),
2093
-                array(),
2094
-                true
2095
-            ),
2096
-            'default_price_row'                        => $this->_get_ticket_price_row(
2097
-                'TICKETNUM',
2098
-                'PRICENUM',
2099
-                null,
2100
-                true,
2101
-                null
2102
-            ),
2103
-            'default_price_rows'                       => '',
2104
-            'default_base_price_amount'                => 0,
2105
-            'default_base_price_name'                  => '',
2106
-            'default_base_price_description'           => '',
2107
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2108
-                'TICKETNUM',
2109
-                'PRICENUM',
2110
-                null,
2111
-                true
2112
-            ),
2113
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2114
-                'DTTNUM',
2115
-                null,
2116
-                array(),
2117
-                array(),
2118
-                true
2119
-            ),
2120
-            'existing_available_datetime_tickets_list' => '',
2121
-            'existing_available_ticket_datetimes_list' => '',
2122
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2123
-                'DTTNUM',
2124
-                'TICKETNUM',
2125
-                null,
2126
-                null,
2127
-                array(),
2128
-                true
2129
-            ),
2130
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2131
-                'DTTNUM',
2132
-                'TICKETNUM',
2133
-                null,
2134
-                null,
2135
-                array(),
2136
-                true
2137
-            ),
2138
-        );
2139
-        $ticket_row = 1;
2140
-        foreach ($all_tickets as $ticket) {
2141
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2142
-                'DTTNUM',
2143
-                $ticket_row,
2144
-                null,
2145
-                $ticket,
2146
-                array(),
2147
-                true
2148
-            );
2149
-            $ticket_row++;
2150
-        }
2151
-        $datetime_row = 1;
2152
-        foreach ($all_datetimes as $datetime) {
2153
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2154
-                $datetime_row,
2155
-                'TICKETNUM',
2156
-                $datetime,
2157
-                null,
2158
-                array(),
2159
-                true
2160
-            );
2161
-            $datetime_row++;
2162
-        }
2163
-        /** @var EEM_Price $price_model */
2164
-        $price_model = EE_Registry::instance()->load_model('Price');
2165
-        $default_prices = $price_model->get_all_default_prices();
2166
-        $price_row = 1;
2167
-        foreach ($default_prices as $price) {
2168
-            if (! $price instanceof EE_Price) {
2169
-                continue;
2170
-            }
2171
-            if ($price->is_base_price()) {
2172
-                $template_args['default_base_price_amount'] = $price->get_pretty(
2173
-                    'PRC_amount',
2174
-                    'localized_float'
2175
-                );
2176
-                $template_args['default_base_price_name'] = $price->get('PRC_name');
2177
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
2178
-                $price_row++;
2179
-                continue;
2180
-            }
2181
-            $show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2182
-                             || count($default_prices) === 1);
2183
-            $show_create = ! (count($default_prices) > 1
2184
-                              && count($default_prices)
2185
-                                 !== $price_row);
2186
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2187
-                'TICKETNUM',
2188
-                $price_row,
2189
-                $price,
2190
-                true,
2191
-                null,
2192
-                $show_trash,
2193
-                $show_create
2194
-            );
2195
-            $price_row++;
2196
-        }
2197
-        $template_args = apply_filters(
2198
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2199
-            $template_args,
2200
-            $all_datetimes,
2201
-            $all_tickets,
2202
-            $this->_is_creating_event
2203
-        );
2204
-        return EEH_Template::display_template(
2205
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2206
-            $template_args,
2207
-            true
2208
-        );
2209
-    }
2069
+	/**
2070
+	 * @param array $all_datetimes
2071
+	 * @param array $all_tickets
2072
+	 * @return mixed
2073
+	 * @throws ReflectionException
2074
+	 * @throws InvalidArgumentException
2075
+	 * @throws InvalidInterfaceException
2076
+	 * @throws InvalidDataTypeException
2077
+	 * @throws DomainException
2078
+	 * @throws EE_Error
2079
+	 */
2080
+	protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2081
+	{
2082
+		$template_args = array(
2083
+			'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2084
+				'DTTNUM',
2085
+				null,
2086
+				true,
2087
+				$all_datetimes
2088
+			),
2089
+			'default_ticket_row'                       => $this->_get_ticket_row(
2090
+				'TICKETNUM',
2091
+				null,
2092
+				array(),
2093
+				array(),
2094
+				true
2095
+			),
2096
+			'default_price_row'                        => $this->_get_ticket_price_row(
2097
+				'TICKETNUM',
2098
+				'PRICENUM',
2099
+				null,
2100
+				true,
2101
+				null
2102
+			),
2103
+			'default_price_rows'                       => '',
2104
+			'default_base_price_amount'                => 0,
2105
+			'default_base_price_name'                  => '',
2106
+			'default_base_price_description'           => '',
2107
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2108
+				'TICKETNUM',
2109
+				'PRICENUM',
2110
+				null,
2111
+				true
2112
+			),
2113
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2114
+				'DTTNUM',
2115
+				null,
2116
+				array(),
2117
+				array(),
2118
+				true
2119
+			),
2120
+			'existing_available_datetime_tickets_list' => '',
2121
+			'existing_available_ticket_datetimes_list' => '',
2122
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2123
+				'DTTNUM',
2124
+				'TICKETNUM',
2125
+				null,
2126
+				null,
2127
+				array(),
2128
+				true
2129
+			),
2130
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2131
+				'DTTNUM',
2132
+				'TICKETNUM',
2133
+				null,
2134
+				null,
2135
+				array(),
2136
+				true
2137
+			),
2138
+		);
2139
+		$ticket_row = 1;
2140
+		foreach ($all_tickets as $ticket) {
2141
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2142
+				'DTTNUM',
2143
+				$ticket_row,
2144
+				null,
2145
+				$ticket,
2146
+				array(),
2147
+				true
2148
+			);
2149
+			$ticket_row++;
2150
+		}
2151
+		$datetime_row = 1;
2152
+		foreach ($all_datetimes as $datetime) {
2153
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2154
+				$datetime_row,
2155
+				'TICKETNUM',
2156
+				$datetime,
2157
+				null,
2158
+				array(),
2159
+				true
2160
+			);
2161
+			$datetime_row++;
2162
+		}
2163
+		/** @var EEM_Price $price_model */
2164
+		$price_model = EE_Registry::instance()->load_model('Price');
2165
+		$default_prices = $price_model->get_all_default_prices();
2166
+		$price_row = 1;
2167
+		foreach ($default_prices as $price) {
2168
+			if (! $price instanceof EE_Price) {
2169
+				continue;
2170
+			}
2171
+			if ($price->is_base_price()) {
2172
+				$template_args['default_base_price_amount'] = $price->get_pretty(
2173
+					'PRC_amount',
2174
+					'localized_float'
2175
+				);
2176
+				$template_args['default_base_price_name'] = $price->get('PRC_name');
2177
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
2178
+				$price_row++;
2179
+				continue;
2180
+			}
2181
+			$show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2182
+							 || count($default_prices) === 1);
2183
+			$show_create = ! (count($default_prices) > 1
2184
+							  && count($default_prices)
2185
+								 !== $price_row);
2186
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2187
+				'TICKETNUM',
2188
+				$price_row,
2189
+				$price,
2190
+				true,
2191
+				null,
2192
+				$show_trash,
2193
+				$show_create
2194
+			);
2195
+			$price_row++;
2196
+		}
2197
+		$template_args = apply_filters(
2198
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2199
+			$template_args,
2200
+			$all_datetimes,
2201
+			$all_tickets,
2202
+			$this->_is_creating_event
2203
+		);
2204
+		return EEH_Template::display_template(
2205
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2206
+			$template_args,
2207
+			true
2208
+		);
2209
+	}
2210 2210
 }
Please login to merge, or discard this patch.