Completed
Branch FET-10766-extract-activation-d... (2c1e01)
by
unknown
104:24 queued 93:14
created

EE_System::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 67
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 45
nc 1
nop 3
dl 0
loc 67
rs 9.2815
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
use EventEspresso\core\exceptions\ExceptionStackTraceDisplay;
4
use EventEspresso\core\exceptions\InvalidDataTypeException;
5
use EventEspresso\core\exceptions\InvalidEntityException;
6
use EventEspresso\core\exceptions\InvalidInterfaceException;
7
use EventEspresso\core\interfaces\ResettableInterface;
8
use EventEspresso\core\services\activation\ActivatableInterface;
9
use EventEspresso\core\services\activation\ActivationHistory;
10
use EventEspresso\core\services\activation\ActivationsAndUpgradesManager;
11
use EventEspresso\core\services\activation\ActivationsFactory;
12
use EventEspresso\core\services\loaders\LoaderFactory;
13
use EventEspresso\core\services\loaders\LoaderInterface;
14
use EventEspresso\core\services\activation\RequestType;
15
use EventEspresso\core\services\shortcodes\ShortcodesManager;
16
17
18
defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed');
19
20
21
22
/**
23
 * EE_System
24
 * The backbone of the core application that the rest of the system builds off of once bootstrapping is complete
25
 *
26
 * @package        Event Espresso
27
 * @subpackage     core/
28
 * @author         Brent Christensen, Michael Nelson
29
 */
