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