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