30
class EE_System implements ActivatableInterface, ResettableInterface
31
{
32
33
34
    /**
35
     * @deprecated 4.9.40
36
     * @see        \EventEspresso\core\services\activation\RequestTypeDetector
37
     */
38
    const req_type_normal = 0;
39
40
    /**
41
     * @deprecated 4.9.40
42
     * @see        \EventEspresso\core\services\activation\RequestTypeDetector
43
     */
44
    const req_type_new_activation = 1;
45
46
    /**
47
     * @deprecated 4.9.40
48
     * @see        \EventEspresso\core\services\activation\RequestTypeDetector
49
     */
50
    const req_type_reactivation = 2;
51
52
    /**
53
     * @deprecated 4.9.40
54
     * @see        \EventEspresso\core\services\activation\RequestTypeDetector
55
     */
56
    const req_type_upgrade = 3;
57
58
    /**
59
     * @deprecated 4.9.40
60
     * @see        \EventEspresso\core\services\activation\RequestTypeDetector
61
     */
62
    const req_type_downgrade = 4;
63
64
    /**
65
     * @deprecated since version 4.6.0.dev.006
66
     * Now whenever a new_activation is detected the request type is still just
67
     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
68
     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
69
     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
70
     * (Specifically, when the migration manager indicates migrations are finished
71
     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
72
     */
73
    const req_type_activation_but_not_installed = 5;
74
75
    /**
76
     * @deprecated 4.9.40
77
     * @see        \EventEspresso\core\services\activation\RequestTypeDetector
78
     */
79
    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
80
81
82
    /**
83
     * @var EE_System $_instance
84
     */
85
    private static $_instance;
86
87
    /**
88
     * @var EE_Registry $registry
89
     */
90
    private $registry;
91
92
    /**
93
     * @var LoaderInterface $loader
94
     */
95
    private $loader;
96
97
    /**
98
     * @var EE_Capabilities $capabilities
99
     */
100
    private $capabilities;
101
102
    /**
103
     * @var EE_Maintenance_Mode $maintenance_mode
104
     */
105
    private $maintenance_mode;
106
107
    /**
108
     * @var ActivationsAndUpgradesManager $activations_and_upgrades_manager
109
     */
110
    private $activations_and_upgrades_manager;
111
112
    /**
113
     * @var ActivationHistory $activation_history
114
     */
115
    private $activation_history;
116
117
    /**
118
     * @var \EventEspresso\core\services\activation\RequestType $request_type
119
     */
120
    private $request_type;
121
122
    /**
123
     * @var bool $activation_detected
124
     */
125
    private $activation_detected = false;
126
127
128
129
    /**
130
     * @singleton method used to instantiate class object
131
     * @param EE_Registry|null         $registry
132
     * @param LoaderInterface|null     $loader
133
     * @param EE_Maintenance_Mode|null $maintenance_mode
134
     * @return EE_System
135
     */
136
    public static function instance(
137
        EE_Registry $registry = null,
138
        LoaderInterface $loader = null,
139
        EE_Maintenance_Mode $maintenance_mode = null
140
    ) {
141
        // check if class object is instantiated
142
        if (! self::$_instance instanceof EE_System) {
143
            self::$_instance = new self(
144
                $registry,
0 ignored issues
show
Bug introduced by
It seems like $registry defined by parameter $registry on line 137 can be null; however, EE_System::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
145
                $loader,
0 ignored issues
show
Bug introduced by
It seems like $loader defined by parameter $loader on line 138 can be null; however, EE_System::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
146
                $maintenance_mode
0 ignored issues
show
Bug introduced by
It seems like $maintenance_mode defined by parameter $maintenance_mode on line 139 can be null; however, EE_System::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
147
            );
148
        }
149
        return self::$_instance;
150
    }
151
152
153
154
    /**
155
     * resets the instance and returns it
156
     *
157
     * @return EE_System
158
     * @throws InvalidInterfaceException
159
     * @throws InvalidDataTypeException
160
     * @throws DomainException
161
     * @throws InvalidArgumentException
162
     * @throws InvalidEntityException
163
     */
164
    public static function reset()
165
    {
166
        //make sure none of the old hooks are left hanging around
167
        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
168
        //we need to reset the migration manager in order for it to detect DMSs properly
169
        EE_Data_Migration_Manager::reset();
170
        self::instance()->detect_activations_or_upgrades();
171
        self::instance()->activations_and_upgrades_manager->performActivationsAndUpgrades();
172
        return self::instance();
173
    }
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 EE_Maintenance_Mode $maintenance_mode
185
     */
186
    private function __construct(
187
        EE_Registry $registry,
188
        LoaderInterface $loader,
189
        EE_Maintenance_Mode $maintenance_mode
190
    ) {
191
        $this->registry = $registry;
192
        $this->loader = $loader;
193
        $this->maintenance_mode = $maintenance_mode;
194
        do_action('AHEE__EE_System__construct__begin', $this);
195
        add_action(
196
            'AHEE__EE_Bootstrap__load_espresso_addons',
197
            array($this, 'loadCapabilities'),
198
            5
199
        );
200
        add_action(
201
            'AHEE__EE_Bootstrap__load_espresso_addons',
202
            array($this, 'loadCommandBus'),
203
            7
204
        );
205
        add_action(
206
            'AHEE__EE_Bootstrap__load_espresso_addons',
207
            array($this, 'loadPluginApi'),
208
            9
209
        );
210
        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
211
        add_action(
212
            'AHEE__EE_Bootstrap__load_espresso_addons',
213
            array($this, 'load_espresso_addons')
214
        );
215
        // when an ee addon is activated, we want to call the core hook(s) again
216
        // because the newly-activated addon didn't get a chance to run at all
217
        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
218
        // detect whether install or upgrade
219
        add_action(
220
            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
221
            array($this, 'detect_activations_or_upgrades'),
222
            3
223
        );
224
        // load EE_Config, EE_Textdomain, etc
225
        add_action(
226
            'AHEE__EE_Bootstrap__load_core_configuration',
227
            array($this, 'load_core_configuration'),
228
            5
229
        );
230
        // load EE_Config, EE_Textdomain, etc
231
        add_action(
232
            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
233
            array($this, 'register_shortcodes_modules_and_widgets'),
234
            7
235
        );
236
        // you wanna get going? I wanna get going... let's get going!
237
        add_action(
238
            'AHEE__EE_Bootstrap__brew_espresso',
239
            array($this, 'brew_espresso'),
240
            9
241
        );
242
        //other housekeeping
243
        //exclude EE critical pages from wp_list_pages
244
        add_filter(
245
            'wp_list_pages_excludes',
246
            array($this, 'remove_pages_from_wp_list_pages'),
247
            10
248
        );
249
        // ALL EE Addons should use the following hook point to attach their initial setup too
250
        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
251
        do_action('AHEE__EE_System__construct__complete', $this);
252
    }
253
254
255
256
    /**
257
     * load and setup EE_Capabilities
258
     *
259
     * @return void
260
     * @throws InvalidArgumentException
261
     * @throws InvalidInterfaceException
262
     * @throws InvalidDataTypeException
263
     * @throws EE_Error
264
     */
265
    public function loadCapabilities()
266
    {
267
        $this->capabilities = $this->loader->getShared('EE_Capabilities');
268
        add_action(
269
            'AHEE__EE_Capabilities__init_caps__before_initialization',
270
            function() {
271
                LoaderFactory::getLoader()->getShared('Payment_Method_Manager');
272
            }
273
        );
274
    }
275
276
277
278
    /**
279
     * create and cache the CommandBus, and also add middleware
280
     * The CapChecker middleware requires the use of EE_Capabilities
281
     * which is why we need to load the CommandBus after Caps are set up
282
     *
283
     * @return void
284
     * @throws EE_Error
285
     */
286
    public function loadCommandBus()
287
    {
288
        $this->loader->getShared(
289
            'CommandBusInterface',
290
            array(
291
                null,
292
                apply_filters(
293
                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
294
                    array(
295
                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
296
                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
297
                    )
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::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
314
    }
315
316
317
318
    /**
319
     * Gets the ActivationHistory object for this addon
320
     *
321
     * @return ActivationHistory
322
     */
323
    public function getActivationHistory()
324
    {
325
        return $this->activation_history;
326
    }
327
328
329
330
    /**
331
     * @param ActivationHistory $activation_history
332
     */
333
    public function setActivationHistory(ActivationHistory $activation_history)
334
    {
335
        $this->activation_history = $activation_history;
336
    }
337
338
339
340
    /**
341
     * @return RequestType
342
     */
343
    public function getRequestType()
344
    {
345
        return $this->request_type;
346
    }
347
348
349
350
    /**
351
     * @param RequestType $request_type
352
     */
353
    public function setRequestType(RequestType $request_type)
354
    {
355
        $this->request_type = $request_type;
356
    }
357
358
    /**
359
     * load_espresso_addons
360
     * allow addons to load first so that they can set hooks for running DMS's, etc
361
     * this is hooked into both:
362
     *    'AHEE__EE_Bootstrap__load_core_configuration'
363
     *        which runs during the WP 'plugins_loaded' action at priority 5
364
     *    and the WP 'activate_plugin' hook point
365
     *
366
     * @return void
367
     * @throws EE_Error
368
     */
369
    public function load_espresso_addons()
370
    {
371
        do_action('AHEE__EE_System__load_espresso_addons');
372
        //if the WP API basic auth plugin isn't already loaded, load it now.
373
        //We want it for mobile apps. Just include the entire plugin
374
        //also, don't load the basic auth when a plugin is getting activated, because
375
        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
376
        //and causes a fatal error
377
        if (
378
            ! (
379
                isset($_GET['activate'])
380
                && $_GET['activate'] === 'true'
381
            )
382
            && ! function_exists('json_basic_auth_handler')
383
            && ! function_exists('json_basic_auth_error')
384
            && ! (
385
                isset($_GET['action'])
386
                && in_array($_GET['action'], array('activate', 'activate-selected'), true)
387
            )
388
        ) {
389
            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
390
        }
391
        do_action('AHEE__EE_System__load_espresso_addons__complete');
392
    }
393
394
395
396
    /**
397
     * detect_activations_or_upgrades
398
     * Checks for activation or upgrade of core first;
399
     * then also checks if any registered addons have been activated or upgraded
400
     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
401
     * which runs during the WP 'plugins_loaded' action at priority 3
402
     *
403
     * @return void
404
     * @throws DomainException
405
     * @throws InvalidArgumentException
406
     * @throws InvalidEntityException
407
     * @throws InvalidInterfaceException
408
     * @throws InvalidDataTypeException
409
     */
410
    public function detect_activations_or_upgrades()
411
    {
412
        if(
413
            (defined('DOING_AJAX') && DOING_AJAX)
414
            || (defined('REST_REQUEST') && REST_REQUEST)
415
        ) {
416
            return;
417
        }
418
        $this->activations_and_upgrades_manager = ActivationsFactory::getActivationsAndUpgradesManager();
419
        $this->activation_detected = $this->activations_and_upgrades_manager->detectActivationsAndVersionChanges(
420
            array_merge(
421
                array($this),
422
                get_object_vars($this->registry->addons)
423
            )
424
        );
425
    }
426
427
428
429
    /**
430
     * load_core_configuration
431
     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
432
     * which runs during the WP 'plugins_loaded' action at priority 5
433
     *
434
     * @return void
435
     * @throws ReflectionException
436
     */
437
    public function load_core_configuration()
438
    {
439
        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
440
        $this->loader->getShared('EE_Load_Textdomain');
441
        //load textdomain
442
        EE_Load_Textdomain::load_textdomain();
443
        // load and setup EE_Config and EE_Network_Config
444
        $config = $this->loader->getShared('EE_Config');
445
        $this->loader->getShared('EE_Network_Config');
446
        // setup autoloaders
447
        // enable logging?
448
        if ($config->admin->use_full_logging) {
449
            $this->loader->getShared('EE_Log');
450
        }
451
        // check for activation errors
452
        $activation_errors = get_option('ee_plugin_activation_errors', false);
453
        if ($activation_errors) {
454
            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
455
            update_option('ee_plugin_activation_errors', false);
456
        }
457
        // get model names
458
        $this->_parse_model_names();
459
        //load caf stuff a chance to play during the activation process too.
460
        $this->_maybe_brew_regular();
461
        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
462
    }
463
464
465
466
    /**
467
     * cycles through all of the models/*.model.php files, and assembles an array of model names
468
     *
469
     * @return void
470
     * @throws ReflectionException
471
     */
472
    private function _parse_model_names()
473
    {
474
        //get all the files in the EE_MODELS folder that end in .model.php
475
        $models = glob(EE_MODELS . '*.model.php');
476
        $model_names = array();
477
        $non_abstract_db_models = array();
478
        foreach ($models as $model) {
479
            // get model classname
480
            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
481
            $short_name = str_replace('EEM_', '', $classname);
482
            $reflectionClass = new ReflectionClass($classname);
483
            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
484
                $non_abstract_db_models[$short_name] = $classname;
485
            }
486
            $model_names[$short_name] = $classname;
487
        }
488
        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
489
        $this->registry->non_abstract_db_models = apply_filters(
490
            'FHEE__EE_System__parse_implemented_model_names',
491
            $non_abstract_db_models
492
        );
493
    }
494
495
496
497
    /**
498
     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
499
     * that need to be setup before our EE_System launches.
500
     *
501
     * @return void
502
     */
503
    private function _maybe_brew_regular()
504
    {
505
        if (
506
            ! $this->activation_detected
507
            && (! defined('EE_DECAF') || EE_DECAF !== true)
508
            && is_readable(EE_CAFF_PATH . 'brewing_regular.php')
509
        ) {
510
            require_once EE_CAFF_PATH . 'brewing_regular.php';
511
        }
512
    }
513
514
515
516
    /**
517
     * register_shortcodes_modules_and_widgets
518
     * generate lists of shortcodes and modules, then verify paths and classes
519
     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
520
     * which runs during the WP 'plugins_loaded' action at priority 7
521
     *
522
     * @access public
523
     * @return void
524
     * @throws Exception
525
     */
526
    public function register_shortcodes_modules_and_widgets()
527
    {
528
        if ($this->activation_detected) {
529
            return;
530
        }
531
        // check for addons using old hook point
532
        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
533
            $this->_incompatible_addon_error();
534
        }
535
        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
536
        try {
537
            // load, register, and add shortcodes the new way
538
            new ShortcodesManager(
539
            // and the old way, but we'll put it under control of the new system
540
                EE_Config::getLegacyShortcodesManager()
541
            );
542
        } catch (Exception $exception) {
543
            new ExceptionStackTraceDisplay($exception);
544
        }
545
    }
546
547
548
549
    /**
550
     * _incompatible_addon_error
551
     *
552
     * @access public
553
     * @return void
554
     */
555
    private function _incompatible_addon_error()
556
    {
557
        // get array of classes hooking into here
558
        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
559
            'AHEE__EE_System__register_shortcodes_modules_and_addons'
560
        );
561
        if (! empty($class_names)) {
562
            $msg = __(
563
                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
564
                'event_espresso'
565
            );
566
            $msg .= '<ul>';
567
            foreach ($class_names as $class_name) {
568
                $msg .= '<li><b>Event Espresso - ' . str_replace(
569
                        array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
570
                        $class_name
571
                    ) . '</b></li>';
572
            }
573
            $msg .= '</ul>';
574
            $msg .= __(
575
                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
576
                'event_espresso'
577
            );
578
            // save list of incompatible addons to wp-options for later use
579
            add_option('ee_incompatible_addons', $class_names, '', 'no');
580
            if (is_admin()) {
581
                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
582
            }
583
        }
584
    }
585
586
587
588
    /**
589
     * brew_espresso
590
     * begins the process of setting hooks for initializing EE in the correct order
591
     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
592
     * which runs during the WP 'plugins_loaded' action at priority 9
593
     *
594
     * @return void
595
     */
596
    public function brew_espresso()
597
    {
598
        if ($this->activation_detected) {
599
            add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
600
            return;
601
        }
602
        do_action('AHEE__EE_System__brew_espresso__begin', $this);
603
        // load some final core systems
604
        add_action('init', array($this, 'set_hooks_for_core'), 1);
605
        add_action('init', array($this, 'load_CPTs_and_session'), 5);
606
        add_action('init', array($this, 'load_controllers'), 7);
607
        add_action('init', array($this, 'core_loaded_and_ready'), 9);
608
        add_action('init', array($this, 'initialize'), 10);
609
        add_action('init', array($this, 'initialize_last'), 100);
610
        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
611
            // pew pew pew
612
            $this->loader->getShared('EE_PUE');
613
            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
614
        }
615
        do_action('AHEE__EE_System__brew_espresso__complete', $this);
616
    }
