Completed
Branch EDTR/routing (63c8e0)
by
unknown
52:00 queued 43:18
created
core/EE_System.core.php 1 patch
Indentation   +1262 added lines, -1262 removed lines patch added patch discarded remove patch
@@ -29,1266 +29,1266 @@
 block discarded – undo
29 29
 final class EE_System implements ResettableInterface
30 30
 {
31 31
 
32
-    /**
33
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
34
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
35
-     */
36
-    const req_type_normal = 0;
37
-
38
-    /**
39
-     * Indicates this is a brand new installation of EE so we should install
40
-     * tables and default data etc
41
-     */
42
-    const req_type_new_activation = 1;
43
-
44
-    /**
45
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
46
-     * and we just exited maintenance mode). We MUST check the database is setup properly
47
-     * and that default data is setup too
48
-     */
49
-    const req_type_reactivation = 2;
50
-
51
-    /**
52
-     * indicates that EE has been upgraded since its previous request.
53
-     * We may have data migration scripts to call and will want to trigger maintenance mode
54
-     */
55
-    const req_type_upgrade = 3;
56
-
57
-    /**
58
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
59
-     */
60
-    const req_type_downgrade = 4;
61
-
62
-    /**
63
-     * @deprecated since version 4.6.0.dev.006
64
-     * Now whenever a new_activation is detected the request type is still just
65
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
66
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
67
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
68
-     * (Specifically, when the migration manager indicates migrations are finished
69
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
70
-     */
71
-    const req_type_activation_but_not_installed = 5;
72
-
73
-    /**
74
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
75
-     */
76
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
77
-
78
-    /**
79
-     * @var EE_System $_instance
80
-     */
81
-    private static $_instance;
82
-
83
-    /**
84
-     * @var EE_Registry $registry
85
-     */
86
-    private $registry;
87
-
88
-    /**
89
-     * @var LoaderInterface $loader
90
-     */
91
-    private $loader;
92
-
93
-    /**
94
-     * @var EE_Capabilities $capabilities
95
-     */
96
-    private $capabilities;
97
-
98
-    /**
99
-     * @var EE_Maintenance_Mode $maintenance_mode
100
-     */
101
-    private $maintenance_mode;
102
-
103
-    /**
104
-     * @var RequestInterface $request
105
-     */
106
-    private $request;
107
-
108
-    /**
109
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
110
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
111
-     *
112
-     * @var int $_req_type
113
-     */
114
-    private $_req_type;
115
-
116
-
117
-    /**
118
-     * @var RouteHandler $router
119
-     */
120
-    private $router;
121
-
122
-    /**
123
-     * Whether or not there was a non-micro version change in EE core version during this request
124
-     *
125
-     * @var boolean $_major_version_change
126
-     */
127
-    private $_major_version_change = false;
128
-
129
-    /**
130
-     * A Context DTO dedicated solely to identifying the current request type.
131
-     *
132
-     * @var RequestTypeContextCheckerInterface $request_type
133
-     */
134
-    private $request_type;
135
-
136
-
137
-    /**
138
-     * @singleton method used to instantiate class object
139
-     * @param EE_Registry|null         $registry
140
-     * @param LoaderInterface|null     $loader
141
-     * @param RequestInterface|null    $request
142
-     * @param EE_Maintenance_Mode|null $maintenance_mode
143
-     * @return EE_System
144
-     */
145
-    public static function instance(
146
-        EE_Registry $registry = null,
147
-        LoaderInterface $loader = null,
148
-        RequestInterface $request = null,
149
-        EE_Maintenance_Mode $maintenance_mode = null
150
-    ) {
151
-        // check if class object is instantiated
152
-        if (! self::$_instance instanceof EE_System) {
153
-            self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
154
-        }
155
-        return self::$_instance;
156
-    }
157
-
158
-
159
-    /**
160
-     * resets the instance and returns it
161
-     *
162
-     * @return EE_System
163
-     */
164
-    public static function reset()
165
-    {
166
-        self::$_instance->_req_type = null;
167
-        // make sure none of the old hooks are left hanging around
168
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
169
-        // we need to reset the migration manager in order for it to detect DMSs properly
170
-        EE_Data_Migration_Manager::reset();
171
-        self::instance()->detect_activations_or_upgrades();
172
-        self::instance()->perform_activations_upgrades_and_migrations();
173
-        return self::instance();
174
-    }
175
-
176
-
177
-    /**
178
-     * sets hooks for running rest of system
179
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
180
-     * starting EE Addons from any other point may lead to problems
181
-     *
182
-     * @param EE_Registry         $registry
183
-     * @param LoaderInterface     $loader
184
-     * @param RequestInterface    $request
185
-     * @param EE_Maintenance_Mode $maintenance_mode
186
-     */
187
-    private function __construct(
188
-        EE_Registry $registry,
189
-        LoaderInterface $loader,
190
-        RequestInterface $request,
191
-        EE_Maintenance_Mode $maintenance_mode
192
-    ) {
193
-        $this->registry = $registry;
194
-        $this->loader = $loader;
195
-        $this->request = $request;
196
-        $this->maintenance_mode = $maintenance_mode;
197
-        do_action('AHEE__EE_System__construct__begin', $this);
198
-        add_action(
199
-            'AHEE__EE_Bootstrap__load_espresso_addons',
200
-            array($this, 'loadCapabilities'),
201
-            5
202
-        );
203
-        add_action(
204
-            'AHEE__EE_Bootstrap__load_espresso_addons',
205
-            array($this, 'loadCommandBus'),
206
-            7
207
-        );
208
-        add_action(
209
-            'AHEE__EE_Bootstrap__load_espresso_addons',
210
-            array($this, 'loadPluginApi'),
211
-            9
212
-        );
213
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
214
-        add_action(
215
-            'AHEE__EE_Bootstrap__load_espresso_addons',
216
-            array($this, 'load_espresso_addons')
217
-        );
218
-        // when an ee addon is activated, we want to call the core hook(s) again
219
-        // because the newly-activated addon didn't get a chance to run at all
220
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
221
-        // detect whether install or upgrade
222
-        add_action(
223
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
224
-            array($this, 'detect_activations_or_upgrades'),
225
-            3
226
-        );
227
-        // load EE_Config, EE_Textdomain, etc
228
-        add_action(
229
-            'AHEE__EE_Bootstrap__load_core_configuration',
230
-            array($this, 'load_core_configuration'),
231
-            5
232
-        );
233
-        // load specifications for matching routes to current request
234
-        add_action(
235
-            'AHEE__EE_Bootstrap__load_core_configuration',
236
-            array($this, 'loadRouteMatchSpecifications')
237
-        );
238
-        // load EE_Config, EE_Textdomain, etc
239
-        add_action(
240
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
241
-            array($this, 'register_shortcodes_modules_and_widgets'),
242
-            7
243
-        );
244
-        // you wanna get going? I wanna get going... let's get going!
245
-        add_action(
246
-            'AHEE__EE_Bootstrap__brew_espresso',
247
-            array($this, 'brew_espresso'),
248
-            9
249
-        );
250
-        // other housekeeping
251
-        // exclude EE critical pages from wp_list_pages
252
-        add_filter(
253
-            'wp_list_pages_excludes',
254
-            array($this, 'remove_pages_from_wp_list_pages'),
255
-            10
256
-        );
257
-        // ALL EE Addons should use the following hook point to attach their initial setup too
258
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
259
-        do_action('AHEE__EE_System__construct__complete', $this);
260
-    }
261
-
262
-
263
-    /**
264
-     * load and setup EE_Capabilities
265
-     *
266
-     * @return void
267
-     */
268
-    public function loadCapabilities()
269
-    {
270
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
271
-        add_action(
272
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
273
-            function () {
274
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
275
-            }
276
-        );
277
-    }
278
-
279
-
280
-    /**
281
-     * create and cache the CommandBus, and also add middleware
282
-     * The CapChecker middleware requires the use of EE_Capabilities
283
-     * which is why we need to load the CommandBus after Caps are set up
284
-     *
285
-     * @return void
286
-     */
287
-    public function loadCommandBus()
288
-    {
289
-        $this->loader->getShared(
290
-            'CommandBusInterface',
291
-            array(
292
-                null,
293
-                apply_filters(
294
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
295
-                    array(
296
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
297
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
298
-                    )
299
-                ),
300
-            )
301
-        );
302
-    }
303
-
304
-
305
-    /**
306
-     * @return void
307
-     * @throws EE_Error
308
-     */
309
-    public function loadPluginApi()
310
-    {
311
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
312
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
313
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
314
-        $this->loader->getShared('EE_Request_Handler');
315
-    }
316
-
317
-
318
-    /**
319
-     * @param string $addon_name
320
-     * @param string $version_constant
321
-     * @param string $min_version_required
322
-     * @param string $load_callback
323
-     * @param string $plugin_file_constant
324
-     * @return void
325
-     */
326
-    private function deactivateIncompatibleAddon(
327
-        $addon_name,
328
-        $version_constant,
329
-        $min_version_required,
330
-        $load_callback,
331
-        $plugin_file_constant
332
-    ) {
333
-        if (! defined($version_constant)) {
334
-            return;
335
-        }
336
-        $addon_version = constant($version_constant);
337
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
338
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
339
-            if (! function_exists('deactivate_plugins')) {
340
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
341
-            }
342
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
343
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
344
-            EE_Error::add_error(
345
-                sprintf(
346
-                    esc_html__(
347
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
348
-                        'event_espresso'
349
-                    ),
350
-                    $addon_name,
351
-                    $min_version_required
352
-                ),
353
-                __FILE__,
354
-                __FUNCTION__ . "({$addon_name})",
355
-                __LINE__
356
-            );
357
-            EE_Error::get_notices(false, true);
358
-        }
359
-    }
360
-
361
-
362
-    /**
363
-     * load_espresso_addons
364
-     * allow addons to load first so that they can set hooks for running DMS's, etc
365
-     * this is hooked into both:
366
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
367
-     *        which runs during the WP 'plugins_loaded' action at priority 5
368
-     *    and the WP 'activate_plugin' hook point
369
-     *
370
-     * @access public
371
-     * @return void
372
-     */
373
-    public function load_espresso_addons()
374
-    {
375
-        $this->deactivateIncompatibleAddon(
376
-            'Wait Lists',
377
-            'EE_WAIT_LISTS_VERSION',
378
-            '1.0.0.beta.074',
379
-            'load_espresso_wait_lists',
380
-            'EE_WAIT_LISTS_PLUGIN_FILE'
381
-        );
382
-        $this->deactivateIncompatibleAddon(
383
-            'Automated Upcoming Event Notifications',
384
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
385
-            '1.0.0.beta.091',
386
-            'load_espresso_automated_upcoming_event_notification',
387
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
388
-        );
389
-        do_action('AHEE__EE_System__load_espresso_addons');
390
-        // if the WP API basic auth plugin isn't already loaded, load it now.
391
-        // We want it for mobile apps. Just include the entire plugin
392
-        // also, don't load the basic auth when a plugin is getting activated, because
393
-        // it could be the basic auth plugin, and it doesn't check if its methods are already defined
394
-        // and causes a fatal error
395
-        if (($this->request->isWordPressApi() || $this->request->isApi())
396
-            && $this->request->getRequestParam('activate') !== 'true'
397
-            && ! function_exists('json_basic_auth_handler')
398
-            && ! function_exists('json_basic_auth_error')
399
-            && ! in_array(
400
-                $this->request->getRequestParam('action'),
401
-                array('activate', 'activate-selected'),
402
-                true
403
-            )
404
-        ) {
405
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
406
-        }
407
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
408
-    }
409
-
410
-
411
-    /**
412
-     * detect_activations_or_upgrades
413
-     * Checks for activation or upgrade of core first;
414
-     * then also checks if any registered addons have been activated or upgraded
415
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
416
-     * which runs during the WP 'plugins_loaded' action at priority 3
417
-     *
418
-     * @access public
419
-     * @return void
420
-     */
421
-    public function detect_activations_or_upgrades()
422
-    {
423
-        // first off: let's make sure to handle core
424
-        $this->detect_if_activation_or_upgrade();
425
-        foreach ($this->registry->addons as $addon) {
426
-            if ($addon instanceof EE_Addon) {
427
-                // detect teh request type for that addon
428
-                $addon->detect_activation_or_upgrade();
429
-            }
430
-        }
431
-    }
432
-
433
-
434
-    /**
435
-     * detect_if_activation_or_upgrade
436
-     * Takes care of detecting whether this is a brand new install or code upgrade,
437
-     * and either setting up the DB or setting up maintenance mode etc.
438
-     *
439
-     * @access public
440
-     * @return void
441
-     */
442
-    public function detect_if_activation_or_upgrade()
443
-    {
444
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
445
-        // check if db has been updated, or if its a brand-new installation
446
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
447
-        $request_type = $this->detect_req_type($espresso_db_update);
448
-        // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
449
-        switch ($request_type) {
450
-            case EE_System::req_type_new_activation:
451
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
452
-                $this->_handle_core_version_change($espresso_db_update);
453
-                break;
454
-            case EE_System::req_type_reactivation:
455
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
456
-                $this->_handle_core_version_change($espresso_db_update);
457
-                break;
458
-            case EE_System::req_type_upgrade:
459
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
460
-                // migrations may be required now that we've upgraded
461
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
462
-                $this->_handle_core_version_change($espresso_db_update);
463
-                break;
464
-            case EE_System::req_type_downgrade:
465
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
466
-                // its possible migrations are no longer required
467
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
468
-                $this->_handle_core_version_change($espresso_db_update);
469
-                break;
470
-            case EE_System::req_type_normal:
471
-            default:
472
-                break;
473
-        }
474
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
475
-    }
476
-
477
-
478
-    /**
479
-     * Updates the list of installed versions and sets hooks for
480
-     * initializing the database later during the request
481
-     *
482
-     * @param array $espresso_db_update
483
-     */
484
-    private function _handle_core_version_change($espresso_db_update)
485
-    {
486
-        $this->update_list_of_installed_versions($espresso_db_update);
487
-        // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
488
-        add_action(
489
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
490
-            array($this, 'initialize_db_if_no_migrations_required')
491
-        );
492
-    }
493
-
494
-
495
-    /**
496
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
497
-     * information about what versions of EE have been installed and activated,
498
-     * NOT necessarily the state of the database
499
-     *
500
-     * @param mixed $espresso_db_update           the value of the WordPress option.
501
-     *                                            If not supplied, fetches it from the options table
502
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
503
-     */
504
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
505
-    {
506
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
507
-        if (! $espresso_db_update) {
508
-            $espresso_db_update = get_option('espresso_db_update');
509
-        }
510
-        // check that option is an array
511
-        if (! is_array($espresso_db_update)) {
512
-            // if option is FALSE, then it never existed
513
-            if ($espresso_db_update === false) {
514
-                // make $espresso_db_update an array and save option with autoload OFF
515
-                $espresso_db_update = array();
516
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
517
-            } else {
518
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
519
-                $espresso_db_update = array($espresso_db_update => array());
520
-                update_option('espresso_db_update', $espresso_db_update);
521
-            }
522
-        } else {
523
-            $corrected_db_update = array();
524
-            // if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
525
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
526
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
527
-                    // the key is an int, and the value IS NOT an array
528
-                    // so it must be numerically-indexed, where values are versions installed...
529
-                    // fix it!
530
-                    $version_string = $should_be_array;
531
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
532
-                } else {
533
-                    // ok it checks out
534
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
535
-                }
536
-            }
537
-            $espresso_db_update = $corrected_db_update;
538
-            update_option('espresso_db_update', $espresso_db_update);
539
-        }
540
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
541
-        return $espresso_db_update;
542
-    }
543
-
544
-
545
-    /**
546
-     * Does the traditional work of setting up the plugin's database and adding default data.
547
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
548
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
549
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
550
-     * so that it will be done when migrations are finished
551
-     *
552
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
553
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
554
-     *                                       This is a resource-intensive job
555
-     *                                       so we prefer to only do it when necessary
556
-     * @return void
557
-     * @throws EE_Error
558
-     */
559
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
560
-    {
561
-        $request_type = $this->detect_req_type();
562
-        // only initialize system if we're not in maintenance mode.
563
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
564
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
565
-            $rewrite_rules = $this->loader->getShared(
566
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
567
-            );
568
-            $rewrite_rules->flush();
569
-            if ($verify_schema) {
570
-                EEH_Activation::initialize_db_and_folders();
571
-            }
572
-            EEH_Activation::initialize_db_content();
573
-            EEH_Activation::system_initialization();
574
-            if ($initialize_addons_too) {
575
-                $this->initialize_addons();
576
-            }
577
-        } else {
578
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
579
-        }
580
-        if ($request_type === EE_System::req_type_new_activation
581
-            || $request_type === EE_System::req_type_reactivation
582
-            || (
583
-                $request_type === EE_System::req_type_upgrade
584
-                && $this->is_major_version_change()
585
-            )
586
-        ) {
587
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
588
-        }
589
-    }
590
-
591
-
592
-    /**
593
-     * Initializes the db for all registered addons
594
-     *
595
-     * @throws EE_Error
596
-     */
597
-    public function initialize_addons()
598
-    {
599
-        // foreach registered addon, make sure its db is up-to-date too
600
-        foreach ($this->registry->addons as $addon) {
601
-            if ($addon instanceof EE_Addon) {
602
-                $addon->initialize_db_if_no_migrations_required();
603
-            }
604
-        }
605
-    }
606
-
607
-
608
-    /**
609
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
610
-     *
611
-     * @param    array  $version_history
612
-     * @param    string $current_version_to_add version to be added to the version history
613
-     * @return    boolean success as to whether or not this option was changed
614
-     */
615
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
616
-    {
617
-        if (! $version_history) {
618
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
619
-        }
620
-        if ($current_version_to_add === null) {
621
-            $current_version_to_add = espresso_version();
622
-        }
623
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
624
-        // re-save
625
-        return update_option('espresso_db_update', $version_history);
626
-    }
627
-
628
-
629
-    /**
630
-     * Detects if the current version indicated in the has existed in the list of
631
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
632
-     *
633
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
634
-     *                                  If not supplied, fetches it from the options table.
635
-     *                                  Also, caches its result so later parts of the code can also know whether
636
-     *                                  there's been an update or not. This way we can add the current version to
637
-     *                                  espresso_db_update, but still know if this is a new install or not
638
-     * @return int one of the constants on EE_System::req_type_
639
-     */
640
-    public function detect_req_type($espresso_db_update = null)
641
-    {
642
-        if ($this->_req_type === null) {
643
-            $espresso_db_update = ! empty($espresso_db_update)
644
-                ? $espresso_db_update
645
-                : $this->fix_espresso_db_upgrade_option();
646
-            $this->_req_type = EE_System::detect_req_type_given_activation_history(
647
-                $espresso_db_update,
648
-                'ee_espresso_activation',
649
-                espresso_version()
650
-            );
651
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
652
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
653
-        }
654
-        return $this->_req_type;
655
-    }
656
-
657
-
658
-    /**
659
-     * Returns whether or not there was a non-micro version change (ie, change in either
660
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
661
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
662
-     *
663
-     * @param $activation_history
664
-     * @return bool
665
-     */
666
-    private function _detect_major_version_change($activation_history)
667
-    {
668
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
669
-        $previous_version_parts = explode('.', $previous_version);
670
-        $current_version_parts = explode('.', espresso_version());
671
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
672
-               && (
673
-                   $previous_version_parts[0] !== $current_version_parts[0]
674
-                   || $previous_version_parts[1] !== $current_version_parts[1]
675
-               );
676
-    }
677
-
678
-
679
-    /**
680
-     * Returns true if either the major or minor version of EE changed during this request.
681
-     * 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
682
-     *
683
-     * @return bool
684
-     */
685
-    public function is_major_version_change()
686
-    {
687
-        return $this->_major_version_change;
688
-    }
689
-
690
-
691
-    /**
692
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
693
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
694
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
695
-     * just activated to (for core that will always be espresso_version())
696
-     *
697
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
698
-     *                                                 ee plugin. for core that's 'espresso_db_update'
699
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
700
-     *                                                 indicate that this plugin was just activated
701
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
702
-     *                                                 espresso_version())
703
-     * @return int one of the constants on EE_System::req_type_*
704
-     */
705
-    public static function detect_req_type_given_activation_history(
706
-        $activation_history_for_addon,
707
-        $activation_indicator_option_name,
708
-        $version_to_upgrade_to
709
-    ) {
710
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
711
-        if ($activation_history_for_addon) {
712
-            // it exists, so this isn't a completely new install
713
-            // check if this version already in that list of previously installed versions
714
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
715
-                // it a version we haven't seen before
716
-                if ($version_is_higher === 1) {
717
-                    $req_type = EE_System::req_type_upgrade;
718
-                } else {
719
-                    $req_type = EE_System::req_type_downgrade;
720
-                }
721
-                delete_option($activation_indicator_option_name);
722
-            } else {
723
-                // its not an update. maybe a reactivation?
724
-                if (get_option($activation_indicator_option_name, false)) {
725
-                    if ($version_is_higher === -1) {
726
-                        $req_type = EE_System::req_type_downgrade;
727
-                    } elseif ($version_is_higher === 0) {
728
-                        // we've seen this version before, but it's an activation. must be a reactivation
729
-                        $req_type = EE_System::req_type_reactivation;
730
-                    } else {// $version_is_higher === 1
731
-                        $req_type = EE_System::req_type_upgrade;
732
-                    }
733
-                    delete_option($activation_indicator_option_name);
734
-                } else {
735
-                    // we've seen this version before and the activation indicate doesn't show it was just activated
736
-                    if ($version_is_higher === -1) {
737
-                        $req_type = EE_System::req_type_downgrade;
738
-                    } elseif ($version_is_higher === 0) {
739
-                        // we've seen this version before and it's not an activation. its normal request
740
-                        $req_type = EE_System::req_type_normal;
741
-                    } else {// $version_is_higher === 1
742
-                        $req_type = EE_System::req_type_upgrade;
743
-                    }
744
-                }
745
-            }
746
-        } else {
747
-            // brand new install
748
-            $req_type = EE_System::req_type_new_activation;
749
-            delete_option($activation_indicator_option_name);
750
-        }
751
-        return $req_type;
752
-    }
753
-
754
-
755
-    /**
756
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
757
-     * the $activation_history_for_addon
758
-     *
759
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
760
-     *                                             sometimes containing 'unknown-date'
761
-     * @param string $version_to_upgrade_to        (current version)
762
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
763
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
764
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
765
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
766
-     */
767
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
768
-    {
769
-        // find the most recently-activated version
770
-        $most_recently_active_version =
771
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
772
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
773
-    }
774
-
775
-
776
-    /**
777
-     * Gets the most recently active version listed in the activation history,
778
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
779
-     *
780
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
781
-     *                                   sometimes containing 'unknown-date'
782
-     * @return string
783
-     */
784
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
785
-    {
786
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
787
-        $most_recently_active_version = '0.0.0.dev.000';
788
-        if (is_array($activation_history)) {
789
-            foreach ($activation_history as $version => $times_activated) {
790
-                // check there is a record of when this version was activated. Otherwise,
791
-                // mark it as unknown
792
-                if (! $times_activated) {
793
-                    $times_activated = array('unknown-date');
794
-                }
795
-                if (is_string($times_activated)) {
796
-                    $times_activated = array($times_activated);
797
-                }
798
-                foreach ($times_activated as $an_activation) {
799
-                    if ($an_activation !== 'unknown-date'
800
-                        && $an_activation
801
-                           > $most_recently_active_version_activation) {
802
-                        $most_recently_active_version = $version;
803
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
804
-                            ? '1970-01-01 00:00:00'
805
-                            : $an_activation;
806
-                    }
807
-                }
808
-            }
809
-        }
810
-        return $most_recently_active_version;
811
-    }
812
-
813
-
814
-    /**
815
-     * This redirects to the about EE page after activation
816
-     *
817
-     * @return void
818
-     */
819
-    public function redirect_to_about_ee()
820
-    {
821
-        $notices = EE_Error::get_notices(false);
822
-        // if current user is an admin and it's not an ajax or rest request
823
-        if (! isset($notices['errors'])
824
-            && $this->request->isAdmin()
825
-            && apply_filters(
826
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
827
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
828
-            )
829
-        ) {
830
-            $query_params = array('page' => 'espresso_about');
831
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
832
-                $query_params['new_activation'] = true;
833
-            }
834
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
835
-                $query_params['reactivation'] = true;
836
-            }
837
-            $url = add_query_arg($query_params, admin_url('admin.php'));
838
-            wp_safe_redirect($url);
839
-            exit();
840
-        }
841
-    }
842
-
843
-
844
-    /**
845
-     * load_core_configuration
846
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
847
-     * which runs during the WP 'plugins_loaded' action at priority 5
848
-     *
849
-     * @return void
850
-     * @throws ReflectionException
851
-     * @throws Exception
852
-     */
853
-    public function load_core_configuration()
854
-    {
855
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
856
-        $this->loader->getShared('EE_Load_Textdomain');
857
-        // load textdomain
858
-        EE_Load_Textdomain::load_textdomain();
859
-        // load caf stuff a chance to play during the activation process too.
860
-        $this->_maybe_brew_regular();
861
-        // load and setup EE_Config and EE_Network_Config
862
-        $config = $this->loader->getShared('EE_Config');
863
-        $this->loader->getShared('EE_Network_Config');
864
-        // setup autoloaders
865
-        // enable logging?
866
-        if ($config->admin->use_remote_logging) {
867
-            $this->loader->getShared('EE_Log');
868
-        }
869
-        // check for activation errors
870
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
871
-        if ($activation_errors) {
872
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
873
-            update_option('ee_plugin_activation_errors', false);
874
-        }
875
-        // get model names
876
-        $this->_parse_model_names();
877
-        // configure custom post type definitions
878
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
879
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
880
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
881
-    }
882
-
883
-
884
-    /**
885
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
886
-     *
887
-     * @return void
888
-     * @throws ReflectionException
889
-     */
890
-    private function _parse_model_names()
891
-    {
892
-        // get all the files in the EE_MODELS folder that end in .model.php
893
-        $models = glob(EE_MODELS . '*.model.php');
894
-        $model_names = array();
895
-        $non_abstract_db_models = array();
896
-        foreach ($models as $model) {
897
-            // get model classname
898
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
899
-            $short_name = str_replace('EEM_', '', $classname);
900
-            $reflectionClass = new ReflectionClass($classname);
901
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
902
-                $non_abstract_db_models[ $short_name ] = $classname;
903
-            }
904
-            $model_names[ $short_name ] = $classname;
905
-        }
906
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
907
-        $this->registry->non_abstract_db_models = apply_filters(
908
-            'FHEE__EE_System__parse_implemented_model_names',
909
-            $non_abstract_db_models
910
-        );
911
-    }
912
-
913
-
914
-    /**
915
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
916
-     * that need to be setup before our EE_System launches.
917
-     *
918
-     * @return void
919
-     * @throws DomainException
920
-     * @throws InvalidArgumentException
921
-     * @throws InvalidDataTypeException
922
-     * @throws InvalidInterfaceException
923
-     * @throws InvalidClassException
924
-     * @throws InvalidFilePathException
925
-     */
926
-    private function _maybe_brew_regular()
927
-    {
928
-        /** @var Domain $domain */
929
-        $domain = DomainFactory::getShared(
930
-            new FullyQualifiedName(
931
-                'EventEspresso\core\domain\Domain'
932
-            ),
933
-            array(
934
-                new FilePath(EVENT_ESPRESSO_MAIN_FILE),
935
-                Version::fromString(espresso_version()),
936
-            )
937
-        );
938
-        if ($domain->isCaffeinated()) {
939
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
940
-        }
941
-    }
942
-
943
-
944
-    /**
945
-     * @since 4.9.71.p
946
-     * @throws Exception
947
-     */
948
-    public function loadRouteMatchSpecifications()
949
-    {
950
-        try {
951
-            $this->loader->getShared('EventEspresso\core\services\routing\RouteMatchSpecificationManager');
952
-            $this->loader->getShared('EventEspresso\core\services\routing\RouteCollection');
953
-            $this->router = $this->loader->getShared('EventEspresso\core\services\routing\RouteHandler');
954
-            // load dependencies for Routes
955
-            /** @var EventEspresso\core\domain\entities\routing\handlers\RouteHandlersDependencyMap $route_dependencies */
956
-            $route_dependencies = LocalDependencyMapFactory::create(
957
-                'EventEspresso\core\domain\entities\routing\handlers\RouteHandlersDependencyMap'
958
-            );
959
-            $route_dependencies->register();
960
-        } catch (Exception $exception) {
961
-            new ExceptionStackTraceDisplay($exception);
962
-        }
963
-        do_action('AHEE__EE_System__loadRouteMatchSpecifications');
964
-    }
965
-
966
-
967
-    /**
968
-     * register_shortcodes_modules_and_widgets
969
-     * generate lists of shortcodes and modules, then verify paths and classes
970
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
971
-     * which runs during the WP 'plugins_loaded' action at priority 7
972
-     *
973
-     * @access public
974
-     * @return void
975
-     * @throws Exception
976
-     */
977
-    public function register_shortcodes_modules_and_widgets()
978
-    {
979
-        $this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\frontend\ShortcodeRequests');
980
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
981
-        // check for addons using old hook point
982
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
983
-            $this->_incompatible_addon_error();
984
-        }
985
-    }
986
-
987
-
988
-    /**
989
-     * _incompatible_addon_error
990
-     *
991
-     * @access public
992
-     * @return void
993
-     */
994
-    private function _incompatible_addon_error()
995
-    {
996
-        // get array of classes hooking into here
997
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
998
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
999
-        );
1000
-        if (! empty($class_names)) {
1001
-            $msg = __(
1002
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1003
-                'event_espresso'
1004
-            );
1005
-            $msg .= '<ul>';
1006
-            foreach ($class_names as $class_name) {
1007
-                $msg .= '<li><b>Event Espresso - '
1008
-                        . str_replace(
1009
-                            array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'),
1010
-                            '',
1011
-                            $class_name
1012
-                        ) . '</b></li>';
1013
-            }
1014
-            $msg .= '</ul>';
1015
-            $msg .= __(
1016
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1017
-                'event_espresso'
1018
-            );
1019
-            // save list of incompatible addons to wp-options for later use
1020
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
1021
-            if (is_admin()) {
1022
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1023
-            }
1024
-        }
1025
-    }
1026
-
1027
-
1028
-    /**
1029
-     * brew_espresso
1030
-     * begins the process of setting hooks for initializing EE in the correct order
1031
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1032
-     * which runs during the WP 'plugins_loaded' action at priority 9
1033
-     *
1034
-     * @return void
1035
-     * @throws Exception
1036
-     */
1037
-    public function brew_espresso()
1038
-    {
1039
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1040
-        // load some final core systems
1041
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1042
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1043
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1044
-        add_action('init', array($this, 'load_controllers'), 7);
1045
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1046
-        add_action('init', array($this, 'initialize'), 10);
1047
-        add_action('init', array($this, 'initialize_last'), 100);
1048
-        $this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\shared\GQLRequests');
1049
-        $this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\admin\PueRequests');
1050
-        $this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\shared\RestApiRequests');
1051
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1052
-    }
1053
-
1054
-
1055
-    /**
1056
-     *    set_hooks_for_core
1057
-     *
1058
-     * @access public
1059
-     * @return    void
1060
-     * @throws EE_Error
1061
-     */
1062
-    public function set_hooks_for_core()
1063
-    {
1064
-        $this->_deactivate_incompatible_addons();
1065
-        do_action('AHEE__EE_System__set_hooks_for_core');
1066
-        $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1067
-        // caps need to be initialized on every request so that capability maps are set.
1068
-        // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1069
-        $this->registry->CAP->init_caps();
1070
-    }
1071
-
1072
-
1073
-    /**
1074
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1075
-     * deactivates any addons considered incompatible with the current version of EE
1076
-     */
1077
-    private function _deactivate_incompatible_addons()
1078
-    {
1079
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1080
-        if (! empty($incompatible_addons)) {
1081
-            $active_plugins = get_option('active_plugins', array());
1082
-            foreach ($active_plugins as $active_plugin) {
1083
-                foreach ($incompatible_addons as $incompatible_addon) {
1084
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1085
-                        unset($_GET['activate']);
1086
-                        espresso_deactivate_plugin($active_plugin);
1087
-                    }
1088
-                }
1089
-            }
1090
-        }
1091
-    }
1092
-
1093
-
1094
-    /**
1095
-     *    perform_activations_upgrades_and_migrations
1096
-     *
1097
-     * @access public
1098
-     * @return    void
1099
-     */
1100
-    public function perform_activations_upgrades_and_migrations()
1101
-    {
1102
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1103
-    }
1104
-
1105
-
1106
-    /**
1107
-     * @return void
1108
-     * @throws DomainException
1109
-     */
1110
-    public function load_CPTs_and_session()
1111
-    {
1112
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1113
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */
1114
-        $register_custom_taxonomies = $this->loader->getShared(
1115
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
1116
-        );
1117
-        $register_custom_taxonomies->registerCustomTaxonomies();
1118
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
1119
-        $register_custom_post_types = $this->loader->getShared(
1120
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
1121
-        );
1122
-        $register_custom_post_types->registerCustomPostTypes();
1123
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */
1124
-        $register_custom_taxonomy_terms = $this->loader->getShared(
1125
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
1126
-        );
1127
-        $register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1128
-        // load legacy Custom Post Types and Taxonomies
1129
-        $this->loader->getShared('EE_Register_CPTs');
1130
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1131
-    }
1132
-
1133
-
1134
-    /**
1135
-     * load_controllers
1136
-     * this is the best place to load any additional controllers that needs access to EE core.
1137
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1138
-     * time
1139
-     *
1140
-     * @access public
1141
-     * @return void
1142
-     * @throws Exception
1143
-     */
1144
-    public function load_controllers()
1145
-    {
1146
-        do_action('AHEE__EE_System__load_controllers__start');
1147
-        // now start loading routes
1148
-        $this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\frontend\FrontendRequests');
1149
-        $this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\admin\EspressoLegacyAdmin');
1150
-        $this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventEditor');
1151
-        $this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage');
1152
-        $this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\shared\WordPressHeartbeat');
1153
-        do_action('AHEE__EE_System__load_controllers__complete');
1154
-    }
1155
-
1156
-
1157
-    /**
1158
-     * core_loaded_and_ready
1159
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1160
-     *
1161
-     * @access public
1162
-     * @return void
1163
-     * @throws Exception
1164
-     */
1165
-    public function core_loaded_and_ready()
1166
-    {
1167
-        $this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\shared\AssetRequests');
1168
-        $this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\shared\SessionRequests');
1169
-        // integrate WP_Query with the EE models
1170
-        $this->loader->getShared('EE_CPT_Strategy');
1171
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1172
-        // always load template tags, because it's faster than checking if it's a front-end request, and many page
1173
-        // builders require these even on the front-end
1174
-        require_once EE_PUBLIC . 'template_tags.php';
1175
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1176
-    }
1177
-
1178
-
1179
-    /**
1180
-     * initialize
1181
-     * this is the best place to begin initializing client code
1182
-     *
1183
-     * @access public
1184
-     * @return void
1185
-     */
1186
-    public function initialize()
1187
-    {
1188
-        do_action('AHEE__EE_System__initialize');
1189
-    }
1190
-
1191
-
1192
-    /**
1193
-     * initialize_last
1194
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1195
-     * initialize has done so
1196
-     *
1197
-     * @access public
1198
-     * @return void
1199
-     * @throws Exception
1200
-     */
1201
-    public function initialize_last()
1202
-    {
1203
-        do_action('AHEE__EE_System__initialize_last');
1204
-        /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1205
-        $rewrite_rules = $this->loader->getShared(
1206
-            'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1207
-        );
1208
-        $rewrite_rules->flushRewriteRules();
1209
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1210
-        $this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\admin\PersonalDataRequests');
1211
-    }
1212
-
1213
-
1214
-    /**
1215
-     * @return void
1216
-     */
1217
-    public function addEspressoToolbar()
1218
-    {
1219
-        $this->loader->getShared(
1220
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1221
-            array($this->registry->CAP)
1222
-        );
1223
-    }
1224
-
1225
-
1226
-    /**
1227
-     * do_not_cache
1228
-     * sets no cache headers and defines no cache constants for WP plugins
1229
-     *
1230
-     * @access public
1231
-     * @return void
1232
-     */
1233
-    public static function do_not_cache()
1234
-    {
1235
-        // set no cache constants
1236
-        if (! defined('DONOTCACHEPAGE')) {
1237
-            define('DONOTCACHEPAGE', true);
1238
-        }
1239
-        if (! defined('DONOTCACHCEOBJECT')) {
1240
-            define('DONOTCACHCEOBJECT', true);
1241
-        }
1242
-        if (! defined('DONOTCACHEDB')) {
1243
-            define('DONOTCACHEDB', true);
1244
-        }
1245
-        // add no cache headers
1246
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1247
-        // plus a little extra for nginx and Google Chrome
1248
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1249
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1250
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1251
-    }
1252
-
1253
-
1254
-    /**
1255
-     *    extra_nocache_headers
1256
-     *
1257
-     * @access    public
1258
-     * @param $headers
1259
-     * @return    array
1260
-     */
1261
-    public static function extra_nocache_headers($headers)
1262
-    {
1263
-        // for NGINX
1264
-        $headers['X-Accel-Expires'] = 0;
1265
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1266
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1267
-        return $headers;
1268
-    }
1269
-
1270
-
1271
-    /**
1272
-     *    nocache_headers
1273
-     *
1274
-     * @access    public
1275
-     * @return    void
1276
-     */
1277
-    public static function nocache_headers()
1278
-    {
1279
-        nocache_headers();
1280
-    }
1281
-
1282
-
1283
-    /**
1284
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1285
-     * never returned with the function.
1286
-     *
1287
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1288
-     * @return array
1289
-     */
1290
-    public function remove_pages_from_wp_list_pages($exclude_array)
1291
-    {
1292
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1293
-    }
32
+	/**
33
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
34
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
35
+	 */
36
+	const req_type_normal = 0;
37
+
38
+	/**
39
+	 * Indicates this is a brand new installation of EE so we should install
40
+	 * tables and default data etc
41
+	 */
42
+	const req_type_new_activation = 1;
43
+
44
+	/**
45
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
46
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
47
+	 * and that default data is setup too
48
+	 */
49
+	const req_type_reactivation = 2;
50
+
51
+	/**
52
+	 * indicates that EE has been upgraded since its previous request.
53
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
54
+	 */
55
+	const req_type_upgrade = 3;
56
+
57
+	/**
58
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
59
+	 */
60
+	const req_type_downgrade = 4;
61
+
62
+	/**
63
+	 * @deprecated since version 4.6.0.dev.006
64
+	 * Now whenever a new_activation is detected the request type is still just
65
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
66
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
67
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
68
+	 * (Specifically, when the migration manager indicates migrations are finished
69
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
70
+	 */
71
+	const req_type_activation_but_not_installed = 5;
72
+
73
+	/**
74
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
75
+	 */
76
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
77
+
78
+	/**
79
+	 * @var EE_System $_instance
80
+	 */
81
+	private static $_instance;
82
+
83
+	/**
84
+	 * @var EE_Registry $registry
85
+	 */
86
+	private $registry;
87
+
88
+	/**
89
+	 * @var LoaderInterface $loader
90
+	 */
91
+	private $loader;
92
+
93
+	/**
94
+	 * @var EE_Capabilities $capabilities
95
+	 */
96
+	private $capabilities;
97
+
98
+	/**
99
+	 * @var EE_Maintenance_Mode $maintenance_mode
100
+	 */
101
+	private $maintenance_mode;
102
+
103
+	/**
104
+	 * @var RequestInterface $request
105
+	 */
106
+	private $request;
107
+
108
+	/**
109
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
110
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
111
+	 *
112
+	 * @var int $_req_type
113
+	 */
114
+	private $_req_type;
115
+
116
+
117
+	/**
118
+	 * @var RouteHandler $router
119
+	 */
120
+	private $router;
121
+
122
+	/**
123
+	 * Whether or not there was a non-micro version change in EE core version during this request
124
+	 *
125
+	 * @var boolean $_major_version_change
126
+	 */
127
+	private $_major_version_change = false;
128
+
129
+	/**
130
+	 * A Context DTO dedicated solely to identifying the current request type.
131
+	 *
132
+	 * @var RequestTypeContextCheckerInterface $request_type
133
+	 */
134
+	private $request_type;
135
+
136
+
137
+	/**
138
+	 * @singleton method used to instantiate class object
139
+	 * @param EE_Registry|null         $registry
140
+	 * @param LoaderInterface|null     $loader
141
+	 * @param RequestInterface|null    $request
142
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
143
+	 * @return EE_System
144
+	 */
145
+	public static function instance(
146
+		EE_Registry $registry = null,
147
+		LoaderInterface $loader = null,
148
+		RequestInterface $request = null,
149
+		EE_Maintenance_Mode $maintenance_mode = null
150
+	) {
151
+		// check if class object is instantiated
152
+		if (! self::$_instance instanceof EE_System) {
153
+			self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
154
+		}
155
+		return self::$_instance;
156
+	}
157
+
158
+
159
+	/**
160
+	 * resets the instance and returns it
161
+	 *
162
+	 * @return EE_System
163
+	 */
164
+	public static function reset()
165
+	{
166
+		self::$_instance->_req_type = null;
167
+		// make sure none of the old hooks are left hanging around
168
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
169
+		// we need to reset the migration manager in order for it to detect DMSs properly
170
+		EE_Data_Migration_Manager::reset();
171
+		self::instance()->detect_activations_or_upgrades();
172
+		self::instance()->perform_activations_upgrades_and_migrations();
173
+		return self::instance();
174
+	}
175
+
176
+
177
+	/**
178
+	 * sets hooks for running rest of system
179
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
180
+	 * starting EE Addons from any other point may lead to problems
181
+	 *
182
+	 * @param EE_Registry         $registry
183
+	 * @param LoaderInterface     $loader
184
+	 * @param RequestInterface    $request
185
+	 * @param EE_Maintenance_Mode $maintenance_mode
186
+	 */
187
+	private function __construct(
188
+		EE_Registry $registry,
189
+		LoaderInterface $loader,
190
+		RequestInterface $request,
191
+		EE_Maintenance_Mode $maintenance_mode
192
+	) {
193
+		$this->registry = $registry;
194
+		$this->loader = $loader;
195
+		$this->request = $request;
196
+		$this->maintenance_mode = $maintenance_mode;
197
+		do_action('AHEE__EE_System__construct__begin', $this);
198
+		add_action(
199
+			'AHEE__EE_Bootstrap__load_espresso_addons',
200
+			array($this, 'loadCapabilities'),
201
+			5
202
+		);
203
+		add_action(
204
+			'AHEE__EE_Bootstrap__load_espresso_addons',
205
+			array($this, 'loadCommandBus'),
206
+			7
207
+		);
208
+		add_action(
209
+			'AHEE__EE_Bootstrap__load_espresso_addons',
210
+			array($this, 'loadPluginApi'),
211
+			9
212
+		);
213
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
214
+		add_action(
215
+			'AHEE__EE_Bootstrap__load_espresso_addons',
216
+			array($this, 'load_espresso_addons')
217
+		);
218
+		// when an ee addon is activated, we want to call the core hook(s) again
219
+		// because the newly-activated addon didn't get a chance to run at all
220
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
221
+		// detect whether install or upgrade
222
+		add_action(
223
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
224
+			array($this, 'detect_activations_or_upgrades'),
225
+			3
226
+		);
227
+		// load EE_Config, EE_Textdomain, etc
228
+		add_action(
229
+			'AHEE__EE_Bootstrap__load_core_configuration',
230
+			array($this, 'load_core_configuration'),
231
+			5
232
+		);
233
+		// load specifications for matching routes to current request
234
+		add_action(
235
+			'AHEE__EE_Bootstrap__load_core_configuration',
236
+			array($this, 'loadRouteMatchSpecifications')
237
+		);
238
+		// load EE_Config, EE_Textdomain, etc
239
+		add_action(
240
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
241
+			array($this, 'register_shortcodes_modules_and_widgets'),
242
+			7
243
+		);
244
+		// you wanna get going? I wanna get going... let's get going!
245
+		add_action(
246
+			'AHEE__EE_Bootstrap__brew_espresso',
247
+			array($this, 'brew_espresso'),
248
+			9
249
+		);
250
+		// other housekeeping
251
+		// exclude EE critical pages from wp_list_pages
252
+		add_filter(
253
+			'wp_list_pages_excludes',
254
+			array($this, 'remove_pages_from_wp_list_pages'),
255
+			10
256
+		);
257
+		// ALL EE Addons should use the following hook point to attach their initial setup too
258
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
259
+		do_action('AHEE__EE_System__construct__complete', $this);
260
+	}
261
+
262
+
263
+	/**
264
+	 * load and setup EE_Capabilities
265
+	 *
266
+	 * @return void
267
+	 */
268
+	public function loadCapabilities()
269
+	{
270
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
271
+		add_action(
272
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
273
+			function () {
274
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
275
+			}
276
+		);
277
+	}
278
+
279
+
280
+	/**
281
+	 * create and cache the CommandBus, and also add middleware
282
+	 * The CapChecker middleware requires the use of EE_Capabilities
283
+	 * which is why we need to load the CommandBus after Caps are set up
284
+	 *
285
+	 * @return void
286
+	 */
287
+	public function loadCommandBus()
288
+	{
289
+		$this->loader->getShared(
290
+			'CommandBusInterface',
291
+			array(
292
+				null,
293
+				apply_filters(
294
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
295
+					array(
296
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
297
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
298
+					)
299
+				),
300
+			)
301
+		);
302
+	}
303
+
304
+
305
+	/**
306
+	 * @return void
307
+	 * @throws EE_Error
308
+	 */
309
+	public function loadPluginApi()
310
+	{
311
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
312
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
313
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
314
+		$this->loader->getShared('EE_Request_Handler');
315
+	}
316
+
317
+
318
+	/**
319
+	 * @param string $addon_name
320
+	 * @param string $version_constant
321
+	 * @param string $min_version_required
322
+	 * @param string $load_callback
323
+	 * @param string $plugin_file_constant
324
+	 * @return void
325
+	 */
326
+	private function deactivateIncompatibleAddon(
327
+		$addon_name,
328
+		$version_constant,
329
+		$min_version_required,
330
+		$load_callback,
331
+		$plugin_file_constant
332
+	) {
333
+		if (! defined($version_constant)) {
334
+			return;
335
+		}
336
+		$addon_version = constant($version_constant);
337
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
338
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
339
+			if (! function_exists('deactivate_plugins')) {
340
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
341
+			}
342
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
343
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
344
+			EE_Error::add_error(
345
+				sprintf(
346
+					esc_html__(
347
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
348
+						'event_espresso'
349
+					),
350
+					$addon_name,
351
+					$min_version_required
352
+				),
353
+				__FILE__,
354
+				__FUNCTION__ . "({$addon_name})",
355
+				__LINE__
356
+			);
357
+			EE_Error::get_notices(false, true);
358
+		}
359
+	}
360
+
361
+
362
+	/**
363
+	 * load_espresso_addons
364
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
365
+	 * this is hooked into both:
366
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
367
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
368
+	 *    and the WP 'activate_plugin' hook point
369
+	 *
370
+	 * @access public
371
+	 * @return void
372
+	 */
373
+	public function load_espresso_addons()
374
+	{
375
+		$this->deactivateIncompatibleAddon(
376
+			'Wait Lists',
377
+			'EE_WAIT_LISTS_VERSION',
378
+			'1.0.0.beta.074',
379
+			'load_espresso_wait_lists',
380
+			'EE_WAIT_LISTS_PLUGIN_FILE'
381
+		);
382
+		$this->deactivateIncompatibleAddon(
383
+			'Automated Upcoming Event Notifications',
384
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
385
+			'1.0.0.beta.091',
386
+			'load_espresso_automated_upcoming_event_notification',
387
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
388
+		);
389
+		do_action('AHEE__EE_System__load_espresso_addons');
390
+		// if the WP API basic auth plugin isn't already loaded, load it now.
391
+		// We want it for mobile apps. Just include the entire plugin
392
+		// also, don't load the basic auth when a plugin is getting activated, because
393
+		// it could be the basic auth plugin, and it doesn't check if its methods are already defined
394
+		// and causes a fatal error
395
+		if (($this->request->isWordPressApi() || $this->request->isApi())
396
+			&& $this->request->getRequestParam('activate') !== 'true'
397
+			&& ! function_exists('json_basic_auth_handler')
398
+			&& ! function_exists('json_basic_auth_error')
399
+			&& ! in_array(
400
+				$this->request->getRequestParam('action'),
401
+				array('activate', 'activate-selected'),
402
+				true
403
+			)
404
+		) {
405
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
406
+		}
407
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
408
+	}
409
+
410
+
411
+	/**
412
+	 * detect_activations_or_upgrades
413
+	 * Checks for activation or upgrade of core first;
414
+	 * then also checks if any registered addons have been activated or upgraded
415
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
416
+	 * which runs during the WP 'plugins_loaded' action at priority 3
417
+	 *
418
+	 * @access public
419
+	 * @return void
420
+	 */
421
+	public function detect_activations_or_upgrades()
422
+	{
423
+		// first off: let's make sure to handle core
424
+		$this->detect_if_activation_or_upgrade();
425
+		foreach ($this->registry->addons as $addon) {
426
+			if ($addon instanceof EE_Addon) {
427
+				// detect teh request type for that addon
428
+				$addon->detect_activation_or_upgrade();
429
+			}
430
+		}
431
+	}
432
+
433
+
434
+	/**
435
+	 * detect_if_activation_or_upgrade
436
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
437
+	 * and either setting up the DB or setting up maintenance mode etc.
438
+	 *
439
+	 * @access public
440
+	 * @return void
441
+	 */
442
+	public function detect_if_activation_or_upgrade()
443
+	{
444
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
445
+		// check if db has been updated, or if its a brand-new installation
446
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
447
+		$request_type = $this->detect_req_type($espresso_db_update);
448
+		// EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
449
+		switch ($request_type) {
450
+			case EE_System::req_type_new_activation:
451
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
452
+				$this->_handle_core_version_change($espresso_db_update);
453
+				break;
454
+			case EE_System::req_type_reactivation:
455
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
456
+				$this->_handle_core_version_change($espresso_db_update);
457
+				break;
458
+			case EE_System::req_type_upgrade:
459
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
460
+				// migrations may be required now that we've upgraded
461
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
462
+				$this->_handle_core_version_change($espresso_db_update);
463
+				break;
464
+			case EE_System::req_type_downgrade:
465
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
466
+				// its possible migrations are no longer required
467
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
468
+				$this->_handle_core_version_change($espresso_db_update);
469
+				break;
470
+			case EE_System::req_type_normal:
471
+			default:
472
+				break;
473
+		}
474
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
475
+	}
476
+
477
+
478
+	/**
479
+	 * Updates the list of installed versions and sets hooks for
480
+	 * initializing the database later during the request
481
+	 *
482
+	 * @param array $espresso_db_update
483
+	 */
484
+	private function _handle_core_version_change($espresso_db_update)
485
+	{
486
+		$this->update_list_of_installed_versions($espresso_db_update);
487
+		// get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
488
+		add_action(
489
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
490
+			array($this, 'initialize_db_if_no_migrations_required')
491
+		);
492
+	}
493
+
494
+
495
+	/**
496
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
497
+	 * information about what versions of EE have been installed and activated,
498
+	 * NOT necessarily the state of the database
499
+	 *
500
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
501
+	 *                                            If not supplied, fetches it from the options table
502
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
503
+	 */
504
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
505
+	{
506
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
507
+		if (! $espresso_db_update) {
508
+			$espresso_db_update = get_option('espresso_db_update');
509
+		}
510
+		// check that option is an array
511
+		if (! is_array($espresso_db_update)) {
512
+			// if option is FALSE, then it never existed
513
+			if ($espresso_db_update === false) {
514
+				// make $espresso_db_update an array and save option with autoload OFF
515
+				$espresso_db_update = array();
516
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
517
+			} else {
518
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
519
+				$espresso_db_update = array($espresso_db_update => array());
520
+				update_option('espresso_db_update', $espresso_db_update);
521
+			}
522
+		} else {
523
+			$corrected_db_update = array();
524
+			// if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
525
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
526
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
527
+					// the key is an int, and the value IS NOT an array
528
+					// so it must be numerically-indexed, where values are versions installed...
529
+					// fix it!
530
+					$version_string = $should_be_array;
531
+					$corrected_db_update[ $version_string ] = array('unknown-date');
532
+				} else {
533
+					// ok it checks out
534
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
535
+				}
536
+			}
537
+			$espresso_db_update = $corrected_db_update;
538
+			update_option('espresso_db_update', $espresso_db_update);
539
+		}
540
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
541
+		return $espresso_db_update;
542
+	}
543
+
544
+
545
+	/**
546
+	 * Does the traditional work of setting up the plugin's database and adding default data.
547
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
548
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
549
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
550
+	 * so that it will be done when migrations are finished
551
+	 *
552
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
553
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
554
+	 *                                       This is a resource-intensive job
555
+	 *                                       so we prefer to only do it when necessary
556
+	 * @return void
557
+	 * @throws EE_Error
558
+	 */
559
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
560
+	{
561
+		$request_type = $this->detect_req_type();
562
+		// only initialize system if we're not in maintenance mode.
563
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
564
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
565
+			$rewrite_rules = $this->loader->getShared(
566
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
567
+			);
568
+			$rewrite_rules->flush();
569
+			if ($verify_schema) {
570
+				EEH_Activation::initialize_db_and_folders();
571
+			}
572
+			EEH_Activation::initialize_db_content();
573
+			EEH_Activation::system_initialization();
574
+			if ($initialize_addons_too) {
575
+				$this->initialize_addons();
576
+			}
577
+		} else {
578
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
579
+		}
580
+		if ($request_type === EE_System::req_type_new_activation
581
+			|| $request_type === EE_System::req_type_reactivation
582
+			|| (
583
+				$request_type === EE_System::req_type_upgrade
584
+				&& $this->is_major_version_change()
585
+			)
586
+		) {
587
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
588
+		}
589
+	}
590
+
591
+
592
+	/**
593
+	 * Initializes the db for all registered addons
594
+	 *
595
+	 * @throws EE_Error
596
+	 */
597
+	public function initialize_addons()
598
+	{
599
+		// foreach registered addon, make sure its db is up-to-date too
600
+		foreach ($this->registry->addons as $addon) {
601
+			if ($addon instanceof EE_Addon) {
602
+				$addon->initialize_db_if_no_migrations_required();
603
+			}
604
+		}
605
+	}
606
+
607
+
608
+	/**
609
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
610
+	 *
611
+	 * @param    array  $version_history
612
+	 * @param    string $current_version_to_add version to be added to the version history
613
+	 * @return    boolean success as to whether or not this option was changed
614
+	 */
615
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
616
+	{
617
+		if (! $version_history) {
618
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
619
+		}
620
+		if ($current_version_to_add === null) {
621
+			$current_version_to_add = espresso_version();
622
+		}
623
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
624
+		// re-save
625
+		return update_option('espresso_db_update', $version_history);
626
+	}
627
+
628
+
629
+	/**
630
+	 * Detects if the current version indicated in the has existed in the list of
631
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
632
+	 *
633
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
634
+	 *                                  If not supplied, fetches it from the options table.
635
+	 *                                  Also, caches its result so later parts of the code can also know whether
636
+	 *                                  there's been an update or not. This way we can add the current version to
637
+	 *                                  espresso_db_update, but still know if this is a new install or not
638
+	 * @return int one of the constants on EE_System::req_type_
639
+	 */
640
+	public function detect_req_type($espresso_db_update = null)
641
+	{
642
+		if ($this->_req_type === null) {
643
+			$espresso_db_update = ! empty($espresso_db_update)
644
+				? $espresso_db_update
645
+				: $this->fix_espresso_db_upgrade_option();
646
+			$this->_req_type = EE_System::detect_req_type_given_activation_history(
647
+				$espresso_db_update,
648
+				'ee_espresso_activation',
649
+				espresso_version()
650
+			);
651
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
652
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
653
+		}
654
+		return $this->_req_type;
655
+	}
656
+
657
+
658
+	/**
659
+	 * Returns whether or not there was a non-micro version change (ie, change in either
660
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
661
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
662
+	 *
663
+	 * @param $activation_history
664
+	 * @return bool
665
+	 */
666
+	private function _detect_major_version_change($activation_history)
667
+	{
668
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
669
+		$previous_version_parts = explode('.', $previous_version);
670
+		$current_version_parts = explode('.', espresso_version());
671
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
672
+			   && (
673
+				   $previous_version_parts[0] !== $current_version_parts[0]
674
+				   || $previous_version_parts[1] !== $current_version_parts[1]
675
+			   );
676
+	}
677
+
678
+
679
+	/**
680
+	 * Returns true if either the major or minor version of EE changed during this request.
681
+	 * 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
682
+	 *
683
+	 * @return bool
684
+	 */
685
+	public function is_major_version_change()
686
+	{
687
+		return $this->_major_version_change;
688
+	}
689
+
690
+
691
+	/**
692
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
693
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
694
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
695
+	 * just activated to (for core that will always be espresso_version())
696
+	 *
697
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
698
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
699
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
700
+	 *                                                 indicate that this plugin was just activated
701
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
702
+	 *                                                 espresso_version())
703
+	 * @return int one of the constants on EE_System::req_type_*
704
+	 */
705
+	public static function detect_req_type_given_activation_history(
706
+		$activation_history_for_addon,
707
+		$activation_indicator_option_name,
708
+		$version_to_upgrade_to
709
+	) {
710
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
711
+		if ($activation_history_for_addon) {
712
+			// it exists, so this isn't a completely new install
713
+			// check if this version already in that list of previously installed versions
714
+			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
715
+				// it a version we haven't seen before
716
+				if ($version_is_higher === 1) {
717
+					$req_type = EE_System::req_type_upgrade;
718
+				} else {
719
+					$req_type = EE_System::req_type_downgrade;
720
+				}
721
+				delete_option($activation_indicator_option_name);
722
+			} else {
723
+				// its not an update. maybe a reactivation?
724
+				if (get_option($activation_indicator_option_name, false)) {
725
+					if ($version_is_higher === -1) {
726
+						$req_type = EE_System::req_type_downgrade;
727
+					} elseif ($version_is_higher === 0) {
728
+						// we've seen this version before, but it's an activation. must be a reactivation
729
+						$req_type = EE_System::req_type_reactivation;
730
+					} else {// $version_is_higher === 1
731
+						$req_type = EE_System::req_type_upgrade;
732
+					}
733
+					delete_option($activation_indicator_option_name);
734
+				} else {
735
+					// we've seen this version before and the activation indicate doesn't show it was just activated
736
+					if ($version_is_higher === -1) {
737
+						$req_type = EE_System::req_type_downgrade;
738
+					} elseif ($version_is_higher === 0) {
739
+						// we've seen this version before and it's not an activation. its normal request
740
+						$req_type = EE_System::req_type_normal;
741
+					} else {// $version_is_higher === 1
742
+						$req_type = EE_System::req_type_upgrade;
743
+					}
744
+				}
745
+			}
746
+		} else {
747
+			// brand new install
748
+			$req_type = EE_System::req_type_new_activation;
749
+			delete_option($activation_indicator_option_name);
750
+		}
751
+		return $req_type;
752
+	}
753
+
754
+
755
+	/**
756
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
757
+	 * the $activation_history_for_addon
758
+	 *
759
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
760
+	 *                                             sometimes containing 'unknown-date'
761
+	 * @param string $version_to_upgrade_to        (current version)
762
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
763
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
764
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
765
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
766
+	 */
767
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
768
+	{
769
+		// find the most recently-activated version
770
+		$most_recently_active_version =
771
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
772
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
773
+	}
774
+
775
+
776
+	/**
777
+	 * Gets the most recently active version listed in the activation history,
778
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
779
+	 *
780
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
781
+	 *                                   sometimes containing 'unknown-date'
782
+	 * @return string
783
+	 */
784
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
785
+	{
786
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
787
+		$most_recently_active_version = '0.0.0.dev.000';
788
+		if (is_array($activation_history)) {
789
+			foreach ($activation_history as $version => $times_activated) {
790
+				// check there is a record of when this version was activated. Otherwise,
791
+				// mark it as unknown
792
+				if (! $times_activated) {
793
+					$times_activated = array('unknown-date');
794
+				}
795
+				if (is_string($times_activated)) {
796
+					$times_activated = array($times_activated);
797
+				}
798
+				foreach ($times_activated as $an_activation) {
799
+					if ($an_activation !== 'unknown-date'
800
+						&& $an_activation
801
+						   > $most_recently_active_version_activation) {
802
+						$most_recently_active_version = $version;
803
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
804
+							? '1970-01-01 00:00:00'
805
+							: $an_activation;
806
+					}
807
+				}
808
+			}
809
+		}
810
+		return $most_recently_active_version;
811
+	}
812
+
813
+
814
+	/**
815
+	 * This redirects to the about EE page after activation
816
+	 *
817
+	 * @return void
818
+	 */
819
+	public function redirect_to_about_ee()
820
+	{
821
+		$notices = EE_Error::get_notices(false);
822
+		// if current user is an admin and it's not an ajax or rest request
823
+		if (! isset($notices['errors'])
824
+			&& $this->request->isAdmin()
825
+			&& apply_filters(
826
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
827
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
828
+			)
829
+		) {
830
+			$query_params = array('page' => 'espresso_about');
831
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
832
+				$query_params['new_activation'] = true;
833
+			}
834
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
835
+				$query_params['reactivation'] = true;
836
+			}
837
+			$url = add_query_arg($query_params, admin_url('admin.php'));
838
+			wp_safe_redirect($url);
839
+			exit();
840
+		}
841
+	}
842
+
843
+
844
+	/**
845
+	 * load_core_configuration
846
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
847
+	 * which runs during the WP 'plugins_loaded' action at priority 5
848
+	 *
849
+	 * @return void
850
+	 * @throws ReflectionException
851
+	 * @throws Exception
852
+	 */
853
+	public function load_core_configuration()
854
+	{
855
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
856
+		$this->loader->getShared('EE_Load_Textdomain');
857
+		// load textdomain
858
+		EE_Load_Textdomain::load_textdomain();
859
+		// load caf stuff a chance to play during the activation process too.
860
+		$this->_maybe_brew_regular();
861
+		// load and setup EE_Config and EE_Network_Config
862
+		$config = $this->loader->getShared('EE_Config');
863
+		$this->loader->getShared('EE_Network_Config');
864
+		// setup autoloaders
865
+		// enable logging?
866
+		if ($config->admin->use_remote_logging) {
867
+			$this->loader->getShared('EE_Log');
868
+		}
869
+		// check for activation errors
870
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
871
+		if ($activation_errors) {
872
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
873
+			update_option('ee_plugin_activation_errors', false);
874
+		}
875
+		// get model names
876
+		$this->_parse_model_names();
877
+		// configure custom post type definitions
878
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
879
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
880
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
881
+	}
882
+
883
+
884
+	/**
885
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
886
+	 *
887
+	 * @return void
888
+	 * @throws ReflectionException
889
+	 */
890
+	private function _parse_model_names()
891
+	{
892
+		// get all the files in the EE_MODELS folder that end in .model.php
893
+		$models = glob(EE_MODELS . '*.model.php');
894
+		$model_names = array();
895
+		$non_abstract_db_models = array();
896
+		foreach ($models as $model) {
897
+			// get model classname
898
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
899
+			$short_name = str_replace('EEM_', '', $classname);
900
+			$reflectionClass = new ReflectionClass($classname);
901
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
902
+				$non_abstract_db_models[ $short_name ] = $classname;
903
+			}
904
+			$model_names[ $short_name ] = $classname;
905
+		}
906
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
907
+		$this->registry->non_abstract_db_models = apply_filters(
908
+			'FHEE__EE_System__parse_implemented_model_names',
909
+			$non_abstract_db_models
910
+		);
911
+	}
912
+
913
+
914
+	/**
915
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
916
+	 * that need to be setup before our EE_System launches.
917
+	 *
918
+	 * @return void
919
+	 * @throws DomainException
920
+	 * @throws InvalidArgumentException
921
+	 * @throws InvalidDataTypeException
922
+	 * @throws InvalidInterfaceException
923
+	 * @throws InvalidClassException
924
+	 * @throws InvalidFilePathException
925
+	 */
926
+	private function _maybe_brew_regular()
927
+	{
928
+		/** @var Domain $domain */
929
+		$domain = DomainFactory::getShared(
930
+			new FullyQualifiedName(
931
+				'EventEspresso\core\domain\Domain'
932
+			),
933
+			array(
934
+				new FilePath(EVENT_ESPRESSO_MAIN_FILE),
935
+				Version::fromString(espresso_version()),
936
+			)
937
+		);
938
+		if ($domain->isCaffeinated()) {
939
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
940
+		}
941
+	}
942
+
943
+
944
+	/**
945
+	 * @since 4.9.71.p
946
+	 * @throws Exception
947
+	 */
948
+	public function loadRouteMatchSpecifications()
949
+	{
950
+		try {
951
+			$this->loader->getShared('EventEspresso\core\services\routing\RouteMatchSpecificationManager');
952
+			$this->loader->getShared('EventEspresso\core\services\routing\RouteCollection');
953
+			$this->router = $this->loader->getShared('EventEspresso\core\services\routing\RouteHandler');
954
+			// load dependencies for Routes
955
+			/** @var EventEspresso\core\domain\entities\routing\handlers\RouteHandlersDependencyMap $route_dependencies */
956
+			$route_dependencies = LocalDependencyMapFactory::create(
957
+				'EventEspresso\core\domain\entities\routing\handlers\RouteHandlersDependencyMap'
958
+			);
959
+			$route_dependencies->register();
960
+		} catch (Exception $exception) {
961
+			new ExceptionStackTraceDisplay($exception);
962
+		}
963
+		do_action('AHEE__EE_System__loadRouteMatchSpecifications');
964
+	}
965
+
966
+
967
+	/**
968
+	 * register_shortcodes_modules_and_widgets
969
+	 * generate lists of shortcodes and modules, then verify paths and classes
970
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
971
+	 * which runs during the WP 'plugins_loaded' action at priority 7
972
+	 *
973
+	 * @access public
974
+	 * @return void
975
+	 * @throws Exception
976
+	 */
977
+	public function register_shortcodes_modules_and_widgets()
978
+	{
979
+		$this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\frontend\ShortcodeRequests');
980
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
981
+		// check for addons using old hook point
982
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
983
+			$this->_incompatible_addon_error();
984
+		}
985
+	}
986
+
987
+
988
+	/**
989
+	 * _incompatible_addon_error
990
+	 *
991
+	 * @access public
992
+	 * @return void
993
+	 */
994
+	private function _incompatible_addon_error()
995
+	{
996
+		// get array of classes hooking into here
997
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
998
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
999
+		);
1000
+		if (! empty($class_names)) {
1001
+			$msg = __(
1002
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1003
+				'event_espresso'
1004
+			);
1005
+			$msg .= '<ul>';
1006
+			foreach ($class_names as $class_name) {
1007
+				$msg .= '<li><b>Event Espresso - '
1008
+						. str_replace(
1009
+							array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'),
1010
+							'',
1011
+							$class_name
1012
+						) . '</b></li>';
1013
+			}
1014
+			$msg .= '</ul>';
1015
+			$msg .= __(
1016
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1017
+				'event_espresso'
1018
+			);
1019
+			// save list of incompatible addons to wp-options for later use
1020
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
1021
+			if (is_admin()) {
1022
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1023
+			}
1024
+		}
1025
+	}
1026
+
1027
+
1028
+	/**
1029
+	 * brew_espresso
1030
+	 * begins the process of setting hooks for initializing EE in the correct order
1031
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1032
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1033
+	 *
1034
+	 * @return void
1035
+	 * @throws Exception
1036
+	 */
1037
+	public function brew_espresso()
1038
+	{
1039
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1040
+		// load some final core systems
1041
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1042
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1043
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1044
+		add_action('init', array($this, 'load_controllers'), 7);
1045
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1046
+		add_action('init', array($this, 'initialize'), 10);
1047
+		add_action('init', array($this, 'initialize_last'), 100);
1048
+		$this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\shared\GQLRequests');
1049
+		$this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\admin\PueRequests');
1050
+		$this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\shared\RestApiRequests');
1051
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1052
+	}
1053
+
1054
+
1055
+	/**
1056
+	 *    set_hooks_for_core
1057
+	 *
1058
+	 * @access public
1059
+	 * @return    void
1060
+	 * @throws EE_Error
1061
+	 */
1062
+	public function set_hooks_for_core()
1063
+	{
1064
+		$this->_deactivate_incompatible_addons();
1065
+		do_action('AHEE__EE_System__set_hooks_for_core');
1066
+		$this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1067
+		// caps need to be initialized on every request so that capability maps are set.
1068
+		// @see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1069
+		$this->registry->CAP->init_caps();
1070
+	}
1071
+
1072
+
1073
+	/**
1074
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1075
+	 * deactivates any addons considered incompatible with the current version of EE
1076
+	 */
1077
+	private function _deactivate_incompatible_addons()
1078
+	{
1079
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1080
+		if (! empty($incompatible_addons)) {
1081
+			$active_plugins = get_option('active_plugins', array());
1082
+			foreach ($active_plugins as $active_plugin) {
1083
+				foreach ($incompatible_addons as $incompatible_addon) {
1084
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1085
+						unset($_GET['activate']);
1086
+						espresso_deactivate_plugin($active_plugin);
1087
+					}
1088
+				}
1089
+			}
1090
+		}
1091
+	}
1092
+
1093
+
1094
+	/**
1095
+	 *    perform_activations_upgrades_and_migrations
1096
+	 *
1097
+	 * @access public
1098
+	 * @return    void
1099
+	 */
1100
+	public function perform_activations_upgrades_and_migrations()
1101
+	{
1102
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1103
+	}
1104
+
1105
+
1106
+	/**
1107
+	 * @return void
1108
+	 * @throws DomainException
1109
+	 */
1110
+	public function load_CPTs_and_session()
1111
+	{
1112
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1113
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */
1114
+		$register_custom_taxonomies = $this->loader->getShared(
1115
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
1116
+		);
1117
+		$register_custom_taxonomies->registerCustomTaxonomies();
1118
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
1119
+		$register_custom_post_types = $this->loader->getShared(
1120
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
1121
+		);
1122
+		$register_custom_post_types->registerCustomPostTypes();
1123
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */
1124
+		$register_custom_taxonomy_terms = $this->loader->getShared(
1125
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
1126
+		);
1127
+		$register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1128
+		// load legacy Custom Post Types and Taxonomies
1129
+		$this->loader->getShared('EE_Register_CPTs');
1130
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1131
+	}
1132
+
1133
+
1134
+	/**
1135
+	 * load_controllers
1136
+	 * this is the best place to load any additional controllers that needs access to EE core.
1137
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1138
+	 * time
1139
+	 *
1140
+	 * @access public
1141
+	 * @return void
1142
+	 * @throws Exception
1143
+	 */
1144
+	public function load_controllers()
1145
+	{
1146
+		do_action('AHEE__EE_System__load_controllers__start');
1147
+		// now start loading routes
1148
+		$this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\frontend\FrontendRequests');
1149
+		$this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\admin\EspressoLegacyAdmin');
1150
+		$this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventEditor');
1151
+		$this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage');
1152
+		$this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\shared\WordPressHeartbeat');
1153
+		do_action('AHEE__EE_System__load_controllers__complete');
1154
+	}
1155
+
1156
+
1157
+	/**
1158
+	 * core_loaded_and_ready
1159
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1160
+	 *
1161
+	 * @access public
1162
+	 * @return void
1163
+	 * @throws Exception
1164
+	 */
1165
+	public function core_loaded_and_ready()
1166
+	{
1167
+		$this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\shared\AssetRequests');
1168
+		$this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\shared\SessionRequests');
1169
+		// integrate WP_Query with the EE models
1170
+		$this->loader->getShared('EE_CPT_Strategy');
1171
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1172
+		// always load template tags, because it's faster than checking if it's a front-end request, and many page
1173
+		// builders require these even on the front-end
1174
+		require_once EE_PUBLIC . 'template_tags.php';
1175
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1176
+	}
1177
+
1178
+
1179
+	/**
1180
+	 * initialize
1181
+	 * this is the best place to begin initializing client code
1182
+	 *
1183
+	 * @access public
1184
+	 * @return void
1185
+	 */
1186
+	public function initialize()
1187
+	{
1188
+		do_action('AHEE__EE_System__initialize');
1189
+	}
1190
+
1191
+
1192
+	/**
1193
+	 * initialize_last
1194
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1195
+	 * initialize has done so
1196
+	 *
1197
+	 * @access public
1198
+	 * @return void
1199
+	 * @throws Exception
1200
+	 */
1201
+	public function initialize_last()
1202
+	{
1203
+		do_action('AHEE__EE_System__initialize_last');
1204
+		/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1205
+		$rewrite_rules = $this->loader->getShared(
1206
+			'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1207
+		);
1208
+		$rewrite_rules->flushRewriteRules();
1209
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1210
+		$this->router->addRoute('EventEspresso\core\domain\entities\routing\handlers\admin\PersonalDataRequests');
1211
+	}
1212
+
1213
+
1214
+	/**
1215
+	 * @return void
1216
+	 */
1217
+	public function addEspressoToolbar()
1218
+	{
1219
+		$this->loader->getShared(
1220
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1221
+			array($this->registry->CAP)
1222
+		);
1223
+	}
1224
+
1225
+
1226
+	/**
1227
+	 * do_not_cache
1228
+	 * sets no cache headers and defines no cache constants for WP plugins
1229
+	 *
1230
+	 * @access public
1231
+	 * @return void
1232
+	 */
1233
+	public static function do_not_cache()
1234
+	{
1235
+		// set no cache constants
1236
+		if (! defined('DONOTCACHEPAGE')) {
1237
+			define('DONOTCACHEPAGE', true);
1238
+		}
1239
+		if (! defined('DONOTCACHCEOBJECT')) {
1240
+			define('DONOTCACHCEOBJECT', true);
1241
+		}
1242
+		if (! defined('DONOTCACHEDB')) {
1243
+			define('DONOTCACHEDB', true);
1244
+		}
1245
+		// add no cache headers
1246
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1247
+		// plus a little extra for nginx and Google Chrome
1248
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1249
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1250
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1251
+	}
1252
+
1253
+
1254
+	/**
1255
+	 *    extra_nocache_headers
1256
+	 *
1257
+	 * @access    public
1258
+	 * @param $headers
1259
+	 * @return    array
1260
+	 */
1261
+	public static function extra_nocache_headers($headers)
1262
+	{
1263
+		// for NGINX
1264
+		$headers['X-Accel-Expires'] = 0;
1265
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1266
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1267
+		return $headers;
1268
+	}
1269
+
1270
+
1271
+	/**
1272
+	 *    nocache_headers
1273
+	 *
1274
+	 * @access    public
1275
+	 * @return    void
1276
+	 */
1277
+	public static function nocache_headers()
1278
+	{
1279
+		nocache_headers();
1280
+	}
1281
+
1282
+
1283
+	/**
1284
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1285
+	 * never returned with the function.
1286
+	 *
1287
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1288
+	 * @return array
1289
+	 */
1290
+	public function remove_pages_from_wp_list_pages($exclude_array)
1291
+	{
1292
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1293
+	}
1294 1294
 }
