Completed
Branch BUG-10236-refresh-fix-reset-ca... (625540)
by
unknown
13:14 queued 17s
created
core/EE_System.core.php 1 patch
Indentation   +1432 added lines, -1432 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\shortcodes\ShortcodesManager;
5 5
 
6 6
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -21,1437 +21,1437 @@  discard block
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
26
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
27
-     */
28
-    const req_type_normal = 0;
29
-
30
-    /**
31
-     * Indicates this is a brand new installation of EE so we should install
32
-     * tables and default data etc
33
-     */
34
-    const req_type_new_activation = 1;
35
-
36
-    /**
37
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
38
-     * and we just exited maintenance mode). We MUST check the database is setup properly
39
-     * and that default data is setup too
40
-     */
41
-    const req_type_reactivation = 2;
42
-
43
-    /**
44
-     * indicates that EE has been upgraded since its previous request.
45
-     * We may have data migration scripts to call and will want to trigger maintenance mode
46
-     */
47
-    const req_type_upgrade = 3;
48
-
49
-    /**
50
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
51
-     */
52
-    const req_type_downgrade = 4;
53
-
54
-    /**
55
-     * @deprecated since version 4.6.0.dev.006
56
-     * Now whenever a new_activation is detected the request type is still just
57
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
58
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
59
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
60
-     * (Specifically, when the migration manager indicates migrations are finished
61
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
62
-     */
63
-    const req_type_activation_but_not_installed = 5;
64
-
65
-    /**
66
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
67
-     */
68
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
69
-
70
-
71
-    /**
72
-     *    instance of the EE_System object
73
-     *
74
-     * @var    $_instance
75
-     * @access    private
76
-     */
77
-    private static $_instance = null;
78
-
79
-    /**
80
-     * @type  EE_Registry $Registry
81
-     * @access    protected
82
-     */
83
-    protected $registry;
84
-
85
-    /**
86
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
87
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
88
-     *
89
-     * @var int
90
-     */
91
-    private $_req_type;
92
-
93
-    /**
94
-     * Whether or not there was a non-micro version change in EE core version during this request
95
-     *
96
-     * @var boolean
97
-     */
98
-    private $_major_version_change = false;
99
-
100
-
101
-
102
-    /**
103
-     * @singleton method used to instantiate class object
104
-     * @access    public
105
-     * @param  \EE_Registry $Registry
106
-     * @return \EE_System
107
-     */
108
-    public static function instance(EE_Registry $Registry = null)
109
-    {
110
-        // check if class object is instantiated
111
-        if ( ! self::$_instance instanceof EE_System) {
112
-            self::$_instance = new self($Registry);
113
-        }
114
-        return self::$_instance;
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     * resets the instance and returns it
121
-     *
122
-     * @return EE_System
123
-     */
124
-    public static function reset()
125
-    {
126
-        self::$_instance->_req_type = null;
127
-        //make sure none of the old hooks are left hanging around
128
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
129
-        //we need to reset the migration manager in order for it to detect DMSs properly
130
-        EE_Data_Migration_Manager::reset();
131
-        self::instance()->detect_activations_or_upgrades();
132
-        self::instance()->perform_activations_upgrades_and_migrations();
133
-        return self::instance();
134
-    }
135
-
136
-
137
-
138
-    /**
139
-     *    sets hooks for running rest of system
140
-     *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
141
-     *    starting EE Addons from any other point may lead to problems
142
-     *
143
-     * @access private
144
-     * @param  \EE_Registry $Registry
145
-     */
146
-    private function __construct(EE_Registry $Registry)
147
-    {
148
-        $this->registry = $Registry;
149
-        do_action('AHEE__EE_System__construct__begin', $this);
150
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
151
-        add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
152
-        // right before the plugin is saved to the active_plugins option, we want to call the core hook(s) again
153
-        // because the newly-activated addon has not executed yet.
154
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
155
-        // detect whether install or upgrade
156
-        add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
157
-            3);
158
-        // load EE_Config, EE_Textdomain, etc
159
-        add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
160
-        // load EE_Config, EE_Textdomain, etc
161
-        add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
162
-            array($this, 'register_shortcodes_modules_and_widgets'), 7);
163
-        // you wanna get going? I wanna get going... let's get going!
164
-        add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
165
-        //other housekeeping
166
-        //exclude EE critical pages from wp_list_pages
167
-        add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
168
-        // ALL EE Addons should use the following hook point to attach their initial setup too
169
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when
170
-        // the EE_Config loads
171
-        do_action('AHEE__EE_System__construct__complete', $this);
172
-    }
173
-
174
-
175
-    /**
176
-     * load_espresso_addons
177
-     * allow addons to load first so that they can set hooks for running DMS's, etc
178
-     * this is hooked into both:
179
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
180
-     *        which runs during the WP 'plugins_loaded' action at priority 5
181
-     *    and the WP 'activate_plugin' hookpoint
182
-     *
183
-     * @access public
184
-     * @return void
185
-     * @throws EE_Error
186
-     * @throws \EventEspresso\core\exceptions\InvalidExecutionPathException
187
-     */
188
-    public function load_espresso_addons()
189
-    {
190
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
191
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
192
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
193
-        //load and setup EE_Capabilities
194
-        $this->registry->load_core('Capabilities');
195
-
196
-        do_action('AHEE__EE_System__load_espresso_addons');
197
-        //if the WP API basic auth plugin isn't already loaded, load it now.
198
-        //We want it for mobile apps. Just include the entire plugin
199
-        //also, don't load the basic auth when a plugin is getting activated, because
200
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
201
-        //and causes a fatal error
202
-        if ( ! function_exists('json_basic_auth_handler')
203
-             && ! function_exists('json_basic_auth_error')
204
-             && ! (
205
-                isset($_GET['action'])
206
-                && in_array($_GET['action'], array('activate', 'activate-selected'))
207
-            )
208
-             && ! (
209
-                isset($_GET['activate'])
210
-                && $_GET['activate'] === 'true'
211
-            )
212
-        ) {
213
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
214
-        }
215
-        $this->_maybe_brew_regular();
216
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
217
-        $this->registry->CAP->init_caps();
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * detect_activations_or_upgrades
224
-     * Checks for activation or upgrade of core first;
225
-     * then also checks if any registered addons have been activated or upgraded
226
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
227
-     * which runs during the WP 'plugins_loaded' action at priority 3
228
-     *
229
-     * @access public
230
-     * @return void
231
-     */
232
-    public function detect_activations_or_upgrades()
233
-    {
234
-        //first off: let's make sure to handle core
235
-        $this->detect_if_activation_or_upgrade();
236
-        foreach ($this->registry->addons as $addon) {
237
-            //detect teh request type for that addon
238
-            $addon->detect_activation_or_upgrade();
239
-        }
240
-    }
241
-
242
-
243
-
244
-    /**
245
-     * detect_if_activation_or_upgrade
246
-     * Takes care of detecting whether this is a brand new install or code upgrade,
247
-     * and either setting up the DB or setting up maintenance mode etc.
248
-     *
249
-     * @access public
250
-     * @return void
251
-     */
252
-    public function detect_if_activation_or_upgrade()
253
-    {
254
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
255
-        // load M-Mode class
256
-        $this->registry->load_core('Maintenance_Mode');
257
-        // check if db has been updated, or if its a brand-new installation
258
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
259
-        $request_type = $this->detect_req_type($espresso_db_update);
260
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
261
-        switch ($request_type) {
262
-            case EE_System::req_type_new_activation:
263
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
264
-                $this->_handle_core_version_change($espresso_db_update);
265
-                break;
266
-            case EE_System::req_type_reactivation:
267
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
268
-                $this->_handle_core_version_change($espresso_db_update);
269
-                break;
270
-            case EE_System::req_type_upgrade:
271
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
272
-                //migrations may be required now that we've upgraded
273
-                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
274
-                $this->_handle_core_version_change($espresso_db_update);
275
-                //				echo "done upgrade";die;
276
-                break;
277
-            case EE_System::req_type_downgrade:
278
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
279
-                //its possible migrations are no longer required
280
-                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
281
-                $this->_handle_core_version_change($espresso_db_update);
282
-                break;
283
-            case EE_System::req_type_normal:
284
-            default:
285
-                //				$this->_maybe_redirect_to_ee_about();
286
-                break;
287
-        }
288
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
289
-    }
290
-
291
-
292
-
293
-    /**
294
-     * Updates the list of installed versions and sets hooks for
295
-     * initializing the database later during the request
296
-     *
297
-     * @param array $espresso_db_update
298
-     */
299
-    protected function _handle_core_version_change($espresso_db_update)
300
-    {
301
-        $this->update_list_of_installed_versions($espresso_db_update);
302
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
303
-        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
304
-            array($this, 'initialize_db_if_no_migrations_required'));
305
-    }
306
-
307
-
308
-
309
-    /**
310
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
311
-     * information about what versions of EE have been installed and activated,
312
-     * NOT necessarily the state of the database
313
-     *
314
-     * @param null $espresso_db_update
315
-     * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
316
-     *           from the options table
317
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
318
-     */
319
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
320
-    {
321
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
322
-        if ( ! $espresso_db_update) {
323
-            $espresso_db_update = get_option('espresso_db_update');
324
-        }
325
-        // check that option is an array
326
-        if ( ! is_array($espresso_db_update)) {
327
-            // if option is FALSE, then it never existed
328
-            if ($espresso_db_update === false) {
329
-                // make $espresso_db_update an array and save option with autoload OFF
330
-                $espresso_db_update = array();
331
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
332
-            } else {
333
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
334
-                $espresso_db_update = array($espresso_db_update => array());
335
-                update_option('espresso_db_update', $espresso_db_update);
336
-            }
337
-        } else {
338
-            $corrected_db_update = array();
339
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
340
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
341
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
342
-                    //the key is an int, and the value IS NOT an array
343
-                    //so it must be numerically-indexed, where values are versions installed...
344
-                    //fix it!
345
-                    $version_string = $should_be_array;
346
-                    $corrected_db_update[$version_string] = array('unknown-date');
347
-                } else {
348
-                    //ok it checks out
349
-                    $corrected_db_update[$should_be_version_string] = $should_be_array;
350
-                }
351
-            }
352
-            $espresso_db_update = $corrected_db_update;
353
-            update_option('espresso_db_update', $espresso_db_update);
354
-        }
355
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
356
-        return $espresso_db_update;
357
-    }
358
-
359
-
360
-    /**
361
-     * Does the traditional work of setting up the plugin's database and adding default data.
362
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
363
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
364
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
365
-     * so that it will be done when migrations are finished
366
-     *
367
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
368
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
369
-     *                                       This is a resource-intensive job
370
-     *                                       so we prefer to only do it when necessary
371
-     * @return void
372
-     * @throws EE_Error
373
-     */
374
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
375
-    {
376
-        $request_type = $this->detect_req_type();
377
-        //only initialize system if we're not in maintenance mode.
378
-        if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
379
-            update_option('ee_flush_rewrite_rules', true);
380
-            if ($verify_schema) {
381
-                EEH_Activation::initialize_db_and_folders();
382
-            }
383
-            EEH_Activation::initialize_db_content();
384
-            EEH_Activation::system_initialization();
385
-            if ($initialize_addons_too) {
386
-                $this->initialize_addons();
387
-            }
388
-        } else {
389
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
390
-        }
391
-        if ($request_type === EE_System::req_type_new_activation
392
-            || $request_type === EE_System::req_type_reactivation
393
-            || (
394
-                $request_type === EE_System::req_type_upgrade
395
-                && $this->is_major_version_change()
396
-            )
397
-        ) {
398
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
399
-        }
400
-    }
401
-
402
-
403
-
404
-    /**
405
-     * Initializes the db for all registered addons
406
-     */
407
-    public function initialize_addons()
408
-    {
409
-        //foreach registered addon, make sure its db is up-to-date too
410
-        foreach ($this->registry->addons as $addon) {
411
-            $addon->initialize_db_if_no_migrations_required();
412
-        }
413
-    }
414
-
415
-
416
-
417
-    /**
418
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
419
-     *
420
-     * @param    array  $version_history
421
-     * @param    string $current_version_to_add version to be added to the version history
422
-     * @return    boolean success as to whether or not this option was changed
423
-     */
424
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
425
-    {
426
-        if ( ! $version_history) {
427
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
428
-        }
429
-        if ($current_version_to_add == null) {
430
-            $current_version_to_add = espresso_version();
431
-        }
432
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
433
-        // re-save
434
-        return update_option('espresso_db_update', $version_history);
435
-    }
436
-
437
-
438
-
439
-    /**
440
-     * Detects if the current version indicated in the has existed in the list of
441
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
442
-     *
443
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
444
-     *                                  If not supplied, fetches it from the options table.
445
-     *                                  Also, caches its result so later parts of the code can also know whether
446
-     *                                  there's been an update or not. This way we can add the current version to
447
-     *                                  espresso_db_update, but still know if this is a new install or not
448
-     * @return int one of the constants on EE_System::req_type_
449
-     */
450
-    public function detect_req_type($espresso_db_update = null)
451
-    {
452
-        if ($this->_req_type === null) {
453
-            $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
454
-                : $this->fix_espresso_db_upgrade_option();
455
-            $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
456
-                'ee_espresso_activation', espresso_version());
457
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
458
-        }
459
-        return $this->_req_type;
460
-    }
461
-
462
-
463
-
464
-    /**
465
-     * Returns whether or not there was a non-micro version change (ie, change in either
466
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
467
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
468
-     *
469
-     * @param $activation_history
470
-     * @return bool
471
-     */
472
-    protected function _detect_major_version_change($activation_history)
473
-    {
474
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
475
-        $previous_version_parts = explode('.', $previous_version);
476
-        $current_version_parts = explode('.', espresso_version());
477
-        return isset(
478
-            $previous_version_parts[0],
479
-            $previous_version_parts[1],
480
-            $current_version_parts[0],
481
-            $current_version_parts[1]
482
-        )
483
-               && ($previous_version_parts[0] !== $current_version_parts[0]
484
-                   || $previous_version_parts[1] !== $current_version_parts[1]
485
-               );
486
-    }
487
-
488
-
489
-
490
-    /**
491
-     * Returns true if either the major or minor version of EE changed during this request.
492
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
493
-     *
494
-     * @return bool
495
-     */
496
-    public function is_major_version_change()
497
-    {
498
-        return $this->_major_version_change;
499
-    }
500
-
501
-
502
-
503
-    /**
504
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
505
-     * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
506
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
507
-     * just activated to (for core that will always be espresso_version())
508
-     *
509
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
510
-     *                                                 ee plugin. for core that's 'espresso_db_update'
511
-     * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
512
-     *                                                 indicate that this plugin was just activated
513
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
514
-     *                                                 espresso_version())
515
-     * @return int one of the constants on EE_System::req_type_*
516
-     */
517
-    public static function detect_req_type_given_activation_history(
518
-        $activation_history_for_addon,
519
-        $activation_indicator_option_name,
520
-        $version_to_upgrade_to
521
-    ) {
522
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
523
-        if ($activation_history_for_addon) {
524
-            //it exists, so this isn't a completely new install
525
-            //check if this version already in that list of previously installed versions
526
-            if (! isset($activation_history_for_addon[$version_to_upgrade_to])) {
527
-                //it a version we haven't seen before
528
-                if ($version_is_higher === 1) {
529
-                    $req_type = EE_System::req_type_upgrade;
530
-                } else {
531
-                    $req_type = EE_System::req_type_downgrade;
532
-                }
533
-                delete_option($activation_indicator_option_name);
534
-            } else {
535
-                // its not an update. maybe a reactivation?
536
-                if (get_option($activation_indicator_option_name, false)) {
537
-                    if ($version_is_higher === -1) {
538
-                        $req_type = EE_System::req_type_downgrade;
539
-                    } elseif ($version_is_higher === 0) {
540
-                        //we've seen this version before, but it's an activation. must be a reactivation
541
-                        $req_type = EE_System::req_type_reactivation;
542
-                    } else {//$version_is_higher === 1
543
-                        $req_type = EE_System::req_type_upgrade;
544
-                    }
545
-                    delete_option($activation_indicator_option_name);
546
-                } else {
547
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
548
-                    if ($version_is_higher === -1) {
549
-                        $req_type = EE_System::req_type_downgrade;
550
-                    } elseif ($version_is_higher === 0) {
551
-                        //we've seen this version before and it's not an activation. its normal request
552
-                        $req_type = EE_System::req_type_normal;
553
-                    } else {//$version_is_higher === 1
554
-                        $req_type = EE_System::req_type_upgrade;
555
-                    }
556
-                }
557
-            }
558
-        } else {
559
-            //brand new install
560
-            $req_type = EE_System::req_type_new_activation;
561
-            delete_option($activation_indicator_option_name);
562
-        }
563
-        return $req_type;
564
-    }
565
-
566
-
567
-
568
-    /**
569
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
570
-     * the $activation_history_for_addon
571
-     *
572
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
573
-     *                                             sometimes containing 'unknown-date'
574
-     * @param string $version_to_upgrade_to        (current version)
575
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
576
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
577
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
578
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
579
-     */
580
-    protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
581
-    {
582
-        //find the most recently-activated version
583
-        $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history(
584
-            $activation_history_for_addon
585
-        );
586
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
587
-    }
588
-
589
-
590
-
591
-    /**
592
-     * Gets the most recently active version listed in the activation history,
593
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
594
-     *
595
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
596
-     *                                   sometimes containing 'unknown-date'
597
-     * @return string
598
-     */
599
-    protected static function _get_most_recently_active_version_from_activation_history($activation_history)
600
-    {
601
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
602
-        $most_recently_active_version = '0.0.0.dev.000';
603
-        if (is_array($activation_history)) {
604
-            foreach ($activation_history as $version => $times_activated) {
605
-                //check there is a record of when this version was activated. Otherwise,
606
-                //mark it as unknown
607
-                if (! $times_activated) {
608
-                    $times_activated = array('unknown-date');
609
-                }
610
-                if (is_string($times_activated)) {
611
-                    $times_activated = array($times_activated);
612
-                }
613
-                foreach ($times_activated as $an_activation) {
614
-                    if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
615
-                        $most_recently_active_version = $version;
616
-                        $most_recently_active_version_activation = $an_activation == 'unknown-date'
617
-                            ? '1970-01-01 00:00:00' : $an_activation;
618
-                    }
619
-                }
620
-            }
621
-        }
622
-        return $most_recently_active_version;
623
-    }
624
-
625
-
626
-
627
-    /**
628
-     * This redirects to the about EE page after activation
629
-     *
630
-     * @return void
631
-     */
632
-    public function redirect_to_about_ee()
633
-    {
634
-        $notices = EE_Error::get_notices(false);
635
-        //if current user is an admin and it's not an ajax or rest request
636
-        if (! (defined('DOING_AJAX') && DOING_AJAX)
637
-            && ! (defined('REST_REQUEST') && REST_REQUEST)
638
-            && ! isset($notices['errors'])
639
-            && apply_filters(
640
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
641
-                $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
642
-            )
643
-        ) {
644
-            $query_params = array('page' => 'espresso_about');
645
-            if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
646
-                $query_params['new_activation'] = true;
647
-            }
648
-            if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
649
-                $query_params['reactivation'] = true;
650
-            }
651
-            $url = add_query_arg($query_params, admin_url('admin.php'));
652
-            wp_safe_redirect($url);
653
-            exit();
654
-        }
655
-    }
656
-
657
-
658
-
659
-    /**
660
-     * load_core_configuration
661
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
662
-     * which runs during the WP 'plugins_loaded' action at priority 5
663
-     *
664
-     * @return void
665
-     */
666
-    public function load_core_configuration()
667
-    {
668
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
669
-        $this->registry->load_core('EE_Load_Textdomain');
670
-        //load textdomain
671
-        EE_Load_Textdomain::load_textdomain();
672
-        // load and setup EE_Config and EE_Network_Config
673
-        $this->registry->load_core('Config');
674
-        $this->registry->load_core('Network_Config');
675
-        // setup autoloaders
676
-        // enable logging?
677
-        if ($this->registry->CFG->admin->use_full_logging) {
678
-            $this->registry->load_core('Log');
679
-        }
680
-        // check for activation errors
681
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
682
-        if ($activation_errors) {
683
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
684
-            update_option('ee_plugin_activation_errors', false);
685
-        }
686
-        // get model names
687
-        $this->_parse_model_names();
688
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
689
-    }
690
-
691
-
692
-
693
-    /**
694
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
695
-     *
696
-     * @return void
697
-     */
698
-    private function _parse_model_names()
699
-    {
700
-        //get all the files in the EE_MODELS folder that end in .model.php
701
-        $models = glob(EE_MODELS . '*.model.php');
702
-        $model_names = array();
703
-        $non_abstract_db_models = array();
704
-        foreach ($models as $model) {
705
-            // get model classname
706
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
707
-            $short_name = str_replace('EEM_', '', $classname);
708
-            $reflectionClass = new ReflectionClass($classname);
709
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
710
-                $non_abstract_db_models[$short_name] = $classname;
711
-            }
712
-            $model_names[$short_name] = $classname;
713
-        }
714
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
715
-        $this->registry->non_abstract_db_models = apply_filters(
716
-            'FHEE__EE_System__parse_implemented_model_names',
717
-            $non_abstract_db_models
718
-        );
719
-    }
720
-
721
-
722
-
723
-    /**
724
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
725
-     * that need to be setup before our EE_System launches.
726
-     *
727
-     * @return void
728
-     */
729
-    private function _maybe_brew_regular()
730
-    {
731
-        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
732
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
733
-        }
734
-    }
735
-
736
-
737
-
738
-    /**
739
-     * register_shortcodes_modules_and_widgets
740
-     * generate lists of shortcodes and modules, then verify paths and classes
741
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
742
-     * which runs during the WP 'plugins_loaded' action at priority 7
743
-     *
744
-     * @access public
745
-     * @return void
746
-     */
747
-    public function register_shortcodes_modules_and_widgets()
748
-    {
749
-        try {
750
-            // load, register, and add shortcodes the new way
751
-            new ShortcodesManager(
752
-                // and the old way, but we'll put it under control of the new system
753
-                EE_Config::getLegacyShortcodesManager()
754
-            );
755
-        } catch (Exception $exception) {
756
-            new ExceptionStackTraceDisplay($exception);
757
-        }
758
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
759
-        // check for addons using old hookpoint
760
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
761
-            $this->_incompatible_addon_error();
762
-        }
763
-    }
764
-
765
-
766
-
767
-    /**
768
-     * _incompatible_addon_error
769
-     *
770
-     * @access public
771
-     * @return void
772
-     */
773
-    private function _incompatible_addon_error()
774
-    {
775
-        // get array of classes hooking into here
776
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
777
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
778
-        );
779
-        if (! empty($class_names)) {
780
-            $msg = esc_html__(
781
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
782
-                'event_espresso'
783
-            );
784
-            $msg .= '<ul>';
785
-            foreach ($class_names as $class_name) {
786
-                $msg .= '<li><b>Event Espresso - '
787
-                        . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', $class_name)
788
-                        . '</b></li>';
789
-            }
790
-            $msg .= '</ul>';
791
-            $msg .= esc_html__(
792
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
793
-                'event_espresso'
794
-            );
795
-            // save list of incompatible addons to wp-options for later use
796
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
797
-            if (is_admin()) {
798
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
799
-            }
800
-        }
801
-    }
802
-
803
-
804
-
805
-    /**
806
-     * brew_espresso
807
-     * begins the process of setting hooks for initializing EE in the correct order
808
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
809
-     * which runs during the WP 'plugins_loaded' action at priority 9
810
-     *
811
-     * @return void
812
-     */
813
-    public function brew_espresso()
814
-    {
815
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
816
-        // load some final core systems
817
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
818
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
819
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
820
-        add_action('init', array($this, 'load_controllers'), 7);
821
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
822
-        add_action('init', array($this, 'initialize'), 10);
823
-        add_action('init', array($this, 'initialize_last'), 100);
824
-        add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
825
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
826
-            // pew pew pew
827
-            $this->registry->load_core('PUE');
828
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
829
-        }
830
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
831
-    }
832
-
833
-
834
-
835
-    /**
836
-     *    set_hooks_for_core
837
-     *
838
-     * @access public
839
-     * @return    void
840
-     */
841
-    public function set_hooks_for_core()
842
-    {
843
-        $this->_deactivate_incompatible_addons();
844
-        do_action('AHEE__EE_System__set_hooks_for_core');
845
-    }
846
-
847
-
848
-
849
-    /**
850
-     * Using the information gathered in EE_System::_incompatible_addon_error,
851
-     * deactivates any addons considered incompatible with the current version of EE
852
-     */
853
-    private function _deactivate_incompatible_addons()
854
-    {
855
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
856
-        if (! empty($incompatible_addons)) {
857
-            $active_plugins = get_option('active_plugins', array());
858
-            foreach ($active_plugins as $active_plugin) {
859
-                foreach ($incompatible_addons as $incompatible_addon) {
860
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
861
-                        unset($_GET['activate']);
862
-                        espresso_deactivate_plugin($active_plugin);
863
-                    }
864
-                }
865
-            }
866
-        }
867
-    }
868
-
869
-
870
-
871
-    /**
872
-     *    perform_activations_upgrades_and_migrations
873
-     *
874
-     * @access public
875
-     * @return    void
876
-     */
877
-    public function perform_activations_upgrades_and_migrations()
878
-    {
879
-        //first check if we had previously attempted to setup EE's directories but failed
880
-        if (EEH_Activation::upload_directories_incomplete()) {
881
-            EEH_Activation::create_upload_directories();
882
-        }
883
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
884
-    }
885
-
886
-
887
-
888
-    /**
889
-     *    load_CPTs_and_session
890
-     *
891
-     * @access public
892
-     * @return    void
893
-     */
894
-    public function load_CPTs_and_session()
895
-    {
896
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
897
-        // register Custom Post Types
898
-        $this->registry->load_core('Register_CPTs');
899
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
900
-    }
901
-
902
-
903
-
904
-    /**
905
-     * load_controllers
906
-     * this is the best place to load any additional controllers that needs access to EE core.
907
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
908
-     * time
909
-     *
910
-     * @access public
911
-     * @return void
912
-     */
913
-    public function load_controllers()
914
-    {
915
-        do_action('AHEE__EE_System__load_controllers__start');
916
-        // let's get it started
917
-        if (! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
918
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
919
-            $this->registry->load_core('Front_Controller');
920
-        } elseif (! EE_FRONT_AJAX) {
921
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
922
-            EE_Registry::instance()->load_core('Admin');
923
-        }
924
-        do_action('AHEE__EE_System__load_controllers__complete');
925
-    }
926
-
927
-
928
-
929
-    /**
930
-     * core_loaded_and_ready
931
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
932
-     *
933
-     * @access public
934
-     * @return void
935
-     */
936
-    public function core_loaded_and_ready()
937
-    {
938
-        do_action('AHEE__EE_System__core_loaded_and_ready');
939
-        // load_espresso_template_tags
940
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
941
-            require_once(EE_PUBLIC . 'template_tags.php');
942
-        }
943
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
944
-        $this->registry->load_core('Session');
945
-        $this->registry->create('EventEspresso\core\services\assets\Registry');
946
-        wp_enqueue_script('espresso_core');
947
-    }
948
-
949
-
950
-
951
-    /**
952
-     * initialize
953
-     * this is the best place to begin initializing client code
954
-     *
955
-     * @access public
956
-     * @return void
957
-     */
958
-    public function initialize()
959
-    {
960
-        do_action('AHEE__EE_System__initialize');
961
-    }
962
-
963
-
964
-
965
-    /**
966
-     * initialize_last
967
-     * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
968
-     * initialize has done so
969
-     *
970
-     * @access public
971
-     * @return void
972
-     */
973
-    public function initialize_last()
974
-    {
975
-        do_action('AHEE__EE_System__initialize_last');
976
-    }
977
-
978
-
979
-
980
-    /**
981
-     * set_hooks_for_shortcodes_modules_and_addons
982
-     * this is the best place for other systems to set callbacks for hooking into other parts of EE
983
-     * this happens at the very beginning of the wp_loaded hookpoint
984
-     *
985
-     * @access public
986
-     * @return void
987
-     */
988
-    public function set_hooks_for_shortcodes_modules_and_addons()
989
-    {
990
-        //		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
991
-    }
992
-
993
-
994
-
995
-    /**
996
-     * do_not_cache
997
-     * sets no cache headers and defines no cache constants for WP plugins
998
-     *
999
-     * @access public
1000
-     * @return void
1001
-     */
1002
-    public static function do_not_cache()
1003
-    {
1004
-        // set no cache constants
1005
-        if (! defined('DONOTCACHEPAGE')) {
1006
-            define('DONOTCACHEPAGE', true);
1007
-        }
1008
-        if (! defined('DONOTCACHCEOBJECT')) {
1009
-            define('DONOTCACHCEOBJECT', true);
1010
-        }
1011
-        if (! defined('DONOTCACHEDB')) {
1012
-            define('DONOTCACHEDB', true);
1013
-        }
1014
-        // add no cache headers
1015
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1016
-        // plus a little extra for nginx and Google Chrome
1017
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1018
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes
1019
-        // with the registration process
1020
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1021
-    }
1022
-
1023
-
1024
-
1025
-    /**
1026
-     *    extra_nocache_headers
1027
-     *
1028
-     * @access    public
1029
-     * @param $headers
1030
-     * @return    array
1031
-     */
1032
-    public static function extra_nocache_headers($headers)
1033
-    {
1034
-        // for NGINX
1035
-        $headers['X-Accel-Expires'] = 0;
1036
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1037
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1038
-        return $headers;
1039
-    }
1040
-
1041
-
1042
-
1043
-    /**
1044
-     *    nocache_headers
1045
-     *
1046
-     * @access    public
1047
-     * @return    void
1048
-     */
1049
-    public static function nocache_headers()
1050
-    {
1051
-        nocache_headers();
1052
-    }
1053
-
1054
-
1055
-
1056
-    /**
1057
-     *    espresso_toolbar_items
1058
-     *
1059
-     * @access public
1060
-     * @param  WP_Admin_Bar $admin_bar
1061
-     * @return void
1062
-     */
1063
-    public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1064
-    {
1065
-        // if in full M-Mode, or its an AJAX request, or user is NOT an admin
1066
-        if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1067
-            || defined('DOING_AJAX')
1068
-            || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1069
-        ) {
1070
-            return;
1071
-        }
1072
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1073
-        $menu_class = 'espresso_menu_item_class';
1074
-        //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1075
-        //because they're only defined in each of their respective constructors
1076
-        //and this might be a frontend request, in which case they aren't available
1077
-        $events_admin_url = admin_url("admin.php?page=espresso_events");
1078
-        $reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1079
-        $extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1080
-        //Top Level
1081
-        $admin_bar->add_menu(array(
1082
-            'id'    => 'espresso-toolbar',
1083
-            'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1084
-                       . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1085
-                       . '</span>',
1086
-            'href'  => $events_admin_url,
1087
-            'meta'  => array(
1088
-                'title' => esc_html__('Event Espresso', 'event_espresso'),
1089
-                'class' => $menu_class . 'first',
1090
-            ),
1091
-        ));
1092
-        //Events
1093
-        if ($this->registry->CAP->current_user_can(
1094
-            'ee_read_events',
1095
-            'ee_admin_bar_menu_espresso-toolbar-events'
1096
-        )) {
1097
-            $admin_bar->add_menu(array(
1098
-                'id'     => 'espresso-toolbar-events',
1099
-                'parent' => 'espresso-toolbar',
1100
-                'title'  => esc_html__('Events', 'event_espresso'),
1101
-                'href'   => $events_admin_url,
1102
-                'meta'   => array(
1103
-                    'title'  => esc_html__('Events', 'event_espresso'),
1104
-                    'target' => '',
1105
-                    'class'  => $menu_class,
1106
-                ),
1107
-            ));
1108
-        }
1109
-        if ($this->registry->CAP->current_user_can(
1110
-            'ee_edit_events',
1111
-            'ee_admin_bar_menu_espresso-toolbar-events-new'
1112
-        )) {
1113
-            //Events Add New
1114
-            $admin_bar->add_menu(array(
1115
-                'id'     => 'espresso-toolbar-events-new',
1116
-                'parent' => 'espresso-toolbar-events',
1117
-                'title'  => esc_html__('Add New', 'event_espresso'),
1118
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1119
-                'meta'   => array(
1120
-                    'title'  => esc_html__('Add New', 'event_espresso'),
1121
-                    'target' => '',
1122
-                    'class'  => $menu_class,
1123
-                ),
1124
-            ));
1125
-        }
1126
-        if (is_single() && (get_post_type() == 'espresso_events')) {
1127
-            //Current post
1128
-            global $post;
1129
-            if ($this->registry->CAP->current_user_can('ee_edit_event',
1130
-                'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)
1131
-            ) {
1132
-                //Events Edit Current Event
1133
-                $admin_bar->add_menu(array(
1134
-                    'id'     => 'espresso-toolbar-events-edit',
1135
-                    'parent' => 'espresso-toolbar-events',
1136
-                    'title'  => esc_html__('Edit Event', 'event_espresso'),
1137
-                    'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID),
1138
-                        $events_admin_url),
1139
-                    'meta'   => array(
1140
-                        'title'  => esc_html__('Edit Event', 'event_espresso'),
1141
-                        'target' => '',
1142
-                        'class'  => $menu_class,
1143
-                    ),
1144
-                ));
1145
-            }
1146
-        }
1147
-        //Events View
1148
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1149
-            'ee_admin_bar_menu_espresso-toolbar-events-view')
1150
-        ) {
1151
-            $admin_bar->add_menu(array(
1152
-                'id'     => 'espresso-toolbar-events-view',
1153
-                'parent' => 'espresso-toolbar-events',
1154
-                'title'  => esc_html__('View', 'event_espresso'),
1155
-                'href'   => $events_admin_url,
1156
-                'meta'   => array(
1157
-                    'title'  => esc_html__('View', 'event_espresso'),
1158
-                    'target' => '',
1159
-                    'class'  => $menu_class,
1160
-                ),
1161
-            ));
1162
-        }
1163
-        if ($this->registry->CAP->current_user_can(
1164
-            'ee_read_events',
1165
-            'ee_admin_bar_menu_espresso-toolbar-events-all'
1166
-        )) {
1167
-            //Events View All
1168
-            $admin_bar->add_menu(array(
1169
-                'id'     => 'espresso-toolbar-events-all',
1170
-                'parent' => 'espresso-toolbar-events-view',
1171
-                'title'  => esc_html__('All', 'event_espresso'),
1172
-                'href'   => $events_admin_url,
1173
-                'meta'   => array(
1174
-                    'title'  => esc_html__('All', 'event_espresso'),
1175
-                    'target' => '',
1176
-                    'class'  => $menu_class,
1177
-                ),
1178
-            ));
1179
-        }
1180
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1181
-            'ee_admin_bar_menu_espresso-toolbar-events-today')
1182
-        ) {
1183
-            //Events View Today
1184
-            $admin_bar->add_menu(array(
1185
-                'id'     => 'espresso-toolbar-events-today',
1186
-                'parent' => 'espresso-toolbar-events-view',
1187
-                'title'  => esc_html__('Today', 'event_espresso'),
1188
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1189
-                    $events_admin_url),
1190
-                'meta'   => array(
1191
-                    'title'  => esc_html__('Today', 'event_espresso'),
1192
-                    'target' => '',
1193
-                    'class'  => $menu_class,
1194
-                ),
1195
-            ));
1196
-        }
1197
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1198
-            'ee_admin_bar_menu_espresso-toolbar-events-month')
1199
-        ) {
1200
-            //Events View This Month
1201
-            $admin_bar->add_menu(array(
1202
-                'id'     => 'espresso-toolbar-events-month',
1203
-                'parent' => 'espresso-toolbar-events-view',
1204
-                'title'  => esc_html__('This Month', 'event_espresso'),
1205
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1206
-                    $events_admin_url),
1207
-                'meta'   => array(
1208
-                    'title'  => esc_html__('This Month', 'event_espresso'),
1209
-                    'target' => '',
1210
-                    'class'  => $menu_class,
1211
-                ),
1212
-            ));
1213
-        }
1214
-        //Registration Overview
1215
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1216
-            'ee_admin_bar_menu_espresso-toolbar-registrations')
1217
-        ) {
1218
-            $admin_bar->add_menu(array(
1219
-                'id'     => 'espresso-toolbar-registrations',
1220
-                'parent' => 'espresso-toolbar',
1221
-                'title'  => esc_html__('Registrations', 'event_espresso'),
1222
-                'href'   => $reg_admin_url,
1223
-                'meta'   => array(
1224
-                    'title'  => esc_html__('Registrations', 'event_espresso'),
1225
-                    'target' => '',
1226
-                    'class'  => $menu_class,
1227
-                ),
1228
-            ));
1229
-        }
1230
-        //Registration Overview Today
1231
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1232
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today')
1233
-        ) {
1234
-            $admin_bar->add_menu(array(
1235
-                'id'     => 'espresso-toolbar-registrations-today',
1236
-                'parent' => 'espresso-toolbar-registrations',
1237
-                'title'  => esc_html__('Today', 'event_espresso'),
1238
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1239
-                    $reg_admin_url),
1240
-                'meta'   => array(
1241
-                    'title'  => esc_html__('Today', 'event_espresso'),
1242
-                    'target' => '',
1243
-                    'class'  => $menu_class,
1244
-                ),
1245
-            ));
1246
-        }
1247
-        //Registration Overview Today Completed
1248
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1249
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')
1250
-        ) {
1251
-            $admin_bar->add_menu(array(
1252
-                'id'     => 'espresso-toolbar-registrations-today-approved',
1253
-                'parent' => 'espresso-toolbar-registrations-today',
1254
-                'title'  => esc_html__('Approved', 'event_espresso'),
1255
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1256
-                    'action'      => 'default',
1257
-                    'status'      => 'today',
1258
-                    '_reg_status' => EEM_Registration::status_id_approved,
1259
-                ), $reg_admin_url),
1260
-                'meta'   => array(
1261
-                    'title'  => esc_html__('Approved', 'event_espresso'),
1262
-                    'target' => '',
1263
-                    'class'  => $menu_class,
1264
-                ),
1265
-            ));
1266
-        }
1267
-        //Registration Overview Today Pending\
1268
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1269
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')
1270
-        ) {
1271
-            $admin_bar->add_menu(array(
1272
-                'id'     => 'espresso-toolbar-registrations-today-pending',
1273
-                'parent' => 'espresso-toolbar-registrations-today',
1274
-                'title'  => esc_html__('Pending', 'event_espresso'),
1275
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1276
-                    'action'     => 'default',
1277
-                    'status'     => 'today',
1278
-                    'reg_status' => EEM_Registration::status_id_pending_payment,
1279
-                ), $reg_admin_url),
1280
-                'meta'   => array(
1281
-                    'title'  => esc_html__('Pending Payment', 'event_espresso'),
1282
-                    'target' => '',
1283
-                    'class'  => $menu_class,
1284
-                ),
1285
-            ));
1286
-        }
1287
-        //Registration Overview Today Incomplete
1288
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1289
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')
1290
-        ) {
1291
-            $admin_bar->add_menu(array(
1292
-                'id'     => 'espresso-toolbar-registrations-today-not-approved',
1293
-                'parent' => 'espresso-toolbar-registrations-today',
1294
-                'title'  => esc_html__('Not Approved', 'event_espresso'),
1295
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1296
-                    'action'      => 'default',
1297
-                    'status'      => 'today',
1298
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1299
-                ), $reg_admin_url),
1300
-                'meta'   => array(
1301
-                    'title'  => esc_html__('Not Approved', 'event_espresso'),
1302
-                    'target' => '',
1303
-                    'class'  => $menu_class,
1304
-                ),
1305
-            ));
1306
-        }
1307
-        //Registration Overview Today Incomplete
1308
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1309
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')
1310
-        ) {
1311
-            $admin_bar->add_menu(array(
1312
-                'id'     => 'espresso-toolbar-registrations-today-cancelled',
1313
-                'parent' => 'espresso-toolbar-registrations-today',
1314
-                'title'  => esc_html__('Cancelled', 'event_espresso'),
1315
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1316
-                    'action'      => 'default',
1317
-                    'status'      => 'today',
1318
-                    '_reg_status' => EEM_Registration::status_id_cancelled,
1319
-                ), $reg_admin_url),
1320
-                'meta'   => array(
1321
-                    'title'  => esc_html__('Cancelled', 'event_espresso'),
1322
-                    'target' => '',
1323
-                    'class'  => $menu_class,
1324
-                ),
1325
-            ));
1326
-        }
1327
-        //Registration Overview This Month
1328
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1329
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month')
1330
-        ) {
1331
-            $admin_bar->add_menu(array(
1332
-                'id'     => 'espresso-toolbar-registrations-month',
1333
-                'parent' => 'espresso-toolbar-registrations',
1334
-                'title'  => esc_html__('This Month', 'event_espresso'),
1335
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1336
-                    $reg_admin_url),
1337
-                'meta'   => array(
1338
-                    'title'  => esc_html__('This Month', 'event_espresso'),
1339
-                    'target' => '',
1340
-                    'class'  => $menu_class,
1341
-                ),
1342
-            ));
1343
-        }
1344
-        //Registration Overview This Month Approved
1345
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1346
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')
1347
-        ) {
1348
-            $admin_bar->add_menu(array(
1349
-                'id'     => 'espresso-toolbar-registrations-month-approved',
1350
-                'parent' => 'espresso-toolbar-registrations-month',
1351
-                'title'  => esc_html__('Approved', 'event_espresso'),
1352
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1353
-                    'action'      => 'default',
1354
-                    'status'      => 'month',
1355
-                    '_reg_status' => EEM_Registration::status_id_approved,
1356
-                ), $reg_admin_url),
1357
-                'meta'   => array(
1358
-                    'title'  => esc_html__('Approved', 'event_espresso'),
1359
-                    'target' => '',
1360
-                    'class'  => $menu_class,
1361
-                ),
1362
-            ));
1363
-        }
1364
-        //Registration Overview This Month Pending
1365
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1366
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')
1367
-        ) {
1368
-            $admin_bar->add_menu(array(
1369
-                'id'     => 'espresso-toolbar-registrations-month-pending',
1370
-                'parent' => 'espresso-toolbar-registrations-month',
1371
-                'title'  => esc_html__('Pending', 'event_espresso'),
1372
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1373
-                    'action'      => 'default',
1374
-                    'status'      => 'month',
1375
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1376
-                ), $reg_admin_url),
1377
-                'meta'   => array(
1378
-                    'title'  => esc_html__('Pending', 'event_espresso'),
1379
-                    'target' => '',
1380
-                    'class'  => $menu_class,
1381
-                ),
1382
-            ));
1383
-        }
1384
-        //Registration Overview This Month Not Approved
1385
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1386
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')
1387
-        ) {
1388
-            $admin_bar->add_menu(array(
1389
-                'id'     => 'espresso-toolbar-registrations-month-not-approved',
1390
-                'parent' => 'espresso-toolbar-registrations-month',
1391
-                'title'  => esc_html__('Not Approved', 'event_espresso'),
1392
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1393
-                    'action'      => 'default',
1394
-                    'status'      => 'month',
1395
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1396
-                ), $reg_admin_url),
1397
-                'meta'   => array(
1398
-                    'title'  => esc_html__('Not Approved', 'event_espresso'),
1399
-                    'target' => '',
1400
-                    'class'  => $menu_class,
1401
-                ),
1402
-            ));
1403
-        }
1404
-        //Registration Overview This Month Cancelled
1405
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1406
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')
1407
-        ) {
1408
-            $admin_bar->add_menu(array(
1409
-                'id'     => 'espresso-toolbar-registrations-month-cancelled',
1410
-                'parent' => 'espresso-toolbar-registrations-month',
1411
-                'title'  => esc_html__('Cancelled', 'event_espresso'),
1412
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1413
-                    'action'      => 'default',
1414
-                    'status'      => 'month',
1415
-                    '_reg_status' => EEM_Registration::status_id_cancelled,
1416
-                ), $reg_admin_url),
1417
-                'meta'   => array(
1418
-                    'title'  => esc_html__('Cancelled', 'event_espresso'),
1419
-                    'target' => '',
1420
-                    'class'  => $menu_class,
1421
-                ),
1422
-            ));
1423
-        }
1424
-        //Extensions & Services
1425
-        if ($this->registry->CAP->current_user_can('ee_read_ee',
1426
-            'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')
1427
-        ) {
1428
-            $admin_bar->add_menu(array(
1429
-                'id'     => 'espresso-toolbar-extensions-and-services',
1430
-                'parent' => 'espresso-toolbar',
1431
-                'title'  => esc_html__('Extensions & Services', 'event_espresso'),
1432
-                'href'   => $extensions_admin_url,
1433
-                'meta'   => array(
1434
-                    'title'  => esc_html__('Extensions & Services', 'event_espresso'),
1435
-                    'target' => '',
1436
-                    'class'  => $menu_class,
1437
-                ),
1438
-            ));
1439
-        }
1440
-    }
1441
-
1442
-
1443
-
1444
-    /**
1445
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1446
-     * never returned with the function.
1447
-     *
1448
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1449
-     * @return array
1450
-     */
1451
-    public function remove_pages_from_wp_list_pages($exclude_array)
1452
-    {
1453
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1454
-    }
24
+	/**
25
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
26
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
27
+	 */
28
+	const req_type_normal = 0;
29
+
30
+	/**
31
+	 * Indicates this is a brand new installation of EE so we should install
32
+	 * tables and default data etc
33
+	 */
34
+	const req_type_new_activation = 1;
35
+
36
+	/**
37
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
38
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
39
+	 * and that default data is setup too
40
+	 */
41
+	const req_type_reactivation = 2;
42
+
43
+	/**
44
+	 * indicates that EE has been upgraded since its previous request.
45
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
46
+	 */
47
+	const req_type_upgrade = 3;
48
+
49
+	/**
50
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
51
+	 */
52
+	const req_type_downgrade = 4;
53
+
54
+	/**
55
+	 * @deprecated since version 4.6.0.dev.006
56
+	 * Now whenever a new_activation is detected the request type is still just
57
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
58
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
59
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
60
+	 * (Specifically, when the migration manager indicates migrations are finished
61
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
62
+	 */
63
+	const req_type_activation_but_not_installed = 5;
64
+
65
+	/**
66
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
67
+	 */
68
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
69
+
70
+
71
+	/**
72
+	 *    instance of the EE_System object
73
+	 *
74
+	 * @var    $_instance
75
+	 * @access    private
76
+	 */
77
+	private static $_instance = null;
78
+
79
+	/**
80
+	 * @type  EE_Registry $Registry
81
+	 * @access    protected
82
+	 */
83
+	protected $registry;
84
+
85
+	/**
86
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
87
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
88
+	 *
89
+	 * @var int
90
+	 */
91
+	private $_req_type;
92
+
93
+	/**
94
+	 * Whether or not there was a non-micro version change in EE core version during this request
95
+	 *
96
+	 * @var boolean
97
+	 */
98
+	private $_major_version_change = false;
99
+
100
+
101
+
102
+	/**
103
+	 * @singleton method used to instantiate class object
104
+	 * @access    public
105
+	 * @param  \EE_Registry $Registry
106
+	 * @return \EE_System
107
+	 */
108
+	public static function instance(EE_Registry $Registry = null)
109
+	{
110
+		// check if class object is instantiated
111
+		if ( ! self::$_instance instanceof EE_System) {
112
+			self::$_instance = new self($Registry);
113
+		}
114
+		return self::$_instance;
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 * resets the instance and returns it
121
+	 *
122
+	 * @return EE_System
123
+	 */
124
+	public static function reset()
125
+	{
126
+		self::$_instance->_req_type = null;
127
+		//make sure none of the old hooks are left hanging around
128
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
129
+		//we need to reset the migration manager in order for it to detect DMSs properly
130
+		EE_Data_Migration_Manager::reset();
131
+		self::instance()->detect_activations_or_upgrades();
132
+		self::instance()->perform_activations_upgrades_and_migrations();
133
+		return self::instance();
134
+	}
135
+
136
+
137
+
138
+	/**
139
+	 *    sets hooks for running rest of system
140
+	 *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
141
+	 *    starting EE Addons from any other point may lead to problems
142
+	 *
143
+	 * @access private
144
+	 * @param  \EE_Registry $Registry
145
+	 */
146
+	private function __construct(EE_Registry $Registry)
147
+	{
148
+		$this->registry = $Registry;
149
+		do_action('AHEE__EE_System__construct__begin', $this);
150
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
151
+		add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
152
+		// right before the plugin is saved to the active_plugins option, we want to call the core hook(s) again
153
+		// because the newly-activated addon has not executed yet.
154
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
155
+		// detect whether install or upgrade
156
+		add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
157
+			3);
158
+		// load EE_Config, EE_Textdomain, etc
159
+		add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
160
+		// load EE_Config, EE_Textdomain, etc
161
+		add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
162
+			array($this, 'register_shortcodes_modules_and_widgets'), 7);
163
+		// you wanna get going? I wanna get going... let's get going!
164
+		add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
165
+		//other housekeeping
166
+		//exclude EE critical pages from wp_list_pages
167
+		add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
168
+		// ALL EE Addons should use the following hook point to attach their initial setup too
169
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when
170
+		// the EE_Config loads
171
+		do_action('AHEE__EE_System__construct__complete', $this);
172
+	}
173
+
174
+
175
+	/**
176
+	 * load_espresso_addons
177
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
178
+	 * this is hooked into both:
179
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
180
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
181
+	 *    and the WP 'activate_plugin' hookpoint
182
+	 *
183
+	 * @access public
184
+	 * @return void
185
+	 * @throws EE_Error
186
+	 * @throws \EventEspresso\core\exceptions\InvalidExecutionPathException
187
+	 */
188
+	public function load_espresso_addons()
189
+	{
190
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
191
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
192
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
193
+		//load and setup EE_Capabilities
194
+		$this->registry->load_core('Capabilities');
195
+
196
+		do_action('AHEE__EE_System__load_espresso_addons');
197
+		//if the WP API basic auth plugin isn't already loaded, load it now.
198
+		//We want it for mobile apps. Just include the entire plugin
199
+		//also, don't load the basic auth when a plugin is getting activated, because
200
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
201
+		//and causes a fatal error
202
+		if ( ! function_exists('json_basic_auth_handler')
203
+			 && ! function_exists('json_basic_auth_error')
204
+			 && ! (
205
+				isset($_GET['action'])
206
+				&& in_array($_GET['action'], array('activate', 'activate-selected'))
207
+			)
208
+			 && ! (
209
+				isset($_GET['activate'])
210
+				&& $_GET['activate'] === 'true'
211
+			)
212
+		) {
213
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
214
+		}
215
+		$this->_maybe_brew_regular();
216
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
217
+		$this->registry->CAP->init_caps();
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * detect_activations_or_upgrades
224
+	 * Checks for activation or upgrade of core first;
225
+	 * then also checks if any registered addons have been activated or upgraded
226
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
227
+	 * which runs during the WP 'plugins_loaded' action at priority 3
228
+	 *
229
+	 * @access public
230
+	 * @return void
231
+	 */
232
+	public function detect_activations_or_upgrades()
233
+	{
234
+		//first off: let's make sure to handle core
235
+		$this->detect_if_activation_or_upgrade();
236
+		foreach ($this->registry->addons as $addon) {
237
+			//detect teh request type for that addon
238
+			$addon->detect_activation_or_upgrade();
239
+		}
240
+	}
241
+
242
+
243
+
244
+	/**
245
+	 * detect_if_activation_or_upgrade
246
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
247
+	 * and either setting up the DB or setting up maintenance mode etc.
248
+	 *
249
+	 * @access public
250
+	 * @return void
251
+	 */
252
+	public function detect_if_activation_or_upgrade()
253
+	{
254
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
255
+		// load M-Mode class
256
+		$this->registry->load_core('Maintenance_Mode');
257
+		// check if db has been updated, or if its a brand-new installation
258
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
259
+		$request_type = $this->detect_req_type($espresso_db_update);
260
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
261
+		switch ($request_type) {
262
+			case EE_System::req_type_new_activation:
263
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
264
+				$this->_handle_core_version_change($espresso_db_update);
265
+				break;
266
+			case EE_System::req_type_reactivation:
267
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
268
+				$this->_handle_core_version_change($espresso_db_update);
269
+				break;
270
+			case EE_System::req_type_upgrade:
271
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
272
+				//migrations may be required now that we've upgraded
273
+				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
274
+				$this->_handle_core_version_change($espresso_db_update);
275
+				//				echo "done upgrade";die;
276
+				break;
277
+			case EE_System::req_type_downgrade:
278
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
279
+				//its possible migrations are no longer required
280
+				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
281
+				$this->_handle_core_version_change($espresso_db_update);
282
+				break;
283
+			case EE_System::req_type_normal:
284
+			default:
285
+				//				$this->_maybe_redirect_to_ee_about();
286
+				break;
287
+		}
288
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
289
+	}
290
+
291
+
292
+
293
+	/**
294
+	 * Updates the list of installed versions and sets hooks for
295
+	 * initializing the database later during the request
296
+	 *
297
+	 * @param array $espresso_db_update
298
+	 */
299
+	protected function _handle_core_version_change($espresso_db_update)
300
+	{
301
+		$this->update_list_of_installed_versions($espresso_db_update);
302
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
303
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
304
+			array($this, 'initialize_db_if_no_migrations_required'));
305
+	}
306
+
307
+
308
+
309
+	/**
310
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
311
+	 * information about what versions of EE have been installed and activated,
312
+	 * NOT necessarily the state of the database
313
+	 *
314
+	 * @param null $espresso_db_update
315
+	 * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
316
+	 *           from the options table
317
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
318
+	 */
319
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
320
+	{
321
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
322
+		if ( ! $espresso_db_update) {
323
+			$espresso_db_update = get_option('espresso_db_update');
324
+		}
325
+		// check that option is an array
326
+		if ( ! is_array($espresso_db_update)) {
327
+			// if option is FALSE, then it never existed
328
+			if ($espresso_db_update === false) {
329
+				// make $espresso_db_update an array and save option with autoload OFF
330
+				$espresso_db_update = array();
331
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
332
+			} else {
333
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
334
+				$espresso_db_update = array($espresso_db_update => array());
335
+				update_option('espresso_db_update', $espresso_db_update);
336
+			}
337
+		} else {
338
+			$corrected_db_update = array();
339
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
340
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
341
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
342
+					//the key is an int, and the value IS NOT an array
343
+					//so it must be numerically-indexed, where values are versions installed...
344
+					//fix it!
345
+					$version_string = $should_be_array;
346
+					$corrected_db_update[$version_string] = array('unknown-date');
347
+				} else {
348
+					//ok it checks out
349
+					$corrected_db_update[$should_be_version_string] = $should_be_array;
350
+				}
351
+			}
352
+			$espresso_db_update = $corrected_db_update;
353
+			update_option('espresso_db_update', $espresso_db_update);
354
+		}
355
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
356
+		return $espresso_db_update;
357
+	}
358
+
359
+
360
+	/**
361
+	 * Does the traditional work of setting up the plugin's database and adding default data.
362
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
363
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
364
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
365
+	 * so that it will be done when migrations are finished
366
+	 *
367
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
368
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
369
+	 *                                       This is a resource-intensive job
370
+	 *                                       so we prefer to only do it when necessary
371
+	 * @return void
372
+	 * @throws EE_Error
373
+	 */
374
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
375
+	{
376
+		$request_type = $this->detect_req_type();
377
+		//only initialize system if we're not in maintenance mode.
378
+		if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
379
+			update_option('ee_flush_rewrite_rules', true);
380
+			if ($verify_schema) {
381
+				EEH_Activation::initialize_db_and_folders();
382
+			}
383
+			EEH_Activation::initialize_db_content();
384
+			EEH_Activation::system_initialization();
385
+			if ($initialize_addons_too) {
386
+				$this->initialize_addons();
387
+			}
388
+		} else {
389
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
390
+		}
391
+		if ($request_type === EE_System::req_type_new_activation
392
+			|| $request_type === EE_System::req_type_reactivation
393
+			|| (
394
+				$request_type === EE_System::req_type_upgrade
395
+				&& $this->is_major_version_change()
396
+			)
397
+		) {
398
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
399
+		}
400
+	}
401
+
402
+
403
+
404
+	/**
405
+	 * Initializes the db for all registered addons
406
+	 */
407
+	public function initialize_addons()
408
+	{
409
+		//foreach registered addon, make sure its db is up-to-date too
410
+		foreach ($this->registry->addons as $addon) {
411
+			$addon->initialize_db_if_no_migrations_required();
412
+		}
413
+	}
414
+
415
+
416
+
417
+	/**
418
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
419
+	 *
420
+	 * @param    array  $version_history
421
+	 * @param    string $current_version_to_add version to be added to the version history
422
+	 * @return    boolean success as to whether or not this option was changed
423
+	 */
424
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
425
+	{
426
+		if ( ! $version_history) {
427
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
428
+		}
429
+		if ($current_version_to_add == null) {
430
+			$current_version_to_add = espresso_version();
431
+		}
432
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
433
+		// re-save
434
+		return update_option('espresso_db_update', $version_history);
435
+	}
436
+
437
+
438
+
439
+	/**
440
+	 * Detects if the current version indicated in the has existed in the list of
441
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
442
+	 *
443
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
444
+	 *                                  If not supplied, fetches it from the options table.
445
+	 *                                  Also, caches its result so later parts of the code can also know whether
446
+	 *                                  there's been an update or not. This way we can add the current version to
447
+	 *                                  espresso_db_update, but still know if this is a new install or not
448
+	 * @return int one of the constants on EE_System::req_type_
449
+	 */
450
+	public function detect_req_type($espresso_db_update = null)
451
+	{
452
+		if ($this->_req_type === null) {
453
+			$espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
454
+				: $this->fix_espresso_db_upgrade_option();
455
+			$this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
456
+				'ee_espresso_activation', espresso_version());
457
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
458
+		}
459
+		return $this->_req_type;
460
+	}
461
+
462
+
463
+
464
+	/**
465
+	 * Returns whether or not there was a non-micro version change (ie, change in either
466
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
467
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
468
+	 *
469
+	 * @param $activation_history
470
+	 * @return bool
471
+	 */
472
+	protected function _detect_major_version_change($activation_history)
473
+	{
474
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
475
+		$previous_version_parts = explode('.', $previous_version);
476
+		$current_version_parts = explode('.', espresso_version());
477
+		return isset(
478
+			$previous_version_parts[0],
479
+			$previous_version_parts[1],
480
+			$current_version_parts[0],
481
+			$current_version_parts[1]
482
+		)
483
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
484
+				   || $previous_version_parts[1] !== $current_version_parts[1]
485
+			   );
486
+	}
487
+
488
+
489
+
490
+	/**
491
+	 * Returns true if either the major or minor version of EE changed during this request.
492
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
493
+	 *
494
+	 * @return bool
495
+	 */
496
+	public function is_major_version_change()
497
+	{
498
+		return $this->_major_version_change;
499
+	}
500
+
501
+
502
+
503
+	/**
504
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
505
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
506
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
507
+	 * just activated to (for core that will always be espresso_version())
508
+	 *
509
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
510
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
511
+	 * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
512
+	 *                                                 indicate that this plugin was just activated
513
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
514
+	 *                                                 espresso_version())
515
+	 * @return int one of the constants on EE_System::req_type_*
516
+	 */
517
+	public static function detect_req_type_given_activation_history(
518
+		$activation_history_for_addon,
519
+		$activation_indicator_option_name,
520
+		$version_to_upgrade_to
521
+	) {
522
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
523
+		if ($activation_history_for_addon) {
524
+			//it exists, so this isn't a completely new install
525
+			//check if this version already in that list of previously installed versions
526
+			if (! isset($activation_history_for_addon[$version_to_upgrade_to])) {
527
+				//it a version we haven't seen before
528
+				if ($version_is_higher === 1) {
529
+					$req_type = EE_System::req_type_upgrade;
530
+				} else {
531
+					$req_type = EE_System::req_type_downgrade;
532
+				}
533
+				delete_option($activation_indicator_option_name);
534
+			} else {
535
+				// its not an update. maybe a reactivation?
536
+				if (get_option($activation_indicator_option_name, false)) {
537
+					if ($version_is_higher === -1) {
538
+						$req_type = EE_System::req_type_downgrade;
539
+					} elseif ($version_is_higher === 0) {
540
+						//we've seen this version before, but it's an activation. must be a reactivation
541
+						$req_type = EE_System::req_type_reactivation;
542
+					} else {//$version_is_higher === 1
543
+						$req_type = EE_System::req_type_upgrade;
544
+					}
545
+					delete_option($activation_indicator_option_name);
546
+				} else {
547
+					//we've seen this version before and the activation indicate doesn't show it was just activated
548
+					if ($version_is_higher === -1) {
549
+						$req_type = EE_System::req_type_downgrade;
550
+					} elseif ($version_is_higher === 0) {
551
+						//we've seen this version before and it's not an activation. its normal request
552
+						$req_type = EE_System::req_type_normal;
553
+					} else {//$version_is_higher === 1
554
+						$req_type = EE_System::req_type_upgrade;
555
+					}
556
+				}
557
+			}
558
+		} else {
559
+			//brand new install
560
+			$req_type = EE_System::req_type_new_activation;
561
+			delete_option($activation_indicator_option_name);
562
+		}
563
+		return $req_type;
564
+	}
565
+
566
+
567
+
568
+	/**
569
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
570
+	 * the $activation_history_for_addon
571
+	 *
572
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
573
+	 *                                             sometimes containing 'unknown-date'
574
+	 * @param string $version_to_upgrade_to        (current version)
575
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
576
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
577
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
578
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
579
+	 */
580
+	protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
581
+	{
582
+		//find the most recently-activated version
583
+		$most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history(
584
+			$activation_history_for_addon
585
+		);
586
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
587
+	}
588
+
589
+
590
+
591
+	/**
592
+	 * Gets the most recently active version listed in the activation history,
593
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
594
+	 *
595
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
596
+	 *                                   sometimes containing 'unknown-date'
597
+	 * @return string
598
+	 */
599
+	protected static function _get_most_recently_active_version_from_activation_history($activation_history)
600
+	{
601
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
602
+		$most_recently_active_version = '0.0.0.dev.000';
603
+		if (is_array($activation_history)) {
604
+			foreach ($activation_history as $version => $times_activated) {
605
+				//check there is a record of when this version was activated. Otherwise,
606
+				//mark it as unknown
607
+				if (! $times_activated) {
608
+					$times_activated = array('unknown-date');
609
+				}
610
+				if (is_string($times_activated)) {
611
+					$times_activated = array($times_activated);
612
+				}
613
+				foreach ($times_activated as $an_activation) {
614
+					if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
615
+						$most_recently_active_version = $version;
616
+						$most_recently_active_version_activation = $an_activation == 'unknown-date'
617
+							? '1970-01-01 00:00:00' : $an_activation;
618
+					}
619
+				}
620
+			}
621
+		}
622
+		return $most_recently_active_version;
623
+	}
624
+
625
+
626
+
627
+	/**
628
+	 * This redirects to the about EE page after activation
629
+	 *
630
+	 * @return void
631
+	 */
632
+	public function redirect_to_about_ee()
633
+	{
634
+		$notices = EE_Error::get_notices(false);
635
+		//if current user is an admin and it's not an ajax or rest request
636
+		if (! (defined('DOING_AJAX') && DOING_AJAX)
637
+			&& ! (defined('REST_REQUEST') && REST_REQUEST)
638
+			&& ! isset($notices['errors'])
639
+			&& apply_filters(
640
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
641
+				$this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
642
+			)
643
+		) {
644
+			$query_params = array('page' => 'espresso_about');
645
+			if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
646
+				$query_params['new_activation'] = true;
647
+			}
648
+			if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
649
+				$query_params['reactivation'] = true;
650
+			}
651
+			$url = add_query_arg($query_params, admin_url('admin.php'));
652
+			wp_safe_redirect($url);
653
+			exit();
654
+		}
655
+	}
656
+
657
+
658
+
659
+	/**
660
+	 * load_core_configuration
661
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
662
+	 * which runs during the WP 'plugins_loaded' action at priority 5
663
+	 *
664
+	 * @return void
665
+	 */
666
+	public function load_core_configuration()
667
+	{
668
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
669
+		$this->registry->load_core('EE_Load_Textdomain');
670
+		//load textdomain
671
+		EE_Load_Textdomain::load_textdomain();
672
+		// load and setup EE_Config and EE_Network_Config
673
+		$this->registry->load_core('Config');
674
+		$this->registry->load_core('Network_Config');
675
+		// setup autoloaders
676
+		// enable logging?
677
+		if ($this->registry->CFG->admin->use_full_logging) {
678
+			$this->registry->load_core('Log');
679
+		}
680
+		// check for activation errors
681
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
682
+		if ($activation_errors) {
683
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
684
+			update_option('ee_plugin_activation_errors', false);
685
+		}
686
+		// get model names
687
+		$this->_parse_model_names();
688
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
689
+	}
690
+
691
+
692
+
693
+	/**
694
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
695
+	 *
696
+	 * @return void
697
+	 */
698
+	private function _parse_model_names()
699
+	{
700
+		//get all the files in the EE_MODELS folder that end in .model.php
701
+		$models = glob(EE_MODELS . '*.model.php');
702
+		$model_names = array();
703
+		$non_abstract_db_models = array();
704
+		foreach ($models as $model) {
705
+			// get model classname
706
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
707
+			$short_name = str_replace('EEM_', '', $classname);
708
+			$reflectionClass = new ReflectionClass($classname);
709
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
710
+				$non_abstract_db_models[$short_name] = $classname;
711
+			}
712
+			$model_names[$short_name] = $classname;
713
+		}
714
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
715
+		$this->registry->non_abstract_db_models = apply_filters(
716
+			'FHEE__EE_System__parse_implemented_model_names',
717
+			$non_abstract_db_models
718
+		);
719
+	}
720
+
721
+
722
+
723
+	/**
724
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
725
+	 * that need to be setup before our EE_System launches.
726
+	 *
727
+	 * @return void
728
+	 */
729
+	private function _maybe_brew_regular()
730
+	{
731
+		if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
732
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
733
+		}
734
+	}
735
+
736
+
737
+
738
+	/**
739
+	 * register_shortcodes_modules_and_widgets
740
+	 * generate lists of shortcodes and modules, then verify paths and classes
741
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
742
+	 * which runs during the WP 'plugins_loaded' action at priority 7
743
+	 *
744
+	 * @access public
745
+	 * @return void
746
+	 */
747
+	public function register_shortcodes_modules_and_widgets()
748
+	{
749
+		try {
750
+			// load, register, and add shortcodes the new way
751
+			new ShortcodesManager(
752
+				// and the old way, but we'll put it under control of the new system
753
+				EE_Config::getLegacyShortcodesManager()
754
+			);
755
+		} catch (Exception $exception) {
756
+			new ExceptionStackTraceDisplay($exception);
757
+		}
758
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
759
+		// check for addons using old hookpoint
760
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
761
+			$this->_incompatible_addon_error();
762
+		}
763
+	}
764
+
765
+
766
+
767
+	/**
768
+	 * _incompatible_addon_error
769
+	 *
770
+	 * @access public
771
+	 * @return void
772
+	 */
773
+	private function _incompatible_addon_error()
774
+	{
775
+		// get array of classes hooking into here
776
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
777
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
778
+		);
779
+		if (! empty($class_names)) {
780
+			$msg = esc_html__(
781
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
782
+				'event_espresso'
783
+			);
784
+			$msg .= '<ul>';
785
+			foreach ($class_names as $class_name) {
786
+				$msg .= '<li><b>Event Espresso - '
787
+						. str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', $class_name)
788
+						. '</b></li>';
789
+			}
790
+			$msg .= '</ul>';
791
+			$msg .= esc_html__(
792
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
793
+				'event_espresso'
794
+			);
795
+			// save list of incompatible addons to wp-options for later use
796
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
797
+			if (is_admin()) {
798
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
799
+			}
800
+		}
801
+	}
802
+
803
+
804
+
805
+	/**
806
+	 * brew_espresso
807
+	 * begins the process of setting hooks for initializing EE in the correct order
808
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
809
+	 * which runs during the WP 'plugins_loaded' action at priority 9
810
+	 *
811
+	 * @return void
812
+	 */
813
+	public function brew_espresso()
814
+	{
815
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
816
+		// load some final core systems
817
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
818
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
819
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
820
+		add_action('init', array($this, 'load_controllers'), 7);
821
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
822
+		add_action('init', array($this, 'initialize'), 10);
823
+		add_action('init', array($this, 'initialize_last'), 100);
824
+		add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
825
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
826
+			// pew pew pew
827
+			$this->registry->load_core('PUE');
828
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
829
+		}
830
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
831
+	}
832
+
833
+
834
+
835
+	/**
836
+	 *    set_hooks_for_core
837
+	 *
838
+	 * @access public
839
+	 * @return    void
840
+	 */
841
+	public function set_hooks_for_core()
842
+	{
843
+		$this->_deactivate_incompatible_addons();
844
+		do_action('AHEE__EE_System__set_hooks_for_core');
845
+	}
846
+
847
+
848
+
849
+	/**
850
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
851
+	 * deactivates any addons considered incompatible with the current version of EE
852
+	 */
853
+	private function _deactivate_incompatible_addons()
854
+	{
855
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
856
+		if (! empty($incompatible_addons)) {
857
+			$active_plugins = get_option('active_plugins', array());
858
+			foreach ($active_plugins as $active_plugin) {
859
+				foreach ($incompatible_addons as $incompatible_addon) {
860
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
861
+						unset($_GET['activate']);
862
+						espresso_deactivate_plugin($active_plugin);
863
+					}
864
+				}
865
+			}
866
+		}
867
+	}
868
+
869
+
870
+
871
+	/**
872
+	 *    perform_activations_upgrades_and_migrations
873
+	 *
874
+	 * @access public
875
+	 * @return    void
876
+	 */
877
+	public function perform_activations_upgrades_and_migrations()
878
+	{
879
+		//first check if we had previously attempted to setup EE's directories but failed
880
+		if (EEH_Activation::upload_directories_incomplete()) {
881
+			EEH_Activation::create_upload_directories();
882
+		}
883
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
884
+	}
885
+
886
+
887
+
888
+	/**
889
+	 *    load_CPTs_and_session
890
+	 *
891
+	 * @access public
892
+	 * @return    void
893
+	 */
894
+	public function load_CPTs_and_session()
895
+	{
896
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
897
+		// register Custom Post Types
898
+		$this->registry->load_core('Register_CPTs');
899
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
900
+	}
901
+
902
+
903
+
904
+	/**
905
+	 * load_controllers
906
+	 * this is the best place to load any additional controllers that needs access to EE core.
907
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
908
+	 * time
909
+	 *
910
+	 * @access public
911
+	 * @return void
912
+	 */
913
+	public function load_controllers()
914
+	{
915
+		do_action('AHEE__EE_System__load_controllers__start');
916
+		// let's get it started
917
+		if (! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
918
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
919
+			$this->registry->load_core('Front_Controller');
920
+		} elseif (! EE_FRONT_AJAX) {
921
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
922
+			EE_Registry::instance()->load_core('Admin');
923
+		}
924
+		do_action('AHEE__EE_System__load_controllers__complete');
925
+	}
926
+
927
+
928
+
929
+	/**
930
+	 * core_loaded_and_ready
931
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
932
+	 *
933
+	 * @access public
934
+	 * @return void
935
+	 */
936
+	public function core_loaded_and_ready()
937
+	{
938
+		do_action('AHEE__EE_System__core_loaded_and_ready');
939
+		// load_espresso_template_tags
940
+		if (is_readable(EE_PUBLIC . 'template_tags.php')) {
941
+			require_once(EE_PUBLIC . 'template_tags.php');
942
+		}
943
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
944
+		$this->registry->load_core('Session');
945
+		$this->registry->create('EventEspresso\core\services\assets\Registry');
946
+		wp_enqueue_script('espresso_core');
947
+	}
948
+
949
+
950
+
951
+	/**
952
+	 * initialize
953
+	 * this is the best place to begin initializing client code
954
+	 *
955
+	 * @access public
956
+	 * @return void
957
+	 */
958
+	public function initialize()
959
+	{
960
+		do_action('AHEE__EE_System__initialize');
961
+	}
962
+
963
+
964
+
965
+	/**
966
+	 * initialize_last
967
+	 * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
968
+	 * initialize has done so
969
+	 *
970
+	 * @access public
971
+	 * @return void
972
+	 */
973
+	public function initialize_last()
974
+	{
975
+		do_action('AHEE__EE_System__initialize_last');
976
+	}
977
+
978
+
979
+
980
+	/**
981
+	 * set_hooks_for_shortcodes_modules_and_addons
982
+	 * this is the best place for other systems to set callbacks for hooking into other parts of EE
983
+	 * this happens at the very beginning of the wp_loaded hookpoint
984
+	 *
985
+	 * @access public
986
+	 * @return void
987
+	 */
988
+	public function set_hooks_for_shortcodes_modules_and_addons()
989
+	{
990
+		//		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
991
+	}
992
+
993
+
994
+
995
+	/**
996
+	 * do_not_cache
997
+	 * sets no cache headers and defines no cache constants for WP plugins
998
+	 *
999
+	 * @access public
1000
+	 * @return void
1001
+	 */
1002
+	public static function do_not_cache()
1003
+	{
1004
+		// set no cache constants
1005
+		if (! defined('DONOTCACHEPAGE')) {
1006
+			define('DONOTCACHEPAGE', true);
1007
+		}
1008
+		if (! defined('DONOTCACHCEOBJECT')) {
1009
+			define('DONOTCACHCEOBJECT', true);
1010
+		}
1011
+		if (! defined('DONOTCACHEDB')) {
1012
+			define('DONOTCACHEDB', true);
1013
+		}
1014
+		// add no cache headers
1015
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1016
+		// plus a little extra for nginx and Google Chrome
1017
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1018
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes
1019
+		// with the registration process
1020
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1021
+	}
1022
+
1023
+
1024
+
1025
+	/**
1026
+	 *    extra_nocache_headers
1027
+	 *
1028
+	 * @access    public
1029
+	 * @param $headers
1030
+	 * @return    array
1031
+	 */
1032
+	public static function extra_nocache_headers($headers)
1033
+	{
1034
+		// for NGINX
1035
+		$headers['X-Accel-Expires'] = 0;
1036
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1037
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1038
+		return $headers;
1039
+	}
1040
+
1041
+
1042
+
1043
+	/**
1044
+	 *    nocache_headers
1045
+	 *
1046
+	 * @access    public
1047
+	 * @return    void
1048
+	 */
1049
+	public static function nocache_headers()
1050
+	{
1051
+		nocache_headers();
1052
+	}
1053
+
1054
+
1055
+
1056
+	/**
1057
+	 *    espresso_toolbar_items
1058
+	 *
1059
+	 * @access public
1060
+	 * @param  WP_Admin_Bar $admin_bar
1061
+	 * @return void
1062
+	 */
1063
+	public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1064
+	{
1065
+		// if in full M-Mode, or its an AJAX request, or user is NOT an admin
1066
+		if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1067
+			|| defined('DOING_AJAX')
1068
+			|| ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1069
+		) {
1070
+			return;
1071
+		}
1072
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1073
+		$menu_class = 'espresso_menu_item_class';
1074
+		//we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1075
+		//because they're only defined in each of their respective constructors
1076
+		//and this might be a frontend request, in which case they aren't available
1077
+		$events_admin_url = admin_url("admin.php?page=espresso_events");
1078
+		$reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1079
+		$extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1080
+		//Top Level
1081
+		$admin_bar->add_menu(array(
1082
+			'id'    => 'espresso-toolbar',
1083
+			'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1084
+					   . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1085
+					   . '</span>',
1086
+			'href'  => $events_admin_url,
1087
+			'meta'  => array(
1088
+				'title' => esc_html__('Event Espresso', 'event_espresso'),
1089
+				'class' => $menu_class . 'first',
1090
+			),
1091
+		));
1092
+		//Events
1093
+		if ($this->registry->CAP->current_user_can(
1094
+			'ee_read_events',
1095
+			'ee_admin_bar_menu_espresso-toolbar-events'
1096
+		)) {
1097
+			$admin_bar->add_menu(array(
1098
+				'id'     => 'espresso-toolbar-events',
1099
+				'parent' => 'espresso-toolbar',
1100
+				'title'  => esc_html__('Events', 'event_espresso'),
1101
+				'href'   => $events_admin_url,
1102
+				'meta'   => array(
1103
+					'title'  => esc_html__('Events', 'event_espresso'),
1104
+					'target' => '',
1105
+					'class'  => $menu_class,
1106
+				),
1107
+			));
1108
+		}
1109
+		if ($this->registry->CAP->current_user_can(
1110
+			'ee_edit_events',
1111
+			'ee_admin_bar_menu_espresso-toolbar-events-new'
1112
+		)) {
1113
+			//Events Add New
1114
+			$admin_bar->add_menu(array(
1115
+				'id'     => 'espresso-toolbar-events-new',
1116
+				'parent' => 'espresso-toolbar-events',
1117
+				'title'  => esc_html__('Add New', 'event_espresso'),
1118
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1119
+				'meta'   => array(
1120
+					'title'  => esc_html__('Add New', 'event_espresso'),
1121
+					'target' => '',
1122
+					'class'  => $menu_class,
1123
+				),
1124
+			));
1125
+		}
1126
+		if (is_single() && (get_post_type() == 'espresso_events')) {
1127
+			//Current post
1128
+			global $post;
1129
+			if ($this->registry->CAP->current_user_can('ee_edit_event',
1130
+				'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)
1131
+			) {
1132
+				//Events Edit Current Event
1133
+				$admin_bar->add_menu(array(
1134
+					'id'     => 'espresso-toolbar-events-edit',
1135
+					'parent' => 'espresso-toolbar-events',
1136
+					'title'  => esc_html__('Edit Event', 'event_espresso'),
1137
+					'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID),
1138
+						$events_admin_url),
1139
+					'meta'   => array(
1140
+						'title'  => esc_html__('Edit Event', 'event_espresso'),
1141
+						'target' => '',
1142
+						'class'  => $menu_class,
1143
+					),
1144
+				));
1145
+			}
1146
+		}
1147
+		//Events View
1148
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1149
+			'ee_admin_bar_menu_espresso-toolbar-events-view')
1150
+		) {
1151
+			$admin_bar->add_menu(array(
1152
+				'id'     => 'espresso-toolbar-events-view',
1153
+				'parent' => 'espresso-toolbar-events',
1154
+				'title'  => esc_html__('View', 'event_espresso'),
1155
+				'href'   => $events_admin_url,
1156
+				'meta'   => array(
1157
+					'title'  => esc_html__('View', 'event_espresso'),
1158
+					'target' => '',
1159
+					'class'  => $menu_class,
1160
+				),
1161
+			));
1162
+		}
1163
+		if ($this->registry->CAP->current_user_can(
1164
+			'ee_read_events',
1165
+			'ee_admin_bar_menu_espresso-toolbar-events-all'
1166
+		)) {
1167
+			//Events View All
1168
+			$admin_bar->add_menu(array(
1169
+				'id'     => 'espresso-toolbar-events-all',
1170
+				'parent' => 'espresso-toolbar-events-view',
1171
+				'title'  => esc_html__('All', 'event_espresso'),
1172
+				'href'   => $events_admin_url,
1173
+				'meta'   => array(
1174
+					'title'  => esc_html__('All', 'event_espresso'),
1175
+					'target' => '',
1176
+					'class'  => $menu_class,
1177
+				),
1178
+			));
1179
+		}
1180
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1181
+			'ee_admin_bar_menu_espresso-toolbar-events-today')
1182
+		) {
1183
+			//Events View Today
1184
+			$admin_bar->add_menu(array(
1185
+				'id'     => 'espresso-toolbar-events-today',
1186
+				'parent' => 'espresso-toolbar-events-view',
1187
+				'title'  => esc_html__('Today', 'event_espresso'),
1188
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1189
+					$events_admin_url),
1190
+				'meta'   => array(
1191
+					'title'  => esc_html__('Today', 'event_espresso'),
1192
+					'target' => '',
1193
+					'class'  => $menu_class,
1194
+				),
1195
+			));
1196
+		}
1197
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1198
+			'ee_admin_bar_menu_espresso-toolbar-events-month')
1199
+		) {
1200
+			//Events View This Month
1201
+			$admin_bar->add_menu(array(
1202
+				'id'     => 'espresso-toolbar-events-month',
1203
+				'parent' => 'espresso-toolbar-events-view',
1204
+				'title'  => esc_html__('This Month', 'event_espresso'),
1205
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1206
+					$events_admin_url),
1207
+				'meta'   => array(
1208
+					'title'  => esc_html__('This Month', 'event_espresso'),
1209
+					'target' => '',
1210
+					'class'  => $menu_class,
1211
+				),
1212
+			));
1213
+		}
1214
+		//Registration Overview
1215
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1216
+			'ee_admin_bar_menu_espresso-toolbar-registrations')
1217
+		) {
1218
+			$admin_bar->add_menu(array(
1219
+				'id'     => 'espresso-toolbar-registrations',
1220
+				'parent' => 'espresso-toolbar',
1221
+				'title'  => esc_html__('Registrations', 'event_espresso'),
1222
+				'href'   => $reg_admin_url,
1223
+				'meta'   => array(
1224
+					'title'  => esc_html__('Registrations', 'event_espresso'),
1225
+					'target' => '',
1226
+					'class'  => $menu_class,
1227
+				),
1228
+			));
1229
+		}
1230
+		//Registration Overview Today
1231
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1232
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today')
1233
+		) {
1234
+			$admin_bar->add_menu(array(
1235
+				'id'     => 'espresso-toolbar-registrations-today',
1236
+				'parent' => 'espresso-toolbar-registrations',
1237
+				'title'  => esc_html__('Today', 'event_espresso'),
1238
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1239
+					$reg_admin_url),
1240
+				'meta'   => array(
1241
+					'title'  => esc_html__('Today', 'event_espresso'),
1242
+					'target' => '',
1243
+					'class'  => $menu_class,
1244
+				),
1245
+			));
1246
+		}
1247
+		//Registration Overview Today Completed
1248
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1249
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')
1250
+		) {
1251
+			$admin_bar->add_menu(array(
1252
+				'id'     => 'espresso-toolbar-registrations-today-approved',
1253
+				'parent' => 'espresso-toolbar-registrations-today',
1254
+				'title'  => esc_html__('Approved', 'event_espresso'),
1255
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1256
+					'action'      => 'default',
1257
+					'status'      => 'today',
1258
+					'_reg_status' => EEM_Registration::status_id_approved,
1259
+				), $reg_admin_url),
1260
+				'meta'   => array(
1261
+					'title'  => esc_html__('Approved', 'event_espresso'),
1262
+					'target' => '',
1263
+					'class'  => $menu_class,
1264
+				),
1265
+			));
1266
+		}
1267
+		//Registration Overview Today Pending\
1268
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1269
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')
1270
+		) {
1271
+			$admin_bar->add_menu(array(
1272
+				'id'     => 'espresso-toolbar-registrations-today-pending',
1273
+				'parent' => 'espresso-toolbar-registrations-today',
1274
+				'title'  => esc_html__('Pending', 'event_espresso'),
1275
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1276
+					'action'     => 'default',
1277
+					'status'     => 'today',
1278
+					'reg_status' => EEM_Registration::status_id_pending_payment,
1279
+				), $reg_admin_url),
1280
+				'meta'   => array(
1281
+					'title'  => esc_html__('Pending Payment', 'event_espresso'),
1282
+					'target' => '',
1283
+					'class'  => $menu_class,
1284
+				),
1285
+			));
1286
+		}
1287
+		//Registration Overview Today Incomplete
1288
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1289
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')
1290
+		) {
1291
+			$admin_bar->add_menu(array(
1292
+				'id'     => 'espresso-toolbar-registrations-today-not-approved',
1293
+				'parent' => 'espresso-toolbar-registrations-today',
1294
+				'title'  => esc_html__('Not Approved', 'event_espresso'),
1295
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1296
+					'action'      => 'default',
1297
+					'status'      => 'today',
1298
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1299
+				), $reg_admin_url),
1300
+				'meta'   => array(
1301
+					'title'  => esc_html__('Not Approved', 'event_espresso'),
1302
+					'target' => '',
1303
+					'class'  => $menu_class,
1304
+				),
1305
+			));
1306
+		}
1307
+		//Registration Overview Today Incomplete
1308
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1309
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')
1310
+		) {
1311
+			$admin_bar->add_menu(array(
1312
+				'id'     => 'espresso-toolbar-registrations-today-cancelled',
1313
+				'parent' => 'espresso-toolbar-registrations-today',
1314
+				'title'  => esc_html__('Cancelled', 'event_espresso'),
1315
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1316
+					'action'      => 'default',
1317
+					'status'      => 'today',
1318
+					'_reg_status' => EEM_Registration::status_id_cancelled,
1319
+				), $reg_admin_url),
1320
+				'meta'   => array(
1321
+					'title'  => esc_html__('Cancelled', 'event_espresso'),
1322
+					'target' => '',
1323
+					'class'  => $menu_class,
1324
+				),
1325
+			));
1326
+		}
1327
+		//Registration Overview This Month
1328
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1329
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month')
1330
+		) {
1331
+			$admin_bar->add_menu(array(
1332
+				'id'     => 'espresso-toolbar-registrations-month',
1333
+				'parent' => 'espresso-toolbar-registrations',
1334
+				'title'  => esc_html__('This Month', 'event_espresso'),
1335
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1336
+					$reg_admin_url),
1337
+				'meta'   => array(
1338
+					'title'  => esc_html__('This Month', 'event_espresso'),
1339
+					'target' => '',
1340
+					'class'  => $menu_class,
1341
+				),
1342
+			));
1343
+		}
1344
+		//Registration Overview This Month Approved
1345
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1346
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')
1347
+		) {
1348
+			$admin_bar->add_menu(array(
1349
+				'id'     => 'espresso-toolbar-registrations-month-approved',
1350
+				'parent' => 'espresso-toolbar-registrations-month',
1351
+				'title'  => esc_html__('Approved', 'event_espresso'),
1352
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1353
+					'action'      => 'default',
1354
+					'status'      => 'month',
1355
+					'_reg_status' => EEM_Registration::status_id_approved,
1356
+				), $reg_admin_url),
1357
+				'meta'   => array(
1358
+					'title'  => esc_html__('Approved', 'event_espresso'),
1359
+					'target' => '',
1360
+					'class'  => $menu_class,
1361
+				),
1362
+			));
1363
+		}
1364
+		//Registration Overview This Month Pending
1365
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1366
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')
1367
+		) {
1368
+			$admin_bar->add_menu(array(
1369
+				'id'     => 'espresso-toolbar-registrations-month-pending',
1370
+				'parent' => 'espresso-toolbar-registrations-month',
1371
+				'title'  => esc_html__('Pending', 'event_espresso'),
1372
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1373
+					'action'      => 'default',
1374
+					'status'      => 'month',
1375
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1376
+				), $reg_admin_url),
1377
+				'meta'   => array(
1378
+					'title'  => esc_html__('Pending', 'event_espresso'),
1379
+					'target' => '',
1380
+					'class'  => $menu_class,
1381
+				),
1382
+			));
1383
+		}
1384
+		//Registration Overview This Month Not Approved
1385
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1386
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')
1387
+		) {
1388
+			$admin_bar->add_menu(array(
1389
+				'id'     => 'espresso-toolbar-registrations-month-not-approved',
1390
+				'parent' => 'espresso-toolbar-registrations-month',
1391
+				'title'  => esc_html__('Not Approved', 'event_espresso'),
1392
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1393
+					'action'      => 'default',
1394
+					'status'      => 'month',
1395
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1396
+				), $reg_admin_url),
1397
+				'meta'   => array(
1398
+					'title'  => esc_html__('Not Approved', 'event_espresso'),
1399
+					'target' => '',
1400
+					'class'  => $menu_class,
1401
+				),
1402
+			));
1403
+		}
1404
+		//Registration Overview This Month Cancelled
1405
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1406
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')
1407
+		) {
1408
+			$admin_bar->add_menu(array(
1409
+				'id'     => 'espresso-toolbar-registrations-month-cancelled',
1410
+				'parent' => 'espresso-toolbar-registrations-month',
1411
+				'title'  => esc_html__('Cancelled', 'event_espresso'),
1412
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1413
+					'action'      => 'default',
1414
+					'status'      => 'month',
1415
+					'_reg_status' => EEM_Registration::status_id_cancelled,
1416
+				), $reg_admin_url),
1417
+				'meta'   => array(
1418
+					'title'  => esc_html__('Cancelled', 'event_espresso'),
1419
+					'target' => '',
1420
+					'class'  => $menu_class,
1421
+				),
1422
+			));
1423
+		}
1424
+		//Extensions & Services
1425
+		if ($this->registry->CAP->current_user_can('ee_read_ee',
1426
+			'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')
1427
+		) {
1428
+			$admin_bar->add_menu(array(
1429
+				'id'     => 'espresso-toolbar-extensions-and-services',
1430
+				'parent' => 'espresso-toolbar',
1431
+				'title'  => esc_html__('Extensions & Services', 'event_espresso'),
1432
+				'href'   => $extensions_admin_url,
1433
+				'meta'   => array(
1434
+					'title'  => esc_html__('Extensions & Services', 'event_espresso'),
1435
+					'target' => '',
1436
+					'class'  => $menu_class,
1437
+				),
1438
+			));
1439
+		}
1440
+	}
1441
+
1442
+
1443
+
1444
+	/**
1445
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1446
+	 * never returned with the function.
1447
+	 *
1448
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1449
+	 * @return array
1450
+	 */
1451
+	public function remove_pages_from_wp_list_pages($exclude_array)
1452
+	{
1453
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1454
+	}
1455 1455
 
1456 1456
 
1457 1457
 
Please login to merge, or discard this patch.