617
618
619
620
    /**
621
     *    set_hooks_for_core
622
     *
623
     * @access public
624
     * @return    void
625
     * @throws EE_Error
626
     */
627
    public function set_hooks_for_core()
628
    {
629
        do_action('AHEE__EE_System__set_hooks_for_core');
630
        //caps need to be initialized on every request so that capability maps are set.
631
        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
632
        $this->capabilities->init_caps();
633
    }
634
635
636
637
    /**
638
     *    perform_activations_upgrades_and_migrations
639
     *
640
     * @access public
641
     * @return    void
642
     */
643
    public function perform_activations_upgrades_and_migrations()
644
    {
645
        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
646
    }
647
648
649
650
    /**
651
     *    load_CPTs_and_session
652
     *
653
     * @access public
654
     * @return    void
655
     */
656
    public function load_CPTs_and_session()
657
    {
658
        do_action('AHEE__EE_System__load_CPTs_and_session__start');
659
        // register Custom Post Types
660
        $this->loader->getShared('EE_Register_CPTs');
661
        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
662
    }
663
664
665
666
    /**
667
     * load_controllers
668
     * this is the best place to load any additional controllers that needs access to EE core.
669
     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
670
     * time
671
     *
672
     * @access public
673
     * @return void
674
     */
675
    public function load_controllers()