Please login to merge, or discard this patch.
core/services/routing/RouteMatchSpecificationDependencyResolver.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -21,18 +21,18 @@
 block discarded – undo
21 21
 class RouteMatchSpecificationDependencyResolver extends DependencyResolver
22 22
 {
23 23
 
24
-    /**
25
-     * Used to configure and/or setup any aliases or namespace roots required by the DependencyResolver
26
-     *
27
-     * @since 4.9.71.p
28
-     * @throws InvalidAliasException
29
-     */
30
-    public function initialize()
31
-    {
32
-        $this->addAlias(
33
-            'EventEspresso\core\services\request\Request',
34
-            'EventEspresso\core\services\request\RequestInterface'
35
-        );
36
-        $this->addNamespaceRoot('EventEspresso\core\domain\entities\routing\specifications');
37
-    }
24
+	/**
25
+	 * Used to configure and/or setup any aliases or namespace roots required by the DependencyResolver
26
+	 *
27
+	 * @since 4.9.71.p
28
+	 * @throws InvalidAliasException
29
+	 */
30
+	public function initialize()
31
+	{
32
+		$this->addAlias(
33
+			'EventEspresso\core\services\request\Request',
34
+			'EventEspresso\core\services\request\RequestInterface'
35
+		);
36
+		$this->addNamespaceRoot('EventEspresso\core\domain\entities\routing\specifications');
37
+	}
38 38
 }
