Completed
Branch FET/paypal-pro-cardinal-integr... (d98144)
by
unknown
26:37 queued 18:23
created
core/EE_Config.core.php 2 patches
Indentation   +3154 added lines, -3154 removed lines patch added patch discarded remove patch
@@ -14,2509 +14,2509 @@  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('/', $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 . '/' . $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 . '/' . $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 . '/' . $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 . '/' . $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('\\', '/'), '/', $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('/', $module_path);
1159
-            // remove last segment
1160
-            array_pop($module_path);
1161
-            // glue it back together
1162
-            $module_path = implode('/', $module_path) . '/';
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, '/') . '/';
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 . '/' . $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
-}
1501
-
1502
-/**
1503
- * Base class used for config classes. These classes should generally not have
1504
- * magic functions in use, except we'll allow them to magically set and get stuff...
1505
- * basically, they should just be well-defined stdClasses
1506
- */
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;
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('/', $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 . '/' . $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 . '/' . $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 . '/' . $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 . '/' . $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('\\', '/'), '/', $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('/', $module_path);
1159
+			// remove last segment
1160
+			array_pop($module_path);
1161
+			// glue it back together
1162
+			$module_path = implode('/', $module_path) . '/';
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, '/') . '/';
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 . '/' . $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
+}
2262 1501
 
2263
-    /**
2264
-     * ReCaptcha Type
2265
-     *
2266
-     * @var string $recaptcha_type
2267
-     *    options: 'audio', 'image'
2268
-     */
2269
-    public $recaptcha_type;
1502
+/**
1503
+ * Base class used for config classes. These classes should generally not have
1504
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1505
+ * basically, they should just be well-defined stdClasses
1506
+ */
1507
+class EE_Config_Base
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,157 +2525,157 @@  discard block
 block discarded – undo
2525 2525
 class EE_Admin_Config extends EE_Config_Base
2526 2526
 {
2527 2527
 
2528
-    /**
2529
-     * @var boolean $use_personnel_manager
2530
-     */
2531
-    public $use_personnel_manager;
2532
-
2533
-    /**
2534
-     * @var boolean $use_dashboard_widget
2535
-     */
2536
-    public $use_dashboard_widget;
2537
-
2538
-    /**
2539
-     * @var int $events_in_dashboard
2540
-     */
2541
-    public $events_in_dashboard;
2542
-
2543
-    /**
2544
-     * @var boolean $use_event_timezones
2545
-     */
2546
-    public $use_event_timezones;
2547
-
2548
-    /**
2549
-     * @var boolean $use_full_logging
2550
-     */
2551
-    public $use_full_logging;
2552
-
2553
-    /**
2554
-     * @var string $log_file_name
2555
-     */
2556
-    public $log_file_name;
2557
-
2558
-    /**
2559
-     * @var string $debug_file_name
2560
-     */
2561
-    public $debug_file_name;
2562
-
2563
-    /**
2564
-     * @var boolean $use_remote_logging
2565
-     */
2566
-    public $use_remote_logging;
2567
-
2568
-    /**
2569
-     * @var string $remote_logging_url
2570
-     */
2571
-    public $remote_logging_url;
2572
-
2573
-    /**
2574
-     * @var boolean $show_reg_footer
2575
-     */
2576
-    public $show_reg_footer;
2577
-
2578
-    /**
2579
-     * @var string $affiliate_id
2580
-     */
2581
-    public $affiliate_id;
2582
-
2583
-    /**
2584
-     * help tours on or off (global setting)
2585
-     *
2586
-     * @var boolean
2587
-     */
2588
-    public $help_tour_activation;
2589
-
2590
-    /**
2591
-     * adds extra layer of encoding to session data to prevent serialization errors
2592
-     * but is incompatible with some server configuration errors
2593
-     * if you get "500 internal server errors" during registration, try turning this on
2594
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2595
-     *
2596
-     * @var boolean $encode_session_data
2597
-     */
2598
-    private $encode_session_data = false;
2599
-
2600
-
2601
-    /**
2602
-     *    class constructor
2603
-     *
2604
-     * @access    public
2605
-     */
2606
-    public function __construct()
2607
-    {
2608
-        // set default general admin settings
2609
-        $this->use_personnel_manager = true;
2610
-        $this->use_dashboard_widget = true;
2611
-        $this->events_in_dashboard = 30;
2612
-        $this->use_event_timezones = false;
2613
-        $this->use_full_logging = false;
2614
-        $this->use_remote_logging = false;
2615
-        $this->remote_logging_url = null;
2616
-        $this->show_reg_footer = apply_filters(
2617
-            'FHEE__EE_Admin_Config__show_reg_footer__default',
2618
-            false
2619
-        );
2620
-        $this->affiliate_id = 'default';
2621
-        $this->help_tour_activation = true;
2622
-        $this->encode_session_data = false;
2623
-    }
2624
-
2625
-
2626
-    /**
2627
-     * @param bool $reset
2628
-     * @return string
2629
-     */
2630
-    public function log_file_name($reset = false)
2631
-    {
2632
-        if (empty($this->log_file_name) || $reset) {
2633
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2634
-            EE_Config::instance()->update_espresso_config(false, false);
2635
-        }
2636
-        return $this->log_file_name;
2637
-    }
2638
-
2639
-
2640
-    /**
2641
-     * @param bool $reset
2642
-     * @return string
2643
-     */
2644
-    public function debug_file_name($reset = false)
2645
-    {
2646
-        if (empty($this->debug_file_name) || $reset) {
2647
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2648
-            EE_Config::instance()->update_espresso_config(false, false);
2649
-        }
2650
-        return $this->debug_file_name;
2651
-    }
2652
-
2653
-
2654
-    /**
2655
-     * @return string
2656
-     */
2657
-    public function affiliate_id()
2658
-    {
2659
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2660
-    }
2661
-
2662
-
2663
-    /**
2664
-     * @return boolean
2665
-     */
2666
-    public function encode_session_data()
2667
-    {
2668
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2669
-    }
2670
-
2671
-
2672
-    /**
2673
-     * @param boolean $encode_session_data
2674
-     */
2675
-    public function set_encode_session_data($encode_session_data)
2676
-    {
2677
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2678
-    }
2528
+	/**
2529
+	 * @var boolean $use_personnel_manager
2530
+	 */
2531
+	public $use_personnel_manager;
2532
+
2533
+	/**
2534
+	 * @var boolean $use_dashboard_widget
2535
+	 */
2536
+	public $use_dashboard_widget;
2537
+
2538
+	/**
2539
+	 * @var int $events_in_dashboard
2540
+	 */
2541
+	public $events_in_dashboard;
2542
+
2543
+	/**
2544
+	 * @var boolean $use_event_timezones
2545
+	 */
2546
+	public $use_event_timezones;
2547
+
2548
+	/**
2549
+	 * @var boolean $use_full_logging
2550
+	 */
2551
+	public $use_full_logging;
2552
+
2553
+	/**
2554
+	 * @var string $log_file_name
2555
+	 */
2556
+	public $log_file_name;
2557
+
2558
+	/**
2559
+	 * @var string $debug_file_name
2560
+	 */
2561
+	public $debug_file_name;
2562
+
2563
+	/**
2564
+	 * @var boolean $use_remote_logging
2565
+	 */
2566
+	public $use_remote_logging;
2567
+
2568
+	/**
2569
+	 * @var string $remote_logging_url
2570
+	 */
2571
+	public $remote_logging_url;
2572
+
2573
+	/**
2574
+	 * @var boolean $show_reg_footer
2575
+	 */
2576
+	public $show_reg_footer;
2577
+
2578
+	/**
2579
+	 * @var string $affiliate_id
2580
+	 */
2581
+	public $affiliate_id;
2582
+
2583
+	/**
2584
+	 * help tours on or off (global setting)
2585
+	 *
2586
+	 * @var boolean
2587
+	 */
2588
+	public $help_tour_activation;
2589
+
2590
+	/**
2591
+	 * adds extra layer of encoding to session data to prevent serialization errors
2592
+	 * but is incompatible with some server configuration errors
2593
+	 * if you get "500 internal server errors" during registration, try turning this on
2594
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2595
+	 *
2596
+	 * @var boolean $encode_session_data
2597
+	 */
2598
+	private $encode_session_data = false;
2599
+
2600
+
2601
+	/**
2602
+	 *    class constructor
2603
+	 *
2604
+	 * @access    public
2605
+	 */
2606
+	public function __construct()
2607
+	{
2608
+		// set default general admin settings
2609
+		$this->use_personnel_manager = true;
2610
+		$this->use_dashboard_widget = true;
2611
+		$this->events_in_dashboard = 30;
2612
+		$this->use_event_timezones = false;
2613
+		$this->use_full_logging = false;
2614
+		$this->use_remote_logging = false;
2615
+		$this->remote_logging_url = null;
2616
+		$this->show_reg_footer = apply_filters(
2617
+			'FHEE__EE_Admin_Config__show_reg_footer__default',
2618
+			false
2619
+		);
2620
+		$this->affiliate_id = 'default';
2621
+		$this->help_tour_activation = true;
2622
+		$this->encode_session_data = false;
2623
+	}
2624
+
2625
+
2626
+	/**
2627
+	 * @param bool $reset
2628
+	 * @return string
2629
+	 */
2630
+	public function log_file_name($reset = false)
2631
+	{
2632
+		if (empty($this->log_file_name) || $reset) {
2633
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2634
+			EE_Config::instance()->update_espresso_config(false, false);
2635
+		}
2636
+		return $this->log_file_name;
2637
+	}
2638
+
2639
+
2640
+	/**
2641
+	 * @param bool $reset
2642
+	 * @return string
2643
+	 */
2644
+	public function debug_file_name($reset = false)
2645
+	{
2646
+		if (empty($this->debug_file_name) || $reset) {
2647
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2648
+			EE_Config::instance()->update_espresso_config(false, false);
2649
+		}
2650
+		return $this->debug_file_name;
2651
+	}
2652
+
2653
+
2654
+	/**
2655
+	 * @return string
2656
+	 */
2657
+	public function affiliate_id()
2658
+	{
2659
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2660
+	}
2661
+
2662
+
2663
+	/**
2664
+	 * @return boolean
2665
+	 */
2666
+	public function encode_session_data()
2667
+	{
2668
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2669
+	}
2670
+
2671
+
2672
+	/**
2673
+	 * @param boolean $encode_session_data
2674
+	 */
2675
+	public function set_encode_session_data($encode_session_data)
2676
+	{
2677
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2678
+	}
2679 2679
 }
2680 2680
 
2681 2681
 /**
@@ -2684,70 +2684,70 @@  discard block
 block discarded – undo
2684 2684
 class EE_Template_Config extends EE_Config_Base
2685 2685
 {
2686 2686
 
2687
-    /**
2688
-     * @var boolean $enable_default_style
2689
-     */
2690
-    public $enable_default_style;
2691
-
2692
-    /**
2693
-     * @var string $custom_style_sheet
2694
-     */
2695
-    public $custom_style_sheet;
2696
-
2697
-    /**
2698
-     * @var boolean $display_address_in_regform
2699
-     */
2700
-    public $display_address_in_regform;
2701
-
2702
-    /**
2703
-     * @var int $display_description_on_multi_reg_page
2704
-     */
2705
-    public $display_description_on_multi_reg_page;
2706
-
2707
-    /**
2708
-     * @var boolean $use_custom_templates
2709
-     */
2710
-    public $use_custom_templates;
2711
-
2712
-    /**
2713
-     * @var string $current_espresso_theme
2714
-     */
2715
-    public $current_espresso_theme;
2716
-
2717
-    /**
2718
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2719
-     */
2720
-    public $EED_Ticket_Selector;
2721
-
2722
-    /**
2723
-     * @var EE_Event_Single_Config $EED_Event_Single
2724
-     */
2725
-    public $EED_Event_Single;
2726
-
2727
-    /**
2728
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2729
-     */
2730
-    public $EED_Events_Archive;
2731
-
2732
-
2733
-    /**
2734
-     *    class constructor
2735
-     *
2736
-     * @access    public
2737
-     */
2738
-    public function __construct()
2739
-    {
2740
-        // set default template settings
2741
-        $this->enable_default_style = true;
2742
-        $this->custom_style_sheet = null;
2743
-        $this->display_address_in_regform = true;
2744
-        $this->display_description_on_multi_reg_page = false;
2745
-        $this->use_custom_templates = false;
2746
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2747
-        $this->EED_Event_Single = null;
2748
-        $this->EED_Events_Archive = null;
2749
-        $this->EED_Ticket_Selector = null;
2750
-    }
2687
+	/**
2688
+	 * @var boolean $enable_default_style
2689
+	 */
2690
+	public $enable_default_style;
2691
+
2692
+	/**
2693
+	 * @var string $custom_style_sheet
2694
+	 */
2695
+	public $custom_style_sheet;
2696
+
2697
+	/**
2698
+	 * @var boolean $display_address_in_regform
2699
+	 */
2700
+	public $display_address_in_regform;
2701
+
2702
+	/**
2703
+	 * @var int $display_description_on_multi_reg_page
2704
+	 */
2705
+	public $display_description_on_multi_reg_page;
2706
+
2707
+	/**
2708
+	 * @var boolean $use_custom_templates
2709
+	 */
2710
+	public $use_custom_templates;
2711
+
2712
+	/**
2713
+	 * @var string $current_espresso_theme
2714
+	 */
2715
+	public $current_espresso_theme;
2716
+
2717
+	/**
2718
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2719
+	 */
2720
+	public $EED_Ticket_Selector;
2721
+
2722
+	/**
2723
+	 * @var EE_Event_Single_Config $EED_Event_Single
2724
+	 */
2725
+	public $EED_Event_Single;
2726
+
2727
+	/**
2728
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2729
+	 */
2730
+	public $EED_Events_Archive;
2731
+
2732
+
2733
+	/**
2734
+	 *    class constructor
2735
+	 *
2736
+	 * @access    public
2737
+	 */
2738
+	public function __construct()
2739
+	{
2740
+		// set default template settings
2741
+		$this->enable_default_style = true;
2742
+		$this->custom_style_sheet = null;
2743
+		$this->display_address_in_regform = true;
2744
+		$this->display_description_on_multi_reg_page = false;
2745
+		$this->use_custom_templates = false;
2746
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2747
+		$this->EED_Event_Single = null;
2748
+		$this->EED_Events_Archive = null;
2749
+		$this->EED_Ticket_Selector = null;
2750
+	}
2751 2751
 }
2752 2752
 
2753 2753
 /**
@@ -2756,114 +2756,114 @@  discard block
 block discarded – undo
2756 2756
 class EE_Map_Config extends EE_Config_Base
2757 2757
 {
2758 2758
 
2759
-    /**
2760
-     * @var boolean $use_google_maps
2761
-     */
2762
-    public $use_google_maps;
2763
-
2764
-    /**
2765
-     * @var string $api_key
2766
-     */
2767
-    public $google_map_api_key;
2768
-
2769
-    /**
2770
-     * @var int $event_details_map_width
2771
-     */
2772
-    public $event_details_map_width;
2773
-
2774
-    /**
2775
-     * @var int $event_details_map_height
2776
-     */
2777
-    public $event_details_map_height;
2778
-
2779
-    /**
2780
-     * @var int $event_details_map_zoom
2781
-     */
2782
-    public $event_details_map_zoom;
2783
-
2784
-    /**
2785
-     * @var boolean $event_details_display_nav
2786
-     */
2787
-    public $event_details_display_nav;
2788
-
2789
-    /**
2790
-     * @var boolean $event_details_nav_size
2791
-     */
2792
-    public $event_details_nav_size;
2793
-
2794
-    /**
2795
-     * @var string $event_details_control_type
2796
-     */
2797
-    public $event_details_control_type;
2798
-
2799
-    /**
2800
-     * @var string $event_details_map_align
2801
-     */
2802
-    public $event_details_map_align;
2803
-
2804
-    /**
2805
-     * @var int $event_list_map_width
2806
-     */
2807
-    public $event_list_map_width;
2808
-
2809
-    /**
2810
-     * @var int $event_list_map_height
2811
-     */
2812
-    public $event_list_map_height;
2813
-
2814
-    /**
2815
-     * @var int $event_list_map_zoom
2816
-     */
2817
-    public $event_list_map_zoom;
2818
-
2819
-    /**
2820
-     * @var boolean $event_list_display_nav
2821
-     */
2822
-    public $event_list_display_nav;
2823
-
2824
-    /**
2825
-     * @var boolean $event_list_nav_size
2826
-     */
2827
-    public $event_list_nav_size;
2828
-
2829
-    /**
2830
-     * @var string $event_list_control_type
2831
-     */
2832
-    public $event_list_control_type;
2833
-
2834
-    /**
2835
-     * @var string $event_list_map_align
2836
-     */
2837
-    public $event_list_map_align;
2838
-
2839
-
2840
-    /**
2841
-     *    class constructor
2842
-     *
2843
-     * @access    public
2844
-     */
2845
-    public function __construct()
2846
-    {
2847
-        // set default map settings
2848
-        $this->use_google_maps = true;
2849
-        $this->google_map_api_key = '';
2850
-        // for event details pages (reg page)
2851
-        $this->event_details_map_width = 585;            // ee_map_width_single
2852
-        $this->event_details_map_height = 362;            // ee_map_height_single
2853
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2854
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2855
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2856
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2857
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2858
-        // for event list pages
2859
-        $this->event_list_map_width = 300;            // ee_map_width
2860
-        $this->event_list_map_height = 185;        // ee_map_height
2861
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2862
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2863
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2864
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2865
-        $this->event_list_map_align = 'center';            // ee_map_align
2866
-    }
2759
+	/**
2760
+	 * @var boolean $use_google_maps
2761
+	 */
2762
+	public $use_google_maps;
2763
+
2764
+	/**
2765
+	 * @var string $api_key
2766
+	 */
2767
+	public $google_map_api_key;
2768
+
2769
+	/**
2770
+	 * @var int $event_details_map_width
2771
+	 */
2772
+	public $event_details_map_width;
2773
+
2774
+	/**
2775
+	 * @var int $event_details_map_height
2776
+	 */
2777
+	public $event_details_map_height;
2778
+
2779
+	/**
2780
+	 * @var int $event_details_map_zoom
2781
+	 */
2782
+	public $event_details_map_zoom;
2783
+
2784
+	/**
2785
+	 * @var boolean $event_details_display_nav
2786
+	 */
2787
+	public $event_details_display_nav;
2788
+
2789
+	/**
2790
+	 * @var boolean $event_details_nav_size
2791
+	 */
2792
+	public $event_details_nav_size;
2793
+
2794
+	/**
2795
+	 * @var string $event_details_control_type
2796
+	 */
2797
+	public $event_details_control_type;
2798
+
2799
+	/**
2800
+	 * @var string $event_details_map_align
2801
+	 */
2802
+	public $event_details_map_align;
2803
+
2804
+	/**
2805
+	 * @var int $event_list_map_width
2806
+	 */
2807
+	public $event_list_map_width;
2808
+
2809
+	/**
2810
+	 * @var int $event_list_map_height
2811
+	 */
2812
+	public $event_list_map_height;
2813
+
2814
+	/**
2815
+	 * @var int $event_list_map_zoom
2816
+	 */
2817
+	public $event_list_map_zoom;
2818
+
2819
+	/**
2820
+	 * @var boolean $event_list_display_nav
2821
+	 */
2822
+	public $event_list_display_nav;
2823
+
2824
+	/**
2825
+	 * @var boolean $event_list_nav_size
2826
+	 */
2827
+	public $event_list_nav_size;
2828
+
2829
+	/**
2830
+	 * @var string $event_list_control_type
2831
+	 */
2832
+	public $event_list_control_type;
2833
+
2834
+	/**
2835
+	 * @var string $event_list_map_align
2836
+	 */
2837
+	public $event_list_map_align;
2838
+
2839
+
2840
+	/**
2841
+	 *    class constructor
2842
+	 *
2843
+	 * @access    public
2844
+	 */
2845
+	public function __construct()
2846
+	{
2847
+		// set default map settings
2848
+		$this->use_google_maps = true;
2849
+		$this->google_map_api_key = '';
2850
+		// for event details pages (reg page)
2851
+		$this->event_details_map_width = 585;            // ee_map_width_single
2852
+		$this->event_details_map_height = 362;            // ee_map_height_single
2853
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2854
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2855
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2856
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2857
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2858
+		// for event list pages
2859
+		$this->event_list_map_width = 300;            // ee_map_width
2860
+		$this->event_list_map_height = 185;        // ee_map_height
2861
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2862
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2863
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2864
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2865
+		$this->event_list_map_align = 'center';            // ee_map_align
2866
+	}
2867 2867
 }
2868 2868
 
2869 2869
 /**
@@ -2872,46 +2872,46 @@  discard block
 block discarded – undo
2872 2872
 class EE_Events_Archive_Config extends EE_Config_Base
2873 2873
 {
2874 2874
 
2875
-    public $display_status_banner;
2875
+	public $display_status_banner;
2876 2876
 
2877
-    public $display_description;
2877
+	public $display_description;
2878 2878
 
2879
-    public $display_ticket_selector;
2879
+	public $display_ticket_selector;
2880 2880
 
2881
-    public $display_datetimes;
2881
+	public $display_datetimes;
2882 2882
 
2883
-    public $display_venue;
2883
+	public $display_venue;
2884 2884
 
2885
-    public $display_expired_events;
2885
+	public $display_expired_events;
2886 2886
 
2887
-    public $use_sortable_display_order;
2887
+	public $use_sortable_display_order;
2888 2888
 
2889
-    public $display_order_tickets;
2889
+	public $display_order_tickets;
2890 2890
 
2891
-    public $display_order_datetimes;
2891
+	public $display_order_datetimes;
2892 2892
 
2893
-    public $display_order_event;
2893
+	public $display_order_event;
2894 2894
 
2895
-    public $display_order_venue;
2895
+	public $display_order_venue;
2896 2896
 
2897 2897
 
2898
-    /**
2899
-     *    class constructor
2900
-     */
2901
-    public function __construct()
2902
-    {
2903
-        $this->display_status_banner = 0;
2904
-        $this->display_description = 1;
2905
-        $this->display_ticket_selector = 0;
2906
-        $this->display_datetimes = 1;
2907
-        $this->display_venue = 0;
2908
-        $this->display_expired_events = 0;
2909
-        $this->use_sortable_display_order = false;
2910
-        $this->display_order_tickets = 100;
2911
-        $this->display_order_datetimes = 110;
2912
-        $this->display_order_event = 120;
2913
-        $this->display_order_venue = 130;
2914
-    }
2898
+	/**
2899
+	 *    class constructor
2900
+	 */
2901
+	public function __construct()
2902
+	{
2903
+		$this->display_status_banner = 0;
2904
+		$this->display_description = 1;
2905
+		$this->display_ticket_selector = 0;
2906
+		$this->display_datetimes = 1;
2907
+		$this->display_venue = 0;
2908
+		$this->display_expired_events = 0;
2909
+		$this->use_sortable_display_order = false;
2910
+		$this->display_order_tickets = 100;
2911
+		$this->display_order_datetimes = 110;
2912
+		$this->display_order_event = 120;
2913
+		$this->display_order_venue = 130;
2914
+	}
2915 2915
 }
2916 2916
 
2917 2917
 /**
@@ -2920,34 +2920,34 @@  discard block
 block discarded – undo
2920 2920
 class EE_Event_Single_Config extends EE_Config_Base
2921 2921
 {
2922 2922
 
2923
-    public $display_status_banner_single;
2923
+	public $display_status_banner_single;
2924 2924
 
2925
-    public $display_venue;
2925
+	public $display_venue;
2926 2926
 
2927
-    public $use_sortable_display_order;
2927
+	public $use_sortable_display_order;
2928 2928
 
2929
-    public $display_order_tickets;
2929
+	public $display_order_tickets;
2930 2930
 
2931
-    public $display_order_datetimes;
2931
+	public $display_order_datetimes;
2932 2932
 
2933
-    public $display_order_event;
2933
+	public $display_order_event;
2934 2934
 
2935
-    public $display_order_venue;
2935
+	public $display_order_venue;
2936 2936
 
2937 2937
 
2938
-    /**
2939
-     *    class constructor
2940
-     */
2941
-    public function __construct()
2942
-    {
2943
-        $this->display_status_banner_single = 0;
2944
-        $this->display_venue = 1;
2945
-        $this->use_sortable_display_order = false;
2946
-        $this->display_order_tickets = 100;
2947
-        $this->display_order_datetimes = 110;
2948
-        $this->display_order_event = 120;
2949
-        $this->display_order_venue = 130;
2950
-    }
2938
+	/**
2939
+	 *    class constructor
2940
+	 */
2941
+	public function __construct()
2942
+	{
2943
+		$this->display_status_banner_single = 0;
2944
+		$this->display_venue = 1;
2945
+		$this->use_sortable_display_order = false;
2946
+		$this->display_order_tickets = 100;
2947
+		$this->display_order_datetimes = 110;
2948
+		$this->display_order_event = 120;
2949
+		$this->display_order_venue = 130;
2950
+	}
2951 2951
 }
2952 2952
 
2953 2953
 /**
@@ -2956,172 +2956,172 @@  discard block
 block discarded – undo
2956 2956
 class EE_Ticket_Selector_Config extends EE_Config_Base
2957 2957
 {
2958 2958
 
2959
-    /**
2960
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2961
-     */
2962
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2963
-
2964
-    /**
2965
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2966
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2967
-     */
2968
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2969
-
2970
-    /**
2971
-     * @var boolean $show_ticket_sale_columns
2972
-     */
2973
-    public $show_ticket_sale_columns;
2974
-
2975
-    /**
2976
-     * @var boolean $show_ticket_details
2977
-     */
2978
-    public $show_ticket_details;
2979
-
2980
-    /**
2981
-     * @var boolean $show_expired_tickets
2982
-     */
2983
-    public $show_expired_tickets;
2984
-
2985
-    /**
2986
-     * whether or not to display a dropdown box populated with event datetimes
2987
-     * that toggles which tickets are displayed for a ticket selector.
2988
-     * uses one of the *_DATETIME_SELECTOR constants defined above
2989
-     *
2990
-     * @var string $show_datetime_selector
2991
-     */
2992
-    private $show_datetime_selector = 'no_datetime_selector';
2993
-
2994
-    /**
2995
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
2996
-     *
2997
-     * @var int $datetime_selector_threshold
2998
-     */
2999
-    private $datetime_selector_threshold = 3;
3000
-
3001
-    /**
3002
-     * determines the maximum number of "checked" dates in the date and time filter
3003
-     *
3004
-     * @var int $datetime_selector_checked
3005
-     */
3006
-    private $datetime_selector_max_checked = 10;
3007
-
3008
-
3009
-    /**
3010
-     *    class constructor
3011
-     */
3012
-    public function __construct()
3013
-    {
3014
-        $this->show_ticket_sale_columns = true;
3015
-        $this->show_ticket_details = true;
3016
-        $this->show_expired_tickets = true;
3017
-        $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3018
-        $this->datetime_selector_threshold = 3;
3019
-        $this->datetime_selector_max_checked = 10;
3020
-    }
3021
-
3022
-
3023
-    /**
3024
-     * returns true if a datetime selector should be displayed
3025
-     *
3026
-     * @param array $datetimes
3027
-     * @return bool
3028
-     */
3029
-    public function showDatetimeSelector(array $datetimes)
3030
-    {
3031
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
3032
-        return ! (
3033
-            $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3034
-            || (
3035
-                $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3036
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
3037
-            )
3038
-        );
3039
-    }
3040
-
3041
-
3042
-    /**
3043
-     * @return string
3044
-     */
3045
-    public function getShowDatetimeSelector()
3046
-    {
3047
-        return $this->show_datetime_selector;
3048
-    }
3049
-
3050
-
3051
-    /**
3052
-     * @param bool $keys_only
3053
-     * @return array
3054
-     */
3055
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3056
-    {
3057
-        return $keys_only
3058
-            ? array(
3059
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3060
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3061
-            )
3062
-            : array(
3063
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3064
-                    'Do not show date & time filter',
3065
-                    'event_espresso'
3066
-                ),
3067
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3068
-                    'Maybe show date & time filter',
3069
-                    'event_espresso'
3070
-                ),
3071
-            );
3072
-    }
3073
-
3074
-
3075
-    /**
3076
-     * @param string $show_datetime_selector
3077
-     */
3078
-    public function setShowDatetimeSelector($show_datetime_selector)
3079
-    {
3080
-        $this->show_datetime_selector = in_array(
3081
-            $show_datetime_selector,
3082
-            $this->getShowDatetimeSelectorOptions(),
3083
-            true
3084
-        )
3085
-            ? $show_datetime_selector
3086
-            : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3087
-    }
3088
-
3089
-
3090
-    /**
3091
-     * @return int
3092
-     */
3093
-    public function getDatetimeSelectorThreshold()
3094
-    {
3095
-        return $this->datetime_selector_threshold;
3096
-    }
3097
-
3098
-
3099
-    /**
3100
-     * @param int $datetime_selector_threshold
3101
-     */
3102
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3103
-    {
3104
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3105
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3106
-    }
3107
-
3108
-
3109
-    /**
3110
-     * @return int
3111
-     */
3112
-    public function getDatetimeSelectorMaxChecked()
3113
-    {
3114
-        return $this->datetime_selector_max_checked;
3115
-    }
3116
-
3117
-
3118
-    /**
3119
-     * @param int $datetime_selector_max_checked
3120
-     */
3121
-    public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3122
-    {
3123
-        $this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3124
-    }
2959
+	/**
2960
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2961
+	 */
2962
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2963
+
2964
+	/**
2965
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2966
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2967
+	 */
2968
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2969
+
2970
+	/**
2971
+	 * @var boolean $show_ticket_sale_columns
2972
+	 */
2973
+	public $show_ticket_sale_columns;
2974
+
2975
+	/**
2976
+	 * @var boolean $show_ticket_details
2977
+	 */
2978
+	public $show_ticket_details;
2979
+
2980
+	/**
2981
+	 * @var boolean $show_expired_tickets
2982
+	 */
2983
+	public $show_expired_tickets;
2984
+
2985
+	/**
2986
+	 * whether or not to display a dropdown box populated with event datetimes
2987
+	 * that toggles which tickets are displayed for a ticket selector.
2988
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
2989
+	 *
2990
+	 * @var string $show_datetime_selector
2991
+	 */
2992
+	private $show_datetime_selector = 'no_datetime_selector';
2993
+
2994
+	/**
2995
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
2996
+	 *
2997
+	 * @var int $datetime_selector_threshold
2998
+	 */
2999
+	private $datetime_selector_threshold = 3;
3000
+
3001
+	/**
3002
+	 * determines the maximum number of "checked" dates in the date and time filter
3003
+	 *
3004
+	 * @var int $datetime_selector_checked
3005
+	 */
3006
+	private $datetime_selector_max_checked = 10;
3007
+
3008
+
3009
+	/**
3010
+	 *    class constructor
3011
+	 */
3012
+	public function __construct()
3013
+	{
3014
+		$this->show_ticket_sale_columns = true;
3015
+		$this->show_ticket_details = true;
3016
+		$this->show_expired_tickets = true;
3017
+		$this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3018
+		$this->datetime_selector_threshold = 3;
3019
+		$this->datetime_selector_max_checked = 10;
3020
+	}
3021
+
3022
+
3023
+	/**
3024
+	 * returns true if a datetime selector should be displayed
3025
+	 *
3026
+	 * @param array $datetimes
3027
+	 * @return bool
3028
+	 */
3029
+	public function showDatetimeSelector(array $datetimes)
3030
+	{
3031
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
3032
+		return ! (
3033
+			$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3034
+			|| (
3035
+				$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3036
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
3037
+			)
3038
+		);
3039
+	}
3040
+
3041
+
3042
+	/**
3043
+	 * @return string
3044
+	 */
3045
+	public function getShowDatetimeSelector()
3046
+	{
3047
+		return $this->show_datetime_selector;
3048
+	}
3049
+
3050
+
3051
+	/**
3052
+	 * @param bool $keys_only
3053
+	 * @return array
3054
+	 */
3055
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3056
+	{
3057
+		return $keys_only
3058
+			? array(
3059
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3060
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3061
+			)
3062
+			: array(
3063
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3064
+					'Do not show date & time filter',
3065
+					'event_espresso'
3066
+				),
3067
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3068
+					'Maybe show date & time filter',
3069
+					'event_espresso'
3070
+				),
3071
+			);
3072
+	}
3073
+
3074
+
3075
+	/**
3076
+	 * @param string $show_datetime_selector
3077
+	 */
3078
+	public function setShowDatetimeSelector($show_datetime_selector)
3079
+	{
3080
+		$this->show_datetime_selector = in_array(
3081
+			$show_datetime_selector,
3082
+			$this->getShowDatetimeSelectorOptions(),
3083
+			true
3084
+		)
3085
+			? $show_datetime_selector
3086
+			: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3087
+	}
3088
+
3089
+
3090
+	/**
3091
+	 * @return int
3092
+	 */
3093
+	public function getDatetimeSelectorThreshold()
3094
+	{
3095
+		return $this->datetime_selector_threshold;
3096
+	}
3097
+
3098
+
3099
+	/**
3100
+	 * @param int $datetime_selector_threshold
3101
+	 */
3102
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3103
+	{
3104
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3105
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3106
+	}
3107
+
3108
+
3109
+	/**
3110
+	 * @return int
3111
+	 */
3112
+	public function getDatetimeSelectorMaxChecked()
3113
+	{
3114
+		return $this->datetime_selector_max_checked;
3115
+	}
3116
+
3117
+
3118
+	/**
3119
+	 * @param int $datetime_selector_max_checked
3120
+	 */
3121
+	public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3122
+	{
3123
+		$this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3124
+	}
3125 3125
 }
3126 3126
 
3127 3127
 /**
@@ -3134,86 +3134,86 @@  discard block
 block discarded – undo
3134 3134
 class EE_Environment_Config extends EE_Config_Base
3135 3135
 {
3136 3136
 
3137
-    /**
3138
-     * Hold any php environment variables that we want to track.
3139
-     *
3140
-     * @var stdClass;
3141
-     */
3142
-    public $php;
3143
-
3144
-
3145
-    /**
3146
-     *    constructor
3147
-     */
3148
-    public function __construct()
3149
-    {
3150
-        $this->php = new stdClass();
3151
-        $this->_set_php_values();
3152
-    }
3153
-
3154
-
3155
-    /**
3156
-     * This sets the php environment variables.
3157
-     *
3158
-     * @since 4.4.0
3159
-     * @return void
3160
-     */
3161
-    protected function _set_php_values()
3162
-    {
3163
-        $this->php->max_input_vars = ini_get('max_input_vars');
3164
-        $this->php->version = phpversion();
3165
-    }
3166
-
3167
-
3168
-    /**
3169
-     * helper method for determining whether input_count is
3170
-     * reaching the potential maximum the server can handle
3171
-     * according to max_input_vars
3172
-     *
3173
-     * @param int   $input_count the count of input vars.
3174
-     * @return array {
3175
-     *                           An array that represents whether available space and if no available space the error
3176
-     *                           message.
3177
-     * @type bool   $has_space   whether more inputs can be added.
3178
-     * @type string $msg         Any message to be displayed.
3179
-     *                           }
3180
-     */
3181
-    public function max_input_vars_limit_check($input_count = 0)
3182
-    {
3183
-        if (! empty($this->php->max_input_vars)
3184
-            && ($input_count >= $this->php->max_input_vars)
3185
-        ) {
3186
-            // check the server setting because the config value could be stale
3187
-            $max_input_vars = ini_get('max_input_vars');
3188
-            if ($input_count >= $max_input_vars) {
3189
-                return sprintf(
3190
-                    esc_html__(
3191
-                        '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.',
3192
-                        'event_espresso'
3193
-                    ),
3194
-                    '<br>',
3195
-                    $input_count,
3196
-                    $max_input_vars
3197
-                );
3198
-            } else {
3199
-                return '';
3200
-            }
3201
-        } else {
3202
-            return '';
3203
-        }
3204
-    }
3205
-
3206
-
3207
-    /**
3208
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3209
-     *
3210
-     * @since 4.4.1
3211
-     * @return void
3212
-     */
3213
-    public function recheck_values()
3214
-    {
3215
-        $this->_set_php_values();
3216
-    }
3137
+	/**
3138
+	 * Hold any php environment variables that we want to track.
3139
+	 *
3140
+	 * @var stdClass;
3141
+	 */
3142
+	public $php;
3143
+
3144
+
3145
+	/**
3146
+	 *    constructor
3147
+	 */
3148
+	public function __construct()
3149
+	{
3150
+		$this->php = new stdClass();
3151
+		$this->_set_php_values();
3152
+	}
3153
+
3154
+
3155
+	/**
3156
+	 * This sets the php environment variables.
3157
+	 *
3158
+	 * @since 4.4.0
3159
+	 * @return void
3160
+	 */
3161
+	protected function _set_php_values()
3162
+	{
3163
+		$this->php->max_input_vars = ini_get('max_input_vars');
3164
+		$this->php->version = phpversion();
3165
+	}
3166
+
3167
+
3168
+	/**
3169
+	 * helper method for determining whether input_count is
3170
+	 * reaching the potential maximum the server can handle
3171
+	 * according to max_input_vars
3172
+	 *
3173
+	 * @param int   $input_count the count of input vars.
3174
+	 * @return array {
3175
+	 *                           An array that represents whether available space and if no available space the error
3176
+	 *                           message.
3177
+	 * @type bool   $has_space   whether more inputs can be added.
3178
+	 * @type string $msg         Any message to be displayed.
3179
+	 *                           }
3180
+	 */
3181
+	public function max_input_vars_limit_check($input_count = 0)
3182
+	{
3183
+		if (! empty($this->php->max_input_vars)
3184
+			&& ($input_count >= $this->php->max_input_vars)
3185
+		) {
3186
+			// check the server setting because the config value could be stale
3187
+			$max_input_vars = ini_get('max_input_vars');
3188
+			if ($input_count >= $max_input_vars) {
3189
+				return sprintf(
3190
+					esc_html__(
3191
+						'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.',
3192
+						'event_espresso'
3193
+					),
3194
+					'<br>',
3195
+					$input_count,
3196
+					$max_input_vars
3197
+				);
3198
+			} else {
3199
+				return '';
3200
+			}
3201
+		} else {
3202
+			return '';
3203
+		}
3204
+	}
3205
+
3206
+
3207
+	/**
3208
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3209
+	 *
3210
+	 * @since 4.4.1
3211
+	 * @return void
3212
+	 */
3213
+	public function recheck_values()
3214
+	{
3215
+		$this->_set_php_values();
3216
+	}
3217 3217
 }
3218 3218
 
3219 3219
 /**
@@ -3226,21 +3226,21 @@  discard block
 block discarded – undo
3226 3226
 class EE_Tax_Config extends EE_Config_Base
3227 3227
 {
3228 3228
 
3229
-    /*
3229
+	/*
3230 3230
      * flag to indicate whether or not to display ticket prices with the taxes included
3231 3231
      *
3232 3232
      * @var boolean $prices_displayed_including_taxes
3233 3233
      */
3234
-    public $prices_displayed_including_taxes;
3234
+	public $prices_displayed_including_taxes;
3235 3235
 
3236 3236
 
3237
-    /**
3238
-     *    class constructor
3239
-     */
3240
-    public function __construct()
3241
-    {
3242
-        $this->prices_displayed_including_taxes = true;
3243
-    }
3237
+	/**
3238
+	 *    class constructor
3239
+	 */
3240
+	public function __construct()
3241
+	{
3242
+		$this->prices_displayed_including_taxes = true;
3243
+	}
3244 3244
 }
3245 3245
 
3246 3246
 /**
@@ -3254,19 +3254,19 @@  discard block
 block discarded – undo
3254 3254
 class EE_Messages_Config extends EE_Config_Base
3255 3255
 {
3256 3256
 
3257
-    /**
3258
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3259
-     * A value of 0 represents never deleting.  Default is 0.
3260
-     *
3261
-     * @var integer
3262
-     */
3263
-    public $delete_threshold;
3257
+	/**
3258
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3259
+	 * A value of 0 represents never deleting.  Default is 0.
3260
+	 *
3261
+	 * @var integer
3262
+	 */
3263
+	public $delete_threshold;
3264 3264
 
3265 3265
 
3266
-    public function __construct()
3267
-    {
3268
-        $this->delete_threshold = 0;
3269
-    }
3266
+	public function __construct()
3267
+	{
3268
+		$this->delete_threshold = 0;
3269
+	}
3270 3270
 }
3271 3271
 
3272 3272
 /**
@@ -3277,31 +3277,31 @@  discard block
 block discarded – undo
3277 3277
 class EE_Gateway_Config extends EE_Config_Base
3278 3278
 {
3279 3279
 
3280
-    /**
3281
-     * Array with keys that are payment gateways slugs, and values are arrays
3282
-     * with any config info the gateway wants to store
3283
-     *
3284
-     * @var array
3285
-     */
3286
-    public $payment_settings;
3287
-
3288
-    /**
3289
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3290
-     * the gateway is stored in the uploads directory
3291
-     *
3292
-     * @var array
3293
-     */
3294
-    public $active_gateways;
3295
-
3296
-
3297
-    /**
3298
-     *    class constructor
3299
-     *
3300
-     * @deprecated
3301
-     */
3302
-    public function __construct()
3303
-    {
3304
-        $this->payment_settings = array();
3305
-        $this->active_gateways = array('Invoice' => false);
3306
-    }
3280
+	/**
3281
+	 * Array with keys that are payment gateways slugs, and values are arrays
3282
+	 * with any config info the gateway wants to store
3283
+	 *
3284
+	 * @var array
3285
+	 */
3286
+	public $payment_settings;
3287
+
3288
+	/**
3289
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3290
+	 * the gateway is stored in the uploads directory
3291
+	 *
3292
+	 * @var array
3293
+	 */
3294
+	public $active_gateways;
3295
+
3296
+
3297
+	/**
3298
+	 *    class constructor
3299
+	 *
3300
+	 * @deprecated
3301
+	 */
3302
+	public function __construct()
3303
+	{
3304
+		$this->payment_settings = array();
3305
+		$this->active_gateways = array('Invoice' => false);
3306
+	}
3307 3307
 }
Please login to merge, or discard this patch.
Spacing   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
     public static function instance()
146 146
     {
147 147
         // check if class object is instantiated, and instantiated properly
148
-        if (! self::$_instance instanceof EE_Config) {
148
+        if ( ! self::$_instance instanceof EE_Config) {
149 149
             self::$_instance = new self();
150 150
         }
151 151
         return self::$_instance;
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
                 $this
284 284
             );
285 285
             if (is_object($settings) && property_exists($this, $config)) {
286
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
286
+                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__'.$config, $settings);
287 287
                 // call configs populate method to ensure any defaults are set for empty values.
288 288
                 if (method_exists($settings, 'populate')) {
289 289
                     $this->{$config}->populate();
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
                         break;
557 557
                     // TEST #2 : check that settings section exists
558 558
                     case 2:
559
-                        if (! isset($this->{$section})) {
559
+                        if ( ! isset($this->{$section})) {
560 560
                             if ($display_errors) {
561 561
                                 throw new EE_Error(
562 562
                                     sprintf(
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
                         break;
571 571
                     // TEST #3 : check that section is the proper format
572 572
                     case 3:
573
-                        if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
573
+                        if ( ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
574 574
                         ) {
575 575
                             if ($display_errors) {
576 576
                                 throw new EE_Error(
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
                         break;
617 617
                     // TEST #6 : verify config class is accessible
618 618
                     case 6:
619
-                        if (! class_exists($config_class)) {
619
+                        if ( ! class_exists($config_class)) {
620 620
                             if ($display_errors) {
621 621
                                 throw new EE_Error(
622 622
                                     sprintf(
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
                         break;
634 634
                     // TEST #7 : check that config has even been set
635 635
                     case 7:
636
-                        if (! isset($this->{$section}->{$name})) {
636
+                        if ( ! isset($this->{$section}->{$name})) {
637 637
                             if ($display_errors) {
638 638
                                 throw new EE_Error(
639 639
                                     sprintf(
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
                         break;
652 652
                     // TEST #8 : check that config is the requested type
653 653
                     case 8:
654
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
654
+                        if ( ! $this->{$section}->{$name} instanceof $config_class) {
655 655
                             if ($display_errors) {
656 656
                                 throw new EE_Error(
657 657
                                     sprintf(
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
                         break;
671 671
                     // TEST #9 : verify config object
672 672
                     case 9:
673
-                        if (! $config_obj instanceof EE_Config_Base) {
673
+                        if ( ! $config_obj instanceof EE_Config_Base) {
674 674
                             if ($display_errors) {
675 675
                                 throw new EE_Error(
676 676
                                     sprintf(
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
      */
703 703
     private function _generate_config_option_name($section = '', $name = '')
704 704
     {
705
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
705
+        return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name));
706 706
     }
707 707
 
708 708
 
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
     {
720 720
         return ! empty($config_class)
721 721
             ? $config_class
722
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
722
+            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config';
723 723
     }
724 724
 
725 725
 
@@ -738,17 +738,17 @@  discard block
 block discarded – undo
738 738
         // ensure config class is set to something
739 739
         $config_class = $this->_set_config_class($config_class, $name);
740 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))) {
741
+        if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
742 742
             return null;
743 743
         }
744 744
         $config_option_name = $this->_generate_config_option_name($section, $name);
745 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;
746
+        if ( ! isset($this->_addon_option_names[$config_option_name])) {
747
+            $this->_addon_option_names[$config_option_name] = $config_class;
748 748
             $this->update_addon_option_names();
749 749
         }
750 750
         // verify the incoming config object but suppress errors
751
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
751
+        if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
752 752
             $config_obj = new $config_class();
753 753
         }
754 754
         if (get_option($config_option_name)) {
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
         // get class name of the incoming object
796 796
         $config_class = get_class($config_obj);
797 797
         // run tests 1-5 and 9 to verify config
798
-        if (! $this->_verify_config_params(
798
+        if ( ! $this->_verify_config_params(
799 799
             $section,
800 800
             $name,
801 801
             $config_class,
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
         }
808 808
         $config_option_name = $this->_generate_config_option_name($section, $name);
809 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 ])) {
810
+        if ( ! isset($this->_addon_option_names[$config_option_name])) {
811 811
             // save new config to db
812 812
             if ($this->set_config($section, $name, $config_class, $config_obj)) {
813 813
                 return true;
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
                             'event_espresso'
834 834
                         ),
835 835
                         $config_class,
836
-                        'EE_Config->' . $section . '->' . $name
836
+                        'EE_Config->'.$section.'->'.$name
837 837
                     ),
838 838
                     __FILE__,
839 839
                     __FUNCTION__,
@@ -859,7 +859,7 @@  discard block
 block discarded – undo
859 859
         // ensure config class is set to something
860 860
         $config_class = $this->_set_config_class($config_class, $name);
861 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))) {
862
+        if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
863 863
             return null;
864 864
         }
865 865
         // now test if the requested config object exists, but suppress errors
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
         // retrieve the wp-option for this config class.
905 905
         $config_option = maybe_unserialize(get_option($config_option_name, array()));
906 906
         if (empty($config_option)) {
907
-            EE_Config::log($config_option_name . '-NOT-FOUND');
907
+            EE_Config::log($config_option_name.'-NOT-FOUND');
908 908
         }
909 909
         return $config_option;
910 910
     }
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
             // copy incoming $_REQUEST and sanitize it so we can save it
923 923
             $_request = $_REQUEST;
924 924
             array_walk_recursive($_request, 'sanitize_text_field');
925
-            $config_log[ (string) microtime(true) ] = array(
925
+            $config_log[(string) microtime(true)] = array(
926 926
                 'config_name' => $config_option_name,
927 927
                 'request'     => $_request,
928 928
             );
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
      */
938 938
     public static function trim_log()
939 939
     {
940
-        if (! EE_Config::logging_enabled()) {
940
+        if ( ! EE_Config::logging_enabled()) {
941 941
             return;
942 942
         }
943 943
         $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
     public static function get_page_for_posts()
962 962
     {
963 963
         $page_for_posts = get_option('page_for_posts');
964
-        if (! $page_for_posts) {
964
+        if ( ! $page_for_posts) {
965 965
             return 'posts';
966 966
         }
967 967
         /** @type WPDB $wpdb */
@@ -1011,20 +1011,20 @@  discard block
 block discarded – undo
1011 1011
     {
1012 1012
         // only init widgets on admin pages when not in complete maintenance, and
1013 1013
         // on frontend when not in any maintenance mode
1014
-        if (! EE_Maintenance_Mode::instance()->level()
1014
+        if ( ! EE_Maintenance_Mode::instance()->level()
1015 1015
             || (
1016 1016
                 is_admin()
1017 1017
                 && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1018 1018
             )
1019 1019
         ) {
1020 1020
             // grab list of installed widgets
1021
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1021
+            $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR);
1022 1022
             // filter list of modules to register
1023 1023
             $widgets_to_register = apply_filters(
1024 1024
                 'FHEE__EE_Config__register_widgets__widgets_to_register',
1025 1025
                 $widgets_to_register
1026 1026
             );
1027
-            if (! empty($widgets_to_register)) {
1027
+            if ( ! empty($widgets_to_register)) {
1028 1028
                 // cycle thru widget folders
1029 1029
                 foreach ($widgets_to_register as $widget_path) {
1030 1030
                     // add to list of installed widget modules
@@ -1074,31 +1074,31 @@  discard block
 block discarded – undo
1074 1074
         // create classname from widget directory name
1075 1075
         $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1076 1076
         // add class prefix
1077
-        $widget_class = 'EEW_' . $widget;
1077
+        $widget_class = 'EEW_'.$widget;
1078 1078
         // does the widget exist ?
1079
-        if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) {
1079
+        if ( ! is_readable($widget_path.'/'.$widget_class.$widget_ext)) {
1080 1080
             $msg = sprintf(
1081 1081
                 __(
1082 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 1083
                     'event_espresso'
1084 1084
                 ),
1085 1085
                 $widget_class,
1086
-                $widget_path . '/' . $widget_class . $widget_ext
1086
+                $widget_path.'/'.$widget_class.$widget_ext
1087 1087
             );
1088
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1088
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1089 1089
             return;
1090 1090
         }
1091 1091
         // load the widget class file
1092
-        require_once($widget_path . '/' . $widget_class . $widget_ext);
1092
+        require_once($widget_path.'/'.$widget_class.$widget_ext);
1093 1093
         // verify that class exists
1094
-        if (! class_exists($widget_class)) {
1094
+        if ( ! class_exists($widget_class)) {
1095 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__);
1096
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1097 1097
             return;
1098 1098
         }
1099 1099
         register_widget($widget_class);
1100 1100
         // add to array of registered widgets
1101
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext;
1101
+        EE_Registry::instance()->widgets->{$widget_class} = $widget_path.'/'.$widget_class.$widget_ext;
1102 1102
     }
1103 1103
 
1104 1104
 
@@ -1111,18 +1111,18 @@  discard block
 block discarded – undo
1111 1111
     private function _register_modules()
1112 1112
     {
1113 1113
         // grab list of installed modules
1114
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1114
+        $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR);
1115 1115
         // filter list of modules to register
1116 1116
         $modules_to_register = apply_filters(
1117 1117
             'FHEE__EE_Config__register_modules__modules_to_register',
1118 1118
             $modules_to_register
1119 1119
         );
1120
-        if (! empty($modules_to_register)) {
1120
+        if ( ! empty($modules_to_register)) {
1121 1121
             // loop through folders
1122 1122
             foreach ($modules_to_register as $module_path) {
1123 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'
1124
+                if ($module_path !== EE_MODULES.'zzz-copy-this-module-template'
1125
+                    && $module_path !== EE_MODULES.'gateways'
1126 1126
                 ) {
1127 1127
                     // add to list of installed modules
1128 1128
                     EE_Config::register_module($module_path);
@@ -1159,25 +1159,25 @@  discard block
 block discarded – undo
1159 1159
             // remove last segment
1160 1160
             array_pop($module_path);
1161 1161
             // glue it back together
1162
-            $module_path = implode('/', $module_path) . '/';
1162
+            $module_path = implode('/', $module_path).'/';
1163 1163
             // take first segment from file name pieces and sanitize it
1164 1164
             $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1165 1165
             // ensure class prefix is added
1166
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1166
+            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module;
1167 1167
         } else {
1168 1168
             // we need to generate the filename based off of the folder name
1169 1169
             // grab and sanitize module name
1170 1170
             $module = strtolower(basename($module_path));
1171 1171
             $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1172 1172
             // like trailingslashit()
1173
-            $module_path = rtrim($module_path, '/') . '/';
1173
+            $module_path = rtrim($module_path, '/').'/';
1174 1174
             // create classname from module directory name
1175 1175
             $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1176 1176
             // add class prefix
1177
-            $module_class = 'EED_' . $module;
1177
+            $module_class = 'EED_'.$module;
1178 1178
         }
1179 1179
         // does the module exist ?
1180
-        if (! is_readable($module_path . '/' . $module_class . $module_ext)) {
1180
+        if ( ! is_readable($module_path.'/'.$module_class.$module_ext)) {
1181 1181
             $msg = sprintf(
1182 1182
                 __(
1183 1183
                     'The requested %s module file could not be found or is not readable due to file permissions.',
@@ -1185,19 +1185,19 @@  discard block
 block discarded – undo
1185 1185
                 ),
1186 1186
                 $module
1187 1187
             );
1188
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1188
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1189 1189
             return false;
1190 1190
         }
1191 1191
         // load the module class file
1192
-        require_once($module_path . $module_class . $module_ext);
1192
+        require_once($module_path.$module_class.$module_ext);
1193 1193
         // verify that class exists
1194
-        if (! class_exists($module_class)) {
1194
+        if ( ! class_exists($module_class)) {
1195 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__);
1196
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1197 1197
             return false;
1198 1198
         }
1199 1199
         // add to array of registered modules
1200
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1200
+        EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext;
1201 1201
         do_action(
1202 1202
             'AHEE__EE_Config__register_module__complete',
1203 1203
             $module_class,
@@ -1248,26 +1248,26 @@  discard block
 block discarded – undo
1248 1248
     {
1249 1249
         do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1250 1250
         $module = str_replace('EED_', '', $module);
1251
-        $module_class = 'EED_' . $module;
1252
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1251
+        $module_class = 'EED_'.$module;
1252
+        if ( ! isset(EE_Registry::instance()->modules->{$module_class})) {
1253 1253
             $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1254
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1254
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1255 1255
             return false;
1256 1256
         }
1257 1257
         if (empty($route)) {
1258 1258
             $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1259
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1259
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1260 1260
             return false;
1261 1261
         }
1262
-        if (! method_exists('EED_' . $module, $method_name)) {
1262
+        if ( ! method_exists('EED_'.$module, $method_name)) {
1263 1263
             $msg = sprintf(
1264 1264
                 __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1265 1265
                 $route
1266 1266
             );
1267
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1267
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1268 1268
             return false;
1269 1269
         }
1270
-        EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1270
+        EE_Config::$_module_route_map[(string) $key][(string) $route] = array('EED_'.$module, $method_name);
1271 1271
         return true;
1272 1272
     }
1273 1273
 
@@ -1284,8 +1284,8 @@  discard block
 block discarded – undo
1284 1284
     {
1285 1285
         do_action('AHEE__EE_Config__get_route__begin', $route);
1286 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 ];
1287
+        if (isset(EE_Config::$_module_route_map[$key][$route])) {
1288
+            return EE_Config::$_module_route_map[$key][$route];
1289 1289
         }
1290 1290
         return null;
1291 1291
     }
@@ -1317,47 +1317,47 @@  discard block
 block discarded – undo
1317 1317
     public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1318 1318
     {
1319 1319
         do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1320
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1320
+        if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1321 1321
             $msg = sprintf(
1322 1322
                 __('The module route %s for this forward has not been registered.', 'event_espresso'),
1323 1323
                 $route
1324 1324
             );
1325
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1325
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1326 1326
             return false;
1327 1327
         }
1328 1328
         if (empty($forward)) {
1329 1329
             $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1330
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1330
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1331 1331
             return false;
1332 1332
         }
1333 1333
         if (is_array($forward)) {
1334
-            if (! isset($forward[1])) {
1334
+            if ( ! isset($forward[1])) {
1335 1335
                 $msg = sprintf(
1336 1336
                     __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1337 1337
                     $route
1338 1338
                 );
1339
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1339
+                EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1340 1340
                 return false;
1341 1341
             }
1342
-            if (! method_exists($forward[0], $forward[1])) {
1342
+            if ( ! method_exists($forward[0], $forward[1])) {
1343 1343
                 $msg = sprintf(
1344 1344
                     __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1345 1345
                     $forward[1],
1346 1346
                     $route
1347 1347
                 );
1348
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1348
+                EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1349 1349
                 return false;
1350 1350
             }
1351
-        } elseif (! function_exists($forward)) {
1351
+        } elseif ( ! function_exists($forward)) {
1352 1352
             $msg = sprintf(
1353 1353
                 __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1354 1354
                 $forward,
1355 1355
                 $route
1356 1356
             );
1357
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1357
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1358 1358
             return false;
1359 1359
         }
1360
-        EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1360
+        EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1361 1361
         return true;
1362 1362
     }
1363 1363
 
@@ -1375,10 +1375,10 @@  discard block
 block discarded – undo
1375 1375
     public static function get_forward($route = null, $status = 0, $key = 'ee')
1376 1376
     {
1377 1377
         do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1378
-        if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1378
+        if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1379 1379
             return apply_filters(
1380 1380
                 'FHEE__EE_Config__get_forward',
1381
-                EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1381
+                EE_Config::$_module_forward_map[$key][$route][$status],
1382 1382
                 $route,
1383 1383
                 $status
1384 1384
             );
@@ -1402,15 +1402,15 @@  discard block
 block discarded – undo
1402 1402
     public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1403 1403
     {
1404 1404
         do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1405
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1405
+        if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1406 1406
             $msg = sprintf(
1407 1407
                 __('The module route %s for this view has not been registered.', 'event_espresso'),
1408 1408
                 $route
1409 1409
             );
1410
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1410
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1411 1411
             return false;
1412 1412
         }
1413
-        if (! is_readable($view)) {
1413
+        if ( ! is_readable($view)) {
1414 1414
             $msg = sprintf(
1415 1415
                 __(
1416 1416
                     'The %s view file could not be found or is not readable due to file permissions.',
@@ -1418,10 +1418,10 @@  discard block
 block discarded – undo
1418 1418
                 ),
1419 1419
                 $view
1420 1420
             );
1421
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1421
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1422 1422
             return false;
1423 1423
         }
1424
-        EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1424
+        EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1425 1425
         return true;
1426 1426
     }
1427 1427
 
@@ -1439,10 +1439,10 @@  discard block
 block discarded – undo
1439 1439
     public static function get_view($route = null, $status = 0, $key = 'ee')
1440 1440
     {
1441 1441
         do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1442
-        if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1442
+        if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1443 1443
             return apply_filters(
1444 1444
                 'FHEE__EE_Config__get_view',
1445
-                EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1445
+                EE_Config::$_module_view_map[$key][$route][$status],
1446 1446
                 $route,
1447 1447
                 $status
1448 1448
             );
@@ -1469,7 +1469,7 @@  discard block
 block discarded – undo
1469 1469
     public static function getLegacyShortcodesManager()
1470 1470
     {
1471 1471
 
1472
-        if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1472
+        if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1473 1473
             EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1474 1474
                 EE_Registry::instance()
1475 1475
             );
@@ -1516,7 +1516,7 @@  discard block
 block discarded – undo
1516 1516
      */
1517 1517
     public function get_pretty($property)
1518 1518
     {
1519
-        if (! property_exists($this, $property)) {
1519
+        if ( ! property_exists($this, $property)) {
1520 1520
             throw new EE_Error(
1521 1521
                 sprintf(
1522 1522
                     __(
@@ -1745,11 +1745,11 @@  discard block
 block discarded – undo
1745 1745
      */
1746 1746
     public function reg_page_url()
1747 1747
     {
1748
-        if (! $this->reg_page_url) {
1748
+        if ( ! $this->reg_page_url) {
1749 1749
             $this->reg_page_url = add_query_arg(
1750 1750
                 array('uts' => time()),
1751 1751
                 get_permalink($this->reg_page_id)
1752
-            ) . '#checkout';
1752
+            ).'#checkout';
1753 1753
         }
1754 1754
         return $this->reg_page_url;
1755 1755
     }
@@ -1765,7 +1765,7 @@  discard block
 block discarded – undo
1765 1765
      */
1766 1766
     public function txn_page_url($query_args = array())
1767 1767
     {
1768
-        if (! $this->txn_page_url) {
1768
+        if ( ! $this->txn_page_url) {
1769 1769
             $this->txn_page_url = get_permalink($this->txn_page_id);
1770 1770
         }
1771 1771
         if ($query_args) {
@@ -1786,7 +1786,7 @@  discard block
 block discarded – undo
1786 1786
      */
1787 1787
     public function thank_you_page_url($query_args = array())
1788 1788
     {
1789
-        if (! $this->thank_you_page_url) {
1789
+        if ( ! $this->thank_you_page_url) {
1790 1790
             $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1791 1791
         }
1792 1792
         if ($query_args) {
@@ -1805,7 +1805,7 @@  discard block
 block discarded – undo
1805 1805
      */
1806 1806
     public function cancel_page_url()
1807 1807
     {
1808
-        if (! $this->cancel_page_url) {
1808
+        if ( ! $this->cancel_page_url) {
1809 1809
             $this->cancel_page_url = get_permalink($this->cancel_page_id);
1810 1810
         }
1811 1811
         return $this->cancel_page_url;
@@ -1848,13 +1848,13 @@  discard block
 block discarded – undo
1848 1848
         $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1849 1849
         $option = self::OPTION_NAME_UXIP;
1850 1850
         // set correct table for query
1851
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1851
+        $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options';
1852 1852
         // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1853 1853
         // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1854 1854
         // re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1855 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 1856
         // for the purpose of caching.
1857
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1857
+        $pre = apply_filters('pre_option_'.$option, false, $option);
1858 1858
         if (false !== $pre) {
1859 1859
             EE_Core_Config::$ee_ueip_option = $pre;
1860 1860
             return EE_Core_Config::$ee_ueip_option;
@@ -1868,10 +1868,10 @@  discard block
 block discarded – undo
1868 1868
         if (is_object($row)) {
1869 1869
             $value = $row->option_value;
1870 1870
         } else { // option does not exist so use default.
1871
-            EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1871
+            EE_Core_Config::$ee_ueip_option = apply_filters('default_option_'.$option, false, $option);
1872 1872
             return EE_Core_Config::$ee_ueip_option;
1873 1873
         }
1874
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1874
+        EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option);
1875 1875
         return EE_Core_Config::$ee_ueip_option;
1876 1876
     }
1877 1877
 
@@ -2125,37 +2125,37 @@  discard block
 block discarded – undo
2125 2125
         // but override if requested
2126 2126
         $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2127 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)
2128
+        if ( ! empty($CNT_ISO)
2129 2129
             && EE_Maintenance_Mode::instance()->models_can_query()
2130 2130
             && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2131 2131
         ) {
2132 2132
             // retrieve the country settings from the db, just in case they have been customized
2133 2133
             $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2134 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: $
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 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
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 2142
                 $this->dec_mrk = $country->currency_decimal_mark(
2143
-                );    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2143
+                ); // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2144 2144
                 $this->thsnds = $country->currency_thousands_separator(
2145
-                );    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2145
+                ); // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2146 2146
             }
2147 2147
         }
2148 2148
         // fallback to hardcoded defaults, in case the above failed
2149 2149
         if (empty($this->code)) {
2150 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
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 2159
         }
2160 2160
     }
2161 2161
 }
@@ -2414,8 +2414,8 @@  discard block
 block discarded – undo
2414 2414
             $closing_a_tag = '';
2415 2415
             if (function_exists('get_privacy_policy_url')) {
2416 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">';
2417
+                if ( ! empty($privacy_page_url)) {
2418
+                    $opening_a_tag = '<a href="'.$privacy_page_url.'" target="_blank">';
2419 2419
                     $closing_a_tag = '</a>';
2420 2420
                 }
2421 2421
             }
@@ -2630,7 +2630,7 @@  discard block
 block discarded – undo
2630 2630
     public function log_file_name($reset = false)
2631 2631
     {
2632 2632
         if (empty($this->log_file_name) || $reset) {
2633
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2633
+            $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt';
2634 2634
             EE_Config::instance()->update_espresso_config(false, false);
2635 2635
         }
2636 2636
         return $this->log_file_name;
@@ -2644,7 +2644,7 @@  discard block
 block discarded – undo
2644 2644
     public function debug_file_name($reset = false)
2645 2645
     {
2646 2646
         if (empty($this->debug_file_name) || $reset) {
2647
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2647
+            $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt';
2648 2648
             EE_Config::instance()->update_espresso_config(false, false);
2649 2649
         }
2650 2650
         return $this->debug_file_name;
@@ -2848,21 +2848,21 @@  discard block
 block discarded – undo
2848 2848
         $this->use_google_maps = true;
2849 2849
         $this->google_map_api_key = '';
2850 2850
         // for event details pages (reg page)
2851
-        $this->event_details_map_width = 585;            // ee_map_width_single
2852
-        $this->event_details_map_height = 362;            // ee_map_height_single
2853
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2854
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2855
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2856
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2857
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2851
+        $this->event_details_map_width = 585; // ee_map_width_single
2852
+        $this->event_details_map_height = 362; // ee_map_height_single
2853
+        $this->event_details_map_zoom = 14; // ee_map_zoom_single
2854
+        $this->event_details_display_nav = true; // ee_map_nav_display_single
2855
+        $this->event_details_nav_size = false; // ee_map_nav_size_single
2856
+        $this->event_details_control_type = 'default'; // ee_map_type_control_single
2857
+        $this->event_details_map_align = 'center'; // ee_map_align_single
2858 2858
         // for event list pages
2859
-        $this->event_list_map_width = 300;            // ee_map_width
2860
-        $this->event_list_map_height = 185;        // ee_map_height
2861
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2862
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2863
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2864
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2865
-        $this->event_list_map_align = 'center';            // ee_map_align
2859
+        $this->event_list_map_width = 300; // ee_map_width
2860
+        $this->event_list_map_height = 185; // ee_map_height
2861
+        $this->event_list_map_zoom = 12; // ee_map_zoom
2862
+        $this->event_list_display_nav = false; // ee_map_nav_display
2863
+        $this->event_list_nav_size = true; // ee_map_nav_size
2864
+        $this->event_list_control_type = 'dropdown'; // ee_map_type_control
2865
+        $this->event_list_map_align = 'center'; // ee_map_align
2866 2866
     }
2867 2867
 }
2868 2868
 
@@ -3180,7 +3180,7 @@  discard block
 block discarded – undo
3180 3180
      */
3181 3181
     public function max_input_vars_limit_check($input_count = 0)
3182 3182
     {
3183
-        if (! empty($this->php->max_input_vars)
3183
+        if ( ! empty($this->php->max_input_vars)
3184 3184
             && ($input_count >= $this->php->max_input_vars)
3185 3185
         ) {
3186 3186
             // check the server setting because the config value could be stale
Please login to merge, or discard this patch.
core/espresso_definitions.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -7,16 +7,16 @@  discard block
 block discarded – undo
7 7
 define('EE_SUPPORT_EMAIL', '[email protected]');
8 8
 // used to be DIRECTORY_SEPARATOR, but that caused issues on windows
9 9
 if (! defined('DS')) {
10
-    define('DS', '/');
10
+	define('DS', '/');
11 11
 }
12 12
 if (! defined('PS')) {
13
-    define('PS', PATH_SEPARATOR);
13
+	define('PS', PATH_SEPARATOR);
14 14
 }
15 15
 if (! defined('SP')) {
16
-    define('SP', ' ');
16
+	define('SP', ' ');
17 17
 }
18 18
 if (! defined('EENL')) {
19
-    define('EENL', "\n");
19
+	define('EENL', "\n");
20 20
 }
21 21
 // define the plugin directory and URL
22 22
 define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
@@ -70,16 +70,16 @@  discard block
 block discarded – undo
70 70
 define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages/');
71 71
 // check for DOMPDF fonts in uploads
72 72
 if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/')) {
73
-    define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/');
73
+	define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/');
74 74
 }
75 75
 // ajax constants
76 76
 define(
77
-    'EE_FRONT_AJAX',
78
-    isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax'])
77
+	'EE_FRONT_AJAX',
78
+	isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax'])
79 79
 );
80 80
 define(
81
-    'EE_ADMIN_AJAX',
82
-    isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax'])
81
+	'EE_ADMIN_AJAX',
82
+	isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax'])
83 83
 );
84 84
 // just a handy constant occasionally needed for finding values representing infinity in the DB
85 85
 // you're better to use this than its straight value (currently -1) in case you ever
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 define('EE_INF_IN_DB', -1);
88 88
 define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX);
89 89
 if (! defined('EE_DEBUG')) {
90
-    define('EE_DEBUG', false);
90
+	define('EE_DEBUG', false);
91 91
 }
92 92
 // for older WP versions
93 93
 if (! defined('MONTH_IN_SECONDS')) {
94
-    define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
94
+	define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
95 95
 }
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -6,71 +6,71 @@  discard block
 block discarded – undo
6 6
 define('EE_MIN_PHP_VER_RECOMMENDED', '5.6.32');
7 7
 define('EE_SUPPORT_EMAIL', '[email protected]');
8 8
 // used to be DIRECTORY_SEPARATOR, but that caused issues on windows
9
-if (! defined('DS')) {
9
+if ( ! defined('DS')) {
10 10
     define('DS', '/');
11 11
 }
12
-if (! defined('PS')) {
12
+if ( ! defined('PS')) {
13 13
     define('PS', PATH_SEPARATOR);
14 14
 }
15
-if (! defined('SP')) {
15
+if ( ! defined('SP')) {
16 16
     define('SP', ' ');
17 17
 }
18
-if (! defined('EENL')) {
18
+if ( ! defined('EENL')) {
19 19
     define('EENL', "\n");
20 20
 }
21 21
 // define the plugin directory and URL
22 22
 define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
23
-define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE) . '/');
23
+define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE).'/');
24 24
 define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
25 25
 // main root folder paths
26
-define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages/');
27
-define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core/');
28
-define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules/');
29
-define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public/');
30
-define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes/');
31
-define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets/');
32
-define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods/');
33
-define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated/');
26
+define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH.'admin_pages/');
27
+define('EE_CORE', EE_PLUGIN_DIR_PATH.'core/');
28
+define('EE_MODULES', EE_PLUGIN_DIR_PATH.'modules/');
29
+define('EE_PUBLIC', EE_PLUGIN_DIR_PATH.'public/');
30
+define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH.'shortcodes/');
31
+define('EE_WIDGETS', EE_PLUGIN_DIR_PATH.'widgets/');
32
+define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH.'payment_methods/');
33
+define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH.'caffeinated/');
34 34
 // core system paths
35
-define('EE_ADMIN', EE_CORE . 'admin/');
36
-define('EE_CPTS', EE_CORE . 'CPTs/');
37
-define('EE_CLASSES', EE_CORE . 'db_classes/');
38
-define('EE_INTERFACES', EE_CORE . 'interfaces/');
39
-define('EE_BUSINESS', EE_CORE . 'business/');
40
-define('EE_MODELS', EE_CORE . 'db_models/');
41
-define('EE_HELPERS', EE_CORE . 'helpers/');
42
-define('EE_LIBRARIES', EE_CORE . 'libraries/');
43
-define('EE_TEMPLATES', EE_CORE . 'templates/');
44
-define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs/');
45
-define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets/');
46
-define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections/');
35
+define('EE_ADMIN', EE_CORE.'admin/');
36
+define('EE_CPTS', EE_CORE.'CPTs/');
37
+define('EE_CLASSES', EE_CORE.'db_classes/');
38
+define('EE_INTERFACES', EE_CORE.'interfaces/');
39
+define('EE_BUSINESS', EE_CORE.'business/');
40
+define('EE_MODELS', EE_CORE.'db_models/');
41
+define('EE_HELPERS', EE_CORE.'helpers/');
42
+define('EE_LIBRARIES', EE_CORE.'libraries/');
43
+define('EE_TEMPLATES', EE_CORE.'templates/');
44
+define('EE_THIRD_PARTY', EE_CORE.'third_party_libs/');
45
+define('EE_GLOBAL_ASSETS', EE_TEMPLATES.'global_assets/');
46
+define('EE_FORM_SECTIONS', EE_LIBRARIES.'form_sections/');
47 47
 // gateways
48
-define('EE_GATEWAYS', EE_MODULES . 'gateways/');
49
-define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules/gateways/');
48
+define('EE_GATEWAYS', EE_MODULES.'gateways/');
49
+define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules/gateways/');
50 50
 // asset URL paths
51
-define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core/templates/');
52
-define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets/');
53
-define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images/');
54
-define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core/third_party_libs/');
55
-define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
56
-define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
51
+define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL.'core/templates/');
52
+define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL.'global_assets/');
53
+define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL.'images/');
54
+define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL.'core/third_party_libs/');
55
+define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL.'core/helpers/assets/');
56
+define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL.'core/libraries/');
57 57
 // define upload paths
58 58
 $uploads = wp_upload_dir();
59 59
 // define the uploads directory and URL
60
-define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . '/espresso/');
61
-define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . '/espresso/');
60
+define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].'/espresso/');
61
+define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].'/espresso/');
62 62
 // define the templates directory and URL
63
-define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . '/espresso/templates/');
64
-define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . '/espresso/templates/');
63
+define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'].'/espresso/templates/');
64
+define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'].'/espresso/templates/');
65 65
 // define the gateway directory and URL
66
-define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . '/espresso/gateways/');
67
-define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . '/espresso/gateways/');
66
+define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'].'/espresso/gateways/');
67
+define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'].'/espresso/gateways/');
68 68
 // languages folder/path
69
-define('EE_LANGUAGES_SAFE_LOC', '../' . 'uploads/' . 'espresso/languages/');
70
-define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages/');
69
+define('EE_LANGUAGES_SAFE_LOC', '../'.'uploads/'.'espresso/languages/');
70
+define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'languages/');
71 71
 // check for DOMPDF fonts in uploads
72
-if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/')) {
73
-    define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/');
72
+if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts/')) {
73
+    define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts/');
74 74
 }
75 75
 // ajax constants
76 76
 define(
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
 // want to change its default value! or find when -1 means infinity
87 87
 define('EE_INF_IN_DB', -1);
88 88
 define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX);
89
-if (! defined('EE_DEBUG')) {
89
+if ( ! defined('EE_DEBUG')) {
90 90
     define('EE_DEBUG', false);
91 91
 }
92 92
 // for older WP versions
93
-if (! defined('MONTH_IN_SECONDS')) {
93
+if ( ! defined('MONTH_IN_SECONDS')) {
94 94
     define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
95 95
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin.core.php 2 patches
Indentation   +1025 added lines, -1025 removed lines patch added patch discarded remove patch
@@ -20,488 +20,488 @@  discard block
 block discarded – undo
20 20
 final class EE_Admin implements InterminableInterface
21 21
 {
22 22
 
23
-    /**
24
-     * @var EE_Admin $_instance
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
30
-     */
31
-    private $persistent_admin_notice_manager;
32
-
33
-    /**
34
-     * @var LoaderInterface
35
-     */
36
-    protected $loader;
37
-
38
-    /**
39
-     * @singleton method used to instantiate class object
40
-     * @return EE_Admin
41
-     * @throws EE_Error
42
-     */
43
-    public static function instance()
44
-    {
45
-        // check if class object is instantiated
46
-        if (! self::$_instance instanceof EE_Admin) {
47
-            self::$_instance = new self();
48
-        }
49
-        return self::$_instance;
50
-    }
51
-
52
-
53
-    /**
54
-     * @return EE_Admin
55
-     * @throws EE_Error
56
-     */
57
-    public static function reset()
58
-    {
59
-        self::$_instance = null;
60
-        return self::instance();
61
-    }
62
-
63
-
64
-    /**
65
-     * class constructor
66
-     *
67
-     * @throws EE_Error
68
-     * @throws InvalidDataTypeException
69
-     * @throws InvalidInterfaceException
70
-     * @throws InvalidArgumentException
71
-     */
72
-    protected function __construct()
73
-    {
74
-        // define global EE_Admin constants
75
-        $this->_define_all_constants();
76
-        // set autoloaders for our admin page classes based on included path information
77
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
78
-        // admin hooks
79
-        add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
80
-        // load EE_Request_Handler early
81
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
82
-        add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
83
-        add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
84
-        add_action('wp_loaded', array($this, 'wp_loaded'), 100);
85
-        add_action('admin_init', array($this, 'admin_init'), 100);
86
-        add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
87
-        add_action('admin_notices', array($this, 'display_admin_notices'), 10);
88
-        add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
89
-        add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
90
-        add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
91
-        add_action('load-plugins.php', array($this, 'hookIntoWpPluginsPage'));
92
-        add_action('display_post_states', array($this, 'displayStateForCriticalPages'), 10, 2);
93
-        add_filter('plugin_row_meta', array($this, 'addLinksToPluginRowMeta'), 10, 2);
94
-        // reset Environment config (we only do this on admin page loads);
95
-        EE_Registry::instance()->CFG->environment->recheck_values();
96
-        do_action('AHEE__EE_Admin__loaded');
97
-    }
98
-
99
-
100
-    /**
101
-     * _define_all_constants
102
-     * define constants that are set globally for all admin pages
103
-     *
104
-     * @return void
105
-     */
106
-    private function _define_all_constants()
107
-    {
108
-        if (! defined('EE_ADMIN_URL')) {
109
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
110
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
111
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/');
112
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
113
-            define('WP_AJAX_URL', admin_url('admin-ajax.php'));
114
-        }
115
-    }
116
-
117
-
118
-    /**
119
-     * filter_plugin_actions - adds links to the Plugins page listing
120
-     *
121
-     * @param    array  $links
122
-     * @param    string $plugin
123
-     * @return    array
124
-     */
125
-    public function filter_plugin_actions($links, $plugin)
126
-    {
127
-        // set $main_file in stone
128
-        static $main_file;
129
-        // if $main_file is not set yet
130
-        if (! $main_file) {
131
-            $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
132
-        }
133
-        if ($plugin === $main_file) {
134
-            // compare current plugin to this one
135
-            if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
136
-                $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
137
-                                    . ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
138
-                                    . esc_html__('Maintenance Mode Active', 'event_espresso')
139
-                                    . '</a>';
140
-                array_unshift($links, $maintenance_link);
141
-            } else {
142
-                $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
143
-                                     . esc_html__('Settings', 'event_espresso')
144
-                                     . '</a>';
145
-                $events_link = '<a href="admin.php?page=espresso_events">'
146
-                               . esc_html__('Events', 'event_espresso')
147
-                               . '</a>';
148
-                // add before other links
149
-                array_unshift($links, $org_settings_link, $events_link);
150
-            }
151
-        }
152
-        return $links;
153
-    }
154
-
155
-
156
-    /**
157
-     * _get_request
158
-     *
159
-     * @return void
160
-     * @throws EE_Error
161
-     * @throws InvalidArgumentException
162
-     * @throws InvalidDataTypeException
163
-     * @throws InvalidInterfaceException
164
-     * @throws ReflectionException
165
-     */
166
-    public function get_request()
167
-    {
168
-        EE_Registry::instance()->load_core('Request_Handler');
169
-    }
170
-
171
-
172
-    /**
173
-     * hide_admin_pages_except_maintenance_mode
174
-     *
175
-     * @param array $admin_page_folder_names
176
-     * @return array
177
-     */
178
-    public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
179
-    {
180
-        return array(
181
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance/',
182
-            'about'       => EE_ADMIN_PAGES . 'about/',
183
-            'support'     => EE_ADMIN_PAGES . 'support/',
184
-        );
185
-    }
186
-
187
-
188
-    /**
189
-     * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
190
-     * EE_Front_Controller's init phases have run
191
-     *
192
-     * @return void
193
-     * @throws EE_Error
194
-     * @throws InvalidArgumentException
195
-     * @throws InvalidDataTypeException
196
-     * @throws InvalidInterfaceException
197
-     * @throws ReflectionException
198
-     * @throws ServiceNotFoundException
199
-     */
200
-    public function init()
201
-    {
202
-        // only enable most of the EE_Admin IF we're not in full maintenance mode
203
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
204
-            $this->initModelsReady();
205
-        }
206
-        // run the admin page factory but ONLY if we are doing an ee admin ajax request
207
-        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
208
-            try {
209
-                // this loads the controller for the admin pages which will setup routing etc
210
-                EE_Registry::instance()->load_core('Admin_Page_Loader');
211
-            } catch (EE_Error $e) {
212
-                $e->get_error();
213
-            }
214
-        }
215
-        add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
216
-        // make sure our CPTs and custom taxonomy metaboxes get shown for first time users
217
-        add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
218
-        add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
219
-        // exclude EE critical pages from all nav menus and wp_list_pages
220
-        add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
221
-    }
222
-
223
-
224
-    /**
225
-     * Gets the loader (and if it wasn't previously set, sets it)
226
-     * @return LoaderInterface
227
-     * @throws InvalidArgumentException
228
-     * @throws InvalidDataTypeException
229
-     * @throws InvalidInterfaceException
230
-     */
231
-    protected function getLoader()
232
-    {
233
-        if (! $this->loader instanceof LoaderInterface) {
234
-            $this->loader = LoaderFactory::getLoader();
235
-        }
236
-        return $this->loader;
237
-    }
238
-
239
-
240
-    /**
241
-     * Method that's fired on admin requests (including admin ajax) but only when the models are usable
242
-     * (ie, the site isn't in maintenance mode)
243
-     * @since 4.9.63.p
244
-     * @return void
245
-     */
246
-    protected function initModelsReady()
247
-    {
248
-        // ok so we want to enable the entire admin
249
-        $this->persistent_admin_notice_manager = $this->getLoader()->getShared(
250
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
251
-        );
252
-        $this->persistent_admin_notice_manager->setReturnUrl(
253
-            EE_Admin_Page::add_query_args_and_nonce(
254
-                array(
255
-                    'page'   => EE_Registry::instance()->REQ->get('page', ''),
256
-                    'action' => EE_Registry::instance()->REQ->get('action', ''),
257
-                ),
258
-                EE_ADMIN_URL
259
-            )
260
-        );
261
-        $this->maybeSetDatetimeWarningNotice();
262
-        // at a glance dashboard widget
263
-        add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
264
-        // filter for get_edit_post_link used on comments for custom post types
265
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
266
-    }
267
-
268
-
269
-    /**
270
-     *    get_persistent_admin_notices
271
-     *
272
-     * @access    public
273
-     * @return void
274
-     * @throws EE_Error
275
-     * @throws InvalidArgumentException
276
-     * @throws InvalidDataTypeException
277
-     * @throws InvalidInterfaceException
278
-     */
279
-    public function maybeSetDatetimeWarningNotice()
280
-    {
281
-        // add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
282
-        // @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
283
-        // with this.  But after enough time (indeterminate at this point) we can just remove this notice.
284
-        // this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
285
-        if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
286
-            && ! get_option('timezone_string')
287
-            && EEM_Event::instance()->count() > 0
288
-        ) {
289
-            new PersistentAdminNotice(
290
-                'datetime_fix_notice',
291
-                sprintf(
292
-                    esc_html__(
293
-                        '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
294
-                        'event_espresso'
295
-                    ),
296
-                    '<strong>',
297
-                    '</strong>',
298
-                    '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
299
-                    '</a>',
300
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
301
-                        array(
302
-                            'page'   => 'espresso_maintenance_settings',
303
-                            'action' => 'datetime_tools',
304
-                        ),
305
-                        admin_url('admin.php')
306
-                    ) . '">'
307
-                ),
308
-                false,
309
-                'manage_options',
310
-                'datetime_fix_persistent_notice'
311
-            );
312
-        }
313
-    }
314
-
315
-
316
-    /**
317
-     * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
318
-     * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
319
-     * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
320
-     * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
321
-     * normal property on the post_type object.  It's found ONLY in this particular context.
322
-     *
323
-     * @param WP_Post $post_type WP post type object
324
-     * @return WP_Post
325
-     * @throws InvalidArgumentException
326
-     * @throws InvalidDataTypeException
327
-     * @throws InvalidInterfaceException
328
-     */
329
-    public function remove_pages_from_nav_menu($post_type)
330
-    {
331
-        // if this isn't the "pages" post type let's get out
332
-        if ($post_type->name !== 'page') {
333
-            return $post_type;
334
-        }
335
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
336
-        $post_type->_default_query = array(
337
-            'post__not_in' => $critical_pages,
338
-        );
339
-        return $post_type;
340
-    }
341
-
342
-
343
-    /**
344
-     * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
345
-     * metaboxes get shown as well
346
-     *
347
-     * @return void
348
-     */
349
-    public function enable_hidden_ee_nav_menu_metaboxes()
350
-    {
351
-        global $wp_meta_boxes, $pagenow;
352
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
353
-            return;
354
-        }
355
-        $user = wp_get_current_user();
356
-        // has this been done yet?
357
-        if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
358
-            return;
359
-        }
360
-
361
-        $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID);
362
-        $initial_meta_boxes = apply_filters(
363
-            'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
364
-            array(
365
-                'nav-menu-theme-locations',
366
-                'add-page',
367
-                'add-custom-links',
368
-                'add-category',
369
-                'add-espresso_events',
370
-                'add-espresso_venues',
371
-                'add-espresso_event_categories',
372
-                'add-espresso_venue_categories',
373
-                'add-post-type-post',
374
-                'add-post-type-page',
375
-            )
376
-        );
377
-
378
-        if (is_array($hidden_meta_boxes)) {
379
-            foreach ($hidden_meta_boxes as $key => $meta_box_id) {
380
-                if (in_array($meta_box_id, $initial_meta_boxes, true)) {
381
-                    unset($hidden_meta_boxes[ $key ]);
382
-                }
383
-            }
384
-        }
385
-        update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
386
-        update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
387
-    }
388
-
389
-
390
-    /**
391
-     * This method simply registers custom nav menu boxes for "nav_menus.php route"
392
-     * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
393
-     *
394
-     * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
395
-     *         addons etc.
396
-     * @return void
397
-     */
398
-    public function register_custom_nav_menu_boxes()
399
-    {
400
-        add_meta_box(
401
-            'add-extra-nav-menu-pages',
402
-            esc_html__('Event Espresso Pages', 'event_espresso'),
403
-            array($this, 'ee_cpt_archive_pages'),
404
-            'nav-menus',
405
-            'side',
406
-            'core'
407
-        );
408
-    }
409
-
410
-
411
-    /**
412
-     * Use this to edit the post link for our cpts so that the edit link points to the correct page.
413
-     *
414
-     * @since   4.3.0
415
-     * @param string $link the original link generated by wp
416
-     * @param int    $id   post id
417
-     * @return string  the (maybe) modified link
418
-     */
419
-    public function modify_edit_post_link($link, $id)
420
-    {
421
-        if (! $post = get_post($id)) {
422
-            return $link;
423
-        }
424
-        if ($post->post_type === 'espresso_attendees') {
425
-            $query_args = array(
426
-                'action' => 'edit_attendee',
427
-                'post'   => $id,
428
-            );
429
-            return EEH_URL::add_query_args_and_nonce(
430
-                $query_args,
431
-                admin_url('admin.php?page=espresso_registrations')
432
-            );
433
-        }
434
-        return $link;
435
-    }
436
-
437
-
438
-    public function ee_cpt_archive_pages()
439
-    {
440
-        global $nav_menu_selected_id;
441
-        $db_fields = false;
442
-        $walker = new Walker_Nav_Menu_Checklist($db_fields);
443
-        $current_tab = 'event-archives';
444
-        $removed_args = array(
445
-            'action',
446
-            'customlink-tab',
447
-            'edit-menu-item',
448
-            'menu-item',
449
-            'page-tab',
450
-            '_wpnonce',
451
-        );
452
-        ?>
23
+	/**
24
+	 * @var EE_Admin $_instance
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
30
+	 */
31
+	private $persistent_admin_notice_manager;
32
+
33
+	/**
34
+	 * @var LoaderInterface
35
+	 */
36
+	protected $loader;
37
+
38
+	/**
39
+	 * @singleton method used to instantiate class object
40
+	 * @return EE_Admin
41
+	 * @throws EE_Error
42
+	 */
43
+	public static function instance()
44
+	{
45
+		// check if class object is instantiated
46
+		if (! self::$_instance instanceof EE_Admin) {
47
+			self::$_instance = new self();
48
+		}
49
+		return self::$_instance;
50
+	}
51
+
52
+
53
+	/**
54
+	 * @return EE_Admin
55
+	 * @throws EE_Error
56
+	 */
57
+	public static function reset()
58
+	{
59
+		self::$_instance = null;
60
+		return self::instance();
61
+	}
62
+
63
+
64
+	/**
65
+	 * class constructor
66
+	 *
67
+	 * @throws EE_Error
68
+	 * @throws InvalidDataTypeException
69
+	 * @throws InvalidInterfaceException
70
+	 * @throws InvalidArgumentException
71
+	 */
72
+	protected function __construct()
73
+	{
74
+		// define global EE_Admin constants
75
+		$this->_define_all_constants();
76
+		// set autoloaders for our admin page classes based on included path information
77
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
78
+		// admin hooks
79
+		add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
80
+		// load EE_Request_Handler early
81
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
82
+		add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
83
+		add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
84
+		add_action('wp_loaded', array($this, 'wp_loaded'), 100);
85
+		add_action('admin_init', array($this, 'admin_init'), 100);
86
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
87
+		add_action('admin_notices', array($this, 'display_admin_notices'), 10);
88
+		add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
89
+		add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
90
+		add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
91
+		add_action('load-plugins.php', array($this, 'hookIntoWpPluginsPage'));
92
+		add_action('display_post_states', array($this, 'displayStateForCriticalPages'), 10, 2);
93
+		add_filter('plugin_row_meta', array($this, 'addLinksToPluginRowMeta'), 10, 2);
94
+		// reset Environment config (we only do this on admin page loads);
95
+		EE_Registry::instance()->CFG->environment->recheck_values();
96
+		do_action('AHEE__EE_Admin__loaded');
97
+	}
98
+
99
+
100
+	/**
101
+	 * _define_all_constants
102
+	 * define constants that are set globally for all admin pages
103
+	 *
104
+	 * @return void
105
+	 */
106
+	private function _define_all_constants()
107
+	{
108
+		if (! defined('EE_ADMIN_URL')) {
109
+			define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
110
+			define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
111
+			define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/');
112
+			define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
113
+			define('WP_AJAX_URL', admin_url('admin-ajax.php'));
114
+		}
115
+	}
116
+
117
+
118
+	/**
119
+	 * filter_plugin_actions - adds links to the Plugins page listing
120
+	 *
121
+	 * @param    array  $links
122
+	 * @param    string $plugin
123
+	 * @return    array
124
+	 */
125
+	public function filter_plugin_actions($links, $plugin)
126
+	{
127
+		// set $main_file in stone
128
+		static $main_file;
129
+		// if $main_file is not set yet
130
+		if (! $main_file) {
131
+			$main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
132
+		}
133
+		if ($plugin === $main_file) {
134
+			// compare current plugin to this one
135
+			if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
136
+				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
137
+									. ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
138
+									. esc_html__('Maintenance Mode Active', 'event_espresso')
139
+									. '</a>';
140
+				array_unshift($links, $maintenance_link);
141
+			} else {
142
+				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
143
+									 . esc_html__('Settings', 'event_espresso')
144
+									 . '</a>';
145
+				$events_link = '<a href="admin.php?page=espresso_events">'
146
+							   . esc_html__('Events', 'event_espresso')
147
+							   . '</a>';
148
+				// add before other links
149
+				array_unshift($links, $org_settings_link, $events_link);
150
+			}
151
+		}
152
+		return $links;
153
+	}
154
+
155
+
156
+	/**
157
+	 * _get_request
158
+	 *
159
+	 * @return void
160
+	 * @throws EE_Error
161
+	 * @throws InvalidArgumentException
162
+	 * @throws InvalidDataTypeException
163
+	 * @throws InvalidInterfaceException
164
+	 * @throws ReflectionException
165
+	 */
166
+	public function get_request()
167
+	{
168
+		EE_Registry::instance()->load_core('Request_Handler');
169
+	}
170
+
171
+
172
+	/**
173
+	 * hide_admin_pages_except_maintenance_mode
174
+	 *
175
+	 * @param array $admin_page_folder_names
176
+	 * @return array
177
+	 */
178
+	public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
179
+	{
180
+		return array(
181
+			'maintenance' => EE_ADMIN_PAGES . 'maintenance/',
182
+			'about'       => EE_ADMIN_PAGES . 'about/',
183
+			'support'     => EE_ADMIN_PAGES . 'support/',
184
+		);
185
+	}
186
+
187
+
188
+	/**
189
+	 * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
190
+	 * EE_Front_Controller's init phases have run
191
+	 *
192
+	 * @return void
193
+	 * @throws EE_Error
194
+	 * @throws InvalidArgumentException
195
+	 * @throws InvalidDataTypeException
196
+	 * @throws InvalidInterfaceException
197
+	 * @throws ReflectionException
198
+	 * @throws ServiceNotFoundException
199
+	 */
200
+	public function init()
201
+	{
202
+		// only enable most of the EE_Admin IF we're not in full maintenance mode
203
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
204
+			$this->initModelsReady();
205
+		}
206
+		// run the admin page factory but ONLY if we are doing an ee admin ajax request
207
+		if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
208
+			try {
209
+				// this loads the controller for the admin pages which will setup routing etc
210
+				EE_Registry::instance()->load_core('Admin_Page_Loader');
211
+			} catch (EE_Error $e) {
212
+				$e->get_error();
213
+			}
214
+		}
215
+		add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
216
+		// make sure our CPTs and custom taxonomy metaboxes get shown for first time users
217
+		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
218
+		add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
219
+		// exclude EE critical pages from all nav menus and wp_list_pages
220
+		add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
221
+	}
222
+
223
+
224
+	/**
225
+	 * Gets the loader (and if it wasn't previously set, sets it)
226
+	 * @return LoaderInterface
227
+	 * @throws InvalidArgumentException
228
+	 * @throws InvalidDataTypeException
229
+	 * @throws InvalidInterfaceException
230
+	 */
231
+	protected function getLoader()
232
+	{
233
+		if (! $this->loader instanceof LoaderInterface) {
234
+			$this->loader = LoaderFactory::getLoader();
235
+		}
236
+		return $this->loader;
237
+	}
238
+
239
+
240
+	/**
241
+	 * Method that's fired on admin requests (including admin ajax) but only when the models are usable
242
+	 * (ie, the site isn't in maintenance mode)
243
+	 * @since 4.9.63.p
244
+	 * @return void
245
+	 */
246
+	protected function initModelsReady()
247
+	{
248
+		// ok so we want to enable the entire admin
249
+		$this->persistent_admin_notice_manager = $this->getLoader()->getShared(
250
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
251
+		);
252
+		$this->persistent_admin_notice_manager->setReturnUrl(
253
+			EE_Admin_Page::add_query_args_and_nonce(
254
+				array(
255
+					'page'   => EE_Registry::instance()->REQ->get('page', ''),
256
+					'action' => EE_Registry::instance()->REQ->get('action', ''),
257
+				),
258
+				EE_ADMIN_URL
259
+			)
260
+		);
261
+		$this->maybeSetDatetimeWarningNotice();
262
+		// at a glance dashboard widget
263
+		add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
264
+		// filter for get_edit_post_link used on comments for custom post types
265
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
266
+	}
267
+
268
+
269
+	/**
270
+	 *    get_persistent_admin_notices
271
+	 *
272
+	 * @access    public
273
+	 * @return void
274
+	 * @throws EE_Error
275
+	 * @throws InvalidArgumentException
276
+	 * @throws InvalidDataTypeException
277
+	 * @throws InvalidInterfaceException
278
+	 */
279
+	public function maybeSetDatetimeWarningNotice()
280
+	{
281
+		// add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
282
+		// @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
283
+		// with this.  But after enough time (indeterminate at this point) we can just remove this notice.
284
+		// this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
285
+		if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
286
+			&& ! get_option('timezone_string')
287
+			&& EEM_Event::instance()->count() > 0
288
+		) {
289
+			new PersistentAdminNotice(
290
+				'datetime_fix_notice',
291
+				sprintf(
292
+					esc_html__(
293
+						'%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
294
+						'event_espresso'
295
+					),
296
+					'<strong>',
297
+					'</strong>',
298
+					'<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
299
+					'</a>',
300
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
301
+						array(
302
+							'page'   => 'espresso_maintenance_settings',
303
+							'action' => 'datetime_tools',
304
+						),
305
+						admin_url('admin.php')
306
+					) . '">'
307
+				),
308
+				false,
309
+				'manage_options',
310
+				'datetime_fix_persistent_notice'
311
+			);
312
+		}
313
+	}
314
+
315
+
316
+	/**
317
+	 * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
318
+	 * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
319
+	 * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
320
+	 * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
321
+	 * normal property on the post_type object.  It's found ONLY in this particular context.
322
+	 *
323
+	 * @param WP_Post $post_type WP post type object
324
+	 * @return WP_Post
325
+	 * @throws InvalidArgumentException
326
+	 * @throws InvalidDataTypeException
327
+	 * @throws InvalidInterfaceException
328
+	 */
329
+	public function remove_pages_from_nav_menu($post_type)
330
+	{
331
+		// if this isn't the "pages" post type let's get out
332
+		if ($post_type->name !== 'page') {
333
+			return $post_type;
334
+		}
335
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
336
+		$post_type->_default_query = array(
337
+			'post__not_in' => $critical_pages,
338
+		);
339
+		return $post_type;
340
+	}
341
+
342
+
343
+	/**
344
+	 * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
345
+	 * metaboxes get shown as well
346
+	 *
347
+	 * @return void
348
+	 */
349
+	public function enable_hidden_ee_nav_menu_metaboxes()
350
+	{
351
+		global $wp_meta_boxes, $pagenow;
352
+		if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
353
+			return;
354
+		}
355
+		$user = wp_get_current_user();
356
+		// has this been done yet?
357
+		if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
358
+			return;
359
+		}
360
+
361
+		$hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID);
362
+		$initial_meta_boxes = apply_filters(
363
+			'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
364
+			array(
365
+				'nav-menu-theme-locations',
366
+				'add-page',
367
+				'add-custom-links',
368
+				'add-category',
369
+				'add-espresso_events',
370
+				'add-espresso_venues',
371
+				'add-espresso_event_categories',
372
+				'add-espresso_venue_categories',
373
+				'add-post-type-post',
374
+				'add-post-type-page',
375
+			)
376
+		);
377
+
378
+		if (is_array($hidden_meta_boxes)) {
379
+			foreach ($hidden_meta_boxes as $key => $meta_box_id) {
380
+				if (in_array($meta_box_id, $initial_meta_boxes, true)) {
381
+					unset($hidden_meta_boxes[ $key ]);
382
+				}
383
+			}
384
+		}
385
+		update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
386
+		update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
387
+	}
388
+
389
+
390
+	/**
391
+	 * This method simply registers custom nav menu boxes for "nav_menus.php route"
392
+	 * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
393
+	 *
394
+	 * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
395
+	 *         addons etc.
396
+	 * @return void
397
+	 */
398
+	public function register_custom_nav_menu_boxes()
399
+	{
400
+		add_meta_box(
401
+			'add-extra-nav-menu-pages',
402
+			esc_html__('Event Espresso Pages', 'event_espresso'),
403
+			array($this, 'ee_cpt_archive_pages'),
404
+			'nav-menus',
405
+			'side',
406
+			'core'
407
+		);
408
+	}
409
+
410
+
411
+	/**
412
+	 * Use this to edit the post link for our cpts so that the edit link points to the correct page.
413
+	 *
414
+	 * @since   4.3.0
415
+	 * @param string $link the original link generated by wp
416
+	 * @param int    $id   post id
417
+	 * @return string  the (maybe) modified link
418
+	 */
419
+	public function modify_edit_post_link($link, $id)
420
+	{
421
+		if (! $post = get_post($id)) {
422
+			return $link;
423
+		}
424
+		if ($post->post_type === 'espresso_attendees') {
425
+			$query_args = array(
426
+				'action' => 'edit_attendee',
427
+				'post'   => $id,
428
+			);
429
+			return EEH_URL::add_query_args_and_nonce(
430
+				$query_args,
431
+				admin_url('admin.php?page=espresso_registrations')
432
+			);
433
+		}
434
+		return $link;
435
+	}
436
+
437
+
438
+	public function ee_cpt_archive_pages()
439
+	{
440
+		global $nav_menu_selected_id;
441
+		$db_fields = false;
442
+		$walker = new Walker_Nav_Menu_Checklist($db_fields);
443
+		$current_tab = 'event-archives';
444
+		$removed_args = array(
445
+			'action',
446
+			'customlink-tab',
447
+			'edit-menu-item',
448
+			'menu-item',
449
+			'page-tab',
450
+			'_wpnonce',
451
+		);
452
+		?>
453 453
         <div id="posttype-extra-nav-menu-pages" class="posttypediv">
454 454
             <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
455 455
                 <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>>
456 456
                     <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives"
457 457
                        href="<?php
458
-                        if ($nav_menu_selected_id) {
459
-                            echo esc_url(
460
-                                add_query_arg(
461
-                                    'extra-nav-menu-pages-tab',
462
-                                    'event-archives',
463
-                                    remove_query_arg($removed_args)
464
-                                )
465
-                            );
466
-                        }
467
-                        ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
458
+						if ($nav_menu_selected_id) {
459
+							echo esc_url(
460
+								add_query_arg(
461
+									'extra-nav-menu-pages-tab',
462
+									'event-archives',
463
+									remove_query_arg($removed_args)
464
+								)
465
+							);
466
+						}
467
+						?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
468 468
                         <?php esc_html_e('Event Archive Pages', 'event_espresso'); ?>
469 469
                     </a>
470 470
                 </li>
471 471
             </ul><!-- .posttype-tabs -->
472 472
 
473 473
             <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
474
-            echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
475
-            ?>">
474
+			echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
475
+			?>">
476 476
                 <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
477 477
                     <?php
478
-                    $pages = $this->_get_extra_nav_menu_pages_items();
479
-                    $args['walker'] = $walker;
480
-                    echo walk_nav_menu_tree(
481
-                        array_map(
482
-                            array($this, '_setup_extra_nav_menu_pages_items'),
483
-                            $pages
484
-                        ),
485
-                        0,
486
-                        (object) $args
487
-                    );
488
-                    ?>
478
+					$pages = $this->_get_extra_nav_menu_pages_items();
479
+					$args['walker'] = $walker;
480
+					echo walk_nav_menu_tree(
481
+						array_map(
482
+							array($this, '_setup_extra_nav_menu_pages_items'),
483
+							$pages
484
+						),
485
+						0,
486
+						(object) $args
487
+					);
488
+					?>
489 489
                 </ul>
490 490
             </div><!-- /.tabs-panel -->
491 491
 
492 492
             <p class="button-controls">
493 493
                 <span class="list-controls">
494 494
                     <a href="<?php
495
-                             echo esc_url(
496
-                                 add_query_arg(
497
-                                     array(
498
-                                         'extra-nav-menu-pages-tab' => 'event-archives',
499
-                                         'selectall'                => 1,
500
-                                     ),
501
-                                     remove_query_arg($removed_args)
502
-                                 )
503
-                             );
504
-                        ?>#posttype-extra-nav-menu-pages" class="select-all"><?php esc_html_e('Select All', 'event_espresso'); ?></a>
495
+							 echo esc_url(
496
+								 add_query_arg(
497
+									 array(
498
+										 'extra-nav-menu-pages-tab' => 'event-archives',
499
+										 'selectall'                => 1,
500
+									 ),
501
+									 remove_query_arg($removed_args)
502
+								 )
503
+							 );
504
+						?>#posttype-extra-nav-menu-pages" class="select-all"><?php esc_html_e('Select All', 'event_espresso'); ?></a>
505 505
                 </span>
506 506
                 <span class="add-to-menu">
507 507
                     <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?>
@@ -514,566 +514,566 @@  discard block
 block discarded – undo
514 514
 
515 515
         </div><!-- /.posttypediv -->
516 516
         <?php
517
-    }
518
-
519
-
520
-    /**
521
-     * Returns an array of event archive nav items.
522
-     *
523
-     * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
524
-     *        method we use for getting the extra nav menu items
525
-     * @return array
526
-     */
527
-    private function _get_extra_nav_menu_pages_items()
528
-    {
529
-        $menuitems[] = array(
530
-            'title'       => esc_html__('Event List', 'event_espresso'),
531
-            'url'         => get_post_type_archive_link('espresso_events'),
532
-            'description' => esc_html__('Archive page for all events.', 'event_espresso'),
533
-        );
534
-        return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
535
-    }
536
-
537
-
538
-    /**
539
-     * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
540
-     * the properties and converts it to the menu item object.
541
-     *
542
-     * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
543
-     * @param $menu_item_values
544
-     * @return stdClass
545
-     */
546
-    private function _setup_extra_nav_menu_pages_items($menu_item_values)
547
-    {
548
-        $menu_item = new stdClass();
549
-        $keys = array(
550
-            'ID'               => 0,
551
-            'db_id'            => 0,
552
-            'menu_item_parent' => 0,
553
-            'object_id'        => -1,
554
-            'post_parent'      => 0,
555
-            'type'             => 'custom',
556
-            'object'           => '',
557
-            'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
558
-            'title'            => '',
559
-            'url'              => '',
560
-            'target'           => '',
561
-            'attr_title'       => '',
562
-            'description'      => '',
563
-            'classes'          => array(),
564
-            'xfn'              => '',
565
-        );
566
-
567
-        foreach ($keys as $key => $value) {
568
-            $menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
569
-        }
570
-        return $menu_item;
571
-    }
572
-
573
-
574
-    /**
575
-     * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
576
-     * EE_Admin_Page route is called.
577
-     *
578
-     * @return void
579
-     */
580
-    public function route_admin_request()
581
-    {
582
-    }
583
-
584
-
585
-    /**
586
-     * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
587
-     *
588
-     * @return void
589
-     */
590
-    public function wp_loaded()
591
-    {
592
-    }
593
-
594
-
595
-    /**
596
-     * admin_init
597
-     *
598
-     * @return void
599
-     * @throws EE_Error
600
-     * @throws InvalidArgumentException
601
-     * @throws InvalidDataTypeException
602
-     * @throws InvalidInterfaceException
603
-     * @throws ReflectionException
604
-     */
605
-    public function admin_init()
606
-    {
607
-        /**
608
-         * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
609
-         * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
610
-         * - check if doing post processing.
611
-         * - check if doing post processing of one of EE CPTs
612
-         * - instantiate the corresponding EE CPT model for the post_type being processed.
613
-         */
614
-        if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
615
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
616
-            $custom_post_types = $this->getLoader()->getShared(
617
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
618
-            );
619
-            $custom_post_types->getCustomPostTypeModels($_POST['post_type']);
620
-        }
621
-
622
-
623
-        /**
624
-         * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
625
-         * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
626
-         * Pages" tab in the EE General Settings Admin page.
627
-         * This is for user-proofing.
628
-         */
629
-        add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
630
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
631
-            $this->adminInitModelsReady();
632
-        }
633
-    }
634
-
635
-
636
-    /**
637
-     * Runs on admin_init but only if models are usable (ie, we're not in maintenanc emode)
638
-     */
639
-    protected function adminInitModelsReady()
640
-    {
641
-        if (function_exists('wp_add_privacy_policy_content')) {
642
-            $this->getLoader()->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager');
643
-        }
644
-    }
645
-
646
-
647
-    /**
648
-     * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
649
-     *
650
-     * @param string $output Current output.
651
-     * @return string
652
-     * @throws InvalidArgumentException
653
-     * @throws InvalidDataTypeException
654
-     * @throws InvalidInterfaceException
655
-     */
656
-    public function modify_dropdown_pages($output)
657
-    {
658
-        // get critical pages
659
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
660
-
661
-        // split current output by line break for easier parsing.
662
-        $split_output = explode("\n", $output);
663
-
664
-        // loop through to remove any critical pages from the array.
665
-        foreach ($critical_pages as $page_id) {
666
-            $needle = 'value="' . $page_id . '"';
667
-            foreach ($split_output as $key => $haystack) {
668
-                if (strpos($haystack, $needle) !== false) {
669
-                    unset($split_output[ $key ]);
670
-                }
671
-            }
672
-        }
673
-        // replace output with the new contents
674
-        return implode("\n", $split_output);
675
-    }
676
-
677
-
678
-    /**
679
-     * enqueue all admin scripts that need loaded for admin pages
680
-     *
681
-     * @return void
682
-     */
683
-    public function enqueue_admin_scripts()
684
-    {
685
-        // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
686
-        // Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
687
-        // calls.
688
-        wp_enqueue_script(
689
-            'ee-inject-wp',
690
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
691
-            array('jquery'),
692
-            EVENT_ESPRESSO_VERSION,
693
-            true
694
-        );
695
-        // register cookie script for future dependencies
696
-        wp_register_script(
697
-            'jquery-cookie',
698
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
699
-            array('jquery'),
700
-            '2.1',
701
-            true
702
-        );
703
-        // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
704
-        // via: add_filter('FHEE_load_joyride', '__return_true' );
705
-        if (apply_filters('FHEE_load_joyride', false)) {
706
-            // joyride style
707
-            wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
708
-            wp_register_style(
709
-                'ee-joyride-css',
710
-                EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
711
-                array('joyride-css'),
712
-                EVENT_ESPRESSO_VERSION
713
-            );
714
-            wp_register_script(
715
-                'joyride-modernizr',
716
-                EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
717
-                array(),
718
-                '2.1',
719
-                true
720
-            );
721
-            // joyride JS
722
-            wp_register_script(
723
-                'jquery-joyride',
724
-                EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
725
-                array('jquery-cookie', 'joyride-modernizr'),
726
-                '2.1',
727
-                true
728
-            );
729
-            // wanna go for a joyride?
730
-            wp_enqueue_style('ee-joyride-css');
731
-            wp_enqueue_script('jquery-joyride');
732
-        }
733
-    }
734
-
735
-
736
-    /**
737
-     * display_admin_notices
738
-     *
739
-     * @return void
740
-     */
741
-    public function display_admin_notices()
742
-    {
743
-        echo EE_Error::get_notices();
744
-    }
745
-
746
-
747
-    /**
748
-     * @param array $elements
749
-     * @return array
750
-     * @throws EE_Error
751
-     * @throws InvalidArgumentException
752
-     * @throws InvalidDataTypeException
753
-     * @throws InvalidInterfaceException
754
-     */
755
-    public function dashboard_glance_items($elements)
756
-    {
757
-        $elements = is_array($elements) ? $elements : array($elements);
758
-        $events = EEM_Event::instance()->count();
759
-        $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(
760
-            array('page' => 'espresso_events'),
761
-            admin_url('admin.php')
762
-        );
763
-        $items['events']['text'] = sprintf(
764
-            esc_html(
765
-                _n('%s Event', '%s Events', $events, 'event_espresso')
766
-            ),
767
-            number_format_i18n($events)
768
-        );
769
-        $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso');
770
-        $registrations = EEM_Registration::instance()->count(
771
-            array(
772
-                array(
773
-                    'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
774
-                ),
775
-            )
776
-        );
777
-        $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
778
-            array('page' => 'espresso_registrations'),
779
-            admin_url('admin.php')
780
-        );
781
-        $items['registrations']['text'] = sprintf(
782
-            esc_html(
783
-                _n('%s Registration', '%s Registrations', $registrations, 'event_espresso')
784
-            ),
785
-            number_format_i18n($registrations)
786
-        );
787
-        $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
788
-
789
-        $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
790
-
791
-        foreach ($items as $type => $item_properties) {
792
-            $elements[] = sprintf(
793
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
794
-                $item_properties['url'],
795
-                $item_properties['title'],
796
-                $item_properties['text']
797
-            );
798
-        }
799
-        return $elements;
800
-    }
801
-
802
-
803
-    /**
804
-     * check_for_invalid_datetime_formats
805
-     * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
806
-     * their selected format can be parsed by PHP
807
-     *
808
-     * @param    $value
809
-     * @param    $option
810
-     * @throws EE_Error
811
-     * @return    string
812
-     */
813
-    public function check_for_invalid_datetime_formats($value, $option)
814
-    {
815
-        // check for date_format or time_format
816
-        switch ($option) {
817
-            case 'date_format':
818
-                $date_time_format = $value . ' ' . get_option('time_format');
819
-                break;
820
-            case 'time_format':
821
-                $date_time_format = get_option('date_format') . ' ' . $value;
822
-                break;
823
-            default:
824
-                $date_time_format = false;
825
-        }
826
-        // do we have a date_time format to check ?
827
-        if ($date_time_format) {
828
-            $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
829
-
830
-            if (is_array($error_msg)) {
831
-                $msg = '<p>'
832
-                       . sprintf(
833
-                           esc_html__(
834
-                               'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
835
-                               'event_espresso'
836
-                           ),
837
-                           date($date_time_format),
838
-                           $date_time_format
839
-                       )
840
-                       . '</p><p><ul>';
841
-
842
-
843
-                foreach ($error_msg as $error) {
844
-                    $msg .= '<li>' . $error . '</li>';
845
-                }
846
-
847
-                $msg .= '</ul></p><p>'
848
-                        . sprintf(
849
-                            esc_html__(
850
-                                '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
851
-                                'event_espresso'
852
-                            ),
853
-                            '<span style="color:#D54E21;">',
854
-                            '</span>'
855
-                        )
856
-                        . '</p>';
857
-
858
-                // trigger WP settings error
859
-                add_settings_error(
860
-                    'date_format',
861
-                    'date_format',
862
-                    $msg
863
-                );
864
-
865
-                // set format to something valid
866
-                switch ($option) {
867
-                    case 'date_format':
868
-                        $value = 'F j, Y';
869
-                        break;
870
-                    case 'time_format':
871
-                        $value = 'g:i a';
872
-                        break;
873
-                }
874
-            }
875
-        }
876
-        return $value;
877
-    }
878
-
879
-
880
-    /**
881
-     * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
882
-     *
883
-     * @param $content
884
-     * @return    string
885
-     */
886
-    public function its_eSpresso($content)
887
-    {
888
-        return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
889
-    }
890
-
891
-
892
-    /**
893
-     * espresso_admin_footer
894
-     *
895
-     * @return    string
896
-     */
897
-    public function espresso_admin_footer()
898
-    {
899
-        return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
900
-    }
901
-
902
-
903
-    /**
904
-     * static method for registering ee admin page.
905
-     * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
906
-     *
907
-     * @since      4.3.0
908
-     * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
909
-     * @see        EE_Register_Admin_Page::register()
910
-     * @param       $page_basename
911
-     * @param       $page_path
912
-     * @param array $config
913
-     * @return void
914
-     * @throws EE_Error
915
-     */
916
-    public static function register_ee_admin_page($page_basename, $page_path, $config = array())
917
-    {
918
-        EE_Error::doing_it_wrong(
919
-            __METHOD__,
920
-            sprintf(
921
-                esc_html__(
922
-                    'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
923
-                    'event_espresso'
924
-                ),
925
-                $page_basename
926
-            ),
927
-            '4.3'
928
-        );
929
-        if (class_exists('EE_Register_Admin_Page')) {
930
-            $config['page_path'] = $page_path;
931
-        }
932
-        EE_Register_Admin_Page::register($page_basename, $config);
933
-    }
934
-
935
-
936
-    /**
937
-     * @deprecated 4.8.41
938
-     * @param  int      $post_ID
939
-     * @param  \WP_Post $post
940
-     * @return void
941
-     */
942
-    public static function parse_post_content_on_save($post_ID, $post)
943
-    {
944
-        EE_Error::doing_it_wrong(
945
-            __METHOD__,
946
-            esc_html__('Usage is deprecated', 'event_espresso'),
947
-            '4.8.41'
948
-        );
949
-    }
950
-
951
-
952
-    /**
953
-     * @deprecated 4.8.41
954
-     * @param  $option
955
-     * @param  $old_value
956
-     * @param  $value
957
-     * @return void
958
-     */
959
-    public function reset_page_for_posts_on_change($option, $old_value, $value)
960
-    {
961
-        EE_Error::doing_it_wrong(
962
-            __METHOD__,
963
-            esc_html__('Usage is deprecated', 'event_espresso'),
964
-            '4.8.41'
965
-        );
966
-    }
967
-
968
-
969
-    /**
970
-     * @deprecated 4.9.27
971
-     * @return void
972
-     */
973
-    public function get_persistent_admin_notices()
974
-    {
975
-        EE_Error::doing_it_wrong(
976
-            __METHOD__,
977
-            sprintf(
978
-                esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
979
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
980
-            ),
981
-            '4.9.27'
982
-        );
983
-    }
984
-
985
-
986
-    /**
987
-     * @deprecated 4.9.27
988
-     * @throws InvalidInterfaceException
989
-     * @throws InvalidDataTypeException
990
-     * @throws DomainException
991
-     */
992
-    public function dismiss_ee_nag_notice_callback()
993
-    {
994
-        EE_Error::doing_it_wrong(
995
-            __METHOD__,
996
-            sprintf(
997
-                esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
998
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
999
-            ),
1000
-            '4.9.27'
1001
-        );
1002
-        $this->persistent_admin_notice_manager->dismissNotice();
1003
-    }
1004
-
1005
-
1006
-    /**
1007
-     * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page.
1008
-     *
1009
-     * @throws InvalidArgumentException
1010
-     * @throws InvalidDataTypeException
1011
-     * @throws InvalidInterfaceException
1012
-     */
1013
-    public function hookIntoWpPluginsPage()
1014
-    {
1015
-        $this->getLoader()->getShared('EventEspresso\core\domain\services\admin\ExitModal');
1016
-        $this->getLoader()
1017
-                     ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells')
1018
-                     ->decafUpsells();
1019
-    }
1020
-
1021
-
1022
-    /**
1023
-     * Hooks into the "post states" filter in a wp post type list table.
1024
-     *
1025
-     * @param array   $post_states
1026
-     * @param WP_Post $post
1027
-     * @return array
1028
-     * @throws InvalidArgumentException
1029
-     * @throws InvalidDataTypeException
1030
-     * @throws InvalidInterfaceException
1031
-     */
1032
-    public function displayStateForCriticalPages($post_states, $post)
1033
-    {
1034
-        $post_states = (array) $post_states;
1035
-        if (! $post instanceof WP_Post || $post->post_type !== 'page') {
1036
-            return $post_states;
1037
-        }
1038
-        /** @var EE_Core_Config $config */
1039
-        $config = $this->getLoader()->getShared('EE_Config')->core;
1040
-        if (in_array($post->ID, $config->get_critical_pages_array(), true)) {
1041
-            $post_states[] = sprintf(
1042
-                /* Translators: Using company name - Event Espresso Critical Page */
1043
-                esc_html__('%s Critical Page', 'event_espresso'),
1044
-                'Event Espresso'
1045
-            );
1046
-        }
1047
-        return $post_states;
1048
-    }
1049
-
1050
-
1051
-    /**
1052
-     * Show documentation links on the plugins page
1053
-     *
1054
-     * @param mixed $meta Plugin Row Meta
1055
-     * @param mixed $file Plugin Base file
1056
-     * @return array
1057
-     */
1058
-    public function addLinksToPluginRowMeta($meta, $file)
1059
-    {
1060
-        if (EE_PLUGIN_BASENAME === $file) {
1061
-            $row_meta = array(
1062
-                'docs' => '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4"'
1063
-                          . ' aria-label="'
1064
-                          . esc_attr__('View Event Espresso documentation', 'event_espresso')
1065
-                          . '">'
1066
-                          . esc_html__('Docs', 'event_espresso')
1067
-                          . '</a>',
1068
-                'api'  => '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API"'
1069
-                          . ' aria-label="'
1070
-                          . esc_attr__('View Event Espresso API docs', 'event_espresso')
1071
-                          . '">'
1072
-                          . esc_html__('API docs', 'event_espresso')
1073
-                          . '</a>',
1074
-            );
1075
-            return array_merge($meta, $row_meta);
1076
-        }
1077
-        return (array) $meta;
1078
-    }
517
+	}
518
+
519
+
520
+	/**
521
+	 * Returns an array of event archive nav items.
522
+	 *
523
+	 * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
524
+	 *        method we use for getting the extra nav menu items
525
+	 * @return array
526
+	 */
527
+	private function _get_extra_nav_menu_pages_items()
528
+	{
529
+		$menuitems[] = array(
530
+			'title'       => esc_html__('Event List', 'event_espresso'),
531
+			'url'         => get_post_type_archive_link('espresso_events'),
532
+			'description' => esc_html__('Archive page for all events.', 'event_espresso'),
533
+		);
534
+		return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
535
+	}
536
+
537
+
538
+	/**
539
+	 * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
540
+	 * the properties and converts it to the menu item object.
541
+	 *
542
+	 * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
543
+	 * @param $menu_item_values
544
+	 * @return stdClass
545
+	 */
546
+	private function _setup_extra_nav_menu_pages_items($menu_item_values)
547
+	{
548
+		$menu_item = new stdClass();
549
+		$keys = array(
550
+			'ID'               => 0,
551
+			'db_id'            => 0,
552
+			'menu_item_parent' => 0,
553
+			'object_id'        => -1,
554
+			'post_parent'      => 0,
555
+			'type'             => 'custom',
556
+			'object'           => '',
557
+			'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
558
+			'title'            => '',
559
+			'url'              => '',
560
+			'target'           => '',
561
+			'attr_title'       => '',
562
+			'description'      => '',
563
+			'classes'          => array(),
564
+			'xfn'              => '',
565
+		);
566
+
567
+		foreach ($keys as $key => $value) {
568
+			$menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
569
+		}
570
+		return $menu_item;
571
+	}
572
+
573
+
574
+	/**
575
+	 * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
576
+	 * EE_Admin_Page route is called.
577
+	 *
578
+	 * @return void
579
+	 */
580
+	public function route_admin_request()
581
+	{
582
+	}
583
+
584
+
585
+	/**
586
+	 * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
587
+	 *
588
+	 * @return void
589
+	 */
590
+	public function wp_loaded()
591
+	{
592
+	}
593
+
594
+
595
+	/**
596
+	 * admin_init
597
+	 *
598
+	 * @return void
599
+	 * @throws EE_Error
600
+	 * @throws InvalidArgumentException
601
+	 * @throws InvalidDataTypeException
602
+	 * @throws InvalidInterfaceException
603
+	 * @throws ReflectionException
604
+	 */
605
+	public function admin_init()
606
+	{
607
+		/**
608
+		 * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
609
+		 * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
610
+		 * - check if doing post processing.
611
+		 * - check if doing post processing of one of EE CPTs
612
+		 * - instantiate the corresponding EE CPT model for the post_type being processed.
613
+		 */
614
+		if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
615
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
616
+			$custom_post_types = $this->getLoader()->getShared(
617
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
618
+			);
619
+			$custom_post_types->getCustomPostTypeModels($_POST['post_type']);
620
+		}
621
+
622
+
623
+		/**
624
+		 * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
625
+		 * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
626
+		 * Pages" tab in the EE General Settings Admin page.
627
+		 * This is for user-proofing.
628
+		 */
629
+		add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
630
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
631
+			$this->adminInitModelsReady();
632
+		}
633
+	}
634
+
635
+
636
+	/**
637
+	 * Runs on admin_init but only if models are usable (ie, we're not in maintenanc emode)
638
+	 */
639
+	protected function adminInitModelsReady()
640
+	{
641
+		if (function_exists('wp_add_privacy_policy_content')) {
642
+			$this->getLoader()->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager');
643
+		}
644
+	}
645
+
646
+
647
+	/**
648
+	 * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
649
+	 *
650
+	 * @param string $output Current output.
651
+	 * @return string
652
+	 * @throws InvalidArgumentException
653
+	 * @throws InvalidDataTypeException
654
+	 * @throws InvalidInterfaceException
655
+	 */
656
+	public function modify_dropdown_pages($output)
657
+	{
658
+		// get critical pages
659
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
660
+
661
+		// split current output by line break for easier parsing.
662
+		$split_output = explode("\n", $output);
663
+
664
+		// loop through to remove any critical pages from the array.
665
+		foreach ($critical_pages as $page_id) {
666
+			$needle = 'value="' . $page_id . '"';
667
+			foreach ($split_output as $key => $haystack) {
668
+				if (strpos($haystack, $needle) !== false) {
669
+					unset($split_output[ $key ]);
670
+				}
671
+			}
672
+		}
673
+		// replace output with the new contents
674
+		return implode("\n", $split_output);
675
+	}
676
+
677
+
678
+	/**
679
+	 * enqueue all admin scripts that need loaded for admin pages
680
+	 *
681
+	 * @return void
682
+	 */
683
+	public function enqueue_admin_scripts()
684
+	{
685
+		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
686
+		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
687
+		// calls.
688
+		wp_enqueue_script(
689
+			'ee-inject-wp',
690
+			EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
691
+			array('jquery'),
692
+			EVENT_ESPRESSO_VERSION,
693
+			true
694
+		);
695
+		// register cookie script for future dependencies
696
+		wp_register_script(
697
+			'jquery-cookie',
698
+			EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
699
+			array('jquery'),
700
+			'2.1',
701
+			true
702
+		);
703
+		// joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
704
+		// via: add_filter('FHEE_load_joyride', '__return_true' );
705
+		if (apply_filters('FHEE_load_joyride', false)) {
706
+			// joyride style
707
+			wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
708
+			wp_register_style(
709
+				'ee-joyride-css',
710
+				EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
711
+				array('joyride-css'),
712
+				EVENT_ESPRESSO_VERSION
713
+			);
714
+			wp_register_script(
715
+				'joyride-modernizr',
716
+				EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
717
+				array(),
718
+				'2.1',
719
+				true
720
+			);
721
+			// joyride JS
722
+			wp_register_script(
723
+				'jquery-joyride',
724
+				EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
725
+				array('jquery-cookie', 'joyride-modernizr'),
726
+				'2.1',
727
+				true
728
+			);
729
+			// wanna go for a joyride?
730
+			wp_enqueue_style('ee-joyride-css');
731
+			wp_enqueue_script('jquery-joyride');
732
+		}
733
+	}
734
+
735
+
736
+	/**
737
+	 * display_admin_notices
738
+	 *
739
+	 * @return void
740
+	 */
741
+	public function display_admin_notices()
742
+	{
743
+		echo EE_Error::get_notices();
744
+	}
745
+
746
+
747
+	/**
748
+	 * @param array $elements
749
+	 * @return array
750
+	 * @throws EE_Error
751
+	 * @throws InvalidArgumentException
752
+	 * @throws InvalidDataTypeException
753
+	 * @throws InvalidInterfaceException
754
+	 */
755
+	public function dashboard_glance_items($elements)
756
+	{
757
+		$elements = is_array($elements) ? $elements : array($elements);
758
+		$events = EEM_Event::instance()->count();
759
+		$items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(
760
+			array('page' => 'espresso_events'),
761
+			admin_url('admin.php')
762
+		);
763
+		$items['events']['text'] = sprintf(
764
+			esc_html(
765
+				_n('%s Event', '%s Events', $events, 'event_espresso')
766
+			),
767
+			number_format_i18n($events)
768
+		);
769
+		$items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso');
770
+		$registrations = EEM_Registration::instance()->count(
771
+			array(
772
+				array(
773
+					'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
774
+				),
775
+			)
776
+		);
777
+		$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
778
+			array('page' => 'espresso_registrations'),
779
+			admin_url('admin.php')
780
+		);
781
+		$items['registrations']['text'] = sprintf(
782
+			esc_html(
783
+				_n('%s Registration', '%s Registrations', $registrations, 'event_espresso')
784
+			),
785
+			number_format_i18n($registrations)
786
+		);
787
+		$items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
788
+
789
+		$items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
790
+
791
+		foreach ($items as $type => $item_properties) {
792
+			$elements[] = sprintf(
793
+				'<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
794
+				$item_properties['url'],
795
+				$item_properties['title'],
796
+				$item_properties['text']
797
+			);
798
+		}
799
+		return $elements;
800
+	}
801
+
802
+
803
+	/**
804
+	 * check_for_invalid_datetime_formats
805
+	 * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
806
+	 * their selected format can be parsed by PHP
807
+	 *
808
+	 * @param    $value
809
+	 * @param    $option
810
+	 * @throws EE_Error
811
+	 * @return    string
812
+	 */
813
+	public function check_for_invalid_datetime_formats($value, $option)
814
+	{
815
+		// check for date_format or time_format
816
+		switch ($option) {
817
+			case 'date_format':
818
+				$date_time_format = $value . ' ' . get_option('time_format');
819
+				break;
820
+			case 'time_format':
821
+				$date_time_format = get_option('date_format') . ' ' . $value;
822
+				break;
823
+			default:
824
+				$date_time_format = false;
825
+		}
826
+		// do we have a date_time format to check ?
827
+		if ($date_time_format) {
828
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
829
+
830
+			if (is_array($error_msg)) {
831
+				$msg = '<p>'
832
+					   . sprintf(
833
+						   esc_html__(
834
+							   'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
835
+							   'event_espresso'
836
+						   ),
837
+						   date($date_time_format),
838
+						   $date_time_format
839
+					   )
840
+					   . '</p><p><ul>';
841
+
842
+
843
+				foreach ($error_msg as $error) {
844
+					$msg .= '<li>' . $error . '</li>';
845
+				}
846
+
847
+				$msg .= '</ul></p><p>'
848
+						. sprintf(
849
+							esc_html__(
850
+								'%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
851
+								'event_espresso'
852
+							),
853
+							'<span style="color:#D54E21;">',
854
+							'</span>'
855
+						)
856
+						. '</p>';
857
+
858
+				// trigger WP settings error
859
+				add_settings_error(
860
+					'date_format',
861
+					'date_format',
862
+					$msg
863
+				);
864
+
865
+				// set format to something valid
866
+				switch ($option) {
867
+					case 'date_format':
868
+						$value = 'F j, Y';
869
+						break;
870
+					case 'time_format':
871
+						$value = 'g:i a';
872
+						break;
873
+				}
874
+			}
875
+		}
876
+		return $value;
877
+	}
878
+
879
+
880
+	/**
881
+	 * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
882
+	 *
883
+	 * @param $content
884
+	 * @return    string
885
+	 */
886
+	public function its_eSpresso($content)
887
+	{
888
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
889
+	}
890
+
891
+
892
+	/**
893
+	 * espresso_admin_footer
894
+	 *
895
+	 * @return    string
896
+	 */
897
+	public function espresso_admin_footer()
898
+	{
899
+		return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
900
+	}
901
+
902
+
903
+	/**
904
+	 * static method for registering ee admin page.
905
+	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
906
+	 *
907
+	 * @since      4.3.0
908
+	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
909
+	 * @see        EE_Register_Admin_Page::register()
910
+	 * @param       $page_basename
911
+	 * @param       $page_path
912
+	 * @param array $config
913
+	 * @return void
914
+	 * @throws EE_Error
915
+	 */
916
+	public static function register_ee_admin_page($page_basename, $page_path, $config = array())
917
+	{
918
+		EE_Error::doing_it_wrong(
919
+			__METHOD__,
920
+			sprintf(
921
+				esc_html__(
922
+					'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
923
+					'event_espresso'
924
+				),
925
+				$page_basename
926
+			),
927
+			'4.3'
928
+		);
929
+		if (class_exists('EE_Register_Admin_Page')) {
930
+			$config['page_path'] = $page_path;
931
+		}
932
+		EE_Register_Admin_Page::register($page_basename, $config);
933
+	}
934
+
935
+
936
+	/**
937
+	 * @deprecated 4.8.41
938
+	 * @param  int      $post_ID
939
+	 * @param  \WP_Post $post
940
+	 * @return void
941
+	 */
942
+	public static function parse_post_content_on_save($post_ID, $post)
943
+	{
944
+		EE_Error::doing_it_wrong(
945
+			__METHOD__,
946
+			esc_html__('Usage is deprecated', 'event_espresso'),
947
+			'4.8.41'
948
+		);
949
+	}
950
+
951
+
952
+	/**
953
+	 * @deprecated 4.8.41
954
+	 * @param  $option
955
+	 * @param  $old_value
956
+	 * @param  $value
957
+	 * @return void
958
+	 */
959
+	public function reset_page_for_posts_on_change($option, $old_value, $value)
960
+	{
961
+		EE_Error::doing_it_wrong(
962
+			__METHOD__,
963
+			esc_html__('Usage is deprecated', 'event_espresso'),
964
+			'4.8.41'
965
+		);
966
+	}
967
+
968
+
969
+	/**
970
+	 * @deprecated 4.9.27
971
+	 * @return void
972
+	 */
973
+	public function get_persistent_admin_notices()
974
+	{
975
+		EE_Error::doing_it_wrong(
976
+			__METHOD__,
977
+			sprintf(
978
+				esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
979
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
980
+			),
981
+			'4.9.27'
982
+		);
983
+	}
984
+
985
+
986
+	/**
987
+	 * @deprecated 4.9.27
988
+	 * @throws InvalidInterfaceException
989
+	 * @throws InvalidDataTypeException
990
+	 * @throws DomainException
991
+	 */
992
+	public function dismiss_ee_nag_notice_callback()
993
+	{
994
+		EE_Error::doing_it_wrong(
995
+			__METHOD__,
996
+			sprintf(
997
+				esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
998
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
999
+			),
1000
+			'4.9.27'
1001
+		);
1002
+		$this->persistent_admin_notice_manager->dismissNotice();
1003
+	}
1004
+
1005
+
1006
+	/**
1007
+	 * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page.
1008
+	 *
1009
+	 * @throws InvalidArgumentException
1010
+	 * @throws InvalidDataTypeException
1011
+	 * @throws InvalidInterfaceException
1012
+	 */
1013
+	public function hookIntoWpPluginsPage()
1014
+	{
1015
+		$this->getLoader()->getShared('EventEspresso\core\domain\services\admin\ExitModal');
1016
+		$this->getLoader()
1017
+					 ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells')
1018
+					 ->decafUpsells();
1019
+	}
1020
+
1021
+
1022
+	/**
1023
+	 * Hooks into the "post states" filter in a wp post type list table.
1024
+	 *
1025
+	 * @param array   $post_states
1026
+	 * @param WP_Post $post
1027
+	 * @return array
1028
+	 * @throws InvalidArgumentException
1029
+	 * @throws InvalidDataTypeException
1030
+	 * @throws InvalidInterfaceException
1031
+	 */
1032
+	public function displayStateForCriticalPages($post_states, $post)
1033
+	{
1034
+		$post_states = (array) $post_states;
1035
+		if (! $post instanceof WP_Post || $post->post_type !== 'page') {
1036
+			return $post_states;
1037
+		}
1038
+		/** @var EE_Core_Config $config */
1039
+		$config = $this->getLoader()->getShared('EE_Config')->core;
1040
+		if (in_array($post->ID, $config->get_critical_pages_array(), true)) {
1041
+			$post_states[] = sprintf(
1042
+				/* Translators: Using company name - Event Espresso Critical Page */
1043
+				esc_html__('%s Critical Page', 'event_espresso'),
1044
+				'Event Espresso'
1045
+			);
1046
+		}
1047
+		return $post_states;
1048
+	}
1049
+
1050
+
1051
+	/**
1052
+	 * Show documentation links on the plugins page
1053
+	 *
1054
+	 * @param mixed $meta Plugin Row Meta
1055
+	 * @param mixed $file Plugin Base file
1056
+	 * @return array
1057
+	 */
1058
+	public function addLinksToPluginRowMeta($meta, $file)
1059
+	{
1060
+		if (EE_PLUGIN_BASENAME === $file) {
1061
+			$row_meta = array(
1062
+				'docs' => '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4"'
1063
+						  . ' aria-label="'
1064
+						  . esc_attr__('View Event Espresso documentation', 'event_espresso')
1065
+						  . '">'
1066
+						  . esc_html__('Docs', 'event_espresso')
1067
+						  . '</a>',
1068
+				'api'  => '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API"'
1069
+						  . ' aria-label="'
1070
+						  . esc_attr__('View Event Espresso API docs', 'event_espresso')
1071
+						  . '">'
1072
+						  . esc_html__('API docs', 'event_espresso')
1073
+						  . '</a>',
1074
+			);
1075
+			return array_merge($meta, $row_meta);
1076
+		}
1077
+		return (array) $meta;
1078
+	}
1079 1079
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
     public static function instance()
44 44
     {
45 45
         // check if class object is instantiated
46
-        if (! self::$_instance instanceof EE_Admin) {
46
+        if ( ! self::$_instance instanceof EE_Admin) {
47 47
             self::$_instance = new self();
48 48
         }
49 49
         return self::$_instance;
@@ -105,11 +105,11 @@  discard block
 block discarded – undo
105 105
      */
106 106
     private function _define_all_constants()
107 107
     {
108
-        if (! defined('EE_ADMIN_URL')) {
109
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
110
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
111
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/');
112
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
108
+        if ( ! defined('EE_ADMIN_URL')) {
109
+            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/');
110
+            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/');
111
+            define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates/');
112
+            define('WP_ADMIN_PATH', ABSPATH.'wp-admin/');
113 113
             define('WP_AJAX_URL', admin_url('admin-ajax.php'));
114 114
         }
115 115
     }
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         // set $main_file in stone
128 128
         static $main_file;
129 129
         // if $main_file is not set yet
130
-        if (! $main_file) {
130
+        if ( ! $main_file) {
131 131
             $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
132 132
         }
133 133
         if ($plugin === $main_file) {
@@ -178,9 +178,9 @@  discard block
 block discarded – undo
178 178
     public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
179 179
     {
180 180
         return array(
181
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance/',
182
-            'about'       => EE_ADMIN_PAGES . 'about/',
183
-            'support'     => EE_ADMIN_PAGES . 'support/',
181
+            'maintenance' => EE_ADMIN_PAGES.'maintenance/',
182
+            'about'       => EE_ADMIN_PAGES.'about/',
183
+            'support'     => EE_ADMIN_PAGES.'support/',
184 184
         );
185 185
     }
186 186
 
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
             $this->initModelsReady();
205 205
         }
206 206
         // run the admin page factory but ONLY if we are doing an ee admin ajax request
207
-        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
207
+        if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
208 208
             try {
209 209
                 // this loads the controller for the admin pages which will setup routing etc
210 210
                 EE_Registry::instance()->load_core('Admin_Page_Loader');
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
      */
231 231
     protected function getLoader()
232 232
     {
233
-        if (! $this->loader instanceof LoaderInterface) {
233
+        if ( ! $this->loader instanceof LoaderInterface) {
234 234
             $this->loader = LoaderFactory::getLoader();
235 235
         }
236 236
         return $this->loader;
@@ -297,13 +297,13 @@  discard block
 block discarded – undo
297 297
                     '</strong>',
298 298
                     '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
299 299
                     '</a>',
300
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
300
+                    '<a href="'.EE_Admin_Page::add_query_args_and_nonce(
301 301
                         array(
302 302
                             'page'   => 'espresso_maintenance_settings',
303 303
                             'action' => 'datetime_tools',
304 304
                         ),
305 305
                         admin_url('admin.php')
306
-                    ) . '">'
306
+                    ).'">'
307 307
                 ),
308 308
                 false,
309 309
                 'manage_options',
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
     public function enable_hidden_ee_nav_menu_metaboxes()
350 350
     {
351 351
         global $wp_meta_boxes, $pagenow;
352
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
352
+        if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
353 353
             return;
354 354
         }
355 355
         $user = wp_get_current_user();
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
         if (is_array($hidden_meta_boxes)) {
379 379
             foreach ($hidden_meta_boxes as $key => $meta_box_id) {
380 380
                 if (in_array($meta_box_id, $initial_meta_boxes, true)) {
381
-                    unset($hidden_meta_boxes[ $key ]);
381
+                    unset($hidden_meta_boxes[$key]);
382 382
                 }
383 383
             }
384 384
         }
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
      */
419 419
     public function modify_edit_post_link($link, $id)
420 420
     {
421
-        if (! $post = get_post($id)) {
421
+        if ( ! $post = get_post($id)) {
422 422
             return $link;
423 423
         }
424 424
         if ($post->post_type === 'espresso_attendees') {
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
         );
566 566
 
567 567
         foreach ($keys as $key => $value) {
568
-            $menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
568
+            $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
569 569
         }
570 570
         return $menu_item;
571 571
     }
@@ -663,10 +663,10 @@  discard block
 block discarded – undo
663 663
 
664 664
         // loop through to remove any critical pages from the array.
665 665
         foreach ($critical_pages as $page_id) {
666
-            $needle = 'value="' . $page_id . '"';
666
+            $needle = 'value="'.$page_id.'"';
667 667
             foreach ($split_output as $key => $haystack) {
668 668
                 if (strpos($haystack, $needle) !== false) {
669
-                    unset($split_output[ $key ]);
669
+                    unset($split_output[$key]);
670 670
                 }
671 671
             }
672 672
         }
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
         // calls.
688 688
         wp_enqueue_script(
689 689
             'ee-inject-wp',
690
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
690
+            EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js',
691 691
             array('jquery'),
692 692
             EVENT_ESPRESSO_VERSION,
693 693
             true
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
         // register cookie script for future dependencies
696 696
         wp_register_script(
697 697
             'jquery-cookie',
698
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
698
+            EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js',
699 699
             array('jquery'),
700 700
             '2.1',
701 701
             true
@@ -704,16 +704,16 @@  discard block
 block discarded – undo
704 704
         // via: add_filter('FHEE_load_joyride', '__return_true' );
705 705
         if (apply_filters('FHEE_load_joyride', false)) {
706 706
             // joyride style
707
-            wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
707
+            wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1');
708 708
             wp_register_style(
709 709
                 'ee-joyride-css',
710
-                EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
710
+                EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css',
711 711
                 array('joyride-css'),
712 712
                 EVENT_ESPRESSO_VERSION
713 713
             );
714 714
             wp_register_script(
715 715
                 'joyride-modernizr',
716
-                EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
716
+                EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js',
717 717
                 array(),
718 718
                 '2.1',
719 719
                 true
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
             // joyride JS
722 722
             wp_register_script(
723 723
                 'jquery-joyride',
724
-                EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
724
+                EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js',
725 725
                 array('jquery-cookie', 'joyride-modernizr'),
726 726
                 '2.1',
727 727
                 true
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
 
791 791
         foreach ($items as $type => $item_properties) {
792 792
             $elements[] = sprintf(
793
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
793
+                '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>',
794 794
                 $item_properties['url'],
795 795
                 $item_properties['title'],
796 796
                 $item_properties['text']
@@ -815,10 +815,10 @@  discard block
 block discarded – undo
815 815
         // check for date_format or time_format
816 816
         switch ($option) {
817 817
             case 'date_format':
818
-                $date_time_format = $value . ' ' . get_option('time_format');
818
+                $date_time_format = $value.' '.get_option('time_format');
819 819
                 break;
820 820
             case 'time_format':
821
-                $date_time_format = get_option('date_format') . ' ' . $value;
821
+                $date_time_format = get_option('date_format').' '.$value;
822 822
                 break;
823 823
             default:
824 824
                 $date_time_format = false;
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
 
842 842
 
843 843
                 foreach ($error_msg as $error) {
844
-                    $msg .= '<li>' . $error . '</li>';
844
+                    $msg .= '<li>'.$error.'</li>';
845 845
                 }
846 846
 
847 847
                 $msg .= '</ul></p><p>'
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
     public function displayStateForCriticalPages($post_states, $post)
1033 1033
     {
1034 1034
         $post_states = (array) $post_states;
1035
-        if (! $post instanceof WP_Post || $post->post_type !== 'page') {
1035
+        if ( ! $post instanceof WP_Post || $post->post_type !== 'page') {
1036 1036
             return $post_states;
1037 1037
         }
1038 1038
         /** @var EE_Core_Config $config */
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Loader.core.php 2 patches
Indentation   +673 added lines, -673 removed lines patch added patch discarded remove patch
@@ -24,677 +24,677 @@
 block discarded – undo
24 24
 class EE_Admin_Page_Loader
25 25
 {
26 26
 
27
-    /**
28
-     * _installed_pages
29
-     * objects for page_init objects detected and loaded
30
-     *
31
-     * @access private
32
-     * @var \EE_Admin_Page_Init[]
33
-     */
34
-    private $_installed_pages = array();
35
-
36
-
37
-    /**
38
-     * this is used to hold the registry of menu slugs for all the installed admin pages
39
-     *
40
-     * @var array
41
-     */
42
-    private $_menu_slugs = array();
43
-
44
-
45
-    /**
46
-     * _caffeinated_extends
47
-     * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and
48
-     * pieces needed to do so).  This property is defined in the _set_caffeinated method.
49
-     *
50
-     * @var array
51
-     */
52
-    private $_caffeinated_extends = array();
53
-
54
-
55
-    /**
56
-     * _current_caf_extend_slug
57
-     * This property is used for holding the page slug that is required for referencing the correct
58
-     * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed.
59
-     *
60
-     * @var array
61
-     */
62
-    private $_current_caf_extend_slug;
63
-
64
-    /**
65
-     * _prepped_menu_maps
66
-     * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu.
67
-     *
68
-     * @since  4.4.0
69
-     * @var EE_Admin_Page_Menu_Map[]
70
-     */
71
-    private $_prepped_menu_maps = array();
72
-
73
-
74
-    /**
75
-     * _admin_menu_groups
76
-     * array that holds the group headings and details for
77
-     *
78
-     * @access private
79
-     * @var array
80
-     */
81
-    private $_admin_menu_groups = array();
82
-
83
-
84
-    /**
85
-     * This property will hold the hook file for setting up the filter that does all the connections between admin
86
-     * pages.
87
-     *
88
-     * @var string
89
-     */
90
-    public $hook_file;
91
-
92
-
93
-    /**
94
-     * constructor
95
-     *
96
-     * @access public
97
-     * @return \EE_Admin_Page_Loader
98
-     */
99
-    public function __construct()
100
-    {
101
-        // load menu_map classes
102
-        EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core');
103
-        // define the default "groups" for the admin_pages
104
-        $this->_set_menu_groups();
105
-
106
-        // let's do a scan and see what installed pages we have
107
-        $this->_get_installed_pages();
108
-        // set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to).
109
-        add_action('admin_menu', array($this, 'set_menus'));
110
-        add_action('network_admin_menu', array($this, 'set_network_menus'));
111
-    }
112
-
113
-
114
-    /**
115
-     * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by
116
-     * files in the caffeinated folder.
117
-     *
118
-     * @access private
119
-     * @return void
120
-     */
121
-    private function _define_caffeinated_constants()
122
-    {
123
-        if (! defined('EE_CORE_CAF_ADMIN')) {
124
-            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
125
-            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
126
-            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
127
-            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
128
-            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
129
-            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
130
-        }
131
-    }
132
-
133
-
134
-    /**
135
-     * _set_menu_groups
136
-     * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array)
137
-     *
138
-     * @access private
139
-     * @return void
140
-     */
141
-    private function _set_menu_groups()
142
-    {
143
-
144
-        // set array of EE_Admin_Page_Menu_Group objects
145
-        $groups = array(
146
-            'main'       => new EE_Admin_Page_Menu_Group(
147
-                array(
148
-                    'menu_label'   => __('Main', 'event_espresso'),
149
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::NONE,
150
-                    'menu_slug'    => 'main',
151
-                    'capability'   => 'ee_read_ee',
152
-                    'menu_order'   => 0,
153
-                    'parent_slug'  => 'espresso_events',
154
-                )
155
-            ),
156
-            'management' => new EE_Admin_Page_Menu_Group(
157
-                array(
158
-                    'menu_label'   => __('Management', 'event_espresso'),
159
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
160
-                    'menu_slug'    => 'management',
161
-                    'capability'   => 'ee_read_ee',
162
-                    'menu_order'   => 10,
163
-                    'parent_slug'  => 'espresso_events',
164
-                )
165
-            ),
166
-            'settings'   => new EE_Admin_Page_Menu_Group(
167
-                array(
168
-                    'menu_label'   => __('Settings', 'event_espresso'),
169
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
170
-                    'menu_slug'    => 'settings',
171
-                    'capability'   => 'ee_read_ee',
172
-                    'menu_order'   => 30,
173
-                    'parent_slug'  => 'espresso_events',
174
-                )
175
-            ),
176
-            'templates'  => new EE_Admin_Page_Menu_Group(
177
-                array(
178
-                    'menu_label'   => __('Templates', 'event_espresso'),
179
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
180
-                    'menu_slug'    => 'templates',
181
-                    'capability'   => 'ee_read_ee',
182
-                    'menu_order'   => 40,
183
-                    'parent_slug'  => 'espresso_events',
184
-                )
185
-            ),
186
-            'extras'     => new EE_Admin_Page_Menu_Group(
187
-                array(
188
-                    'menu_label'              => __('Extras', 'event_espresso'),
189
-                    'show_on_menu'            => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
190
-                    'menu_slug'               => 'extras',
191
-                    'capability'              => 'ee_read_ee',
192
-                    'menu_order'              => 50,
193
-                    'parent_slug'             => 'espresso_events',
194
-                    'maintenance_mode_parent' => 'espresso_maintenance_settings',
195
-                )
196
-            ),
197
-            'tools'      => new EE_Admin_Page_Menu_Group(
198
-                array(
199
-                    'menu_label'   => __("Tools", "event_espresso"),
200
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
201
-                    'menu_slug'    => 'tools',
202
-                    'capability'   => 'ee_read_ee',
203
-                    'menu_order'   => 60,
204
-                    'parent_slug'  => 'espresso_events',
205
-                )
206
-            ),
207
-            'addons'     => new EE_Admin_Page_Menu_Group(
208
-                array(
209
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
210
-                    'menu_label'   => __('Add-ons', 'event_espresso'),
211
-                    'menu_slug'    => 'addons',
212
-                    'capability'   => 'ee_read_ee',
213
-                    'menu_order'   => 20,
214
-                    'parent_slug'  => 'espresso_events',
215
-                )
216
-            ),
217
-        );
218
-        $this->_admin_menu_groups = apply_filters(
219
-            'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups',
220
-            $groups
221
-        );
222
-    }
223
-
224
-
225
-    /**
226
-     * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group
227
-     * slug.  The other utility with this function is it validates that all the groups are instances of
228
-     * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons).
229
-     *
230
-     * @since  4.4.0
231
-     * @throws \EE_Error
232
-     * @return EE_Admin_Page_Menu_Group[]
233
-     */
234
-    private function _rearrange_menu_groups()
235
-    {
236
-        $groups = array();
237
-        // first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
238
-        usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
239
-        foreach ($this->_admin_menu_groups as $group) {
240
-            if (! $group instanceof EE_Admin_Page_Menu_Group) {
241
-                throw new EE_Error(
242
-                    sprintf(
243
-                        __(
244
-                            'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups.  All values in this array are required to be a EE_Admin_Page_Menu_Group object.  Instead there was: %s',
245
-                            'event_espresso'
246
-                        ),
247
-                        print_r($group, true)
248
-                    )
249
-                );
250
-            }
251
-            $groups[ $group->menu_slug ] = $group;
252
-        }
253
-        return $groups;
254
-    }
255
-
256
-
257
-    /**
258
-     * _get_installed_pages
259
-     * This just gets the list of installed EE_Admin_pages.
260
-     *
261
-     * @access private
262
-     * @throws EE_Error
263
-     * @return void
264
-     */
265
-    private function _get_installed_pages()
266
-    {
267
-        $installed_refs = array();
268
-        $exclude = array('assets', 'templates');
269
-        // grab everything in the  admin core directory
270
-        $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
271
-        if ($admin_screens) {
272
-            foreach ($admin_screens as $admin_screen) {
273
-                // files and anything in the exclude array need not apply
274
-                if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
275
-                    // these folders represent the different EE admin pages
276
-                    $installed_refs[ basename($admin_screen) ] = $admin_screen;
277
-                }
278
-            }
279
-        }
280
-        if (empty($installed_refs)) {
281
-            $error_msg[] = __(
282
-                'There are no EE_Admin pages detected, it looks like EE did not install properly',
283
-                'event_espresso'
284
-            );
285
-            $error_msg[] = $error_msg[0] . "\r\n"
286
-                           . sprintf(
287
-                               __(
288
-                                   'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
289
-                                   'event_espresso'
290
-                               ),
291
-                               EE_ADMIN_PAGES
292
-                           );
293
-            throw new EE_Error(implode('||', $error_msg));
294
-        }
295
-        // this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
296
-        $installed_refs = $this->_set_caffeinated($installed_refs);
297
-        // allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.;
298
-        $installed_refs = apply_filters(
299
-            'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
300
-            $installed_refs
301
-        );
302
-        $this->_caffeinated_extends = apply_filters(
303
-            'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends',
304
-            $this->_caffeinated_extends
305
-        );
306
-        // loop through admin pages and setup the $_installed_pages array.
307
-        $hooks_ref = array();
308
-        foreach ($installed_refs as $page => $path) {
309
-            // set autoloaders for our admin page classes based on included path information
310
-            EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path);
311
-            // build list of installed pages
312
-            $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path);
313
-            // verify returned object
314
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
315
-                if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
316
-                    continue;
317
-                }
318
-                // skip if in full maintenance mode and maintenance_mode_parent is set
319
-                $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent;
320
-                if (empty($maintenance_mode_parent)
321
-                    && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
322
-                ) {
323
-                    unset($installed_refs[ $page ]);
324
-                    continue;
325
-                }
326
-                $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug;
327
-                $this->_menu_slugs[ $menu_slug ] = $page;
328
-                // flag for register hooks on extended pages b/c extended pages use the default INIT.
329
-                $extend = false;
330
-                // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
331
-                if (isset($this->_caffeinated_extends[ $page ])) {
332
-                    $this->_current_caf_extend_slug = $page;
333
-                    $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name();
334
-                    $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path'];
335
-                    $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page'];
336
-                    add_filter(
337
-                        "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}",
338
-                        function ($path_to_file) use ($caf_path) {
339
-                            return $caf_path;
340
-                        }
341
-                    );
342
-                    add_filter(
343
-                        "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
344
-                        function ($admin_page) use ($caf_admin_page) {
345
-                            return $caf_admin_page;
346
-                        }
347
-                    );
348
-                    $extend = true;
349
-                }
350
-                // let's do the registered hooks
351
-                $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend);
352
-                $hooks_ref = array_merge($hooks_ref, $extended_hooks);
353
-            }
354
-        }
355
-        // the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder.  So we want to make sure we load the file for the parent.
356
-        // first make sure we've got unique values
357
-        $hooks_ref = array_unique($hooks_ref);
358
-        // now let's loop and require!
359
-        foreach ($hooks_ref as $path) {
360
-            require_once($path);
361
-        }
362
-        // make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested.
363
-        global $ee_menu_slugs;
364
-        $ee_menu_slugs = $this->_menu_slugs;
365
-        // we need to loop again to run any early code
366
-        foreach ($installed_refs as $page => $path) {
367
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
368
-                $this->_installed_pages[ $page ]->do_initial_loads();
369
-            }
370
-        }
371
-        do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
372
-    }
373
-
374
-
375
-    /**
376
-     * get_admin_page_object
377
-     *
378
-     * @param string $page_slug
379
-     * @return EE_Admin_Page
380
-     */
381
-    public function get_admin_page_object($page_slug = '')
382
-    {
383
-        if (isset($this->_installed_pages[ $page_slug ])) {
384
-            return $this->_installed_pages[ $page_slug ]->loaded_page_object();
385
-        }
386
-        return null;
387
-    }
388
-
389
-
390
-    /**
391
-     * _get_classname_for_admin_page
392
-     * generates an "Admin Page" class based on the directory  name
393
-     *
394
-     * @param $dir_name
395
-     * @return string
396
-     */
397
-    private function _get_classname_for_admin_page($dir_name = '')
398
-    {
399
-        $class_name = str_replace('_', ' ', strtolower($dir_name));
400
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
401
-    }
402
-
403
-
404
-    /**
405
-     * _get_classname_for_admin_init_page
406
-     * generates an "Admin Page Init" class based on the directory  name
407
-     *
408
-     * @param $dir_name
409
-     * @return string
410
-     */
411
-    private function _get_classname_for_admin_init_page($dir_name = '')
412
-    {
413
-        $class_name = str_replace('_', ' ', strtolower($dir_name));
414
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
415
-    }
416
-
417
-
418
-    /**
419
-     * _load_admin_page
420
-     * Loads and instantiates page_init object for a single EE_admin page.
421
-     *
422
-     * @param  string $page page_reference
423
-     * @param string  $path
424
-     * @throws EE_Error
425
-     * @return object|bool  return page object if valid, bool false if not.
426
-     */
427
-    private function _load_admin_page($page = '', $path = '')
428
-    {
429
-        $class_name = $this->_get_classname_for_admin_init_page($page);
430
-        EE_Registry::instance()->load_file($path, $class_name, 'core');
431
-        if (! class_exists($class_name)) {
432
-            $inner_error_msg = '<br />'
433
-                               . sprintf(
434
-                                   esc_html__(
435
-                                       'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
436
-                                       'event_espresso'
437
-                                   ),
438
-                                   '<strong>' . $class_name . '</strong>'
439
-                               );
440
-            $error_msg[] = sprintf(
441
-                __('Something went wrong with loading the %s admin page.', 'event_espresso'),
442
-                $page
443
-            );
444
-            $error_msg[] = $error_msg[0]
445
-                           . "\r\n"
446
-                           . sprintf(
447
-                               esc_html__(
448
-                                   'There is no Init class in place for the %s admin page.',
449
-                                   'event_espresso'
450
-                               ),
451
-                               $page
452
-                           )
453
-                           . $inner_error_msg;
454
-            throw new EE_Error(implode('||', $error_msg));
455
-        }
456
-        $a = new ReflectionClass($class_name);
457
-        return $a->newInstance();
458
-    }
459
-
460
-
461
-    /**
462
-     * set_menus
463
-     * This method sets up the menus for EE Admin Pages
464
-     *
465
-     * @access private
466
-     * @return void
467
-     */
468
-    public function set_menus()
469
-    {
470
-        // prep the menu pages (sort, group.)
471
-        $this->_prep_pages();
472
-        foreach ($this->_prepped_menu_maps as $menu_map) {
473
-            if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
474
-                $menu_map->add_menu_page(false);
475
-            }
476
-        }
477
-    }
478
-
479
-
480
-    /**
481
-     * set_network_menus
482
-     * This method sets up the menus for network EE Admin Pages.
483
-     * Almost identical to EE_Admin_Page_Loader::set_menus() except pages
484
-     * are only added to the menu map if they are intended for the admin menu
485
-     *
486
-     * @return void
487
-     */
488
-    public function set_network_menus()
489
-    {
490
-        $this->_prep_pages();
491
-        foreach ($this->_prepped_menu_maps as $menu_map) {
492
-            if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
493
-                $menu_map->add_menu_page(true);
494
-            }
495
-        }
496
-    }
497
-
498
-
499
-    /**
500
-     * _prep_pages
501
-     * sets the _prepped_menu_maps property
502
-     *
503
-     * @access private
504
-     * @throws EE_Error
505
-     * @return void
506
-     */
507
-    private function _prep_pages()
508
-    {
509
-        $pages_array = array();
510
-        // rearrange _admin_menu_groups to be indexed by group slug.
511
-        $menu_groups = $this->_rearrange_menu_groups();
512
-        foreach ($this->_installed_pages as $page) {
513
-            if ($page instanceof EE_Admin_page_Init) {
514
-                $page_map = $page->get_menu_map();
515
-                // if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
516
-                if (is_array($page_map) || empty($page_map)) {
517
-                    new PersistentAdminNotice(
518
-                        'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
519
-                        sprintf(
520
-                            __(
521
-                                'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
522
-                                'event_espresso'
523
-                            ),
524
-                            $page->label
525
-                        )
526
-                    );
527
-                    continue;
528
-                }
529
-                // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
530
-                if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
531
-                    throw new EE_Error(
532
-                        sprintf(
533
-                            __(
534
-                                'The menu map for %s must be an EE_Admin_Page_Menu_Map object.  Instead it is %s.  Please double check that the menu map has been configured correctly.',
535
-                                'event_espresso'
536
-                            ),
537
-                            $page->label,
538
-                            $page_map
539
-                        )
540
-                    );
541
-                }
542
-                // use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array.
543
-                if (empty($page_map->maintenance_mode_parent)
544
-                    && EE_Maintenance_Mode::instance()->level()
545
-                       == EE_Maintenance_Mode::level_2_complete_maintenance) {
546
-                    continue;
547
-                }
548
-                // assign to group (remember $page_map has the admin page stored in it).
549
-                $pages_array[ $page_map->menu_group ][] = $page_map;
550
-            }
551
-        }
552
-        if (empty($pages_array)) {
553
-            throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso'));
554
-        }
555
-        // let's sort the groups, make sure it's a valid group, add header (if to show).
556
-        foreach ($pages_array as $group => $menu_maps) {
557
-            // valid_group?
558
-            if (! array_key_exists($group, $menu_groups)) {
559
-                continue;
560
-            }
561
-            // sort pages.
562
-            usort($menu_maps, array($this, '_sort_menu_maps'));
563
-            // prepend header
564
-            array_unshift($menu_maps, $menu_groups[ $group ]);
565
-            // reset $pages_array with prepped data
566
-            $pages_array[ $group ] = $menu_maps;
567
-        }
568
-        // now let's setup the _prepped_menu_maps property
569
-        foreach ($menu_groups as $group => $group_objs) {
570
-            if (isset($pages_array[ $group ])) {
571
-                $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]);
572
-            }
573
-        }/**/
574
-    }
575
-
576
-
577
-    /**
578
-     * This method is the "workhorse" for detecting and setting up caffeinated functionality.
579
-     * In this method there are three checks being done:
580
-     * 1. Do we have any NEW admin page sets.  If we do, lets add them into the menu setup (via the $installed_refs
581
-     * array) etc.  (new page sets are found in caffeinated/new/{page})
582
-     * 2. Do we have any EXTENDED page sets.  Basically an extended EE_Admin Page extends the core {child}_Admin_Page
583
-     * class.  eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class:
584
-     * Extend_Events_Admin_Page extends Events_Admin_Page.
585
-     * 3. Do we have any files just for setting up hooks into other core pages.  The files can be any name in
586
-     * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the
587
-     * classname inside.  These classes are instantiated really early so that any hooks in them are run before the
588
-     * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated
589
-     * admin_pages)
590
-     *
591
-     * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be
592
-     *                              loaded.
593
-     * @return array
594
-     */
595
-    private function _set_caffeinated($installed_refs)
596
-    {
597
-
598
-        // first let's check if there IS a caffeinated folder. If there is not then lets get out.
599
-        if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin') || (defined('EE_DECAF') && EE_DECAF)) {
600
-            return $installed_refs;
601
-        }
602
-        $this->_define_caffeinated_constants();
603
-        $exclude = array('tickets');
604
-        // okay let's setup an "New" pages first (we'll return installed refs later)
605
-        $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
606
-        if ($new_admin_screens) {
607
-            foreach ($new_admin_screens as $admin_screen) {
608
-                // files and anything in the exclude array need not apply
609
-                if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
610
-                    // these folders represent the different NEW EE admin pages
611
-                    $installed_refs[ basename($admin_screen) ] = $admin_screen;
612
-                    // set autoloaders for our admin page classes based on included path information
613
-                    EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen);
614
-                }
615
-            }
616
-        }
617
-        // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
618
-        $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
619
-        if ($extends) {
620
-            foreach ($extends as $extend) {
621
-                if (is_dir($extend)) {
622
-                    $extend_ref = basename($extend);
623
-                    // now let's make sure there is a file that matches the expected format
624
-                    $filename = str_replace(
625
-                        ' ',
626
-                        '_',
627
-                        ucwords(
628
-                            str_replace(
629
-                                '_',
630
-                                ' ',
631
-                                $extend_ref
632
-                            )
633
-                        )
634
-                    );
635
-                    $filename = 'Extend_' . $filename . '_Admin_Page';
636
-                    $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace(
637
-                        array('\\', '/'),
638
-                        '/',
639
-                        EE_CORE_CAF_ADMIN
640
-                        . 'extend/'
641
-                        . $extend_ref
642
-                        . '/'
643
-                        . $filename
644
-                        . '.core.php'
645
-                    );
646
-                    $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename;
647
-                    // set autoloaders for our admin page classes based on included path information
648
-                    EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend);
649
-                }
650
-            }
651
-        }
652
-        // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
653
-        $ee_admin_hooks = array();
654
-        $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
655
-        if ($hooks) {
656
-            foreach ($hooks as $hook) {
657
-                if (is_readable($hook)) {
658
-                    require_once $hook;
659
-                    $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
660
-                    $classname = str_replace('.class.php', '', $classname);
661
-                    if (class_exists($classname)) {
662
-                        $a = new ReflectionClass($classname);
663
-                        $ee_admin_hooks[] = $a->newInstance();
664
-                    }
665
-                }
666
-            }
667
-        }/**/
668
-        $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks);
669
-        return $installed_refs;
670
-    }
671
-
672
-
673
-    /**
674
-     * Utility method for sorting the _menu_maps (callback for usort php function)
675
-     *
676
-     * @since  4.4.0
677
-     * @param  EE_Admin_Page_Menu_Map $a menu_map object
678
-     * @param  EE_Admin_Page_Menu_Map $b being compared to
679
-     * @return int    sort order
680
-     */
681
-    private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b)
682
-    {
683
-        if ($a->menu_order == $b->menu_order) {
684
-            return 0;
685
-        }
686
-        return ($a->menu_order < $b->menu_order) ? -1 : 1;
687
-    }
688
-
689
-
690
-    /**
691
-     * _default_header_link
692
-     * This is just a dummy method to use with header submenu items
693
-     *
694
-     * @return bool false
695
-     */
696
-    public function _default_header_link()
697
-    {
698
-        return false;
699
-    }
27
+	/**
28
+	 * _installed_pages
29
+	 * objects for page_init objects detected and loaded
30
+	 *
31
+	 * @access private
32
+	 * @var \EE_Admin_Page_Init[]
33
+	 */
34
+	private $_installed_pages = array();
35
+
36
+
37
+	/**
38
+	 * this is used to hold the registry of menu slugs for all the installed admin pages
39
+	 *
40
+	 * @var array
41
+	 */
42
+	private $_menu_slugs = array();
43
+
44
+
45
+	/**
46
+	 * _caffeinated_extends
47
+	 * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and
48
+	 * pieces needed to do so).  This property is defined in the _set_caffeinated method.
49
+	 *
50
+	 * @var array
51
+	 */
52
+	private $_caffeinated_extends = array();
53
+
54
+
55
+	/**
56
+	 * _current_caf_extend_slug
57
+	 * This property is used for holding the page slug that is required for referencing the correct
58
+	 * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed.
59
+	 *
60
+	 * @var array
61
+	 */
62
+	private $_current_caf_extend_slug;
63
+
64
+	/**
65
+	 * _prepped_menu_maps
66
+	 * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu.
67
+	 *
68
+	 * @since  4.4.0
69
+	 * @var EE_Admin_Page_Menu_Map[]
70
+	 */
71
+	private $_prepped_menu_maps = array();
72
+
73
+
74
+	/**
75
+	 * _admin_menu_groups
76
+	 * array that holds the group headings and details for
77
+	 *
78
+	 * @access private
79
+	 * @var array
80
+	 */
81
+	private $_admin_menu_groups = array();
82
+
83
+
84
+	/**
85
+	 * This property will hold the hook file for setting up the filter that does all the connections between admin
86
+	 * pages.
87
+	 *
88
+	 * @var string
89
+	 */
90
+	public $hook_file;
91
+
92
+
93
+	/**
94
+	 * constructor
95
+	 *
96
+	 * @access public
97
+	 * @return \EE_Admin_Page_Loader
98
+	 */
99
+	public function __construct()
100
+	{
101
+		// load menu_map classes
102
+		EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core');
103
+		// define the default "groups" for the admin_pages
104
+		$this->_set_menu_groups();
105
+
106
+		// let's do a scan and see what installed pages we have
107
+		$this->_get_installed_pages();
108
+		// set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to).
109
+		add_action('admin_menu', array($this, 'set_menus'));
110
+		add_action('network_admin_menu', array($this, 'set_network_menus'));
111
+	}
112
+
113
+
114
+	/**
115
+	 * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by
116
+	 * files in the caffeinated folder.
117
+	 *
118
+	 * @access private
119
+	 * @return void
120
+	 */
121
+	private function _define_caffeinated_constants()
122
+	{
123
+		if (! defined('EE_CORE_CAF_ADMIN')) {
124
+			define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
125
+			define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
126
+			define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
127
+			define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
128
+			define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
129
+			define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
130
+		}
131
+	}
132
+
133
+
134
+	/**
135
+	 * _set_menu_groups
136
+	 * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array)
137
+	 *
138
+	 * @access private
139
+	 * @return void
140
+	 */
141
+	private function _set_menu_groups()
142
+	{
143
+
144
+		// set array of EE_Admin_Page_Menu_Group objects
145
+		$groups = array(
146
+			'main'       => new EE_Admin_Page_Menu_Group(
147
+				array(
148
+					'menu_label'   => __('Main', 'event_espresso'),
149
+					'show_on_menu' => EE_Admin_Page_Menu_Map::NONE,
150
+					'menu_slug'    => 'main',
151
+					'capability'   => 'ee_read_ee',
152
+					'menu_order'   => 0,
153
+					'parent_slug'  => 'espresso_events',
154
+				)
155
+			),
156
+			'management' => new EE_Admin_Page_Menu_Group(
157
+				array(
158
+					'menu_label'   => __('Management', 'event_espresso'),
159
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
160
+					'menu_slug'    => 'management',
161
+					'capability'   => 'ee_read_ee',
162
+					'menu_order'   => 10,
163
+					'parent_slug'  => 'espresso_events',
164
+				)
165
+			),
166
+			'settings'   => new EE_Admin_Page_Menu_Group(
167
+				array(
168
+					'menu_label'   => __('Settings', 'event_espresso'),
169
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
170
+					'menu_slug'    => 'settings',
171
+					'capability'   => 'ee_read_ee',
172
+					'menu_order'   => 30,
173
+					'parent_slug'  => 'espresso_events',
174
+				)
175
+			),
176
+			'templates'  => new EE_Admin_Page_Menu_Group(
177
+				array(
178
+					'menu_label'   => __('Templates', 'event_espresso'),
179
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
180
+					'menu_slug'    => 'templates',
181
+					'capability'   => 'ee_read_ee',
182
+					'menu_order'   => 40,
183
+					'parent_slug'  => 'espresso_events',
184
+				)
185
+			),
186
+			'extras'     => new EE_Admin_Page_Menu_Group(
187
+				array(
188
+					'menu_label'              => __('Extras', 'event_espresso'),
189
+					'show_on_menu'            => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
190
+					'menu_slug'               => 'extras',
191
+					'capability'              => 'ee_read_ee',
192
+					'menu_order'              => 50,
193
+					'parent_slug'             => 'espresso_events',
194
+					'maintenance_mode_parent' => 'espresso_maintenance_settings',
195
+				)
196
+			),
197
+			'tools'      => new EE_Admin_Page_Menu_Group(
198
+				array(
199
+					'menu_label'   => __("Tools", "event_espresso"),
200
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
201
+					'menu_slug'    => 'tools',
202
+					'capability'   => 'ee_read_ee',
203
+					'menu_order'   => 60,
204
+					'parent_slug'  => 'espresso_events',
205
+				)
206
+			),
207
+			'addons'     => new EE_Admin_Page_Menu_Group(
208
+				array(
209
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
210
+					'menu_label'   => __('Add-ons', 'event_espresso'),
211
+					'menu_slug'    => 'addons',
212
+					'capability'   => 'ee_read_ee',
213
+					'menu_order'   => 20,
214
+					'parent_slug'  => 'espresso_events',
215
+				)
216
+			),
217
+		);
218
+		$this->_admin_menu_groups = apply_filters(
219
+			'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups',
220
+			$groups
221
+		);
222
+	}
223
+
224
+
225
+	/**
226
+	 * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group
227
+	 * slug.  The other utility with this function is it validates that all the groups are instances of
228
+	 * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons).
229
+	 *
230
+	 * @since  4.4.0
231
+	 * @throws \EE_Error
232
+	 * @return EE_Admin_Page_Menu_Group[]
233
+	 */
234
+	private function _rearrange_menu_groups()
235
+	{
236
+		$groups = array();
237
+		// first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
238
+		usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
239
+		foreach ($this->_admin_menu_groups as $group) {
240
+			if (! $group instanceof EE_Admin_Page_Menu_Group) {
241
+				throw new EE_Error(
242
+					sprintf(
243
+						__(
244
+							'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups.  All values in this array are required to be a EE_Admin_Page_Menu_Group object.  Instead there was: %s',
245
+							'event_espresso'
246
+						),
247
+						print_r($group, true)
248
+					)
249
+				);
250
+			}
251
+			$groups[ $group->menu_slug ] = $group;
252
+		}
253
+		return $groups;
254
+	}
255
+
256
+
257
+	/**
258
+	 * _get_installed_pages
259
+	 * This just gets the list of installed EE_Admin_pages.
260
+	 *
261
+	 * @access private
262
+	 * @throws EE_Error
263
+	 * @return void
264
+	 */
265
+	private function _get_installed_pages()
266
+	{
267
+		$installed_refs = array();
268
+		$exclude = array('assets', 'templates');
269
+		// grab everything in the  admin core directory
270
+		$admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
271
+		if ($admin_screens) {
272
+			foreach ($admin_screens as $admin_screen) {
273
+				// files and anything in the exclude array need not apply
274
+				if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
275
+					// these folders represent the different EE admin pages
276
+					$installed_refs[ basename($admin_screen) ] = $admin_screen;
277
+				}
278
+			}
279
+		}
280
+		if (empty($installed_refs)) {
281
+			$error_msg[] = __(
282
+				'There are no EE_Admin pages detected, it looks like EE did not install properly',
283
+				'event_espresso'
284
+			);
285
+			$error_msg[] = $error_msg[0] . "\r\n"
286
+						   . sprintf(
287
+							   __(
288
+								   'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
289
+								   'event_espresso'
290
+							   ),
291
+							   EE_ADMIN_PAGES
292
+						   );
293
+			throw new EE_Error(implode('||', $error_msg));
294
+		}
295
+		// this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
296
+		$installed_refs = $this->_set_caffeinated($installed_refs);
297
+		// allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.;
298
+		$installed_refs = apply_filters(
299
+			'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
300
+			$installed_refs
301
+		);
302
+		$this->_caffeinated_extends = apply_filters(
303
+			'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends',
304
+			$this->_caffeinated_extends
305
+		);
306
+		// loop through admin pages and setup the $_installed_pages array.
307
+		$hooks_ref = array();
308
+		foreach ($installed_refs as $page => $path) {
309
+			// set autoloaders for our admin page classes based on included path information
310
+			EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path);
311
+			// build list of installed pages
312
+			$this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path);
313
+			// verify returned object
314
+			if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
315
+				if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
316
+					continue;
317
+				}
318
+				// skip if in full maintenance mode and maintenance_mode_parent is set
319
+				$maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent;
320
+				if (empty($maintenance_mode_parent)
321
+					&& EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
322
+				) {
323
+					unset($installed_refs[ $page ]);
324
+					continue;
325
+				}
326
+				$menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug;
327
+				$this->_menu_slugs[ $menu_slug ] = $page;
328
+				// flag for register hooks on extended pages b/c extended pages use the default INIT.
329
+				$extend = false;
330
+				// now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
331
+				if (isset($this->_caffeinated_extends[ $page ])) {
332
+					$this->_current_caf_extend_slug = $page;
333
+					$admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name();
334
+					$caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path'];
335
+					$caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page'];
336
+					add_filter(
337
+						"FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}",
338
+						function ($path_to_file) use ($caf_path) {
339
+							return $caf_path;
340
+						}
341
+					);
342
+					add_filter(
343
+						"FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
344
+						function ($admin_page) use ($caf_admin_page) {
345
+							return $caf_admin_page;
346
+						}
347
+					);
348
+					$extend = true;
349
+				}
350
+				// let's do the registered hooks
351
+				$extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend);
352
+				$hooks_ref = array_merge($hooks_ref, $extended_hooks);
353
+			}
354
+		}
355
+		// the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder.  So we want to make sure we load the file for the parent.
356
+		// first make sure we've got unique values
357
+		$hooks_ref = array_unique($hooks_ref);
358
+		// now let's loop and require!
359
+		foreach ($hooks_ref as $path) {
360
+			require_once($path);
361
+		}
362
+		// make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested.
363
+		global $ee_menu_slugs;
364
+		$ee_menu_slugs = $this->_menu_slugs;
365
+		// we need to loop again to run any early code
366
+		foreach ($installed_refs as $page => $path) {
367
+			if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
368
+				$this->_installed_pages[ $page ]->do_initial_loads();
369
+			}
370
+		}
371
+		do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
372
+	}
373
+
374
+
375
+	/**
376
+	 * get_admin_page_object
377
+	 *
378
+	 * @param string $page_slug
379
+	 * @return EE_Admin_Page
380
+	 */
381
+	public function get_admin_page_object($page_slug = '')
382
+	{
383
+		if (isset($this->_installed_pages[ $page_slug ])) {
384
+			return $this->_installed_pages[ $page_slug ]->loaded_page_object();
385
+		}
386
+		return null;
387
+	}
388
+
389
+
390
+	/**
391
+	 * _get_classname_for_admin_page
392
+	 * generates an "Admin Page" class based on the directory  name
393
+	 *
394
+	 * @param $dir_name
395
+	 * @return string
396
+	 */
397
+	private function _get_classname_for_admin_page($dir_name = '')
398
+	{
399
+		$class_name = str_replace('_', ' ', strtolower($dir_name));
400
+		return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
401
+	}
402
+
403
+
404
+	/**
405
+	 * _get_classname_for_admin_init_page
406
+	 * generates an "Admin Page Init" class based on the directory  name
407
+	 *
408
+	 * @param $dir_name
409
+	 * @return string
410
+	 */
411
+	private function _get_classname_for_admin_init_page($dir_name = '')
412
+	{
413
+		$class_name = str_replace('_', ' ', strtolower($dir_name));
414
+		return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
415
+	}
416
+
417
+
418
+	/**
419
+	 * _load_admin_page
420
+	 * Loads and instantiates page_init object for a single EE_admin page.
421
+	 *
422
+	 * @param  string $page page_reference
423
+	 * @param string  $path
424
+	 * @throws EE_Error
425
+	 * @return object|bool  return page object if valid, bool false if not.
426
+	 */
427
+	private function _load_admin_page($page = '', $path = '')
428
+	{
429
+		$class_name = $this->_get_classname_for_admin_init_page($page);
430
+		EE_Registry::instance()->load_file($path, $class_name, 'core');
431
+		if (! class_exists($class_name)) {
432
+			$inner_error_msg = '<br />'
433
+							   . sprintf(
434
+								   esc_html__(
435
+									   'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
436
+									   'event_espresso'
437
+								   ),
438
+								   '<strong>' . $class_name . '</strong>'
439
+							   );
440
+			$error_msg[] = sprintf(
441
+				__('Something went wrong with loading the %s admin page.', 'event_espresso'),
442
+				$page
443
+			);
444
+			$error_msg[] = $error_msg[0]
445
+						   . "\r\n"
446
+						   . sprintf(
447
+							   esc_html__(
448
+								   'There is no Init class in place for the %s admin page.',
449
+								   'event_espresso'
450
+							   ),
451
+							   $page
452
+						   )
453
+						   . $inner_error_msg;
454
+			throw new EE_Error(implode('||', $error_msg));
455
+		}
456
+		$a = new ReflectionClass($class_name);
457
+		return $a->newInstance();
458
+	}
459
+
460
+
461
+	/**
462
+	 * set_menus
463
+	 * This method sets up the menus for EE Admin Pages
464
+	 *
465
+	 * @access private
466
+	 * @return void
467
+	 */
468
+	public function set_menus()
469
+	{
470
+		// prep the menu pages (sort, group.)
471
+		$this->_prep_pages();
472
+		foreach ($this->_prepped_menu_maps as $menu_map) {
473
+			if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
474
+				$menu_map->add_menu_page(false);
475
+			}
476
+		}
477
+	}
478
+
479
+
480
+	/**
481
+	 * set_network_menus
482
+	 * This method sets up the menus for network EE Admin Pages.
483
+	 * Almost identical to EE_Admin_Page_Loader::set_menus() except pages
484
+	 * are only added to the menu map if they are intended for the admin menu
485
+	 *
486
+	 * @return void
487
+	 */
488
+	public function set_network_menus()
489
+	{
490
+		$this->_prep_pages();
491
+		foreach ($this->_prepped_menu_maps as $menu_map) {
492
+			if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
493
+				$menu_map->add_menu_page(true);
494
+			}
495
+		}
496
+	}
497
+
498
+
499
+	/**
500
+	 * _prep_pages
501
+	 * sets the _prepped_menu_maps property
502
+	 *
503
+	 * @access private
504
+	 * @throws EE_Error
505
+	 * @return void
506
+	 */
507
+	private function _prep_pages()
508
+	{
509
+		$pages_array = array();
510
+		// rearrange _admin_menu_groups to be indexed by group slug.
511
+		$menu_groups = $this->_rearrange_menu_groups();
512
+		foreach ($this->_installed_pages as $page) {
513
+			if ($page instanceof EE_Admin_page_Init) {
514
+				$page_map = $page->get_menu_map();
515
+				// if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
516
+				if (is_array($page_map) || empty($page_map)) {
517
+					new PersistentAdminNotice(
518
+						'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
519
+						sprintf(
520
+							__(
521
+								'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
522
+								'event_espresso'
523
+							),
524
+							$page->label
525
+						)
526
+					);
527
+					continue;
528
+				}
529
+				// if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
530
+				if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
531
+					throw new EE_Error(
532
+						sprintf(
533
+							__(
534
+								'The menu map for %s must be an EE_Admin_Page_Menu_Map object.  Instead it is %s.  Please double check that the menu map has been configured correctly.',
535
+								'event_espresso'
536
+							),
537
+							$page->label,
538
+							$page_map
539
+						)
540
+					);
541
+				}
542
+				// use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array.
543
+				if (empty($page_map->maintenance_mode_parent)
544
+					&& EE_Maintenance_Mode::instance()->level()
545
+					   == EE_Maintenance_Mode::level_2_complete_maintenance) {
546
+					continue;
547
+				}
548
+				// assign to group (remember $page_map has the admin page stored in it).
549
+				$pages_array[ $page_map->menu_group ][] = $page_map;
550
+			}
551
+		}
552
+		if (empty($pages_array)) {
553
+			throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso'));
554
+		}
555
+		// let's sort the groups, make sure it's a valid group, add header (if to show).
556
+		foreach ($pages_array as $group => $menu_maps) {
557
+			// valid_group?
558
+			if (! array_key_exists($group, $menu_groups)) {
559
+				continue;
560
+			}
561
+			// sort pages.
562
+			usort($menu_maps, array($this, '_sort_menu_maps'));
563
+			// prepend header
564
+			array_unshift($menu_maps, $menu_groups[ $group ]);
565
+			// reset $pages_array with prepped data
566
+			$pages_array[ $group ] = $menu_maps;
567
+		}
568
+		// now let's setup the _prepped_menu_maps property
569
+		foreach ($menu_groups as $group => $group_objs) {
570
+			if (isset($pages_array[ $group ])) {
571
+				$this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]);
572
+			}
573
+		}/**/
574
+	}
575
+
576
+
577
+	/**
578
+	 * This method is the "workhorse" for detecting and setting up caffeinated functionality.
579
+	 * In this method there are three checks being done:
580
+	 * 1. Do we have any NEW admin page sets.  If we do, lets add them into the menu setup (via the $installed_refs
581
+	 * array) etc.  (new page sets are found in caffeinated/new/{page})
582
+	 * 2. Do we have any EXTENDED page sets.  Basically an extended EE_Admin Page extends the core {child}_Admin_Page
583
+	 * class.  eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class:
584
+	 * Extend_Events_Admin_Page extends Events_Admin_Page.
585
+	 * 3. Do we have any files just for setting up hooks into other core pages.  The files can be any name in
586
+	 * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the
587
+	 * classname inside.  These classes are instantiated really early so that any hooks in them are run before the
588
+	 * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated
589
+	 * admin_pages)
590
+	 *
591
+	 * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be
592
+	 *                              loaded.
593
+	 * @return array
594
+	 */
595
+	private function _set_caffeinated($installed_refs)
596
+	{
597
+
598
+		// first let's check if there IS a caffeinated folder. If there is not then lets get out.
599
+		if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin') || (defined('EE_DECAF') && EE_DECAF)) {
600
+			return $installed_refs;
601
+		}
602
+		$this->_define_caffeinated_constants();
603
+		$exclude = array('tickets');
604
+		// okay let's setup an "New" pages first (we'll return installed refs later)
605
+		$new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
606
+		if ($new_admin_screens) {
607
+			foreach ($new_admin_screens as $admin_screen) {
608
+				// files and anything in the exclude array need not apply
609
+				if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
610
+					// these folders represent the different NEW EE admin pages
611
+					$installed_refs[ basename($admin_screen) ] = $admin_screen;
612
+					// set autoloaders for our admin page classes based on included path information
613
+					EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen);
614
+				}
615
+			}
616
+		}
617
+		// let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
618
+		$extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
619
+		if ($extends) {
620
+			foreach ($extends as $extend) {
621
+				if (is_dir($extend)) {
622
+					$extend_ref = basename($extend);
623
+					// now let's make sure there is a file that matches the expected format
624
+					$filename = str_replace(
625
+						' ',
626
+						'_',
627
+						ucwords(
628
+							str_replace(
629
+								'_',
630
+								' ',
631
+								$extend_ref
632
+							)
633
+						)
634
+					);
635
+					$filename = 'Extend_' . $filename . '_Admin_Page';
636
+					$this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace(
637
+						array('\\', '/'),
638
+						'/',
639
+						EE_CORE_CAF_ADMIN
640
+						. 'extend/'
641
+						. $extend_ref
642
+						. '/'
643
+						. $filename
644
+						. '.core.php'
645
+					);
646
+					$this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename;
647
+					// set autoloaders for our admin page classes based on included path information
648
+					EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend);
649
+				}
650
+			}
651
+		}
652
+		// let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
653
+		$ee_admin_hooks = array();
654
+		$hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
655
+		if ($hooks) {
656
+			foreach ($hooks as $hook) {
657
+				if (is_readable($hook)) {
658
+					require_once $hook;
659
+					$classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
660
+					$classname = str_replace('.class.php', '', $classname);
661
+					if (class_exists($classname)) {
662
+						$a = new ReflectionClass($classname);
663
+						$ee_admin_hooks[] = $a->newInstance();
664
+					}
665
+				}
666
+			}
667
+		}/**/
668
+		$ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks);
669
+		return $installed_refs;
670
+	}
671
+
672
+
673
+	/**
674
+	 * Utility method for sorting the _menu_maps (callback for usort php function)
675
+	 *
676
+	 * @since  4.4.0
677
+	 * @param  EE_Admin_Page_Menu_Map $a menu_map object
678
+	 * @param  EE_Admin_Page_Menu_Map $b being compared to
679
+	 * @return int    sort order
680
+	 */
681
+	private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b)
682
+	{
683
+		if ($a->menu_order == $b->menu_order) {
684
+			return 0;
685
+		}
686
+		return ($a->menu_order < $b->menu_order) ? -1 : 1;
687
+	}
688
+
689
+
690
+	/**
691
+	 * _default_header_link
692
+	 * This is just a dummy method to use with header submenu items
693
+	 *
694
+	 * @return bool false
695
+	 */
696
+	public function _default_header_link()
697
+	{
698
+		return false;
699
+	}
700 700
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -120,13 +120,13 @@  discard block
 block discarded – undo
120 120
      */
121 121
     private function _define_caffeinated_constants()
122 122
     {
123
-        if (! defined('EE_CORE_CAF_ADMIN')) {
124
-            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
125
-            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
126
-            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
127
-            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
128
-            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
129
-            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
123
+        if ( ! defined('EE_CORE_CAF_ADMIN')) {
124
+            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH.'caffeinated/admin/');
125
+            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL.'caffeinated/admin/');
126
+            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN.'new/');
127
+            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN.'extend/');
128
+            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL.'extend/');
129
+            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN.'hooks/');
130 130
         }
131 131
     }
132 132
 
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
         // first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
238 238
         usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
239 239
         foreach ($this->_admin_menu_groups as $group) {
240
-            if (! $group instanceof EE_Admin_Page_Menu_Group) {
240
+            if ( ! $group instanceof EE_Admin_Page_Menu_Group) {
241 241
                 throw new EE_Error(
242 242
                     sprintf(
243 243
                         __(
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
                     )
249 249
                 );
250 250
             }
251
-            $groups[ $group->menu_slug ] = $group;
251
+            $groups[$group->menu_slug] = $group;
252 252
         }
253 253
         return $groups;
254 254
     }
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
         $installed_refs = array();
268 268
         $exclude = array('assets', 'templates');
269 269
         // grab everything in the  admin core directory
270
-        $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
270
+        $admin_screens = glob(EE_ADMIN_PAGES.'*', GLOB_ONLYDIR);
271 271
         if ($admin_screens) {
272 272
             foreach ($admin_screens as $admin_screen) {
273 273
                 // files and anything in the exclude array need not apply
274 274
                 if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
275 275
                     // these folders represent the different EE admin pages
276
-                    $installed_refs[ basename($admin_screen) ] = $admin_screen;
276
+                    $installed_refs[basename($admin_screen)] = $admin_screen;
277 277
                 }
278 278
             }
279 279
         }
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
                 'There are no EE_Admin pages detected, it looks like EE did not install properly',
283 283
                 'event_espresso'
284 284
             );
285
-            $error_msg[] = $error_msg[0] . "\r\n"
285
+            $error_msg[] = $error_msg[0]."\r\n"
286 286
                            . sprintf(
287 287
                                __(
288 288
                                    'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
@@ -309,46 +309,46 @@  discard block
 block discarded – undo
309 309
             // set autoloaders for our admin page classes based on included path information
310 310
             EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path);
311 311
             // build list of installed pages
312
-            $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path);
312
+            $this->_installed_pages[$page] = $this->_load_admin_page($page, $path);
313 313
             // verify returned object
314
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
315
-                if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
314
+            if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
315
+                if ( ! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
316 316
                     continue;
317 317
                 }
318 318
                 // skip if in full maintenance mode and maintenance_mode_parent is set
319
-                $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent;
319
+                $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent;
320 320
                 if (empty($maintenance_mode_parent)
321 321
                     && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
322 322
                 ) {
323
-                    unset($installed_refs[ $page ]);
323
+                    unset($installed_refs[$page]);
324 324
                     continue;
325 325
                 }
326
-                $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug;
327
-                $this->_menu_slugs[ $menu_slug ] = $page;
326
+                $menu_slug = $this->_installed_pages[$page]->get_menu_map()->menu_slug;
327
+                $this->_menu_slugs[$menu_slug] = $page;
328 328
                 // flag for register hooks on extended pages b/c extended pages use the default INIT.
329 329
                 $extend = false;
330 330
                 // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
331
-                if (isset($this->_caffeinated_extends[ $page ])) {
331
+                if (isset($this->_caffeinated_extends[$page])) {
332 332
                     $this->_current_caf_extend_slug = $page;
333
-                    $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name();
334
-                    $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path'];
335
-                    $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page'];
333
+                    $admin_page_name = $this->_installed_pages[$page]->get_admin_page_name();
334
+                    $caf_path = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['path'];
335
+                    $caf_admin_page = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['admin_page'];
336 336
                     add_filter(
337 337
                         "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}",
338
-                        function ($path_to_file) use ($caf_path) {
338
+                        function($path_to_file) use ($caf_path) {
339 339
                             return $caf_path;
340 340
                         }
341 341
                     );
342 342
                     add_filter(
343 343
                         "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
344
-                        function ($admin_page) use ($caf_admin_page) {
344
+                        function($admin_page) use ($caf_admin_page) {
345 345
                             return $caf_admin_page;
346 346
                         }
347 347
                     );
348 348
                     $extend = true;
349 349
                 }
350 350
                 // let's do the registered hooks
351
-                $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend);
351
+                $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend);
352 352
                 $hooks_ref = array_merge($hooks_ref, $extended_hooks);
353 353
             }
354 354
         }
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
         $ee_menu_slugs = $this->_menu_slugs;
365 365
         // we need to loop again to run any early code
366 366
         foreach ($installed_refs as $page => $path) {
367
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
368
-                $this->_installed_pages[ $page ]->do_initial_loads();
367
+            if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
368
+                $this->_installed_pages[$page]->do_initial_loads();
369 369
             }
370 370
         }
371 371
         do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
@@ -380,8 +380,8 @@  discard block
 block discarded – undo
380 380
      */
381 381
     public function get_admin_page_object($page_slug = '')
382 382
     {
383
-        if (isset($this->_installed_pages[ $page_slug ])) {
384
-            return $this->_installed_pages[ $page_slug ]->loaded_page_object();
383
+        if (isset($this->_installed_pages[$page_slug])) {
384
+            return $this->_installed_pages[$page_slug]->loaded_page_object();
385 385
         }
386 386
         return null;
387 387
     }
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
     private function _get_classname_for_admin_page($dir_name = '')
398 398
     {
399 399
         $class_name = str_replace('_', ' ', strtolower($dir_name));
400
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
400
+        return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page';
401 401
     }
402 402
 
403 403
 
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
     private function _get_classname_for_admin_init_page($dir_name = '')
412 412
     {
413 413
         $class_name = str_replace('_', ' ', strtolower($dir_name));
414
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
414
+        return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page_Init';
415 415
     }
416 416
 
417 417
 
@@ -428,14 +428,14 @@  discard block
 block discarded – undo
428 428
     {
429 429
         $class_name = $this->_get_classname_for_admin_init_page($page);
430 430
         EE_Registry::instance()->load_file($path, $class_name, 'core');
431
-        if (! class_exists($class_name)) {
431
+        if ( ! class_exists($class_name)) {
432 432
             $inner_error_msg = '<br />'
433 433
                                . sprintf(
434 434
                                    esc_html__(
435 435
                                        'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
436 436
                                        'event_espresso'
437 437
                                    ),
438
-                                   '<strong>' . $class_name . '</strong>'
438
+                                   '<strong>'.$class_name.'</strong>'
439 439
                                );
440 440
             $error_msg[] = sprintf(
441 441
                 __('Something went wrong with loading the %s admin page.', 'event_espresso'),
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
                 // if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
516 516
                 if (is_array($page_map) || empty($page_map)) {
517 517
                     new PersistentAdminNotice(
518
-                        'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
518
+                        'menu_map_warning_'.str_replace(' ', '_', $page->label).'_'.EVENT_ESPRESSO_VERSION,
519 519
                         sprintf(
520 520
                             __(
521 521
                                 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
                     continue;
528 528
                 }
529 529
                 // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
530
-                if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
530
+                if ( ! $page_map instanceof EE_Admin_Page_Menu_Map) {
531 531
                     throw new EE_Error(
532 532
                         sprintf(
533 533
                             __(
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
                     continue;
547 547
                 }
548 548
                 // assign to group (remember $page_map has the admin page stored in it).
549
-                $pages_array[ $page_map->menu_group ][] = $page_map;
549
+                $pages_array[$page_map->menu_group][] = $page_map;
550 550
             }
551 551
         }
552 552
         if (empty($pages_array)) {
@@ -555,20 +555,20 @@  discard block
 block discarded – undo
555 555
         // let's sort the groups, make sure it's a valid group, add header (if to show).
556 556
         foreach ($pages_array as $group => $menu_maps) {
557 557
             // valid_group?
558
-            if (! array_key_exists($group, $menu_groups)) {
558
+            if ( ! array_key_exists($group, $menu_groups)) {
559 559
                 continue;
560 560
             }
561 561
             // sort pages.
562 562
             usort($menu_maps, array($this, '_sort_menu_maps'));
563 563
             // prepend header
564
-            array_unshift($menu_maps, $menu_groups[ $group ]);
564
+            array_unshift($menu_maps, $menu_groups[$group]);
565 565
             // reset $pages_array with prepped data
566
-            $pages_array[ $group ] = $menu_maps;
566
+            $pages_array[$group] = $menu_maps;
567 567
         }
568 568
         // now let's setup the _prepped_menu_maps property
569 569
         foreach ($menu_groups as $group => $group_objs) {
570
-            if (isset($pages_array[ $group ])) {
571
-                $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]);
570
+            if (isset($pages_array[$group])) {
571
+                $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]);
572 572
             }
573 573
         }/**/
574 574
     }
@@ -596,26 +596,26 @@  discard block
 block discarded – undo
596 596
     {
597 597
 
598 598
         // first let's check if there IS a caffeinated folder. If there is not then lets get out.
599
-        if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin') || (defined('EE_DECAF') && EE_DECAF)) {
599
+        if ( ! is_dir(EE_PLUGIN_DIR_PATH.'caffeinated/admin') || (defined('EE_DECAF') && EE_DECAF)) {
600 600
             return $installed_refs;
601 601
         }
602 602
         $this->_define_caffeinated_constants();
603 603
         $exclude = array('tickets');
604 604
         // okay let's setup an "New" pages first (we'll return installed refs later)
605
-        $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
605
+        $new_admin_screens = glob(EE_CORE_CAF_ADMIN.'new/*', GLOB_ONLYDIR);
606 606
         if ($new_admin_screens) {
607 607
             foreach ($new_admin_screens as $admin_screen) {
608 608
                 // files and anything in the exclude array need not apply
609 609
                 if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
610 610
                     // these folders represent the different NEW EE admin pages
611
-                    $installed_refs[ basename($admin_screen) ] = $admin_screen;
611
+                    $installed_refs[basename($admin_screen)] = $admin_screen;
612 612
                     // set autoloaders for our admin page classes based on included path information
613 613
                     EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen);
614 614
                 }
615 615
             }
616 616
         }
617 617
         // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
618
-        $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
618
+        $extends = glob(EE_CORE_CAF_ADMIN.'extend/*', GLOB_ONLYDIR);
619 619
         if ($extends) {
620 620
             foreach ($extends as $extend) {
621 621
                 if (is_dir($extend)) {
@@ -632,8 +632,8 @@  discard block
 block discarded – undo
632 632
                             )
633 633
                         )
634 634
                     );
635
-                    $filename = 'Extend_' . $filename . '_Admin_Page';
636
-                    $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace(
635
+                    $filename = 'Extend_'.$filename.'_Admin_Page';
636
+                    $this->_caffeinated_extends[$extend_ref]['path'] = str_replace(
637 637
                         array('\\', '/'),
638 638
                         '/',
639 639
                         EE_CORE_CAF_ADMIN
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
                         . $filename
644 644
                         . '.core.php'
645 645
                     );
646
-                    $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename;
646
+                    $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename;
647 647
                     // set autoloaders for our admin page classes based on included path information
648 648
                     EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend);
649 649
                 }
@@ -651,12 +651,12 @@  discard block
 block discarded – undo
651 651
         }
652 652
         // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
653 653
         $ee_admin_hooks = array();
654
-        $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
654
+        $hooks = glob(EE_CORE_CAF_ADMIN.'hooks/*.class.php');
655 655
         if ($hooks) {
656 656
             foreach ($hooks as $hook) {
657 657
                 if (is_readable($hook)) {
658 658
                     require_once $hook;
659
-                    $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
659
+                    $classname = str_replace(EE_CORE_CAF_ADMIN.'hooks/', '', $hook);
660 660
                     $classname = str_replace('.class.php', '', $classname);
661 661
                     if (class_exists($classname)) {
662 662
                         $a = new ReflectionClass($classname);
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Init.core.php 2 patches
Indentation   +420 added lines, -420 removed lines patch added patch discarded remove patch
@@ -13,424 +13,424 @@
 block discarded – undo
13 13
 abstract class EE_Admin_Page_Init extends EE_Base
14 14
 {
15 15
 
16
-    // identity properties (set in _set_defaults and _set_init_properties)
17
-    public $label;
18
-
19
-    /**
20
-     * Menu map has a capability.  However, this allows admin pages to have separate capability requirements for menus
21
-     * and accessing pages.  If capability is NOT set, then it defaults to the menu_map capability.
22
-     *
23
-     * @var string
24
-     */
25
-    public $capability;
26
-
27
-
28
-    /**
29
-     * This holds the menu map object for this admin page.
30
-     *
31
-     * @var EE_Admin_Page_Menu_Map
32
-     */
33
-    protected $_menu_map;
34
-
35
-    /**
36
-     * deprecated
37
-     */
38
-    public $menu_label;
39
-    public $menu_slug;
40
-
41
-
42
-    // set in _set_defaults
43
-    protected $_folder_name;
44
-    protected $_folder_path;
45
-    protected $_file_name;
46
-    public $hook_file;
47
-    protected $_wp_page_slug;
48
-    protected $_routing;
49
-
50
-
51
-    // will hold page object.
52
-    protected $_loaded_page_object;
53
-
54
-
55
-    // for caf
56
-    protected $_files_hooked;
57
-    protected $_hook_paths;
58
-
59
-    // load_page?
60
-    private $_load_page;
61
-
62
-
63
-    /**
64
-     * @Constructor
65
-     * @access public
66
-     * @return void
67
-     */
68
-    public function __construct()
69
-    {
70
-        // set global defaults
71
-        $this->_set_defaults();
72
-        // set properties that are always available with objects.
73
-        $this->_set_init_properties();
74
-        // global styles/scripts across all wp admin pages
75
-        add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5);
76
-        // load initial stuff.
77
-        $this->_set_file_and_folder_name();
78
-        $this->_set_menu_map();
79
-        if (empty($this->_menu_map) || is_array($this->_menu_map)) {
80
-            EE_Error::doing_it_wrong(
81
-                get_class($this) . '::$_menu_map',
82
-                sprintf(
83
-                    __(
84
-                        'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core.  Please see Admin_Page_Init class examples in core for the new way of setting this property up.',
85
-                        'event_espresso'
86
-                    ),
87
-                    get_class($this)
88
-                ),
89
-                '4.4.0'
90
-            );
91
-            return;
92
-        }
93
-        // set default capability
94
-        $this->_set_capability();
95
-    }
96
-
97
-
98
-    /**
99
-     * _set_init_properties
100
-     * Child classes use to set the following properties:
101
-     * $label
102
-     *
103
-     * @abstract
104
-     * @access protected
105
-     * @return void
106
-     */
107
-    abstract protected function _set_init_properties();
108
-
109
-
110
-    /**
111
-     * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of
112
-     * EE_Admin_Page_Menu_Map.  Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu.
113
-     *
114
-     * @since 4.4.0
115
-     * @ return void.
116
-     */
117
-    protected function _set_menu_map()
118
-    {
119
-        return array();
120
-    }
121
-
122
-
123
-    /**
124
-     * returns the menu map for this admin page
125
-     *
126
-     * @since 4.4.0
127
-     * @return EE_Admin_Page_Menu_Map
128
-     */
129
-    public function get_menu_map()
130
-    {
131
-        return $this->_menu_map;
132
-    }
133
-
134
-
135
-    /**
136
-     * This loads scripts and styles for the EE_Admin system
137
-     * that must be available on ALL WP admin pages (i.e. EE_menu items)
138
-     *
139
-     * @return void
140
-     */
141
-    public function load_wp_global_scripts_styles()
142
-    {
143
-        wp_register_style(
144
-            'espresso_menu',
145
-            EE_ADMIN_URL . 'assets/admin-menu-styles.css',
146
-            array('dashicons'),
147
-            EVENT_ESPRESSO_VERSION
148
-        );
149
-        wp_enqueue_style('espresso_menu');
150
-    }
151
-
152
-
153
-    /**
154
-     * this sets default properties (might be overridden in _set_init_properties);
155
-     *
156
-     * @access private
157
-     * @return  void
158
-     */
159
-    private function _set_defaults()
160
-    {
161
-        $this->_file_name = $this->_folder_name = $this->_wp_page_slug = $this->capability = null;
162
-        $this->_routing = true;
163
-        $this->_load_page = false;
164
-        $this->_files_hooked = $this->_hook_paths = array();
165
-        // menu_map
166
-        $this->_menu_map = $this->get_menu_map();
167
-    }
168
-
169
-
170
-    protected function _set_capability()
171
-    {
172
-        $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability;
173
-        $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability);
174
-    }
175
-
176
-
177
-    /**
178
-     * initialize_admin_page
179
-     * This method is what executes the loading of the specific page class for the given dir_name as called by the
180
-     * EE_Admin_Init class.
181
-     *
182
-     * @access  public
183
-     * @uses    _initialize_admin_page()
184
-     * @param  string $dir_name directory name for specific admin_page being loaded.
185
-     * @return void
186
-     */
187
-    public function initialize_admin_page()
188
-    {
189
-        // let's check user access first
190
-        $this->_check_user_access();
191
-        if (! is_object($this->_loaded_page_object)) {
192
-            return;
193
-        }
194
-        $this->_loaded_page_object->route_admin_request();
195
-        return;
196
-    }
197
-
198
-
199
-    public function set_page_dependencies($wp_page_slug)
200
-    {
201
-        if (! $this->_load_page) {
202
-            return;
203
-        }
204
-        if (! is_object($this->_loaded_page_object)) {
205
-            $msg[] = __(
206
-                'We can\'t load the page because we\'re missing a valid page object that tells us what to load',
207
-                'event_espresso'
208
-            );
209
-            $msg[] = $msg[0] . "\r\n"
210
-                     . sprintf(
211
-                         __(
212
-                             'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory',
213
-                             'event_espresso'
214
-                         ),
215
-                         $this->_file_name,
216
-                         $this->_file_name,
217
-                         $this->_folder_path . $this->_file_name,
218
-                         $this->_menu_map->menu_slug
219
-                     );
220
-            throw new EE_Error(implode('||', $msg));
221
-        }
222
-        $this->_loaded_page_object->set_wp_page_slug($wp_page_slug);
223
-        $page_hook = 'load-' . $wp_page_slug;
224
-        // hook into page load hook so all page specific stuff get's loaded.
225
-        if (! empty($wp_page_slug)) {
226
-            add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies'));
227
-        }
228
-    }
229
-
230
-
231
-    /**
232
-     * This executes the intial page loads for EE_Admin pages to take care of any ajax or other code needing to run
233
-     * before the load-page... hook. Note, the page loads are happening around the wp_init hook.
234
-     *
235
-     * @return void
236
-     */
237
-    public function do_initial_loads()
238
-    {
239
-        // no loading or initializing if menu map is setup incorrectly.
240
-        if (empty($this->_menu_map) || is_array($this->_menu_map)) {
241
-            return;
242
-        }
243
-        $this->_initialize_admin_page();
244
-    }
245
-
246
-
247
-    /**
248
-     * all we're doing here is setting the $_file_name property for later use.
249
-     *
250
-     * @access private
251
-     * @return void
252
-     */
253
-    private function _set_file_and_folder_name()
254
-    {
255
-        $bt = debug_backtrace();
256
-        // for more reliable determination of folder name
257
-        // we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this).  Why?  Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins)
258
-        $class = get_class($this);
259
-        foreach ($bt as $index => $values) {
260
-            if (isset($values['class']) && $values['class'] == $class) {
261
-                $file_index = $index - 1;
262
-                $this->_folder_name = basename(dirname($bt[ $file_index ]['file']));
263
-                if (! empty($this->_folder_name)) {
264
-                    break;
265
-                }
266
-            }
267
-        }
268
-        $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/';
269
-        $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name);
270
-        $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name));
271
-        $this->_file_name = str_replace(' ', '_', $this->_file_name);
272
-    }
273
-
274
-
275
-    /**
276
-     * This automatically checks if we have a hook class in the loaded child directory.  If we DO then we will register
277
-     * it with the appropriate pages.  That way all we have to do is make sure the file is named correctly and
278
-     * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do:
279
-     * events_Messages_Hooks.class.php
280
-     *
281
-     * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks
282
-     *                     files/classes
283
-     * @return array
284
-     */
285
-    public function register_hooks($extend = false)
286
-    {
287
-
288
-        // get a list of files in the directory that have the "Hook" in their name an
289
-        // if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property.  Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf.
290
-        if ($extend) {
291
-            $hook_files_glob_path = apply_filters(
292
-                'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend',
293
-                EE_CORE_CAF_ADMIN_EXTEND
294
-                . $this->_folder_name
295
-                . '/*'
296
-                . $this->_file_name
297
-                . '_Hooks_Extend.class.php'
298
-            );
299
-            $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend);
300
-        }
301
-        // loop through decaf folders
302
-        $hook_files_glob_path = apply_filters(
303
-            'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path',
304
-            $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php'
305
-        );
306
-        $this->_hook_paths = array_merge(
307
-            $this->_register_hook_files($hook_files_glob_path),
308
-            $this->_hook_paths
309
-        );  // making sure any extended hook paths are later in the array than the core hook paths!
310
-        return $this->_hook_paths;
311
-    }
312
-
313
-
314
-    protected function _register_hook_files($hook_files_glob_path, $extend = false)
315
-    {
316
-        $hook_paths = array();
317
-        if ($hook_files = glob($hook_files_glob_path)) {
318
-            if (empty($hook_files)) {
319
-                return array();
320
-            }
321
-            foreach ($hook_files as $file) {
322
-                // lets get the linked admin.
323
-                $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . '/', '', $file)
324
-                    : str_replace($this->_folder_path, '', $file);
325
-                $replace = $extend
326
-                    ? '_' . $this->_file_name . '_Hooks_Extend.class.php'
327
-                    : '_'
328
-                      . $this->_file_name
329
-                      . '_Hooks.class.php';
330
-                $rel_admin = str_replace($replace, '', $hook_file);
331
-                $rel_admin = strtolower($rel_admin);
332
-                $hook_paths[] = $file;
333
-                // make sure we haven't already got a hook setup for this page path
334
-                if (in_array($rel_admin, $this->_files_hooked)) {
335
-                    continue;
336
-                }
337
-                $this->hook_file = $hook_file;
338
-                $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin;
339
-                $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook'));
340
-                $this->_files_hooked[] = $rel_admin;
341
-            }
342
-        }
343
-        return $hook_paths;
344
-    }
345
-
346
-
347
-    public function load_admin_hook($registered_pages)
348
-    {
349
-        $this->hook_file;
350
-        $hook_file = (array) $this->hook_file;
351
-        return array_merge($hook_file, $registered_pages);
352
-    }
353
-
354
-
355
-    /**
356
-     * _initialize_admin_page
357
-     *
358
-     * @see  initialize_admin_page() for info
359
-     */
360
-    protected function _initialize_admin_page()
361
-    {
362
-
363
-        // JUST CHECK WE'RE ON RIGHT PAGE.
364
-        if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) {
365
-            return;
366
-        } //not on the right page so let's get out.
367
-        $this->_load_page = true;
368
-
369
-        // we don't need to do a page_request check here because it's only called via WP menu system.
370
-        $admin_page = $this->_file_name . '_Admin_Page';
371
-        $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page;
372
-        $admin_page = apply_filters(
373
-            "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}",
374
-            $admin_page
375
-        );
376
-        // define requested admin page class name then load the file and instantiate
377
-        $path_to_file = str_replace(array('\\', '/'), '/', $this->_folder_path . $admin_page . '.core.php');
378
-        $path_to_file = apply_filters(
379
-            "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}",
380
-            $path_to_file
381
-        );// so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page
382
-        if (is_readable($path_to_file)) {
383
-            // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place
384
-            do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization');
385
-            do_action(
386
-                'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug
387
-            );
388
-            require_once($path_to_file);
389
-            $a = new ReflectionClass($admin_page);
390
-            $this->_loaded_page_object = $a->newInstance($this->_routing);
391
-        }
392
-        do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization');
393
-        do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug);
394
-    }
395
-
396
-
397
-    public function get_admin_page_name()
398
-    {
399
-        return $this->_file_name . '_Admin_Page';
400
-    }
401
-
402
-
403
-    /**
404
-     * @return mixed
405
-     */
406
-    public function loaded_page_object()
407
-    {
408
-        return $this->_loaded_page_object;
409
-    }
410
-
411
-
412
-    // public function set_autoloaders($className)
413
-    // {
414
-    //     $dir_ref = array(
415
-    //         $this->_folder_path => array('core', 'class'),
416
-    //     );
417
-    //     EEH_Autoloader::try_autoload($dir_ref, $className);
418
-    // }
419
-    /**
420
-     * _check_user_access
421
-     * verifies user access for this admin page.  If no user access is available then let's gracefully exit with a
422
-     * WordPress die message.
423
-     *
424
-     * @return bool|die true if pass (or admin) wp_die if fail
425
-     */
426
-    private function _check_user_access()
427
-    {
428
-        if (! EE_Registry::instance()->CAP->current_user_can(
429
-            $this->_menu_map->capability,
430
-            $this->_menu_map->menu_slug
431
-        )) {
432
-            wp_die(__('You don\'t have access to this page.', 'event_espresso'), '', array('back_link' => true));
433
-        }
434
-        return true;
435
-    }
16
+	// identity properties (set in _set_defaults and _set_init_properties)
17
+	public $label;
18
+
19
+	/**
20
+	 * Menu map has a capability.  However, this allows admin pages to have separate capability requirements for menus
21
+	 * and accessing pages.  If capability is NOT set, then it defaults to the menu_map capability.
22
+	 *
23
+	 * @var string
24
+	 */
25
+	public $capability;
26
+
27
+
28
+	/**
29
+	 * This holds the menu map object for this admin page.
30
+	 *
31
+	 * @var EE_Admin_Page_Menu_Map
32
+	 */
33
+	protected $_menu_map;
34
+
35
+	/**
36
+	 * deprecated
37
+	 */
38
+	public $menu_label;
39
+	public $menu_slug;
40
+
41
+
42
+	// set in _set_defaults
43
+	protected $_folder_name;
44
+	protected $_folder_path;
45
+	protected $_file_name;
46
+	public $hook_file;
47
+	protected $_wp_page_slug;
48
+	protected $_routing;
49
+
50
+
51
+	// will hold page object.
52
+	protected $_loaded_page_object;
53
+
54
+
55
+	// for caf
56
+	protected $_files_hooked;
57
+	protected $_hook_paths;
58
+
59
+	// load_page?
60
+	private $_load_page;
61
+
62
+
63
+	/**
64
+	 * @Constructor
65
+	 * @access public
66
+	 * @return void
67
+	 */
68
+	public function __construct()
69
+	{
70
+		// set global defaults
71
+		$this->_set_defaults();
72
+		// set properties that are always available with objects.
73
+		$this->_set_init_properties();
74
+		// global styles/scripts across all wp admin pages
75
+		add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5);
76
+		// load initial stuff.
77
+		$this->_set_file_and_folder_name();
78
+		$this->_set_menu_map();
79
+		if (empty($this->_menu_map) || is_array($this->_menu_map)) {
80
+			EE_Error::doing_it_wrong(
81
+				get_class($this) . '::$_menu_map',
82
+				sprintf(
83
+					__(
84
+						'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core.  Please see Admin_Page_Init class examples in core for the new way of setting this property up.',
85
+						'event_espresso'
86
+					),
87
+					get_class($this)
88
+				),
89
+				'4.4.0'
90
+			);
91
+			return;
92
+		}
93
+		// set default capability
94
+		$this->_set_capability();
95
+	}
96
+
97
+
98
+	/**
99
+	 * _set_init_properties
100
+	 * Child classes use to set the following properties:
101
+	 * $label
102
+	 *
103
+	 * @abstract
104
+	 * @access protected
105
+	 * @return void
106
+	 */
107
+	abstract protected function _set_init_properties();
108
+
109
+
110
+	/**
111
+	 * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of
112
+	 * EE_Admin_Page_Menu_Map.  Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu.
113
+	 *
114
+	 * @since 4.4.0
115
+	 * @ return void.
116
+	 */
117
+	protected function _set_menu_map()
118
+	{
119
+		return array();
120
+	}
121
+
122
+
123
+	/**
124
+	 * returns the menu map for this admin page
125
+	 *
126
+	 * @since 4.4.0
127
+	 * @return EE_Admin_Page_Menu_Map
128
+	 */
129
+	public function get_menu_map()
130
+	{
131
+		return $this->_menu_map;
132
+	}
133
+
134
+
135
+	/**
136
+	 * This loads scripts and styles for the EE_Admin system
137
+	 * that must be available on ALL WP admin pages (i.e. EE_menu items)
138
+	 *
139
+	 * @return void
140
+	 */
141
+	public function load_wp_global_scripts_styles()
142
+	{
143
+		wp_register_style(
144
+			'espresso_menu',
145
+			EE_ADMIN_URL . 'assets/admin-menu-styles.css',
146
+			array('dashicons'),
147
+			EVENT_ESPRESSO_VERSION
148
+		);
149
+		wp_enqueue_style('espresso_menu');
150
+	}
151
+
152
+
153
+	/**
154
+	 * this sets default properties (might be overridden in _set_init_properties);
155
+	 *
156
+	 * @access private
157
+	 * @return  void
158
+	 */
159
+	private function _set_defaults()
160
+	{
161
+		$this->_file_name = $this->_folder_name = $this->_wp_page_slug = $this->capability = null;
162
+		$this->_routing = true;
163
+		$this->_load_page = false;
164
+		$this->_files_hooked = $this->_hook_paths = array();
165
+		// menu_map
166
+		$this->_menu_map = $this->get_menu_map();
167
+	}
168
+
169
+
170
+	protected function _set_capability()
171
+	{
172
+		$capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability;
173
+		$this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability);
174
+	}
175
+
176
+
177
+	/**
178
+	 * initialize_admin_page
179
+	 * This method is what executes the loading of the specific page class for the given dir_name as called by the
180
+	 * EE_Admin_Init class.
181
+	 *
182
+	 * @access  public
183
+	 * @uses    _initialize_admin_page()
184
+	 * @param  string $dir_name directory name for specific admin_page being loaded.
185
+	 * @return void
186
+	 */
187
+	public function initialize_admin_page()
188
+	{
189
+		// let's check user access first
190
+		$this->_check_user_access();
191
+		if (! is_object($this->_loaded_page_object)) {
192
+			return;
193
+		}
194
+		$this->_loaded_page_object->route_admin_request();
195
+		return;
196
+	}
197
+
198
+
199
+	public function set_page_dependencies($wp_page_slug)
200
+	{
201
+		if (! $this->_load_page) {
202
+			return;
203
+		}
204
+		if (! is_object($this->_loaded_page_object)) {
205
+			$msg[] = __(
206
+				'We can\'t load the page because we\'re missing a valid page object that tells us what to load',
207
+				'event_espresso'
208
+			);
209
+			$msg[] = $msg[0] . "\r\n"
210
+					 . sprintf(
211
+						 __(
212
+							 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory',
213
+							 'event_espresso'
214
+						 ),
215
+						 $this->_file_name,
216
+						 $this->_file_name,
217
+						 $this->_folder_path . $this->_file_name,
218
+						 $this->_menu_map->menu_slug
219
+					 );
220
+			throw new EE_Error(implode('||', $msg));
221
+		}
222
+		$this->_loaded_page_object->set_wp_page_slug($wp_page_slug);
223
+		$page_hook = 'load-' . $wp_page_slug;
224
+		// hook into page load hook so all page specific stuff get's loaded.
225
+		if (! empty($wp_page_slug)) {
226
+			add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies'));
227
+		}
228
+	}
229
+
230
+
231
+	/**
232
+	 * This executes the intial page loads for EE_Admin pages to take care of any ajax or other code needing to run
233
+	 * before the load-page... hook. Note, the page loads are happening around the wp_init hook.
234
+	 *
235
+	 * @return void
236
+	 */
237
+	public function do_initial_loads()
238
+	{
239
+		// no loading or initializing if menu map is setup incorrectly.
240
+		if (empty($this->_menu_map) || is_array($this->_menu_map)) {
241
+			return;
242
+		}
243
+		$this->_initialize_admin_page();
244
+	}
245
+
246
+
247
+	/**
248
+	 * all we're doing here is setting the $_file_name property for later use.
249
+	 *
250
+	 * @access private
251
+	 * @return void
252
+	 */
253
+	private function _set_file_and_folder_name()
254
+	{
255
+		$bt = debug_backtrace();
256
+		// for more reliable determination of folder name
257
+		// we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this).  Why?  Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins)
258
+		$class = get_class($this);
259
+		foreach ($bt as $index => $values) {
260
+			if (isset($values['class']) && $values['class'] == $class) {
261
+				$file_index = $index - 1;
262
+				$this->_folder_name = basename(dirname($bt[ $file_index ]['file']));
263
+				if (! empty($this->_folder_name)) {
264
+					break;
265
+				}
266
+			}
267
+		}
268
+		$this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/';
269
+		$this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name);
270
+		$this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name));
271
+		$this->_file_name = str_replace(' ', '_', $this->_file_name);
272
+	}
273
+
274
+
275
+	/**
276
+	 * This automatically checks if we have a hook class in the loaded child directory.  If we DO then we will register
277
+	 * it with the appropriate pages.  That way all we have to do is make sure the file is named correctly and
278
+	 * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do:
279
+	 * events_Messages_Hooks.class.php
280
+	 *
281
+	 * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks
282
+	 *                     files/classes
283
+	 * @return array
284
+	 */
285
+	public function register_hooks($extend = false)
286
+	{
287
+
288
+		// get a list of files in the directory that have the "Hook" in their name an
289
+		// if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property.  Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf.
290
+		if ($extend) {
291
+			$hook_files_glob_path = apply_filters(
292
+				'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend',
293
+				EE_CORE_CAF_ADMIN_EXTEND
294
+				. $this->_folder_name
295
+				. '/*'
296
+				. $this->_file_name
297
+				. '_Hooks_Extend.class.php'
298
+			);
299
+			$this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend);
300
+		}
301
+		// loop through decaf folders
302
+		$hook_files_glob_path = apply_filters(
303
+			'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path',
304
+			$this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php'
305
+		);
306
+		$this->_hook_paths = array_merge(
307
+			$this->_register_hook_files($hook_files_glob_path),
308
+			$this->_hook_paths
309
+		);  // making sure any extended hook paths are later in the array than the core hook paths!
310
+		return $this->_hook_paths;
311
+	}
312
+
313
+
314
+	protected function _register_hook_files($hook_files_glob_path, $extend = false)
315
+	{
316
+		$hook_paths = array();
317
+		if ($hook_files = glob($hook_files_glob_path)) {
318
+			if (empty($hook_files)) {
319
+				return array();
320
+			}
321
+			foreach ($hook_files as $file) {
322
+				// lets get the linked admin.
323
+				$hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . '/', '', $file)
324
+					: str_replace($this->_folder_path, '', $file);
325
+				$replace = $extend
326
+					? '_' . $this->_file_name . '_Hooks_Extend.class.php'
327
+					: '_'
328
+					  . $this->_file_name
329
+					  . '_Hooks.class.php';
330
+				$rel_admin = str_replace($replace, '', $hook_file);
331
+				$rel_admin = strtolower($rel_admin);
332
+				$hook_paths[] = $file;
333
+				// make sure we haven't already got a hook setup for this page path
334
+				if (in_array($rel_admin, $this->_files_hooked)) {
335
+					continue;
336
+				}
337
+				$this->hook_file = $hook_file;
338
+				$rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin;
339
+				$filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook'));
340
+				$this->_files_hooked[] = $rel_admin;
341
+			}
342
+		}
343
+		return $hook_paths;
344
+	}
345
+
346
+
347
+	public function load_admin_hook($registered_pages)
348
+	{
349
+		$this->hook_file;
350
+		$hook_file = (array) $this->hook_file;
351
+		return array_merge($hook_file, $registered_pages);
352
+	}
353
+
354
+
355
+	/**
356
+	 * _initialize_admin_page
357
+	 *
358
+	 * @see  initialize_admin_page() for info
359
+	 */
360
+	protected function _initialize_admin_page()
361
+	{
362
+
363
+		// JUST CHECK WE'RE ON RIGHT PAGE.
364
+		if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) {
365
+			return;
366
+		} //not on the right page so let's get out.
367
+		$this->_load_page = true;
368
+
369
+		// we don't need to do a page_request check here because it's only called via WP menu system.
370
+		$admin_page = $this->_file_name . '_Admin_Page';
371
+		$hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page;
372
+		$admin_page = apply_filters(
373
+			"FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}",
374
+			$admin_page
375
+		);
376
+		// define requested admin page class name then load the file and instantiate
377
+		$path_to_file = str_replace(array('\\', '/'), '/', $this->_folder_path . $admin_page . '.core.php');
378
+		$path_to_file = apply_filters(
379
+			"FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}",
380
+			$path_to_file
381
+		);// so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page
382
+		if (is_readable($path_to_file)) {
383
+			// This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place
384
+			do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization');
385
+			do_action(
386
+				'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug
387
+			);
388
+			require_once($path_to_file);
389
+			$a = new ReflectionClass($admin_page);
390
+			$this->_loaded_page_object = $a->newInstance($this->_routing);
391
+		}
392
+		do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization');
393
+		do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug);
394
+	}
395
+
396
+
397
+	public function get_admin_page_name()
398
+	{
399
+		return $this->_file_name . '_Admin_Page';
400
+	}
401
+
402
+
403
+	/**
404
+	 * @return mixed
405
+	 */
406
+	public function loaded_page_object()
407
+	{
408
+		return $this->_loaded_page_object;
409
+	}
410
+
411
+
412
+	// public function set_autoloaders($className)
413
+	// {
414
+	//     $dir_ref = array(
415
+	//         $this->_folder_path => array('core', 'class'),
416
+	//     );
417
+	//     EEH_Autoloader::try_autoload($dir_ref, $className);
418
+	// }
419
+	/**
420
+	 * _check_user_access
421
+	 * verifies user access for this admin page.  If no user access is available then let's gracefully exit with a
422
+	 * WordPress die message.
423
+	 *
424
+	 * @return bool|die true if pass (or admin) wp_die if fail
425
+	 */
426
+	private function _check_user_access()
427
+	{
428
+		if (! EE_Registry::instance()->CAP->current_user_can(
429
+			$this->_menu_map->capability,
430
+			$this->_menu_map->menu_slug
431
+		)) {
432
+			wp_die(__('You don\'t have access to this page.', 'event_espresso'), '', array('back_link' => true));
433
+		}
434
+		return true;
435
+	}
436 436
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
         $this->_set_menu_map();
79 79
         if (empty($this->_menu_map) || is_array($this->_menu_map)) {
80 80
             EE_Error::doing_it_wrong(
81
-                get_class($this) . '::$_menu_map',
81
+                get_class($this).'::$_menu_map',
82 82
                 sprintf(
83 83
                     __(
84 84
                         'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core.  Please see Admin_Page_Init class examples in core for the new way of setting this property up.',
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
     {
143 143
         wp_register_style(
144 144
             'espresso_menu',
145
-            EE_ADMIN_URL . 'assets/admin-menu-styles.css',
145
+            EE_ADMIN_URL.'assets/admin-menu-styles.css',
146 146
             array('dashicons'),
147 147
             EVENT_ESPRESSO_VERSION
148 148
         );
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
     protected function _set_capability()
171 171
     {
172 172
         $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability;
173
-        $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability);
173
+        $this->capability = apply_filters('FHEE_'.$this->_menu_map->menu_slug.'_capability', $capability);
174 174
     }
175 175
 
176 176
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
     {
189 189
         // let's check user access first
190 190
         $this->_check_user_access();
191
-        if (! is_object($this->_loaded_page_object)) {
191
+        if ( ! is_object($this->_loaded_page_object)) {
192 192
             return;
193 193
         }
194 194
         $this->_loaded_page_object->route_admin_request();
@@ -198,15 +198,15 @@  discard block
 block discarded – undo
198 198
 
199 199
     public function set_page_dependencies($wp_page_slug)
200 200
     {
201
-        if (! $this->_load_page) {
201
+        if ( ! $this->_load_page) {
202 202
             return;
203 203
         }
204
-        if (! is_object($this->_loaded_page_object)) {
204
+        if ( ! is_object($this->_loaded_page_object)) {
205 205
             $msg[] = __(
206 206
                 'We can\'t load the page because we\'re missing a valid page object that tells us what to load',
207 207
                 'event_espresso'
208 208
             );
209
-            $msg[] = $msg[0] . "\r\n"
209
+            $msg[] = $msg[0]."\r\n"
210 210
                      . sprintf(
211 211
                          __(
212 212
                              'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory',
@@ -214,15 +214,15 @@  discard block
 block discarded – undo
214 214
                          ),
215 215
                          $this->_file_name,
216 216
                          $this->_file_name,
217
-                         $this->_folder_path . $this->_file_name,
217
+                         $this->_folder_path.$this->_file_name,
218 218
                          $this->_menu_map->menu_slug
219 219
                      );
220 220
             throw new EE_Error(implode('||', $msg));
221 221
         }
222 222
         $this->_loaded_page_object->set_wp_page_slug($wp_page_slug);
223
-        $page_hook = 'load-' . $wp_page_slug;
223
+        $page_hook = 'load-'.$wp_page_slug;
224 224
         // hook into page load hook so all page specific stuff get's loaded.
225
-        if (! empty($wp_page_slug)) {
225
+        if ( ! empty($wp_page_slug)) {
226 226
             add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies'));
227 227
         }
228 228
     }
@@ -259,13 +259,13 @@  discard block
 block discarded – undo
259 259
         foreach ($bt as $index => $values) {
260 260
             if (isset($values['class']) && $values['class'] == $class) {
261 261
                 $file_index = $index - 1;
262
-                $this->_folder_name = basename(dirname($bt[ $file_index ]['file']));
263
-                if (! empty($this->_folder_name)) {
262
+                $this->_folder_name = basename(dirname($bt[$file_index]['file']));
263
+                if ( ! empty($this->_folder_name)) {
264 264
                     break;
265 265
                 }
266 266
             }
267 267
         }
268
-        $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/';
268
+        $this->_folder_path = EE_ADMIN_PAGES.$this->_folder_name.'/';
269 269
         $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name);
270 270
         $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name));
271 271
         $this->_file_name = str_replace(' ', '_', $this->_file_name);
@@ -301,12 +301,12 @@  discard block
 block discarded – undo
301 301
         // loop through decaf folders
302 302
         $hook_files_glob_path = apply_filters(
303 303
             'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path',
304
-            $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php'
304
+            $this->_folder_path.'*'.$this->_file_name.'_Hooks.class.php'
305 305
         );
306 306
         $this->_hook_paths = array_merge(
307 307
             $this->_register_hook_files($hook_files_glob_path),
308 308
             $this->_hook_paths
309
-        );  // making sure any extended hook paths are later in the array than the core hook paths!
309
+        ); // making sure any extended hook paths are later in the array than the core hook paths!
310 310
         return $this->_hook_paths;
311 311
     }
312 312
 
@@ -320,10 +320,10 @@  discard block
 block discarded – undo
320 320
             }
321 321
             foreach ($hook_files as $file) {
322 322
                 // lets get the linked admin.
323
-                $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . '/', '', $file)
323
+                $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND.$this->_folder_name.'/', '', $file)
324 324
                     : str_replace($this->_folder_path, '', $file);
325 325
                 $replace = $extend
326
-                    ? '_' . $this->_file_name . '_Hooks_Extend.class.php'
326
+                    ? '_'.$this->_file_name.'_Hooks_Extend.class.php'
327 327
                     : '_'
328 328
                       . $this->_file_name
329 329
                       . '_Hooks.class.php';
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
                     continue;
336 336
                 }
337 337
                 $this->hook_file = $hook_file;
338
-                $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin;
338
+                $rel_admin_hook = 'FHEE_do_other_page_hooks_'.$rel_admin;
339 339
                 $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook'));
340 340
                 $this->_files_hooked[] = $rel_admin;
341 341
             }
@@ -361,42 +361,42 @@  discard block
 block discarded – undo
361 361
     {
362 362
 
363 363
         // JUST CHECK WE'RE ON RIGHT PAGE.
364
-        if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) {
364
+        if (( ! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) {
365 365
             return;
366 366
         } //not on the right page so let's get out.
367 367
         $this->_load_page = true;
368 368
 
369 369
         // we don't need to do a page_request check here because it's only called via WP menu system.
370
-        $admin_page = $this->_file_name . '_Admin_Page';
371
-        $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page;
370
+        $admin_page = $this->_file_name.'_Admin_Page';
371
+        $hook_suffix = $this->_menu_map->menu_slug.'_'.$admin_page;
372 372
         $admin_page = apply_filters(
373 373
             "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}",
374 374
             $admin_page
375 375
         );
376 376
         // define requested admin page class name then load the file and instantiate
377
-        $path_to_file = str_replace(array('\\', '/'), '/', $this->_folder_path . $admin_page . '.core.php');
377
+        $path_to_file = str_replace(array('\\', '/'), '/', $this->_folder_path.$admin_page.'.core.php');
378 378
         $path_to_file = apply_filters(
379 379
             "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}",
380 380
             $path_to_file
381
-        );// so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page
381
+        ); // so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page
382 382
         if (is_readable($path_to_file)) {
383 383
             // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place
384 384
             do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization');
385 385
             do_action(
386
-                'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug
386
+                'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_'.$this->_menu_map->menu_slug
387 387
             );
388 388
             require_once($path_to_file);
389 389
             $a = new ReflectionClass($admin_page);
390 390
             $this->_loaded_page_object = $a->newInstance($this->_routing);
391 391
         }
392 392
         do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization');
393
-        do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug);
393
+        do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_'.$this->_menu_map->menu_slug);
394 394
     }
395 395
 
396 396
 
397 397
     public function get_admin_page_name()
398 398
     {
399
-        return $this->_file_name . '_Admin_Page';
399
+        return $this->_file_name.'_Admin_Page';
400 400
     }
401 401
 
402 402
 
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
      */
426 426
     private function _check_user_access()
427 427
     {
428
-        if (! EE_Registry::instance()->CAP->current_user_can(
428
+        if ( ! EE_Registry::instance()->CAP->current_user_can(
429 429
             $this->_menu_map->capability,
430 430
             $this->_menu_map->menu_slug
431 431
         )) {
Please login to merge, or discard this patch.
core/admin/EE_Admin_Hooks.core.php 2 patches
Indentation   +718 added lines, -718 removed lines patch added patch discarded remove patch
@@ -13,722 +13,722 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * we're just going to use this to hold the name of the caller class (child class name)
18
-     *
19
-     * @var string
20
-     */
21
-    public $caller;
22
-
23
-
24
-    /**
25
-     * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e.
26
-     * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks).  This flag is
27
-     * used later to make sure we require the needed files.
28
-     *
29
-     * @var bool
30
-     */
31
-    protected $_extend;
32
-
33
-
34
-    /**
35
-     * child classes MUST set this property so that the page object can be loaded correctly
36
-     *
37
-     * @var string
38
-     */
39
-    protected $_name;
40
-
41
-
42
-    /**
43
-     * This is set by child classes and is an associative array of ajax hooks in the format:
44
-     * array(
45
-     *    'ajax_action_ref' => 'executing_method'; //must be public
46
-     * )
47
-     *
48
-     * @var array
49
-     */
50
-    protected $_ajax_func;
51
-
52
-
53
-    /**
54
-     * This is an array of methods that get executed on a page routes admin_init hook. Use the following format:
55
-     * array(
56
-     *    'page_route' => 'executing_method' //must be public
57
-     * )
58
-     *
59
-     * @var array
60
-     */
61
-    protected $_init_func;
62
-
63
-
64
-    /**
65
-     * This is an array of methods that output metabox content for the given page route.  Use the following format:
66
-     * array(
67
-     *    0 => array(
68
-     *        'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected
69
-     *        with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox
70
-     *        will be added to each route.
71
-     *        'func' =>  'executing_method',  //must be public (i.e. public function executing_method($post,
72
-     *        $callback_args){} ).  Note if you include callback args in the array then you need to declare them in the
73
-     *        method arguments.
74
-     *        'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it
75
-     *        automatically)
76
-     *        'priority' => 'default', //default 'default' (optional)
77
-     *        'label' => __('Localized Title', 'event_espresso'),
78
-     *        'context' => 'advanced' //advanced is default (optional),
79
-     *    'callback_args' => array() //any callback args to include (optional)
80
-     * )
81
-     * Why are we indexing numerically?  Because it's possible there may be more than one metabox per page_route.
82
-     *
83
-     * @var array
84
-     */
85
-    protected $_metaboxes;
86
-
87
-
88
-    /**
89
-     * This is an array of values that indicate any metaboxes we want removed from a given page route.  Usually this is
90
-     * used when caffeinated functionality is replacing decaffeinated functionality.  Use the following format for the
91
-     * array: array(
92
-     *    0 => array(
93
-     *        'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s)
94
-     *        that are in the class being connected with (i.e. 'edit', or 'create_new').
95
-     *        'id' => 'identifier_for_metabox', //what the id is of the metabox being removed
96
-     *        'context' => 'normal', //the context for the metabox being removed (has to match)
97
-     *        'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox
98
-     *        using the currently loaded screen object->id  however, there may be cases where you have to specify the
99
-     *        id for the screen the metabox is on.
100
-     *    )
101
-     * )
102
-     *
103
-     * @var array
104
-     */
105
-    protected $_remove_metaboxes;
106
-
107
-
108
-    /**
109
-     * This parent class takes care of loading the scripts and styles if the child class has set the properties for
110
-     * them in the following format.  Note, the first array index ('register') is for defining all the registers.  The
111
-     * second array index is for indicating what routes each script/style loads on. array(
112
-     * 'registers' => array(
113
-     *        'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency'
114
-     *        argument to link scripts together.
115
-     *            'type' => 'js' // 'js' or 'css' (defaults to js).  This tells us what type of wp_function to use
116
-     *            'url' => 'http://urltoscript.css.js',
117
-     *            'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has
118
-     *            already been registered elsewhere in the system.  You can just use the depends array to make sure it
119
-     *            gets loaded before the one you are setting here.
120
-     *            'footer' => TRUE //defaults to true (styles don't use this parameter)
121
-     *        ),
122
-     *    'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes
123
-     *    the script gets enqueued on.
124
-     *        'script_ref' => array('route_one', 'route_two')
125
-     *    ),
126
-     *    'localize' => array( //this allows you to set a localize object.  Indicate which script the object is being
127
-     *    attached to and then include an array indexed by the name of the object and the array of key/value pairs for
128
-     *    the object.
129
-     *        'scrip_ref' => array(
130
-     *            'NAME_OF_JS_OBJECT' => array(
131
-     *                'translate_ref' => __('localized_string', 'event_espresso'),
132
-     *                'some_data' => 5
133
-     *            )
134
-     *        )
135
-     *    )
136
-     * )
137
-     *
138
-     * @var array
139
-     */
140
-    protected $_scripts_styles;
141
-
142
-
143
-    /**
144
-     * This is a property that will contain the current route.
145
-     *
146
-     * @var string;
147
-     */
148
-    protected $_current_route;
149
-
150
-
151
-    /**
152
-     * this optional property can be set by child classes to override the priority for the automatic action/filter hook
153
-     * loading in the `_load_routed_hooks()` method.  Please follow this format: array(
154
-     *    'wp_hook_reference' => 1
155
-     *    )
156
-     * )
157
-     *
158
-     * @var array
159
-     */
160
-    protected $_wp_action_filters_priority;
161
-
162
-
163
-    /**
164
-     * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST
165
-     *
166
-     * @var array
167
-     */
168
-    protected $_req_data;
169
-
170
-
171
-    /**
172
-     * This just holds an instance of the page object for this hook
173
-     *
174
-     * @var EE_Admin_Page
175
-     */
176
-    protected $_page_object;
177
-
178
-
179
-    /**
180
-     * This holds the EE_Admin_Page object from the calling admin page that this object hooks into.
181
-     *
182
-     * @var EE_Admin_Page|EE_Admin_Page_CPT
183
-     */
184
-    protected $_adminpage_obj;
185
-
186
-
187
-    /**
188
-     * Holds EE_Registry object
189
-     *
190
-     * @var EE_Registry
191
-     */
192
-    protected $EE = null;
193
-
194
-
195
-    /**
196
-     * constructor
197
-     *
198
-     * @param EE_Admin_Page $admin_page the calling admin_page_object
199
-     */
200
-    public function __construct(EE_Admin_Page $adminpage)
201
-    {
202
-
203
-        $this->_adminpage_obj = $adminpage;
204
-        $this->_req_data = array_merge($_GET, $_POST);
205
-        $this->_set_defaults();
206
-        $this->_set_hooks_properties();
207
-        // first let's verify we're on the right page
208
-        if (! isset($this->_req_data['page'])
209
-            || (isset($this->_req_data['page'])
210
-                && $this->_adminpage_obj->page_slug
211
-                   != $this->_req_data['page'])) {
212
-            return;
213
-        } //get out nothing more to be done here.
214
-        // allow for extends to modify properties
215
-        if (method_exists($this, '_extend_properties')) {
216
-            $this->_extend_properties();
217
-        }
218
-        $this->_set_page_object();
219
-        $this->_init_hooks();
220
-        $this->_load_custom_methods();
221
-        $this->_load_routed_hooks();
222
-        add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
223
-        add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20);
224
-        add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15);
225
-        $this->_ajax_hooks();
226
-    }
227
-
228
-
229
-    /**
230
-     * used by child classes to set the following properties:
231
-     * $_ajax_func (optional)
232
-     * $_init_func (optional)
233
-     * $_metaboxes (optional)
234
-     * $_scripts (optional)
235
-     * $_styles (optional)
236
-     * $_name (required)
237
-     * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the
238
-     * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen
239
-     * really early on page load (just after admin_init) if they want to have them registered for handling early.
240
-     *
241
-     * @access protected
242
-     * @abstract
243
-     * @return void
244
-     */
245
-    abstract protected function _set_hooks_properties();
246
-
247
-
248
-    /**
249
-     * The hooks for enqueue_scripts and enqueue_styles will be run in here.  Child classes need to define their
250
-     * scripts and styles in the relevant $_scripts and $_styles properties.  Child classes must have also already
251
-     * registered the scripts and styles using wp_register_script and wp_register_style functions.
252
-     *
253
-     * @access public
254
-     * @return void
255
-     */
256
-    public function enqueue_scripts_styles()
257
-    {
258
-
259
-        if (! empty($this->_scripts_styles)) {
260
-            // first let's do all the registrations
261
-            if (! isset($this->_scripts_styles['registers'])) {
262
-                $msg[] = __(
263
-                    'There is no "registers" index in the <code>$this->_scripts_styles</code> property.',
264
-                    'event_espresso'
265
-                );
266
-                $msg[] = sprintf(
267
-                    __(
268
-                        'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child',
269
-                        'event_espresso'
270
-                    ),
271
-                    '<strong>' . $this->caller . '</strong>'
272
-                );
273
-                throw new EE_Error(implode('||', $msg));
274
-            }
275
-            foreach ($this->_scripts_styles['registers'] as $ref => $details) {
276
-                $defaults = array(
277
-                    'type'    => 'js',
278
-                    'url'     => '',
279
-                    'depends' => array(),
280
-                    'version' => EVENT_ESPRESSO_VERSION,
281
-                    'footer'  => true,
282
-                );
283
-                $details = wp_parse_args($details, $defaults);
284
-                extract($details);
285
-                // let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do
286
-                $this->_scripts_styles['registers'][ $ref ]['type'] = $type;
287
-                // let's make sure we're not missing any REQUIRED parameters
288
-                if (empty($url)) {
289
-                    $msg[] = sprintf(
290
-                        __('Missing the url for the requested %s', 'event_espresso'),
291
-                        $type == 'js' ? 'script' : 'stylesheet'
292
-                    );
293
-                    $msg[] = sprintf(
294
-                        __(
295
-                            'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref',
296
-                            'event_espresso'
297
-                        ),
298
-                        '<strong>' . $this->caller . '</strong>',
299
-                        $ref
300
-                    );
301
-                    throw new EE_Error(implode('||', $msg));
302
-                }
303
-                // made it here so let's do the appropriate registration
304
-                $type == 'js'
305
-                    ? wp_register_script($ref, $url, $depends, $version, $footer)
306
-                    : wp_register_style(
307
-                        $ref,
308
-                        $url,
309
-                        $depends,
310
-                        $version
311
-                    );
312
-            }
313
-            // k now lets do the enqueues
314
-            if (! isset($this->_scripts_styles['enqueues'])) {
315
-                return;
316
-            }  //not sure if we should throw an error here or not.
317
-
318
-            foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) {
319
-                // make sure $routes is an array
320
-                $routes = (array) $routes;
321
-                if (in_array($this->_current_route, $routes)) {
322
-                    $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref)
323
-                        : wp_enqueue_style($ref);
324
-                    // if we have a localization for the script let's do that too.
325
-                    if (isset($this->_scripts_styles['localize'][ $ref ])) {
326
-                        foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) {
327
-                            wp_localize_script(
328
-                                $ref,
329
-                                $object_name,
330
-                                $this->_scripts_styles['localize'][ $ref ][ $object_name ]
331
-                            );
332
-                        }
333
-                    }
334
-                }
335
-            }
336
-            // let's do the deregisters
337
-            if (! isset($this->_scripts_styles['deregisters'])) {
338
-                return;
339
-            }
340
-            foreach ($this->_scripts_styles['deregisters'] as $ref => $details) {
341
-                $defaults = array(
342
-                    'type' => 'js',
343
-                );
344
-                $details = wp_parse_args($details, $defaults);
345
-                extract($details);
346
-                $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref);
347
-            }
348
-        }
349
-    }
350
-
351
-
352
-    /**
353
-     * just set the defaults for the hooks properties.
354
-     *
355
-     * @access private
356
-     * @return void
357
-     */
358
-    private function _set_defaults()
359
-    {
360
-        $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array();
361
-        $this->_current_route = $this->getCurrentRoute();
362
-        $this->caller = get_class($this);
363
-        $this->_extend = stripos($this->caller, 'Extend') ? true : false;
364
-    }
365
-
366
-
367
-    /**
368
-     * A helper for determining the current route.
369
-     * @return string
370
-     */
371
-    private function getCurrentRoute()
372
-    {
373
-        // list tables do something else with 'action' for bulk actions.
374
-        $action = ! empty($_REQUEST['action']) && $_REQUEST['action'] !== '-1' ? $_REQUEST['action'] : 'default';
375
-        // we set a 'route' variable in some cases where action is being used by something else.
376
-        $action = $action === 'default' && isset($_REQUEST['route']) ? $_REQUEST['route'] : $action;
377
-        return sanitize_key($action);
378
-    }
379
-
380
-
381
-    /**
382
-     * this sets the _page_object property
383
-     *
384
-     * @access protected
385
-     * @return void
386
-     */
387
-    protected function _set_page_object()
388
-    {
389
-        // first make sure $this->_name is set
390
-        if (empty($this->_name)) {
391
-            $msg[] = __('We can\'t load the page object', 'event_espresso');
392
-            $msg[] = sprintf(
393
-                __("This is because the %s child class has not set the '_name' property", 'event_espresso'),
394
-                $this->caller
395
-            );
396
-            throw new EE_Error(implode('||', $msg));
397
-        }
398
-        $ref = str_replace('_', ' ', $this->_name); // take the_message -> the message
399
-        $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message
400
-        // first default file (if exists)
401
-        $decaf_file = EE_ADMIN_PAGES . $this->_name . '/' . $ref . '.core.php';
402
-        if (is_readable($decaf_file)) {
403
-            require_once($decaf_file);
404
-        }
405
-        // now we have to do require for extended file (if needed)
406
-        if ($this->_extend) {
407
-            require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . '/Extend_' . $ref . '.core.php');
408
-        }
409
-        // if we've got an extended class we use that!
410
-        $ref = $this->_extend ? 'Extend_' . $ref : $ref;
411
-        // let's make sure the class exists
412
-        if (! class_exists($ref)) {
413
-            $msg[] = __('We can\'t load the page object', 'event_espresso');
414
-            $msg[] = sprintf(
415
-                __(
416
-                    'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class',
417
-                    'event_espresso'
418
-                ),
419
-                $ref
420
-            );
421
-            throw new EE_Error(implode('||', $msg));
422
-        }
423
-        $a = new ReflectionClass($ref);
424
-        $this->_page_object = $a->newInstance(false);
425
-    }
426
-
427
-
428
-    /**
429
-     * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded.  The
430
-     * advantage of this is when doing things like running our own db interactions on saves etc.  Remember that
431
-     * $this->_req_data (all the _POST and _GET data) is available to your methods.
432
-     *
433
-     * @access private
434
-     * @return void
435
-     */
436
-    private function _load_custom_methods()
437
-    {
438
-        /**
439
-         * method cannot be named 'default' (@see http://us3.php
440
-         * .net/manual/en/reserved.keywords.php) so need to
441
-         * handle routes that are "default"
442
-         *
443
-         * @since 4.3.0
444
-         */
445
-        $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route;
446
-        // these run before the Admin_Page route executes.
447
-        if (method_exists($this, $method_callback)) {
448
-            call_user_func(array($this, $method_callback));
449
-        }
450
-        // these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes.  There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens.
451
-        // first the actions
452
-        // note that these action hooks will have the $query_args value available.
453
-        $admin_class_name = get_class($this->_adminpage_obj);
454
-        if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) {
455
-            add_action(
456
-                'AHEE__'
457
-                . $admin_class_name
458
-                . '___redirect_after_action__before_redirect_modification_'
459
-                . $this->_current_route,
460
-                array($this, '_redirect_action_early_' . $this->_current_route),
461
-                10
462
-            );
463
-        }
464
-        if (method_exists($this, '_redirect_action_' . $this->_current_route)) {
465
-            add_action(
466
-                'AHEE_redirect_' . $admin_class_name . $this->_current_route,
467
-                array($this, '_redirect_action_' . $this->_current_route),
468
-                10
469
-            );
470
-        }
471
-        // let's hook into the _redirect itself and allow for changing where the user goes after redirect.  This will have $query_args and $redirect_url available.
472
-        if (method_exists($this, '_redirect_filter_' . $this->_current_route)) {
473
-            add_filter(
474
-                'FHEE_redirect_' . $admin_class_name . $this->_current_route,
475
-                array($this, '_redirect_filter_' . $this->_current_route),
476
-                10,
477
-                2
478
-            );
479
-        }
480
-    }
481
-
482
-
483
-    /**
484
-     * This method will search for a corresponding method with a name matching the route and the wp_hook to run.  This
485
-     * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route.
486
-     * just remember, methods MUST be public Future hooks should be added in here to be access by child classes.
487
-     *
488
-     * @return void
489
-     */
490
-    private function _load_routed_hooks()
491
-    {
492
-
493
-        // this array provides the hook action names that will be referenced.  Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook.  We'll default all priorities for automatic hooks to 10.
494
-        $hook_filter_array = array(
495
-            'admin_footer'                                                                            => array(
496
-                'type'     => 'action',
497
-                'argnum'   => 1,
498
-                'priority' => 10,
499
-            ),
500
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array(
501
-                'type'     => 'filter',
502
-                'argnum'   => 1,
503
-                'priority' => 10,
504
-            ),
505
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug                               => array(
506
-                'type'     => 'filter',
507
-                'argnum'   => 1,
508
-                'priority' => 10,
509
-            ),
510
-            'FHEE_list_table_views'                                                                   => array(
511
-                'type'     => 'filter',
512
-                'argnum'   => 1,
513
-                'priority' => 10,
514
-            ),
515
-            'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'                              => array(
516
-                'type'     => 'action',
517
-                'argnum'   => 1,
518
-                'priority' => 10,
519
-            ),
520
-        );
521
-        foreach ($hook_filter_array as $hook => $args) {
522
-            if (method_exists($this, $this->_current_route . '_' . $hook)) {
523
-                if (isset($this->_wp_action_filters_priority[ $hook ])) {
524
-                    $args['priority'] = $this->_wp_action_filters_priority[ $hook ];
525
-                }
526
-                if ($args['type'] == 'action') {
527
-                    add_action(
528
-                        $hook,
529
-                        array($this, $this->_current_route . '_' . $hook),
530
-                        $args['priority'],
531
-                        $args['argnum']
532
-                    );
533
-                } else {
534
-                    add_filter(
535
-                        $hook,
536
-                        array($this, $this->_current_route . '_' . $hook),
537
-                        $args['priority'],
538
-                        $args['argnum']
539
-                    );
540
-                }
541
-            }
542
-        }
543
-    }
544
-
545
-
546
-    /**
547
-     * Loop throught the $_ajax_func array and add_actions for the array.
548
-     *
549
-     * @return void
550
-     */
551
-    private function _ajax_hooks()
552
-    {
553
-
554
-        if (empty($this->_ajax_func)) {
555
-            return;
556
-        } //get out there's nothing to take care of.
557
-        foreach ($this->_ajax_func as $action => $method) {
558
-            // make sure method exists
559
-            if (! method_exists($this, $method)) {
560
-                $msg[] = __(
561
-                    'There is no corresponding method for the hook labeled in the _ajax_func array',
562
-                    'event_espresso'
563
-                ) . '<br />';
564
-                $msg[] = sprintf(
565
-                    __(
566
-                        'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
567
-                        'event_espresso'
568
-                    ),
569
-                    $method,
570
-                    $this->caller
571
-                );
572
-                throw new EE_Error(implode('||', $msg));
573
-            }
574
-            add_action('wp_ajax_' . $action, array($this, $method));
575
-        }
576
-    }
577
-
578
-
579
-    /**
580
-     * Loop throught the $_init_func array and add_actions for the array.
581
-     *
582
-     * @return void
583
-     */
584
-    protected function _init_hooks()
585
-    {
586
-        if (empty($this->_init_func)) {
587
-            return;
588
-        } //get out there's nothing to take care of.
589
-        // We need to determine what page_route we are on!
590
-        $current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default';
591
-        foreach ($this->_init_func as $route => $method) {
592
-            // make sure method exists
593
-            if (! method_exists($this, $method)) {
594
-                $msg[] = __(
595
-                    'There is no corresponding method for the hook labeled in the _init_func array',
596
-                    'event_espresso'
597
-                ) . '<br />';
598
-                $msg[] = sprintf(
599
-                    __(
600
-                        'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
601
-                        'event_espresso'
602
-                    ),
603
-                    $method,
604
-                    $this->caller
605
-                );
606
-                throw new EE_Error(implode('||', $msg));
607
-            }
608
-            if ($route == $this->_current_route) {
609
-                add_action('admin_init', array($this, $method));
610
-            }
611
-        }
612
-    }
613
-
614
-
615
-    /**
616
-     * Loop through the _metaboxes property and add_metaboxes accordingly
617
-     * //todo we could eventually make this a config component class (i.e. new EE_Metabox);
618
-     *
619
-     * @access public
620
-     * @return void
621
-     */
622
-    public function add_metaboxes()
623
-    {
624
-        if (empty($this->_metaboxes)) {
625
-            return;
626
-        } //get out we don't have any metaboxes to set for this connection
627
-        $this->_handle_metabox_array($this->_metaboxes);
628
-    }
629
-
630
-
631
-    private function _handle_metabox_array($boxes, $add = true)
632
-    {
633
-
634
-        foreach ($boxes as $box) {
635
-            if (! isset($box['page_route'])) {
636
-                continue;
637
-            } //we dont' have a valid array
638
-            // let's make sure $box['page_route'] is an array so the "foreach" will work.
639
-            $box['page_route'] = (array) $box['page_route'];
640
-            foreach ($box['page_route'] as $route) {
641
-                if ($route != $this->_current_route) {
642
-                    continue;
643
-                } //get out we only add metaboxes for set route.
644
-                if ($add) {
645
-                    $this->_add_metabox($box);
646
-                } else {
647
-                    $this->_remove_metabox($box);
648
-                }
649
-            }
650
-        }
651
-    }
652
-
653
-
654
-    /**
655
-     * Loop through the _remove_metaboxes property and remove metaboxes accordingly.
656
-     *
657
-     * @access public
658
-     * @return void
659
-     */
660
-    public function remove_metaboxes()
661
-    {
662
-
663
-        if (empty($this->_remove_metaboxes)) {
664
-            return;
665
-        } //get out there are no metaboxes to remove
666
-        $this->_handle_metabox_array($this->_remove_metaboxes, false);
667
-    }
668
-
669
-
670
-    /**
671
-     * This just handles adding a metabox
672
-     *
673
-     * @access private
674
-     * @param array $args an array of args that have been set for this metabox by the child class
675
-     */
676
-    private function _add_metabox($args)
677
-    {
678
-        $current_screen = get_current_screen();
679
-        $screen_id = is_object($current_screen) ? $current_screen->id : null;
680
-        $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
681
-        // set defaults
682
-        $defaults = array(
683
-            'func'          => $func,
684
-            'id'            => $this->caller . '_' . $func . '_metabox',
685
-            'priority'      => 'default',
686
-            'label'         => $this->caller,
687
-            'context'       => 'advanced',
688
-            'callback_args' => array(),
689
-            'page'          => isset($args['page']) ? $args['page'] : $screen_id,
690
-        );
691
-        $args = wp_parse_args($args, $defaults);
692
-        extract($args);
693
-        // make sure method exists
694
-        if (! method_exists($this, $func)) {
695
-            $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />';
696
-            $msg[] = sprintf(
697
-                __(
698
-                    'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
699
-                    'event_espresso'
700
-                ),
701
-                $func,
702
-                $this->caller
703
-            );
704
-            throw new EE_Error(implode('||', $msg));
705
-        }
706
-        // everything checks out so lets add the metabox
707
-        add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args);
708
-    }
709
-
710
-
711
-    private function _remove_metabox($args)
712
-    {
713
-        $current_screen = get_current_screen();
714
-        $screen_id = is_object($current_screen) ? $current_screen->id : null;
715
-        $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
716
-        // set defaults
717
-        $defaults = array(
718
-            'id'      => isset($args['id'])
719
-                ? $args['id']
720
-                : $this->_current_route
721
-                  . '_'
722
-                  . $this->caller
723
-                  . '_'
724
-                  . $func
725
-                  . '_metabox',
726
-            'context' => 'default',
727
-            'screen'  => isset($args['screen']) ? $args['screen'] : $screen_id,
728
-        );
729
-        $args = wp_parse_args($args, $defaults);
730
-        extract($args);
731
-        // everything checks out so lets remove the box!
732
-        remove_meta_box($id, $screen, $context);
733
-    }
16
+	/**
17
+	 * we're just going to use this to hold the name of the caller class (child class name)
18
+	 *
19
+	 * @var string
20
+	 */
21
+	public $caller;
22
+
23
+
24
+	/**
25
+	 * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e.
26
+	 * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks).  This flag is
27
+	 * used later to make sure we require the needed files.
28
+	 *
29
+	 * @var bool
30
+	 */
31
+	protected $_extend;
32
+
33
+
34
+	/**
35
+	 * child classes MUST set this property so that the page object can be loaded correctly
36
+	 *
37
+	 * @var string
38
+	 */
39
+	protected $_name;
40
+
41
+
42
+	/**
43
+	 * This is set by child classes and is an associative array of ajax hooks in the format:
44
+	 * array(
45
+	 *    'ajax_action_ref' => 'executing_method'; //must be public
46
+	 * )
47
+	 *
48
+	 * @var array
49
+	 */
50
+	protected $_ajax_func;
51
+
52
+
53
+	/**
54
+	 * This is an array of methods that get executed on a page routes admin_init hook. Use the following format:
55
+	 * array(
56
+	 *    'page_route' => 'executing_method' //must be public
57
+	 * )
58
+	 *
59
+	 * @var array
60
+	 */
61
+	protected $_init_func;
62
+
63
+
64
+	/**
65
+	 * This is an array of methods that output metabox content for the given page route.  Use the following format:
66
+	 * array(
67
+	 *    0 => array(
68
+	 *        'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected
69
+	 *        with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox
70
+	 *        will be added to each route.
71
+	 *        'func' =>  'executing_method',  //must be public (i.e. public function executing_method($post,
72
+	 *        $callback_args){} ).  Note if you include callback args in the array then you need to declare them in the
73
+	 *        method arguments.
74
+	 *        'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it
75
+	 *        automatically)
76
+	 *        'priority' => 'default', //default 'default' (optional)
77
+	 *        'label' => __('Localized Title', 'event_espresso'),
78
+	 *        'context' => 'advanced' //advanced is default (optional),
79
+	 *    'callback_args' => array() //any callback args to include (optional)
80
+	 * )
81
+	 * Why are we indexing numerically?  Because it's possible there may be more than one metabox per page_route.
82
+	 *
83
+	 * @var array
84
+	 */
85
+	protected $_metaboxes;
86
+
87
+
88
+	/**
89
+	 * This is an array of values that indicate any metaboxes we want removed from a given page route.  Usually this is
90
+	 * used when caffeinated functionality is replacing decaffeinated functionality.  Use the following format for the
91
+	 * array: array(
92
+	 *    0 => array(
93
+	 *        'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s)
94
+	 *        that are in the class being connected with (i.e. 'edit', or 'create_new').
95
+	 *        'id' => 'identifier_for_metabox', //what the id is of the metabox being removed
96
+	 *        'context' => 'normal', //the context for the metabox being removed (has to match)
97
+	 *        'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox
98
+	 *        using the currently loaded screen object->id  however, there may be cases where you have to specify the
99
+	 *        id for the screen the metabox is on.
100
+	 *    )
101
+	 * )
102
+	 *
103
+	 * @var array
104
+	 */
105
+	protected $_remove_metaboxes;
106
+
107
+
108
+	/**
109
+	 * This parent class takes care of loading the scripts and styles if the child class has set the properties for
110
+	 * them in the following format.  Note, the first array index ('register') is for defining all the registers.  The
111
+	 * second array index is for indicating what routes each script/style loads on. array(
112
+	 * 'registers' => array(
113
+	 *        'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency'
114
+	 *        argument to link scripts together.
115
+	 *            'type' => 'js' // 'js' or 'css' (defaults to js).  This tells us what type of wp_function to use
116
+	 *            'url' => 'http://urltoscript.css.js',
117
+	 *            'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has
118
+	 *            already been registered elsewhere in the system.  You can just use the depends array to make sure it
119
+	 *            gets loaded before the one you are setting here.
120
+	 *            'footer' => TRUE //defaults to true (styles don't use this parameter)
121
+	 *        ),
122
+	 *    'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes
123
+	 *    the script gets enqueued on.
124
+	 *        'script_ref' => array('route_one', 'route_two')
125
+	 *    ),
126
+	 *    'localize' => array( //this allows you to set a localize object.  Indicate which script the object is being
127
+	 *    attached to and then include an array indexed by the name of the object and the array of key/value pairs for
128
+	 *    the object.
129
+	 *        'scrip_ref' => array(
130
+	 *            'NAME_OF_JS_OBJECT' => array(
131
+	 *                'translate_ref' => __('localized_string', 'event_espresso'),
132
+	 *                'some_data' => 5
133
+	 *            )
134
+	 *        )
135
+	 *    )
136
+	 * )
137
+	 *
138
+	 * @var array
139
+	 */
140
+	protected $_scripts_styles;
141
+
142
+
143
+	/**
144
+	 * This is a property that will contain the current route.
145
+	 *
146
+	 * @var string;
147
+	 */
148
+	protected $_current_route;
149
+
150
+
151
+	/**
152
+	 * this optional property can be set by child classes to override the priority for the automatic action/filter hook
153
+	 * loading in the `_load_routed_hooks()` method.  Please follow this format: array(
154
+	 *    'wp_hook_reference' => 1
155
+	 *    )
156
+	 * )
157
+	 *
158
+	 * @var array
159
+	 */
160
+	protected $_wp_action_filters_priority;
161
+
162
+
163
+	/**
164
+	 * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST
165
+	 *
166
+	 * @var array
167
+	 */
168
+	protected $_req_data;
169
+
170
+
171
+	/**
172
+	 * This just holds an instance of the page object for this hook
173
+	 *
174
+	 * @var EE_Admin_Page
175
+	 */
176
+	protected $_page_object;
177
+
178
+
179
+	/**
180
+	 * This holds the EE_Admin_Page object from the calling admin page that this object hooks into.
181
+	 *
182
+	 * @var EE_Admin_Page|EE_Admin_Page_CPT
183
+	 */
184
+	protected $_adminpage_obj;
185
+
186
+
187
+	/**
188
+	 * Holds EE_Registry object
189
+	 *
190
+	 * @var EE_Registry
191
+	 */
192
+	protected $EE = null;
193
+
194
+
195
+	/**
196
+	 * constructor
197
+	 *
198
+	 * @param EE_Admin_Page $admin_page the calling admin_page_object
199
+	 */
200
+	public function __construct(EE_Admin_Page $adminpage)
201
+	{
202
+
203
+		$this->_adminpage_obj = $adminpage;
204
+		$this->_req_data = array_merge($_GET, $_POST);
205
+		$this->_set_defaults();
206
+		$this->_set_hooks_properties();
207
+		// first let's verify we're on the right page
208
+		if (! isset($this->_req_data['page'])
209
+			|| (isset($this->_req_data['page'])
210
+				&& $this->_adminpage_obj->page_slug
211
+				   != $this->_req_data['page'])) {
212
+			return;
213
+		} //get out nothing more to be done here.
214
+		// allow for extends to modify properties
215
+		if (method_exists($this, '_extend_properties')) {
216
+			$this->_extend_properties();
217
+		}
218
+		$this->_set_page_object();
219
+		$this->_init_hooks();
220
+		$this->_load_custom_methods();
221
+		$this->_load_routed_hooks();
222
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
223
+		add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20);
224
+		add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15);
225
+		$this->_ajax_hooks();
226
+	}
227
+
228
+
229
+	/**
230
+	 * used by child classes to set the following properties:
231
+	 * $_ajax_func (optional)
232
+	 * $_init_func (optional)
233
+	 * $_metaboxes (optional)
234
+	 * $_scripts (optional)
235
+	 * $_styles (optional)
236
+	 * $_name (required)
237
+	 * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the
238
+	 * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen
239
+	 * really early on page load (just after admin_init) if they want to have them registered for handling early.
240
+	 *
241
+	 * @access protected
242
+	 * @abstract
243
+	 * @return void
244
+	 */
245
+	abstract protected function _set_hooks_properties();
246
+
247
+
248
+	/**
249
+	 * The hooks for enqueue_scripts and enqueue_styles will be run in here.  Child classes need to define their
250
+	 * scripts and styles in the relevant $_scripts and $_styles properties.  Child classes must have also already
251
+	 * registered the scripts and styles using wp_register_script and wp_register_style functions.
252
+	 *
253
+	 * @access public
254
+	 * @return void
255
+	 */
256
+	public function enqueue_scripts_styles()
257
+	{
258
+
259
+		if (! empty($this->_scripts_styles)) {
260
+			// first let's do all the registrations
261
+			if (! isset($this->_scripts_styles['registers'])) {
262
+				$msg[] = __(
263
+					'There is no "registers" index in the <code>$this->_scripts_styles</code> property.',
264
+					'event_espresso'
265
+				);
266
+				$msg[] = sprintf(
267
+					__(
268
+						'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child',
269
+						'event_espresso'
270
+					),
271
+					'<strong>' . $this->caller . '</strong>'
272
+				);
273
+				throw new EE_Error(implode('||', $msg));
274
+			}
275
+			foreach ($this->_scripts_styles['registers'] as $ref => $details) {
276
+				$defaults = array(
277
+					'type'    => 'js',
278
+					'url'     => '',
279
+					'depends' => array(),
280
+					'version' => EVENT_ESPRESSO_VERSION,
281
+					'footer'  => true,
282
+				);
283
+				$details = wp_parse_args($details, $defaults);
284
+				extract($details);
285
+				// let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do
286
+				$this->_scripts_styles['registers'][ $ref ]['type'] = $type;
287
+				// let's make sure we're not missing any REQUIRED parameters
288
+				if (empty($url)) {
289
+					$msg[] = sprintf(
290
+						__('Missing the url for the requested %s', 'event_espresso'),
291
+						$type == 'js' ? 'script' : 'stylesheet'
292
+					);
293
+					$msg[] = sprintf(
294
+						__(
295
+							'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref',
296
+							'event_espresso'
297
+						),
298
+						'<strong>' . $this->caller . '</strong>',
299
+						$ref
300
+					);
301
+					throw new EE_Error(implode('||', $msg));
302
+				}
303
+				// made it here so let's do the appropriate registration
304
+				$type == 'js'
305
+					? wp_register_script($ref, $url, $depends, $version, $footer)
306
+					: wp_register_style(
307
+						$ref,
308
+						$url,
309
+						$depends,
310
+						$version
311
+					);
312
+			}
313
+			// k now lets do the enqueues
314
+			if (! isset($this->_scripts_styles['enqueues'])) {
315
+				return;
316
+			}  //not sure if we should throw an error here or not.
317
+
318
+			foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) {
319
+				// make sure $routes is an array
320
+				$routes = (array) $routes;
321
+				if (in_array($this->_current_route, $routes)) {
322
+					$this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref)
323
+						: wp_enqueue_style($ref);
324
+					// if we have a localization for the script let's do that too.
325
+					if (isset($this->_scripts_styles['localize'][ $ref ])) {
326
+						foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) {
327
+							wp_localize_script(
328
+								$ref,
329
+								$object_name,
330
+								$this->_scripts_styles['localize'][ $ref ][ $object_name ]
331
+							);
332
+						}
333
+					}
334
+				}
335
+			}
336
+			// let's do the deregisters
337
+			if (! isset($this->_scripts_styles['deregisters'])) {
338
+				return;
339
+			}
340
+			foreach ($this->_scripts_styles['deregisters'] as $ref => $details) {
341
+				$defaults = array(
342
+					'type' => 'js',
343
+				);
344
+				$details = wp_parse_args($details, $defaults);
345
+				extract($details);
346
+				$type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref);
347
+			}
348
+		}
349
+	}
350
+
351
+
352
+	/**
353
+	 * just set the defaults for the hooks properties.
354
+	 *
355
+	 * @access private
356
+	 * @return void
357
+	 */
358
+	private function _set_defaults()
359
+	{
360
+		$this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array();
361
+		$this->_current_route = $this->getCurrentRoute();
362
+		$this->caller = get_class($this);
363
+		$this->_extend = stripos($this->caller, 'Extend') ? true : false;
364
+	}
365
+
366
+
367
+	/**
368
+	 * A helper for determining the current route.
369
+	 * @return string
370
+	 */
371
+	private function getCurrentRoute()
372
+	{
373
+		// list tables do something else with 'action' for bulk actions.
374
+		$action = ! empty($_REQUEST['action']) && $_REQUEST['action'] !== '-1' ? $_REQUEST['action'] : 'default';
375
+		// we set a 'route' variable in some cases where action is being used by something else.
376
+		$action = $action === 'default' && isset($_REQUEST['route']) ? $_REQUEST['route'] : $action;
377
+		return sanitize_key($action);
378
+	}
379
+
380
+
381
+	/**
382
+	 * this sets the _page_object property
383
+	 *
384
+	 * @access protected
385
+	 * @return void
386
+	 */
387
+	protected function _set_page_object()
388
+	{
389
+		// first make sure $this->_name is set
390
+		if (empty($this->_name)) {
391
+			$msg[] = __('We can\'t load the page object', 'event_espresso');
392
+			$msg[] = sprintf(
393
+				__("This is because the %s child class has not set the '_name' property", 'event_espresso'),
394
+				$this->caller
395
+			);
396
+			throw new EE_Error(implode('||', $msg));
397
+		}
398
+		$ref = str_replace('_', ' ', $this->_name); // take the_message -> the message
399
+		$ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message
400
+		// first default file (if exists)
401
+		$decaf_file = EE_ADMIN_PAGES . $this->_name . '/' . $ref . '.core.php';
402
+		if (is_readable($decaf_file)) {
403
+			require_once($decaf_file);
404
+		}
405
+		// now we have to do require for extended file (if needed)
406
+		if ($this->_extend) {
407
+			require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . '/Extend_' . $ref . '.core.php');
408
+		}
409
+		// if we've got an extended class we use that!
410
+		$ref = $this->_extend ? 'Extend_' . $ref : $ref;
411
+		// let's make sure the class exists
412
+		if (! class_exists($ref)) {
413
+			$msg[] = __('We can\'t load the page object', 'event_espresso');
414
+			$msg[] = sprintf(
415
+				__(
416
+					'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class',
417
+					'event_espresso'
418
+				),
419
+				$ref
420
+			);
421
+			throw new EE_Error(implode('||', $msg));
422
+		}
423
+		$a = new ReflectionClass($ref);
424
+		$this->_page_object = $a->newInstance(false);
425
+	}
426
+
427
+
428
+	/**
429
+	 * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded.  The
430
+	 * advantage of this is when doing things like running our own db interactions on saves etc.  Remember that
431
+	 * $this->_req_data (all the _POST and _GET data) is available to your methods.
432
+	 *
433
+	 * @access private
434
+	 * @return void
435
+	 */
436
+	private function _load_custom_methods()
437
+	{
438
+		/**
439
+		 * method cannot be named 'default' (@see http://us3.php
440
+		 * .net/manual/en/reserved.keywords.php) so need to
441
+		 * handle routes that are "default"
442
+		 *
443
+		 * @since 4.3.0
444
+		 */
445
+		$method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route;
446
+		// these run before the Admin_Page route executes.
447
+		if (method_exists($this, $method_callback)) {
448
+			call_user_func(array($this, $method_callback));
449
+		}
450
+		// these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes.  There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens.
451
+		// first the actions
452
+		// note that these action hooks will have the $query_args value available.
453
+		$admin_class_name = get_class($this->_adminpage_obj);
454
+		if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) {
455
+			add_action(
456
+				'AHEE__'
457
+				. $admin_class_name
458
+				. '___redirect_after_action__before_redirect_modification_'
459
+				. $this->_current_route,
460
+				array($this, '_redirect_action_early_' . $this->_current_route),
461
+				10
462
+			);
463
+		}
464
+		if (method_exists($this, '_redirect_action_' . $this->_current_route)) {
465
+			add_action(
466
+				'AHEE_redirect_' . $admin_class_name . $this->_current_route,
467
+				array($this, '_redirect_action_' . $this->_current_route),
468
+				10
469
+			);
470
+		}
471
+		// let's hook into the _redirect itself and allow for changing where the user goes after redirect.  This will have $query_args and $redirect_url available.
472
+		if (method_exists($this, '_redirect_filter_' . $this->_current_route)) {
473
+			add_filter(
474
+				'FHEE_redirect_' . $admin_class_name . $this->_current_route,
475
+				array($this, '_redirect_filter_' . $this->_current_route),
476
+				10,
477
+				2
478
+			);
479
+		}
480
+	}
481
+
482
+
483
+	/**
484
+	 * This method will search for a corresponding method with a name matching the route and the wp_hook to run.  This
485
+	 * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route.
486
+	 * just remember, methods MUST be public Future hooks should be added in here to be access by child classes.
487
+	 *
488
+	 * @return void
489
+	 */
490
+	private function _load_routed_hooks()
491
+	{
492
+
493
+		// this array provides the hook action names that will be referenced.  Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook.  We'll default all priorities for automatic hooks to 10.
494
+		$hook_filter_array = array(
495
+			'admin_footer'                                                                            => array(
496
+				'type'     => 'action',
497
+				'argnum'   => 1,
498
+				'priority' => 10,
499
+			),
500
+			'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array(
501
+				'type'     => 'filter',
502
+				'argnum'   => 1,
503
+				'priority' => 10,
504
+			),
505
+			'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug                               => array(
506
+				'type'     => 'filter',
507
+				'argnum'   => 1,
508
+				'priority' => 10,
509
+			),
510
+			'FHEE_list_table_views'                                                                   => array(
511
+				'type'     => 'filter',
512
+				'argnum'   => 1,
513
+				'priority' => 10,
514
+			),
515
+			'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'                              => array(
516
+				'type'     => 'action',
517
+				'argnum'   => 1,
518
+				'priority' => 10,
519
+			),
520
+		);
521
+		foreach ($hook_filter_array as $hook => $args) {
522
+			if (method_exists($this, $this->_current_route . '_' . $hook)) {
523
+				if (isset($this->_wp_action_filters_priority[ $hook ])) {
524
+					$args['priority'] = $this->_wp_action_filters_priority[ $hook ];
525
+				}
526
+				if ($args['type'] == 'action') {
527
+					add_action(
528
+						$hook,
529
+						array($this, $this->_current_route . '_' . $hook),
530
+						$args['priority'],
531
+						$args['argnum']
532
+					);
533
+				} else {
534
+					add_filter(
535
+						$hook,
536
+						array($this, $this->_current_route . '_' . $hook),
537
+						$args['priority'],
538
+						$args['argnum']
539
+					);
540
+				}
541
+			}
542
+		}
543
+	}
544
+
545
+
546
+	/**
547
+	 * Loop throught the $_ajax_func array and add_actions for the array.
548
+	 *
549
+	 * @return void
550
+	 */
551
+	private function _ajax_hooks()
552
+	{
553
+
554
+		if (empty($this->_ajax_func)) {
555
+			return;
556
+		} //get out there's nothing to take care of.
557
+		foreach ($this->_ajax_func as $action => $method) {
558
+			// make sure method exists
559
+			if (! method_exists($this, $method)) {
560
+				$msg[] = __(
561
+					'There is no corresponding method for the hook labeled in the _ajax_func array',
562
+					'event_espresso'
563
+				) . '<br />';
564
+				$msg[] = sprintf(
565
+					__(
566
+						'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
567
+						'event_espresso'
568
+					),
569
+					$method,
570
+					$this->caller
571
+				);
572
+				throw new EE_Error(implode('||', $msg));
573
+			}
574
+			add_action('wp_ajax_' . $action, array($this, $method));
575
+		}
576
+	}
577
+
578
+
579
+	/**
580
+	 * Loop throught the $_init_func array and add_actions for the array.
581
+	 *
582
+	 * @return void
583
+	 */
584
+	protected function _init_hooks()
585
+	{
586
+		if (empty($this->_init_func)) {
587
+			return;
588
+		} //get out there's nothing to take care of.
589
+		// We need to determine what page_route we are on!
590
+		$current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default';
591
+		foreach ($this->_init_func as $route => $method) {
592
+			// make sure method exists
593
+			if (! method_exists($this, $method)) {
594
+				$msg[] = __(
595
+					'There is no corresponding method for the hook labeled in the _init_func array',
596
+					'event_espresso'
597
+				) . '<br />';
598
+				$msg[] = sprintf(
599
+					__(
600
+						'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
601
+						'event_espresso'
602
+					),
603
+					$method,
604
+					$this->caller
605
+				);
606
+				throw new EE_Error(implode('||', $msg));
607
+			}
608
+			if ($route == $this->_current_route) {
609
+				add_action('admin_init', array($this, $method));
610
+			}
611
+		}
612
+	}
613
+
614
+
615
+	/**
616
+	 * Loop through the _metaboxes property and add_metaboxes accordingly
617
+	 * //todo we could eventually make this a config component class (i.e. new EE_Metabox);
618
+	 *
619
+	 * @access public
620
+	 * @return void
621
+	 */
622
+	public function add_metaboxes()
623
+	{
624
+		if (empty($this->_metaboxes)) {
625
+			return;
626
+		} //get out we don't have any metaboxes to set for this connection
627
+		$this->_handle_metabox_array($this->_metaboxes);
628
+	}
629
+
630
+
631
+	private function _handle_metabox_array($boxes, $add = true)
632
+	{
633
+
634
+		foreach ($boxes as $box) {
635
+			if (! isset($box['page_route'])) {
636
+				continue;
637
+			} //we dont' have a valid array
638
+			// let's make sure $box['page_route'] is an array so the "foreach" will work.
639
+			$box['page_route'] = (array) $box['page_route'];
640
+			foreach ($box['page_route'] as $route) {
641
+				if ($route != $this->_current_route) {
642
+					continue;
643
+				} //get out we only add metaboxes for set route.
644
+				if ($add) {
645
+					$this->_add_metabox($box);
646
+				} else {
647
+					$this->_remove_metabox($box);
648
+				}
649
+			}
650
+		}
651
+	}
652
+
653
+
654
+	/**
655
+	 * Loop through the _remove_metaboxes property and remove metaboxes accordingly.
656
+	 *
657
+	 * @access public
658
+	 * @return void
659
+	 */
660
+	public function remove_metaboxes()
661
+	{
662
+
663
+		if (empty($this->_remove_metaboxes)) {
664
+			return;
665
+		} //get out there are no metaboxes to remove
666
+		$this->_handle_metabox_array($this->_remove_metaboxes, false);
667
+	}
668
+
669
+
670
+	/**
671
+	 * This just handles adding a metabox
672
+	 *
673
+	 * @access private
674
+	 * @param array $args an array of args that have been set for this metabox by the child class
675
+	 */
676
+	private function _add_metabox($args)
677
+	{
678
+		$current_screen = get_current_screen();
679
+		$screen_id = is_object($current_screen) ? $current_screen->id : null;
680
+		$func = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
681
+		// set defaults
682
+		$defaults = array(
683
+			'func'          => $func,
684
+			'id'            => $this->caller . '_' . $func . '_metabox',
685
+			'priority'      => 'default',
686
+			'label'         => $this->caller,
687
+			'context'       => 'advanced',
688
+			'callback_args' => array(),
689
+			'page'          => isset($args['page']) ? $args['page'] : $screen_id,
690
+		);
691
+		$args = wp_parse_args($args, $defaults);
692
+		extract($args);
693
+		// make sure method exists
694
+		if (! method_exists($this, $func)) {
695
+			$msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />';
696
+			$msg[] = sprintf(
697
+				__(
698
+					'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
699
+					'event_espresso'
700
+				),
701
+				$func,
702
+				$this->caller
703
+			);
704
+			throw new EE_Error(implode('||', $msg));
705
+		}
706
+		// everything checks out so lets add the metabox
707
+		add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args);
708
+	}
709
+
710
+
711
+	private function _remove_metabox($args)
712
+	{
713
+		$current_screen = get_current_screen();
714
+		$screen_id = is_object($current_screen) ? $current_screen->id : null;
715
+		$func = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
716
+		// set defaults
717
+		$defaults = array(
718
+			'id'      => isset($args['id'])
719
+				? $args['id']
720
+				: $this->_current_route
721
+				  . '_'
722
+				  . $this->caller
723
+				  . '_'
724
+				  . $func
725
+				  . '_metabox',
726
+			'context' => 'default',
727
+			'screen'  => isset($args['screen']) ? $args['screen'] : $screen_id,
728
+		);
729
+		$args = wp_parse_args($args, $defaults);
730
+		extract($args);
731
+		// everything checks out so lets remove the box!
732
+		remove_meta_box($id, $screen, $context);
733
+	}
734 734
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         $this->_set_defaults();
206 206
         $this->_set_hooks_properties();
207 207
         // first let's verify we're on the right page
208
-        if (! isset($this->_req_data['page'])
208
+        if ( ! isset($this->_req_data['page'])
209 209
             || (isset($this->_req_data['page'])
210 210
                 && $this->_adminpage_obj->page_slug
211 211
                    != $this->_req_data['page'])) {
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
     public function enqueue_scripts_styles()
257 257
     {
258 258
 
259
-        if (! empty($this->_scripts_styles)) {
259
+        if ( ! empty($this->_scripts_styles)) {
260 260
             // first let's do all the registrations
261
-            if (! isset($this->_scripts_styles['registers'])) {
261
+            if ( ! isset($this->_scripts_styles['registers'])) {
262 262
                 $msg[] = __(
263 263
                     'There is no "registers" index in the <code>$this->_scripts_styles</code> property.',
264 264
                     'event_espresso'
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
                         'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child',
269 269
                         'event_espresso'
270 270
                     ),
271
-                    '<strong>' . $this->caller . '</strong>'
271
+                    '<strong>'.$this->caller.'</strong>'
272 272
                 );
273 273
                 throw new EE_Error(implode('||', $msg));
274 274
             }
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
                 $details = wp_parse_args($details, $defaults);
284 284
                 extract($details);
285 285
                 // let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do
286
-                $this->_scripts_styles['registers'][ $ref ]['type'] = $type;
286
+                $this->_scripts_styles['registers'][$ref]['type'] = $type;
287 287
                 // let's make sure we're not missing any REQUIRED parameters
288 288
                 if (empty($url)) {
289 289
                     $msg[] = sprintf(
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
                             'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref',
296 296
                             'event_espresso'
297 297
                         ),
298
-                        '<strong>' . $this->caller . '</strong>',
298
+                        '<strong>'.$this->caller.'</strong>',
299 299
                         $ref
300 300
                     );
301 301
                     throw new EE_Error(implode('||', $msg));
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
                     );
312 312
             }
313 313
             // k now lets do the enqueues
314
-            if (! isset($this->_scripts_styles['enqueues'])) {
314
+            if ( ! isset($this->_scripts_styles['enqueues'])) {
315 315
                 return;
316 316
             }  //not sure if we should throw an error here or not.
317 317
 
@@ -319,22 +319,22 @@  discard block
 block discarded – undo
319 319
                 // make sure $routes is an array
320 320
                 $routes = (array) $routes;
321 321
                 if (in_array($this->_current_route, $routes)) {
322
-                    $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref)
322
+                    $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref)
323 323
                         : wp_enqueue_style($ref);
324 324
                     // if we have a localization for the script let's do that too.
325
-                    if (isset($this->_scripts_styles['localize'][ $ref ])) {
326
-                        foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) {
325
+                    if (isset($this->_scripts_styles['localize'][$ref])) {
326
+                        foreach ($this->_scripts_styles['localize'][$ref] as $object_name => $indexes) {
327 327
                             wp_localize_script(
328 328
                                 $ref,
329 329
                                 $object_name,
330
-                                $this->_scripts_styles['localize'][ $ref ][ $object_name ]
330
+                                $this->_scripts_styles['localize'][$ref][$object_name]
331 331
                             );
332 332
                         }
333 333
                     }
334 334
                 }
335 335
             }
336 336
             // let's do the deregisters
337
-            if (! isset($this->_scripts_styles['deregisters'])) {
337
+            if ( ! isset($this->_scripts_styles['deregisters'])) {
338 338
                 return;
339 339
             }
340 340
             foreach ($this->_scripts_styles['deregisters'] as $ref => $details) {
@@ -396,20 +396,20 @@  discard block
 block discarded – undo
396 396
             throw new EE_Error(implode('||', $msg));
397 397
         }
398 398
         $ref = str_replace('_', ' ', $this->_name); // take the_message -> the message
399
-        $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message
399
+        $ref = str_replace(' ', '_', ucwords($ref)).'_Admin_Page'; // take the message -> The_Message
400 400
         // first default file (if exists)
401
-        $decaf_file = EE_ADMIN_PAGES . $this->_name . '/' . $ref . '.core.php';
401
+        $decaf_file = EE_ADMIN_PAGES.$this->_name.'/'.$ref.'.core.php';
402 402
         if (is_readable($decaf_file)) {
403 403
             require_once($decaf_file);
404 404
         }
405 405
         // now we have to do require for extended file (if needed)
406 406
         if ($this->_extend) {
407
-            require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . '/Extend_' . $ref . '.core.php');
407
+            require_once(EE_CORE_CAF_ADMIN_EXTEND.$this->_name.'/Extend_'.$ref.'.core.php');
408 408
         }
409 409
         // if we've got an extended class we use that!
410
-        $ref = $this->_extend ? 'Extend_' . $ref : $ref;
410
+        $ref = $this->_extend ? 'Extend_'.$ref : $ref;
411 411
         // let's make sure the class exists
412
-        if (! class_exists($ref)) {
412
+        if ( ! class_exists($ref)) {
413 413
             $msg[] = __('We can\'t load the page object', 'event_espresso');
414 414
             $msg[] = sprintf(
415 415
                 __(
@@ -451,28 +451,28 @@  discard block
 block discarded – undo
451 451
         // first the actions
452 452
         // note that these action hooks will have the $query_args value available.
453 453
         $admin_class_name = get_class($this->_adminpage_obj);
454
-        if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) {
454
+        if (method_exists($this, '_redirect_action_early_'.$this->_current_route)) {
455 455
             add_action(
456 456
                 'AHEE__'
457 457
                 . $admin_class_name
458 458
                 . '___redirect_after_action__before_redirect_modification_'
459 459
                 . $this->_current_route,
460
-                array($this, '_redirect_action_early_' . $this->_current_route),
460
+                array($this, '_redirect_action_early_'.$this->_current_route),
461 461
                 10
462 462
             );
463 463
         }
464
-        if (method_exists($this, '_redirect_action_' . $this->_current_route)) {
464
+        if (method_exists($this, '_redirect_action_'.$this->_current_route)) {
465 465
             add_action(
466
-                'AHEE_redirect_' . $admin_class_name . $this->_current_route,
467
-                array($this, '_redirect_action_' . $this->_current_route),
466
+                'AHEE_redirect_'.$admin_class_name.$this->_current_route,
467
+                array($this, '_redirect_action_'.$this->_current_route),
468 468
                 10
469 469
             );
470 470
         }
471 471
         // let's hook into the _redirect itself and allow for changing where the user goes after redirect.  This will have $query_args and $redirect_url available.
472
-        if (method_exists($this, '_redirect_filter_' . $this->_current_route)) {
472
+        if (method_exists($this, '_redirect_filter_'.$this->_current_route)) {
473 473
             add_filter(
474
-                'FHEE_redirect_' . $admin_class_name . $this->_current_route,
475
-                array($this, '_redirect_filter_' . $this->_current_route),
474
+                'FHEE_redirect_'.$admin_class_name.$this->_current_route,
475
+                array($this, '_redirect_filter_'.$this->_current_route),
476 476
                 10,
477 477
                 2
478 478
             );
@@ -497,12 +497,12 @@  discard block
 block discarded – undo
497 497
                 'argnum'   => 1,
498 498
                 'priority' => 10,
499 499
             ),
500
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array(
500
+            'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug.'_'.$this->_current_route => array(
501 501
                 'type'     => 'filter',
502 502
                 'argnum'   => 1,
503 503
                 'priority' => 10,
504 504
             ),
505
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug                               => array(
505
+            'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug                               => array(
506 506
                 'type'     => 'filter',
507 507
                 'argnum'   => 1,
508 508
                 'priority' => 10,
@@ -519,21 +519,21 @@  discard block
 block discarded – undo
519 519
             ),
520 520
         );
521 521
         foreach ($hook_filter_array as $hook => $args) {
522
-            if (method_exists($this, $this->_current_route . '_' . $hook)) {
523
-                if (isset($this->_wp_action_filters_priority[ $hook ])) {
524
-                    $args['priority'] = $this->_wp_action_filters_priority[ $hook ];
522
+            if (method_exists($this, $this->_current_route.'_'.$hook)) {
523
+                if (isset($this->_wp_action_filters_priority[$hook])) {
524
+                    $args['priority'] = $this->_wp_action_filters_priority[$hook];
525 525
                 }
526 526
                 if ($args['type'] == 'action') {
527 527
                     add_action(
528 528
                         $hook,
529
-                        array($this, $this->_current_route . '_' . $hook),
529
+                        array($this, $this->_current_route.'_'.$hook),
530 530
                         $args['priority'],
531 531
                         $args['argnum']
532 532
                     );
533 533
                 } else {
534 534
                     add_filter(
535 535
                         $hook,
536
-                        array($this, $this->_current_route . '_' . $hook),
536
+                        array($this, $this->_current_route.'_'.$hook),
537 537
                         $args['priority'],
538 538
                         $args['argnum']
539 539
                     );
@@ -556,11 +556,11 @@  discard block
 block discarded – undo
556 556
         } //get out there's nothing to take care of.
557 557
         foreach ($this->_ajax_func as $action => $method) {
558 558
             // make sure method exists
559
-            if (! method_exists($this, $method)) {
559
+            if ( ! method_exists($this, $method)) {
560 560
                 $msg[] = __(
561 561
                     'There is no corresponding method for the hook labeled in the _ajax_func array',
562 562
                     'event_espresso'
563
-                ) . '<br />';
563
+                ).'<br />';
564 564
                 $msg[] = sprintf(
565 565
                     __(
566 566
                         'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
                 );
572 572
                 throw new EE_Error(implode('||', $msg));
573 573
             }
574
-            add_action('wp_ajax_' . $action, array($this, $method));
574
+            add_action('wp_ajax_'.$action, array($this, $method));
575 575
         }
576 576
     }
577 577
 
@@ -590,11 +590,11 @@  discard block
 block discarded – undo
590 590
         $current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default';
591 591
         foreach ($this->_init_func as $route => $method) {
592 592
             // make sure method exists
593
-            if (! method_exists($this, $method)) {
593
+            if ( ! method_exists($this, $method)) {
594 594
                 $msg[] = __(
595 595
                     'There is no corresponding method for the hook labeled in the _init_func array',
596 596
                     'event_espresso'
597
-                ) . '<br />';
597
+                ).'<br />';
598 598
                 $msg[] = sprintf(
599 599
                     __(
600 600
                         'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
     {
633 633
 
634 634
         foreach ($boxes as $box) {
635
-            if (! isset($box['page_route'])) {
635
+            if ( ! isset($box['page_route'])) {
636 636
                 continue;
637 637
             } //we dont' have a valid array
638 638
             // let's make sure $box['page_route'] is an array so the "foreach" will work.
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
         // set defaults
682 682
         $defaults = array(
683 683
             'func'          => $func,
684
-            'id'            => $this->caller . '_' . $func . '_metabox',
684
+            'id'            => $this->caller.'_'.$func.'_metabox',
685 685
             'priority'      => 'default',
686 686
             'label'         => $this->caller,
687 687
             'context'       => 'advanced',
@@ -691,8 +691,8 @@  discard block
 block discarded – undo
691 691
         $args = wp_parse_args($args, $defaults);
692 692
         extract($args);
693 693
         // make sure method exists
694
-        if (! method_exists($this, $func)) {
695
-            $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />';
694
+        if ( ! method_exists($this, $func)) {
695
+            $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso').'<br />';
696 696
             $msg[] = sprintf(
697 697
                 __(
698 698
                     'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
Please login to merge, or discard this patch.
core/db_classes/EE_Import.class.php 2 patches
Indentation   +950 added lines, -950 removed lines patch added patch discarded remove patch
@@ -14,91 +14,91 @@  discard block
 block discarded – undo
14 14
 class EE_Import implements ResettableInterface
15 15
 {
16 16
 
17
-    const do_insert = 'insert';
18
-    const do_update = 'update';
19
-    const do_nothing = 'nothing';
20
-
21
-
22
-    // instance of the EE_Import object
23
-    private static $_instance = null;
24
-
25
-    private static $_csv_array = array();
26
-
27
-    /**
28
-     *
29
-     * @var array of model names
30
-     */
31
-    private static $_model_list = array();
32
-
33
-    private static $_columns_to_save = array();
34
-
35
-    protected $_total_inserts = 0;
36
-    protected $_total_updates = 0;
37
-    protected $_total_insert_errors = 0;
38
-    protected $_total_update_errors = 0;
39
-
40
-
41
-    /**
42
-     *        private constructor to prevent direct creation
43
-     *
44
-     * @Constructor
45
-     * @access private
46
-     * @return void
47
-     */
48
-    private function __construct()
49
-    {
50
-        $this->_total_inserts = 0;
51
-        $this->_total_updates = 0;
52
-        $this->_total_insert_errors = 0;
53
-        $this->_total_update_errors = 0;
54
-    }
55
-
56
-
57
-    /**
58
-     *    @ singleton method used to instantiate class object
59
-     *    @ access public
60
-     *
61
-     * @return EE_Import
62
-     */
63
-    public static function instance()
64
-    {
65
-        // check if class object is instantiated
66
-        if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) {
67
-            self::$_instance = new self();
68
-        }
69
-        return self::$_instance;
70
-    }
71
-
72
-    /**
73
-     * Resets the importer
74
-     *
75
-     * @return EE_Import
76
-     */
77
-    public static function reset()
78
-    {
79
-        self::$_instance = null;
80
-        return self::instance();
81
-    }
82
-
83
-
84
-    /**
85
-     *    @ generates HTML for a file upload input and form
86
-     *    @ access    public
87
-     *
88
-     * @param    string $title  - heading for the form
89
-     * @param    string $intro  - additional text explaing what to do
90
-     * @param    string $page   - EE Admin page to direct form to - in the form "espresso_{pageslug}"
91
-     * @param    string $action - EE Admin page route array "action" that form will direct to
92
-     * @param    string $type   - type of file to import
93
-     *                          @ return    string
94
-     */
95
-    public function upload_form($title, $intro, $form_url, $action, $type)
96
-    {
97
-
98
-        $form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url);
99
-
100
-        ob_start();
101
-        ?>
17
+	const do_insert = 'insert';
18
+	const do_update = 'update';
19
+	const do_nothing = 'nothing';
20
+
21
+
22
+	// instance of the EE_Import object
23
+	private static $_instance = null;
24
+
25
+	private static $_csv_array = array();
26
+
27
+	/**
28
+	 *
29
+	 * @var array of model names
30
+	 */
31
+	private static $_model_list = array();
32
+
33
+	private static $_columns_to_save = array();
34
+
35
+	protected $_total_inserts = 0;
36
+	protected $_total_updates = 0;
37
+	protected $_total_insert_errors = 0;
38
+	protected $_total_update_errors = 0;
39
+
40
+
41
+	/**
42
+	 *        private constructor to prevent direct creation
43
+	 *
44
+	 * @Constructor
45
+	 * @access private
46
+	 * @return void
47
+	 */
48
+	private function __construct()
49
+	{
50
+		$this->_total_inserts = 0;
51
+		$this->_total_updates = 0;
52
+		$this->_total_insert_errors = 0;
53
+		$this->_total_update_errors = 0;
54
+	}
55
+
56
+
57
+	/**
58
+	 *    @ singleton method used to instantiate class object
59
+	 *    @ access public
60
+	 *
61
+	 * @return EE_Import
62
+	 */
63
+	public static function instance()
64
+	{
65
+		// check if class object is instantiated
66
+		if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) {
67
+			self::$_instance = new self();
68
+		}
69
+		return self::$_instance;
70
+	}
71
+
72
+	/**
73
+	 * Resets the importer
74
+	 *
75
+	 * @return EE_Import
76
+	 */
77
+	public static function reset()
78
+	{
79
+		self::$_instance = null;
80
+		return self::instance();
81
+	}
82
+
83
+
84
+	/**
85
+	 *    @ generates HTML for a file upload input and form
86
+	 *    @ access    public
87
+	 *
88
+	 * @param    string $title  - heading for the form
89
+	 * @param    string $intro  - additional text explaing what to do
90
+	 * @param    string $page   - EE Admin page to direct form to - in the form "espresso_{pageslug}"
91
+	 * @param    string $action - EE Admin page route array "action" that form will direct to
92
+	 * @param    string $type   - type of file to import
93
+	 *                          @ return    string
94
+	 */
95
+	public function upload_form($title, $intro, $form_url, $action, $type)
96
+	{
97
+
98
+		$form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url);
99
+
100
+		ob_start();
101
+		?>
102 102
         <div class="ee-upload-form-dv">
103 103
             <h3><?php echo $title; ?></h3>
104 104
             <p><?php echo $intro; ?></p>
@@ -114,874 +114,874 @@  discard block
 block discarded – undo
114 114
                 <b><?php _e('Attention', 'event_espresso'); ?></b><br/>
115 115
                 <?php echo sprintf(__('Accepts .%s file types only.', 'event_espresso'), $type); ?>
116 116
                 <?php echo __(
117
-                    'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.',
118
-                    'event_espresso'
119
-                ); ?>
117
+					'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.',
118
+					'event_espresso'
119
+				); ?>
120 120
             </p>
121 121
 
122 122
         </div>
123 123
 
124 124
         <?php
125
-        $uploader = ob_get_clean();
126
-        return $uploader;
127
-    }
128
-
129
-
130
-    /**
131
-     * @Import Event Espresso data - some code "borrowed" from event espresso csv_import.php
132
-     * @access public
133
-     * @return boolean success
134
-     */
135
-    public function import()
136
-    {
137
-
138
-        require_once(EE_CLASSES . 'EE_CSV.class.php');
139
-        $this->EE_CSV = EE_CSV::instance();
140
-
141
-        if (isset($_REQUEST['import'])) {
142
-            if (isset($_POST['csv_submitted'])) {
143
-                switch ($_FILES['file']['error'][0]) {
144
-                    case UPLOAD_ERR_OK:
145
-                        $error_msg = false;
146
-                        break;
147
-                    case UPLOAD_ERR_INI_SIZE:
148
-                        $error_msg = __(
149
-                            "'The uploaded file exceeds the upload_max_filesize directive in php.ini.'",
150
-                            "event_espresso"
151
-                        );
152
-                        break;
153
-                    case UPLOAD_ERR_FORM_SIZE:
154
-                        $error_msg = __(
155
-                            'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
156
-                            "event_espresso"
157
-                        );
158
-                        break;
159
-                    case UPLOAD_ERR_PARTIAL:
160
-                        $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso");
161
-                        break;
162
-                    case UPLOAD_ERR_NO_FILE:
163
-                        $error_msg = __('No file was uploaded.', "event_espresso");
164
-                        break;
165
-                    case UPLOAD_ERR_NO_TMP_DIR:
166
-                        $error_msg = __('Missing a temporary folder.', "event_espresso");
167
-                        break;
168
-                    case UPLOAD_ERR_CANT_WRITE:
169
-                        $error_msg = __('Failed to write file to disk.', "event_espresso");
170
-                        break;
171
-                    case UPLOAD_ERR_EXTENSION:
172
-                        $error_msg = __('File upload stopped by extension.', "event_espresso");
173
-                        break;
174
-                    default:
175
-                        $error_msg = __(
176
-                            'An unknown error occurred and the file could not be uploaded',
177
-                            "event_espresso"
178
-                        );
179
-                        break;
180
-                }
181
-
182
-                if (! $error_msg) {
183
-                    $filename = $_FILES['file']['name'][0];
184
-                    $file_ext = substr(strrchr($filename, '.'), 1);
185
-                    $file_type = $_FILES['file']['type'][0];
186
-                    $temp_file = $_FILES['file']['tmp_name'][0];
187
-                    $filesize = $_FILES['file']['size'][0] / 1024;// convert from bytes to KB
188
-
189
-                    if ($file_ext == 'csv') {
190
-                        $max_upload = $this->EE_CSV->get_max_upload_size();// max upload size in KB
191
-                        if ($filesize < $max_upload || true) {
192
-                            $wp_upload_dir = str_replace(array('\\', '/'), '/', wp_upload_dir());
193
-                            $path_to_file = $wp_upload_dir['basedir'] . '/espresso/' . $filename;
194
-
195
-                            if (move_uploaded_file($temp_file, $path_to_file)) {
196
-                                // convert csv to array
197
-                                $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file);
198
-
199
-                                // was data successfully stored in an array?
200
-                                if (is_array($this->csv_array)) {
201
-                                    $import_what = str_replace('csv_import_', '', $_REQUEST['action']);
202
-                                    $import_what = str_replace('_', ' ', ucwords($import_what));
203
-                                    $processed_data = $this->csv_array;
204
-                                    $this->columns_to_save = false;
205
-
206
-                                    // if any imports require funcky processing, we'll catch them in the switch
207
-                                    switch ($_REQUEST['action']) {
208
-                                        case "import_events":
209
-                                        case "event_list":
210
-                                            $import_what = 'Event Details';
211
-                                            break;
212
-
213
-                                        case 'groupon_import_csv':
214
-                                            $import_what = 'Groupon Codes';
215
-                                            $processed_data = $this->process_groupon_codes();
216
-                                            break;
217
-                                    }
218
-                                    // save processed codes to db
219
-                                    if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) {
220
-                                        return true;
221
-                                    }
222
-                                } else {
223
-                                    // no array? must be an error
224
-                                    EE_Error::add_error(
225
-                                        sprintf(__("No file seems to have been uploaded", "event_espresso")),
226
-                                        __FILE__,
227
-                                        __FUNCTION__,
228
-                                        __LINE__
229
-                                    );
230
-                                    return false;
231
-                                }
232
-                            } else {
233
-                                EE_Error::add_error(
234
-                                    sprintf(__("%s was not successfully uploaded", "event_espresso"), $filename),
235
-                                    __FILE__,
236
-                                    __FUNCTION__,
237
-                                    __LINE__
238
-                                );
239
-                                return false;
240
-                            }
241
-                        } else {
242
-                            EE_Error::add_error(
243
-                                sprintf(
244
-                                    __(
245
-                                        "%s was too large of a file and could not be uploaded. The max filesize is %s' KB.",
246
-                                        "event_espresso"
247
-                                    ),
248
-                                    $filename,
249
-                                    $max_upload
250
-                                ),
251
-                                __FILE__,
252
-                                __FUNCTION__,
253
-                                __LINE__
254
-                            );
255
-                            return false;
256
-                        }
257
-                    } else {
258
-                        EE_Error::add_error(
259
-                            sprintf(__("%s  had an invalid file extension, not uploaded", "event_espresso"), $filename),
260
-                            __FILE__,
261
-                            __FUNCTION__,
262
-                            __LINE__
263
-                        );
264
-                        return false;
265
-                    }
266
-                } else {
267
-                    EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
268
-                    return false;
269
-                }
270
-            }
271
-        }
272
-        return;
273
-    }
274
-
275
-
276
-    /**
277
-     *    Given an array of data (usually from a CSV import) attempts to save that data to the db.
278
-     *    If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names,
279
-     *    next level being numeric indexes adn each value representing a model object, and the last layer down
280
-     *    being keys of model fields and their proposed values.
281
-     *    If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned.
282
-     *    If the CSV data says (in the metadata row) that it's from the SAME database,
283
-     *    we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those
284
-     *    IDs DON'T exist in the database, they're treated as temporary IDs,
285
-     *    which can used elsewhere to refer to the same object. Once an item
286
-     *    with a temporary ID gets inserted, we record its mapping from temporary
287
-     *    ID to real ID, and use the real ID in place of the temporary ID
288
-     *    when that temporary ID was used as a foreign key.
289
-     *    If the CSV data says (in the metadata again) that it's from a DIFFERENT database,
290
-     *    we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with
291
-     *    ID 1, and the database already has an event with ID 1, we assume that's just a coincidence,
292
-     *    and insert a new event, and map it's temporary ID of 1 over to its new real ID.
293
-     *    An important exception are non-auto-increment primary keys. If one entry in the
294
-     *    CSV file has the same ID as one in the DB, we assume they are meant to be
295
-     *    the same item, and instead update the item in the DB with that same ID.
296
-     *    Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th
297
-     *    time you import a CSV from a different site, we remember their mappings, and
298
-     * will try to update the item in the DB instead of inserting another item (eg
299
-     * if we previously imported an event with temporary ID 1, and then it got a
300
-     * real ID of 123, we remember that. So the next time we import an event with
301
-     * temporary ID, from the same site, we know that it's real ID is 123, and will
302
-     * update that event, instead of adding a new event).
303
-     *
304
-     * @access public
305
-     * @param array $csv_data_array - the array containing the csv data produced from
306
-     *                              EE_CSV::import_csv_to_model_data_array()
307
-     * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table
308
-     *                              fields they will be saved to
309
-     * @return TRUE on success, FALSE on fail
310
-     * @throws \EE_Error
311
-     */
312
-    public function save_csv_data_array_to_db($csv_data_array, $model_name = false)
313
-    {
314
-        $success = false;
315
-        $error = false;
316
-        // whther to treat this import as if it's data froma different database or not
317
-        // ie, if it IS from a different database, ignore foreign keys whihf
318
-        $export_from_site_a_to_b = true;
319
-        // first level of array is not table information but a table name was passed to the function
320
-        // array is only two levels deep, so let's fix that by adding a level, else the next steps will fail
321
-        if ($model_name) {
322
-            $csv_data_array = array($csv_data_array);
323
-        }
324
-        // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name...
325
-        $old_site_url = 'none-specified';
326
-        // hanlde metadata
327
-        if (isset($csv_data_array[ EE_CSV::metadata_header ])) {
328
-            $csv_metadata = array_shift($csv_data_array[ EE_CSV::metadata_header ]);
329
-            // ok so its metadata, dont try to save it to ehte db obviously...
330
-            if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) {
331
-                EE_Error::add_attention(
332
-                    sprintf(
333
-                        __(
334
-                            "CSV Data appears to be from the same database, so attempting to update data",
335
-                            "event_espresso"
336
-                        )
337
-                    )
338
-                );
339
-                $export_from_site_a_to_b = false;
340
-            } else {
341
-                $old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url;
342
-                EE_Error::add_attention(
343
-                    sprintf(
344
-                        __(
345
-                            "CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database",
346
-                            "event_espresso"
347
-                        ),
348
-                        $old_site_url,
349
-                        site_url()
350
-                    )
351
-                );
352
-            };
353
-            unset($csv_data_array[ EE_CSV::metadata_header ]);
354
-        }
355
-        /**
356
-         * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and
357
-         * the value will be the newly-inserted ID.
358
-         * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option
359
-         */
360
-        $old_db_to_new_db_mapping = get_option('ee_id_mapping_from' . sanitize_title($old_site_url), array());
361
-        if ($old_db_to_new_db_mapping) {
362
-            EE_Error::add_attention(
363
-                sprintf(
364
-                    __(
365
-                        "We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s",
366
-                        "event_espresso"
367
-                    ),
368
-                    $old_site_url,
369
-                    site_url()
370
-                )
371
-            );
372
-        }
373
-        $old_db_to_new_db_mapping = $this->save_data_rows_to_db(
374
-            $csv_data_array,
375
-            $export_from_site_a_to_b,
376
-            $old_db_to_new_db_mapping
377
-        );
378
-
379
-        // save the mapping from old db to new db in case they try re-importing the same data from the same website again
380
-        update_option('ee_id_mapping_from' . sanitize_title($old_site_url), $old_db_to_new_db_mapping);
381
-
382
-        if ($this->_total_updates > 0) {
383
-            EE_Error::add_success(
384
-                sprintf(
385
-                    __("%s existing records in the database were updated.", "event_espresso"),
386
-                    $this->_total_updates
387
-                )
388
-            );
389
-            $success = true;
390
-        }
391
-        if ($this->_total_inserts > 0) {
392
-            EE_Error::add_success(
393
-                sprintf(__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts)
394
-            );
395
-            $success = true;
396
-        }
397
-
398
-        if ($this->_total_update_errors > 0) {
399
-            EE_Error::add_error(
400
-                sprintf(
401
-                    __(
402
-                        "'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'",
403
-                        "event_espresso"
404
-                    ),
405
-                    $this->_total_update_errors
406
-                ),
407
-                __FILE__,
408
-                __FUNCTION__,
409
-                __LINE__
410
-            );
411
-            $error = true;
412
-        }
413
-        if ($this->_total_insert_errors > 0) {
414
-            EE_Error::add_error(
415
-                sprintf(
416
-                    __(
417
-                        "One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'",
418
-                        "event_espresso"
419
-                    ),
420
-                    $this->_total_insert_errors
421
-                ),
422
-                __FILE__,
423
-                __FUNCTION__,
424
-                __LINE__
425
-            );
426
-            $error = true;
427
-        }
428
-
429
-        // lastly, we need to update the datetime and ticket sold amounts
430
-        // as those may have been affected by this
431
-        EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all());
432
-
433
-        // if there was at least one success and absolutely no errors
434
-        if ($success && ! $error) {
435
-            return true;
436
-        } else {
437
-            return false;
438
-        }
439
-    }
440
-
441
-
442
-    /**
443
-     * Processes the array of data, given the knowledge that it's from the same database or a different one,
444
-     * and the mapping from temporary IDs to real IDs.
445
-     * If the data is from a different database, we treat the primary keys and their corresponding
446
-     * foreign keys as "temp Ids", basically identifiers that get mapped to real primary keys
447
-     * in the real target database. As items are inserted, their temporary primary keys
448
-     * are mapped to the real IDs in the target database. Also, before doing any update or
449
-     * insert, we replace all the temp ID which are foreign keys with their mapped real IDs.
450
-     * An exception: string primary keys are treated as real IDs, or else we'd need to
451
-     * dynamically generate new string primary keys which would be very awkard for the country table etc.
452
-     * Also, models with no primary key are strange too. We combine use their primar key INDEX (a
453
-     * combination of fields) to create a unique string identifying the row and store
454
-     * those in the mapping.
455
-     *
456
-     * If the data is from the same database, we usually treat primary keys as real IDs.
457
-     * An exception is if there is nothing in the database for that ID. If that's the case,
458
-     * we need to insert a new row for that ID, and then map from the non-existent ID
459
-     * to the newly-inserted real ID.
460
-     *
461
-     * @param type $csv_data_array
462
-     * @param type $export_from_site_a_to_b
463
-     * @param type $old_db_to_new_db_mapping
464
-     * @return array updated $old_db_to_new_db_mapping
465
-     */
466
-    public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping)
467
-    {
468
-        foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) {
469
-            // now check that assumption was correct. If
470
-            if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) {
471
-                $model_name = $model_name_in_csv_data;
472
-            } else {
473
-                // no table info in the array and no table name passed to the function?? FAIL
474
-                EE_Error::add_error(
475
-                    __(
476
-                        'No table information was specified and/or found, therefore the import could not be completed',
477
-                        'event_espresso'
478
-                    ),
479
-                    __FILE__,
480
-                    __FUNCTION__,
481
-                    __LINE__
482
-                );
483
-                return false;
484
-            }
485
-            /* @var $model EEM_Base */
486
-            $model = EE_Registry::instance()->load_model($model_name);
487
-
488
-            // so without further ado, scanning all the data provided for primary keys and their inital values
489
-            foreach ($model_data_from_import as $model_object_data) {
490
-                // before we do ANYTHING, make sure the csv row wasn't just completely blank
491
-                $row_is_completely_empty = true;
492
-                foreach ($model_object_data as $field) {
493
-                    if ($field) {
494
-                        $row_is_completely_empty = false;
495
-                    }
496
-                }
497
-                if ($row_is_completely_empty) {
498
-                    continue;
499
-                }
500
-                // find the PK in the row of data (or a combined key if
501
-                // there is no primary key)
502
-                if ($model->has_primary_key_field()) {
503
-                    $id_in_csv = $model_object_data[ $model->primary_key_name() ];
504
-                } else {
505
-                    $id_in_csv = $model->get_index_primary_key_string($model_object_data);
506
-                }
507
-
508
-
509
-                $model_object_data = $this->_replace_temp_ids_with_mappings(
510
-                    $model_object_data,
511
-                    $model,
512
-                    $old_db_to_new_db_mapping,
513
-                    $export_from_site_a_to_b
514
-                );
515
-                // now we need to decide if we're going to add a new model object given the $model_object_data,
516
-                // or just update.
517
-                if ($export_from_site_a_to_b) {
518
-                    $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db(
519
-                        $id_in_csv,
520
-                        $model_object_data,
521
-                        $model,
522
-                        $old_db_to_new_db_mapping
523
-                    );
524
-                } else {// this is just a re-import
525
-                    $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db(
526
-                        $id_in_csv,
527
-                        $model_object_data,
528
-                        $model,
529
-                        $old_db_to_new_db_mapping
530
-                    );
531
-                }
532
-                if ($what_to_do == self::do_nothing) {
533
-                    continue;
534
-                }
535
-
536
-                // double-check we actually want to insert, if that's what we're planning
537
-                // based on whether this item would be unique in the DB or not
538
-                if ($what_to_do == self::do_insert) {
539
-                    // we're supposed to be inserting. But wait, will this thing
540
-                    // be acceptable if inserted?
541
-                    $conflicting = $model->get_one_conflicting($model_object_data, false);
542
-                    if ($conflicting) {
543
-                        // ok, this item would conflict if inserted. Just update the item that it conflicts with.
544
-                        $what_to_do = self::do_update;
545
-                        // and if this model has a primary key, remember its mapping
546
-                        if ($model->has_primary_key_field()) {
547
-                            $old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ] = $conflicting->ID();
548
-                            $model_object_data[ $model->primary_key_name() ] = $conflicting->ID();
549
-                        } else {
550
-                            // we want to update this conflicting item, instead of inserting a conflicting item
551
-                            // so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields
552
-                            // for the WHERE conditions in the update). At the time of this comment, there were no models like this
553
-                            foreach ($model->get_combined_primary_key_fields() as $key_field) {
554
-                                $model_object_data[ $key_field->get_name() ] = $conflicting->get(
555
-                                    $key_field->get_name()
556
-                                );
557
-                            }
558
-                        }
559
-                    }
560
-                }
561
-                if ($what_to_do == self::do_insert) {
562
-                    $old_db_to_new_db_mapping = $this->_insert_from_data_array(
563
-                        $id_in_csv,
564
-                        $model_object_data,
565
-                        $model,
566
-                        $old_db_to_new_db_mapping
567
-                    );
568
-                } elseif ($what_to_do == self::do_update) {
569
-                    $old_db_to_new_db_mapping = $this->_update_from_data_array(
570
-                        $id_in_csv,
571
-                        $model_object_data,
572
-                        $model,
573
-                        $old_db_to_new_db_mapping
574
-                    );
575
-                } else {
576
-                    throw new EE_Error(
577
-                        sprintf(
578
-                            __(
579
-                                'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid',
580
-                                'event_espresso'
581
-                            ),
582
-                            $what_to_do
583
-                        )
584
-                    );
585
-                }
586
-            }
587
-        }
588
-        return $old_db_to_new_db_mapping;
589
-    }
590
-
591
-
592
-    /**
593
-     * Decides whether or not to insert, given that this data is from another database.
594
-     * So, if the primary key of this $model_object_data already exists in the database,
595
-     * it's just a coincidence and we should still insert. The only time we should
596
-     * update is when we know what it maps to, or there's something that would
597
-     * conflict (and we should instead just update that conflicting thing)
598
-     *
599
-     * @param string   $id_in_csv
600
-     * @param array    $model_object_data        by reference so it can be modified
601
-     * @param EEM_Base $model
602
-     * @param array    $old_db_to_new_db_mapping by reference so it can be modified
603
-     * @return string one of the consts on this class that starts with do_*
604
-     */
605
-    protected function _decide_whether_to_insert_or_update_given_data_from_other_db(
606
-        $id_in_csv,
607
-        $model_object_data,
608
-        $model,
609
-        $old_db_to_new_db_mapping
610
-    ) {
611
-        $model_name = $model->get_this_model_name();
612
-        // if it's a site-to-site export-and-import, see if this modelobject's id
613
-        // in the old data that we know of
614
-        if (isset($old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ])) {
615
-            return self::do_update;
616
-        } else {
617
-            return self::do_insert;
618
-        }
619
-    }
620
-
621
-    /**
622
-     * If this thing basically already exists in the database, we want to update it;
623
-     * otherwise insert it (ie, someone tweaked the CSV file, or the item was
624
-     * deleted in the database so it should be re-inserted)
625
-     *
626
-     * @param type     $id_in_csv
627
-     * @param type     $model_object_data
628
-     * @param EEM_Base $model
629
-     * @param type     $old_db_to_new_db_mapping
630
-     * @return
631
-     */
632
-    protected function _decide_whether_to_insert_or_update_given_data_from_same_db(
633
-        $id_in_csv,
634
-        $model_object_data,
635
-        $model
636
-    ) {
637
-        // in this case, check if this thing ACTUALLY exists in the database
638
-        if ($model->get_one_conflicting($model_object_data)) {
639
-            return self::do_update;
640
-        } else {
641
-            return self::do_insert;
642
-        }
643
-    }
644
-
645
-    /**
646
-     * Using the $old_db_to_new_db_mapping array, replaces all the temporary IDs
647
-     * with their mapped real IDs. Eg, if importing from site A to B, the mapping
648
-     * file may indicate that the ID "my_event_id" maps to an actual event ID of 123.
649
-     * So this function searches for any event temp Ids called "my_event_id" and
650
-     * replaces them with 123.
651
-     * Also, if there is no temp ID for the INT foreign keys from another database,
652
-     * replaces them with 0 or the field's default.
653
-     *
654
-     * @param type     $model_object_data
655
-     * @param EEM_Base $model
656
-     * @param type     $old_db_to_new_db_mapping
657
-     * @param boolean  $export_from_site_a_to_b
658
-     * @return array updated model object data with temp IDs removed
659
-     */
660
-    protected function _replace_temp_ids_with_mappings(
661
-        $model_object_data,
662
-        $model,
663
-        $old_db_to_new_db_mapping,
664
-        $export_from_site_a_to_b
665
-    ) {
666
-        // if this model object's primary key is in the mapping, replace it
667
-        if ($model->has_primary_key_field() &&
668
-            $model->get_primary_key_field()->is_auto_increment() &&
669
-            isset($old_db_to_new_db_mapping[ $model->get_this_model_name() ]) &&
670
-            isset(
671
-                $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ]
672
-            )) {
673
-            $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name(
674
-            ) ][ $model_object_data[ $model->primary_key_name() ] ];
675
-        }
676
-
677
-        try {
678
-            $model_name_field = $model->get_field_containing_related_model_name();
679
-            $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to();
680
-        } catch (EE_Error $e) {
681
-            $model_name_field = null;
682
-            $models_pointed_to_by_model_name_field = array();
683
-        }
684
-        foreach ($model->field_settings(true) as $field_obj) {
685
-            if ($field_obj instanceof EE_Foreign_Key_Int_Field) {
686
-                $models_pointed_to = $field_obj->get_model_names_pointed_to();
687
-                $found_a_mapping = false;
688
-                foreach ($models_pointed_to as $model_pointed_to_by_fk) {
689
-                    if ($model_name_field) {
690
-                        $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ];
691
-                        if ($value_of_model_name_field == $model_pointed_to_by_fk) {
692
-                            $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
693
-                                $model_object_data[ $field_obj->get_name() ],
694
-                                $model_pointed_to_by_fk,
695
-                                $old_db_to_new_db_mapping,
696
-                                $export_from_site_a_to_b
697
-                            );
698
-                            $found_a_mapping = true;
699
-                            break;
700
-                        }
701
-                    } else {
702
-                        $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
703
-                            $model_object_data[ $field_obj->get_name() ],
704
-                            $model_pointed_to_by_fk,
705
-                            $old_db_to_new_db_mapping,
706
-                            $export_from_site_a_to_b
707
-                        );
708
-                        $found_a_mapping = true;
709
-                    }
710
-                    // once we've found a mapping for this field no need to continue
711
-                    if ($found_a_mapping) {
712
-                        break;
713
-                    }
714
-                }
715
-            } else {
716
-                // it's a string foreign key (which we leave alone, because those are things
717
-                // like country names, which we'd really rather not make 2 USAs etc (we'd actually
718
-                // prefer to just update one)
719
-                // or it's just a regular value that ought to be replaced
720
-            }
721
-        }
722
-        //
723
-        if ($model instanceof EEM_Term_Taxonomy) {
724
-            $model_object_data = $this->_handle_split_term_ids($model_object_data);
725
-        }
726
-        return $model_object_data;
727
-    }
728
-
729
-    /**
730
-     * If the data was exported PRE-4.2, but then imported POST-4.2, then the term_id
731
-     * this term-taxonomy refers to may be out-of-date so we need to update it.
732
-     * see https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/
733
-     *
734
-     * @param type $model_object_data
735
-     * @return array new model object data
736
-     */
737
-    protected function _handle_split_term_ids($model_object_data)
738
-    {
739
-        if (isset($model_object_data['term_id'])
740
-            && isset($model_object_data['taxonomy'])
741
-            && apply_filters(
742
-                'FHEE__EE_Import__handle_split_term_ids__function_exists',
743
-                function_exists('wp_get_split_term'),
744
-                $model_object_data
745
-            )) {
746
-            $new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']);
747
-            if ($new_term_id) {
748
-                $model_object_data['term_id'] = $new_term_id;
749
-            }
750
-        }
751
-        return $model_object_data;
752
-    }
753
-
754
-    /**
755
-     * Given the object's ID and its model's name, find it int he mapping data,
756
-     * bearing in mind where it came from
757
-     *
758
-     * @param type   $object_id
759
-     * @param string $model_name
760
-     * @param array  $old_db_to_new_db_mapping
761
-     * @param type   $export_from_site_a_to_b
762
-     * @return int
763
-     */
764
-    protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b)
765
-    {
766
-        if (isset($old_db_to_new_db_mapping[ $model_name ][ $object_id ])) {
767
-            return $old_db_to_new_db_mapping[ $model_name ][ $object_id ];
768
-        } elseif ($object_id == '0' || $object_id == '') {
769
-            // leave as-is
770
-            return $object_id;
771
-        } elseif ($export_from_site_a_to_b) {
772
-            // we couldn't find a mapping for this, and it's from a different site,
773
-            // so blank it out
774
-            return null;
775
-        } elseif (! $export_from_site_a_to_b) {
776
-            // we coudln't find a mapping for this, but it's from thsi DB anyway
777
-            // so let's just leave it as-is
778
-            return $object_id;
779
-        }
780
-    }
781
-
782
-    /**
783
-     *
784
-     * @param type     $id_in_csv
785
-     * @param type     $model_object_data
786
-     * @param EEM_Base $model
787
-     * @param type     $old_db_to_new_db_mapping
788
-     * @return array updated $old_db_to_new_db_mapping
789
-     */
790
-    protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping)
791
-    {
792
-        // remove the primary key, if there is one (we don't want it for inserts OR updates)
793
-        // we'll put it back in if we need it
794
-        if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) {
795
-            $effective_id = $model_object_data[ $model->primary_key_name() ];
796
-            unset($model_object_data[ $model->primary_key_name() ]);
797
-        } else {
798
-            $effective_id = $model->get_index_primary_key_string($model_object_data);
799
-        }
800
-        // the model takes care of validating the CSV's input
801
-        try {
802
-            $new_id = $model->insert($model_object_data);
803
-            if ($new_id) {
804
-                $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_id;
805
-                $this->_total_inserts++;
806
-                EE_Error::add_success(
807
-                    sprintf(
808
-                        __("Successfully added new %s (with id %s) with csv data %s", "event_espresso"),
809
-                        $model->get_this_model_name(),
810
-                        $new_id,
811
-                        implode(",", $model_object_data)
812
-                    )
813
-                );
814
-            } else {
815
-                $this->_total_insert_errors++;
816
-                // put the ID used back in there for the error message
817
-                if ($model->has_primary_key_field()) {
818
-                    $model_object_data[ $model->primary_key_name() ] = $effective_id;
819
-                }
820
-                EE_Error::add_error(
821
-                    sprintf(
822
-                        __("Could not insert new %s with the csv data: %s", "event_espresso"),
823
-                        $model->get_this_model_name(),
824
-                        http_build_query($model_object_data)
825
-                    ),
826
-                    __FILE__,
827
-                    __FUNCTION__,
828
-                    __LINE__
829
-                );
830
-            }
831
-        } catch (EE_Error $e) {
832
-            $this->_total_insert_errors++;
833
-            if ($model->has_primary_key_field()) {
834
-                $model_object_data[ $model->primary_key_name() ] = $effective_id;
835
-            }
836
-            EE_Error::add_error(
837
-                sprintf(
838
-                    __("Could not insert new %s with the csv data: %s because %s", "event_espresso"),
839
-                    $model->get_this_model_name(),
840
-                    implode(",", $model_object_data),
841
-                    $e->getMessage()
842
-                ),
843
-                __FILE__,
844
-                __FUNCTION__,
845
-                __LINE__
846
-            );
847
-        }
848
-        return $old_db_to_new_db_mapping;
849
-    }
850
-
851
-    /**
852
-     * Given the model object data, finds the row to update and updates it
853
-     *
854
-     * @param string|int $id_in_csv
855
-     * @param array      $model_object_data
856
-     * @param EEM_Base   $model
857
-     * @param array      $old_db_to_new_db_mapping
858
-     * @return array updated $old_db_to_new_db_mapping
859
-     */
860
-    protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping)
861
-    {
862
-        try {
863
-            // let's keep two copies of the model object data:
864
-            // one for performing an update, one for everthing else
865
-            $model_object_data_for_update = $model_object_data;
866
-            if ($model->has_primary_key_field()) {
867
-                $conditions = array($model->primary_key_name() => $model_object_data[ $model->primary_key_name() ]);
868
-                // remove the primary key because we shouldn't use it for updating
869
-                unset($model_object_data_for_update[ $model->primary_key_name() ]);
870
-            } elseif ($model->get_combined_primary_key_fields() > 1) {
871
-                $conditions = array();
872
-                foreach ($model->get_combined_primary_key_fields() as $key_field) {
873
-                    $conditions[ $key_field->get_name() ] = $model_object_data[ $key_field->get_name() ];
874
-                }
875
-            } else {
876
-                $model->primary_key_name(
877
-                );// this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey)
878
-            }
879
-
880
-            $success = $model->update($model_object_data_for_update, array($conditions));
881
-            if ($success) {
882
-                $this->_total_updates++;
883
-                EE_Error::add_success(
884
-                    sprintf(
885
-                        __("Successfully updated %s with csv data %s", "event_espresso"),
886
-                        $model->get_this_model_name(),
887
-                        implode(",", $model_object_data_for_update)
888
-                    )
889
-                );
890
-                // we should still record the mapping even though it was an update
891
-                // because if we were going to insert somethign but it was going to conflict
892
-                // we would have last-minute decided to update. So we'd like to know what we updated
893
-                // and so we record what record ended up being updated using the mapping
894
-                if ($model->has_primary_key_field()) {
895
-                    $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ];
896
-                } else {
897
-                    // no primary key just a combined key
898
-                    $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data);
899
-                }
900
-                $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping;
901
-            } else {
902
-                $matched_items = $model->get_all(array($conditions));
903
-                if (! $matched_items) {
904
-                    // no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck?
905
-                    $this->_total_update_errors++;
906
-                    EE_Error::add_error(
907
-                        sprintf(
908
-                            __(
909
-                                "Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)",
910
-                                "event_espresso"
911
-                            ),
912
-                            $model->get_this_model_name(),
913
-                            http_build_query($model_object_data),
914
-                            http_build_query($conditions)
915
-                        ),
916
-                        __FILE__,
917
-                        __FUNCTION__,
918
-                        __LINE__
919
-                    );
920
-                } else {
921
-                    $this->_total_updates++;
922
-                    EE_Error::add_success(
923
-                        sprintf(
924
-                            __(
925
-                                "%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.",
926
-                                "event_espresso"
927
-                            ),
928
-                            $model->get_this_model_name(),
929
-                            implode(",", $model_object_data)
930
-                        )
931
-                    );
932
-                }
933
-            }
934
-        } catch (EE_Error $e) {
935
-            $this->_total_update_errors++;
936
-            $basic_message = sprintf(
937
-                __("Could not update %s with the csv data: %s because %s", "event_espresso"),
938
-                $model->get_this_model_name(),
939
-                implode(",", $model_object_data),
940
-                $e->getMessage()
941
-            );
942
-            $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString();
943
-            EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__);
944
-        }
945
-        return $old_db_to_new_db_mapping;
946
-    }
947
-
948
-    /**
949
-     * Gets the number of inserts performed since importer was instantiated or reset
950
-     *
951
-     * @return int
952
-     */
953
-    public function get_total_inserts()
954
-    {
955
-        return $this->_total_inserts;
956
-    }
957
-
958
-    /**
959
-     *  Gets the number of insert errors since importer was instantiated or reset
960
-     *
961
-     * @return int
962
-     */
963
-    public function get_total_insert_errors()
964
-    {
965
-        return $this->_total_insert_errors;
966
-    }
967
-
968
-    /**
969
-     *  Gets the number of updates performed since importer was instantiated or reset
970
-     *
971
-     * @return int
972
-     */
973
-    public function get_total_updates()
974
-    {
975
-        return $this->_total_updates;
976
-    }
977
-
978
-    /**
979
-     *  Gets the number of update errors since importer was instantiated or reset
980
-     *
981
-     * @return int
982
-     */
983
-    public function get_total_update_errors()
984
-    {
985
-        return $this->_total_update_errors;
986
-    }
125
+		$uploader = ob_get_clean();
126
+		return $uploader;
127
+	}
128
+
129
+
130
+	/**
131
+	 * @Import Event Espresso data - some code "borrowed" from event espresso csv_import.php
132
+	 * @access public
133
+	 * @return boolean success
134
+	 */
135
+	public function import()
136
+	{
137
+
138
+		require_once(EE_CLASSES . 'EE_CSV.class.php');
139
+		$this->EE_CSV = EE_CSV::instance();
140
+
141
+		if (isset($_REQUEST['import'])) {
142
+			if (isset($_POST['csv_submitted'])) {
143
+				switch ($_FILES['file']['error'][0]) {
144
+					case UPLOAD_ERR_OK:
145
+						$error_msg = false;
146
+						break;
147
+					case UPLOAD_ERR_INI_SIZE:
148
+						$error_msg = __(
149
+							"'The uploaded file exceeds the upload_max_filesize directive in php.ini.'",
150
+							"event_espresso"
151
+						);
152
+						break;
153
+					case UPLOAD_ERR_FORM_SIZE:
154
+						$error_msg = __(
155
+							'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
156
+							"event_espresso"
157
+						);
158
+						break;
159
+					case UPLOAD_ERR_PARTIAL:
160
+						$error_msg = __('The uploaded file was only partially uploaded.', "event_espresso");
161
+						break;
162
+					case UPLOAD_ERR_NO_FILE:
163
+						$error_msg = __('No file was uploaded.', "event_espresso");
164
+						break;
165
+					case UPLOAD_ERR_NO_TMP_DIR:
166
+						$error_msg = __('Missing a temporary folder.', "event_espresso");
167
+						break;
168
+					case UPLOAD_ERR_CANT_WRITE:
169
+						$error_msg = __('Failed to write file to disk.', "event_espresso");
170
+						break;
171
+					case UPLOAD_ERR_EXTENSION:
172
+						$error_msg = __('File upload stopped by extension.', "event_espresso");
173
+						break;
174
+					default:
175
+						$error_msg = __(
176
+							'An unknown error occurred and the file could not be uploaded',
177
+							"event_espresso"
178
+						);
179
+						break;
180
+				}
181
+
182
+				if (! $error_msg) {
183
+					$filename = $_FILES['file']['name'][0];
184
+					$file_ext = substr(strrchr($filename, '.'), 1);
185
+					$file_type = $_FILES['file']['type'][0];
186
+					$temp_file = $_FILES['file']['tmp_name'][0];
187
+					$filesize = $_FILES['file']['size'][0] / 1024;// convert from bytes to KB
188
+
189
+					if ($file_ext == 'csv') {
190
+						$max_upload = $this->EE_CSV->get_max_upload_size();// max upload size in KB
191
+						if ($filesize < $max_upload || true) {
192
+							$wp_upload_dir = str_replace(array('\\', '/'), '/', wp_upload_dir());
193
+							$path_to_file = $wp_upload_dir['basedir'] . '/espresso/' . $filename;
194
+
195
+							if (move_uploaded_file($temp_file, $path_to_file)) {
196
+								// convert csv to array
197
+								$this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file);
198
+
199
+								// was data successfully stored in an array?
200
+								if (is_array($this->csv_array)) {
201
+									$import_what = str_replace('csv_import_', '', $_REQUEST['action']);
202
+									$import_what = str_replace('_', ' ', ucwords($import_what));
203
+									$processed_data = $this->csv_array;
204
+									$this->columns_to_save = false;
205
+
206
+									// if any imports require funcky processing, we'll catch them in the switch
207
+									switch ($_REQUEST['action']) {
208
+										case "import_events":
209
+										case "event_list":
210
+											$import_what = 'Event Details';
211
+											break;
212
+
213
+										case 'groupon_import_csv':
214
+											$import_what = 'Groupon Codes';
215
+											$processed_data = $this->process_groupon_codes();
216
+											break;
217
+									}
218
+									// save processed codes to db
219
+									if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) {
220
+										return true;
221
+									}
222
+								} else {
223
+									// no array? must be an error
224
+									EE_Error::add_error(
225
+										sprintf(__("No file seems to have been uploaded", "event_espresso")),
226
+										__FILE__,
227
+										__FUNCTION__,
228
+										__LINE__
229
+									);
230
+									return false;
231
+								}
232
+							} else {
233
+								EE_Error::add_error(
234
+									sprintf(__("%s was not successfully uploaded", "event_espresso"), $filename),
235
+									__FILE__,
236
+									__FUNCTION__,
237
+									__LINE__
238
+								);
239
+								return false;
240
+							}
241
+						} else {
242
+							EE_Error::add_error(
243
+								sprintf(
244
+									__(
245
+										"%s was too large of a file and could not be uploaded. The max filesize is %s' KB.",
246
+										"event_espresso"
247
+									),
248
+									$filename,
249
+									$max_upload
250
+								),
251
+								__FILE__,
252
+								__FUNCTION__,
253
+								__LINE__
254
+							);
255
+							return false;
256
+						}
257
+					} else {
258
+						EE_Error::add_error(
259
+							sprintf(__("%s  had an invalid file extension, not uploaded", "event_espresso"), $filename),
260
+							__FILE__,
261
+							__FUNCTION__,
262
+							__LINE__
263
+						);
264
+						return false;
265
+					}
266
+				} else {
267
+					EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
268
+					return false;
269
+				}
270
+			}
271
+		}
272
+		return;
273
+	}
274
+
275
+
276
+	/**
277
+	 *    Given an array of data (usually from a CSV import) attempts to save that data to the db.
278
+	 *    If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names,
279
+	 *    next level being numeric indexes adn each value representing a model object, and the last layer down
280
+	 *    being keys of model fields and their proposed values.
281
+	 *    If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned.
282
+	 *    If the CSV data says (in the metadata row) that it's from the SAME database,
283
+	 *    we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those
284
+	 *    IDs DON'T exist in the database, they're treated as temporary IDs,
285
+	 *    which can used elsewhere to refer to the same object. Once an item
286
+	 *    with a temporary ID gets inserted, we record its mapping from temporary
287
+	 *    ID to real ID, and use the real ID in place of the temporary ID
288
+	 *    when that temporary ID was used as a foreign key.
289
+	 *    If the CSV data says (in the metadata again) that it's from a DIFFERENT database,
290
+	 *    we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with
291
+	 *    ID 1, and the database already has an event with ID 1, we assume that's just a coincidence,
292
+	 *    and insert a new event, and map it's temporary ID of 1 over to its new real ID.
293
+	 *    An important exception are non-auto-increment primary keys. If one entry in the
294
+	 *    CSV file has the same ID as one in the DB, we assume they are meant to be
295
+	 *    the same item, and instead update the item in the DB with that same ID.
296
+	 *    Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th
297
+	 *    time you import a CSV from a different site, we remember their mappings, and
298
+	 * will try to update the item in the DB instead of inserting another item (eg
299
+	 * if we previously imported an event with temporary ID 1, and then it got a
300
+	 * real ID of 123, we remember that. So the next time we import an event with
301
+	 * temporary ID, from the same site, we know that it's real ID is 123, and will
302
+	 * update that event, instead of adding a new event).
303
+	 *
304
+	 * @access public
305
+	 * @param array $csv_data_array - the array containing the csv data produced from
306
+	 *                              EE_CSV::import_csv_to_model_data_array()
307
+	 * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table
308
+	 *                              fields they will be saved to
309
+	 * @return TRUE on success, FALSE on fail
310
+	 * @throws \EE_Error
311
+	 */
312
+	public function save_csv_data_array_to_db($csv_data_array, $model_name = false)
313
+	{
314
+		$success = false;
315
+		$error = false;
316
+		// whther to treat this import as if it's data froma different database or not
317
+		// ie, if it IS from a different database, ignore foreign keys whihf
318
+		$export_from_site_a_to_b = true;
319
+		// first level of array is not table information but a table name was passed to the function
320
+		// array is only two levels deep, so let's fix that by adding a level, else the next steps will fail
321
+		if ($model_name) {
322
+			$csv_data_array = array($csv_data_array);
323
+		}
324
+		// begin looking through the $csv_data_array, expecting the toplevel key to be the model's name...
325
+		$old_site_url = 'none-specified';
326
+		// hanlde metadata
327
+		if (isset($csv_data_array[ EE_CSV::metadata_header ])) {
328
+			$csv_metadata = array_shift($csv_data_array[ EE_CSV::metadata_header ]);
329
+			// ok so its metadata, dont try to save it to ehte db obviously...
330
+			if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) {
331
+				EE_Error::add_attention(
332
+					sprintf(
333
+						__(
334
+							"CSV Data appears to be from the same database, so attempting to update data",
335
+							"event_espresso"
336
+						)
337
+					)
338
+				);
339
+				$export_from_site_a_to_b = false;
340
+			} else {
341
+				$old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url;
342
+				EE_Error::add_attention(
343
+					sprintf(
344
+						__(
345
+							"CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database",
346
+							"event_espresso"
347
+						),
348
+						$old_site_url,
349
+						site_url()
350
+					)
351
+				);
352
+			};
353
+			unset($csv_data_array[ EE_CSV::metadata_header ]);
354
+		}
355
+		/**
356
+		 * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and
357
+		 * the value will be the newly-inserted ID.
358
+		 * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option
359
+		 */
360
+		$old_db_to_new_db_mapping = get_option('ee_id_mapping_from' . sanitize_title($old_site_url), array());
361
+		if ($old_db_to_new_db_mapping) {
362
+			EE_Error::add_attention(
363
+				sprintf(
364
+					__(
365
+						"We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s",
366
+						"event_espresso"
367
+					),
368
+					$old_site_url,
369
+					site_url()
370
+				)
371
+			);
372
+		}
373
+		$old_db_to_new_db_mapping = $this->save_data_rows_to_db(
374
+			$csv_data_array,
375
+			$export_from_site_a_to_b,
376
+			$old_db_to_new_db_mapping
377
+		);
378
+
379
+		// save the mapping from old db to new db in case they try re-importing the same data from the same website again
380
+		update_option('ee_id_mapping_from' . sanitize_title($old_site_url), $old_db_to_new_db_mapping);
381
+
382
+		if ($this->_total_updates > 0) {
383
+			EE_Error::add_success(
384
+				sprintf(
385
+					__("%s existing records in the database were updated.", "event_espresso"),
386
+					$this->_total_updates
387
+				)
388
+			);
389
+			$success = true;
390
+		}
391
+		if ($this->_total_inserts > 0) {
392
+			EE_Error::add_success(
393
+				sprintf(__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts)
394
+			);
395
+			$success = true;
396
+		}
397
+
398
+		if ($this->_total_update_errors > 0) {
399
+			EE_Error::add_error(
400
+				sprintf(
401
+					__(
402
+						"'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'",
403
+						"event_espresso"
404
+					),
405
+					$this->_total_update_errors
406
+				),
407
+				__FILE__,
408
+				__FUNCTION__,
409
+				__LINE__
410
+			);
411
+			$error = true;
412
+		}
413
+		if ($this->_total_insert_errors > 0) {
414
+			EE_Error::add_error(
415
+				sprintf(
416
+					__(
417
+						"One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'",
418
+						"event_espresso"
419
+					),
420
+					$this->_total_insert_errors
421
+				),
422
+				__FILE__,
423
+				__FUNCTION__,
424
+				__LINE__
425
+			);
426
+			$error = true;
427
+		}
428
+
429
+		// lastly, we need to update the datetime and ticket sold amounts
430
+		// as those may have been affected by this
431
+		EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all());
432
+
433
+		// if there was at least one success and absolutely no errors
434
+		if ($success && ! $error) {
435
+			return true;
436
+		} else {
437
+			return false;
438
+		}
439
+	}
440
+
441
+
442
+	/**
443
+	 * Processes the array of data, given the knowledge that it's from the same database or a different one,
444
+	 * and the mapping from temporary IDs to real IDs.
445
+	 * If the data is from a different database, we treat the primary keys and their corresponding
446
+	 * foreign keys as "temp Ids", basically identifiers that get mapped to real primary keys
447
+	 * in the real target database. As items are inserted, their temporary primary keys
448
+	 * are mapped to the real IDs in the target database. Also, before doing any update or
449
+	 * insert, we replace all the temp ID which are foreign keys with their mapped real IDs.
450
+	 * An exception: string primary keys are treated as real IDs, or else we'd need to
451
+	 * dynamically generate new string primary keys which would be very awkard for the country table etc.
452
+	 * Also, models with no primary key are strange too. We combine use their primar key INDEX (a
453
+	 * combination of fields) to create a unique string identifying the row and store
454
+	 * those in the mapping.
455
+	 *
456
+	 * If the data is from the same database, we usually treat primary keys as real IDs.
457
+	 * An exception is if there is nothing in the database for that ID. If that's the case,
458
+	 * we need to insert a new row for that ID, and then map from the non-existent ID
459
+	 * to the newly-inserted real ID.
460
+	 *
461
+	 * @param type $csv_data_array
462
+	 * @param type $export_from_site_a_to_b
463
+	 * @param type $old_db_to_new_db_mapping
464
+	 * @return array updated $old_db_to_new_db_mapping
465
+	 */
466
+	public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping)
467
+	{
468
+		foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) {
469
+			// now check that assumption was correct. If
470
+			if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) {
471
+				$model_name = $model_name_in_csv_data;
472
+			} else {
473
+				// no table info in the array and no table name passed to the function?? FAIL
474
+				EE_Error::add_error(
475
+					__(
476
+						'No table information was specified and/or found, therefore the import could not be completed',
477
+						'event_espresso'
478
+					),
479
+					__FILE__,
480
+					__FUNCTION__,
481
+					__LINE__
482
+				);
483
+				return false;
484
+			}
485
+			/* @var $model EEM_Base */
486
+			$model = EE_Registry::instance()->load_model($model_name);
487
+
488
+			// so without further ado, scanning all the data provided for primary keys and their inital values
489
+			foreach ($model_data_from_import as $model_object_data) {
490
+				// before we do ANYTHING, make sure the csv row wasn't just completely blank
491
+				$row_is_completely_empty = true;
492
+				foreach ($model_object_data as $field) {
493
+					if ($field) {
494
+						$row_is_completely_empty = false;
495
+					}
496
+				}
497
+				if ($row_is_completely_empty) {
498
+					continue;
499
+				}
500
+				// find the PK in the row of data (or a combined key if
501
+				// there is no primary key)
502
+				if ($model->has_primary_key_field()) {
503
+					$id_in_csv = $model_object_data[ $model->primary_key_name() ];
504
+				} else {
505
+					$id_in_csv = $model->get_index_primary_key_string($model_object_data);
506
+				}
507
+
508
+
509
+				$model_object_data = $this->_replace_temp_ids_with_mappings(
510
+					$model_object_data,
511
+					$model,
512
+					$old_db_to_new_db_mapping,
513
+					$export_from_site_a_to_b
514
+				);
515
+				// now we need to decide if we're going to add a new model object given the $model_object_data,
516
+				// or just update.
517
+				if ($export_from_site_a_to_b) {
518
+					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db(
519
+						$id_in_csv,
520
+						$model_object_data,
521
+						$model,
522
+						$old_db_to_new_db_mapping
523
+					);
524
+				} else {// this is just a re-import
525
+					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db(
526
+						$id_in_csv,
527
+						$model_object_data,
528
+						$model,
529
+						$old_db_to_new_db_mapping
530
+					);
531
+				}
532
+				if ($what_to_do == self::do_nothing) {
533
+					continue;
534
+				}
535
+
536
+				// double-check we actually want to insert, if that's what we're planning
537
+				// based on whether this item would be unique in the DB or not
538
+				if ($what_to_do == self::do_insert) {
539
+					// we're supposed to be inserting. But wait, will this thing
540
+					// be acceptable if inserted?
541
+					$conflicting = $model->get_one_conflicting($model_object_data, false);
542
+					if ($conflicting) {
543
+						// ok, this item would conflict if inserted. Just update the item that it conflicts with.
544
+						$what_to_do = self::do_update;
545
+						// and if this model has a primary key, remember its mapping
546
+						if ($model->has_primary_key_field()) {
547
+							$old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ] = $conflicting->ID();
548
+							$model_object_data[ $model->primary_key_name() ] = $conflicting->ID();
549
+						} else {
550
+							// we want to update this conflicting item, instead of inserting a conflicting item
551
+							// so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields
552
+							// for the WHERE conditions in the update). At the time of this comment, there were no models like this
553
+							foreach ($model->get_combined_primary_key_fields() as $key_field) {
554
+								$model_object_data[ $key_field->get_name() ] = $conflicting->get(
555
+									$key_field->get_name()
556
+								);
557
+							}
558
+						}
559
+					}
560
+				}
561
+				if ($what_to_do == self::do_insert) {
562
+					$old_db_to_new_db_mapping = $this->_insert_from_data_array(
563
+						$id_in_csv,
564
+						$model_object_data,
565
+						$model,
566
+						$old_db_to_new_db_mapping
567
+					);
568
+				} elseif ($what_to_do == self::do_update) {
569
+					$old_db_to_new_db_mapping = $this->_update_from_data_array(
570
+						$id_in_csv,
571
+						$model_object_data,
572
+						$model,
573
+						$old_db_to_new_db_mapping
574
+					);
575
+				} else {
576
+					throw new EE_Error(
577
+						sprintf(
578
+							__(
579
+								'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid',
580
+								'event_espresso'
581
+							),
582
+							$what_to_do
583
+						)
584
+					);
585
+				}
586
+			}
587
+		}
588
+		return $old_db_to_new_db_mapping;
589
+	}
590
+
591
+
592
+	/**
593
+	 * Decides whether or not to insert, given that this data is from another database.
594
+	 * So, if the primary key of this $model_object_data already exists in the database,
595
+	 * it's just a coincidence and we should still insert. The only time we should
596
+	 * update is when we know what it maps to, or there's something that would
597
+	 * conflict (and we should instead just update that conflicting thing)
598
+	 *
599
+	 * @param string   $id_in_csv
600
+	 * @param array    $model_object_data        by reference so it can be modified
601
+	 * @param EEM_Base $model
602
+	 * @param array    $old_db_to_new_db_mapping by reference so it can be modified
603
+	 * @return string one of the consts on this class that starts with do_*
604
+	 */
605
+	protected function _decide_whether_to_insert_or_update_given_data_from_other_db(
606
+		$id_in_csv,
607
+		$model_object_data,
608
+		$model,
609
+		$old_db_to_new_db_mapping
610
+	) {
611
+		$model_name = $model->get_this_model_name();
612
+		// if it's a site-to-site export-and-import, see if this modelobject's id
613
+		// in the old data that we know of
614
+		if (isset($old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ])) {
615
+			return self::do_update;
616
+		} else {
617
+			return self::do_insert;
618
+		}
619
+	}
620
+
621
+	/**
622
+	 * If this thing basically already exists in the database, we want to update it;
623
+	 * otherwise insert it (ie, someone tweaked the CSV file, or the item was
624
+	 * deleted in the database so it should be re-inserted)
625
+	 *
626
+	 * @param type     $id_in_csv
627
+	 * @param type     $model_object_data
628
+	 * @param EEM_Base $model
629
+	 * @param type     $old_db_to_new_db_mapping
630
+	 * @return
631
+	 */
632
+	protected function _decide_whether_to_insert_or_update_given_data_from_same_db(
633
+		$id_in_csv,
634
+		$model_object_data,
635
+		$model
636
+	) {
637
+		// in this case, check if this thing ACTUALLY exists in the database
638
+		if ($model->get_one_conflicting($model_object_data)) {
639
+			return self::do_update;
640
+		} else {
641
+			return self::do_insert;
642
+		}
643
+	}
644
+
645
+	/**
646
+	 * Using the $old_db_to_new_db_mapping array, replaces all the temporary IDs
647
+	 * with their mapped real IDs. Eg, if importing from site A to B, the mapping
648
+	 * file may indicate that the ID "my_event_id" maps to an actual event ID of 123.
649
+	 * So this function searches for any event temp Ids called "my_event_id" and
650
+	 * replaces them with 123.
651
+	 * Also, if there is no temp ID for the INT foreign keys from another database,
652
+	 * replaces them with 0 or the field's default.
653
+	 *
654
+	 * @param type     $model_object_data
655
+	 * @param EEM_Base $model
656
+	 * @param type     $old_db_to_new_db_mapping
657
+	 * @param boolean  $export_from_site_a_to_b
658
+	 * @return array updated model object data with temp IDs removed
659
+	 */
660
+	protected function _replace_temp_ids_with_mappings(
661
+		$model_object_data,
662
+		$model,
663
+		$old_db_to_new_db_mapping,
664
+		$export_from_site_a_to_b
665
+	) {
666
+		// if this model object's primary key is in the mapping, replace it
667
+		if ($model->has_primary_key_field() &&
668
+			$model->get_primary_key_field()->is_auto_increment() &&
669
+			isset($old_db_to_new_db_mapping[ $model->get_this_model_name() ]) &&
670
+			isset(
671
+				$old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ]
672
+			)) {
673
+			$model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name(
674
+			) ][ $model_object_data[ $model->primary_key_name() ] ];
675
+		}
676
+
677
+		try {
678
+			$model_name_field = $model->get_field_containing_related_model_name();
679
+			$models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to();
680
+		} catch (EE_Error $e) {
681
+			$model_name_field = null;
682
+			$models_pointed_to_by_model_name_field = array();
683
+		}
684
+		foreach ($model->field_settings(true) as $field_obj) {
685
+			if ($field_obj instanceof EE_Foreign_Key_Int_Field) {
686
+				$models_pointed_to = $field_obj->get_model_names_pointed_to();
687
+				$found_a_mapping = false;
688
+				foreach ($models_pointed_to as $model_pointed_to_by_fk) {
689
+					if ($model_name_field) {
690
+						$value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ];
691
+						if ($value_of_model_name_field == $model_pointed_to_by_fk) {
692
+							$model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
693
+								$model_object_data[ $field_obj->get_name() ],
694
+								$model_pointed_to_by_fk,
695
+								$old_db_to_new_db_mapping,
696
+								$export_from_site_a_to_b
697
+							);
698
+							$found_a_mapping = true;
699
+							break;
700
+						}
701
+					} else {
702
+						$model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
703
+							$model_object_data[ $field_obj->get_name() ],
704
+							$model_pointed_to_by_fk,
705
+							$old_db_to_new_db_mapping,
706
+							$export_from_site_a_to_b
707
+						);
708
+						$found_a_mapping = true;
709
+					}
710
+					// once we've found a mapping for this field no need to continue
711
+					if ($found_a_mapping) {
712
+						break;
713
+					}
714
+				}
715
+			} else {
716
+				// it's a string foreign key (which we leave alone, because those are things
717
+				// like country names, which we'd really rather not make 2 USAs etc (we'd actually
718
+				// prefer to just update one)
719
+				// or it's just a regular value that ought to be replaced
720
+			}
721
+		}
722
+		//
723
+		if ($model instanceof EEM_Term_Taxonomy) {
724
+			$model_object_data = $this->_handle_split_term_ids($model_object_data);
725
+		}
726
+		return $model_object_data;
727
+	}
728
+
729
+	/**
730
+	 * If the data was exported PRE-4.2, but then imported POST-4.2, then the term_id
731
+	 * this term-taxonomy refers to may be out-of-date so we need to update it.
732
+	 * see https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/
733
+	 *
734
+	 * @param type $model_object_data
735
+	 * @return array new model object data
736
+	 */
737
+	protected function _handle_split_term_ids($model_object_data)
738
+	{
739
+		if (isset($model_object_data['term_id'])
740
+			&& isset($model_object_data['taxonomy'])
741
+			&& apply_filters(
742
+				'FHEE__EE_Import__handle_split_term_ids__function_exists',
743
+				function_exists('wp_get_split_term'),
744
+				$model_object_data
745
+			)) {
746
+			$new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']);
747
+			if ($new_term_id) {
748
+				$model_object_data['term_id'] = $new_term_id;
749
+			}
750
+		}
751
+		return $model_object_data;
752
+	}
753
+
754
+	/**
755
+	 * Given the object's ID and its model's name, find it int he mapping data,
756
+	 * bearing in mind where it came from
757
+	 *
758
+	 * @param type   $object_id
759
+	 * @param string $model_name
760
+	 * @param array  $old_db_to_new_db_mapping
761
+	 * @param type   $export_from_site_a_to_b
762
+	 * @return int
763
+	 */
764
+	protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b)
765
+	{
766
+		if (isset($old_db_to_new_db_mapping[ $model_name ][ $object_id ])) {
767
+			return $old_db_to_new_db_mapping[ $model_name ][ $object_id ];
768
+		} elseif ($object_id == '0' || $object_id == '') {
769
+			// leave as-is
770
+			return $object_id;
771
+		} elseif ($export_from_site_a_to_b) {
772
+			// we couldn't find a mapping for this, and it's from a different site,
773
+			// so blank it out
774
+			return null;
775
+		} elseif (! $export_from_site_a_to_b) {
776
+			// we coudln't find a mapping for this, but it's from thsi DB anyway
777
+			// so let's just leave it as-is
778
+			return $object_id;
779
+		}
780
+	}
781
+
782
+	/**
783
+	 *
784
+	 * @param type     $id_in_csv
785
+	 * @param type     $model_object_data
786
+	 * @param EEM_Base $model
787
+	 * @param type     $old_db_to_new_db_mapping
788
+	 * @return array updated $old_db_to_new_db_mapping
789
+	 */
790
+	protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping)
791
+	{
792
+		// remove the primary key, if there is one (we don't want it for inserts OR updates)
793
+		// we'll put it back in if we need it
794
+		if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) {
795
+			$effective_id = $model_object_data[ $model->primary_key_name() ];
796
+			unset($model_object_data[ $model->primary_key_name() ]);
797
+		} else {
798
+			$effective_id = $model->get_index_primary_key_string($model_object_data);
799
+		}
800
+		// the model takes care of validating the CSV's input
801
+		try {
802
+			$new_id = $model->insert($model_object_data);
803
+			if ($new_id) {
804
+				$old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_id;
805
+				$this->_total_inserts++;
806
+				EE_Error::add_success(
807
+					sprintf(
808
+						__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"),
809
+						$model->get_this_model_name(),
810
+						$new_id,
811
+						implode(",", $model_object_data)
812
+					)
813
+				);
814
+			} else {
815
+				$this->_total_insert_errors++;
816
+				// put the ID used back in there for the error message
817
+				if ($model->has_primary_key_field()) {
818
+					$model_object_data[ $model->primary_key_name() ] = $effective_id;
819
+				}
820
+				EE_Error::add_error(
821
+					sprintf(
822
+						__("Could not insert new %s with the csv data: %s", "event_espresso"),
823
+						$model->get_this_model_name(),
824
+						http_build_query($model_object_data)
825
+					),
826
+					__FILE__,
827
+					__FUNCTION__,
828
+					__LINE__
829
+				);
830
+			}
831
+		} catch (EE_Error $e) {
832
+			$this->_total_insert_errors++;
833
+			if ($model->has_primary_key_field()) {
834
+				$model_object_data[ $model->primary_key_name() ] = $effective_id;
835
+			}
836
+			EE_Error::add_error(
837
+				sprintf(
838
+					__("Could not insert new %s with the csv data: %s because %s", "event_espresso"),
839
+					$model->get_this_model_name(),
840
+					implode(",", $model_object_data),
841
+					$e->getMessage()
842
+				),
843
+				__FILE__,
844
+				__FUNCTION__,
845
+				__LINE__
846
+			);
847
+		}
848
+		return $old_db_to_new_db_mapping;
849
+	}
850
+
851
+	/**
852
+	 * Given the model object data, finds the row to update and updates it
853
+	 *
854
+	 * @param string|int $id_in_csv
855
+	 * @param array      $model_object_data
856
+	 * @param EEM_Base   $model
857
+	 * @param array      $old_db_to_new_db_mapping
858
+	 * @return array updated $old_db_to_new_db_mapping
859
+	 */
860
+	protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping)
861
+	{
862
+		try {
863
+			// let's keep two copies of the model object data:
864
+			// one for performing an update, one for everthing else
865
+			$model_object_data_for_update = $model_object_data;
866
+			if ($model->has_primary_key_field()) {
867
+				$conditions = array($model->primary_key_name() => $model_object_data[ $model->primary_key_name() ]);
868
+				// remove the primary key because we shouldn't use it for updating
869
+				unset($model_object_data_for_update[ $model->primary_key_name() ]);
870
+			} elseif ($model->get_combined_primary_key_fields() > 1) {
871
+				$conditions = array();
872
+				foreach ($model->get_combined_primary_key_fields() as $key_field) {
873
+					$conditions[ $key_field->get_name() ] = $model_object_data[ $key_field->get_name() ];
874
+				}
875
+			} else {
876
+				$model->primary_key_name(
877
+				);// this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey)
878
+			}
879
+
880
+			$success = $model->update($model_object_data_for_update, array($conditions));
881
+			if ($success) {
882
+				$this->_total_updates++;
883
+				EE_Error::add_success(
884
+					sprintf(
885
+						__("Successfully updated %s with csv data %s", "event_espresso"),
886
+						$model->get_this_model_name(),
887
+						implode(",", $model_object_data_for_update)
888
+					)
889
+				);
890
+				// we should still record the mapping even though it was an update
891
+				// because if we were going to insert somethign but it was going to conflict
892
+				// we would have last-minute decided to update. So we'd like to know what we updated
893
+				// and so we record what record ended up being updated using the mapping
894
+				if ($model->has_primary_key_field()) {
895
+					$new_key_for_mapping = $model_object_data[ $model->primary_key_name() ];
896
+				} else {
897
+					// no primary key just a combined key
898
+					$new_key_for_mapping = $model->get_index_primary_key_string($model_object_data);
899
+				}
900
+				$old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping;
901
+			} else {
902
+				$matched_items = $model->get_all(array($conditions));
903
+				if (! $matched_items) {
904
+					// no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck?
905
+					$this->_total_update_errors++;
906
+					EE_Error::add_error(
907
+						sprintf(
908
+							__(
909
+								"Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)",
910
+								"event_espresso"
911
+							),
912
+							$model->get_this_model_name(),
913
+							http_build_query($model_object_data),
914
+							http_build_query($conditions)
915
+						),
916
+						__FILE__,
917
+						__FUNCTION__,
918
+						__LINE__
919
+					);
920
+				} else {
921
+					$this->_total_updates++;
922
+					EE_Error::add_success(
923
+						sprintf(
924
+							__(
925
+								"%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.",
926
+								"event_espresso"
927
+							),
928
+							$model->get_this_model_name(),
929
+							implode(",", $model_object_data)
930
+						)
931
+					);
932
+				}
933
+			}
934
+		} catch (EE_Error $e) {
935
+			$this->_total_update_errors++;
936
+			$basic_message = sprintf(
937
+				__("Could not update %s with the csv data: %s because %s", "event_espresso"),
938
+				$model->get_this_model_name(),
939
+				implode(",", $model_object_data),
940
+				$e->getMessage()
941
+			);
942
+			$debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString();
943
+			EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__);
944
+		}
945
+		return $old_db_to_new_db_mapping;
946
+	}
947
+
948
+	/**
949
+	 * Gets the number of inserts performed since importer was instantiated or reset
950
+	 *
951
+	 * @return int
952
+	 */
953
+	public function get_total_inserts()
954
+	{
955
+		return $this->_total_inserts;
956
+	}
957
+
958
+	/**
959
+	 *  Gets the number of insert errors since importer was instantiated or reset
960
+	 *
961
+	 * @return int
962
+	 */
963
+	public function get_total_insert_errors()
964
+	{
965
+		return $this->_total_insert_errors;
966
+	}
967
+
968
+	/**
969
+	 *  Gets the number of updates performed since importer was instantiated or reset
970
+	 *
971
+	 * @return int
972
+	 */
973
+	public function get_total_updates()
974
+	{
975
+		return $this->_total_updates;
976
+	}
977
+
978
+	/**
979
+	 *  Gets the number of update errors since importer was instantiated or reset
980
+	 *
981
+	 * @return int
982
+	 */
983
+	public function get_total_update_errors()
984
+	{
985
+		return $this->_total_update_errors;
986
+	}
987 987
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     public function import()
136 136
     {
137 137
 
138
-        require_once(EE_CLASSES . 'EE_CSV.class.php');
138
+        require_once(EE_CLASSES.'EE_CSV.class.php');
139 139
         $this->EE_CSV = EE_CSV::instance();
140 140
 
141 141
         if (isset($_REQUEST['import'])) {
@@ -179,18 +179,18 @@  discard block
 block discarded – undo
179 179
                         break;
180 180
                 }
181 181
 
182
-                if (! $error_msg) {
182
+                if ( ! $error_msg) {
183 183
                     $filename = $_FILES['file']['name'][0];
184 184
                     $file_ext = substr(strrchr($filename, '.'), 1);
185 185
                     $file_type = $_FILES['file']['type'][0];
186 186
                     $temp_file = $_FILES['file']['tmp_name'][0];
187
-                    $filesize = $_FILES['file']['size'][0] / 1024;// convert from bytes to KB
187
+                    $filesize = $_FILES['file']['size'][0] / 1024; // convert from bytes to KB
188 188
 
189 189
                     if ($file_ext == 'csv') {
190
-                        $max_upload = $this->EE_CSV->get_max_upload_size();// max upload size in KB
190
+                        $max_upload = $this->EE_CSV->get_max_upload_size(); // max upload size in KB
191 191
                         if ($filesize < $max_upload || true) {
192 192
                             $wp_upload_dir = str_replace(array('\\', '/'), '/', wp_upload_dir());
193
-                            $path_to_file = $wp_upload_dir['basedir'] . '/espresso/' . $filename;
193
+                            $path_to_file = $wp_upload_dir['basedir'].'/espresso/'.$filename;
194 194
 
195 195
                             if (move_uploaded_file($temp_file, $path_to_file)) {
196 196
                                 // convert csv to array
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
         // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name...
325 325
         $old_site_url = 'none-specified';
326 326
         // hanlde metadata
327
-        if (isset($csv_data_array[ EE_CSV::metadata_header ])) {
328
-            $csv_metadata = array_shift($csv_data_array[ EE_CSV::metadata_header ]);
327
+        if (isset($csv_data_array[EE_CSV::metadata_header])) {
328
+            $csv_metadata = array_shift($csv_data_array[EE_CSV::metadata_header]);
329 329
             // ok so its metadata, dont try to save it to ehte db obviously...
330 330
             if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) {
331 331
                 EE_Error::add_attention(
@@ -350,14 +350,14 @@  discard block
 block discarded – undo
350 350
                     )
351 351
                 );
352 352
             };
353
-            unset($csv_data_array[ EE_CSV::metadata_header ]);
353
+            unset($csv_data_array[EE_CSV::metadata_header]);
354 354
         }
355 355
         /**
356 356
          * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and
357 357
          * the value will be the newly-inserted ID.
358 358
          * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option
359 359
          */
360
-        $old_db_to_new_db_mapping = get_option('ee_id_mapping_from' . sanitize_title($old_site_url), array());
360
+        $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url), array());
361 361
         if ($old_db_to_new_db_mapping) {
362 362
             EE_Error::add_attention(
363 363
                 sprintf(
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
         );
378 378
 
379 379
         // save the mapping from old db to new db in case they try re-importing the same data from the same website again
380
-        update_option('ee_id_mapping_from' . sanitize_title($old_site_url), $old_db_to_new_db_mapping);
380
+        update_option('ee_id_mapping_from'.sanitize_title($old_site_url), $old_db_to_new_db_mapping);
381 381
 
382 382
         if ($this->_total_updates > 0) {
383 383
             EE_Error::add_success(
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
                 // find the PK in the row of data (or a combined key if
501 501
                 // there is no primary key)
502 502
                 if ($model->has_primary_key_field()) {
503
-                    $id_in_csv = $model_object_data[ $model->primary_key_name() ];
503
+                    $id_in_csv = $model_object_data[$model->primary_key_name()];
504 504
                 } else {
505 505
                     $id_in_csv = $model->get_index_primary_key_string($model_object_data);
506 506
                 }
@@ -544,14 +544,14 @@  discard block
 block discarded – undo
544 544
                         $what_to_do = self::do_update;
545 545
                         // and if this model has a primary key, remember its mapping
546 546
                         if ($model->has_primary_key_field()) {
547
-                            $old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ] = $conflicting->ID();
548
-                            $model_object_data[ $model->primary_key_name() ] = $conflicting->ID();
547
+                            $old_db_to_new_db_mapping[$model_name][$id_in_csv] = $conflicting->ID();
548
+                            $model_object_data[$model->primary_key_name()] = $conflicting->ID();
549 549
                         } else {
550 550
                             // we want to update this conflicting item, instead of inserting a conflicting item
551 551
                             // so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields
552 552
                             // for the WHERE conditions in the update). At the time of this comment, there were no models like this
553 553
                             foreach ($model->get_combined_primary_key_fields() as $key_field) {
554
-                                $model_object_data[ $key_field->get_name() ] = $conflicting->get(
554
+                                $model_object_data[$key_field->get_name()] = $conflicting->get(
555 555
                                     $key_field->get_name()
556 556
                                 );
557 557
                             }
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
         $model_name = $model->get_this_model_name();
612 612
         // if it's a site-to-site export-and-import, see if this modelobject's id
613 613
         // in the old data that we know of
614
-        if (isset($old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ])) {
614
+        if (isset($old_db_to_new_db_mapping[$model_name][$id_in_csv])) {
615 615
             return self::do_update;
616 616
         } else {
617 617
             return self::do_insert;
@@ -666,12 +666,12 @@  discard block
 block discarded – undo
666 666
         // if this model object's primary key is in the mapping, replace it
667 667
         if ($model->has_primary_key_field() &&
668 668
             $model->get_primary_key_field()->is_auto_increment() &&
669
-            isset($old_db_to_new_db_mapping[ $model->get_this_model_name() ]) &&
669
+            isset($old_db_to_new_db_mapping[$model->get_this_model_name()]) &&
670 670
             isset(
671
-                $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ]
671
+                $old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]]
672 672
             )) {
673
-            $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name(
674
-            ) ][ $model_object_data[ $model->primary_key_name() ] ];
673
+            $model_object_data[$model->primary_key_name()] = $old_db_to_new_db_mapping[$model->get_this_model_name(
674
+            )][$model_object_data[$model->primary_key_name()]];
675 675
         }
676 676
 
677 677
         try {
@@ -687,10 +687,10 @@  discard block
 block discarded – undo
687 687
                 $found_a_mapping = false;
688 688
                 foreach ($models_pointed_to as $model_pointed_to_by_fk) {
689 689
                     if ($model_name_field) {
690
-                        $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ];
690
+                        $value_of_model_name_field = $model_object_data[$model_name_field->get_name()];
691 691
                         if ($value_of_model_name_field == $model_pointed_to_by_fk) {
692
-                            $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
693
-                                $model_object_data[ $field_obj->get_name() ],
692
+                            $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in(
693
+                                $model_object_data[$field_obj->get_name()],
694 694
                                 $model_pointed_to_by_fk,
695 695
                                 $old_db_to_new_db_mapping,
696 696
                                 $export_from_site_a_to_b
@@ -699,8 +699,8 @@  discard block
 block discarded – undo
699 699
                             break;
700 700
                         }
701 701
                     } else {
702
-                        $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
703
-                            $model_object_data[ $field_obj->get_name() ],
702
+                        $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in(
703
+                            $model_object_data[$field_obj->get_name()],
704 704
                             $model_pointed_to_by_fk,
705 705
                             $old_db_to_new_db_mapping,
706 706
                             $export_from_site_a_to_b
@@ -763,8 +763,8 @@  discard block
 block discarded – undo
763 763
      */
764 764
     protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b)
765 765
     {
766
-        if (isset($old_db_to_new_db_mapping[ $model_name ][ $object_id ])) {
767
-            return $old_db_to_new_db_mapping[ $model_name ][ $object_id ];
766
+        if (isset($old_db_to_new_db_mapping[$model_name][$object_id])) {
767
+            return $old_db_to_new_db_mapping[$model_name][$object_id];
768 768
         } elseif ($object_id == '0' || $object_id == '') {
769 769
             // leave as-is
770 770
             return $object_id;
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
             // we couldn't find a mapping for this, and it's from a different site,
773 773
             // so blank it out
774 774
             return null;
775
-        } elseif (! $export_from_site_a_to_b) {
775
+        } elseif ( ! $export_from_site_a_to_b) {
776 776
             // we coudln't find a mapping for this, but it's from thsi DB anyway
777 777
             // so let's just leave it as-is
778 778
             return $object_id;
@@ -792,8 +792,8 @@  discard block
 block discarded – undo
792 792
         // remove the primary key, if there is one (we don't want it for inserts OR updates)
793 793
         // we'll put it back in if we need it
794 794
         if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) {
795
-            $effective_id = $model_object_data[ $model->primary_key_name() ];
796
-            unset($model_object_data[ $model->primary_key_name() ]);
795
+            $effective_id = $model_object_data[$model->primary_key_name()];
796
+            unset($model_object_data[$model->primary_key_name()]);
797 797
         } else {
798 798
             $effective_id = $model->get_index_primary_key_string($model_object_data);
799 799
         }
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
         try {
802 802
             $new_id = $model->insert($model_object_data);
803 803
             if ($new_id) {
804
-                $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_id;
804
+                $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id;
805 805
                 $this->_total_inserts++;
806 806
                 EE_Error::add_success(
807 807
                     sprintf(
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
                 $this->_total_insert_errors++;
816 816
                 // put the ID used back in there for the error message
817 817
                 if ($model->has_primary_key_field()) {
818
-                    $model_object_data[ $model->primary_key_name() ] = $effective_id;
818
+                    $model_object_data[$model->primary_key_name()] = $effective_id;
819 819
                 }
820 820
                 EE_Error::add_error(
821 821
                     sprintf(
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
         } catch (EE_Error $e) {
832 832
             $this->_total_insert_errors++;
833 833
             if ($model->has_primary_key_field()) {
834
-                $model_object_data[ $model->primary_key_name() ] = $effective_id;
834
+                $model_object_data[$model->primary_key_name()] = $effective_id;
835 835
             }
836 836
             EE_Error::add_error(
837 837
                 sprintf(
@@ -864,17 +864,17 @@  discard block
 block discarded – undo
864 864
             // one for performing an update, one for everthing else
865 865
             $model_object_data_for_update = $model_object_data;
866 866
             if ($model->has_primary_key_field()) {
867
-                $conditions = array($model->primary_key_name() => $model_object_data[ $model->primary_key_name() ]);
867
+                $conditions = array($model->primary_key_name() => $model_object_data[$model->primary_key_name()]);
868 868
                 // remove the primary key because we shouldn't use it for updating
869
-                unset($model_object_data_for_update[ $model->primary_key_name() ]);
869
+                unset($model_object_data_for_update[$model->primary_key_name()]);
870 870
             } elseif ($model->get_combined_primary_key_fields() > 1) {
871 871
                 $conditions = array();
872 872
                 foreach ($model->get_combined_primary_key_fields() as $key_field) {
873
-                    $conditions[ $key_field->get_name() ] = $model_object_data[ $key_field->get_name() ];
873
+                    $conditions[$key_field->get_name()] = $model_object_data[$key_field->get_name()];
874 874
                 }
875 875
             } else {
876 876
                 $model->primary_key_name(
877
-                );// this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey)
877
+                ); // this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey)
878 878
             }
879 879
 
880 880
             $success = $model->update($model_object_data_for_update, array($conditions));
@@ -892,15 +892,15 @@  discard block
 block discarded – undo
892 892
                 // we would have last-minute decided to update. So we'd like to know what we updated
893 893
                 // and so we record what record ended up being updated using the mapping
894 894
                 if ($model->has_primary_key_field()) {
895
-                    $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ];
895
+                    $new_key_for_mapping = $model_object_data[$model->primary_key_name()];
896 896
                 } else {
897 897
                     // no primary key just a combined key
898 898
                     $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data);
899 899
                 }
900
-                $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping;
900
+                $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_key_for_mapping;
901 901
             } else {
902 902
                 $matched_items = $model->get_all(array($conditions));
903
-                if (! $matched_items) {
903
+                if ( ! $matched_items) {
904 904
                     // no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck?
905 905
                     $this->_total_update_errors++;
906 906
                     EE_Error::add_error(
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
                 implode(",", $model_object_data),
940 940
                 $e->getMessage()
941 941
             );
942
-            $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString();
942
+            $debug_message = $basic_message.' Stack trace: '.$e->getTraceAsString();
943 943
             EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__);
944 944
         }
945 945
         return $old_db_to_new_db_mapping;
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Addon.lib.php 2 patches
Indentation   +1161 added lines, -1161 removed lines patch added patch discarded remove patch
@@ -22,1225 +22,1225 @@
 block discarded – undo
22 22
 class EE_Register_Addon implements EEI_Plugin_API
23 23
 {
24 24
 
25
-    /**
26
-     * possibly truncated version of the EE core version string
27
-     *
28
-     * @var string
29
-     */
30
-    protected static $_core_version = '';
25
+	/**
26
+	 * possibly truncated version of the EE core version string
27
+	 *
28
+	 * @var string
29
+	 */
30
+	protected static $_core_version = '';
31 31
 
32
-    /**
33
-     * Holds values for registered addons
34
-     *
35
-     * @var array
36
-     */
37
-    protected static $_settings = array();
32
+	/**
33
+	 * Holds values for registered addons
34
+	 *
35
+	 * @var array
36
+	 */
37
+	protected static $_settings = array();
38 38
 
39
-    /**
40
-     * @var  array $_incompatible_addons keys are addon SLUGS
41
-     * (first argument passed to EE_Register_Addon::register()), keys are
42
-     * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
43
-     * Generally this should be used sparingly, as we don't want to muddle up
44
-     * EE core with knowledge of ALL the addons out there.
45
-     * If you want NO versions of an addon to run with a certain version of core,
46
-     * it's usually best to define the addon's "min_core_version" as part of its call
47
-     * to EE_Register_Addon::register(), rather than using this array with a super high value for its
48
-     * minimum plugin version.
49
-     * @access    protected
50
-     */
51
-    protected static $_incompatible_addons = array(
52
-        'Multi_Event_Registration' => '2.0.11.rc.002',
53
-        'Promotions'               => '1.0.0.rc.084',
54
-    );
39
+	/**
40
+	 * @var  array $_incompatible_addons keys are addon SLUGS
41
+	 * (first argument passed to EE_Register_Addon::register()), keys are
42
+	 * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
43
+	 * Generally this should be used sparingly, as we don't want to muddle up
44
+	 * EE core with knowledge of ALL the addons out there.
45
+	 * If you want NO versions of an addon to run with a certain version of core,
46
+	 * it's usually best to define the addon's "min_core_version" as part of its call
47
+	 * to EE_Register_Addon::register(), rather than using this array with a super high value for its
48
+	 * minimum plugin version.
49
+	 * @access    protected
50
+	 */
51
+	protected static $_incompatible_addons = array(
52
+		'Multi_Event_Registration' => '2.0.11.rc.002',
53
+		'Promotions'               => '1.0.0.rc.084',
54
+	);
55 55
 
56 56
 
57
-    /**
58
-     * We should always be comparing core to a version like '4.3.0.rc.000',
59
-     * not just '4.3.0'.
60
-     * So if the addon developer doesn't provide that full version string,
61
-     * fill in the blanks for them
62
-     *
63
-     * @param string $min_core_version
64
-     * @return string always like '4.3.0.rc.000'
65
-     */
66
-    protected static function _effective_version($min_core_version)
67
-    {
68
-        // versions: 4 . 3 . 1 . p . 123
69
-        // offsets:    0 . 1 . 2 . 3 . 4
70
-        $version_parts = explode('.', $min_core_version);
71
-        // check they specified the micro version (after 2nd period)
72
-        if (! isset($version_parts[2])) {
73
-            $version_parts[2] = '0';
74
-        }
75
-        // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
76
-        // soon we can assume that's 'rc', but this current version is 'alpha'
77
-        if (! isset($version_parts[3])) {
78
-            $version_parts[3] = 'dev';
79
-        }
80
-        if (! isset($version_parts[4])) {
81
-            $version_parts[4] = '000';
82
-        }
83
-        return implode('.', $version_parts);
84
-    }
57
+	/**
58
+	 * We should always be comparing core to a version like '4.3.0.rc.000',
59
+	 * not just '4.3.0'.
60
+	 * So if the addon developer doesn't provide that full version string,
61
+	 * fill in the blanks for them
62
+	 *
63
+	 * @param string $min_core_version
64
+	 * @return string always like '4.3.0.rc.000'
65
+	 */
66
+	protected static function _effective_version($min_core_version)
67
+	{
68
+		// versions: 4 . 3 . 1 . p . 123
69
+		// offsets:    0 . 1 . 2 . 3 . 4
70
+		$version_parts = explode('.', $min_core_version);
71
+		// check they specified the micro version (after 2nd period)
72
+		if (! isset($version_parts[2])) {
73
+			$version_parts[2] = '0';
74
+		}
75
+		// if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
76
+		// soon we can assume that's 'rc', but this current version is 'alpha'
77
+		if (! isset($version_parts[3])) {
78
+			$version_parts[3] = 'dev';
79
+		}
80
+		if (! isset($version_parts[4])) {
81
+			$version_parts[4] = '000';
82
+		}
83
+		return implode('.', $version_parts);
84
+	}
85 85
 
86 86
 
87
-    /**
88
-     * Returns whether or not the min core version requirement of the addon is met
89
-     *
90
-     * @param string $min_core_version    the minimum core version required by the addon
91
-     * @param string $actual_core_version the actual core version, optional
92
-     * @return boolean
93
-     */
94
-    public static function _meets_min_core_version_requirement(
95
-        $min_core_version,
96
-        $actual_core_version = EVENT_ESPRESSO_VERSION
97
-    ) {
98
-        return version_compare(
99
-            self::_effective_version($actual_core_version),
100
-            self::_effective_version($min_core_version),
101
-            '>='
102
-        );
103
-    }
87
+	/**
88
+	 * Returns whether or not the min core version requirement of the addon is met
89
+	 *
90
+	 * @param string $min_core_version    the minimum core version required by the addon
91
+	 * @param string $actual_core_version the actual core version, optional
92
+	 * @return boolean
93
+	 */
94
+	public static function _meets_min_core_version_requirement(
95
+		$min_core_version,
96
+		$actual_core_version = EVENT_ESPRESSO_VERSION
97
+	) {
98
+		return version_compare(
99
+			self::_effective_version($actual_core_version),
100
+			self::_effective_version($min_core_version),
101
+			'>='
102
+		);
103
+	}
104 104
 
105 105
 
106
-    /**
107
-     * Method for registering new EE_Addons.
108
-     * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
109
-     * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
110
-     * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
111
-     * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
112
-     * 'activate_plugin', it registers the addon still, but its components are not registered
113
-     * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
114
-     * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
115
-     * (so that we can detect that the addon has activated on the subsequent request)
116
-     *
117
-     * @since    4.3.0
118
-     * @param string                  $addon_name                       [Required] the EE_Addon's name.
119
-     * @param  array                  $setup_args                       {
120
-     *                                                                  An array of arguments provided for registering
121
-     *                                                                  the message type.
122
-     * @type  string                  $class_name                       the addon's main file name.
123
-     *                                                                  If left blank, generated from the addon name,
124
-     *                                                                  changes something like "calendar" to
125
-     *                                                                  "EE_Calendar"
126
-     * @type string                   $min_core_version                 the minimum version of EE Core that the
127
-     *                                                                  addon will work with. eg "4.8.1.rc.084"
128
-     * @type string                   $version                          the "software" version for the addon. eg
129
-     *                                                                  "1.0.0.p" for a first stable release, or
130
-     *                                                                  "1.0.0.rc.043" for a version in progress
131
-     * @type string                   $main_file_path                   the full server path to the main file
132
-     *                                                                  loaded directly by WP
133
-     * @type DomainInterface $domain                                    child class of
134
-     *                                                                  EventEspresso\core\domain\DomainBase
135
-     * @type string                   $domain_fqcn                      Fully Qualified Class Name
136
-     *                                                                  for the addon's Domain class
137
-     *                                                                  (see EventEspresso\core\domain\Domain)
138
-     * @type string                   $admin_path                       full server path to the folder where the
139
-     *                                                                  addon\'s admin files reside
140
-     * @type string                   $admin_callback                   a method to be called when the EE Admin is
141
-     *                                                                  first invoked, can be used for hooking into
142
-     *                                                                  any admin page
143
-     * @type string                   $config_section                   the section name for this addon's
144
-     *                                                                  configuration settings section
145
-     *                                                                  (defaults to "addons")
146
-     * @type string                   $config_class                     the class name for this addon's
147
-     *                                                                  configuration settings object
148
-     * @type string                   $config_name                      the class name for this addon's
149
-     *                                                                  configuration settings object
150
-     * @type string                   $autoloader_paths                 [Required] an array of class names and the full
151
-     *                                                                  server paths to those files.
152
-     * @type string                   $autoloader_folders               an array of  "full server paths" for any
153
-     *                                                                  folders containing classes that might be
154
-     *                                                                  invoked by the addon
155
-     * @type string                   $dms_paths                        [Required] an array of full server paths to
156
-     *                                                                  folders that contain data migration scripts.
157
-     *                                                                  The key should be the EE_Addon class name that
158
-     *                                                                  this set of data migration scripts belongs to.
159
-     *                                                                  If the EE_Addon class is namespaced, then this
160
-     *                                                                  needs to be the Fully Qualified Class Name
161
-     * @type string                   $module_paths                     an array of full server paths to any
162
-     *                                                                  EED_Modules used by the addon
163
-     * @type string                   $shortcode_paths                  an array of full server paths to folders
164
-     *                                                                  that contain EES_Shortcodes
165
-     * @type string                   $widget_paths                     an array of full server paths to folders
166
-     *                                                                  that contain WP_Widgets
167
-     * @type string                   $pue_options
168
-     * @type array                    $capabilities                     an array indexed by role name
169
-     *                                                                  (i.e administrator,author ) and the values
170
-     *                                                                  are an array of caps to add to the role.
171
-     *                                                                  'administrator' => array(
172
-     *                                                                  'read_addon',
173
-     *                                                                  'edit_addon',
174
-     *                                                                  etc.
175
-     *                                                                  ).
176
-     * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
177
-     *                                                                  for any addons that need to register any
178
-     *                                                                  special meta mapped capabilities.  Should
179
-     *                                                                  be indexed where the key is the
180
-     *                                                                  EE_Meta_Capability_Map class name and the
181
-     *                                                                  values are the arguments sent to the class.
182
-     * @type array                    $model_paths                      array of folders containing DB models
183
-     * @see      EE_Register_Model
184
-     * @type array                    $class_paths                      array of folders containing DB classes
185
-     * @see      EE_Register_Model
186
-     * @type array                    $model_extension_paths            array of folders containing DB model
187
-     *                                                                  extensions
188
-     * @see      EE_Register_Model_Extension
189
-     * @type array                    $class_extension_paths            array of folders containing DB class
190
-     *                                                                  extensions
191
-     * @see      EE_Register_Model_Extension
192
-     * @type array message_types {
193
-     *                                                                  An array of message types with the key as
194
-     *                                                                  the message type name and the values as
195
-     *                                                                  below:
196
-     * @type string                   $mtfilename                       [Required] The filename of the message type
197
-     *                                                                  being registered. This will be the main
198
-     *                                                                  EE_{Message Type Name}_message_type class.
199
-     *                                                                  for example:
200
-     *                                                                  EE_Declined_Registration_message_type.class.php
201
-     * @type array                    $autoloadpaths                    [Required] An array of paths to add to the
202
-     *                                                                  messages autoloader for the new message type.
203
-     * @type array                    $messengers_to_activate_with      An array of messengers that this message
204
-     *                                                                  type should activate with. Each value in
205
-     *                                                                  the
206
-     *                                                                  array
207
-     *                                                                  should match the name property of a
208
-     *                                                                  EE_messenger. Optional.
209
-     * @type array                    $messengers_to_validate_with      An array of messengers that this message
210
-     *                                                                  type should validate with. Each value in
211
-     *                                                                  the
212
-     *                                                                  array
213
-     *                                                                  should match the name property of an
214
-     *                                                                  EE_messenger.
215
-     *                                                                  Optional.
216
-     *                                                                  }
217
-     * @type array                    $custom_post_types
218
-     * @type array                    $custom_taxonomies
219
-     * @type array                    $payment_method_paths             each element is the folder containing the
220
-     *                                                                  EE_PMT_Base child class
221
-     *                                                                  (eg,
222
-     *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
223
-     *                                                                  which contains the files
224
-     *                                                                  EE_PMT_Payomatic.pm.php)
225
-     * @type array                    $default_terms
226
-     * @type array                    $namespace                        {
227
-     *                                                                  An array with two items for registering the
228
-     *                                                                  addon's namespace. (If, for some reason, you
229
-     *                                                                  require additional namespaces,
230
-     *                                                                  use
231
-     *                                                                  EventEspresso\core\Psr4Autoloader::addNamespace()
232
-     *                                                                  directly)
233
-     * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
234
-     * @type string                   $FQNS                             the namespace prefix
235
-     * @type string                   $DIR                              a base directory for class files in the
236
-     *                                                                  namespace.
237
-     *                                                                  }
238
-     *                                                                  }
239
-     * @type string                   $privacy_policies                 FQNSs (namespaces, each of which contains only
240
-     *                                                                  privacy policy classes) or FQCNs (specific
241
-     *                                                                  classnames of privacy policy classes)
242
-     * @type string                   $personal_data_exporters          FQNSs (namespaces, each of which contains only
243
-     *                                                                  privacy policy classes) or FQCNs (specific
244
-     *                                                                  classnames of privacy policy classes)
245
-     * @type string                   $personal_data_erasers            FQNSs (namespaces, each of which contains only
246
-     *                                                                  privacy policy classes) or FQCNs (specific
247
-     *                                                                  classnames of privacy policy classes)
248
-     * @return void
249
-     * @throws DomainException
250
-     * @throws EE_Error
251
-     * @throws InvalidArgumentException
252
-     * @throws ReflectionException
253
-     * @throws InvalidDataTypeException
254
-     * @throws InvalidInterfaceException
255
-     */
256
-    public static function register($addon_name = '', $setup_args = array())
257
-    {
258
-        // required fields MUST be present, so let's make sure they are.
259
-        EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
260
-        // get class name for addon
261
-        $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
262
-        // setup $_settings array from incoming values.
263
-        $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
264
-        // setup PUE
265
-        EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
266
-        // does this addon work with this version of core or WordPress ?
267
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
268
-            return;
269
-        }
270
-        // register namespaces
271
-        EE_Register_Addon::_setup_namespaces($addon_settings);
272
-        // check if this is an activation request
273
-        if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
274
-            // dont bother setting up the rest of the addon atm
275
-            return;
276
-        }
277
-        // we need cars
278
-        EE_Register_Addon::_setup_autoloaders($addon_name);
279
-        // register new models and extensions
280
-        EE_Register_Addon::_register_models_and_extensions($addon_name);
281
-        // setup DMS
282
-        EE_Register_Addon::_register_data_migration_scripts($addon_name);
283
-        // if config_class is present let's register config.
284
-        EE_Register_Addon::_register_config($addon_name);
285
-        // register admin pages
286
-        EE_Register_Addon::_register_admin_pages($addon_name);
287
-        // add to list of modules to be registered
288
-        EE_Register_Addon::_register_modules($addon_name);
289
-        // add to list of shortcodes to be registered
290
-        EE_Register_Addon::_register_shortcodes($addon_name);
291
-        // add to list of widgets to be registered
292
-        EE_Register_Addon::_register_widgets($addon_name);
293
-        // register capability related stuff.
294
-        EE_Register_Addon::_register_capabilities($addon_name);
295
-        // any message type to register?
296
-        EE_Register_Addon::_register_message_types($addon_name);
297
-        // any custom post type/ custom capabilities or default terms to register
298
-        EE_Register_Addon::_register_custom_post_types($addon_name);
299
-        // and any payment methods
300
-        EE_Register_Addon::_register_payment_methods($addon_name);
301
-        // and privacy policy generators
302
-        EE_Register_Addon::registerPrivacyPolicies($addon_name);
303
-        // and privacy policy generators
304
-        EE_Register_Addon::registerPersonalDataExporters($addon_name);
305
-        // and privacy policy generators
306
-        EE_Register_Addon::registerPersonalDataErasers($addon_name);
307
-        // load and instantiate main addon class
308
-        $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
309
-        // delay calling after_registration hook on each addon until after all add-ons have been registered.
310
-        add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999);
311
-    }
106
+	/**
107
+	 * Method for registering new EE_Addons.
108
+	 * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
109
+	 * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
110
+	 * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
111
+	 * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
112
+	 * 'activate_plugin', it registers the addon still, but its components are not registered
113
+	 * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
114
+	 * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
115
+	 * (so that we can detect that the addon has activated on the subsequent request)
116
+	 *
117
+	 * @since    4.3.0
118
+	 * @param string                  $addon_name                       [Required] the EE_Addon's name.
119
+	 * @param  array                  $setup_args                       {
120
+	 *                                                                  An array of arguments provided for registering
121
+	 *                                                                  the message type.
122
+	 * @type  string                  $class_name                       the addon's main file name.
123
+	 *                                                                  If left blank, generated from the addon name,
124
+	 *                                                                  changes something like "calendar" to
125
+	 *                                                                  "EE_Calendar"
126
+	 * @type string                   $min_core_version                 the minimum version of EE Core that the
127
+	 *                                                                  addon will work with. eg "4.8.1.rc.084"
128
+	 * @type string                   $version                          the "software" version for the addon. eg
129
+	 *                                                                  "1.0.0.p" for a first stable release, or
130
+	 *                                                                  "1.0.0.rc.043" for a version in progress
131
+	 * @type string                   $main_file_path                   the full server path to the main file
132
+	 *                                                                  loaded directly by WP
133
+	 * @type DomainInterface $domain                                    child class of
134
+	 *                                                                  EventEspresso\core\domain\DomainBase
135
+	 * @type string                   $domain_fqcn                      Fully Qualified Class Name
136
+	 *                                                                  for the addon's Domain class
137
+	 *                                                                  (see EventEspresso\core\domain\Domain)
138
+	 * @type string                   $admin_path                       full server path to the folder where the
139
+	 *                                                                  addon\'s admin files reside
140
+	 * @type string                   $admin_callback                   a method to be called when the EE Admin is
141
+	 *                                                                  first invoked, can be used for hooking into
142
+	 *                                                                  any admin page
143
+	 * @type string                   $config_section                   the section name for this addon's
144
+	 *                                                                  configuration settings section
145
+	 *                                                                  (defaults to "addons")
146
+	 * @type string                   $config_class                     the class name for this addon's
147
+	 *                                                                  configuration settings object
148
+	 * @type string                   $config_name                      the class name for this addon's
149
+	 *                                                                  configuration settings object
150
+	 * @type string                   $autoloader_paths                 [Required] an array of class names and the full
151
+	 *                                                                  server paths to those files.
152
+	 * @type string                   $autoloader_folders               an array of  "full server paths" for any
153
+	 *                                                                  folders containing classes that might be
154
+	 *                                                                  invoked by the addon
155
+	 * @type string                   $dms_paths                        [Required] an array of full server paths to
156
+	 *                                                                  folders that contain data migration scripts.
157
+	 *                                                                  The key should be the EE_Addon class name that
158
+	 *                                                                  this set of data migration scripts belongs to.
159
+	 *                                                                  If the EE_Addon class is namespaced, then this
160
+	 *                                                                  needs to be the Fully Qualified Class Name
161
+	 * @type string                   $module_paths                     an array of full server paths to any
162
+	 *                                                                  EED_Modules used by the addon
163
+	 * @type string                   $shortcode_paths                  an array of full server paths to folders
164
+	 *                                                                  that contain EES_Shortcodes
165
+	 * @type string                   $widget_paths                     an array of full server paths to folders
166
+	 *                                                                  that contain WP_Widgets
167
+	 * @type string                   $pue_options
168
+	 * @type array                    $capabilities                     an array indexed by role name
169
+	 *                                                                  (i.e administrator,author ) and the values
170
+	 *                                                                  are an array of caps to add to the role.
171
+	 *                                                                  'administrator' => array(
172
+	 *                                                                  'read_addon',
173
+	 *                                                                  'edit_addon',
174
+	 *                                                                  etc.
175
+	 *                                                                  ).
176
+	 * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
177
+	 *                                                                  for any addons that need to register any
178
+	 *                                                                  special meta mapped capabilities.  Should
179
+	 *                                                                  be indexed where the key is the
180
+	 *                                                                  EE_Meta_Capability_Map class name and the
181
+	 *                                                                  values are the arguments sent to the class.
182
+	 * @type array                    $model_paths                      array of folders containing DB models
183
+	 * @see      EE_Register_Model
184
+	 * @type array                    $class_paths                      array of folders containing DB classes
185
+	 * @see      EE_Register_Model
186
+	 * @type array                    $model_extension_paths            array of folders containing DB model
187
+	 *                                                                  extensions
188
+	 * @see      EE_Register_Model_Extension
189
+	 * @type array                    $class_extension_paths            array of folders containing DB class
190
+	 *                                                                  extensions
191
+	 * @see      EE_Register_Model_Extension
192
+	 * @type array message_types {
193
+	 *                                                                  An array of message types with the key as
194
+	 *                                                                  the message type name and the values as
195
+	 *                                                                  below:
196
+	 * @type string                   $mtfilename                       [Required] The filename of the message type
197
+	 *                                                                  being registered. This will be the main
198
+	 *                                                                  EE_{Message Type Name}_message_type class.
199
+	 *                                                                  for example:
200
+	 *                                                                  EE_Declined_Registration_message_type.class.php
201
+	 * @type array                    $autoloadpaths                    [Required] An array of paths to add to the
202
+	 *                                                                  messages autoloader for the new message type.
203
+	 * @type array                    $messengers_to_activate_with      An array of messengers that this message
204
+	 *                                                                  type should activate with. Each value in
205
+	 *                                                                  the
206
+	 *                                                                  array
207
+	 *                                                                  should match the name property of a
208
+	 *                                                                  EE_messenger. Optional.
209
+	 * @type array                    $messengers_to_validate_with      An array of messengers that this message
210
+	 *                                                                  type should validate with. Each value in
211
+	 *                                                                  the
212
+	 *                                                                  array
213
+	 *                                                                  should match the name property of an
214
+	 *                                                                  EE_messenger.
215
+	 *                                                                  Optional.
216
+	 *                                                                  }
217
+	 * @type array                    $custom_post_types
218
+	 * @type array                    $custom_taxonomies
219
+	 * @type array                    $payment_method_paths             each element is the folder containing the
220
+	 *                                                                  EE_PMT_Base child class
221
+	 *                                                                  (eg,
222
+	 *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
223
+	 *                                                                  which contains the files
224
+	 *                                                                  EE_PMT_Payomatic.pm.php)
225
+	 * @type array                    $default_terms
226
+	 * @type array                    $namespace                        {
227
+	 *                                                                  An array with two items for registering the
228
+	 *                                                                  addon's namespace. (If, for some reason, you
229
+	 *                                                                  require additional namespaces,
230
+	 *                                                                  use
231
+	 *                                                                  EventEspresso\core\Psr4Autoloader::addNamespace()
232
+	 *                                                                  directly)
233
+	 * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
234
+	 * @type string                   $FQNS                             the namespace prefix
235
+	 * @type string                   $DIR                              a base directory for class files in the
236
+	 *                                                                  namespace.
237
+	 *                                                                  }
238
+	 *                                                                  }
239
+	 * @type string                   $privacy_policies                 FQNSs (namespaces, each of which contains only
240
+	 *                                                                  privacy policy classes) or FQCNs (specific
241
+	 *                                                                  classnames of privacy policy classes)
242
+	 * @type string                   $personal_data_exporters          FQNSs (namespaces, each of which contains only
243
+	 *                                                                  privacy policy classes) or FQCNs (specific
244
+	 *                                                                  classnames of privacy policy classes)
245
+	 * @type string                   $personal_data_erasers            FQNSs (namespaces, each of which contains only
246
+	 *                                                                  privacy policy classes) or FQCNs (specific
247
+	 *                                                                  classnames of privacy policy classes)
248
+	 * @return void
249
+	 * @throws DomainException
250
+	 * @throws EE_Error
251
+	 * @throws InvalidArgumentException
252
+	 * @throws ReflectionException
253
+	 * @throws InvalidDataTypeException
254
+	 * @throws InvalidInterfaceException
255
+	 */
256
+	public static function register($addon_name = '', $setup_args = array())
257
+	{
258
+		// required fields MUST be present, so let's make sure they are.
259
+		EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
260
+		// get class name for addon
261
+		$class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
262
+		// setup $_settings array from incoming values.
263
+		$addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
264
+		// setup PUE
265
+		EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
266
+		// does this addon work with this version of core or WordPress ?
267
+		if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
268
+			return;
269
+		}
270
+		// register namespaces
271
+		EE_Register_Addon::_setup_namespaces($addon_settings);
272
+		// check if this is an activation request
273
+		if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
274
+			// dont bother setting up the rest of the addon atm
275
+			return;
276
+		}
277
+		// we need cars
278
+		EE_Register_Addon::_setup_autoloaders($addon_name);
279
+		// register new models and extensions
280
+		EE_Register_Addon::_register_models_and_extensions($addon_name);
281
+		// setup DMS
282
+		EE_Register_Addon::_register_data_migration_scripts($addon_name);
283
+		// if config_class is present let's register config.
284
+		EE_Register_Addon::_register_config($addon_name);
285
+		// register admin pages
286
+		EE_Register_Addon::_register_admin_pages($addon_name);
287
+		// add to list of modules to be registered
288
+		EE_Register_Addon::_register_modules($addon_name);
289
+		// add to list of shortcodes to be registered
290
+		EE_Register_Addon::_register_shortcodes($addon_name);
291
+		// add to list of widgets to be registered
292
+		EE_Register_Addon::_register_widgets($addon_name);
293
+		// register capability related stuff.
294
+		EE_Register_Addon::_register_capabilities($addon_name);
295
+		// any message type to register?
296
+		EE_Register_Addon::_register_message_types($addon_name);
297
+		// any custom post type/ custom capabilities or default terms to register
298
+		EE_Register_Addon::_register_custom_post_types($addon_name);
299
+		// and any payment methods
300
+		EE_Register_Addon::_register_payment_methods($addon_name);
301
+		// and privacy policy generators
302
+		EE_Register_Addon::registerPrivacyPolicies($addon_name);
303
+		// and privacy policy generators
304
+		EE_Register_Addon::registerPersonalDataExporters($addon_name);
305
+		// and privacy policy generators
306
+		EE_Register_Addon::registerPersonalDataErasers($addon_name);
307
+		// load and instantiate main addon class
308
+		$addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
309
+		// delay calling after_registration hook on each addon until after all add-ons have been registered.
310
+		add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999);
311
+	}
312 312
 
313 313
 
314
-    /**
315
-     * @param string $addon_name
316
-     * @param array  $setup_args
317
-     * @return void
318
-     * @throws EE_Error
319
-     */
320
-    private static function _verify_parameters($addon_name, array $setup_args)
321
-    {
322
-        // required fields MUST be present, so let's make sure they are.
323
-        if (empty($addon_name) || ! is_array($setup_args)) {
324
-            throw new EE_Error(
325
-                __(
326
-                    'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
327
-                    'event_espresso'
328
-                )
329
-            );
330
-        }
331
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
332
-            throw new EE_Error(
333
-                sprintf(
334
-                    __(
335
-                        'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
336
-                        'event_espresso'
337
-                    ),
338
-                    implode(',', array_keys($setup_args))
339
-                )
340
-            );
341
-        }
342
-        // check that addon has not already been registered with that name
343
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
344
-            throw new EE_Error(
345
-                sprintf(
346
-                    __(
347
-                        'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
348
-                        'event_espresso'
349
-                    ),
350
-                    $addon_name
351
-                )
352
-            );
353
-        }
354
-    }
314
+	/**
315
+	 * @param string $addon_name
316
+	 * @param array  $setup_args
317
+	 * @return void
318
+	 * @throws EE_Error
319
+	 */
320
+	private static function _verify_parameters($addon_name, array $setup_args)
321
+	{
322
+		// required fields MUST be present, so let's make sure they are.
323
+		if (empty($addon_name) || ! is_array($setup_args)) {
324
+			throw new EE_Error(
325
+				__(
326
+					'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
327
+					'event_espresso'
328
+				)
329
+			);
330
+		}
331
+		if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
332
+			throw new EE_Error(
333
+				sprintf(
334
+					__(
335
+						'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
336
+						'event_espresso'
337
+					),
338
+					implode(',', array_keys($setup_args))
339
+				)
340
+			);
341
+		}
342
+		// check that addon has not already been registered with that name
343
+		if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
344
+			throw new EE_Error(
345
+				sprintf(
346
+					__(
347
+						'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
348
+						'event_espresso'
349
+					),
350
+					$addon_name
351
+				)
352
+			);
353
+		}
354
+	}
355 355
 
356 356
 
357
-    /**
358
-     * @param string $addon_name
359
-     * @param array  $setup_args
360
-     * @return string
361
-     */
362
-    private static function _parse_class_name($addon_name, array $setup_args)
363
-    {
364
-        if (empty($setup_args['class_name'])) {
365
-            // generate one by first separating name with spaces
366
-            $class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
367
-            // capitalize, then replace spaces with underscores
368
-            $class_name = str_replace(' ', '_', ucwords($class_name));
369
-        } else {
370
-            $class_name = $setup_args['class_name'];
371
-        }
372
-        // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
373
-        return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
374
-            ? $class_name
375
-            : 'EE_' . $class_name;
376
-    }
357
+	/**
358
+	 * @param string $addon_name
359
+	 * @param array  $setup_args
360
+	 * @return string
361
+	 */
362
+	private static function _parse_class_name($addon_name, array $setup_args)
363
+	{
364
+		if (empty($setup_args['class_name'])) {
365
+			// generate one by first separating name with spaces
366
+			$class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
367
+			// capitalize, then replace spaces with underscores
368
+			$class_name = str_replace(' ', '_', ucwords($class_name));
369
+		} else {
370
+			$class_name = $setup_args['class_name'];
371
+		}
372
+		// check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
373
+		return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
374
+			? $class_name
375
+			: 'EE_' . $class_name;
376
+	}
377 377
 
378 378
 
379
-    /**
380
-     * @param string $class_name
381
-     * @param array  $setup_args
382
-     * @return array
383
-     */
384
-    private static function _get_addon_settings($class_name, array $setup_args)
385
-    {
386
-        // setup $_settings array from incoming values.
387
-        $addon_settings = array(
388
-            // generated from the addon name, changes something like "calendar" to "EE_Calendar"
389
-            'class_name'            => $class_name,
390
-            // the addon slug for use in URLs, etc
391
-            'plugin_slug'           => isset($setup_args['plugin_slug'])
392
-                ? (string) $setup_args['plugin_slug']
393
-                : '',
394
-            // page slug to be used when generating the "Settings" link on the WP plugin page
395
-            'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
396
-                ? (string) $setup_args['plugin_action_slug']
397
-                : '',
398
-            // the "software" version for the addon
399
-            'version'               => isset($setup_args['version'])
400
-                ? (string) $setup_args['version']
401
-                : '',
402
-            // the minimum version of EE Core that the addon will work with
403
-            'min_core_version'      => isset($setup_args['min_core_version'])
404
-                ? (string) $setup_args['min_core_version']
405
-                : '',
406
-            // the minimum version of WordPress that the addon will work with
407
-            'min_wp_version'        => isset($setup_args['min_wp_version'])
408
-                ? (string) $setup_args['min_wp_version']
409
-                : EE_MIN_WP_VER_REQUIRED,
410
-            // full server path to main file (file loaded directly by WP)
411
-            'main_file_path'        => isset($setup_args['main_file_path'])
412
-                ? (string) $setup_args['main_file_path']
413
-                : '',
414
-            // instance of \EventEspresso\core\domain\DomainInterface
415
-            'domain'                => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface
416
-                ? $setup_args['domain']
417
-                : null,
418
-            // Fully Qualified Class Name for the addon's Domain class
419
-            'domain_fqcn'           => isset($setup_args['domain_fqcn'])
420
-                ? (string) $setup_args['domain_fqcn']
421
-                : '',
422
-            // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
423
-            'admin_path'            => isset($setup_args['admin_path'])
424
-                ? (string) $setup_args['admin_path'] : '',
425
-            // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
426
-            'admin_callback'        => isset($setup_args['admin_callback'])
427
-                ? (string) $setup_args['admin_callback']
428
-                : '',
429
-            // the section name for this addon's configuration settings section (defaults to "addons")
430
-            'config_section'        => isset($setup_args['config_section'])
431
-                ? (string) $setup_args['config_section']
432
-                : 'addons',
433
-            // the class name for this addon's configuration settings object
434
-            'config_class'          => isset($setup_args['config_class'])
435
-                ? (string) $setup_args['config_class'] : '',
436
-            // the name given to the config for this addons' configuration settings object (optional)
437
-            'config_name'           => isset($setup_args['config_name'])
438
-                ? (string) $setup_args['config_name'] : '',
439
-            // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
440
-            'autoloader_paths'      => isset($setup_args['autoloader_paths'])
441
-                ? (array) $setup_args['autoloader_paths']
442
-                : array(),
443
-            // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
444
-            'autoloader_folders'    => isset($setup_args['autoloader_folders'])
445
-                ? (array) $setup_args['autoloader_folders']
446
-                : array(),
447
-            // array of full server paths to any EE_DMS data migration scripts used by the addon.
448
-            // The key should be the EE_Addon class name that this set of data migration scripts belongs to.
449
-            // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
450
-            'dms_paths'             => isset($setup_args['dms_paths'])
451
-                ? (array) $setup_args['dms_paths']
452
-                : array(),
453
-            // array of full server paths to any EED_Modules used by the addon
454
-            'module_paths'          => isset($setup_args['module_paths'])
455
-                ? (array) $setup_args['module_paths']
456
-                : array(),
457
-            // array of full server paths to any EES_Shortcodes used by the addon
458
-            'shortcode_paths'       => isset($setup_args['shortcode_paths'])
459
-                ? (array) $setup_args['shortcode_paths']
460
-                : array(),
461
-            'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
462
-                ? (array) $setup_args['shortcode_fqcns']
463
-                : array(),
464
-            // array of full server paths to any WP_Widgets used by the addon
465
-            'widget_paths'          => isset($setup_args['widget_paths'])
466
-                ? (array) $setup_args['widget_paths']
467
-                : array(),
468
-            // array of PUE options used by the addon
469
-            'pue_options'           => isset($setup_args['pue_options'])
470
-                ? (array) $setup_args['pue_options']
471
-                : array(),
472
-            'message_types'         => isset($setup_args['message_types'])
473
-                ? (array) $setup_args['message_types']
474
-                : array(),
475
-            'capabilities'          => isset($setup_args['capabilities'])
476
-                ? (array) $setup_args['capabilities']
477
-                : array(),
478
-            'capability_maps'       => isset($setup_args['capability_maps'])
479
-                ? (array) $setup_args['capability_maps']
480
-                : array(),
481
-            'model_paths'           => isset($setup_args['model_paths'])
482
-                ? (array) $setup_args['model_paths']
483
-                : array(),
484
-            'class_paths'           => isset($setup_args['class_paths'])
485
-                ? (array) $setup_args['class_paths']
486
-                : array(),
487
-            'model_extension_paths' => isset($setup_args['model_extension_paths'])
488
-                ? (array) $setup_args['model_extension_paths']
489
-                : array(),
490
-            'class_extension_paths' => isset($setup_args['class_extension_paths'])
491
-                ? (array) $setup_args['class_extension_paths']
492
-                : array(),
493
-            'custom_post_types'     => isset($setup_args['custom_post_types'])
494
-                ? (array) $setup_args['custom_post_types']
495
-                : array(),
496
-            'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
497
-                ? (array) $setup_args['custom_taxonomies']
498
-                : array(),
499
-            'payment_method_paths'  => isset($setup_args['payment_method_paths'])
500
-                ? (array) $setup_args['payment_method_paths']
501
-                : array(),
502
-            'default_terms'         => isset($setup_args['default_terms'])
503
-                ? (array) $setup_args['default_terms']
504
-                : array(),
505
-            // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
506
-            // that can be used for adding upgrading/marketing info
507
-            'plugins_page_row'      => isset($setup_args['plugins_page_row'])
508
-                ? $setup_args['plugins_page_row']
509
-                : '',
510
-            'namespace'             => isset(
511
-                $setup_args['namespace']['FQNS'],
512
-                $setup_args['namespace']['DIR']
513
-            )
514
-                ? (array) $setup_args['namespace']
515
-                : array(),
516
-            'privacy_policies'      => isset($setup_args['privacy_policies'])
517
-                ? (array) $setup_args['privacy_policies']
518
-                : '',
519
-        );
520
-        // if plugin_action_slug is NOT set, but an admin page path IS set,
521
-        // then let's just use the plugin_slug since that will be used for linking to the admin page
522
-        $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
523
-                                                && ! empty($addon_settings['admin_path'])
524
-            ? $addon_settings['plugin_slug']
525
-            : $addon_settings['plugin_action_slug'];
526
-        // full server path to main file (file loaded directly by WP)
527
-        $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
528
-        return $addon_settings;
529
-    }
379
+	/**
380
+	 * @param string $class_name
381
+	 * @param array  $setup_args
382
+	 * @return array
383
+	 */
384
+	private static function _get_addon_settings($class_name, array $setup_args)
385
+	{
386
+		// setup $_settings array from incoming values.
387
+		$addon_settings = array(
388
+			// generated from the addon name, changes something like "calendar" to "EE_Calendar"
389
+			'class_name'            => $class_name,
390
+			// the addon slug for use in URLs, etc
391
+			'plugin_slug'           => isset($setup_args['plugin_slug'])
392
+				? (string) $setup_args['plugin_slug']
393
+				: '',
394
+			// page slug to be used when generating the "Settings" link on the WP plugin page
395
+			'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
396
+				? (string) $setup_args['plugin_action_slug']
397
+				: '',
398
+			// the "software" version for the addon
399
+			'version'               => isset($setup_args['version'])
400
+				? (string) $setup_args['version']
401
+				: '',
402
+			// the minimum version of EE Core that the addon will work with
403
+			'min_core_version'      => isset($setup_args['min_core_version'])
404
+				? (string) $setup_args['min_core_version']
405
+				: '',
406
+			// the minimum version of WordPress that the addon will work with
407
+			'min_wp_version'        => isset($setup_args['min_wp_version'])
408
+				? (string) $setup_args['min_wp_version']
409
+				: EE_MIN_WP_VER_REQUIRED,
410
+			// full server path to main file (file loaded directly by WP)
411
+			'main_file_path'        => isset($setup_args['main_file_path'])
412
+				? (string) $setup_args['main_file_path']
413
+				: '',
414
+			// instance of \EventEspresso\core\domain\DomainInterface
415
+			'domain'                => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface
416
+				? $setup_args['domain']
417
+				: null,
418
+			// Fully Qualified Class Name for the addon's Domain class
419
+			'domain_fqcn'           => isset($setup_args['domain_fqcn'])
420
+				? (string) $setup_args['domain_fqcn']
421
+				: '',
422
+			// path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
423
+			'admin_path'            => isset($setup_args['admin_path'])
424
+				? (string) $setup_args['admin_path'] : '',
425
+			// a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
426
+			'admin_callback'        => isset($setup_args['admin_callback'])
427
+				? (string) $setup_args['admin_callback']
428
+				: '',
429
+			// the section name for this addon's configuration settings section (defaults to "addons")
430
+			'config_section'        => isset($setup_args['config_section'])
431
+				? (string) $setup_args['config_section']
432
+				: 'addons',
433
+			// the class name for this addon's configuration settings object
434
+			'config_class'          => isset($setup_args['config_class'])
435
+				? (string) $setup_args['config_class'] : '',
436
+			// the name given to the config for this addons' configuration settings object (optional)
437
+			'config_name'           => isset($setup_args['config_name'])
438
+				? (string) $setup_args['config_name'] : '',
439
+			// an array of "class names" => "full server paths" for any classes that might be invoked by the addon
440
+			'autoloader_paths'      => isset($setup_args['autoloader_paths'])
441
+				? (array) $setup_args['autoloader_paths']
442
+				: array(),
443
+			// an array of  "full server paths" for any folders containing classes that might be invoked by the addon
444
+			'autoloader_folders'    => isset($setup_args['autoloader_folders'])
445
+				? (array) $setup_args['autoloader_folders']
446
+				: array(),
447
+			// array of full server paths to any EE_DMS data migration scripts used by the addon.
448
+			// The key should be the EE_Addon class name that this set of data migration scripts belongs to.
449
+			// If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
450
+			'dms_paths'             => isset($setup_args['dms_paths'])
451
+				? (array) $setup_args['dms_paths']
452
+				: array(),
453
+			// array of full server paths to any EED_Modules used by the addon
454
+			'module_paths'          => isset($setup_args['module_paths'])
455
+				? (array) $setup_args['module_paths']
456
+				: array(),
457
+			// array of full server paths to any EES_Shortcodes used by the addon
458
+			'shortcode_paths'       => isset($setup_args['shortcode_paths'])
459
+				? (array) $setup_args['shortcode_paths']
460
+				: array(),
461
+			'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
462
+				? (array) $setup_args['shortcode_fqcns']
463
+				: array(),
464
+			// array of full server paths to any WP_Widgets used by the addon
465
+			'widget_paths'          => isset($setup_args['widget_paths'])
466
+				? (array) $setup_args['widget_paths']
467
+				: array(),
468
+			// array of PUE options used by the addon
469
+			'pue_options'           => isset($setup_args['pue_options'])
470
+				? (array) $setup_args['pue_options']
471
+				: array(),
472
+			'message_types'         => isset($setup_args['message_types'])
473
+				? (array) $setup_args['message_types']
474
+				: array(),
475
+			'capabilities'          => isset($setup_args['capabilities'])
476
+				? (array) $setup_args['capabilities']
477
+				: array(),
478
+			'capability_maps'       => isset($setup_args['capability_maps'])
479
+				? (array) $setup_args['capability_maps']
480
+				: array(),
481
+			'model_paths'           => isset($setup_args['model_paths'])
482
+				? (array) $setup_args['model_paths']
483
+				: array(),
484
+			'class_paths'           => isset($setup_args['class_paths'])
485
+				? (array) $setup_args['class_paths']
486
+				: array(),
487
+			'model_extension_paths' => isset($setup_args['model_extension_paths'])
488
+				? (array) $setup_args['model_extension_paths']
489
+				: array(),
490
+			'class_extension_paths' => isset($setup_args['class_extension_paths'])
491
+				? (array) $setup_args['class_extension_paths']
492
+				: array(),
493
+			'custom_post_types'     => isset($setup_args['custom_post_types'])
494
+				? (array) $setup_args['custom_post_types']
495
+				: array(),
496
+			'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
497
+				? (array) $setup_args['custom_taxonomies']
498
+				: array(),
499
+			'payment_method_paths'  => isset($setup_args['payment_method_paths'])
500
+				? (array) $setup_args['payment_method_paths']
501
+				: array(),
502
+			'default_terms'         => isset($setup_args['default_terms'])
503
+				? (array) $setup_args['default_terms']
504
+				: array(),
505
+			// if not empty, inserts a new table row after this plugin's row on the WP Plugins page
506
+			// that can be used for adding upgrading/marketing info
507
+			'plugins_page_row'      => isset($setup_args['plugins_page_row'])
508
+				? $setup_args['plugins_page_row']
509
+				: '',
510
+			'namespace'             => isset(
511
+				$setup_args['namespace']['FQNS'],
512
+				$setup_args['namespace']['DIR']
513
+			)
514
+				? (array) $setup_args['namespace']
515
+				: array(),
516
+			'privacy_policies'      => isset($setup_args['privacy_policies'])
517
+				? (array) $setup_args['privacy_policies']
518
+				: '',
519
+		);
520
+		// if plugin_action_slug is NOT set, but an admin page path IS set,
521
+		// then let's just use the plugin_slug since that will be used for linking to the admin page
522
+		$addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
523
+												&& ! empty($addon_settings['admin_path'])
524
+			? $addon_settings['plugin_slug']
525
+			: $addon_settings['plugin_action_slug'];
526
+		// full server path to main file (file loaded directly by WP)
527
+		$addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
528
+		return $addon_settings;
529
+	}
530 530
 
531 531
 
532
-    /**
533
-     * @param string $addon_name
534
-     * @param array  $addon_settings
535
-     * @return boolean
536
-     */
537
-    private static function _addon_is_compatible($addon_name, array $addon_settings)
538
-    {
539
-        global $wp_version;
540
-        $incompatibility_message = '';
541
-        // check whether this addon version is compatible with EE core
542
-        if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
543
-            && ! self::_meets_min_core_version_requirement(
544
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
545
-                $addon_settings['version']
546
-            )
547
-        ) {
548
-            $incompatibility_message = sprintf(
549
-                __(
550
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.',
551
-                    'event_espresso'
552
-                ),
553
-                $addon_name,
554
-                '<br />',
555
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
556
-                '<span style="font-weight: bold; color: #D54E21;">',
557
-                '</span><br />'
558
-            );
559
-        } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
560
-        ) {
561
-            $incompatibility_message = sprintf(
562
-                __(
563
-                    '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
564
-                    'event_espresso'
565
-                ),
566
-                $addon_name,
567
-                self::_effective_version($addon_settings['min_core_version']),
568
-                self::_effective_version(espresso_version()),
569
-                '<br />',
570
-                '<span style="font-weight: bold; color: #D54E21;">',
571
-                '</span><br />'
572
-            );
573
-        } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
574
-            $incompatibility_message = sprintf(
575
-                __(
576
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
577
-                    'event_espresso'
578
-                ),
579
-                $addon_name,
580
-                $addon_settings['min_wp_version'],
581
-                '<br />',
582
-                '<span style="font-weight: bold; color: #D54E21;">',
583
-                '</span><br />'
584
-            );
585
-        }
586
-        if (! empty($incompatibility_message)) {
587
-            // remove 'activate' from the REQUEST
588
-            // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
589
-            unset($_GET['activate'], $_REQUEST['activate']);
590
-            if (current_user_can('activate_plugins')) {
591
-                // show an error message indicating the plugin didn't activate properly
592
-                EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
593
-            }
594
-            // BAIL FROM THE ADDON REGISTRATION PROCESS
595
-            return false;
596
-        }
597
-        // addon IS compatible
598
-        return true;
599
-    }
532
+	/**
533
+	 * @param string $addon_name
534
+	 * @param array  $addon_settings
535
+	 * @return boolean
536
+	 */
537
+	private static function _addon_is_compatible($addon_name, array $addon_settings)
538
+	{
539
+		global $wp_version;
540
+		$incompatibility_message = '';
541
+		// check whether this addon version is compatible with EE core
542
+		if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
543
+			&& ! self::_meets_min_core_version_requirement(
544
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
545
+				$addon_settings['version']
546
+			)
547
+		) {
548
+			$incompatibility_message = sprintf(
549
+				__(
550
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.',
551
+					'event_espresso'
552
+				),
553
+				$addon_name,
554
+				'<br />',
555
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
556
+				'<span style="font-weight: bold; color: #D54E21;">',
557
+				'</span><br />'
558
+			);
559
+		} elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
560
+		) {
561
+			$incompatibility_message = sprintf(
562
+				__(
563
+					'%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
564
+					'event_espresso'
565
+				),
566
+				$addon_name,
567
+				self::_effective_version($addon_settings['min_core_version']),
568
+				self::_effective_version(espresso_version()),
569
+				'<br />',
570
+				'<span style="font-weight: bold; color: #D54E21;">',
571
+				'</span><br />'
572
+			);
573
+		} elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
574
+			$incompatibility_message = sprintf(
575
+				__(
576
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
577
+					'event_espresso'
578
+				),
579
+				$addon_name,
580
+				$addon_settings['min_wp_version'],
581
+				'<br />',
582
+				'<span style="font-weight: bold; color: #D54E21;">',
583
+				'</span><br />'
584
+			);
585
+		}
586
+		if (! empty($incompatibility_message)) {
587
+			// remove 'activate' from the REQUEST
588
+			// so WP doesn't erroneously tell the user the plugin activated fine when it didn't
589
+			unset($_GET['activate'], $_REQUEST['activate']);
590
+			if (current_user_can('activate_plugins')) {
591
+				// show an error message indicating the plugin didn't activate properly
592
+				EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
593
+			}
594
+			// BAIL FROM THE ADDON REGISTRATION PROCESS
595
+			return false;
596
+		}
597
+		// addon IS compatible
598
+		return true;
599
+	}
600 600
 
601 601
 
602
-    /**
603
-     * if plugin update engine is being used for auto-updates,
604
-     * then let's set that up now before going any further so that ALL addons can be updated
605
-     * (not needed if PUE is not being used)
606
-     *
607
-     * @param string $addon_name
608
-     * @param string $class_name
609
-     * @param array  $setup_args
610
-     * @return void
611
-     */
612
-    private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
613
-    {
614
-        if (! empty($setup_args['pue_options'])) {
615
-            self::$_settings[ $addon_name ]['pue_options'] = array(
616
-                'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
617
-                    ? (string) $setup_args['pue_options']['pue_plugin_slug']
618
-                    : 'espresso_' . strtolower($class_name),
619
-                'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
620
-                    ? (string) $setup_args['pue_options']['plugin_basename']
621
-                    : plugin_basename($setup_args['main_file_path']),
622
-                'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
623
-                    ? (string) $setup_args['pue_options']['checkPeriod']
624
-                    : '24',
625
-                'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
626
-                    ? (string) $setup_args['pue_options']['use_wp_update']
627
-                    : false,
628
-            );
629
-            add_action(
630
-                'AHEE__EE_System__brew_espresso__after_pue_init',
631
-                array('EE_Register_Addon', 'load_pue_update')
632
-            );
633
-        }
634
-    }
602
+	/**
603
+	 * if plugin update engine is being used for auto-updates,
604
+	 * then let's set that up now before going any further so that ALL addons can be updated
605
+	 * (not needed if PUE is not being used)
606
+	 *
607
+	 * @param string $addon_name
608
+	 * @param string $class_name
609
+	 * @param array  $setup_args
610
+	 * @return void
611
+	 */
612
+	private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
613
+	{
614
+		if (! empty($setup_args['pue_options'])) {
615
+			self::$_settings[ $addon_name ]['pue_options'] = array(
616
+				'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
617
+					? (string) $setup_args['pue_options']['pue_plugin_slug']
618
+					: 'espresso_' . strtolower($class_name),
619
+				'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
620
+					? (string) $setup_args['pue_options']['plugin_basename']
621
+					: plugin_basename($setup_args['main_file_path']),
622
+				'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
623
+					? (string) $setup_args['pue_options']['checkPeriod']
624
+					: '24',
625
+				'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
626
+					? (string) $setup_args['pue_options']['use_wp_update']
627
+					: false,
628
+			);
629
+			add_action(
630
+				'AHEE__EE_System__brew_espresso__after_pue_init',
631
+				array('EE_Register_Addon', 'load_pue_update')
632
+			);
633
+		}
634
+	}
635 635
 
636 636
 
637
-    /**
638
-     * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
639
-     *
640
-     * @param array $addon_settings
641
-     * @return void
642
-     */
643
-    private static function _setup_namespaces(array $addon_settings)
644
-    {
645
-        //
646
-        if (isset(
647
-            $addon_settings['namespace']['FQNS'],
648
-            $addon_settings['namespace']['DIR']
649
-        )) {
650
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
651
-                $addon_settings['namespace']['FQNS'],
652
-                $addon_settings['namespace']['DIR']
653
-            );
654
-        }
655
-    }
637
+	/**
638
+	 * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
639
+	 *
640
+	 * @param array $addon_settings
641
+	 * @return void
642
+	 */
643
+	private static function _setup_namespaces(array $addon_settings)
644
+	{
645
+		//
646
+		if (isset(
647
+			$addon_settings['namespace']['FQNS'],
648
+			$addon_settings['namespace']['DIR']
649
+		)) {
650
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
651
+				$addon_settings['namespace']['FQNS'],
652
+				$addon_settings['namespace']['DIR']
653
+			);
654
+		}
655
+	}
656 656
 
657 657
 
658
-    /**
659
-     * @param string $addon_name
660
-     * @param array  $addon_settings
661
-     * @return bool
662
-     * @throws EE_Error
663
-     * @throws InvalidArgumentException
664
-     * @throws ReflectionException
665
-     * @throws InvalidDataTypeException
666
-     * @throws InvalidInterfaceException
667
-     */
668
-    private static function _addon_activation($addon_name, array $addon_settings)
669
-    {
670
-        // this is an activation request
671
-        if (did_action(
672
-            'activate_plugin'
673
-        )) {// to find if THIS is the addon that was activated, just check if we have already registered it or not
674
-            // (as the newly-activated addon wasn't around the first time addons were registered).
675
-            // Note: the presence of pue_options in the addon registration options will initialize the $_settings
676
-            // property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
677
-            if (! isset(self::$_settings[ $addon_name ])
678
-                || (isset(self::$_settings[ $addon_name ])
679
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
680
-                )
681
-            ) {
682
-                self::$_settings[ $addon_name ] = $addon_settings;
683
-                $addon = self::_load_and_init_addon_class($addon_name);
684
-                $addon->set_activation_indicator_option();
685
-                // dont bother setting up the rest of the addon.
686
-                // we know it was just activated and the request will end soon
687
-            }
688
-            return true;
689
-        }
690
-        // make sure this was called in the right place!
691
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
692
-            || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
693
-        ) {
694
-            EE_Error::doing_it_wrong(
695
-                __METHOD__,
696
-                sprintf(
697
-                    __(
698
-                        'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
699
-                        'event_espresso'
700
-                    ),
701
-                    $addon_name
702
-                ),
703
-                '4.3.0'
704
-            );
705
-        }
706
-        // make sure addon settings are set correctly without overwriting anything existing
707
-        if (isset(self::$_settings[ $addon_name ])) {
708
-            self::$_settings[ $addon_name ] += $addon_settings;
709
-        } else {
710
-            self::$_settings[ $addon_name ] = $addon_settings;
711
-        }
712
-        return false;
713
-    }
658
+	/**
659
+	 * @param string $addon_name
660
+	 * @param array  $addon_settings
661
+	 * @return bool
662
+	 * @throws EE_Error
663
+	 * @throws InvalidArgumentException
664
+	 * @throws ReflectionException
665
+	 * @throws InvalidDataTypeException
666
+	 * @throws InvalidInterfaceException
667
+	 */
668
+	private static function _addon_activation($addon_name, array $addon_settings)
669
+	{
670
+		// this is an activation request
671
+		if (did_action(
672
+			'activate_plugin'
673
+		)) {// to find if THIS is the addon that was activated, just check if we have already registered it or not
674
+			// (as the newly-activated addon wasn't around the first time addons were registered).
675
+			// Note: the presence of pue_options in the addon registration options will initialize the $_settings
676
+			// property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
677
+			if (! isset(self::$_settings[ $addon_name ])
678
+				|| (isset(self::$_settings[ $addon_name ])
679
+					&& ! isset(self::$_settings[ $addon_name ]['class_name'])
680
+				)
681
+			) {
682
+				self::$_settings[ $addon_name ] = $addon_settings;
683
+				$addon = self::_load_and_init_addon_class($addon_name);
684
+				$addon->set_activation_indicator_option();
685
+				// dont bother setting up the rest of the addon.
686
+				// we know it was just activated and the request will end soon
687
+			}
688
+			return true;
689
+		}
690
+		// make sure this was called in the right place!
691
+		if (! did_action('AHEE__EE_System__load_espresso_addons')
692
+			|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
693
+		) {
694
+			EE_Error::doing_it_wrong(
695
+				__METHOD__,
696
+				sprintf(
697
+					__(
698
+						'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
699
+						'event_espresso'
700
+					),
701
+					$addon_name
702
+				),
703
+				'4.3.0'
704
+			);
705
+		}
706
+		// make sure addon settings are set correctly without overwriting anything existing
707
+		if (isset(self::$_settings[ $addon_name ])) {
708
+			self::$_settings[ $addon_name ] += $addon_settings;
709
+		} else {
710
+			self::$_settings[ $addon_name ] = $addon_settings;
711
+		}
712
+		return false;
713
+	}
714 714
 
715 715
 
716
-    /**
717
-     * @param string $addon_name
718
-     * @return void
719
-     * @throws EE_Error
720
-     */
721
-    private static function _setup_autoloaders($addon_name)
722
-    {
723
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
724
-            // setup autoloader for single file
725
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
726
-        }
727
-        // setup autoloaders for folders
728
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
729
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
730
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
731
-            }
732
-        }
733
-    }
716
+	/**
717
+	 * @param string $addon_name
718
+	 * @return void
719
+	 * @throws EE_Error
720
+	 */
721
+	private static function _setup_autoloaders($addon_name)
722
+	{
723
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
724
+			// setup autoloader for single file
725
+			EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
726
+		}
727
+		// setup autoloaders for folders
728
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
729
+			foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
730
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
731
+			}
732
+		}
733
+	}
734 734
 
735 735
 
736
-    /**
737
-     * register new models and extensions
738
-     *
739
-     * @param string $addon_name
740
-     * @return void
741
-     * @throws EE_Error
742
-     */
743
-    private static function _register_models_and_extensions($addon_name)
744
-    {
745
-        // register new models
746
-        if (! empty(self::$_settings[ $addon_name ]['model_paths'])
747
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
748
-        ) {
749
-            EE_Register_Model::register(
750
-                $addon_name,
751
-                array(
752
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
753
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
754
-                )
755
-            );
756
-        }
757
-        // register model extensions
758
-        if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
759
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
760
-        ) {
761
-            EE_Register_Model_Extensions::register(
762
-                $addon_name,
763
-                array(
764
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
765
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
766
-                )
767
-            );
768
-        }
769
-    }
736
+	/**
737
+	 * register new models and extensions
738
+	 *
739
+	 * @param string $addon_name
740
+	 * @return void
741
+	 * @throws EE_Error
742
+	 */
743
+	private static function _register_models_and_extensions($addon_name)
744
+	{
745
+		// register new models
746
+		if (! empty(self::$_settings[ $addon_name ]['model_paths'])
747
+			|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
748
+		) {
749
+			EE_Register_Model::register(
750
+				$addon_name,
751
+				array(
752
+					'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
753
+					'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
754
+				)
755
+			);
756
+		}
757
+		// register model extensions
758
+		if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
759
+			|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
760
+		) {
761
+			EE_Register_Model_Extensions::register(
762
+				$addon_name,
763
+				array(
764
+					'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
765
+					'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
766
+				)
767
+			);
768
+		}
769
+	}
770 770
 
771 771
 
772
-    /**
773
-     * @param string $addon_name
774
-     * @return void
775
-     * @throws EE_Error
776
-     */
777
-    private static function _register_data_migration_scripts($addon_name)
778
-    {
779
-        // setup DMS
780
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
781
-            EE_Register_Data_Migration_Scripts::register(
782
-                $addon_name,
783
-                array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
784
-            );
785
-        }
786
-    }
772
+	/**
773
+	 * @param string $addon_name
774
+	 * @return void
775
+	 * @throws EE_Error
776
+	 */
777
+	private static function _register_data_migration_scripts($addon_name)
778
+	{
779
+		// setup DMS
780
+		if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
781
+			EE_Register_Data_Migration_Scripts::register(
782
+				$addon_name,
783
+				array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
784
+			);
785
+		}
786
+	}
787 787
 
788 788
 
789
-    /**
790
-     * @param string $addon_name
791
-     * @return void
792
-     * @throws EE_Error
793
-     */
794
-    private static function _register_config($addon_name)
795
-    {
796
-        // if config_class is present let's register config.
797
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
798
-            EE_Register_Config::register(
799
-                self::$_settings[ $addon_name ]['config_class'],
800
-                array(
801
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
802
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
803
-                )
804
-            );
805
-        }
806
-    }
789
+	/**
790
+	 * @param string $addon_name
791
+	 * @return void
792
+	 * @throws EE_Error
793
+	 */
794
+	private static function _register_config($addon_name)
795
+	{
796
+		// if config_class is present let's register config.
797
+		if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
798
+			EE_Register_Config::register(
799
+				self::$_settings[ $addon_name ]['config_class'],
800
+				array(
801
+					'config_section' => self::$_settings[ $addon_name ]['config_section'],
802
+					'config_name'    => self::$_settings[ $addon_name ]['config_name'],
803
+				)
804
+			);
805
+		}
806
+	}
807 807
 
808 808
 
809
-    /**
810
-     * @param string $addon_name
811
-     * @return void
812
-     * @throws EE_Error
813
-     */
814
-    private static function _register_admin_pages($addon_name)
815
-    {
816
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
817
-            EE_Register_Admin_Page::register(
818
-                $addon_name,
819
-                array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
820
-            );
821
-        }
822
-    }
809
+	/**
810
+	 * @param string $addon_name
811
+	 * @return void
812
+	 * @throws EE_Error
813
+	 */
814
+	private static function _register_admin_pages($addon_name)
815
+	{
816
+		if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
817
+			EE_Register_Admin_Page::register(
818
+				$addon_name,
819
+				array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
820
+			);
821
+		}
822
+	}
823 823
 
824 824
 
825
-    /**
826
-     * @param string $addon_name
827
-     * @return void
828
-     * @throws EE_Error
829
-     */
830
-    private static function _register_modules($addon_name)
831
-    {
832
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
833
-            EE_Register_Module::register(
834
-                $addon_name,
835
-                array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
836
-            );
837
-        }
838
-    }
825
+	/**
826
+	 * @param string $addon_name
827
+	 * @return void
828
+	 * @throws EE_Error
829
+	 */
830
+	private static function _register_modules($addon_name)
831
+	{
832
+		if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
833
+			EE_Register_Module::register(
834
+				$addon_name,
835
+				array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
836
+			);
837
+		}
838
+	}
839 839
 
840 840
 
841
-    /**
842
-     * @param string $addon_name
843
-     * @return void
844
-     * @throws EE_Error
845
-     */
846
-    private static function _register_shortcodes($addon_name)
847
-    {
848
-        if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
849
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
850
-        ) {
851
-            EE_Register_Shortcode::register(
852
-                $addon_name,
853
-                array(
854
-                    'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
855
-                        ? self::$_settings[ $addon_name ]['shortcode_paths']
856
-                        : array(),
857
-                    'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
858
-                        ? self::$_settings[ $addon_name ]['shortcode_fqcns']
859
-                        : array(),
860
-                )
861
-            );
862
-        }
863
-    }
841
+	/**
842
+	 * @param string $addon_name
843
+	 * @return void
844
+	 * @throws EE_Error
845
+	 */
846
+	private static function _register_shortcodes($addon_name)
847
+	{
848
+		if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
849
+			|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
850
+		) {
851
+			EE_Register_Shortcode::register(
852
+				$addon_name,
853
+				array(
854
+					'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
855
+						? self::$_settings[ $addon_name ]['shortcode_paths']
856
+						: array(),
857
+					'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
858
+						? self::$_settings[ $addon_name ]['shortcode_fqcns']
859
+						: array(),
860
+				)
861
+			);
862
+		}
863
+	}
864 864
 
865 865
 
866
-    /**
867
-     * @param string $addon_name
868
-     * @return void
869
-     * @throws EE_Error
870
-     */
871
-    private static function _register_widgets($addon_name)
872
-    {
873
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
874
-            EE_Register_Widget::register(
875
-                $addon_name,
876
-                array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
877
-            );
878
-        }
879
-    }
866
+	/**
867
+	 * @param string $addon_name
868
+	 * @return void
869
+	 * @throws EE_Error
870
+	 */
871
+	private static function _register_widgets($addon_name)
872
+	{
873
+		if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
874
+			EE_Register_Widget::register(
875
+				$addon_name,
876
+				array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
877
+			);
878
+		}
879
+	}
880 880
 
881 881
 
882
-    /**
883
-     * @param string $addon_name
884
-     * @return void
885
-     * @throws EE_Error
886
-     */
887
-    private static function _register_capabilities($addon_name)
888
-    {
889
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
890
-            EE_Register_Capabilities::register(
891
-                $addon_name,
892
-                array(
893
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
894
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
895
-                )
896
-            );
897
-        }
898
-    }
882
+	/**
883
+	 * @param string $addon_name
884
+	 * @return void
885
+	 * @throws EE_Error
886
+	 */
887
+	private static function _register_capabilities($addon_name)
888
+	{
889
+		if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
890
+			EE_Register_Capabilities::register(
891
+				$addon_name,
892
+				array(
893
+					'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
894
+					'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
895
+				)
896
+			);
897
+		}
898
+	}
899 899
 
900 900
 
901
-    /**
902
-     * @param string $addon_name
903
-     * @return void
904
-     * @throws EE_Error
905
-     */
906
-    private static function _register_message_types($addon_name)
907
-    {
908
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
909
-            add_action(
910
-                'EE_Brewing_Regular___messages_caf',
911
-                array('EE_Register_Addon', 'register_message_types')
912
-            );
913
-        }
914
-    }
901
+	/**
902
+	 * @param string $addon_name
903
+	 * @return void
904
+	 * @throws EE_Error
905
+	 */
906
+	private static function _register_message_types($addon_name)
907
+	{
908
+		if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
909
+			add_action(
910
+				'EE_Brewing_Regular___messages_caf',
911
+				array('EE_Register_Addon', 'register_message_types')
912
+			);
913
+		}
914
+	}
915 915
 
916 916
 
917
-    /**
918
-     * @param string $addon_name
919
-     * @return void
920
-     * @throws EE_Error
921
-     */
922
-    private static function _register_custom_post_types($addon_name)
923
-    {
924
-        if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])
925
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
926
-        ) {
927
-            EE_Register_CPT::register(
928
-                $addon_name,
929
-                array(
930
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
931
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
932
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
933
-                )
934
-            );
935
-        }
936
-    }
917
+	/**
918
+	 * @param string $addon_name
919
+	 * @return void
920
+	 * @throws EE_Error
921
+	 */
922
+	private static function _register_custom_post_types($addon_name)
923
+	{
924
+		if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])
925
+			|| ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
926
+		) {
927
+			EE_Register_CPT::register(
928
+				$addon_name,
929
+				array(
930
+					'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
931
+					'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
932
+					'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
933
+				)
934
+			);
935
+		}
936
+	}
937 937
 
938 938
 
939
-    /**
940
-     * @param string $addon_name
941
-     * @return void
942
-     * @throws InvalidArgumentException
943
-     * @throws InvalidInterfaceException
944
-     * @throws InvalidDataTypeException
945
-     * @throws DomainException
946
-     * @throws EE_Error
947
-     */
948
-    private static function _register_payment_methods($addon_name)
949
-    {
950
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
951
-            EE_Register_Payment_Method::register(
952
-                $addon_name,
953
-                array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
954
-            );
955
-        }
956
-    }
939
+	/**
940
+	 * @param string $addon_name
941
+	 * @return void
942
+	 * @throws InvalidArgumentException
943
+	 * @throws InvalidInterfaceException
944
+	 * @throws InvalidDataTypeException
945
+	 * @throws DomainException
946
+	 * @throws EE_Error
947
+	 */
948
+	private static function _register_payment_methods($addon_name)
949
+	{
950
+		if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
951
+			EE_Register_Payment_Method::register(
952
+				$addon_name,
953
+				array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
954
+			);
955
+		}
956
+	}
957 957
 
958 958
 
959
-    /**
960
-     * @param string $addon_name
961
-     * @return void
962
-     * @throws InvalidArgumentException
963
-     * @throws InvalidInterfaceException
964
-     * @throws InvalidDataTypeException
965
-     * @throws DomainException
966
-     * @throws EE_Error
967
-     */
968
-    private static function registerPrivacyPolicies($addon_name)
969
-    {
970
-        if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
971
-            EE_Register_Privacy_Policy::register(
972
-                $addon_name,
973
-                self::$_settings[ $addon_name ]['privacy_policies']
974
-            );
975
-        }
976
-    }
959
+	/**
960
+	 * @param string $addon_name
961
+	 * @return void
962
+	 * @throws InvalidArgumentException
963
+	 * @throws InvalidInterfaceException
964
+	 * @throws InvalidDataTypeException
965
+	 * @throws DomainException
966
+	 * @throws EE_Error
967
+	 */
968
+	private static function registerPrivacyPolicies($addon_name)
969
+	{
970
+		if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
971
+			EE_Register_Privacy_Policy::register(
972
+				$addon_name,
973
+				self::$_settings[ $addon_name ]['privacy_policies']
974
+			);
975
+		}
976
+	}
977 977
 
978 978
 
979
-    /**
980
-     * @param string $addon_name
981
-     * @return void
982
-     */
983
-    private static function registerPersonalDataExporters($addon_name)
984
-    {
985
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
986
-            EE_Register_Personal_Data_Eraser::register(
987
-                $addon_name,
988
-                self::$_settings[ $addon_name ]['personal_data_exporters']
989
-            );
990
-        }
991
-    }
979
+	/**
980
+	 * @param string $addon_name
981
+	 * @return void
982
+	 */
983
+	private static function registerPersonalDataExporters($addon_name)
984
+	{
985
+		if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
986
+			EE_Register_Personal_Data_Eraser::register(
987
+				$addon_name,
988
+				self::$_settings[ $addon_name ]['personal_data_exporters']
989
+			);
990
+		}
991
+	}
992 992
 
993 993
 
994
-    /**
995
-     * @param string $addon_name
996
-     * @return void
997
-     */
998
-    private static function registerPersonalDataErasers($addon_name)
999
-    {
1000
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
1001
-            EE_Register_Personal_Data_Eraser::register(
1002
-                $addon_name,
1003
-                self::$_settings[ $addon_name ]['personal_data_erasers']
1004
-            );
1005
-        }
1006
-    }
994
+	/**
995
+	 * @param string $addon_name
996
+	 * @return void
997
+	 */
998
+	private static function registerPersonalDataErasers($addon_name)
999
+	{
1000
+		if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
1001
+			EE_Register_Personal_Data_Eraser::register(
1002
+				$addon_name,
1003
+				self::$_settings[ $addon_name ]['personal_data_erasers']
1004
+			);
1005
+		}
1006
+	}
1007 1007
 
1008 1008
 
1009
-    /**
1010
-     * Loads and instantiates the EE_Addon class and adds it onto the registry
1011
-     *
1012
-     * @param string $addon_name
1013
-     * @return EE_Addon
1014
-     * @throws InvalidArgumentException
1015
-     * @throws InvalidInterfaceException
1016
-     * @throws InvalidDataTypeException
1017
-     * @throws ReflectionException
1018
-     * @throws EE_Error
1019
-     */
1020
-    private static function _load_and_init_addon_class($addon_name)
1021
-    {
1022
-        $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader();
1023
-        $addon = $loader->getShared(
1024
-            self::$_settings[ $addon_name ]['class_name'],
1025
-            array('EE_Registry::create(addon)' => true)
1026
-        );
1027
-        // setter inject dep map if required
1028
-        if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) {
1029
-            $addon->setDependencyMap($loader->getShared('EE_Dependency_Map'));
1030
-        }
1031
-        // setter inject domain if required
1032
-        if ($addon instanceof RequiresDomainInterface
1033
-            && $addon->domain() === null
1034
-        ) {
1035
-            // using supplied Domain object
1036
-            $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1037
-                ? self::$_settings[ $addon_name ]['domain']
1038
-                : null;
1039
-            // or construct one using Domain FQCN
1040
-            if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1041
-                $domain = $loader->getShared(
1042
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
1043
-                    array(
1044
-                        new EventEspresso\core\domain\values\FilePath(
1045
-                            self::$_settings[ $addon_name ]['main_file_path']
1046
-                        ),
1047
-                        EventEspresso\core\domain\values\Version::fromString(
1048
-                            self::$_settings[ $addon_name ]['version']
1049
-                        ),
1050
-                    )
1051
-                );
1052
-            }
1053
-            if ($domain instanceof DomainInterface) {
1054
-                $addon->setDomain($domain);
1055
-            }
1056
-        }
1057
-        $addon->set_name($addon_name);
1058
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1059
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1060
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1061
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1062
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1063
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
1064
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1065
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1066
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1067
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1068
-        // unfortunately this can't be hooked in upon construction, because we don't have
1069
-        // the plugin mainfile's path upon construction.
1070
-        register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
1071
-        // call any additional admin_callback functions during load_admin_controller hook
1072
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1073
-            add_action(
1074
-                'AHEE__EE_System__load_controllers__load_admin_controllers',
1075
-                array($addon, self::$_settings[ $addon_name ]['admin_callback'])
1076
-            );
1077
-        }
1078
-        return $addon;
1079
-    }
1009
+	/**
1010
+	 * Loads and instantiates the EE_Addon class and adds it onto the registry
1011
+	 *
1012
+	 * @param string $addon_name
1013
+	 * @return EE_Addon
1014
+	 * @throws InvalidArgumentException
1015
+	 * @throws InvalidInterfaceException
1016
+	 * @throws InvalidDataTypeException
1017
+	 * @throws ReflectionException
1018
+	 * @throws EE_Error
1019
+	 */
1020
+	private static function _load_and_init_addon_class($addon_name)
1021
+	{
1022
+		$loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader();
1023
+		$addon = $loader->getShared(
1024
+			self::$_settings[ $addon_name ]['class_name'],
1025
+			array('EE_Registry::create(addon)' => true)
1026
+		);
1027
+		// setter inject dep map if required
1028
+		if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) {
1029
+			$addon->setDependencyMap($loader->getShared('EE_Dependency_Map'));
1030
+		}
1031
+		// setter inject domain if required
1032
+		if ($addon instanceof RequiresDomainInterface
1033
+			&& $addon->domain() === null
1034
+		) {
1035
+			// using supplied Domain object
1036
+			$domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1037
+				? self::$_settings[ $addon_name ]['domain']
1038
+				: null;
1039
+			// or construct one using Domain FQCN
1040
+			if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1041
+				$domain = $loader->getShared(
1042
+					self::$_settings[ $addon_name ]['domain_fqcn'],
1043
+					array(
1044
+						new EventEspresso\core\domain\values\FilePath(
1045
+							self::$_settings[ $addon_name ]['main_file_path']
1046
+						),
1047
+						EventEspresso\core\domain\values\Version::fromString(
1048
+							self::$_settings[ $addon_name ]['version']
1049
+						),
1050
+					)
1051
+				);
1052
+			}
1053
+			if ($domain instanceof DomainInterface) {
1054
+				$addon->setDomain($domain);
1055
+			}
1056
+		}
1057
+		$addon->set_name($addon_name);
1058
+		$addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1059
+		$addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1060
+		$addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1061
+		$addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1062
+		$addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1063
+		$addon->set_version(self::$_settings[ $addon_name ]['version']);
1064
+		$addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1065
+		$addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1066
+		$addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1067
+		$addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1068
+		// unfortunately this can't be hooked in upon construction, because we don't have
1069
+		// the plugin mainfile's path upon construction.
1070
+		register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
1071
+		// call any additional admin_callback functions during load_admin_controller hook
1072
+		if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1073
+			add_action(
1074
+				'AHEE__EE_System__load_controllers__load_admin_controllers',
1075
+				array($addon, self::$_settings[ $addon_name ]['admin_callback'])
1076
+			);
1077
+		}
1078
+		return $addon;
1079
+	}
1080 1080
 
1081 1081
 
1082
-    /**
1083
-     *    load_pue_update - Update notifications
1084
-     *
1085
-     * @return void
1086
-     * @throws InvalidArgumentException
1087
-     * @throws InvalidDataTypeException
1088
-     * @throws InvalidInterfaceException
1089
-     */
1090
-    public static function load_pue_update()
1091
-    {
1092
-        // load PUE client
1093
-        require_once EE_THIRD_PARTY . 'pue/pue-client.php';
1094
-        $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
1095
-        // cycle thru settings
1096
-        foreach (self::$_settings as $settings) {
1097
-            if (! empty($settings['pue_options'])) {
1098
-                // initiate the class and start the plugin update engine!
1099
-                new PluginUpdateEngineChecker(
1100
-                    // host file URL
1101
-                    $license_server,
1102
-                    // plugin slug(s)
1103
-                    array(
1104
-                        'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1105
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1106
-                    ),
1107
-                    // options
1108
-                    array(
1109
-                        'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
1110
-                        'lang_domain'       => 'event_espresso',
1111
-                        'checkPeriod'       => $settings['pue_options']['checkPeriod'],
1112
-                        'option_key'        => 'ee_site_license_key',
1113
-                        'options_page_slug' => 'event_espresso',
1114
-                        'plugin_basename'   => $settings['pue_options']['plugin_basename'],
1115
-                        // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
1116
-                        'use_wp_update'     => $settings['pue_options']['use_wp_update'],
1117
-                    )
1118
-                );
1119
-            }
1120
-        }
1121
-    }
1082
+	/**
1083
+	 *    load_pue_update - Update notifications
1084
+	 *
1085
+	 * @return void
1086
+	 * @throws InvalidArgumentException
1087
+	 * @throws InvalidDataTypeException
1088
+	 * @throws InvalidInterfaceException
1089
+	 */
1090
+	public static function load_pue_update()
1091
+	{
1092
+		// load PUE client
1093
+		require_once EE_THIRD_PARTY . 'pue/pue-client.php';
1094
+		$license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
1095
+		// cycle thru settings
1096
+		foreach (self::$_settings as $settings) {
1097
+			if (! empty($settings['pue_options'])) {
1098
+				// initiate the class and start the plugin update engine!
1099
+				new PluginUpdateEngineChecker(
1100
+					// host file URL
1101
+					$license_server,
1102
+					// plugin slug(s)
1103
+					array(
1104
+						'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1105
+						'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1106
+					),
1107
+					// options
1108
+					array(
1109
+						'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
1110
+						'lang_domain'       => 'event_espresso',
1111
+						'checkPeriod'       => $settings['pue_options']['checkPeriod'],
1112
+						'option_key'        => 'ee_site_license_key',
1113
+						'options_page_slug' => 'event_espresso',
1114
+						'plugin_basename'   => $settings['pue_options']['plugin_basename'],
1115
+						// if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
1116
+						'use_wp_update'     => $settings['pue_options']['use_wp_update'],
1117
+					)
1118
+				);
1119
+			}
1120
+		}
1121
+	}
1122 1122
 
1123 1123
 
1124
-    /**
1125
-     * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1126
-     *
1127
-     * @since 4.4.0
1128
-     * @return void
1129
-     * @throws EE_Error
1130
-     */
1131
-    public static function register_message_types()
1132
-    {
1133
-        foreach (self::$_settings as $addon_name => $settings) {
1134
-            if (! empty($settings['message_types'])) {
1135
-                foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1136
-                    EE_Register_Message_Type::register($message_type, $message_type_settings);
1137
-                }
1138
-            }
1139
-        }
1140
-    }
1124
+	/**
1125
+	 * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1126
+	 *
1127
+	 * @since 4.4.0
1128
+	 * @return void
1129
+	 * @throws EE_Error
1130
+	 */
1131
+	public static function register_message_types()
1132
+	{
1133
+		foreach (self::$_settings as $addon_name => $settings) {
1134
+			if (! empty($settings['message_types'])) {
1135
+				foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1136
+					EE_Register_Message_Type::register($message_type, $message_type_settings);
1137
+				}
1138
+			}
1139
+		}
1140
+	}
1141 1141
 
1142 1142
 
1143
-    /**
1144
-     * This deregisters an addon that was previously registered with a specific addon_name.
1145
-     *
1146
-     * @since    4.3.0
1147
-     * @param string $addon_name the name for the addon that was previously registered
1148
-     * @throws DomainException
1149
-     * @throws EE_Error
1150
-     * @throws InvalidArgumentException
1151
-     * @throws InvalidDataTypeException
1152
-     * @throws InvalidInterfaceException
1153
-     */
1154
-    public static function deregister($addon_name = null)
1155
-    {
1156
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1157
-            try {
1158
-                do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1159
-                $class_name = self::$_settings[ $addon_name ]['class_name'];
1160
-                if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1161
-                    // setup DMS
1162
-                    EE_Register_Data_Migration_Scripts::deregister($addon_name);
1163
-                }
1164
-                if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1165
-                    // register admin page
1166
-                    EE_Register_Admin_Page::deregister($addon_name);
1167
-                }
1168
-                if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1169
-                    // add to list of modules to be registered
1170
-                    EE_Register_Module::deregister($addon_name);
1171
-                }
1172
-                if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1173
-                    || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1174
-                ) {
1175
-                    // add to list of shortcodes to be registered
1176
-                    EE_Register_Shortcode::deregister($addon_name);
1177
-                }
1178
-                if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1179
-                    // if config_class present let's register config.
1180
-                    EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1181
-                }
1182
-                if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1183
-                    // add to list of widgets to be registered
1184
-                    EE_Register_Widget::deregister($addon_name);
1185
-                }
1186
-                if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1187
-                    || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1188
-                ) {
1189
-                    // add to list of shortcodes to be registered
1190
-                    EE_Register_Model::deregister($addon_name);
1191
-                }
1192
-                if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1193
-                    || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1194
-                ) {
1195
-                    // add to list of shortcodes to be registered
1196
-                    EE_Register_Model_Extensions::deregister($addon_name);
1197
-                }
1198
-                if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1199
-                    foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1200
-                        EE_Register_Message_Type::deregister($message_type);
1201
-                    }
1202
-                }
1203
-                // deregister capabilities for addon
1204
-                if (! empty(self::$_settings[ $addon_name ]['capabilities'])
1205
-                    || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1206
-                ) {
1207
-                    EE_Register_Capabilities::deregister($addon_name);
1208
-                }
1209
-                // deregister custom_post_types for addon
1210
-                if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1211
-                    EE_Register_CPT::deregister($addon_name);
1212
-                }
1213
-                if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1214
-                    EE_Register_Payment_Method::deregister($addon_name);
1215
-                }
1216
-                $addon = EE_Registry::instance()->getAddon($class_name);
1217
-                if ($addon instanceof EE_Addon) {
1218
-                    remove_action(
1219
-                        'deactivate_' . $addon->get_main_plugin_file_basename(),
1220
-                        array($addon, 'deactivation')
1221
-                    );
1222
-                    remove_action(
1223
-                        'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1224
-                        array($addon, 'initialize_db_if_no_migrations_required')
1225
-                    );
1226
-                    // remove `after_registration` call
1227
-                    remove_action(
1228
-                        'AHEE__EE_System__load_espresso_addons__complete',
1229
-                        array($addon, 'after_registration'),
1230
-                        999
1231
-                    );
1232
-                }
1233
-                EE_Registry::instance()->removeAddon($class_name);
1234
-            } catch (OutOfBoundsException $addon_not_yet_registered_exception) {
1235
-                // the add-on was not yet registered in the registry,
1236
-                // so RegistryContainer::__get() throws this exception.
1237
-                // also no need to worry about this or log it,
1238
-                // it's ok to deregister an add-on before its registered in the registry
1239
-            } catch (Exception $e) {
1240
-                new ExceptionLogger($e);
1241
-            }
1242
-            unset(self::$_settings[ $addon_name ]);
1243
-            do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1244
-        }
1245
-    }
1143
+	/**
1144
+	 * This deregisters an addon that was previously registered with a specific addon_name.
1145
+	 *
1146
+	 * @since    4.3.0
1147
+	 * @param string $addon_name the name for the addon that was previously registered
1148
+	 * @throws DomainException
1149
+	 * @throws EE_Error
1150
+	 * @throws InvalidArgumentException
1151
+	 * @throws InvalidDataTypeException
1152
+	 * @throws InvalidInterfaceException
1153
+	 */
1154
+	public static function deregister($addon_name = null)
1155
+	{
1156
+		if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1157
+			try {
1158
+				do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1159
+				$class_name = self::$_settings[ $addon_name ]['class_name'];
1160
+				if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1161
+					// setup DMS
1162
+					EE_Register_Data_Migration_Scripts::deregister($addon_name);
1163
+				}
1164
+				if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1165
+					// register admin page
1166
+					EE_Register_Admin_Page::deregister($addon_name);
1167
+				}
1168
+				if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1169
+					// add to list of modules to be registered
1170
+					EE_Register_Module::deregister($addon_name);
1171
+				}
1172
+				if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1173
+					|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1174
+				) {
1175
+					// add to list of shortcodes to be registered
1176
+					EE_Register_Shortcode::deregister($addon_name);
1177
+				}
1178
+				if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1179
+					// if config_class present let's register config.
1180
+					EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1181
+				}
1182
+				if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1183
+					// add to list of widgets to be registered
1184
+					EE_Register_Widget::deregister($addon_name);
1185
+				}
1186
+				if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1187
+					|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
1188
+				) {
1189
+					// add to list of shortcodes to be registered
1190
+					EE_Register_Model::deregister($addon_name);
1191
+				}
1192
+				if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1193
+					|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1194
+				) {
1195
+					// add to list of shortcodes to be registered
1196
+					EE_Register_Model_Extensions::deregister($addon_name);
1197
+				}
1198
+				if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1199
+					foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1200
+						EE_Register_Message_Type::deregister($message_type);
1201
+					}
1202
+				}
1203
+				// deregister capabilities for addon
1204
+				if (! empty(self::$_settings[ $addon_name ]['capabilities'])
1205
+					|| ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1206
+				) {
1207
+					EE_Register_Capabilities::deregister($addon_name);
1208
+				}
1209
+				// deregister custom_post_types for addon
1210
+				if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1211
+					EE_Register_CPT::deregister($addon_name);
1212
+				}
1213
+				if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1214
+					EE_Register_Payment_Method::deregister($addon_name);
1215
+				}
1216
+				$addon = EE_Registry::instance()->getAddon($class_name);
1217
+				if ($addon instanceof EE_Addon) {
1218
+					remove_action(
1219
+						'deactivate_' . $addon->get_main_plugin_file_basename(),
1220
+						array($addon, 'deactivation')
1221
+					);
1222
+					remove_action(
1223
+						'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1224
+						array($addon, 'initialize_db_if_no_migrations_required')
1225
+					);
1226
+					// remove `after_registration` call
1227
+					remove_action(
1228
+						'AHEE__EE_System__load_espresso_addons__complete',
1229
+						array($addon, 'after_registration'),
1230
+						999
1231
+					);
1232
+				}
1233
+				EE_Registry::instance()->removeAddon($class_name);
1234
+			} catch (OutOfBoundsException $addon_not_yet_registered_exception) {
1235
+				// the add-on was not yet registered in the registry,
1236
+				// so RegistryContainer::__get() throws this exception.
1237
+				// also no need to worry about this or log it,
1238
+				// it's ok to deregister an add-on before its registered in the registry
1239
+			} catch (Exception $e) {
1240
+				new ExceptionLogger($e);
1241
+			}
1242
+			unset(self::$_settings[ $addon_name ]);
1243
+			do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1244
+		}
1245
+	}
1246 1246
 }
Please login to merge, or discard this patch.
Spacing   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -69,15 +69,15 @@  discard block
 block discarded – undo
69 69
         // offsets:    0 . 1 . 2 . 3 . 4
70 70
         $version_parts = explode('.', $min_core_version);
71 71
         // check they specified the micro version (after 2nd period)
72
-        if (! isset($version_parts[2])) {
72
+        if ( ! isset($version_parts[2])) {
73 73
             $version_parts[2] = '0';
74 74
         }
75 75
         // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
76 76
         // soon we can assume that's 'rc', but this current version is 'alpha'
77
-        if (! isset($version_parts[3])) {
77
+        if ( ! isset($version_parts[3])) {
78 78
             $version_parts[3] = 'dev';
79 79
         }
80
-        if (! isset($version_parts[4])) {
80
+        if ( ! isset($version_parts[4])) {
81 81
             $version_parts[4] = '000';
82 82
         }
83 83
         return implode('.', $version_parts);
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
         // setup PUE
265 265
         EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
266 266
         // does this addon work with this version of core or WordPress ?
267
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
267
+        if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
268 268
             return;
269 269
         }
270 270
         // register namespaces
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
                 )
329 329
             );
330 330
         }
331
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
331
+        if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
332 332
             throw new EE_Error(
333 333
                 sprintf(
334 334
                     __(
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
             );
341 341
         }
342 342
         // check that addon has not already been registered with that name
343
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
343
+        if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
344 344
             throw new EE_Error(
345 345
                 sprintf(
346 346
                     __(
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
         // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
373 373
         return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
374 374
             ? $class_name
375
-            : 'EE_' . $class_name;
375
+            : 'EE_'.$class_name;
376 376
     }
377 377
 
378 378
 
@@ -539,9 +539,9 @@  discard block
 block discarded – undo
539 539
         global $wp_version;
540 540
         $incompatibility_message = '';
541 541
         // check whether this addon version is compatible with EE core
542
-        if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
542
+        if (isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
543 543
             && ! self::_meets_min_core_version_requirement(
544
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
544
+                EE_Register_Addon::$_incompatible_addons[$addon_name],
545 545
                 $addon_settings['version']
546 546
             )
547 547
         ) {
@@ -552,11 +552,11 @@  discard block
 block discarded – undo
552 552
                 ),
553 553
                 $addon_name,
554 554
                 '<br />',
555
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
555
+                EE_Register_Addon::$_incompatible_addons[$addon_name],
556 556
                 '<span style="font-weight: bold; color: #D54E21;">',
557 557
                 '</span><br />'
558 558
             );
559
-        } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
559
+        } elseif ( ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
560 560
         ) {
561 561
             $incompatibility_message = sprintf(
562 562
                 __(
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
                 '</span><br />'
584 584
             );
585 585
         }
586
-        if (! empty($incompatibility_message)) {
586
+        if ( ! empty($incompatibility_message)) {
587 587
             // remove 'activate' from the REQUEST
588 588
             // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
589 589
             unset($_GET['activate'], $_REQUEST['activate']);
@@ -611,11 +611,11 @@  discard block
 block discarded – undo
611 611
      */
612 612
     private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
613 613
     {
614
-        if (! empty($setup_args['pue_options'])) {
615
-            self::$_settings[ $addon_name ]['pue_options'] = array(
614
+        if ( ! empty($setup_args['pue_options'])) {
615
+            self::$_settings[$addon_name]['pue_options'] = array(
616 616
                 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
617 617
                     ? (string) $setup_args['pue_options']['pue_plugin_slug']
618
-                    : 'espresso_' . strtolower($class_name),
618
+                    : 'espresso_'.strtolower($class_name),
619 619
                 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
620 620
                     ? (string) $setup_args['pue_options']['plugin_basename']
621 621
                     : plugin_basename($setup_args['main_file_path']),
@@ -674,12 +674,12 @@  discard block
 block discarded – undo
674 674
             // (as the newly-activated addon wasn't around the first time addons were registered).
675 675
             // Note: the presence of pue_options in the addon registration options will initialize the $_settings
676 676
             // property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
677
-            if (! isset(self::$_settings[ $addon_name ])
678
-                || (isset(self::$_settings[ $addon_name ])
679
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
677
+            if ( ! isset(self::$_settings[$addon_name])
678
+                || (isset(self::$_settings[$addon_name])
679
+                    && ! isset(self::$_settings[$addon_name]['class_name'])
680 680
                 )
681 681
             ) {
682
-                self::$_settings[ $addon_name ] = $addon_settings;
682
+                self::$_settings[$addon_name] = $addon_settings;
683 683
                 $addon = self::_load_and_init_addon_class($addon_name);
684 684
                 $addon->set_activation_indicator_option();
685 685
                 // dont bother setting up the rest of the addon.
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
             return true;
689 689
         }
690 690
         // make sure this was called in the right place!
691
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
691
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons')
692 692
             || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
693 693
         ) {
694 694
             EE_Error::doing_it_wrong(
@@ -704,10 +704,10 @@  discard block
 block discarded – undo
704 704
             );
705 705
         }
706 706
         // make sure addon settings are set correctly without overwriting anything existing
707
-        if (isset(self::$_settings[ $addon_name ])) {
708
-            self::$_settings[ $addon_name ] += $addon_settings;
707
+        if (isset(self::$_settings[$addon_name])) {
708
+            self::$_settings[$addon_name] += $addon_settings;
709 709
         } else {
710
-            self::$_settings[ $addon_name ] = $addon_settings;
710
+            self::$_settings[$addon_name] = $addon_settings;
711 711
         }
712 712
         return false;
713 713
     }
@@ -720,13 +720,13 @@  discard block
 block discarded – undo
720 720
      */
721 721
     private static function _setup_autoloaders($addon_name)
722 722
     {
723
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
723
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
724 724
             // setup autoloader for single file
725
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
725
+            EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
726 726
         }
727 727
         // setup autoloaders for folders
728
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
729
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
728
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
729
+            foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
730 730
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
731 731
             }
732 732
         }
@@ -743,26 +743,26 @@  discard block
 block discarded – undo
743 743
     private static function _register_models_and_extensions($addon_name)
744 744
     {
745 745
         // register new models
746
-        if (! empty(self::$_settings[ $addon_name ]['model_paths'])
747
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
746
+        if ( ! empty(self::$_settings[$addon_name]['model_paths'])
747
+            || ! empty(self::$_settings[$addon_name]['class_paths'])
748 748
         ) {
749 749
             EE_Register_Model::register(
750 750
                 $addon_name,
751 751
                 array(
752
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
753
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
752
+                    'model_paths' => self::$_settings[$addon_name]['model_paths'],
753
+                    'class_paths' => self::$_settings[$addon_name]['class_paths'],
754 754
                 )
755 755
             );
756 756
         }
757 757
         // register model extensions
758
-        if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
759
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
758
+        if ( ! empty(self::$_settings[$addon_name]['model_extension_paths'])
759
+            || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
760 760
         ) {
761 761
             EE_Register_Model_Extensions::register(
762 762
                 $addon_name,
763 763
                 array(
764
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
765
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
764
+                    'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
765
+                    'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
766 766
                 )
767 767
             );
768 768
         }
@@ -777,10 +777,10 @@  discard block
 block discarded – undo
777 777
     private static function _register_data_migration_scripts($addon_name)
778 778
     {
779 779
         // setup DMS
780
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
780
+        if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
781 781
             EE_Register_Data_Migration_Scripts::register(
782 782
                 $addon_name,
783
-                array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
783
+                array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
784 784
             );
785 785
         }
786 786
     }
@@ -794,12 +794,12 @@  discard block
 block discarded – undo
794 794
     private static function _register_config($addon_name)
795 795
     {
796 796
         // if config_class is present let's register config.
797
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
797
+        if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
798 798
             EE_Register_Config::register(
799
-                self::$_settings[ $addon_name ]['config_class'],
799
+                self::$_settings[$addon_name]['config_class'],
800 800
                 array(
801
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
802
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
801
+                    'config_section' => self::$_settings[$addon_name]['config_section'],
802
+                    'config_name'    => self::$_settings[$addon_name]['config_name'],
803 803
                 )
804 804
             );
805 805
         }
@@ -813,10 +813,10 @@  discard block
 block discarded – undo
813 813
      */
814 814
     private static function _register_admin_pages($addon_name)
815 815
     {
816
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
816
+        if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
817 817
             EE_Register_Admin_Page::register(
818 818
                 $addon_name,
819
-                array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
819
+                array('page_path' => self::$_settings[$addon_name]['admin_path'])
820 820
             );
821 821
         }
822 822
     }
@@ -829,10 +829,10 @@  discard block
 block discarded – undo
829 829
      */
830 830
     private static function _register_modules($addon_name)
831 831
     {
832
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
832
+        if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
833 833
             EE_Register_Module::register(
834 834
                 $addon_name,
835
-                array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
835
+                array('module_paths' => self::$_settings[$addon_name]['module_paths'])
836 836
             );
837 837
         }
838 838
     }
@@ -845,17 +845,17 @@  discard block
 block discarded – undo
845 845
      */
846 846
     private static function _register_shortcodes($addon_name)
847 847
     {
848
-        if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
849
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
848
+        if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])
849
+            || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
850 850
         ) {
851 851
             EE_Register_Shortcode::register(
852 852
                 $addon_name,
853 853
                 array(
854
-                    'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
855
-                        ? self::$_settings[ $addon_name ]['shortcode_paths']
854
+                    'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths'])
855
+                        ? self::$_settings[$addon_name]['shortcode_paths']
856 856
                         : array(),
857
-                    'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
858
-                        ? self::$_settings[ $addon_name ]['shortcode_fqcns']
857
+                    'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns'])
858
+                        ? self::$_settings[$addon_name]['shortcode_fqcns']
859 859
                         : array(),
860 860
                 )
861 861
             );
@@ -870,10 +870,10 @@  discard block
 block discarded – undo
870 870
      */
871 871
     private static function _register_widgets($addon_name)
872 872
     {
873
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
873
+        if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
874 874
             EE_Register_Widget::register(
875 875
                 $addon_name,
876
-                array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
876
+                array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
877 877
             );
878 878
         }
879 879
     }
@@ -886,12 +886,12 @@  discard block
 block discarded – undo
886 886
      */
887 887
     private static function _register_capabilities($addon_name)
888 888
     {
889
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
889
+        if ( ! empty(self::$_settings[$addon_name]['capabilities'])) {
890 890
             EE_Register_Capabilities::register(
891 891
                 $addon_name,
892 892
                 array(
893
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
894
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
893
+                    'capabilities'    => self::$_settings[$addon_name]['capabilities'],
894
+                    'capability_maps' => self::$_settings[$addon_name]['capability_maps'],
895 895
                 )
896 896
             );
897 897
         }
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
      */
906 906
     private static function _register_message_types($addon_name)
907 907
     {
908
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
908
+        if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
909 909
             add_action(
910 910
                 'EE_Brewing_Regular___messages_caf',
911 911
                 array('EE_Register_Addon', 'register_message_types')
@@ -921,15 +921,15 @@  discard block
 block discarded – undo
921 921
      */
922 922
     private static function _register_custom_post_types($addon_name)
923 923
     {
924
-        if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])
925
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
924
+        if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])
925
+            || ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
926 926
         ) {
927 927
             EE_Register_CPT::register(
928 928
                 $addon_name,
929 929
                 array(
930
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
931
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
932
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
930
+                    'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
931
+                    'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
932
+                    'default_terms' => self::$_settings[$addon_name]['default_terms'],
933 933
                 )
934 934
             );
935 935
         }
@@ -947,10 +947,10 @@  discard block
 block discarded – undo
947 947
      */
948 948
     private static function _register_payment_methods($addon_name)
949 949
     {
950
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
950
+        if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
951 951
             EE_Register_Payment_Method::register(
952 952
                 $addon_name,
953
-                array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
953
+                array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
954 954
             );
955 955
         }
956 956
     }
@@ -967,10 +967,10 @@  discard block
 block discarded – undo
967 967
      */
968 968
     private static function registerPrivacyPolicies($addon_name)
969 969
     {
970
-        if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
970
+        if ( ! empty(self::$_settings[$addon_name]['privacy_policies'])) {
971 971
             EE_Register_Privacy_Policy::register(
972 972
                 $addon_name,
973
-                self::$_settings[ $addon_name ]['privacy_policies']
973
+                self::$_settings[$addon_name]['privacy_policies']
974 974
             );
975 975
         }
976 976
     }
@@ -982,10 +982,10 @@  discard block
 block discarded – undo
982 982
      */
983 983
     private static function registerPersonalDataExporters($addon_name)
984 984
     {
985
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
985
+        if ( ! empty(self::$_settings[$addon_name]['personal_data_exporters'])) {
986 986
             EE_Register_Personal_Data_Eraser::register(
987 987
                 $addon_name,
988
-                self::$_settings[ $addon_name ]['personal_data_exporters']
988
+                self::$_settings[$addon_name]['personal_data_exporters']
989 989
             );
990 990
         }
991 991
     }
@@ -997,10 +997,10 @@  discard block
 block discarded – undo
997 997
      */
998 998
     private static function registerPersonalDataErasers($addon_name)
999 999
     {
1000
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
1000
+        if ( ! empty(self::$_settings[$addon_name]['personal_data_erasers'])) {
1001 1001
             EE_Register_Personal_Data_Eraser::register(
1002 1002
                 $addon_name,
1003
-                self::$_settings[ $addon_name ]['personal_data_erasers']
1003
+                self::$_settings[$addon_name]['personal_data_erasers']
1004 1004
             );
1005 1005
         }
1006 1006
     }
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
     {
1022 1022
         $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader();
1023 1023
         $addon = $loader->getShared(
1024
-            self::$_settings[ $addon_name ]['class_name'],
1024
+            self::$_settings[$addon_name]['class_name'],
1025 1025
             array('EE_Registry::create(addon)' => true)
1026 1026
         );
1027 1027
         // setter inject dep map if required
@@ -1033,19 +1033,19 @@  discard block
 block discarded – undo
1033 1033
             && $addon->domain() === null
1034 1034
         ) {
1035 1035
             // using supplied Domain object
1036
-            $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1037
-                ? self::$_settings[ $addon_name ]['domain']
1036
+            $domain = self::$_settings[$addon_name]['domain'] instanceof DomainInterface
1037
+                ? self::$_settings[$addon_name]['domain']
1038 1038
                 : null;
1039 1039
             // or construct one using Domain FQCN
1040
-            if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1040
+            if ($domain === null && self::$_settings[$addon_name]['domain_fqcn'] !== '') {
1041 1041
                 $domain = $loader->getShared(
1042
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
1042
+                    self::$_settings[$addon_name]['domain_fqcn'],
1043 1043
                     array(
1044 1044
                         new EventEspresso\core\domain\values\FilePath(
1045
-                            self::$_settings[ $addon_name ]['main_file_path']
1045
+                            self::$_settings[$addon_name]['main_file_path']
1046 1046
                         ),
1047 1047
                         EventEspresso\core\domain\values\Version::fromString(
1048
-                            self::$_settings[ $addon_name ]['version']
1048
+                            self::$_settings[$addon_name]['version']
1049 1049
                         ),
1050 1050
                     )
1051 1051
                 );
@@ -1055,24 +1055,24 @@  discard block
 block discarded – undo
1055 1055
             }
1056 1056
         }
1057 1057
         $addon->set_name($addon_name);
1058
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1059
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1060
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1061
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1062
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1063
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
1064
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1065
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1066
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1067
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1058
+        $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']);
1059
+        $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']);
1060
+        $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']);
1061
+        $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']);
1062
+        $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']);
1063
+        $addon->set_version(self::$_settings[$addon_name]['version']);
1064
+        $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version']));
1065
+        $addon->set_config_section(self::$_settings[$addon_name]['config_section']);
1066
+        $addon->set_config_class(self::$_settings[$addon_name]['config_class']);
1067
+        $addon->set_config_name(self::$_settings[$addon_name]['config_name']);
1068 1068
         // unfortunately this can't be hooked in upon construction, because we don't have
1069 1069
         // the plugin mainfile's path upon construction.
1070 1070
         register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
1071 1071
         // call any additional admin_callback functions during load_admin_controller hook
1072
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1072
+        if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) {
1073 1073
             add_action(
1074 1074
                 'AHEE__EE_System__load_controllers__load_admin_controllers',
1075
-                array($addon, self::$_settings[ $addon_name ]['admin_callback'])
1075
+                array($addon, self::$_settings[$addon_name]['admin_callback'])
1076 1076
             );
1077 1077
         }
1078 1078
         return $addon;
@@ -1090,11 +1090,11 @@  discard block
 block discarded – undo
1090 1090
     public static function load_pue_update()
1091 1091
     {
1092 1092
         // load PUE client
1093
-        require_once EE_THIRD_PARTY . 'pue/pue-client.php';
1093
+        require_once EE_THIRD_PARTY.'pue/pue-client.php';
1094 1094
         $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
1095 1095
         // cycle thru settings
1096 1096
         foreach (self::$_settings as $settings) {
1097
-            if (! empty($settings['pue_options'])) {
1097
+            if ( ! empty($settings['pue_options'])) {
1098 1098
                 // initiate the class and start the plugin update engine!
1099 1099
                 new PluginUpdateEngineChecker(
1100 1100
                     // host file URL
@@ -1102,7 +1102,7 @@  discard block
 block discarded – undo
1102 1102
                     // plugin slug(s)
1103 1103
                     array(
1104 1104
                         'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1105
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1105
+                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'),
1106 1106
                     ),
1107 1107
                     // options
1108 1108
                     array(
@@ -1131,7 +1131,7 @@  discard block
 block discarded – undo
1131 1131
     public static function register_message_types()
1132 1132
     {
1133 1133
         foreach (self::$_settings as $addon_name => $settings) {
1134
-            if (! empty($settings['message_types'])) {
1134
+            if ( ! empty($settings['message_types'])) {
1135 1135
                 foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1136 1136
                     EE_Register_Message_Type::register($message_type, $message_type_settings);
1137 1137
                 }
@@ -1153,70 +1153,70 @@  discard block
 block discarded – undo
1153 1153
      */
1154 1154
     public static function deregister($addon_name = null)
1155 1155
     {
1156
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1156
+        if (isset(self::$_settings[$addon_name]['class_name'])) {
1157 1157
             try {
1158 1158
                 do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1159
-                $class_name = self::$_settings[ $addon_name ]['class_name'];
1160
-                if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1159
+                $class_name = self::$_settings[$addon_name]['class_name'];
1160
+                if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
1161 1161
                     // setup DMS
1162 1162
                     EE_Register_Data_Migration_Scripts::deregister($addon_name);
1163 1163
                 }
1164
-                if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1164
+                if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
1165 1165
                     // register admin page
1166 1166
                     EE_Register_Admin_Page::deregister($addon_name);
1167 1167
                 }
1168
-                if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1168
+                if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
1169 1169
                     // add to list of modules to be registered
1170 1170
                     EE_Register_Module::deregister($addon_name);
1171 1171
                 }
1172
-                if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1173
-                    || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1172
+                if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])
1173
+                    || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
1174 1174
                 ) {
1175 1175
                     // add to list of shortcodes to be registered
1176 1176
                     EE_Register_Shortcode::deregister($addon_name);
1177 1177
                 }
1178
-                if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1178
+                if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
1179 1179
                     // if config_class present let's register config.
1180
-                    EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1180
+                    EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1181 1181
                 }
1182
-                if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1182
+                if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
1183 1183
                     // add to list of widgets to be registered
1184 1184
                     EE_Register_Widget::deregister($addon_name);
1185 1185
                 }
1186
-                if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1187
-                    || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1186
+                if ( ! empty(self::$_settings[$addon_name]['model_paths'])
1187
+                    || ! empty(self::$_settings[$addon_name]['class_paths'])
1188 1188
                 ) {
1189 1189
                     // add to list of shortcodes to be registered
1190 1190
                     EE_Register_Model::deregister($addon_name);
1191 1191
                 }
1192
-                if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1193
-                    || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1192
+                if ( ! empty(self::$_settings[$addon_name]['model_extension_paths'])
1193
+                    || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
1194 1194
                 ) {
1195 1195
                     // add to list of shortcodes to be registered
1196 1196
                     EE_Register_Model_Extensions::deregister($addon_name);
1197 1197
                 }
1198
-                if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1199
-                    foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1198
+                if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
1199
+                    foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1200 1200
                         EE_Register_Message_Type::deregister($message_type);
1201 1201
                     }
1202 1202
                 }
1203 1203
                 // deregister capabilities for addon
1204
-                if (! empty(self::$_settings[ $addon_name ]['capabilities'])
1205
-                    || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1204
+                if ( ! empty(self::$_settings[$addon_name]['capabilities'])
1205
+                    || ! empty(self::$_settings[$addon_name]['capability_maps'])
1206 1206
                 ) {
1207 1207
                     EE_Register_Capabilities::deregister($addon_name);
1208 1208
                 }
1209 1209
                 // deregister custom_post_types for addon
1210
-                if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1210
+                if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1211 1211
                     EE_Register_CPT::deregister($addon_name);
1212 1212
                 }
1213
-                if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1213
+                if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1214 1214
                     EE_Register_Payment_Method::deregister($addon_name);
1215 1215
                 }
1216 1216
                 $addon = EE_Registry::instance()->getAddon($class_name);
1217 1217
                 if ($addon instanceof EE_Addon) {
1218 1218
                     remove_action(
1219
-                        'deactivate_' . $addon->get_main_plugin_file_basename(),
1219
+                        'deactivate_'.$addon->get_main_plugin_file_basename(),
1220 1220
                         array($addon, 'deactivation')
1221 1221
                     );
1222 1222
                     remove_action(
@@ -1239,7 +1239,7 @@  discard block
 block discarded – undo
1239 1239
             } catch (Exception $e) {
1240 1240
                 new ExceptionLogger($e);
1241 1241
             }
1242
-            unset(self::$_settings[ $addon_name ]);
1242
+            unset(self::$_settings[$addon_name]);
1243 1243
             do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1244 1244
         }
1245 1245
     }
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Proper.form.php 2 patches
Indentation   +1524 added lines, -1524 removed lines patch added patch discarded remove patch
@@ -14,1528 +14,1528 @@
 block discarded – undo
14 14
 class EE_Form_Section_Proper extends EE_Form_Section_Validatable
15 15
 {
16 16
 
17
-    const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
-
19
-    /**
20
-     * Subsections
21
-     *
22
-     * @var EE_Form_Section_Validatable[]
23
-     */
24
-    protected $_subsections = array();
25
-
26
-    /**
27
-     * Strategy for laying out the form
28
-     *
29
-     * @var EE_Form_Section_Layout_Base
30
-     */
31
-    protected $_layout_strategy;
32
-
33
-    /**
34
-     * Whether or not this form has received and validated a form submission yet
35
-     *
36
-     * @var boolean
37
-     */
38
-    protected $_received_submission = false;
39
-
40
-    /**
41
-     * message displayed to users upon successful form submission
42
-     *
43
-     * @var string
44
-     */
45
-    protected $_form_submission_success_message = '';
46
-
47
-    /**
48
-     * message displayed to users upon unsuccessful form submission
49
-     *
50
-     * @var string
51
-     */
52
-    protected $_form_submission_error_message = '';
53
-
54
-    /**
55
-     * @var array like $_REQUEST
56
-     */
57
-    protected $cached_request_data;
58
-
59
-    /**
60
-     * Stores whether this form (and its sub-sections) were found to be valid or not.
61
-     * Starts off as null, but once the form is validated, it set to either true or false
62
-     * @var boolean|null
63
-     */
64
-    protected $is_valid;
65
-
66
-    /**
67
-     * Stores all the data that will localized for form validation
68
-     *
69
-     * @var array
70
-     */
71
-    static protected $_js_localization = array();
72
-
73
-    /**
74
-     * whether or not the form's localized validation JS vars have been set
75
-     *
76
-     * @type boolean
77
-     */
78
-    static protected $_scripts_localized = false;
79
-
80
-
81
-    /**
82
-     * when constructing a proper form section, calls _construct_finalize on children
83
-     * so that they know who their parent is, and what name they've been given.
84
-     *
85
-     * @param array[] $options_array   {
86
-     * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
-     * @type          $include         string[] numerically-indexed where values are section names to be included,
88
-     *                                 and in that order. This is handy if you want
89
-     *                                 the subsections to be ordered differently than the default, and if you override
90
-     *                                 which fields are shown
91
-     * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
-     *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
-     *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
-     *                                 items from that list of inclusions)
95
-     * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
-     *                                 } @see EE_Form_Section_Validatable::__construct()
97
-     * @throws EE_Error
98
-     */
99
-    public function __construct($options_array = array())
100
-    {
101
-        $options_array = (array) apply_filters(
102
-            'FHEE__EE_Form_Section_Proper___construct__options_array',
103
-            $options_array,
104
-            $this
105
-        );
106
-        // call parent first, as it may be setting the name
107
-        parent::__construct($options_array);
108
-        // if they've included subsections in the constructor, add them now
109
-        if (isset($options_array['include'])) {
110
-            // we are going to make sure we ONLY have those subsections to include
111
-            // AND we are going to make sure they're in that specified order
112
-            $reordered_subsections = array();
113
-            foreach ($options_array['include'] as $input_name) {
114
-                if (isset($this->_subsections[ $input_name ])) {
115
-                    $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
-                }
117
-            }
118
-            $this->_subsections = $reordered_subsections;
119
-        }
120
-        if (isset($options_array['exclude'])) {
121
-            $exclude            = $options_array['exclude'];
122
-            $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
-        }
124
-        if (isset($options_array['layout_strategy'])) {
125
-            $this->_layout_strategy = $options_array['layout_strategy'];
126
-        }
127
-        if (! $this->_layout_strategy) {
128
-            $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
-        }
130
-        $this->_layout_strategy->_construct_finalize($this);
131
-        // ok so we are definitely going to want the forms JS,
132
-        // so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
-            // ok so they've constructed this object after when they should have.
135
-            // just enqueue the generic form scripts and initialize the form immediately in the JS
136
-            EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
-        } else {
138
-            add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
-            add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
-        }
141
-        add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
-        /**
143
-         * Gives other plugins a chance to hook in before construct finalize is called.
144
-         * The form probably doesn't yet have a parent form section.
145
-         * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
-         * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
-         * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
-         *
149
-         * @since 4.9.32
150
-         * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
-         *                                              except maybe calling _construct_finalize has been done
152
-         * @param array                  $options_array options passed into the constructor
153
-         */
154
-        do_action(
155
-            'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
-            $this,
157
-            $options_array
158
-        );
159
-        if (isset($options_array['name'])) {
160
-            $this->_construct_finalize(null, $options_array['name']);
161
-        }
162
-    }
163
-
164
-
165
-    /**
166
-     * Finishes construction given the parent form section and this form section's name
167
-     *
168
-     * @param EE_Form_Section_Proper $parent_form_section
169
-     * @param string                 $name
170
-     * @throws EE_Error
171
-     */
172
-    public function _construct_finalize($parent_form_section, $name)
173
-    {
174
-        parent::_construct_finalize($parent_form_section, $name);
175
-        $this->_set_default_name_if_empty();
176
-        $this->_set_default_html_id_if_empty();
177
-        foreach ($this->_subsections as $subsection_name => $subsection) {
178
-            if ($subsection instanceof EE_Form_Section_Base) {
179
-                $subsection->_construct_finalize($this, $subsection_name);
180
-            } else {
181
-                throw new EE_Error(
182
-                    sprintf(
183
-                        esc_html__(
184
-                            'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
-                            'event_espresso'
186
-                        ),
187
-                        $subsection_name,
188
-                        get_class($this),
189
-                        $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
-                    )
191
-                );
192
-            }
193
-        }
194
-        /**
195
-         * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
-         * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
-         * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
-         * This might only happen just before displaying the form, or just before it receives form submission data.
199
-         * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
-         * ensured it has a name, HTML IDs, etc
201
-         *
202
-         * @param EE_Form_Section_Proper      $this
203
-         * @param EE_Form_Section_Proper|null $parent_form_section
204
-         * @param string                      $name
205
-         */
206
-        do_action(
207
-            'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
-            $this,
209
-            $parent_form_section,
210
-            $name
211
-        );
212
-    }
213
-
214
-
215
-    /**
216
-     * Gets the layout strategy for this form section
217
-     *
218
-     * @return EE_Form_Section_Layout_Base
219
-     */
220
-    public function get_layout_strategy()
221
-    {
222
-        return $this->_layout_strategy;
223
-    }
224
-
225
-
226
-    /**
227
-     * Gets the HTML for a single input for this form section according
228
-     * to the layout strategy
229
-     *
230
-     * @param EE_Form_Input_Base $input
231
-     * @return string
232
-     */
233
-    public function get_html_for_input($input)
234
-    {
235
-        return $this->_layout_strategy->layout_input($input);
236
-    }
237
-
238
-
239
-    /**
240
-     * was_submitted - checks if form inputs are present in request data
241
-     * Basically an alias for form_data_present_in() (which is used by both
242
-     * proper form sections and form inputs)
243
-     *
244
-     * @param null $form_data
245
-     * @return boolean
246
-     * @throws EE_Error
247
-     */
248
-    public function was_submitted($form_data = null)
249
-    {
250
-        return $this->form_data_present_in($form_data);
251
-    }
252
-
253
-    /**
254
-     * Gets the cached request data; but if there is none, or $req_data was set with
255
-     * something different, refresh the cache, and then return it
256
-     * @param null $req_data
257
-     * @return array
258
-     */
259
-    protected function getCachedRequest($req_data = null)
260
-    {
261
-        if ($this->cached_request_data === null
262
-            || (
263
-                $req_data !== null &&
264
-                $req_data !== $this->cached_request_data
265
-            )
266
-        ) {
267
-            $req_data = apply_filters(
268
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
269
-                $req_data,
270
-                $this
271
-            );
272
-            if ($req_data === null) {
273
-                $req_data = array_merge($_GET, $_POST);
274
-            }
275
-            $req_data = apply_filters(
276
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
277
-                $req_data,
278
-                $this
279
-            );
280
-            $this->cached_request_data = (array) $req_data;
281
-        }
282
-        return $this->cached_request_data;
283
-    }
284
-
285
-
286
-    /**
287
-     * After the form section is initially created, call this to sanitize the data in the submission
288
-     * which relates to this form section, validate it, and set it as properties on the form.
289
-     *
290
-     * @param array|null $req_data should usually be $_POST (the default).
291
-     *                             However, you CAN supply a different array.
292
-     *                             Consider using set_defaults() instead however.
293
-     *                             (If you rendered the form in the page using echo $form_x->get_html()
294
-     *                             the inputs will have the correct name in the request data for this function
295
-     *                             to find them and populate the form with them.
296
-     *                             If you have a flat form (with only input subsections),
297
-     *                             you can supply a flat array where keys
298
-     *                             are the form input names and values are their values)
299
-     * @param boolean    $validate whether or not to perform validation on this data. Default is,
300
-     *                             of course, to validate that data, and set errors on the invalid values.
301
-     *                             But if the data has already been validated
302
-     *                             (eg you validated the data then stored it in the DB)
303
-     *                             you may want to skip this step.
304
-     * @throws InvalidArgumentException
305
-     * @throws InvalidInterfaceException
306
-     * @throws InvalidDataTypeException
307
-     * @throws EE_Error
308
-     */
309
-    public function receive_form_submission($req_data = null, $validate = true)
310
-    {
311
-        $req_data = $this->getCachedRequest($req_data);
312
-        $this->_normalize($req_data);
313
-        if ($validate) {
314
-            $this->_validate();
315
-            // if it's invalid, we're going to want to re-display so remember what they submitted
316
-            if (! $this->is_valid()) {
317
-                $this->store_submitted_form_data_in_session();
318
-            }
319
-        }
320
-        if ($this->submission_error_message() === '' && ! $this->is_valid()) {
321
-            $this->set_submission_error_message();
322
-        }
323
-        do_action(
324
-            'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
325
-            $req_data,
326
-            $this,
327
-            $validate
328
-        );
329
-    }
330
-
331
-
332
-    /**
333
-     * caches the originally submitted input values in the session
334
-     * so that they can be used to repopulate the form if it failed validation
335
-     *
336
-     * @return boolean whether or not the data was successfully stored in the session
337
-     * @throws InvalidArgumentException
338
-     * @throws InvalidInterfaceException
339
-     * @throws InvalidDataTypeException
340
-     * @throws EE_Error
341
-     */
342
-    protected function store_submitted_form_data_in_session()
343
-    {
344
-        return EE_Registry::instance()->SSN->set_session_data(
345
-            array(
346
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
347
-            )
348
-        );
349
-    }
350
-
351
-
352
-    /**
353
-     * retrieves the originally submitted input values in the session
354
-     * so that they can be used to repopulate the form if it failed validation
355
-     *
356
-     * @return array
357
-     * @throws InvalidArgumentException
358
-     * @throws InvalidInterfaceException
359
-     * @throws InvalidDataTypeException
360
-     */
361
-    protected function get_submitted_form_data_from_session()
362
-    {
363
-        $session = EE_Registry::instance()->SSN;
364
-        if ($session instanceof EE_Session) {
365
-            return $session->get_session_data(
366
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
367
-            );
368
-        }
369
-        return array();
370
-    }
371
-
372
-
373
-    /**
374
-     * flushed the originally submitted input values from the session
375
-     *
376
-     * @return boolean whether or not the data was successfully removed from the session
377
-     * @throws InvalidArgumentException
378
-     * @throws InvalidInterfaceException
379
-     * @throws InvalidDataTypeException
380
-     */
381
-    public static function flush_submitted_form_data_from_session()
382
-    {
383
-        return EE_Registry::instance()->SSN->reset_data(
384
-            array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
385
-        );
386
-    }
387
-
388
-
389
-    /**
390
-     * Populates this form and its subsections with data from the session.
391
-     * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
392
-     * validation errors when displaying too)
393
-     * Returns true if the form was populated from the session, false otherwise
394
-     *
395
-     * @return boolean
396
-     * @throws InvalidArgumentException
397
-     * @throws InvalidInterfaceException
398
-     * @throws InvalidDataTypeException
399
-     * @throws EE_Error
400
-     */
401
-    public function populate_from_session()
402
-    {
403
-        $form_data_in_session = $this->get_submitted_form_data_from_session();
404
-        if (empty($form_data_in_session)) {
405
-            return false;
406
-        }
407
-        $this->receive_form_submission($form_data_in_session);
408
-        add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session'));
409
-        if ($this->form_data_present_in($form_data_in_session)) {
410
-            return true;
411
-        }
412
-        return false;
413
-    }
414
-
415
-
416
-    /**
417
-     * Populates the default data for the form, given an array where keys are
418
-     * the input names, and values are their values (preferably normalized to be their
419
-     * proper PHP types, not all strings... although that should be ok too).
420
-     * Proper subsections are sub-arrays, the key being the subsection's name, and
421
-     * the value being an array formatted in teh same way
422
-     *
423
-     * @param array $default_data
424
-     * @throws EE_Error
425
-     */
426
-    public function populate_defaults($default_data)
427
-    {
428
-        foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
-            if (isset($default_data[ $subsection_name ])) {
430
-                if ($subsection instanceof EE_Form_Input_Base) {
431
-                    $subsection->set_default($default_data[ $subsection_name ]);
432
-                } elseif ($subsection instanceof EE_Form_Section_Proper) {
433
-                    $subsection->populate_defaults($default_data[ $subsection_name ]);
434
-                }
435
-            }
436
-        }
437
-    }
438
-
439
-
440
-    /**
441
-     * returns true if subsection exists
442
-     *
443
-     * @param string $name
444
-     * @return boolean
445
-     */
446
-    public function subsection_exists($name)
447
-    {
448
-        return isset($this->_subsections[ $name ]) ? true : false;
449
-    }
450
-
451
-
452
-    /**
453
-     * Gets the subsection specified by its name
454
-     *
455
-     * @param string  $name
456
-     * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
457
-     *                                                      so that the inputs will be properly configured.
458
-     *                                                      However, some client code may be ok
459
-     *                                                      with construction finalize being called later
460
-     *                                                      (realizing that the subsections' html names
461
-     *                                                      might not be set yet, etc.)
462
-     * @return EE_Form_Section_Base
463
-     * @throws EE_Error
464
-     */
465
-    public function get_subsection($name, $require_construction_to_be_finalized = true)
466
-    {
467
-        if ($require_construction_to_be_finalized) {
468
-            $this->ensure_construct_finalized_called();
469
-        }
470
-        return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
471
-    }
472
-
473
-
474
-    /**
475
-     * Gets all the validatable subsections of this form section
476
-     *
477
-     * @return EE_Form_Section_Validatable[]
478
-     * @throws EE_Error
479
-     */
480
-    public function get_validatable_subsections()
481
-    {
482
-        $validatable_subsections = array();
483
-        foreach ($this->subsections() as $name => $obj) {
484
-            if ($obj instanceof EE_Form_Section_Validatable) {
485
-                $validatable_subsections[ $name ] = $obj;
486
-            }
487
-        }
488
-        return $validatable_subsections;
489
-    }
490
-
491
-
492
-    /**
493
-     * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
494
-     * throw an EE_Error.
495
-     *
496
-     * @param string  $name
497
-     * @param boolean $require_construction_to_be_finalized most client code should
498
-     *                                                      leave this as TRUE so that the inputs will be properly
499
-     *                                                      configured. However, some client code may be ok with
500
-     *                                                      construction finalize being called later
501
-     *                                                      (realizing that the subsections' html names might not be
502
-     *                                                      set yet, etc.)
503
-     * @return EE_Form_Input_Base
504
-     * @throws EE_Error
505
-     */
506
-    public function get_input($name, $require_construction_to_be_finalized = true)
507
-    {
508
-        $subsection = $this->get_subsection(
509
-            $name,
510
-            $require_construction_to_be_finalized
511
-        );
512
-        if (! $subsection instanceof EE_Form_Input_Base) {
513
-            throw new EE_Error(
514
-                sprintf(
515
-                    esc_html__(
516
-                        "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
517
-                        'event_espresso'
518
-                    ),
519
-                    $name,
520
-                    get_class($this),
521
-                    $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
522
-                )
523
-            );
524
-        }
525
-        return $subsection;
526
-    }
527
-
528
-
529
-    /**
530
-     * Like get_input(), gets the proper subsection of the form given the name,
531
-     * otherwise throws an EE_Error
532
-     *
533
-     * @param string  $name
534
-     * @param boolean $require_construction_to_be_finalized most client code should
535
-     *                                                      leave this as TRUE so that the inputs will be properly
536
-     *                                                      configured. However, some client code may be ok with
537
-     *                                                      construction finalize being called later
538
-     *                                                      (realizing that the subsections' html names might not be
539
-     *                                                      set yet, etc.)
540
-     * @return EE_Form_Section_Proper
541
-     * @throws EE_Error
542
-     */
543
-    public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
544
-    {
545
-        $subsection = $this->get_subsection(
546
-            $name,
547
-            $require_construction_to_be_finalized
548
-        );
549
-        if (! $subsection instanceof EE_Form_Section_Proper) {
550
-            throw new EE_Error(
551
-                sprintf(
552
-                    esc_html__(
553
-                        "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
554
-                        'event_espresso'
555
-                    ),
556
-                    $name,
557
-                    get_class($this)
558
-                )
559
-            );
560
-        }
561
-        return $subsection;
562
-    }
563
-
564
-
565
-    /**
566
-     * Gets the value of the specified input. Should be called after receive_form_submission()
567
-     * or populate_defaults() on the form, where the normalized value on the input is set.
568
-     *
569
-     * @param string $name
570
-     * @return mixed depending on the input's type and its normalization strategy
571
-     * @throws EE_Error
572
-     */
573
-    public function get_input_value($name)
574
-    {
575
-        $input = $this->get_input($name);
576
-        return $input->normalized_value();
577
-    }
578
-
579
-
580
-    /**
581
-     * Checks if this form section itself is valid, and then checks its subsections
582
-     *
583
-     * @throws EE_Error
584
-     * @return boolean
585
-     */
586
-    public function is_valid()
587
-    {
588
-        if ($this->is_valid === null) {
589
-            if (! $this->has_received_submission()) {
590
-                throw new EE_Error(
591
-                    sprintf(
592
-                        esc_html__(
593
-                            'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
594
-                            'event_espresso'
595
-                        )
596
-                    )
597
-                );
598
-            }
599
-            if (! parent::is_valid()) {
600
-                $this->is_valid = false;
601
-            } else {
602
-                // ok so no general errors to this entire form section.
603
-                // so let's check the subsections, but only set errors if that hasn't been done yet
604
-                $this->is_valid = true;
605
-                foreach ($this->get_validatable_subsections() as $subsection) {
606
-                    if (! $subsection->is_valid()) {
607
-                        $this->is_valid = false;
608
-                    }
609
-                }
610
-            }
611
-        }
612
-        return $this->is_valid;
613
-    }
614
-
615
-
616
-    /**
617
-     * gets the default name of this form section if none is specified
618
-     *
619
-     * @return void
620
-     */
621
-    protected function _set_default_name_if_empty()
622
-    {
623
-        if (! $this->_name) {
624
-            $classname    = get_class($this);
625
-            $default_name = str_replace('EE_', '', $classname);
626
-            $this->_name  = $default_name;
627
-        }
628
-    }
629
-
630
-
631
-    /**
632
-     * Returns the HTML for the form, except for the form opening and closing tags
633
-     * (as the form section doesn't know where you necessarily want to send the information to),
634
-     * and except for a submit button. Enqueues JS and CSS; if called early enough we will
635
-     * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
636
-     * Not doing_it_wrong because theoretically this CAN be used properly,
637
-     * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
638
-     * any CSS.
639
-     *
640
-     * @throws InvalidArgumentException
641
-     * @throws InvalidInterfaceException
642
-     * @throws InvalidDataTypeException
643
-     * @throws EE_Error
644
-     */
645
-    public function get_html_and_js()
646
-    {
647
-        $this->enqueue_js();
648
-        return $this->get_html();
649
-    }
650
-
651
-
652
-    /**
653
-     * returns HTML for displaying this form section. recursively calls display_section() on all subsections
654
-     *
655
-     * @param bool $display_previously_submitted_data
656
-     * @return string
657
-     * @throws InvalidArgumentException
658
-     * @throws InvalidInterfaceException
659
-     * @throws InvalidDataTypeException
660
-     * @throws EE_Error
661
-     * @throws EE_Error
662
-     * @throws EE_Error
663
-     */
664
-    public function get_html($display_previously_submitted_data = true)
665
-    {
666
-        $this->ensure_construct_finalized_called();
667
-        if ($display_previously_submitted_data) {
668
-            $this->populate_from_session();
669
-        }
670
-        return $this->_form_html_filter
671
-            ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
672
-            : $this->_layout_strategy->layout_form();
673
-    }
674
-
675
-
676
-    /**
677
-     * enqueues JS and CSS for the form.
678
-     * It is preferred to call this before wp_enqueue_scripts so the
679
-     * scripts and styles can be put in the header, but if called later
680
-     * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
681
-     * only be in the header; but in HTML5 its ok in the body.
682
-     * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
683
-     * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
684
-     *
685
-     * @return void
686
-     * @throws EE_Error
687
-     */
688
-    public function enqueue_js()
689
-    {
690
-        $this->_enqueue_and_localize_form_js();
691
-        foreach ($this->subsections() as $subsection) {
692
-            $subsection->enqueue_js();
693
-        }
694
-    }
695
-
696
-
697
-    /**
698
-     * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
699
-     * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
700
-     * the wp_enqueue_scripts hook.
701
-     * However, registering the form js and localizing it can happen when we
702
-     * actually output the form (which is preferred, seeing how teh form's fields
703
-     * could change until it's actually outputted)
704
-     *
705
-     * @param boolean $init_form_validation_automatically whether or not we want the form validation
706
-     *                                                    to be triggered automatically or not
707
-     * @return void
708
-     */
709
-    public static function wp_enqueue_scripts($init_form_validation_automatically = true)
710
-    {
711
-        wp_register_script(
712
-            'ee_form_section_validation',
713
-            EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js',
714
-            array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715
-            EVENT_ESPRESSO_VERSION,
716
-            true
717
-        );
718
-        wp_localize_script(
719
-            'ee_form_section_validation',
720
-            'ee_form_section_validation_init',
721
-            array('init' => $init_form_validation_automatically ? '1' : '0')
722
-        );
723
-    }
724
-
725
-
726
-    /**
727
-     * gets the variables used by form_section_validation.js.
728
-     * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
729
-     * but before the wordpress hook wp_loaded
730
-     *
731
-     * @throws EE_Error
732
-     */
733
-    public function _enqueue_and_localize_form_js()
734
-    {
735
-        $this->ensure_construct_finalized_called();
736
-        // actually, we don't want to localize just yet. There may be other forms on the page.
737
-        // so we need to add our form section data to a static variable accessible by all form sections
738
-        // and localize it just before the footer
739
-        $this->localize_validation_rules();
740
-        add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
741
-        add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
742
-    }
743
-
744
-
745
-    /**
746
-     * add our form section data to a static variable accessible by all form sections
747
-     *
748
-     * @param bool $return_for_subsection
749
-     * @return void
750
-     * @throws EE_Error
751
-     */
752
-    public function localize_validation_rules($return_for_subsection = false)
753
-    {
754
-        // we only want to localize vars ONCE for the entire form,
755
-        // so if the form section doesn't have a parent, then it must be the top dog
756
-        if ($return_for_subsection || ! $this->parent_section()) {
757
-            EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
758
-                'form_section_id'  => $this->html_id(true),
759
-                'validation_rules' => $this->get_jquery_validation_rules(),
760
-                'other_data'       => $this->get_other_js_data(),
761
-                'errors'           => $this->subsection_validation_errors_by_html_name(),
762
-            );
763
-            EE_Form_Section_Proper::$_scripts_localized                                = true;
764
-        }
765
-    }
766
-
767
-
768
-    /**
769
-     * Gets an array of extra data that will be useful for client-side javascript.
770
-     * This is primarily data added by inputs and forms in addition to any
771
-     * scripts they might enqueue
772
-     *
773
-     * @param array $form_other_js_data
774
-     * @return array
775
-     * @throws EE_Error
776
-     */
777
-    public function get_other_js_data($form_other_js_data = array())
778
-    {
779
-        foreach ($this->subsections() as $subsection) {
780
-            $form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
781
-        }
782
-        return $form_other_js_data;
783
-    }
784
-
785
-
786
-    /**
787
-     * Gets a flat array of inputs for this form section and its subsections.
788
-     * Keys are their form names, and values are the inputs themselves
789
-     *
790
-     * @return EE_Form_Input_Base
791
-     * @throws EE_Error
792
-     */
793
-    public function inputs_in_subsections()
794
-    {
795
-        $inputs = array();
796
-        foreach ($this->subsections() as $subsection) {
797
-            if ($subsection instanceof EE_Form_Input_Base) {
798
-                $inputs[ $subsection->html_name() ] = $subsection;
799
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
800
-                $inputs += $subsection->inputs_in_subsections();
801
-            }
802
-        }
803
-        return $inputs;
804
-    }
805
-
806
-
807
-    /**
808
-     * Gets a flat array of all the validation errors.
809
-     * Keys are html names (because those should be unique)
810
-     * and values are a string of all their validation errors
811
-     *
812
-     * @return string[]
813
-     * @throws EE_Error
814
-     */
815
-    public function subsection_validation_errors_by_html_name()
816
-    {
817
-        $inputs = $this->inputs();
818
-        $errors = array();
819
-        foreach ($inputs as $form_input) {
820
-            if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
-                $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
822
-            }
823
-        }
824
-        return $errors;
825
-    }
826
-
827
-
828
-    /**
829
-     * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
830
-     * Should be setup by each form during the _enqueues_and_localize_form_js
831
-     *
832
-     * @throws InvalidArgumentException
833
-     * @throws InvalidInterfaceException
834
-     * @throws InvalidDataTypeException
835
-     */
836
-    public static function localize_script_for_all_forms()
837
-    {
838
-        // allow inputs and stuff to hook in their JS and stuff here
839
-        do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
840
-        EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
841
-        $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
843
-            : 'wp_default';
844
-        EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
845
-        wp_enqueue_script('ee_form_section_validation');
846
-        wp_localize_script(
847
-            'ee_form_section_validation',
848
-            'ee_form_section_vars',
849
-            EE_Form_Section_Proper::$_js_localization
850
-        );
851
-    }
852
-
853
-
854
-    /**
855
-     * ensure_scripts_localized
856
-     *
857
-     * @throws EE_Error
858
-     */
859
-    public function ensure_scripts_localized()
860
-    {
861
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
862
-            $this->_enqueue_and_localize_form_js();
863
-        }
864
-    }
865
-
866
-
867
-    /**
868
-     * Gets the hard-coded validation error messages to be used in the JS. The convention
869
-     * is that the key here should be the same as the custom validation rule put in the JS file
870
-     *
871
-     * @return array keys are custom validation rules, and values are internationalized strings
872
-     */
873
-    private static function _get_localized_error_messages()
874
-    {
875
-        return array(
876
-            'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'),
877
-            'regex'    => esc_html__('Please check your input', 'event_espresso'),
878
-        );
879
-    }
880
-
881
-
882
-    /**
883
-     * @return array
884
-     */
885
-    public static function js_localization()
886
-    {
887
-        return self::$_js_localization;
888
-    }
889
-
890
-
891
-    /**
892
-     * @return void
893
-     */
894
-    public static function reset_js_localization()
895
-    {
896
-        self::$_js_localization = array();
897
-    }
898
-
899
-
900
-    /**
901
-     * Gets the JS to put inside the jquery validation rules for subsection of this form section.
902
-     * See parent function for more...
903
-     *
904
-     * @return array
905
-     * @throws EE_Error
906
-     */
907
-    public function get_jquery_validation_rules()
908
-    {
909
-        $jquery_validation_rules = array();
910
-        foreach ($this->get_validatable_subsections() as $subsection) {
911
-            $jquery_validation_rules = array_merge(
912
-                $jquery_validation_rules,
913
-                $subsection->get_jquery_validation_rules()
914
-            );
915
-        }
916
-        return $jquery_validation_rules;
917
-    }
918
-
919
-
920
-    /**
921
-     * Sanitizes all the data and sets the sanitized value of each field
922
-     *
923
-     * @param array $req_data like $_POST
924
-     * @return void
925
-     * @throws EE_Error
926
-     */
927
-    protected function _normalize($req_data)
928
-    {
929
-        $this->_received_submission = true;
930
-        $this->_validation_errors   = array();
931
-        foreach ($this->get_validatable_subsections() as $subsection) {
932
-            try {
933
-                $subsection->_normalize($req_data);
934
-            } catch (EE_Validation_Error $e) {
935
-                $subsection->add_validation_error($e);
936
-            }
937
-        }
938
-    }
939
-
940
-
941
-    /**
942
-     * Performs validation on this form section and its subsections.
943
-     * For each subsection,
944
-     * calls _validate_{subsection_name} on THIS form (if the function exists)
945
-     * and passes it the subsection, then calls _validate on that subsection.
946
-     * If you need to perform validation on the form as a whole (considering multiple)
947
-     * you would be best to override this _validate method,
948
-     * calling parent::_validate() first.
949
-     *
950
-     * @throws EE_Error
951
-     */
952
-    protected function _validate()
953
-    {
954
-        // reset the cache of whether this form is valid or not- we're re-validating it now
955
-        $this->is_valid = null;
956
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
-            if (method_exists($this, '_validate_' . $subsection_name)) {
958
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
959
-            }
960
-            $subsection->_validate();
961
-        }
962
-    }
963
-
964
-
965
-    /**
966
-     * Gets all the validated inputs for the form section
967
-     *
968
-     * @return array
969
-     * @throws EE_Error
970
-     */
971
-    public function valid_data()
972
-    {
973
-        $inputs = array();
974
-        foreach ($this->subsections() as $subsection_name => $subsection) {
975
-            if ($subsection instanceof EE_Form_Section_Proper) {
976
-                $inputs[ $subsection_name ] = $subsection->valid_data();
977
-            } elseif ($subsection instanceof EE_Form_Input_Base) {
978
-                $inputs[ $subsection_name ] = $subsection->normalized_value();
979
-            }
980
-        }
981
-        return $inputs;
982
-    }
983
-
984
-
985
-    /**
986
-     * Gets all the inputs on this form section
987
-     *
988
-     * @return EE_Form_Input_Base[]
989
-     * @throws EE_Error
990
-     */
991
-    public function inputs()
992
-    {
993
-        $inputs = array();
994
-        foreach ($this->subsections() as $subsection_name => $subsection) {
995
-            if ($subsection instanceof EE_Form_Input_Base) {
996
-                $inputs[ $subsection_name ] = $subsection;
997
-            }
998
-        }
999
-        return $inputs;
1000
-    }
1001
-
1002
-
1003
-    /**
1004
-     * Gets all the subsections which are a proper form
1005
-     *
1006
-     * @return EE_Form_Section_Proper[]
1007
-     * @throws EE_Error
1008
-     */
1009
-    public function subforms()
1010
-    {
1011
-        $form_sections = array();
1012
-        foreach ($this->subsections() as $name => $obj) {
1013
-            if ($obj instanceof EE_Form_Section_Proper) {
1014
-                $form_sections[ $name ] = $obj;
1015
-            }
1016
-        }
1017
-        return $form_sections;
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * Gets all the subsections (inputs, proper subsections, or html-only sections).
1023
-     * Consider using inputs() or subforms()
1024
-     * if you only want form inputs or proper form sections.
1025
-     *
1026
-     * @param boolean $require_construction_to_be_finalized most client code should
1027
-     *                                                      leave this as TRUE so that the inputs will be properly
1028
-     *                                                      configured. However, some client code may be ok with
1029
-     *                                                      construction finalize being called later
1030
-     *                                                      (realizing that the subsections' html names might not be
1031
-     *                                                      set yet, etc.)
1032
-     * @return EE_Form_Section_Proper[]
1033
-     * @throws EE_Error
1034
-     */
1035
-    public function subsections($require_construction_to_be_finalized = true)
1036
-    {
1037
-        if ($require_construction_to_be_finalized) {
1038
-            $this->ensure_construct_finalized_called();
1039
-        }
1040
-        return $this->_subsections;
1041
-    }
1042
-
1043
-
1044
-    /**
1045
-     * Returns whether this form has any subforms or inputs
1046
-     * @return bool
1047
-     */
1048
-    public function hasSubsections()
1049
-    {
1050
-        return ! empty($this->_subsections);
1051
-    }
1052
-
1053
-
1054
-    /**
1055
-     * Returns a simple array where keys are input names, and values are their normalized
1056
-     * values. (Similar to calling get_input_value on inputs)
1057
-     *
1058
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1059
-     *                                        or just this forms' direct children inputs
1060
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1061
-     *                                        or allow multidimensional array
1062
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1063
-     *                                        with array keys being input names
1064
-     *                                        (regardless of whether they are from a subsection or not),
1065
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1066
-     *                                        where keys are always subsection names and values are either
1067
-     *                                        the input's normalized value, or an array like the top-level array
1068
-     * @throws EE_Error
1069
-     */
1070
-    public function input_values($include_subform_inputs = false, $flatten = false)
1071
-    {
1072
-        return $this->_input_values(false, $include_subform_inputs, $flatten);
1073
-    }
1074
-
1075
-
1076
-    /**
1077
-     * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1078
-     * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1079
-     * is not necessarily the value we want to display to users. This creates an array
1080
-     * where keys are the input names, and values are their display values
1081
-     *
1082
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1083
-     *                                        or just this forms' direct children inputs
1084
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1085
-     *                                        or allow multidimensional array
1086
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1087
-     *                                        with array keys being input names
1088
-     *                                        (regardless of whether they are from a subsection or not),
1089
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1090
-     *                                        where keys are always subsection names and values are either
1091
-     *                                        the input's normalized value, or an array like the top-level array
1092
-     * @throws EE_Error
1093
-     */
1094
-    public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1095
-    {
1096
-        return $this->_input_values(true, $include_subform_inputs, $flatten);
1097
-    }
1098
-
1099
-
1100
-    /**
1101
-     * Gets the input values from the form
1102
-     *
1103
-     * @param boolean $pretty                 Whether to retrieve the pretty value,
1104
-     *                                        or just the normalized value
1105
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1106
-     *                                        or just this forms' direct children inputs
1107
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1108
-     *                                        or allow multidimensional array
1109
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1110
-     *                                        input names (regardless of whether they are from a subsection or not),
1111
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1112
-     *                                        where keys are always subsection names and values are either
1113
-     *                                        the input's normalized value, or an array like the top-level array
1114
-     * @throws EE_Error
1115
-     */
1116
-    public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1117
-    {
1118
-        $input_values = array();
1119
-        foreach ($this->subsections() as $subsection_name => $subsection) {
1120
-            if ($subsection instanceof EE_Form_Input_Base) {
1121
-                $input_values[ $subsection_name ] = $pretty
1122
-                    ? $subsection->pretty_value()
1123
-                    : $subsection->normalized_value();
1124
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1125
-                $subform_input_values = $subsection->_input_values(
1126
-                    $pretty,
1127
-                    $include_subform_inputs,
1128
-                    $flatten
1129
-                );
1130
-                if ($flatten) {
1131
-                    $input_values = array_merge($input_values, $subform_input_values);
1132
-                } else {
1133
-                    $input_values[ $subsection_name ] = $subform_input_values;
1134
-                }
1135
-            }
1136
-        }
1137
-        return $input_values;
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * Gets the originally submitted input values from the form
1143
-     *
1144
-     * @param boolean $include_subforms  Whether to include inputs from subforms,
1145
-     *                                   or just this forms' direct children inputs
1146
-     * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1147
-     *                                   with array keys being input names
1148
-     *                                   (regardless of whether they are from a subsection or not),
1149
-     *                                   and if $flatten is FALSE it can be a multidimensional array
1150
-     *                                   where keys are always subsection names and values are either
1151
-     *                                   the input's normalized value, or an array like the top-level array
1152
-     * @throws EE_Error
1153
-     */
1154
-    public function submitted_values($include_subforms = false)
1155
-    {
1156
-        $submitted_values = array();
1157
-        foreach ($this->subsections() as $subsection) {
1158
-            if ($subsection instanceof EE_Form_Input_Base) {
1159
-                // is this input part of an array of inputs?
1160
-                if (strpos($subsection->html_name(), '[') !== false) {
1161
-                    $full_input_name  = EEH_Array::convert_array_values_to_keys(
1162
-                        explode(
1163
-                            '[',
1164
-                            str_replace(']', '', $subsection->html_name())
1165
-                        ),
1166
-                        $subsection->raw_value()
1167
-                    );
1168
-                    $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169
-                } else {
1170
-                    $submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1171
-                }
1172
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173
-                $subform_input_values = $subsection->submitted_values($include_subforms);
1174
-                $submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1175
-            }
1176
-        }
1177
-        return $submitted_values;
1178
-    }
1179
-
1180
-
1181
-    /**
1182
-     * Indicates whether or not this form has received a submission yet
1183
-     * (ie, had receive_form_submission called on it yet)
1184
-     *
1185
-     * @return boolean
1186
-     * @throws EE_Error
1187
-     */
1188
-    public function has_received_submission()
1189
-    {
1190
-        $this->ensure_construct_finalized_called();
1191
-        return $this->_received_submission;
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * Equivalent to passing 'exclude' in the constructor's options array.
1197
-     * Removes the listed inputs from the form
1198
-     *
1199
-     * @param array $inputs_to_exclude values are the input names
1200
-     * @return void
1201
-     */
1202
-    public function exclude(array $inputs_to_exclude = array())
1203
-    {
1204
-        foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
-            unset($this->_subsections[ $input_to_exclude_name ]);
1206
-        }
1207
-    }
1208
-
1209
-
1210
-    /**
1211
-     * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy.
1212
-     * @param array $inputs_to_hide
1213
-     * @throws EE_Error
1214
-     */
1215
-    public function hide(array $inputs_to_hide = array())
1216
-    {
1217
-        foreach ($inputs_to_hide as $input_to_hide) {
1218
-            $input = $this->get_input($input_to_hide);
1219
-            $input->set_display_strategy(new EE_Hidden_Display_Strategy());
1220
-        }
1221
-    }
1222
-
1223
-
1224
-    /**
1225
-     * add_subsections
1226
-     * Adds the listed subsections to the form section.
1227
-     * If $subsection_name_to_target is provided,
1228
-     * then new subsections are added before or after that subsection,
1229
-     * otherwise to the start or end of the entire subsections array.
1230
-     *
1231
-     * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1232
-     *                                                          where keys are their names
1233
-     * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1234
-     *                                                          should be added before or after
1235
-     *                                                          IF $subsection_name_to_target is null,
1236
-     *                                                          then $new_subsections will be added to
1237
-     *                                                          the beginning or end of the entire subsections array
1238
-     * @param boolean                $add_before                whether to add $new_subsections, before or after
1239
-     *                                                          $subsection_name_to_target,
1240
-     *                                                          or if $subsection_name_to_target is null,
1241
-     *                                                          before or after entire subsections array
1242
-     * @return void
1243
-     * @throws EE_Error
1244
-     */
1245
-    public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1246
-    {
1247
-        foreach ($new_subsections as $subsection_name => $subsection) {
1248
-            if (! $subsection instanceof EE_Form_Section_Base) {
1249
-                EE_Error::add_error(
1250
-                    sprintf(
1251
-                        esc_html__(
1252
-                            "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1253
-                            'event_espresso'
1254
-                        ),
1255
-                        get_class($subsection),
1256
-                        $subsection_name,
1257
-                        $this->name()
1258
-                    )
1259
-                );
1260
-                unset($new_subsections[ $subsection_name ]);
1261
-            }
1262
-        }
1263
-        $this->_subsections = EEH_Array::insert_into_array(
1264
-            $this->_subsections,
1265
-            $new_subsections,
1266
-            $subsection_name_to_target,
1267
-            $add_before
1268
-        );
1269
-        if ($this->_construction_finalized) {
1270
-            foreach ($this->_subsections as $name => $subsection) {
1271
-                $subsection->_construct_finalize($this, $name);
1272
-            }
1273
-        }
1274
-    }
1275
-
1276
-
1277
-    /**
1278
-     * @param string $subsection_name
1279
-     * @param bool   $recursive
1280
-     * @return bool
1281
-     */
1282
-    public function has_subsection($subsection_name, $recursive = false)
1283
-    {
1284
-        foreach ($this->_subsections as $name => $subsection) {
1285
-            if ($name === $subsection_name
1286
-                || (
1287
-                    $recursive
1288
-                    && $subsection instanceof EE_Form_Section_Proper
1289
-                    && $subsection->has_subsection($subsection_name, $recursive)
1290
-                )
1291
-            ) {
1292
-                return true;
1293
-            }
1294
-        }
1295
-        return false;
1296
-    }
1297
-
1298
-
1299
-
1300
-    /**
1301
-     * Just gets all validatable subsections to clean their sensitive data
1302
-     *
1303
-     * @throws EE_Error
1304
-     */
1305
-    public function clean_sensitive_data()
1306
-    {
1307
-        foreach ($this->get_validatable_subsections() as $subsection) {
1308
-            $subsection->clean_sensitive_data();
1309
-        }
1310
-    }
1311
-
1312
-
1313
-    /**
1314
-     * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1315
-     * @param string                           $form_submission_error_message
1316
-     * @param EE_Form_Section_Validatable $form_section unused
1317
-     * @throws EE_Error
1318
-     */
1319
-    public function set_submission_error_message(
1320
-        $form_submission_error_message = ''
1321
-    ) {
1322
-        $this->_form_submission_error_message = ! empty($form_submission_error_message)
1323
-            ? $form_submission_error_message
1324
-            : $this->getAllValidationErrorsString();
1325
-    }
1326
-
1327
-
1328
-    /**
1329
-     * Returns the cached error message. A default value is set for this during _validate(),
1330
-     * (called during receive_form_submission) but it can be explicitly set using
1331
-     * set_submission_error_message
1332
-     *
1333
-     * @return string
1334
-     */
1335
-    public function submission_error_message()
1336
-    {
1337
-        return $this->_form_submission_error_message;
1338
-    }
1339
-
1340
-
1341
-    /**
1342
-     * Sets a message to display if the data submitted to the form was valid.
1343
-     * @param string $form_submission_success_message
1344
-     */
1345
-    public function set_submission_success_message($form_submission_success_message = '')
1346
-    {
1347
-        $this->_form_submission_success_message = ! empty($form_submission_success_message)
1348
-            ? $form_submission_success_message
1349
-            : esc_html__('Form submitted successfully', 'event_espresso');
1350
-    }
1351
-
1352
-
1353
-    /**
1354
-     * Gets a message appropriate for display when the form is correctly submitted
1355
-     * @return string
1356
-     */
1357
-    public function submission_success_message()
1358
-    {
1359
-        return $this->_form_submission_success_message;
1360
-    }
1361
-
1362
-
1363
-    /**
1364
-     * Returns the prefix that should be used on child of this form section for
1365
-     * their html names. If this form section itself has a parent, prepends ITS
1366
-     * prefix onto this form section's prefix. Used primarily by
1367
-     * EE_Form_Input_Base::_set_default_html_name_if_empty
1368
-     *
1369
-     * @return string
1370
-     * @throws EE_Error
1371
-     */
1372
-    public function html_name_prefix()
1373
-    {
1374
-        if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1375
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1376
-        }
1377
-        return $this->name();
1378
-    }
1379
-
1380
-
1381
-    /**
1382
-     * Gets the name, but first checks _construct_finalize has been called. If not,
1383
-     * calls it (assumes there is no parent and that we want the name to be whatever
1384
-     * was set, which is probably nothing, or the classname)
1385
-     *
1386
-     * @return string
1387
-     * @throws EE_Error
1388
-     */
1389
-    public function name()
1390
-    {
1391
-        $this->ensure_construct_finalized_called();
1392
-        return parent::name();
1393
-    }
1394
-
1395
-
1396
-    /**
1397
-     * @return EE_Form_Section_Proper
1398
-     * @throws EE_Error
1399
-     */
1400
-    public function parent_section()
1401
-    {
1402
-        $this->ensure_construct_finalized_called();
1403
-        return parent::parent_section();
1404
-    }
1405
-
1406
-
1407
-    /**
1408
-     * make sure construction finalized was called, otherwise children might not be ready
1409
-     *
1410
-     * @return void
1411
-     * @throws EE_Error
1412
-     */
1413
-    public function ensure_construct_finalized_called()
1414
-    {
1415
-        if (! $this->_construction_finalized) {
1416
-            $this->_construct_finalize($this->_parent_section, $this->_name);
1417
-        }
1418
-    }
1419
-
1420
-
1421
-    /**
1422
-     * Checks if any of this form section's inputs, or any of its children's inputs,
1423
-     * are in teh form data. If any are found, returns true. Else false
1424
-     *
1425
-     * @param array $req_data
1426
-     * @return boolean
1427
-     * @throws EE_Error
1428
-     */
1429
-    public function form_data_present_in($req_data = null)
1430
-    {
1431
-        $req_data = $this->getCachedRequest($req_data);
1432
-        foreach ($this->subsections() as $subsection) {
1433
-            if ($subsection instanceof EE_Form_Input_Base) {
1434
-                if ($subsection->form_data_present_in($req_data)) {
1435
-                    return true;
1436
-                }
1437
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
1438
-                if ($subsection->form_data_present_in($req_data)) {
1439
-                    return true;
1440
-                }
1441
-            }
1442
-        }
1443
-        return false;
1444
-    }
1445
-
1446
-
1447
-    /**
1448
-     * Gets validation errors for this form section and subsections
1449
-     * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1450
-     * gets the validation errors for ALL subsection
1451
-     *
1452
-     * @return EE_Validation_Error[]
1453
-     * @throws EE_Error
1454
-     */
1455
-    public function get_validation_errors_accumulated()
1456
-    {
1457
-        $validation_errors = $this->get_validation_errors();
1458
-        foreach ($this->get_validatable_subsections() as $subsection) {
1459
-            if ($subsection instanceof EE_Form_Section_Proper) {
1460
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1461
-            } else {
1462
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors();
1463
-            }
1464
-            if ($validation_errors_on_this_subsection) {
1465
-                $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1466
-            }
1467
-        }
1468
-        return $validation_errors;
1469
-    }
1470
-
1471
-    /**
1472
-     * Fetch validation errors from children and grandchildren and puts them in a single string.
1473
-     * This traverses the form section tree to generate this, but you probably want to instead use
1474
-     * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1475
-     *
1476
-     * @return string
1477
-     * @since 4.9.59.p
1478
-     */
1479
-    protected function getAllValidationErrorsString()
1480
-    {
1481
-        $submission_error_messages = array();
1482
-        // bad, bad, bad registrant
1483
-        foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1484
-            if ($validation_error instanceof EE_Validation_Error) {
1485
-                $form_section = $validation_error->get_form_section();
1486
-                if ($form_section instanceof EE_Form_Input_Base) {
1487
-                    $label = $validation_error->get_form_section()->html_label_text();
1488
-                } elseif ($form_section instanceof EE_Form_Section_Validatable) {
1489
-                    $label = $validation_error->get_form_section()->name();
1490
-                } else {
1491
-                    $label = esc_html__('Unknown', 'event_espresso');
1492
-                }
1493
-                $submission_error_messages[] = sprintf(
1494
-                    __('%s : %s', 'event_espresso'),
1495
-                    $label,
1496
-                    $validation_error->getMessage()
1497
-                );
1498
-            }
1499
-        }
1500
-        return implode('<br', $submission_error_messages);
1501
-    }
1502
-
1503
-
1504
-    /**
1505
-     * This isn't just the name of an input, it's a path pointing to an input. The
1506
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
1507
-     * dot-dot-slash (../) means to ascend into the parent section.
1508
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1509
-     * which will be returned.
1510
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1511
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1512
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1513
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1514
-     * Etc
1515
-     *
1516
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1517
-     * @return EE_Form_Section_Base
1518
-     * @throws EE_Error
1519
-     */
1520
-    public function find_section_from_path($form_section_path)
1521
-    {
1522
-        // check if we can find the input from purely going straight up the tree
1523
-        $input = parent::find_section_from_path($form_section_path);
1524
-        if ($input instanceof EE_Form_Section_Base) {
1525
-            return $input;
1526
-        }
1527
-        $next_slash_pos = strpos($form_section_path, '/');
1528
-        if ($next_slash_pos !== false) {
1529
-            $child_section_name = substr($form_section_path, 0, $next_slash_pos);
1530
-            $subpath            = substr($form_section_path, $next_slash_pos + 1);
1531
-        } else {
1532
-            $child_section_name = $form_section_path;
1533
-            $subpath            = '';
1534
-        }
1535
-        $child_section = $this->get_subsection($child_section_name);
1536
-        if ($child_section instanceof EE_Form_Section_Base) {
1537
-            return $child_section->find_section_from_path($subpath);
1538
-        }
1539
-        return null;
1540
-    }
17
+	const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
+
19
+	/**
20
+	 * Subsections
21
+	 *
22
+	 * @var EE_Form_Section_Validatable[]
23
+	 */
24
+	protected $_subsections = array();
25
+
26
+	/**
27
+	 * Strategy for laying out the form
28
+	 *
29
+	 * @var EE_Form_Section_Layout_Base
30
+	 */
31
+	protected $_layout_strategy;
32
+
33
+	/**
34
+	 * Whether or not this form has received and validated a form submission yet
35
+	 *
36
+	 * @var boolean
37
+	 */
38
+	protected $_received_submission = false;
39
+
40
+	/**
41
+	 * message displayed to users upon successful form submission
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $_form_submission_success_message = '';
46
+
47
+	/**
48
+	 * message displayed to users upon unsuccessful form submission
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $_form_submission_error_message = '';
53
+
54
+	/**
55
+	 * @var array like $_REQUEST
56
+	 */
57
+	protected $cached_request_data;
58
+
59
+	/**
60
+	 * Stores whether this form (and its sub-sections) were found to be valid or not.
61
+	 * Starts off as null, but once the form is validated, it set to either true or false
62
+	 * @var boolean|null
63
+	 */
64
+	protected $is_valid;
65
+
66
+	/**
67
+	 * Stores all the data that will localized for form validation
68
+	 *
69
+	 * @var array
70
+	 */
71
+	static protected $_js_localization = array();
72
+
73
+	/**
74
+	 * whether or not the form's localized validation JS vars have been set
75
+	 *
76
+	 * @type boolean
77
+	 */
78
+	static protected $_scripts_localized = false;
79
+
80
+
81
+	/**
82
+	 * when constructing a proper form section, calls _construct_finalize on children
83
+	 * so that they know who their parent is, and what name they've been given.
84
+	 *
85
+	 * @param array[] $options_array   {
86
+	 * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
+	 * @type          $include         string[] numerically-indexed where values are section names to be included,
88
+	 *                                 and in that order. This is handy if you want
89
+	 *                                 the subsections to be ordered differently than the default, and if you override
90
+	 *                                 which fields are shown
91
+	 * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
+	 *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
+	 *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
+	 *                                 items from that list of inclusions)
95
+	 * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
+	 *                                 } @see EE_Form_Section_Validatable::__construct()
97
+	 * @throws EE_Error
98
+	 */
99
+	public function __construct($options_array = array())
100
+	{
101
+		$options_array = (array) apply_filters(
102
+			'FHEE__EE_Form_Section_Proper___construct__options_array',
103
+			$options_array,
104
+			$this
105
+		);
106
+		// call parent first, as it may be setting the name
107
+		parent::__construct($options_array);
108
+		// if they've included subsections in the constructor, add them now
109
+		if (isset($options_array['include'])) {
110
+			// we are going to make sure we ONLY have those subsections to include
111
+			// AND we are going to make sure they're in that specified order
112
+			$reordered_subsections = array();
113
+			foreach ($options_array['include'] as $input_name) {
114
+				if (isset($this->_subsections[ $input_name ])) {
115
+					$reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
+				}
117
+			}
118
+			$this->_subsections = $reordered_subsections;
119
+		}
120
+		if (isset($options_array['exclude'])) {
121
+			$exclude            = $options_array['exclude'];
122
+			$this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
+		}
124
+		if (isset($options_array['layout_strategy'])) {
125
+			$this->_layout_strategy = $options_array['layout_strategy'];
126
+		}
127
+		if (! $this->_layout_strategy) {
128
+			$this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
+		}
130
+		$this->_layout_strategy->_construct_finalize($this);
131
+		// ok so we are definitely going to want the forms JS,
132
+		// so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
+			// ok so they've constructed this object after when they should have.
135
+			// just enqueue the generic form scripts and initialize the form immediately in the JS
136
+			EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
+		} else {
138
+			add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
+			add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
+		}
141
+		add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
+		/**
143
+		 * Gives other plugins a chance to hook in before construct finalize is called.
144
+		 * The form probably doesn't yet have a parent form section.
145
+		 * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
+		 * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
+		 * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
+		 *
149
+		 * @since 4.9.32
150
+		 * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
+		 *                                              except maybe calling _construct_finalize has been done
152
+		 * @param array                  $options_array options passed into the constructor
153
+		 */
154
+		do_action(
155
+			'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
+			$this,
157
+			$options_array
158
+		);
159
+		if (isset($options_array['name'])) {
160
+			$this->_construct_finalize(null, $options_array['name']);
161
+		}
162
+	}
163
+
164
+
165
+	/**
166
+	 * Finishes construction given the parent form section and this form section's name
167
+	 *
168
+	 * @param EE_Form_Section_Proper $parent_form_section
169
+	 * @param string                 $name
170
+	 * @throws EE_Error
171
+	 */
172
+	public function _construct_finalize($parent_form_section, $name)
173
+	{
174
+		parent::_construct_finalize($parent_form_section, $name);
175
+		$this->_set_default_name_if_empty();
176
+		$this->_set_default_html_id_if_empty();
177
+		foreach ($this->_subsections as $subsection_name => $subsection) {
178
+			if ($subsection instanceof EE_Form_Section_Base) {
179
+				$subsection->_construct_finalize($this, $subsection_name);
180
+			} else {
181
+				throw new EE_Error(
182
+					sprintf(
183
+						esc_html__(
184
+							'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
+							'event_espresso'
186
+						),
187
+						$subsection_name,
188
+						get_class($this),
189
+						$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
+					)
191
+				);
192
+			}
193
+		}
194
+		/**
195
+		 * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
+		 * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
+		 * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
+		 * This might only happen just before displaying the form, or just before it receives form submission data.
199
+		 * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
+		 * ensured it has a name, HTML IDs, etc
201
+		 *
202
+		 * @param EE_Form_Section_Proper      $this
203
+		 * @param EE_Form_Section_Proper|null $parent_form_section
204
+		 * @param string                      $name
205
+		 */
206
+		do_action(
207
+			'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
+			$this,
209
+			$parent_form_section,
210
+			$name
211
+		);
212
+	}
213
+
214
+
215
+	/**
216
+	 * Gets the layout strategy for this form section
217
+	 *
218
+	 * @return EE_Form_Section_Layout_Base
219
+	 */
220
+	public function get_layout_strategy()
221
+	{
222
+		return $this->_layout_strategy;
223
+	}
224
+
225
+
226
+	/**
227
+	 * Gets the HTML for a single input for this form section according
228
+	 * to the layout strategy
229
+	 *
230
+	 * @param EE_Form_Input_Base $input
231
+	 * @return string
232
+	 */
233
+	public function get_html_for_input($input)
234
+	{
235
+		return $this->_layout_strategy->layout_input($input);
236
+	}
237
+
238
+
239
+	/**
240
+	 * was_submitted - checks if form inputs are present in request data
241
+	 * Basically an alias for form_data_present_in() (which is used by both
242
+	 * proper form sections and form inputs)
243
+	 *
244
+	 * @param null $form_data
245
+	 * @return boolean
246
+	 * @throws EE_Error
247
+	 */
248
+	public function was_submitted($form_data = null)
249
+	{
250
+		return $this->form_data_present_in($form_data);
251
+	}
252
+
253
+	/**
254
+	 * Gets the cached request data; but if there is none, or $req_data was set with
255
+	 * something different, refresh the cache, and then return it
256
+	 * @param null $req_data
257
+	 * @return array
258
+	 */
259
+	protected function getCachedRequest($req_data = null)
260
+	{
261
+		if ($this->cached_request_data === null
262
+			|| (
263
+				$req_data !== null &&
264
+				$req_data !== $this->cached_request_data
265
+			)
266
+		) {
267
+			$req_data = apply_filters(
268
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
269
+				$req_data,
270
+				$this
271
+			);
272
+			if ($req_data === null) {
273
+				$req_data = array_merge($_GET, $_POST);
274
+			}
275
+			$req_data = apply_filters(
276
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
277
+				$req_data,
278
+				$this
279
+			);
280
+			$this->cached_request_data = (array) $req_data;
281
+		}
282
+		return $this->cached_request_data;
283
+	}
284
+
285
+
286
+	/**
287
+	 * After the form section is initially created, call this to sanitize the data in the submission
288
+	 * which relates to this form section, validate it, and set it as properties on the form.
289
+	 *
290
+	 * @param array|null $req_data should usually be $_POST (the default).
291
+	 *                             However, you CAN supply a different array.
292
+	 *                             Consider using set_defaults() instead however.
293
+	 *                             (If you rendered the form in the page using echo $form_x->get_html()
294
+	 *                             the inputs will have the correct name in the request data for this function
295
+	 *                             to find them and populate the form with them.
296
+	 *                             If you have a flat form (with only input subsections),
297
+	 *                             you can supply a flat array where keys
298
+	 *                             are the form input names and values are their values)
299
+	 * @param boolean    $validate whether or not to perform validation on this data. Default is,
300
+	 *                             of course, to validate that data, and set errors on the invalid values.
301
+	 *                             But if the data has already been validated
302
+	 *                             (eg you validated the data then stored it in the DB)
303
+	 *                             you may want to skip this step.
304
+	 * @throws InvalidArgumentException
305
+	 * @throws InvalidInterfaceException
306
+	 * @throws InvalidDataTypeException
307
+	 * @throws EE_Error
308
+	 */
309
+	public function receive_form_submission($req_data = null, $validate = true)
310
+	{
311
+		$req_data = $this->getCachedRequest($req_data);
312
+		$this->_normalize($req_data);
313
+		if ($validate) {
314
+			$this->_validate();
315
+			// if it's invalid, we're going to want to re-display so remember what they submitted
316
+			if (! $this->is_valid()) {
317
+				$this->store_submitted_form_data_in_session();
318
+			}
319
+		}
320
+		if ($this->submission_error_message() === '' && ! $this->is_valid()) {
321
+			$this->set_submission_error_message();
322
+		}
323
+		do_action(
324
+			'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
325
+			$req_data,
326
+			$this,
327
+			$validate
328
+		);
329
+	}
330
+
331
+
332
+	/**
333
+	 * caches the originally submitted input values in the session
334
+	 * so that they can be used to repopulate the form if it failed validation
335
+	 *
336
+	 * @return boolean whether or not the data was successfully stored in the session
337
+	 * @throws InvalidArgumentException
338
+	 * @throws InvalidInterfaceException
339
+	 * @throws InvalidDataTypeException
340
+	 * @throws EE_Error
341
+	 */
342
+	protected function store_submitted_form_data_in_session()
343
+	{
344
+		return EE_Registry::instance()->SSN->set_session_data(
345
+			array(
346
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
347
+			)
348
+		);
349
+	}
350
+
351
+
352
+	/**
353
+	 * retrieves the originally submitted input values in the session
354
+	 * so that they can be used to repopulate the form if it failed validation
355
+	 *
356
+	 * @return array
357
+	 * @throws InvalidArgumentException
358
+	 * @throws InvalidInterfaceException
359
+	 * @throws InvalidDataTypeException
360
+	 */
361
+	protected function get_submitted_form_data_from_session()
362
+	{
363
+		$session = EE_Registry::instance()->SSN;
364
+		if ($session instanceof EE_Session) {
365
+			return $session->get_session_data(
366
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
367
+			);
368
+		}
369
+		return array();
370
+	}
371
+
372
+
373
+	/**
374
+	 * flushed the originally submitted input values from the session
375
+	 *
376
+	 * @return boolean whether or not the data was successfully removed from the session
377
+	 * @throws InvalidArgumentException
378
+	 * @throws InvalidInterfaceException
379
+	 * @throws InvalidDataTypeException
380
+	 */
381
+	public static function flush_submitted_form_data_from_session()
382
+	{
383
+		return EE_Registry::instance()->SSN->reset_data(
384
+			array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
385
+		);
386
+	}
387
+
388
+
389
+	/**
390
+	 * Populates this form and its subsections with data from the session.
391
+	 * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
392
+	 * validation errors when displaying too)
393
+	 * Returns true if the form was populated from the session, false otherwise
394
+	 *
395
+	 * @return boolean
396
+	 * @throws InvalidArgumentException
397
+	 * @throws InvalidInterfaceException
398
+	 * @throws InvalidDataTypeException
399
+	 * @throws EE_Error
400
+	 */
401
+	public function populate_from_session()
402
+	{
403
+		$form_data_in_session = $this->get_submitted_form_data_from_session();
404
+		if (empty($form_data_in_session)) {
405
+			return false;
406
+		}
407
+		$this->receive_form_submission($form_data_in_session);
408
+		add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session'));
409
+		if ($this->form_data_present_in($form_data_in_session)) {
410
+			return true;
411
+		}
412
+		return false;
413
+	}
414
+
415
+
416
+	/**
417
+	 * Populates the default data for the form, given an array where keys are
418
+	 * the input names, and values are their values (preferably normalized to be their
419
+	 * proper PHP types, not all strings... although that should be ok too).
420
+	 * Proper subsections are sub-arrays, the key being the subsection's name, and
421
+	 * the value being an array formatted in teh same way
422
+	 *
423
+	 * @param array $default_data
424
+	 * @throws EE_Error
425
+	 */
426
+	public function populate_defaults($default_data)
427
+	{
428
+		foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
+			if (isset($default_data[ $subsection_name ])) {
430
+				if ($subsection instanceof EE_Form_Input_Base) {
431
+					$subsection->set_default($default_data[ $subsection_name ]);
432
+				} elseif ($subsection instanceof EE_Form_Section_Proper) {
433
+					$subsection->populate_defaults($default_data[ $subsection_name ]);
434
+				}
435
+			}
436
+		}
437
+	}
438
+
439
+
440
+	/**
441
+	 * returns true if subsection exists
442
+	 *
443
+	 * @param string $name
444
+	 * @return boolean
445
+	 */
446
+	public function subsection_exists($name)
447
+	{
448
+		return isset($this->_subsections[ $name ]) ? true : false;
449
+	}
450
+
451
+
452
+	/**
453
+	 * Gets the subsection specified by its name
454
+	 *
455
+	 * @param string  $name
456
+	 * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
457
+	 *                                                      so that the inputs will be properly configured.
458
+	 *                                                      However, some client code may be ok
459
+	 *                                                      with construction finalize being called later
460
+	 *                                                      (realizing that the subsections' html names
461
+	 *                                                      might not be set yet, etc.)
462
+	 * @return EE_Form_Section_Base
463
+	 * @throws EE_Error
464
+	 */
465
+	public function get_subsection($name, $require_construction_to_be_finalized = true)
466
+	{
467
+		if ($require_construction_to_be_finalized) {
468
+			$this->ensure_construct_finalized_called();
469
+		}
470
+		return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
471
+	}
472
+
473
+
474
+	/**
475
+	 * Gets all the validatable subsections of this form section
476
+	 *
477
+	 * @return EE_Form_Section_Validatable[]
478
+	 * @throws EE_Error
479
+	 */
480
+	public function get_validatable_subsections()
481
+	{
482
+		$validatable_subsections = array();
483
+		foreach ($this->subsections() as $name => $obj) {
484
+			if ($obj instanceof EE_Form_Section_Validatable) {
485
+				$validatable_subsections[ $name ] = $obj;
486
+			}
487
+		}
488
+		return $validatable_subsections;
489
+	}
490
+
491
+
492
+	/**
493
+	 * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
494
+	 * throw an EE_Error.
495
+	 *
496
+	 * @param string  $name
497
+	 * @param boolean $require_construction_to_be_finalized most client code should
498
+	 *                                                      leave this as TRUE so that the inputs will be properly
499
+	 *                                                      configured. However, some client code may be ok with
500
+	 *                                                      construction finalize being called later
501
+	 *                                                      (realizing that the subsections' html names might not be
502
+	 *                                                      set yet, etc.)
503
+	 * @return EE_Form_Input_Base
504
+	 * @throws EE_Error
505
+	 */
506
+	public function get_input($name, $require_construction_to_be_finalized = true)
507
+	{
508
+		$subsection = $this->get_subsection(
509
+			$name,
510
+			$require_construction_to_be_finalized
511
+		);
512
+		if (! $subsection instanceof EE_Form_Input_Base) {
513
+			throw new EE_Error(
514
+				sprintf(
515
+					esc_html__(
516
+						"Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
517
+						'event_espresso'
518
+					),
519
+					$name,
520
+					get_class($this),
521
+					$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
522
+				)
523
+			);
524
+		}
525
+		return $subsection;
526
+	}
527
+
528
+
529
+	/**
530
+	 * Like get_input(), gets the proper subsection of the form given the name,
531
+	 * otherwise throws an EE_Error
532
+	 *
533
+	 * @param string  $name
534
+	 * @param boolean $require_construction_to_be_finalized most client code should
535
+	 *                                                      leave this as TRUE so that the inputs will be properly
536
+	 *                                                      configured. However, some client code may be ok with
537
+	 *                                                      construction finalize being called later
538
+	 *                                                      (realizing that the subsections' html names might not be
539
+	 *                                                      set yet, etc.)
540
+	 * @return EE_Form_Section_Proper
541
+	 * @throws EE_Error
542
+	 */
543
+	public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
544
+	{
545
+		$subsection = $this->get_subsection(
546
+			$name,
547
+			$require_construction_to_be_finalized
548
+		);
549
+		if (! $subsection instanceof EE_Form_Section_Proper) {
550
+			throw new EE_Error(
551
+				sprintf(
552
+					esc_html__(
553
+						"Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
554
+						'event_espresso'
555
+					),
556
+					$name,
557
+					get_class($this)
558
+				)
559
+			);
560
+		}
561
+		return $subsection;
562
+	}
563
+
564
+
565
+	/**
566
+	 * Gets the value of the specified input. Should be called after receive_form_submission()
567
+	 * or populate_defaults() on the form, where the normalized value on the input is set.
568
+	 *
569
+	 * @param string $name
570
+	 * @return mixed depending on the input's type and its normalization strategy
571
+	 * @throws EE_Error
572
+	 */
573
+	public function get_input_value($name)
574
+	{
575
+		$input = $this->get_input($name);
576
+		return $input->normalized_value();
577
+	}
578
+
579
+
580
+	/**
581
+	 * Checks if this form section itself is valid, and then checks its subsections
582
+	 *
583
+	 * @throws EE_Error
584
+	 * @return boolean
585
+	 */
586
+	public function is_valid()
587
+	{
588
+		if ($this->is_valid === null) {
589
+			if (! $this->has_received_submission()) {
590
+				throw new EE_Error(
591
+					sprintf(
592
+						esc_html__(
593
+							'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
594
+							'event_espresso'
595
+						)
596
+					)
597
+				);
598
+			}
599
+			if (! parent::is_valid()) {
600
+				$this->is_valid = false;
601
+			} else {
602
+				// ok so no general errors to this entire form section.
603
+				// so let's check the subsections, but only set errors if that hasn't been done yet
604
+				$this->is_valid = true;
605
+				foreach ($this->get_validatable_subsections() as $subsection) {
606
+					if (! $subsection->is_valid()) {
607
+						$this->is_valid = false;
608
+					}
609
+				}
610
+			}
611
+		}
612
+		return $this->is_valid;
613
+	}
614
+
615
+
616
+	/**
617
+	 * gets the default name of this form section if none is specified
618
+	 *
619
+	 * @return void
620
+	 */
621
+	protected function _set_default_name_if_empty()
622
+	{
623
+		if (! $this->_name) {
624
+			$classname    = get_class($this);
625
+			$default_name = str_replace('EE_', '', $classname);
626
+			$this->_name  = $default_name;
627
+		}
628
+	}
629
+
630
+
631
+	/**
632
+	 * Returns the HTML for the form, except for the form opening and closing tags
633
+	 * (as the form section doesn't know where you necessarily want to send the information to),
634
+	 * and except for a submit button. Enqueues JS and CSS; if called early enough we will
635
+	 * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
636
+	 * Not doing_it_wrong because theoretically this CAN be used properly,
637
+	 * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
638
+	 * any CSS.
639
+	 *
640
+	 * @throws InvalidArgumentException
641
+	 * @throws InvalidInterfaceException
642
+	 * @throws InvalidDataTypeException
643
+	 * @throws EE_Error
644
+	 */
645
+	public function get_html_and_js()
646
+	{
647
+		$this->enqueue_js();
648
+		return $this->get_html();
649
+	}
650
+
651
+
652
+	/**
653
+	 * returns HTML for displaying this form section. recursively calls display_section() on all subsections
654
+	 *
655
+	 * @param bool $display_previously_submitted_data
656
+	 * @return string
657
+	 * @throws InvalidArgumentException
658
+	 * @throws InvalidInterfaceException
659
+	 * @throws InvalidDataTypeException
660
+	 * @throws EE_Error
661
+	 * @throws EE_Error
662
+	 * @throws EE_Error
663
+	 */
664
+	public function get_html($display_previously_submitted_data = true)
665
+	{
666
+		$this->ensure_construct_finalized_called();
667
+		if ($display_previously_submitted_data) {
668
+			$this->populate_from_session();
669
+		}
670
+		return $this->_form_html_filter
671
+			? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
672
+			: $this->_layout_strategy->layout_form();
673
+	}
674
+
675
+
676
+	/**
677
+	 * enqueues JS and CSS for the form.
678
+	 * It is preferred to call this before wp_enqueue_scripts so the
679
+	 * scripts and styles can be put in the header, but if called later
680
+	 * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
681
+	 * only be in the header; but in HTML5 its ok in the body.
682
+	 * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
683
+	 * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
684
+	 *
685
+	 * @return void
686
+	 * @throws EE_Error
687
+	 */
688
+	public function enqueue_js()
689
+	{
690
+		$this->_enqueue_and_localize_form_js();
691
+		foreach ($this->subsections() as $subsection) {
692
+			$subsection->enqueue_js();
693
+		}
694
+	}
695
+
696
+
697
+	/**
698
+	 * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
699
+	 * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
700
+	 * the wp_enqueue_scripts hook.
701
+	 * However, registering the form js and localizing it can happen when we
702
+	 * actually output the form (which is preferred, seeing how teh form's fields
703
+	 * could change until it's actually outputted)
704
+	 *
705
+	 * @param boolean $init_form_validation_automatically whether or not we want the form validation
706
+	 *                                                    to be triggered automatically or not
707
+	 * @return void
708
+	 */
709
+	public static function wp_enqueue_scripts($init_form_validation_automatically = true)
710
+	{
711
+		wp_register_script(
712
+			'ee_form_section_validation',
713
+			EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js',
714
+			array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715
+			EVENT_ESPRESSO_VERSION,
716
+			true
717
+		);
718
+		wp_localize_script(
719
+			'ee_form_section_validation',
720
+			'ee_form_section_validation_init',
721
+			array('init' => $init_form_validation_automatically ? '1' : '0')
722
+		);
723
+	}
724
+
725
+
726
+	/**
727
+	 * gets the variables used by form_section_validation.js.
728
+	 * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
729
+	 * but before the wordpress hook wp_loaded
730
+	 *
731
+	 * @throws EE_Error
732
+	 */
733
+	public function _enqueue_and_localize_form_js()
734
+	{
735
+		$this->ensure_construct_finalized_called();
736
+		// actually, we don't want to localize just yet. There may be other forms on the page.
737
+		// so we need to add our form section data to a static variable accessible by all form sections
738
+		// and localize it just before the footer
739
+		$this->localize_validation_rules();
740
+		add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
741
+		add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
742
+	}
743
+
744
+
745
+	/**
746
+	 * add our form section data to a static variable accessible by all form sections
747
+	 *
748
+	 * @param bool $return_for_subsection
749
+	 * @return void
750
+	 * @throws EE_Error
751
+	 */
752
+	public function localize_validation_rules($return_for_subsection = false)
753
+	{
754
+		// we only want to localize vars ONCE for the entire form,
755
+		// so if the form section doesn't have a parent, then it must be the top dog
756
+		if ($return_for_subsection || ! $this->parent_section()) {
757
+			EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
758
+				'form_section_id'  => $this->html_id(true),
759
+				'validation_rules' => $this->get_jquery_validation_rules(),
760
+				'other_data'       => $this->get_other_js_data(),
761
+				'errors'           => $this->subsection_validation_errors_by_html_name(),
762
+			);
763
+			EE_Form_Section_Proper::$_scripts_localized                                = true;
764
+		}
765
+	}
766
+
767
+
768
+	/**
769
+	 * Gets an array of extra data that will be useful for client-side javascript.
770
+	 * This is primarily data added by inputs and forms in addition to any
771
+	 * scripts they might enqueue
772
+	 *
773
+	 * @param array $form_other_js_data
774
+	 * @return array
775
+	 * @throws EE_Error
776
+	 */
777
+	public function get_other_js_data($form_other_js_data = array())
778
+	{
779
+		foreach ($this->subsections() as $subsection) {
780
+			$form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
781
+		}
782
+		return $form_other_js_data;
783
+	}
784
+
785
+
786
+	/**
787
+	 * Gets a flat array of inputs for this form section and its subsections.
788
+	 * Keys are their form names, and values are the inputs themselves
789
+	 *
790
+	 * @return EE_Form_Input_Base
791
+	 * @throws EE_Error
792
+	 */
793
+	public function inputs_in_subsections()
794
+	{
795
+		$inputs = array();
796
+		foreach ($this->subsections() as $subsection) {
797
+			if ($subsection instanceof EE_Form_Input_Base) {
798
+				$inputs[ $subsection->html_name() ] = $subsection;
799
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
800
+				$inputs += $subsection->inputs_in_subsections();
801
+			}
802
+		}
803
+		return $inputs;
804
+	}
805
+
806
+
807
+	/**
808
+	 * Gets a flat array of all the validation errors.
809
+	 * Keys are html names (because those should be unique)
810
+	 * and values are a string of all their validation errors
811
+	 *
812
+	 * @return string[]
813
+	 * @throws EE_Error
814
+	 */
815
+	public function subsection_validation_errors_by_html_name()
816
+	{
817
+		$inputs = $this->inputs();
818
+		$errors = array();
819
+		foreach ($inputs as $form_input) {
820
+			if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
+				$errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
822
+			}
823
+		}
824
+		return $errors;
825
+	}
826
+
827
+
828
+	/**
829
+	 * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
830
+	 * Should be setup by each form during the _enqueues_and_localize_form_js
831
+	 *
832
+	 * @throws InvalidArgumentException
833
+	 * @throws InvalidInterfaceException
834
+	 * @throws InvalidDataTypeException
835
+	 */
836
+	public static function localize_script_for_all_forms()
837
+	{
838
+		// allow inputs and stuff to hook in their JS and stuff here
839
+		do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
840
+		EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
841
+		$email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842
+			? EE_Registry::instance()->CFG->registration->email_validation_level
843
+			: 'wp_default';
844
+		EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
845
+		wp_enqueue_script('ee_form_section_validation');
846
+		wp_localize_script(
847
+			'ee_form_section_validation',
848
+			'ee_form_section_vars',
849
+			EE_Form_Section_Proper::$_js_localization
850
+		);
851
+	}
852
+
853
+
854
+	/**
855
+	 * ensure_scripts_localized
856
+	 *
857
+	 * @throws EE_Error
858
+	 */
859
+	public function ensure_scripts_localized()
860
+	{
861
+		if (! EE_Form_Section_Proper::$_scripts_localized) {
862
+			$this->_enqueue_and_localize_form_js();
863
+		}
864
+	}
865
+
866
+
867
+	/**
868
+	 * Gets the hard-coded validation error messages to be used in the JS. The convention
869
+	 * is that the key here should be the same as the custom validation rule put in the JS file
870
+	 *
871
+	 * @return array keys are custom validation rules, and values are internationalized strings
872
+	 */
873
+	private static function _get_localized_error_messages()
874
+	{
875
+		return array(
876
+			'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'),
877
+			'regex'    => esc_html__('Please check your input', 'event_espresso'),
878
+		);
879
+	}
880
+
881
+
882
+	/**
883
+	 * @return array
884
+	 */
885
+	public static function js_localization()
886
+	{
887
+		return self::$_js_localization;
888
+	}
889
+
890
+
891
+	/**
892
+	 * @return void
893
+	 */
894
+	public static function reset_js_localization()
895
+	{
896
+		self::$_js_localization = array();
897
+	}
898
+
899
+
900
+	/**
901
+	 * Gets the JS to put inside the jquery validation rules for subsection of this form section.
902
+	 * See parent function for more...
903
+	 *
904
+	 * @return array
905
+	 * @throws EE_Error
906
+	 */
907
+	public function get_jquery_validation_rules()
908
+	{
909
+		$jquery_validation_rules = array();
910
+		foreach ($this->get_validatable_subsections() as $subsection) {
911
+			$jquery_validation_rules = array_merge(
912
+				$jquery_validation_rules,
913
+				$subsection->get_jquery_validation_rules()
914
+			);
915
+		}
916
+		return $jquery_validation_rules;
917
+	}
918
+
919
+
920
+	/**
921
+	 * Sanitizes all the data and sets the sanitized value of each field
922
+	 *
923
+	 * @param array $req_data like $_POST
924
+	 * @return void
925
+	 * @throws EE_Error
926
+	 */
927
+	protected function _normalize($req_data)
928
+	{
929
+		$this->_received_submission = true;
930
+		$this->_validation_errors   = array();
931
+		foreach ($this->get_validatable_subsections() as $subsection) {
932
+			try {
933
+				$subsection->_normalize($req_data);
934
+			} catch (EE_Validation_Error $e) {
935
+				$subsection->add_validation_error($e);
936
+			}
937
+		}
938
+	}
939
+
940
+
941
+	/**
942
+	 * Performs validation on this form section and its subsections.
943
+	 * For each subsection,
944
+	 * calls _validate_{subsection_name} on THIS form (if the function exists)
945
+	 * and passes it the subsection, then calls _validate on that subsection.
946
+	 * If you need to perform validation on the form as a whole (considering multiple)
947
+	 * you would be best to override this _validate method,
948
+	 * calling parent::_validate() first.
949
+	 *
950
+	 * @throws EE_Error
951
+	 */
952
+	protected function _validate()
953
+	{
954
+		// reset the cache of whether this form is valid or not- we're re-validating it now
955
+		$this->is_valid = null;
956
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
+			if (method_exists($this, '_validate_' . $subsection_name)) {
958
+				call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
959
+			}
960
+			$subsection->_validate();
961
+		}
962
+	}
963
+
964
+
965
+	/**
966
+	 * Gets all the validated inputs for the form section
967
+	 *
968
+	 * @return array
969
+	 * @throws EE_Error
970
+	 */
971
+	public function valid_data()
972
+	{
973
+		$inputs = array();
974
+		foreach ($this->subsections() as $subsection_name => $subsection) {
975
+			if ($subsection instanceof EE_Form_Section_Proper) {
976
+				$inputs[ $subsection_name ] = $subsection->valid_data();
977
+			} elseif ($subsection instanceof EE_Form_Input_Base) {
978
+				$inputs[ $subsection_name ] = $subsection->normalized_value();
979
+			}
980
+		}
981
+		return $inputs;
982
+	}
983
+
984
+
985
+	/**
986
+	 * Gets all the inputs on this form section
987
+	 *
988
+	 * @return EE_Form_Input_Base[]
989
+	 * @throws EE_Error
990
+	 */
991
+	public function inputs()
992
+	{
993
+		$inputs = array();
994
+		foreach ($this->subsections() as $subsection_name => $subsection) {
995
+			if ($subsection instanceof EE_Form_Input_Base) {
996
+				$inputs[ $subsection_name ] = $subsection;
997
+			}
998
+		}
999
+		return $inputs;
1000
+	}
1001
+
1002
+
1003
+	/**
1004
+	 * Gets all the subsections which are a proper form
1005
+	 *
1006
+	 * @return EE_Form_Section_Proper[]
1007
+	 * @throws EE_Error
1008
+	 */
1009
+	public function subforms()
1010
+	{
1011
+		$form_sections = array();
1012
+		foreach ($this->subsections() as $name => $obj) {
1013
+			if ($obj instanceof EE_Form_Section_Proper) {
1014
+				$form_sections[ $name ] = $obj;
1015
+			}
1016
+		}
1017
+		return $form_sections;
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * Gets all the subsections (inputs, proper subsections, or html-only sections).
1023
+	 * Consider using inputs() or subforms()
1024
+	 * if you only want form inputs or proper form sections.
1025
+	 *
1026
+	 * @param boolean $require_construction_to_be_finalized most client code should
1027
+	 *                                                      leave this as TRUE so that the inputs will be properly
1028
+	 *                                                      configured. However, some client code may be ok with
1029
+	 *                                                      construction finalize being called later
1030
+	 *                                                      (realizing that the subsections' html names might not be
1031
+	 *                                                      set yet, etc.)
1032
+	 * @return EE_Form_Section_Proper[]
1033
+	 * @throws EE_Error
1034
+	 */
1035
+	public function subsections($require_construction_to_be_finalized = true)
1036
+	{
1037
+		if ($require_construction_to_be_finalized) {
1038
+			$this->ensure_construct_finalized_called();
1039
+		}
1040
+		return $this->_subsections;
1041
+	}
1042
+
1043
+
1044
+	/**
1045
+	 * Returns whether this form has any subforms or inputs
1046
+	 * @return bool
1047
+	 */
1048
+	public function hasSubsections()
1049
+	{
1050
+		return ! empty($this->_subsections);
1051
+	}
1052
+
1053
+
1054
+	/**
1055
+	 * Returns a simple array where keys are input names, and values are their normalized
1056
+	 * values. (Similar to calling get_input_value on inputs)
1057
+	 *
1058
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1059
+	 *                                        or just this forms' direct children inputs
1060
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1061
+	 *                                        or allow multidimensional array
1062
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1063
+	 *                                        with array keys being input names
1064
+	 *                                        (regardless of whether they are from a subsection or not),
1065
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1066
+	 *                                        where keys are always subsection names and values are either
1067
+	 *                                        the input's normalized value, or an array like the top-level array
1068
+	 * @throws EE_Error
1069
+	 */
1070
+	public function input_values($include_subform_inputs = false, $flatten = false)
1071
+	{
1072
+		return $this->_input_values(false, $include_subform_inputs, $flatten);
1073
+	}
1074
+
1075
+
1076
+	/**
1077
+	 * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1078
+	 * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1079
+	 * is not necessarily the value we want to display to users. This creates an array
1080
+	 * where keys are the input names, and values are their display values
1081
+	 *
1082
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1083
+	 *                                        or just this forms' direct children inputs
1084
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1085
+	 *                                        or allow multidimensional array
1086
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1087
+	 *                                        with array keys being input names
1088
+	 *                                        (regardless of whether they are from a subsection or not),
1089
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1090
+	 *                                        where keys are always subsection names and values are either
1091
+	 *                                        the input's normalized value, or an array like the top-level array
1092
+	 * @throws EE_Error
1093
+	 */
1094
+	public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1095
+	{
1096
+		return $this->_input_values(true, $include_subform_inputs, $flatten);
1097
+	}
1098
+
1099
+
1100
+	/**
1101
+	 * Gets the input values from the form
1102
+	 *
1103
+	 * @param boolean $pretty                 Whether to retrieve the pretty value,
1104
+	 *                                        or just the normalized value
1105
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1106
+	 *                                        or just this forms' direct children inputs
1107
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1108
+	 *                                        or allow multidimensional array
1109
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1110
+	 *                                        input names (regardless of whether they are from a subsection or not),
1111
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1112
+	 *                                        where keys are always subsection names and values are either
1113
+	 *                                        the input's normalized value, or an array like the top-level array
1114
+	 * @throws EE_Error
1115
+	 */
1116
+	public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1117
+	{
1118
+		$input_values = array();
1119
+		foreach ($this->subsections() as $subsection_name => $subsection) {
1120
+			if ($subsection instanceof EE_Form_Input_Base) {
1121
+				$input_values[ $subsection_name ] = $pretty
1122
+					? $subsection->pretty_value()
1123
+					: $subsection->normalized_value();
1124
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1125
+				$subform_input_values = $subsection->_input_values(
1126
+					$pretty,
1127
+					$include_subform_inputs,
1128
+					$flatten
1129
+				);
1130
+				if ($flatten) {
1131
+					$input_values = array_merge($input_values, $subform_input_values);
1132
+				} else {
1133
+					$input_values[ $subsection_name ] = $subform_input_values;
1134
+				}
1135
+			}
1136
+		}
1137
+		return $input_values;
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * Gets the originally submitted input values from the form
1143
+	 *
1144
+	 * @param boolean $include_subforms  Whether to include inputs from subforms,
1145
+	 *                                   or just this forms' direct children inputs
1146
+	 * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1147
+	 *                                   with array keys being input names
1148
+	 *                                   (regardless of whether they are from a subsection or not),
1149
+	 *                                   and if $flatten is FALSE it can be a multidimensional array
1150
+	 *                                   where keys are always subsection names and values are either
1151
+	 *                                   the input's normalized value, or an array like the top-level array
1152
+	 * @throws EE_Error
1153
+	 */
1154
+	public function submitted_values($include_subforms = false)
1155
+	{
1156
+		$submitted_values = array();
1157
+		foreach ($this->subsections() as $subsection) {
1158
+			if ($subsection instanceof EE_Form_Input_Base) {
1159
+				// is this input part of an array of inputs?
1160
+				if (strpos($subsection->html_name(), '[') !== false) {
1161
+					$full_input_name  = EEH_Array::convert_array_values_to_keys(
1162
+						explode(
1163
+							'[',
1164
+							str_replace(']', '', $subsection->html_name())
1165
+						),
1166
+						$subsection->raw_value()
1167
+					);
1168
+					$submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169
+				} else {
1170
+					$submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1171
+				}
1172
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173
+				$subform_input_values = $subsection->submitted_values($include_subforms);
1174
+				$submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1175
+			}
1176
+		}
1177
+		return $submitted_values;
1178
+	}
1179
+
1180
+
1181
+	/**
1182
+	 * Indicates whether or not this form has received a submission yet
1183
+	 * (ie, had receive_form_submission called on it yet)
1184
+	 *
1185
+	 * @return boolean
1186
+	 * @throws EE_Error
1187
+	 */
1188
+	public function has_received_submission()
1189
+	{
1190
+		$this->ensure_construct_finalized_called();
1191
+		return $this->_received_submission;
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * Equivalent to passing 'exclude' in the constructor's options array.
1197
+	 * Removes the listed inputs from the form
1198
+	 *
1199
+	 * @param array $inputs_to_exclude values are the input names
1200
+	 * @return void
1201
+	 */
1202
+	public function exclude(array $inputs_to_exclude = array())
1203
+	{
1204
+		foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
+			unset($this->_subsections[ $input_to_exclude_name ]);
1206
+		}
1207
+	}
1208
+
1209
+
1210
+	/**
1211
+	 * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy.
1212
+	 * @param array $inputs_to_hide
1213
+	 * @throws EE_Error
1214
+	 */
1215
+	public function hide(array $inputs_to_hide = array())
1216
+	{
1217
+		foreach ($inputs_to_hide as $input_to_hide) {
1218
+			$input = $this->get_input($input_to_hide);
1219
+			$input->set_display_strategy(new EE_Hidden_Display_Strategy());
1220
+		}
1221
+	}
1222
+
1223
+
1224
+	/**
1225
+	 * add_subsections
1226
+	 * Adds the listed subsections to the form section.
1227
+	 * If $subsection_name_to_target is provided,
1228
+	 * then new subsections are added before or after that subsection,
1229
+	 * otherwise to the start or end of the entire subsections array.
1230
+	 *
1231
+	 * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1232
+	 *                                                          where keys are their names
1233
+	 * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1234
+	 *                                                          should be added before or after
1235
+	 *                                                          IF $subsection_name_to_target is null,
1236
+	 *                                                          then $new_subsections will be added to
1237
+	 *                                                          the beginning or end of the entire subsections array
1238
+	 * @param boolean                $add_before                whether to add $new_subsections, before or after
1239
+	 *                                                          $subsection_name_to_target,
1240
+	 *                                                          or if $subsection_name_to_target is null,
1241
+	 *                                                          before or after entire subsections array
1242
+	 * @return void
1243
+	 * @throws EE_Error
1244
+	 */
1245
+	public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1246
+	{
1247
+		foreach ($new_subsections as $subsection_name => $subsection) {
1248
+			if (! $subsection instanceof EE_Form_Section_Base) {
1249
+				EE_Error::add_error(
1250
+					sprintf(
1251
+						esc_html__(
1252
+							"Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1253
+							'event_espresso'
1254
+						),
1255
+						get_class($subsection),
1256
+						$subsection_name,
1257
+						$this->name()
1258
+					)
1259
+				);
1260
+				unset($new_subsections[ $subsection_name ]);
1261
+			}
1262
+		}
1263
+		$this->_subsections = EEH_Array::insert_into_array(
1264
+			$this->_subsections,
1265
+			$new_subsections,
1266
+			$subsection_name_to_target,
1267
+			$add_before
1268
+		);
1269
+		if ($this->_construction_finalized) {
1270
+			foreach ($this->_subsections as $name => $subsection) {
1271
+				$subsection->_construct_finalize($this, $name);
1272
+			}
1273
+		}
1274
+	}
1275
+
1276
+
1277
+	/**
1278
+	 * @param string $subsection_name
1279
+	 * @param bool   $recursive
1280
+	 * @return bool
1281
+	 */
1282
+	public function has_subsection($subsection_name, $recursive = false)
1283
+	{
1284
+		foreach ($this->_subsections as $name => $subsection) {
1285
+			if ($name === $subsection_name
1286
+				|| (
1287
+					$recursive
1288
+					&& $subsection instanceof EE_Form_Section_Proper
1289
+					&& $subsection->has_subsection($subsection_name, $recursive)
1290
+				)
1291
+			) {
1292
+				return true;
1293
+			}
1294
+		}
1295
+		return false;
1296
+	}
1297
+
1298
+
1299
+
1300
+	/**
1301
+	 * Just gets all validatable subsections to clean their sensitive data
1302
+	 *
1303
+	 * @throws EE_Error
1304
+	 */
1305
+	public function clean_sensitive_data()
1306
+	{
1307
+		foreach ($this->get_validatable_subsections() as $subsection) {
1308
+			$subsection->clean_sensitive_data();
1309
+		}
1310
+	}
1311
+
1312
+
1313
+	/**
1314
+	 * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1315
+	 * @param string                           $form_submission_error_message
1316
+	 * @param EE_Form_Section_Validatable $form_section unused
1317
+	 * @throws EE_Error
1318
+	 */
1319
+	public function set_submission_error_message(
1320
+		$form_submission_error_message = ''
1321
+	) {
1322
+		$this->_form_submission_error_message = ! empty($form_submission_error_message)
1323
+			? $form_submission_error_message
1324
+			: $this->getAllValidationErrorsString();
1325
+	}
1326
+
1327
+
1328
+	/**
1329
+	 * Returns the cached error message. A default value is set for this during _validate(),
1330
+	 * (called during receive_form_submission) but it can be explicitly set using
1331
+	 * set_submission_error_message
1332
+	 *
1333
+	 * @return string
1334
+	 */
1335
+	public function submission_error_message()
1336
+	{
1337
+		return $this->_form_submission_error_message;
1338
+	}
1339
+
1340
+
1341
+	/**
1342
+	 * Sets a message to display if the data submitted to the form was valid.
1343
+	 * @param string $form_submission_success_message
1344
+	 */
1345
+	public function set_submission_success_message($form_submission_success_message = '')
1346
+	{
1347
+		$this->_form_submission_success_message = ! empty($form_submission_success_message)
1348
+			? $form_submission_success_message
1349
+			: esc_html__('Form submitted successfully', 'event_espresso');
1350
+	}
1351
+
1352
+
1353
+	/**
1354
+	 * Gets a message appropriate for display when the form is correctly submitted
1355
+	 * @return string
1356
+	 */
1357
+	public function submission_success_message()
1358
+	{
1359
+		return $this->_form_submission_success_message;
1360
+	}
1361
+
1362
+
1363
+	/**
1364
+	 * Returns the prefix that should be used on child of this form section for
1365
+	 * their html names. If this form section itself has a parent, prepends ITS
1366
+	 * prefix onto this form section's prefix. Used primarily by
1367
+	 * EE_Form_Input_Base::_set_default_html_name_if_empty
1368
+	 *
1369
+	 * @return string
1370
+	 * @throws EE_Error
1371
+	 */
1372
+	public function html_name_prefix()
1373
+	{
1374
+		if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1375
+			return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1376
+		}
1377
+		return $this->name();
1378
+	}
1379
+
1380
+
1381
+	/**
1382
+	 * Gets the name, but first checks _construct_finalize has been called. If not,
1383
+	 * calls it (assumes there is no parent and that we want the name to be whatever
1384
+	 * was set, which is probably nothing, or the classname)
1385
+	 *
1386
+	 * @return string
1387
+	 * @throws EE_Error
1388
+	 */
1389
+	public function name()
1390
+	{
1391
+		$this->ensure_construct_finalized_called();
1392
+		return parent::name();
1393
+	}
1394
+
1395
+
1396
+	/**
1397
+	 * @return EE_Form_Section_Proper
1398
+	 * @throws EE_Error
1399
+	 */
1400
+	public function parent_section()
1401
+	{
1402
+		$this->ensure_construct_finalized_called();
1403
+		return parent::parent_section();
1404
+	}
1405
+
1406
+
1407
+	/**
1408
+	 * make sure construction finalized was called, otherwise children might not be ready
1409
+	 *
1410
+	 * @return void
1411
+	 * @throws EE_Error
1412
+	 */
1413
+	public function ensure_construct_finalized_called()
1414
+	{
1415
+		if (! $this->_construction_finalized) {
1416
+			$this->_construct_finalize($this->_parent_section, $this->_name);
1417
+		}
1418
+	}
1419
+
1420
+
1421
+	/**
1422
+	 * Checks if any of this form section's inputs, or any of its children's inputs,
1423
+	 * are in teh form data. If any are found, returns true. Else false
1424
+	 *
1425
+	 * @param array $req_data
1426
+	 * @return boolean
1427
+	 * @throws EE_Error
1428
+	 */
1429
+	public function form_data_present_in($req_data = null)
1430
+	{
1431
+		$req_data = $this->getCachedRequest($req_data);
1432
+		foreach ($this->subsections() as $subsection) {
1433
+			if ($subsection instanceof EE_Form_Input_Base) {
1434
+				if ($subsection->form_data_present_in($req_data)) {
1435
+					return true;
1436
+				}
1437
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
1438
+				if ($subsection->form_data_present_in($req_data)) {
1439
+					return true;
1440
+				}
1441
+			}
1442
+		}
1443
+		return false;
1444
+	}
1445
+
1446
+
1447
+	/**
1448
+	 * Gets validation errors for this form section and subsections
1449
+	 * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1450
+	 * gets the validation errors for ALL subsection
1451
+	 *
1452
+	 * @return EE_Validation_Error[]
1453
+	 * @throws EE_Error
1454
+	 */
1455
+	public function get_validation_errors_accumulated()
1456
+	{
1457
+		$validation_errors = $this->get_validation_errors();
1458
+		foreach ($this->get_validatable_subsections() as $subsection) {
1459
+			if ($subsection instanceof EE_Form_Section_Proper) {
1460
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1461
+			} else {
1462
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors();
1463
+			}
1464
+			if ($validation_errors_on_this_subsection) {
1465
+				$validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1466
+			}
1467
+		}
1468
+		return $validation_errors;
1469
+	}
1470
+
1471
+	/**
1472
+	 * Fetch validation errors from children and grandchildren and puts them in a single string.
1473
+	 * This traverses the form section tree to generate this, but you probably want to instead use
1474
+	 * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1475
+	 *
1476
+	 * @return string
1477
+	 * @since 4.9.59.p
1478
+	 */
1479
+	protected function getAllValidationErrorsString()
1480
+	{
1481
+		$submission_error_messages = array();
1482
+		// bad, bad, bad registrant
1483
+		foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1484
+			if ($validation_error instanceof EE_Validation_Error) {
1485
+				$form_section = $validation_error->get_form_section();
1486
+				if ($form_section instanceof EE_Form_Input_Base) {
1487
+					$label = $validation_error->get_form_section()->html_label_text();
1488
+				} elseif ($form_section instanceof EE_Form_Section_Validatable) {
1489
+					$label = $validation_error->get_form_section()->name();
1490
+				} else {
1491
+					$label = esc_html__('Unknown', 'event_espresso');
1492
+				}
1493
+				$submission_error_messages[] = sprintf(
1494
+					__('%s : %s', 'event_espresso'),
1495
+					$label,
1496
+					$validation_error->getMessage()
1497
+				);
1498
+			}
1499
+		}
1500
+		return implode('<br', $submission_error_messages);
1501
+	}
1502
+
1503
+
1504
+	/**
1505
+	 * This isn't just the name of an input, it's a path pointing to an input. The
1506
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
1507
+	 * dot-dot-slash (../) means to ascend into the parent section.
1508
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1509
+	 * which will be returned.
1510
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1511
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1512
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1513
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1514
+	 * Etc
1515
+	 *
1516
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1517
+	 * @return EE_Form_Section_Base
1518
+	 * @throws EE_Error
1519
+	 */
1520
+	public function find_section_from_path($form_section_path)
1521
+	{
1522
+		// check if we can find the input from purely going straight up the tree
1523
+		$input = parent::find_section_from_path($form_section_path);
1524
+		if ($input instanceof EE_Form_Section_Base) {
1525
+			return $input;
1526
+		}
1527
+		$next_slash_pos = strpos($form_section_path, '/');
1528
+		if ($next_slash_pos !== false) {
1529
+			$child_section_name = substr($form_section_path, 0, $next_slash_pos);
1530
+			$subpath            = substr($form_section_path, $next_slash_pos + 1);
1531
+		} else {
1532
+			$child_section_name = $form_section_path;
1533
+			$subpath            = '';
1534
+		}
1535
+		$child_section = $this->get_subsection($child_section_name);
1536
+		if ($child_section instanceof EE_Form_Section_Base) {
1537
+			return $child_section->find_section_from_path($subpath);
1538
+		}
1539
+		return null;
1540
+	}
1541 1541
 }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
             // AND we are going to make sure they're in that specified order
112 112
             $reordered_subsections = array();
113 113
             foreach ($options_array['include'] as $input_name) {
114
-                if (isset($this->_subsections[ $input_name ])) {
115
-                    $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
114
+                if (isset($this->_subsections[$input_name])) {
115
+                    $reordered_subsections[$input_name] = $this->_subsections[$input_name];
116 116
                 }
117 117
             }
118 118
             $this->_subsections = $reordered_subsections;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
         if (isset($options_array['layout_strategy'])) {
125 125
             $this->_layout_strategy = $options_array['layout_strategy'];
126 126
         }
127
-        if (! $this->_layout_strategy) {
127
+        if ( ! $this->_layout_strategy) {
128 128
             $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129 129
         }
130 130
         $this->_layout_strategy->_construct_finalize($this);
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
         if ($validate) {
314 314
             $this->_validate();
315 315
             // if it's invalid, we're going to want to re-display so remember what they submitted
316
-            if (! $this->is_valid()) {
316
+            if ( ! $this->is_valid()) {
317 317
                 $this->store_submitted_form_data_in_session();
318 318
             }
319 319
         }
@@ -426,11 +426,11 @@  discard block
 block discarded – undo
426 426
     public function populate_defaults($default_data)
427 427
     {
428 428
         foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
-            if (isset($default_data[ $subsection_name ])) {
429
+            if (isset($default_data[$subsection_name])) {
430 430
                 if ($subsection instanceof EE_Form_Input_Base) {
431
-                    $subsection->set_default($default_data[ $subsection_name ]);
431
+                    $subsection->set_default($default_data[$subsection_name]);
432 432
                 } elseif ($subsection instanceof EE_Form_Section_Proper) {
433
-                    $subsection->populate_defaults($default_data[ $subsection_name ]);
433
+                    $subsection->populate_defaults($default_data[$subsection_name]);
434 434
                 }
435 435
             }
436 436
         }
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
      */
446 446
     public function subsection_exists($name)
447 447
     {
448
-        return isset($this->_subsections[ $name ]) ? true : false;
448
+        return isset($this->_subsections[$name]) ? true : false;
449 449
     }
450 450
 
451 451
 
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
         if ($require_construction_to_be_finalized) {
468 468
             $this->ensure_construct_finalized_called();
469 469
         }
470
-        return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
470
+        return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
471 471
     }
472 472
 
473 473
 
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
         $validatable_subsections = array();
483 483
         foreach ($this->subsections() as $name => $obj) {
484 484
             if ($obj instanceof EE_Form_Section_Validatable) {
485
-                $validatable_subsections[ $name ] = $obj;
485
+                $validatable_subsections[$name] = $obj;
486 486
             }
487 487
         }
488 488
         return $validatable_subsections;
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
             $name,
510 510
             $require_construction_to_be_finalized
511 511
         );
512
-        if (! $subsection instanceof EE_Form_Input_Base) {
512
+        if ( ! $subsection instanceof EE_Form_Input_Base) {
513 513
             throw new EE_Error(
514 514
                 sprintf(
515 515
                     esc_html__(
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
             $name,
547 547
             $require_construction_to_be_finalized
548 548
         );
549
-        if (! $subsection instanceof EE_Form_Section_Proper) {
549
+        if ( ! $subsection instanceof EE_Form_Section_Proper) {
550 550
             throw new EE_Error(
551 551
                 sprintf(
552 552
                     esc_html__(
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
     public function is_valid()
587 587
     {
588 588
         if ($this->is_valid === null) {
589
-            if (! $this->has_received_submission()) {
589
+            if ( ! $this->has_received_submission()) {
590 590
                 throw new EE_Error(
591 591
                     sprintf(
592 592
                         esc_html__(
@@ -596,14 +596,14 @@  discard block
 block discarded – undo
596 596
                     )
597 597
                 );
598 598
             }
599
-            if (! parent::is_valid()) {
599
+            if ( ! parent::is_valid()) {
600 600
                 $this->is_valid = false;
601 601
             } else {
602 602
                 // ok so no general errors to this entire form section.
603 603
                 // so let's check the subsections, but only set errors if that hasn't been done yet
604 604
                 $this->is_valid = true;
605 605
                 foreach ($this->get_validatable_subsections() as $subsection) {
606
-                    if (! $subsection->is_valid()) {
606
+                    if ( ! $subsection->is_valid()) {
607 607
                         $this->is_valid = false;
608 608
                     }
609 609
                 }
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
      */
621 621
     protected function _set_default_name_if_empty()
622 622
     {
623
-        if (! $this->_name) {
623
+        if ( ! $this->_name) {
624 624
             $classname    = get_class($this);
625 625
             $default_name = str_replace('EE_', '', $classname);
626 626
             $this->_name  = $default_name;
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
     {
711 711
         wp_register_script(
712 712
             'ee_form_section_validation',
713
-            EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js',
713
+            EE_GLOBAL_ASSETS_URL.'scripts'.'/form_section_validation.js',
714 714
             array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715 715
             EVENT_ESPRESSO_VERSION,
716 716
             true
@@ -754,13 +754,13 @@  discard block
 block discarded – undo
754 754
         // we only want to localize vars ONCE for the entire form,
755 755
         // so if the form section doesn't have a parent, then it must be the top dog
756 756
         if ($return_for_subsection || ! $this->parent_section()) {
757
-            EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
757
+            EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
758 758
                 'form_section_id'  => $this->html_id(true),
759 759
                 'validation_rules' => $this->get_jquery_validation_rules(),
760 760
                 'other_data'       => $this->get_other_js_data(),
761 761
                 'errors'           => $this->subsection_validation_errors_by_html_name(),
762 762
             );
763
-            EE_Form_Section_Proper::$_scripts_localized                                = true;
763
+            EE_Form_Section_Proper::$_scripts_localized = true;
764 764
         }
765 765
     }
766 766
 
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
         $inputs = array();
796 796
         foreach ($this->subsections() as $subsection) {
797 797
             if ($subsection instanceof EE_Form_Input_Base) {
798
-                $inputs[ $subsection->html_name() ] = $subsection;
798
+                $inputs[$subsection->html_name()] = $subsection;
799 799
             } elseif ($subsection instanceof EE_Form_Section_Proper) {
800 800
                 $inputs += $subsection->inputs_in_subsections();
801 801
             }
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
         $errors = array();
819 819
         foreach ($inputs as $form_input) {
820 820
             if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
-                $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
821
+                $errors[$form_input->html_name()] = $form_input->get_validation_error_string();
822 822
             }
823 823
         }
824 824
         return $errors;
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
         $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842 842
             ? EE_Registry::instance()->CFG->registration->email_validation_level
843 843
             : 'wp_default';
844
-        EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
844
+        EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
845 845
         wp_enqueue_script('ee_form_section_validation');
846 846
         wp_localize_script(
847 847
             'ee_form_section_validation',
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
      */
859 859
     public function ensure_scripts_localized()
860 860
     {
861
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
861
+        if ( ! EE_Form_Section_Proper::$_scripts_localized) {
862 862
             $this->_enqueue_and_localize_form_js();
863 863
         }
864 864
     }
@@ -954,8 +954,8 @@  discard block
 block discarded – undo
954 954
         // reset the cache of whether this form is valid or not- we're re-validating it now
955 955
         $this->is_valid = null;
956 956
         foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
-            if (method_exists($this, '_validate_' . $subsection_name)) {
958
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
957
+            if (method_exists($this, '_validate_'.$subsection_name)) {
958
+                call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection));
959 959
             }
960 960
             $subsection->_validate();
961 961
         }
@@ -973,9 +973,9 @@  discard block
 block discarded – undo
973 973
         $inputs = array();
974 974
         foreach ($this->subsections() as $subsection_name => $subsection) {
975 975
             if ($subsection instanceof EE_Form_Section_Proper) {
976
-                $inputs[ $subsection_name ] = $subsection->valid_data();
976
+                $inputs[$subsection_name] = $subsection->valid_data();
977 977
             } elseif ($subsection instanceof EE_Form_Input_Base) {
978
-                $inputs[ $subsection_name ] = $subsection->normalized_value();
978
+                $inputs[$subsection_name] = $subsection->normalized_value();
979 979
             }
980 980
         }
981 981
         return $inputs;
@@ -993,7 +993,7 @@  discard block
 block discarded – undo
993 993
         $inputs = array();
994 994
         foreach ($this->subsections() as $subsection_name => $subsection) {
995 995
             if ($subsection instanceof EE_Form_Input_Base) {
996
-                $inputs[ $subsection_name ] = $subsection;
996
+                $inputs[$subsection_name] = $subsection;
997 997
             }
998 998
         }
999 999
         return $inputs;
@@ -1011,7 +1011,7 @@  discard block
 block discarded – undo
1011 1011
         $form_sections = array();
1012 1012
         foreach ($this->subsections() as $name => $obj) {
1013 1013
             if ($obj instanceof EE_Form_Section_Proper) {
1014
-                $form_sections[ $name ] = $obj;
1014
+                $form_sections[$name] = $obj;
1015 1015
             }
1016 1016
         }
1017 1017
         return $form_sections;
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
         $input_values = array();
1119 1119
         foreach ($this->subsections() as $subsection_name => $subsection) {
1120 1120
             if ($subsection instanceof EE_Form_Input_Base) {
1121
-                $input_values[ $subsection_name ] = $pretty
1121
+                $input_values[$subsection_name] = $pretty
1122 1122
                     ? $subsection->pretty_value()
1123 1123
                     : $subsection->normalized_value();
1124 1124
             } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
@@ -1130,7 +1130,7 @@  discard block
 block discarded – undo
1130 1130
                 if ($flatten) {
1131 1131
                     $input_values = array_merge($input_values, $subform_input_values);
1132 1132
                 } else {
1133
-                    $input_values[ $subsection_name ] = $subform_input_values;
1133
+                    $input_values[$subsection_name] = $subform_input_values;
1134 1134
                 }
1135 1135
             }
1136 1136
         }
@@ -1158,7 +1158,7 @@  discard block
 block discarded – undo
1158 1158
             if ($subsection instanceof EE_Form_Input_Base) {
1159 1159
                 // is this input part of an array of inputs?
1160 1160
                 if (strpos($subsection->html_name(), '[') !== false) {
1161
-                    $full_input_name  = EEH_Array::convert_array_values_to_keys(
1161
+                    $full_input_name = EEH_Array::convert_array_values_to_keys(
1162 1162
                         explode(
1163 1163
                             '[',
1164 1164
                             str_replace(']', '', $subsection->html_name())
@@ -1167,7 +1167,7 @@  discard block
 block discarded – undo
1167 1167
                     );
1168 1168
                     $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169 1169
                 } else {
1170
-                    $submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1170
+                    $submitted_values[$subsection->html_name()] = $subsection->raw_value();
1171 1171
                 }
1172 1172
             } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173 1173
                 $subform_input_values = $subsection->submitted_values($include_subforms);
@@ -1202,7 +1202,7 @@  discard block
 block discarded – undo
1202 1202
     public function exclude(array $inputs_to_exclude = array())
1203 1203
     {
1204 1204
         foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
-            unset($this->_subsections[ $input_to_exclude_name ]);
1205
+            unset($this->_subsections[$input_to_exclude_name]);
1206 1206
         }
1207 1207
     }
1208 1208
 
@@ -1245,7 +1245,7 @@  discard block
 block discarded – undo
1245 1245
     public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1246 1246
     {
1247 1247
         foreach ($new_subsections as $subsection_name => $subsection) {
1248
-            if (! $subsection instanceof EE_Form_Section_Base) {
1248
+            if ( ! $subsection instanceof EE_Form_Section_Base) {
1249 1249
                 EE_Error::add_error(
1250 1250
                     sprintf(
1251 1251
                         esc_html__(
@@ -1257,7 +1257,7 @@  discard block
 block discarded – undo
1257 1257
                         $this->name()
1258 1258
                     )
1259 1259
                 );
1260
-                unset($new_subsections[ $subsection_name ]);
1260
+                unset($new_subsections[$subsection_name]);
1261 1261
             }
1262 1262
         }
1263 1263
         $this->_subsections = EEH_Array::insert_into_array(
@@ -1372,7 +1372,7 @@  discard block
 block discarded – undo
1372 1372
     public function html_name_prefix()
1373 1373
     {
1374 1374
         if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1375
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1375
+            return $this->parent_section()->html_name_prefix().'['.$this->name().']';
1376 1376
         }
1377 1377
         return $this->name();
1378 1378
     }
@@ -1412,7 +1412,7 @@  discard block
 block discarded – undo
1412 1412
      */
1413 1413
     public function ensure_construct_finalized_called()
1414 1414
     {
1415
-        if (! $this->_construction_finalized) {
1415
+        if ( ! $this->_construction_finalized) {
1416 1416
             $this->_construct_finalize($this->_parent_section, $this->_name);
1417 1417
         }
1418 1418
     }
Please login to merge, or discard this patch.