676
    {
677
        do_action('AHEE__EE_System__load_controllers__start');
678
        // let's get it started
679
        if (! is_admin() && ! $this->maintenance_mode->level()) {
680
            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
681
            $this->loader->getShared('EE_Front_Controller');
682
        } else if (! EE_FRONT_AJAX) {
683
            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
684
            $this->loader->getShared('EE_Admin');
685
        }
686
        do_action('AHEE__EE_System__load_controllers__complete');
687
    }
688
689
690
691
    /**
692
     * core_loaded_and_ready
693
     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
694
     *
695
     * @access public
696
     * @return void
697
     */
698
    public function core_loaded_and_ready()
699
    {
700
        $this->loader->getShared('EE_Session');
701
        do_action('AHEE__EE_System__core_loaded_and_ready');
702
        // load_espresso_template_tags
703
        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
704
            require_once(EE_PUBLIC . 'template_tags.php');
705
        }
706
        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
707
        $this->loader->getShared('EventEspresso\core\services\assets\Registry');
708
    }
709
710
711
712
    /**
713
     * initialize
714
     * this is the best place to begin initializing client code
715
     *
716
     * @access public
717
     * @return void
718
     */
719
    public function initialize()
720
    {
721
        do_action('AHEE__EE_System__initialize');
722
    }