Please login to merge, or discard this patch.
core/services/routing/RouteMatchSpecificationFactory.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -20,41 +20,41 @@
 block discarded – undo
20 20
 class RouteMatchSpecificationFactory extends FactoryWithDependencyResolver
21 21
 {
22 22
 
23
-    /**
24
-     * RouteMatchSpecificationFactory constructor
25
-     *
26
-     * @param RouteMatchSpecificationDependencyResolver $dependency_resolver
27
-     * @param LoaderInterface                           $loader
28
-     */
29
-    public function __construct(RouteMatchSpecificationDependencyResolver $dependency_resolver, LoaderInterface $loader)
30
-    {
31
-        parent::__construct($dependency_resolver, $loader);
32
-    }
33
-
34
-
35
-    /**
36
-     * @param $fqcn
37
-     * @return RouteMatchSpecification
38
-     * @since 4.9.71.p
39
-     */
40
-    public function createNewRouteMatchSpecification($fqcn)
41
-    {
42
-        $this->dependencyResolver()->resolveDependenciesForClass($fqcn);
43
-        return $this->loader()->getShared($fqcn);
44
-    }
45
-
46
-
47
-    /**
48
-     * @param $fqcn
49
-     * @return RouteMatchSpecification
50
-     * @since 4.9.71.p
51
-     */
52
-    public static function create($fqcn)
53
-    {
54
-        /** @var RouteMatchSpecificationFactory $specification_factory */
55
-        $specification_factory = LoaderFactory::getLoader()->getShared(
56
-            'EventEspresso\core\services\routing\RouteMatchSpecificationFactory'
57
-        );
58
-        return $specification_factory->createNewRouteMatchSpecification($fqcn);
59
-    }
23
+	/**
24
+	 * RouteMatchSpecificationFactory constructor
25
+	 *
26
+	 * @param RouteMatchSpecificationDependencyResolver $dependency_resolver
27
+	 * @param LoaderInterface                           $loader
28
+	 */
29
+	public function __construct(RouteMatchSpecificationDependencyResolver $dependency_resolver, LoaderInterface $loader)
30
+	{
31
+		parent::__construct($dependency_resolver, $loader);
32
+	}
33
+
34
+
35
+	/**
36
+	 * @param $fqcn
37
+	 * @return RouteMatchSpecification
38
+	 * @since 4.9.71.p
39
+	 */
40
+	public function createNewRouteMatchSpecification($fqcn)
41
+	{
42
+		$this->dependencyResolver()->resolveDependenciesForClass($fqcn);
43
+		return $this->loader()->getShared($fqcn);
44
+	}
45
+
46
+
47
+	/**
48
+	 * @param $fqcn
49
+	 * @return RouteMatchSpecification
50
+	 * @since 4.9.71.p
51
+	 */
52
+	public static function create($fqcn)
53
+	{
54
+		/** @var RouteMatchSpecificationFactory $specification_factory */
55
+		$specification_factory = LoaderFactory::getLoader()->getShared(
56
+			'EventEspresso\core\services\routing\RouteMatchSpecificationFactory'
57
+		);
58
+		return $specification_factory->createNewRouteMatchSpecification($fqcn);
59
+	}
60 60
 }
