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