723
724
725
726
    /**
727
     * initialize_last
728
     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
729
     * initialize has done so
730
     *
731
     * @access public
732
     * @return void
733
     */
734
    public function initialize_last()
735
    {
736
        do_action('AHEE__EE_System__initialize_last');
737
        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
738
    }
739
740
741
742
    /**
743
     * @return void
744
     * @throws EE_Error
745
     */
746
    public function addEspressoToolbar()
747
    {
748
        $this->loader->getShared(
749
            'EventEspresso\core\domain\services\admin\AdminToolBar',
750
            array($this->capabilities)
751
        );
752
    }
753
754
755
756
    /**
757
     * do_not_cache
758
     * sets no cache headers and defines no cache constants for WP plugins
759
     *
760
     * @access public
761
     * @return void
762
     */
763
    public static function do_not_cache()
764
    {
765
        // set no cache constants
766
        if (! defined('DONOTCACHEPAGE')) {
767
            define('DONOTCACHEPAGE', true);
768
        }
769
        if (! defined('DONOTCACHCEOBJECT')) {
770
            define('DONOTCACHCEOBJECT', true);
771
        }
772
        if (! defined('DONOTCACHEDB')) {
773
            define('DONOTCACHEDB', true);
774
        }
775
        // add no cache headers
776
        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
777
        // plus a little extra for nginx and Google Chrome
778
        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
779
        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
780
        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
781
    }
