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