Please login to merge, or discard this patch.
core/services/routing/RouteCollection.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -17,75 +17,75 @@
 block discarded – undo
17 17
 class RouteCollection extends Collection
18 18
 {
19 19
 
20
-    const COLLECTION_NAME = 'routes';
20
+	const COLLECTION_NAME = 'routes';
21 21
 
22
-    /**
23
-     * RouteMatchSpecificationCollection constructor
24
-     *
25
-     * @throws InvalidInterfaceException
26
-     */
27
-    public function __construct()
28
-    {
29
-        parent::__construct(
30
-            'EventEspresso\core\domain\entities\routing\handlers\RouteInterface',
31
-            RouteCollection::COLLECTION_NAME
32
-        );
33
-    }
22
+	/**
23
+	 * RouteMatchSpecificationCollection constructor
24
+	 *
25
+	 * @throws InvalidInterfaceException
26
+	 */
27
+	public function __construct()
28
+	{
29
+		parent::__construct(
30
+			'EventEspresso\core\domain\entities\routing\handlers\RouteInterface',
31
+			RouteCollection::COLLECTION_NAME
32
+		);
33
+	}
34 34
 
35 35
 
36
-    /**
37
-     * getIdentifier
38
-     * Overrides EventEspresso\core\services\collections\Collection::getIdentifier()
39
-     * If no $identifier is supplied, then the  fully qualified class name is used
40
-     *
41
-     * @param        $object
42
-     * @param  mixed $identifier
43
-     * @return bool
44
-     */
45
-    public function getIdentifier($object, $identifier = null)
46
-    {
47
-        return ! empty($identifier)
48
-            ? $identifier
49
-            : get_class($object);
50
-    }
36
+	/**
37
+	 * getIdentifier
38
+	 * Overrides EventEspresso\core\services\collections\Collection::getIdentifier()
39
+	 * If no $identifier is supplied, then the  fully qualified class name is used
40
+	 *
41
+	 * @param        $object
42
+	 * @param  mixed $identifier
43
+	 * @return bool
44
+	 */
45
+	public function getIdentifier($object, $identifier = null)
46
+	{
47
+		return ! empty($identifier)
48
+			? $identifier
49
+			: get_class($object);
50
+	}
51 51
 
52 52
 
53
-    /**
54
-     * finds and returns all Routes that have yet to be handled
55
-     *
56
-     * @return RouteInterface[]
57
-     */
58
-    public function getRoutesForCurrentRequest()
59
-    {
60
-        $routes = [];
61
-        $this->rewind();
62
-        while ($this->valid()) {
63
-            /** @var RouteInterface $route */
64
-            $route = $this->current();
65
-            if ($route->matchesCurrentRequest()) {
66
-                $routes[] = $route;
67
-            }
68
-            $this->next();
69
-        }
70
-        $this->rewind();
71
-        return $routes;
72
-    }
53
+	/**
54
+	 * finds and returns all Routes that have yet to be handled
55
+	 *
56
+	 * @return RouteInterface[]
57
+	 */
58
+	public function getRoutesForCurrentRequest()
59
+	{
60
+		$routes = [];
61
+		$this->rewind();
62
+		while ($this->valid()) {
63
+			/** @var RouteInterface $route */
64
+			$route = $this->current();
65
+			if ($route->matchesCurrentRequest()) {
66
+				$routes[] = $route;
67
+			}
68
+			$this->next();
69
+		}
70
+		$this->rewind();
71
+		return $routes;
72
+	}
73 73
 
74 74
 
75
-    /**
76
-     * calls RouteInterface::handleRequest() on all Routes that
77
-     *      - match current request
78
-     *      - have yet to be handled
79
-     *
80
-     * @return void
81
-     */
82
-    public function handleRoutesForCurrentRequest()
83
-    {
84
-        $this->rewind();
85
-        while ($this->valid()) {
86
-            $this->current()->handleRequest();
87
-            $this->next();
88
-        }
89
-        $this->rewind();
90
-    }
75
+	/**
76
+	 * calls RouteInterface::handleRequest() on all Routes that
77
+	 *      - match current request
78
+	 *      - have yet to be handled
79
+	 *
80
+	 * @return void
81
+	 */
82
+	public function handleRoutesForCurrentRequest()
83
+	{
84
+		$this->rewind();
85
+		while ($this->valid()) {
86
+			$this->current()->handleRequest();
87
+			$this->next();
88
+		}
89
+		$this->rewind();
90
+	}
91 91
 }