782
783
784
785
    /**
786
     *    extra_nocache_headers
787
     *
788
     * @access    public
789
     * @param $headers
790
     * @return    array
791
     */
792
    public static function extra_nocache_headers($headers)
793
    {
794
        // for NGINX
795
        $headers['X-Accel-Expires'] = 0;
796
        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
797
        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
798
        return $headers;
799
    }
800
801
802
803
    /**
804
     *    nocache_headers
805
     *
806
     * @access    public
807
     * @return    void
808
     */
809
    public static function nocache_headers()
810
    {
811
        nocache_headers();
812
    }
813
814
815
816
817
    /**
818
     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
819
     * never returned with the function.
820
     *
821
     * @param  array $exclude_array any existing pages being excluded are in this array.
822
     * @return array
823
     */
824
    public function remove_pages_from_wp_list_pages($exclude_array)
825
    {
826
        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
827
    }
828
829
830
831
    /******************************** DEPRECATED ***************************************/
832
833
834
835
    /**
836
     * @deprecated 4.9.40
837
     * @return void
838
     */
839
    public function detect_if_activation_or_upgrade()
840
    {
841
    }
842
843
844
845
    /**
846
     * @deprecated 4.9.40
847
     * @param null $version_history
848
     * @param null $current_version_to_add
849
     * @return void
850
     */
851
    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
852
    {
853
    }
854
855
856
857
    /**
858
     * @deprecated 4.9.40
859
     * @param null $espresso_db_update
860
     * @return int one of the constants on EE_System::req_type_
861
     */
862
    public function detect_req_type($espresso_db_update = null)
863
    {
864
        return $this->getRequestType()->getRequestType();
865
    }
866
867
868
869
    /**
870
     * @deprecated 4.9.40
871
     * @return bool
872
     */
873
    public function is_major_version_change()
874
    {
875
        return $this->getRequestType()->isMajorVersionChange();
876
    }
877
878
879
880
    /**
881
     * @deprecated 4.9.40
882
     * @param array  $activation_history_for_addon
883
     * @param string $activation_indicator_option_name
884
     * @param string $version_to_upgrade_to
885
     * @return int one of the constants on EE_System::req_type_*
886
     */
887
    public static function detect_req_type_given_activation_history(
888
        $activation_history_for_addon,
889
        $activation_indicator_option_name,
890
        $version_to_upgrade_to
891
    ) {
892
        return EE_System::instance()->getRequestType()->getRequestType();
893
    }
894
895
896
897
    /**
898
     * @deprecated 4.9.40
899
     * @param boolean $initialize_addons_too
900
     * @param boolean $verify_schema
901
     * @return void
902
     * @throws EE_Error
903
     */
904
    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
905
    {
906
    }
907
908
909
910
    /**
911
     * @deprecated 4.9.40
912
     * @throws EE_Error
913
     */
914
    public function initialize_addons()
915
    {
916
    }
917
918
919
920
    /**
921
     * @deprecated 4.9.40
922
     * @return void
923
     */
924
    public function redirect_to_about_ee()
925
    {
926
    }
927
928
929
}
930
// End of file EE_System.core.php
931
// Location: /core/EE_System.core.php
932