Please login to merge, or discard this patch.
core/services/routing/RouteMatchSpecificationManager.php 2 patches
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -24,123 +24,123 @@
 block discarded – undo
24 24
  */
25 25
 class RouteMatchSpecificationManager
26 26
 {
27
-    /**
28
-     * @var CollectionInterface|RouteMatchSpecificationInterface[] $specifications
29
-     */
30
-    private $specifications;
27
+	/**
28
+	 * @var CollectionInterface|RouteMatchSpecificationInterface[] $specifications
29
+	 */
30
+	private $specifications;
31 31
 
32
-    /**
33
-     * @var RouteMatchSpecificationFactory $specifications_factory
34
-     */
35
-    private $specifications_factory;
32
+	/**
33
+	 * @var RouteMatchSpecificationFactory $specifications_factory
34
+	 */
35
+	private $specifications_factory;
36 36
 
37 37
 
38
-    /**
39
-     * RouteMatchSpecificationManager constructor.
40
-     *
41
-     * @param RouteMatchSpecificationCollection $specifications
42
-     * @param RouteMatchSpecificationFactory    $specifications_factory
43
-     */
44
-    public function __construct(
45
-        RouteMatchSpecificationCollection $specifications,
46
-        RouteMatchSpecificationFactory $specifications_factory
47
-    ) {
48
-        $this->specifications = $specifications;
49
-        $this->specifications_factory = $specifications_factory;
50
-        add_action('AHEE__EE_System__loadRouteMatchSpecifications', array($this, 'initialize'));
51
-    }
38
+	/**
39
+	 * RouteMatchSpecificationManager constructor.
40
+	 *
41
+	 * @param RouteMatchSpecificationCollection $specifications
42
+	 * @param RouteMatchSpecificationFactory    $specifications_factory
43
+	 */
44
+	public function __construct(
45
+		RouteMatchSpecificationCollection $specifications,
46
+		RouteMatchSpecificationFactory $specifications_factory
47
+	) {
48
+		$this->specifications = $specifications;
49
+		$this->specifications_factory = $specifications_factory;
50
+		add_action('AHEE__EE_System__loadRouteMatchSpecifications', array($this, 'initialize'));
51
+	}
52 52
 
53 53
 
54
-    /**
55
-     * Perform any early setup required for block editors to functions
56
-     *
57
-     * @return void
58
-     * @throws CollectionLoaderException
59
-     * @throws CollectionDetailsException
60
-     */
61
-    public function initialize()
62
-    {
63
-        $this->populateSpecificationCollection();
64
-    }
54
+	/**
55
+	 * Perform any early setup required for block editors to functions
56
+	 *
57
+	 * @return void
58
+	 * @throws CollectionLoaderException
59
+	 * @throws CollectionDetailsException
60
+	 */
61
+	public function initialize()
62
+	{
63
+		$this->populateSpecificationCollection();
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * @return CollectionInterface|RouteMatchSpecificationInterface[]
69
-     * @throws CollectionLoaderException
70
-     * @throws CollectionDetailsException
71
-     * @since 4.9.71.p
72
-     */
73
-    private function populateSpecificationCollection()
74
-    {
75
-        $loader = new CollectionLoader(
76
-            new CollectionDetails(
77
-                // collection name
78
-                RouteMatchSpecificationCollection::COLLECTION_NAME,
79
-                // collection interface
80
-                'EventEspresso\core\domain\entities\routing\specifications\RouteMatchSpecificationInterface',
81
-                // FQCNs for classes to add (all classes within each namespace will be loaded)
82
-                apply_filters(
83
-                    'FHEE__EventEspresso_core_services_routing_RouteMatchSpecificationManager__populateSpecificationCollection__collection_FQCNs',
84
-                    array(
85
-                        'EventEspresso\core\domain\entities\routing\specifications\admin',
86
-                        'EventEspresso\core\domain\entities\routing\specifications\frontend',
87
-                        'EventEspresso\core\domain\entities\routing\specifications\shared',
88
-                    )
89
-                ),
90
-                // filepaths to classes to add
91
-                array(),
92
-                // file mask to use if parsing folder for files to add
93
-                '',
94
-                // what to use as identifier for collection entities
95
-                // using CLASS NAME prevents duplicates (works like a singleton)
96
-                CollectionDetails::ID_CLASS_NAME
97
-            ),
98
-            $this->specifications,
99
-            null,
100
-            $this->specifications_factory
101
-        );
102
-        return $loader->getCollection();
103
-    }
67
+	/**
68
+	 * @return CollectionInterface|RouteMatchSpecificationInterface[]
69
+	 * @throws CollectionLoaderException
70
+	 * @throws CollectionDetailsException
71
+	 * @since 4.9.71.p
72
+	 */
73
+	private function populateSpecificationCollection()
74
+	{
75
+		$loader = new CollectionLoader(
76
+			new CollectionDetails(
77
+				// collection name
78
+				RouteMatchSpecificationCollection::COLLECTION_NAME,
79
+				// collection interface
80
+				'EventEspresso\core\domain\entities\routing\specifications\RouteMatchSpecificationInterface',
81
+				// FQCNs for classes to add (all classes within each namespace will be loaded)
82
+				apply_filters(
83
+					'FHEE__EventEspresso_core_services_routing_RouteMatchSpecificationManager__populateSpecificationCollection__collection_FQCNs',
84
+					array(
85
+						'EventEspresso\core\domain\entities\routing\specifications\admin',
86
+						'EventEspresso\core\domain\entities\routing\specifications\frontend',
87
+						'EventEspresso\core\domain\entities\routing\specifications\shared',
88
+					)
89
+				),
90
+				// filepaths to classes to add
91
+				array(),
92
+				// file mask to use if parsing folder for files to add
93
+				'',
94
+				// what to use as identifier for collection entities
95
+				// using CLASS NAME prevents duplicates (works like a singleton)
96
+				CollectionDetails::ID_CLASS_NAME
97
+			),
98
+			$this->specifications,
99
+			null,
100
+			$this->specifications_factory
101
+		);
102
+		return $loader->getCollection();
103
+	}
104 104
 
105 105
 
106
-    /**
107
-     * Given the FQCN for a RouteMatchSpecification, will return true if the current request matches
108
-     *
109
-     * @param string $routeMatchSpecificationFqcn fully qualified class name
110
-     * @return bool
111
-     * @throws InvalidClassException
112
-     * @since 4.9.71.p
113
-     */
114
-    public function routeMatchesCurrentRequest($routeMatchSpecificationFqcn)
115
-    {
116
-        /** @var RouteMatchSpecificationInterface $specification */
117
-        $specification = $this->specifications->get($routeMatchSpecificationFqcn);
118
-        if (! $specification instanceof $routeMatchSpecificationFqcn) {
119
-            throw new InvalidClassException($routeMatchSpecificationFqcn);
120
-        }
121
-        return $specification->isMatchingRoute();
122
-    }
106
+	/**
107
+	 * Given the FQCN for a RouteMatchSpecification, will return true if the current request matches
108
+	 *
109
+	 * @param string $routeMatchSpecificationFqcn fully qualified class name
110
+	 * @return bool
111
+	 * @throws InvalidClassException
112
+	 * @since 4.9.71.p
113
+	 */
114
+	public function routeMatchesCurrentRequest($routeMatchSpecificationFqcn)
115
+	{
116
+		/** @var RouteMatchSpecificationInterface $specification */
117
+		$specification = $this->specifications->get($routeMatchSpecificationFqcn);
118
+		if (! $specification instanceof $routeMatchSpecificationFqcn) {
119
+			throw new InvalidClassException($routeMatchSpecificationFqcn);
120
+		}
121
+		return $specification->isMatchingRoute();
122
+	}
123 123
 
124 124
 
125
-    /**
126
-     * Handy method for development that returns
127
-     * a list of existing RouteMatchSpecification classes
128
-     * matching the current request that can be used to identify it.
129
-     * If no matches are returned (or nothing acceptable)
130
-     * then create a new one that better matches your requirements.
131
-     *
132
-     * @return array
133
-     * @since 4.9.71.p
134
-     */
135
-    public function findRouteMatchSpecificationsMatchingCurrentRequest()
136
-    {
137
-        $matches = array();
138
-        foreach ($this->specifications as $specification) {
139
-            /** @var RouteMatchSpecificationInterface $specification */
140
-            if ($specification->isMatchingRoute()) {
141
-                $matches[] = get_class($specification);
142
-            }
143
-        }
144
-        return $matches;
145
-    }
125
+	/**
126
+	 * Handy method for development that returns
127
+	 * a list of existing RouteMatchSpecification classes
128
+	 * matching the current request that can be used to identify it.
129
+	 * If no matches are returned (or nothing acceptable)
130
+	 * then create a new one that better matches your requirements.
131
+	 *
132
+	 * @return array
133
+	 * @since 4.9.71.p
134
+	 */
135
+	public function findRouteMatchSpecificationsMatchingCurrentRequest()
136
+	{
137
+		$matches = array();
138
+		foreach ($this->specifications as $specification) {
139
+			/** @var RouteMatchSpecificationInterface $specification */
140
+			if ($specification->isMatchingRoute()) {
141
+				$matches[] = get_class($specification);
142
+			}
143
+		}
144
+		return $matches;
145
+	}
146 146
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@
 block discarded – undo
115 115
     {
116 116
         /** @var RouteMatchSpecificationInterface $specification */
117 117
         $specification = $this->specifications->get($routeMatchSpecificationFqcn);
118
-        if (! $specification instanceof $routeMatchSpecificationFqcn) {
118
+        if ( ! $specification instanceof $routeMatchSpecificationFqcn) {
119 119
             throw new InvalidClassException($routeMatchSpecificationFqcn);
120 120
         }
121 121
         return $specification->isMatchingRoute();
Please login to merge, or discard this patch.
core/services/routing/RouteHandler.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -20,83 +20,83 @@
 block discarded – undo
20 20
 class RouteHandler
21 21
 {
22 22
 
23
-    /**
24
-     * @var LoaderInterface $loader
25
-     */
26
-    private $loader;
23
+	/**
24
+	 * @var LoaderInterface $loader
25
+	 */
26
+	private $loader;
27 27
 
28
-    /**
29
-     * @var RouteCollection $routes
30
-     */
31
-    private $routes;
28
+	/**
29
+	 * @var RouteCollection $routes
30
+	 */
31
+	private $routes;
32 32
 
33 33
 
34
-    /**
35
-     * AdminRouter constructor.
36
-     *
37
-     * @param LoaderInterface  $loader
38
-     * @param RouteCollection $routes
39
-     */
40
-    public function __construct(
41
-        LoaderInterface $loader,
42
-        RouteCollection $routes
43
-    ) {
44
-        $this->loader = $loader;
45
-        $this->routes = $routes;
46
-    }
34
+	/**
35
+	 * AdminRouter constructor.
36
+	 *
37
+	 * @param LoaderInterface  $loader
38
+	 * @param RouteCollection $routes
39
+	 */
40
+	public function __construct(
41
+		LoaderInterface $loader,
42
+		RouteCollection $routes
43
+	) {
44
+		$this->loader = $loader;
45
+		$this->routes = $routes;
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     * @param string    $fqcn  Fully Qualified Class Name for Route
51
-     * @param bool      $handle if true [default] will immediately call RouteInterface::handleRequest()
52
-     * @throws Exception
53
-     * @since $VID:$
54
-     */
55
-    public function addRoute($fqcn, $handle = true)
56
-    {
57
-        try {
58
-            $route = $this->loader->getShared($fqcn);
59
-            if (! $route instanceof RouteInterface) {
60
-                throw new InvalidClassException(
61
-                    sprintf(
62
-                        esc_html__(
63
-                            'The supplied FQCN (%1$s) must be an instance of RouteInterface.',
64
-                            'eventespresso'
65
-                        ),
66
-                        $fqcn
67
-                    )
68
-                );
69
-            }
70
-            $this->routes->add($route);
71
-            if ($handle) {
72
-                $route->handleRequest();
73
-            }
74
-        } catch (Exception $exception) {
75
-            new ExceptionStackTraceDisplay($exception);
76
-        }
77
-    }
49
+	/**
50
+	 * @param string    $fqcn  Fully Qualified Class Name for Route
51
+	 * @param bool      $handle if true [default] will immediately call RouteInterface::handleRequest()
52
+	 * @throws Exception
53
+	 * @since $VID:$
54
+	 */
55
+	public function addRoute($fqcn, $handle = true)
56
+	{
57
+		try {
58
+			$route = $this->loader->getShared($fqcn);
59
+			if (! $route instanceof RouteInterface) {
60
+				throw new InvalidClassException(
61
+					sprintf(
62
+						esc_html__(
63
+							'The supplied FQCN (%1$s) must be an instance of RouteInterface.',
64
+							'eventespresso'
65
+						),
66
+						$fqcn
67
+					)
68
+				);
69
+			}
70
+			$this->routes->add($route);
71
+			if ($handle) {
72
+				$route->handleRequest();
73
+			}
74
+		} catch (Exception $exception) {
75
+			new ExceptionStackTraceDisplay($exception);
76
+		}
77
+	}
78 78
 
79 79
 
80
-    /**
81
-     * finds and returns all Routes that have yet to be handled
82
-     *
83
-     * @return RouteInterface[]
84
-     */
85
-    public function getRoutesForCurrentRequest()
86
-    {
87
-        return $this->routes->getRoutesForCurrentRequest();
88
-    }
80
+	/**
81
+	 * finds and returns all Routes that have yet to be handled
82
+	 *
83
+	 * @return RouteInterface[]
84
+	 */
85
+	public function getRoutesForCurrentRequest()
86
+	{
87
+		return $this->routes->getRoutesForCurrentRequest();
88
+	}
89 89
 
90 90
 
91
-    /**
92
-     * calls RouteInterface::handleRequest() on all Routes that
93
-     *      - match current request
94
-     *      - have yet to be handled
95
-     *
96
-     * @return void
97
-     */
98
-    public function handleRoutesForCurrentRequest()
99
-    {
100
-        $this->routes->handleRoutesForCurrentRequest();
101
-    }
91
+	/**
92
+	 * calls RouteInterface::handleRequest() on all Routes that
93
+	 *      - match current request
94
+	 *      - have yet to be handled
95
+	 *
96
+	 * @return void
97
+	 */
98
+	public function handleRoutesForCurrentRequest()
99
+	{
100
+		$this->routes->handleRoutesForCurrentRequest();
101
+	}
102 102
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@
 block discarded – undo
56 56
     {
57 57
         try {
58 58
             $route = $this->loader->getShared($fqcn);
59
-            if (! $route instanceof RouteInterface) {
59
+            if ( ! $route instanceof RouteInterface) {
60 60
                 throw new InvalidClassException(
61 61
                     sprintf(
62 62
                         esc_html__(
Please login to merge, or discard this patch.
core/domain/entities/routing/specifications/shared/WordPressHeartbeat.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -14,11 +14,11 @@
 block discarded – undo
14 14
  */
15 15
 class WordPressHeartbeat extends RouteMatchSpecification
16 16
 {
17
-    /**
18
-     * @inheritDoc
19
-     */
20
-    public function isMatchingRoute()
21
-    {
22
-        return $this->request->isWordPressHeartbeat();
23
-    }
17
+	/**
18
+	 * @inheritDoc
19
+	 */
20
+	public function isMatchingRoute()
21
+	{
22
+		return $this->request->isWordPressHeartbeat();
23
+	}
24 24
 }
Please login to merge, or discard this patch.
core/domain/entities/routing/specifications/admin/WordPressPostsEditor.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -19,22 +19,22 @@
 block discarded – undo
19 19
  */
20 20
 class WordPressPostsEditor extends MatchAnyRouteSpecification
21 21
 {
22
-    /**
23
-     * WordPressPostsEditor constructor.
24
-     *
25
-     * @param WordPressPostsEditorEdit $edit_post_route_match
26
-     * @param WordPressPostsEditorAddNew $create_post_route_match
27
-     * @param RequestInterface           $request
28
-     * @throws InvalidEntityException
29
-     */
30
-    public function __construct(
31
-        WordPressPostsEditorEdit $edit_post_route_match,
32
-        WordPressPostsEditorAddNew $create_post_route_match,
33
-        RequestInterface $request
34
-    ) {
35
-        parent::__construct(
36
-            array($edit_post_route_match, $create_post_route_match),
37
-            $request
38
-        );
39
-    }
22
+	/**
23
+	 * WordPressPostsEditor constructor.
24
+	 *
25
+	 * @param WordPressPostsEditorEdit $edit_post_route_match
26
+	 * @param WordPressPostsEditorAddNew $create_post_route_match
27
+	 * @param RequestInterface           $request
28
+	 * @throws InvalidEntityException
29
+	 */
30
+	public function __construct(
31
+		WordPressPostsEditorEdit $edit_post_route_match,
32
+		WordPressPostsEditorAddNew $create_post_route_match,
33
+		RequestInterface $request
34
+	) {
35
+		parent::__construct(
36
+			array($edit_post_route_match, $create_post_route_match),
37
+			$request
38
+		);
39
+	}
40 40
 }
Please login to merge, or discard this patch.
core/domain/entities/routing/specifications/admin/WordPressPluginsPage.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@
 block discarded – undo
15 15
 class WordPressPluginsPage extends RouteMatchSpecification
16 16
 {
17 17
 
18
-    /**
19
-     * @inheritDoc
20
-     */
21
-    public function isMatchingRoute()
22
-    {
23
-        return $this->request->isAdmin()
24
-               && strpos($this->request->requestUri(), 'wp-admin/plugins.php') !== false;
25
-    }
18
+	/**
19
+	 * @inheritDoc
20
+	 */
21
+	public function isMatchingRoute()
22
+	{
23
+		return $this->request->isAdmin()
24
+			   && strpos($this->request->requestUri(), 'wp-admin/plugins.php') !== false;
25
+	}
26 26
 }
Please login to merge, or discard this patch.