Completed
Branch FET-9222-rest-api-writes (851ffe)
by
unknown
96:34 queued 85:06
created

EE_System::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 62
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 40
nc 1
nop 1
dl 0
loc 62
rs 9.4743
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
use EventEspresso\core\exceptions\ExceptionStackTraceDisplay;
4
use EventEspresso\core\interfaces\ResettableInterface;
5
use EventEspresso\core\services\loaders\LoaderFactory;
6
use EventEspresso\core\services\shortcodes\ShortcodesManager;
7
8
9
if ( ! defined('EVENT_ESPRESSO_VERSION')) {
10
    exit('No direct script access allowed');
11
}
12
13
14
15
/**
16
 * EE_System
17
 * The backbone of the core application that the rest of the system builds off of once bootstrapping is complete
18
 *
19
 * @package        Event Espresso
20
 * @subpackage     core/
21
 * @author         Brent Christensen, Michael Nelson
22
 */
23
final class EE_System implements ResettableInterface
24
{
25
26
27
    /**
28
     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
29
     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
30
     */
31
    const req_type_normal = 0;
32
33
    /**
34
     * Indicates this is a brand new installation of EE so we should install
35
     * tables and default data etc
36
     */
37
    const req_type_new_activation = 1;
38
39
    /**
40
     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
41
     * and we just exited maintenance mode). We MUST check the database is setup properly
42
     * and that default data is setup too
43
     */
44
    const req_type_reactivation = 2;
45
46
    /**
47
     * indicates that EE has been upgraded since its previous request.
48
     * We may have data migration scripts to call and will want to trigger maintenance mode
49
     */
50
    const req_type_upgrade = 3;
51
52
    /**
53
     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
54
     */
55
    const req_type_downgrade = 4;
56
57
    /**
58
     * @deprecated since version 4.6.0.dev.006
59
     * Now whenever a new_activation is detected the request type is still just
60
     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
61
     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
62
     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
63
     * (Specifically, when the migration manager indicates migrations are finished
64
     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
65
     */
66
    const req_type_activation_but_not_installed = 5;
67
68
    /**
69
     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
70
     */
71
    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
72
73
74
    /**
75
     * @var EE_System $_instance
76
     */
77
    private static $_instance;
78
79
    /**
80
     * @var EE_Registry $registry
81
     */
82
    protected $registry;
83
84
    /**
85
     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
86
     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
87
     *
88
     * @var int $_req_type
89
     */
90
    private $_req_type;
91
92
    /**
93
     * Whether or not there was a non-micro version change in EE core version during this request
94
     *
95
     * @var boolean $_major_version_change
96
     */
97
    private $_major_version_change = false;
98
99
100
101
    /**
102
     * @singleton method used to instantiate class object
103
     * @access    public
104
     * @param  EE_Registry $Registry
105
     * @return EE_System
106
     */
107
    public static function instance(EE_Registry $Registry = null)
108
    {
109
        // check if class object is instantiated
110
        if ( ! self::$_instance instanceof EE_System) {
111
            self::$_instance = new self($Registry);
0 ignored issues
show
Bug introduced by
It seems like $Registry defined by parameter $Registry on line 107 can be null; however, EE_System::__construct() does not accept null, maybe add an additional type check?

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

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

function notNullable(stdClass $x) { }

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

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

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
112
        }
113
        return self::$_instance;
114
    }
115
116
117
118
    /**
119
     * resets the instance and returns it
120
     *
121
     * @return EE_System
122
     */
123
    public static function reset()
124
    {
125
        self::$_instance->_req_type = null;
126
        //make sure none of the old hooks are left hanging around
127
        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
128
        //we need to reset the migration manager in order for it to detect DMSs properly
129
        EE_Data_Migration_Manager::reset();
130
        self::instance()->detect_activations_or_upgrades();
131
        self::instance()->perform_activations_upgrades_and_migrations();
132
        return self::instance();
133
    }
134
135
136
137
    /**
138
     *    sets hooks for running rest of system
139
     *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
140
     *    starting EE Addons from any other point may lead to problems
141
     *
142
     * @access private
143
     * @param  EE_Registry $Registry
144
     */
145
    private function __construct(EE_Registry $Registry)
146
    {
147
        $this->registry = $Registry;
148
        do_action('AHEE__EE_System__construct__begin', $this);
149
        add_action(
150
            'AHEE__EE_Bootstrap__load_espresso_addons',
151
            array($this, 'loadCapabilities'),
152
            5
153
        );
154
        add_action(
155
            'AHEE__EE_Bootstrap__load_espresso_addons',
156
            array($this, 'loadCommandBus'),
157
            7
158
        );
159
        add_action(
160
            'AHEE__EE_Bootstrap__load_espresso_addons',
161
            array($this, 'loadPluginApi'),
162
            9
163
        );
164
        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
165
        add_action(
166
            'AHEE__EE_Bootstrap__load_espresso_addons',
167
            array($this, 'load_espresso_addons')
168
        );
169
        // when an ee addon is activated, we want to call the core hook(s) again
170
        // because the newly-activated addon didn't get a chance to run at all
171
        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
172
        // detect whether install or upgrade
173
        add_action(
174
            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
175
            array($this, 'detect_activations_or_upgrades'),
176
            3
177
        );
178
        // load EE_Config, EE_Textdomain, etc
179
        add_action(
180
            'AHEE__EE_Bootstrap__load_core_configuration',
181
            array($this, 'load_core_configuration'),
182
            5
183
        );
184
        // load EE_Config, EE_Textdomain, etc
185
        add_action(
186
            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
187
            array($this, 'register_shortcodes_modules_and_widgets'),
188
            7
189
        );
190
        // you wanna get going? I wanna get going... let's get going!
191
        add_action(
192
            'AHEE__EE_Bootstrap__brew_espresso',
193
            array($this, 'brew_espresso'),
194
            9
195
        );
196
        //other housekeeping
197
        //exclude EE critical pages from wp_list_pages
198
        add_filter(
199
            'wp_list_pages_excludes',
200
            array($this, 'remove_pages_from_wp_list_pages'),
201
            10
202
        );
203
        // ALL EE Addons should use the following hook point to attach their initial setup too
204
        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
205
        do_action('AHEE__EE_System__construct__complete', $this);
206
    }
207
208
209
210
    /**
211
     * load and setup EE_Capabilities
212
     *
213
     * @return void
214
     * @throws EE_Error
215
     */
216
    public function loadCapabilities()
217
    {
218
        $this->registry->load_core('EE_Capabilities');
219
        add_action(
220
            'AHEE__EE_Capabilities__init_caps__before_initialization',
221
            function() {
222
                EE_Registry::instance()->load_lib('Payment_Method_Manager');
223
            }
224
        );
225
    }
226
227
228
229
    /**
230
     * create and cache the CommandBus, and also add middleware
231
     * The CapChecker middleware requires the use of EE_Capabilities
232
     * which is why we need to load the CommandBus after Caps are set up
233
     *
234
     * @return void
235
     * @throws EE_Error
236
     */
237
    public function loadCommandBus()
238
    {
239
        $this->registry->create(
240
            'CommandBusInterface',
241
            array(
242
                null,
243
                apply_filters(
244
                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
245
                    array(
246
                        $this->registry->create('CapChecker'),
247
                        $this->registry->create('AddActionHook'),
248
                    )
249
                ),
250
            ),
251
            true
252
        );
253
    }
254
255
256
257
    /**
258
     * @return void
259
     * @throws EE_Error
260
     */
261
    public function loadPluginApi()
262
    {
263
        // set autoloaders for all of the classes implementing EEI_Plugin_API
264
        // which provide helpers for EE plugin authors to more easily register certain components with EE.
265
        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
266
    }
267
268
269
270
    /**
271
     * load_espresso_addons
272
     * allow addons to load first so that they can set hooks for running DMS's, etc
273
     * this is hooked into both:
274
     *    'AHEE__EE_Bootstrap__load_core_configuration'
275
     *        which runs during the WP 'plugins_loaded' action at priority 5
276
     *    and the WP 'activate_plugin' hook point
277
     *
278
     * @access public
279
     * @return void
280
     * @throws EE_Error
281
     */
282
    public function load_espresso_addons()
283
    {
284
        do_action('AHEE__EE_System__load_espresso_addons');
285
        //if the WP API basic auth plugin isn't already loaded, load it now.
286
        //We want it for mobile apps. Just include the entire plugin
287
        //also, don't load the basic auth when a plugin is getting activated, because
288
        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
289
        //and causes a fatal error
290
        if (
291
            ! (isset($_GET['activate']) && $_GET['activate'] === 'true')
292
            && ! function_exists('json_basic_auth_handler')
293
            && ! function_exists('json_basic_auth_error')
294
            && ! (
295
                isset($_GET['action'])
296
                && in_array($_GET['action'], array('activate', 'activate-selected'), true)
297
            )
298
        ) {
299
            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
300
        }
301
        do_action('AHEE__EE_System__load_espresso_addons__complete');
302
    }
303
304
305
306
    /**
307
     * detect_activations_or_upgrades
308
     * Checks for activation or upgrade of core first;
309
     * then also checks if any registered addons have been activated or upgraded
310
     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
311
     * which runs during the WP 'plugins_loaded' action at priority 3
312
     *
313
     * @access public
314
     * @return void
315
     */
316
    public function detect_activations_or_upgrades()
317
    {
318
        //first off: let's make sure to handle core
319
        $this->detect_if_activation_or_upgrade();
320
        foreach ($this->registry->addons as $addon) {
321
            //detect teh request type for that addon
322
            $addon->detect_activation_or_upgrade();
323
        }
324
    }
325
326
327
328
    /**
329
     * detect_if_activation_or_upgrade
330
     * Takes care of detecting whether this is a brand new install or code upgrade,
331
     * and either setting up the DB or setting up maintenance mode etc.
332
     *
333
     * @access public
334
     * @return void
335
     */
336
    public function detect_if_activation_or_upgrade()
337
    {
338
        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
339
        // load M-Mode class
340
        $this->registry->load_core('Maintenance_Mode');
341
        // check if db has been updated, or if its a brand-new installation
342
        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
343
        $request_type = $this->detect_req_type($espresso_db_update);
344
        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
345
        switch ($request_type) {
346
            case EE_System::req_type_new_activation:
347
                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
348
                $this->_handle_core_version_change($espresso_db_update);
349
                break;
350
            case EE_System::req_type_reactivation:
351
                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
352
                $this->_handle_core_version_change($espresso_db_update);
353
                break;
354
            case EE_System::req_type_upgrade:
355
                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
356
                //migrations may be required now that we've upgraded
357
                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
358
                $this->_handle_core_version_change($espresso_db_update);
359
                //				echo "done upgrade";die;
360
                break;
361
            case EE_System::req_type_downgrade:
362
                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
363
                //its possible migrations are no longer required
364
                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
365
                $this->_handle_core_version_change($espresso_db_update);
366
                break;
367
            case EE_System::req_type_normal:
368
            default:
369
                //				$this->_maybe_redirect_to_ee_about();
370
                break;
371
        }
372
        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
373
    }
374
375
376
377
    /**
378
     * Updates the list of installed versions and sets hooks for
379
     * initializing the database later during the request
380
     *
381
     * @param array $espresso_db_update
382
     */
383
    protected function _handle_core_version_change($espresso_db_update)
384
    {
385
        $this->update_list_of_installed_versions($espresso_db_update);
386
        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
387
        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
388
            array($this, 'initialize_db_if_no_migrations_required'));
389
    }
390
391
392
393
    /**
394
     * standardizes the wp option 'espresso_db_upgrade' which actually stores
395
     * information about what versions of EE have been installed and activated,
396
     * NOT necessarily the state of the database
397
     *
398
     * @param mixed $espresso_db_update the value of the WordPress option.
399
     *                                            If not supplied, fetches it from the options table
400
     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
401
     */
402
    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
403
    {
404
        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
405
        if ( ! $espresso_db_update) {
406
            $espresso_db_update = get_option('espresso_db_update');
407
        }
408
        // check that option is an array
409
        if ( ! is_array($espresso_db_update)) {
410
            // if option is FALSE, then it never existed
411
            if ($espresso_db_update === false) {
412
                // make $espresso_db_update an array and save option with autoload OFF
413
                $espresso_db_update = array();
414
                add_option('espresso_db_update', $espresso_db_update, '', 'no');
415
            } else {
416
                // option is NOT FALSE but also is NOT an array, so make it an array and save it
417
                $espresso_db_update = array($espresso_db_update => array());
418
                update_option('espresso_db_update', $espresso_db_update);
419
            }
420
        } else {
421
            $corrected_db_update = array();
422
            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
423
            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
424
                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
425
                    //the key is an int, and the value IS NOT an array
426
                    //so it must be numerically-indexed, where values are versions installed...
427
                    //fix it!
428
                    $version_string = $should_be_array;
429
                    $corrected_db_update[$version_string] = array('unknown-date');
430
                } else {
431
                    //ok it checks out
432
                    $corrected_db_update[$should_be_version_string] = $should_be_array;
433
                }
434
            }
435
            $espresso_db_update = $corrected_db_update;
436
            update_option('espresso_db_update', $espresso_db_update);
437
        }
438
        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
439
        return $espresso_db_update;
440
    }
441
442
443
444
    /**
445
     * Does the traditional work of setting up the plugin's database and adding default data.
446
     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
447
     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
448
     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
449
     * so that it will be done when migrations are finished
450
     *
451
     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
452
     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
453
     *                                       This is a resource-intensive job
454
     *                                       so we prefer to only do it when necessary
455
     * @return void
456
     * @throws EE_Error
457
     */
458
    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
459
    {
460
        $request_type = $this->detect_req_type();
461
        //only initialize system if we're not in maintenance mode.
462
        if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
463
            update_option('ee_flush_rewrite_rules', true);
464
            if ($verify_schema) {
465
                EEH_Activation::initialize_db_and_folders();
466
            }
467
            EEH_Activation::initialize_db_content();
468
            EEH_Activation::system_initialization();
469
            if ($initialize_addons_too) {
470
                $this->initialize_addons();
471
            }
472
        } else {
473
            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
474
        }
475
        if ($request_type === EE_System::req_type_new_activation
476
            || $request_type === EE_System::req_type_reactivation
477
            || (
478
                $request_type === EE_System::req_type_upgrade
479
                && $this->is_major_version_change()
480
            )
481
        ) {
482
            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
483
        }
484
    }
485
486
487
488
    /**
489
     * Initializes the db for all registered addons
490
     *
491
     * @throws EE_Error
492
     */
493
    public function initialize_addons()
494
    {
495
        //foreach registered addon, make sure its db is up-to-date too
496
        foreach ($this->registry->addons as $addon) {
497
            $addon->initialize_db_if_no_migrations_required();
498
        }
499
    }
500
501
502
503
    /**
504
     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
505
     *
506
     * @param    array  $version_history
507
     * @param    string $current_version_to_add version to be added to the version history
508
     * @return    boolean success as to whether or not this option was changed
509
     */
510
    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
511
    {
512
        if ( ! $version_history) {
513
            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
514
        }
515
        if ($current_version_to_add === null) {
516
            $current_version_to_add = espresso_version();
517
        }
518
        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
519
        // re-save
520
        return update_option('espresso_db_update', $version_history);
521
    }
522
523
524
525
    /**
526
     * Detects if the current version indicated in the has existed in the list of
527
     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
528
     *
529
     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
530
     *                                  If not supplied, fetches it from the options table.
531
     *                                  Also, caches its result so later parts of the code can also know whether
532
     *                                  there's been an update or not. This way we can add the current version to
533
     *                                  espresso_db_update, but still know if this is a new install or not
534
     * @return int one of the constants on EE_System::req_type_
535
     */
536
    public function detect_req_type($espresso_db_update = null)
537
    {
538
        if ($this->_req_type === null) {
539
            $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
540
                : $this->fix_espresso_db_upgrade_option();
541
            $this->_req_type = EE_System::detect_req_type_given_activation_history($espresso_db_update,
542
                'ee_espresso_activation', espresso_version());
543
            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
544
        }
545
        return $this->_req_type;
546
    }
547
548
549
550
    /**
551
     * Returns whether or not there was a non-micro version change (ie, change in either
552
     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
553
     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
554
     *
555
     * @param $activation_history
556
     * @return bool
557
     */
558
    protected function _detect_major_version_change($activation_history)
559
    {
560
        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
561
        $previous_version_parts = explode('.', $previous_version);
562
        $current_version_parts = explode('.', espresso_version());
563
        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
564
               && ($previous_version_parts[0] !== $current_version_parts[0]
565
                   || $previous_version_parts[1] !== $current_version_parts[1]
566
               );
567
    }
568
569
570
571
    /**
572
     * Returns true if either the major or minor version of EE changed during this request.
573
     * 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
574
     *
575
     * @return bool
576
     */
577
    public function is_major_version_change()
578
    {
579
        return $this->_major_version_change;
580
    }
581
582
583
584
    /**
585
     * Determines the request type for any ee addon, given three piece of info: the current array of activation
586
     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
587
     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
588
     * just activated to (for core that will always be espresso_version())
589
     *
590
     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
591
     *                                                 ee plugin. for core that's 'espresso_db_update'
592
     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
593
     *                                                 indicate that this plugin was just activated
594
     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
595
     *                                                 espresso_version())
596
     * @return int one of the constants on EE_System::req_type_*
597
     */
598
    public static function detect_req_type_given_activation_history(
599
        $activation_history_for_addon,
600
        $activation_indicator_option_name,
601
        $version_to_upgrade_to
602
    ) {
603
        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
604
        if ($activation_history_for_addon) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $activation_history_for_addon of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
605
            //it exists, so this isn't a completely new install
606
            //check if this version already in that list of previously installed versions
607
            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
608
                //it a version we haven't seen before
609
                if ($version_is_higher === 1) {
610
                    $req_type = EE_System::req_type_upgrade;
611
                } else {
612
                    $req_type = EE_System::req_type_downgrade;
613
                }
614
                delete_option($activation_indicator_option_name);
615
            } else {
616
                // its not an update. maybe a reactivation?
617
                if (get_option($activation_indicator_option_name, false)) {
618 View Code Duplication
                    if ($version_is_higher === -1) {
619
                        $req_type = EE_System::req_type_downgrade;
620
                    } elseif ($version_is_higher === 0) {
621
                        //we've seen this version before, but it's an activation. must be a reactivation
622
                        $req_type = EE_System::req_type_reactivation;
623
                    } else {//$version_is_higher === 1
624
                        $req_type = EE_System::req_type_upgrade;
625
                    }
626
                    delete_option($activation_indicator_option_name);
627 View Code Duplication
                } else {
628
                    //we've seen this version before and the activation indicate doesn't show it was just activated
629
                    if ($version_is_higher === -1) {
630
                        $req_type = EE_System::req_type_downgrade;
631
                    } elseif ($version_is_higher === 0) {
632
                        //we've seen this version before and it's not an activation. its normal request
633
                        $req_type = EE_System::req_type_normal;
634
                    } else {//$version_is_higher === 1
635
                        $req_type = EE_System::req_type_upgrade;
636
                    }
637
                }
638
            }
639
        } else {
640
            //brand new install
641
            $req_type = EE_System::req_type_new_activation;
642
            delete_option($activation_indicator_option_name);
643
        }
644
        return $req_type;
645
    }
646
647
648
649
    /**
650
     * Detects if the $version_to_upgrade_to is higher than the most recent version in
651
     * the $activation_history_for_addon
652
     *
653
     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
654
     *                                             sometimes containing 'unknown-date'
655
     * @param string $version_to_upgrade_to        (current version)
656
     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
657
     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
658
     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
659
     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
660
     */
661
    protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
662
    {
663
        //find the most recently-activated version
664
        $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
665
        return version_compare($version_to_upgrade_to, $most_recently_active_version);
666
    }
667
668
669
670
    /**
671
     * Gets the most recently active version listed in the activation history,
672
     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
673
     *
674
     * @param array $activation_history  (keys are versions, values are arrays of times activated,
675
     *                                   sometimes containing 'unknown-date'
676
     * @return string
677
     */
678
    protected static function _get_most_recently_active_version_from_activation_history($activation_history)
679
    {
680
        $most_recently_active_version_activation = '1970-01-01 00:00:00';
681
        $most_recently_active_version = '0.0.0.dev.000';
682
        if (is_array($activation_history)) {
683
            foreach ($activation_history as $version => $times_activated) {
684
                //check there is a record of when this version was activated. Otherwise,
685
                //mark it as unknown
686
                if ( ! $times_activated) {
687
                    $times_activated = array('unknown-date');
688
                }
689
                if (is_string($times_activated)) {
690
                    $times_activated = array($times_activated);
691
                }
692
                foreach ($times_activated as $an_activation) {
693
                    if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
694
                        $most_recently_active_version = $version;
695
                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
696
                            ? '1970-01-01 00:00:00' : $an_activation;
697
                    }
698
                }
699
            }
700
        }
701
        return $most_recently_active_version;
702
    }
703
704
705
706
    /**
707
     * This redirects to the about EE page after activation
708
     *
709
     * @return void
710
     */
711
    public function redirect_to_about_ee()
712
    {
713
        $notices = EE_Error::get_notices(false);
714
        //if current user is an admin and it's not an ajax or rest request
715
        if (
716
            ! (defined('DOING_AJAX') && DOING_AJAX)
717
            && ! (defined('REST_REQUEST') && REST_REQUEST)
718
            && ! isset($notices['errors'])
719
            && apply_filters(
720
                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
721
                $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
722
            )
723
        ) {
724
            $query_params = array('page' => 'espresso_about');
725
            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
726
                $query_params['new_activation'] = true;
727
            }
728
            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
729
                $query_params['reactivation'] = true;
730
            }
731
            $url = add_query_arg($query_params, admin_url('admin.php'));
732
            wp_safe_redirect($url);
733
            exit();
734
        }
735
    }
736
737
738
739
    /**
740
     * load_core_configuration
741
     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
742
     * which runs during the WP 'plugins_loaded' action at priority 5
743
     *
744
     * @return void
745
     * @throws \ReflectionException
746
     */
747
    public function load_core_configuration()
748
    {
749
        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
750
        $this->registry->load_core('EE_Load_Textdomain');
751
        //load textdomain
752
        EE_Load_Textdomain::load_textdomain();
753
        // load and setup EE_Config and EE_Network_Config
754
        $this->registry->load_core('Config');
755
        $this->registry->load_core('Network_Config');
756
        // setup autoloaders
757
        // enable logging?
758
        if ($this->registry->CFG->admin->use_full_logging) {
759
            $this->registry->load_core('Log');
760
        }
761
        // check for activation errors
762
        $activation_errors = get_option('ee_plugin_activation_errors', false);
763
        if ($activation_errors) {
764
            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
765
            update_option('ee_plugin_activation_errors', false);
766
        }
767
        // get model names
768
        $this->_parse_model_names();
769
        //load caf stuff a chance to play during the activation process too.
770
        $this->_maybe_brew_regular();
771
        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
772
    }
773
774
775
776
    /**
777
     * cycles through all of the models/*.model.php files, and assembles an array of model names
778
     *
779
     * @return void
780
     * @throws ReflectionException
781
     */
782
    private function _parse_model_names()
783
    {
784
        //get all the files in the EE_MODELS folder that end in .model.php
785
        $models = glob(EE_MODELS . '*.model.php');
786
        $model_names = array();
787
        $non_abstract_db_models = array();
788
        foreach ($models as $model) {
789
            // get model classname
790
            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
791
            $short_name = str_replace('EEM_', '', $classname);
792
            $reflectionClass = new ReflectionClass($classname);
793
            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
794
                $non_abstract_db_models[$short_name] = $classname;
795
            }
796
            $model_names[$short_name] = $classname;
797
        }
798
        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
799
        $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names',
800
            $non_abstract_db_models);
801
    }
802
803
804
805
    /**
806
     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
807
     * that need to be setup before our EE_System launches.
808
     *
809
     * @return void
810
     */
811
    private function _maybe_brew_regular()
812
    {
813
        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
814
            require_once EE_CAFF_PATH . 'brewing_regular.php';
815
        }
816
    }
817
818
819
820
    /**
821
     * register_shortcodes_modules_and_widgets
822
     * generate lists of shortcodes and modules, then verify paths and classes
823
     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
824
     * which runs during the WP 'plugins_loaded' action at priority 7
825
     *
826
     * @access public
827
     * @return void
828
     */
829
    public function register_shortcodes_modules_and_widgets()
830
    {
831
        try {
832
            // load, register, and add shortcodes the new way
833
            LoaderFactory::getLoader()->getShared(
834
                'EventEspresso\core\services\shortcodes\ShortcodesManager',
835
                array(
836
                    // and the old way, but we'll put it under control of the new system
837
                    EE_Config::getLegacyShortcodesManager()
838
                )
839
            );
840
        } catch (Exception $exception) {
841
            new ExceptionStackTraceDisplay($exception);
842
        }
843
        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
844
        // check for addons using old hook point
845
        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
846
            $this->_incompatible_addon_error();
847
        }
848
    }
849
850
851
852
    /**
853
     * _incompatible_addon_error
854
     *
855
     * @access public
856
     * @return void
857
     */
858
    private function _incompatible_addon_error()
859
    {
860
        // get array of classes hooking into here
861
        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons');
862
        if ( ! empty($class_names)) {
863
            $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:',
864
                'event_espresso');
865
            $msg .= '<ul>';
866
            foreach ($class_names as $class_name) {
867
                $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
868
                        $class_name) . '</b></li>';
869
            }
870
            $msg .= '</ul>';
871
            $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
872
                'event_espresso');
873
            // save list of incompatible addons to wp-options for later use
874
            add_option('ee_incompatible_addons', $class_names, '', 'no');
875
            if (is_admin()) {
876
                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
877
            }
878
        }
879
    }
880
881
882
883
    /**
884
     * brew_espresso
885
     * begins the process of setting hooks for initializing EE in the correct order
886
     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
887
     * which runs during the WP 'plugins_loaded' action at priority 9
888
     *
889
     * @return void
890
     */
891
    public function brew_espresso()
892
    {
893
        do_action('AHEE__EE_System__brew_espresso__begin', $this);
894
        // load some final core systems
895
        add_action('init', array($this, 'set_hooks_for_core'), 1);
896
        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
897
        add_action('init', array($this, 'load_CPTs_and_session'), 5);
898
        add_action('init', array($this, 'load_controllers'), 7);
899
        add_action('init', array($this, 'core_loaded_and_ready'), 9);
900
        add_action('init', array($this, 'initialize'), 10);
901
        add_action('init', array($this, 'initialize_last'), 100);
902
        add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
903
        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
904
            // pew pew pew
905
            $this->registry->load_core('PUE');
906
            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
907
        }
908
        do_action('AHEE__EE_System__brew_espresso__complete', $this);
909
    }
910
911
912
913
    /**
914
     *    set_hooks_for_core
915
     *
916
     * @access public
917
     * @return    void
918
     * @throws EE_Error
919
     */
920
    public function set_hooks_for_core()
921
    {
922
        $this->_deactivate_incompatible_addons();
923
        do_action('AHEE__EE_System__set_hooks_for_core');
924
        //caps need to be initialized on every request so that capability maps are set.
925
        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
926
        $this->registry->CAP->init_caps();
927
    }
928
929
930
931
    /**
932
     * Using the information gathered in EE_System::_incompatible_addon_error,
933
     * deactivates any addons considered incompatible with the current version of EE
934
     */
935
    private function _deactivate_incompatible_addons()
936
    {
937
        $incompatible_addons = get_option('ee_incompatible_addons', array());
938
        if ( ! empty($incompatible_addons)) {
939
            $active_plugins = get_option('active_plugins', array());
940
            foreach ($active_plugins as $active_plugin) {
941
                foreach ($incompatible_addons as $incompatible_addon) {
942
                    if (strpos($active_plugin, $incompatible_addon) !== false) {
943
                        unset($_GET['activate']);
944
                        espresso_deactivate_plugin($active_plugin);
945
                    }
946
                }
947
            }
948
        }
949
    }
950
951
952
953
    /**
954
     *    perform_activations_upgrades_and_migrations
955
     *
956
     * @access public
957
     * @return    void
958
     */
959
    public function perform_activations_upgrades_and_migrations()
960
    {
961
        //first check if we had previously attempted to setup EE's directories but failed
962
        if (EEH_Activation::upload_directories_incomplete()) {
963
            EEH_Activation::create_upload_directories();
964
        }
965
        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
966
    }
967
968
969
970
    /**
971
     *    load_CPTs_and_session
972
     *
973
     * @access public
974
     * @return    void
975
     */
976
    public function load_CPTs_and_session()
977
    {
978
        do_action('AHEE__EE_System__load_CPTs_and_session__start');
979
        // register Custom Post Types
980
        $this->registry->load_core('Register_CPTs');
981
        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
982
    }
983
984
985
986
    /**
987
     * load_controllers
988
     * this is the best place to load any additional controllers that needs access to EE core.
989
     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
990
     * time
991
     *
992
     * @access public
993
     * @return void
994
     */
995
    public function load_controllers()
996
    {
997
        do_action('AHEE__EE_System__load_controllers__start');
998
        // let's get it started
999
        if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
1000
            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1001
            $this->registry->load_core('Front_Controller');
1002
        } else if ( ! EE_FRONT_AJAX) {
1003
            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1004
            EE_Registry::instance()->load_core('Admin');
1005
        }
1006
        do_action('AHEE__EE_System__load_controllers__complete');
1007
    }
1008
1009
1010
1011
    /**
1012
     * core_loaded_and_ready
1013
     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1014
     *
1015
     * @access public
1016
     * @return void
1017
     */
1018
    public function core_loaded_and_ready()
1019
    {
1020
        $this->registry->load_core('Session');
1021
        do_action('AHEE__EE_System__core_loaded_and_ready');
1022
        // load_espresso_template_tags
1023
        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
1024
            require_once(EE_PUBLIC . 'template_tags.php');
1025
        }
1026
        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1027
        $this->registry->create('EventEspresso\core\services\assets\Registry', array(), true);
1028
    }
1029
1030
1031
1032
    /**
1033
     * initialize
1034
     * this is the best place to begin initializing client code
1035
     *
1036
     * @access public
1037
     * @return void
1038
     */
1039
    public function initialize()
1040
    {
1041
        do_action('AHEE__EE_System__initialize');
1042
    }
1043
1044
1045
1046
    /**
1047
     * initialize_last
1048
     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1049
     * initialize has done so
1050
     *
1051
     * @access public
1052
     * @return void
1053
     */
1054
    public function initialize_last()
1055
    {
1056
        do_action('AHEE__EE_System__initialize_last');
1057
    }
1058
1059
1060
1061
    /**
1062
     * set_hooks_for_shortcodes_modules_and_addons
1063
     * this is the best place for other systems to set callbacks for hooking into other parts of EE
1064
     * this happens at the very beginning of the wp_loaded hook point
1065
     *
1066
     * @access public
1067
     * @return void
1068
     */
1069
    public function set_hooks_for_shortcodes_modules_and_addons()
1070
    {
1071
        //		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
1072
    }
1073
1074
1075
1076
    /**
1077
     * do_not_cache
1078
     * sets no cache headers and defines no cache constants for WP plugins
1079
     *
1080
     * @access public
1081
     * @return void
1082
     */
1083
    public static function do_not_cache()
1084
    {
1085
        // set no cache constants
1086
        if ( ! defined('DONOTCACHEPAGE')) {
1087
            define('DONOTCACHEPAGE', true);
1088
        }
1089
        if ( ! defined('DONOTCACHCEOBJECT')) {
1090
            define('DONOTCACHCEOBJECT', true);
1091
        }
1092
        if ( ! defined('DONOTCACHEDB')) {
1093
            define('DONOTCACHEDB', true);
1094
        }
1095
        // add no cache headers
1096
        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1097
        // plus a little extra for nginx and Google Chrome
1098
        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1099
        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1100
        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1101
    }
1102
1103
1104
1105
    /**
1106
     *    extra_nocache_headers
1107
     *
1108
     * @access    public
1109
     * @param $headers
1110
     * @return    array
1111
     */
1112
    public static function extra_nocache_headers($headers)
1113
    {
1114
        // for NGINX
1115
        $headers['X-Accel-Expires'] = 0;
1116
        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1117
        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1118
        return $headers;
1119
    }
1120
1121
1122
1123
    /**
1124
     *    nocache_headers
1125
     *
1126
     * @access    public
1127
     * @return    void
1128
     */
1129
    public static function nocache_headers()
1130
    {
1131
        nocache_headers();
1132
    }
1133
1134
1135
1136
    /**
1137
     *    espresso_toolbar_items
1138
     *
1139
     * @access public
1140
     * @param  WP_Admin_Bar $admin_bar
1141
     * @return void
1142
     */
1143
    public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1144
    {
1145
        // if in full M-Mode, or its an AJAX request, or user is NOT an admin
1146
        if (
1147
            defined('DOING_AJAX')
1148
            || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1149
            || EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
1150
        ) {
1151
            return;
1152
        }
1153
        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1154
        $menu_class = 'espresso_menu_item_class';
1155
        //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1156
        //because they're only defined in each of their respective constructors
1157
        //and this might be a frontend request, in which case they aren't available
1158
        $events_admin_url = admin_url('admin.php?page=espresso_events');
1159
        $reg_admin_url = admin_url('admin.php?page=espresso_registrations');
1160
        $extensions_admin_url = admin_url('admin.php?page=espresso_packages');
1161
        //Top Level
1162
        $admin_bar->add_menu(array(
1163
            'id'    => 'espresso-toolbar',
1164
            'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1165
                       . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1166
                       . '</span>',
1167
            'href'  => $events_admin_url,
1168
            'meta'  => array(
1169
                'title' => __('Event Espresso', 'event_espresso'),
1170
                'class' => $menu_class . 'first',
1171
            ),
1172
        ));
1173
        //Events
1174 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) {
1175
            $admin_bar->add_menu(array(
1176
                'id'     => 'espresso-toolbar-events',
1177
                'parent' => 'espresso-toolbar',
1178
                'title'  => __('Events', 'event_espresso'),
1179
                'href'   => $events_admin_url,
1180
                'meta'   => array(
1181
                    'title'  => __('Events', 'event_espresso'),
1182
                    'target' => '',
1183
                    'class'  => $menu_class,
1184
                ),
1185
            ));
1186
        }
1187
        if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) {
1188
            //Events Add New
1189
            $admin_bar->add_menu(array(
1190
                'id'     => 'espresso-toolbar-events-new',
1191
                'parent' => 'espresso-toolbar-events',
1192
                'title'  => __('Add New', 'event_espresso'),
1193
                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1194
                'meta'   => array(
1195
                    'title'  => __('Add New', 'event_espresso'),
1196
                    'target' => '',
1197
                    'class'  => $menu_class,
1198
                ),
1199
            ));
1200
        }
1201
        if (is_single() && (get_post_type() === 'espresso_events')) {
1202
            //Current post
1203
            global $post;
1204
            if ($this->registry->CAP->current_user_can('ee_edit_event',
1205
                'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)
1206
            ) {
1207
                //Events Edit Current Event
1208
                $admin_bar->add_menu(array(
1209
                    'id'     => 'espresso-toolbar-events-edit',
1210
                    'parent' => 'espresso-toolbar-events',
1211
                    'title'  => __('Edit Event', 'event_espresso'),
1212
                    'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID),
1213
                        $events_admin_url),
1214
                    'meta'   => array(
1215
                        'title'  => __('Edit Event', 'event_espresso'),
1216
                        'target' => '',
1217
                        'class'  => $menu_class,
1218
                    ),
1219
                ));
1220
            }
1221
        }
1222
        //Events View
1223 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_events',
1224
            'ee_admin_bar_menu_espresso-toolbar-events-view')
1225
        ) {
1226
            $admin_bar->add_menu(array(
1227
                'id'     => 'espresso-toolbar-events-view',
1228
                'parent' => 'espresso-toolbar-events',
1229
                'title'  => __('View', 'event_espresso'),
1230
                'href'   => $events_admin_url,
1231
                'meta'   => array(
1232
                    'title'  => __('View', 'event_espresso'),
1233
                    'target' => '',
1234
                    'class'  => $menu_class,
1235
                ),
1236
            ));
1237
        }
1238 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) {
1239
            //Events View All
1240
            $admin_bar->add_menu(array(
1241
                'id'     => 'espresso-toolbar-events-all',
1242
                'parent' => 'espresso-toolbar-events-view',
1243
                'title'  => __('All', 'event_espresso'),
1244
                'href'   => $events_admin_url,
1245
                'meta'   => array(
1246
                    'title'  => __('All', 'event_espresso'),
1247
                    'target' => '',
1248
                    'class'  => $menu_class,
1249
                ),
1250
            ));
1251
        }
1252 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_events',
1253
            'ee_admin_bar_menu_espresso-toolbar-events-today')
1254
        ) {
1255
            //Events View Today
1256
            $admin_bar->add_menu(array(
1257
                'id'     => 'espresso-toolbar-events-today',
1258
                'parent' => 'espresso-toolbar-events-view',
1259
                'title'  => __('Today', 'event_espresso'),
1260
                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1261
                    $events_admin_url),
1262
                'meta'   => array(
1263
                    'title'  => __('Today', 'event_espresso'),
1264
                    'target' => '',
1265
                    'class'  => $menu_class,
1266
                ),
1267
            ));
1268
        }
1269 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_events',
1270
            'ee_admin_bar_menu_espresso-toolbar-events-month')
1271
        ) {
1272
            //Events View This Month
1273
            $admin_bar->add_menu(array(
1274
                'id'     => 'espresso-toolbar-events-month',
1275
                'parent' => 'espresso-toolbar-events-view',
1276
                'title'  => __('This Month', 'event_espresso'),
1277
                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1278
                    $events_admin_url),
1279
                'meta'   => array(
1280
                    'title'  => __('This Month', 'event_espresso'),
1281
                    'target' => '',
1282
                    'class'  => $menu_class,
1283
                ),
1284
            ));
1285
        }
1286
        //Registration Overview
1287 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1288
            'ee_admin_bar_menu_espresso-toolbar-registrations')
1289
        ) {
1290
            $admin_bar->add_menu(array(
1291
                'id'     => 'espresso-toolbar-registrations',
1292
                'parent' => 'espresso-toolbar',
1293
                'title'  => __('Registrations', 'event_espresso'),
1294
                'href'   => $reg_admin_url,
1295
                'meta'   => array(
1296
                    'title'  => __('Registrations', 'event_espresso'),
1297
                    'target' => '',
1298
                    'class'  => $menu_class,
1299
                ),
1300
            ));
1301
        }
1302
        //Registration Overview Today
1303 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1304
            'ee_admin_bar_menu_espresso-toolbar-registrations-today')
1305
        ) {
1306
            $admin_bar->add_menu(array(
1307
                'id'     => 'espresso-toolbar-registrations-today',
1308
                'parent' => 'espresso-toolbar-registrations',
1309
                'title'  => __('Today', 'event_espresso'),
1310
                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1311
                    $reg_admin_url),
1312
                'meta'   => array(
1313
                    'title'  => __('Today', 'event_espresso'),
1314
                    'target' => '',
1315
                    'class'  => $menu_class,
1316
                ),
1317
            ));
1318
        }
1319
        //Registration Overview Today Completed
1320 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1321
            'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')
1322
        ) {
1323
            $admin_bar->add_menu(array(
1324
                'id'     => 'espresso-toolbar-registrations-today-approved',
1325
                'parent' => 'espresso-toolbar-registrations-today',
1326
                'title'  => __('Approved', 'event_espresso'),
1327
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1328
                    'action'      => 'default',
1329
                    'status'      => 'today',
1330
                    '_reg_status' => EEM_Registration::status_id_approved,
1331
                ), $reg_admin_url),
1332
                'meta'   => array(
1333
                    'title'  => __('Approved', 'event_espresso'),
1334
                    'target' => '',
1335
                    'class'  => $menu_class,
1336
                ),
1337
            ));
1338
        }
1339
        //Registration Overview Today Pending\
1340 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1341
            'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')
1342
        ) {
1343
            $admin_bar->add_menu(array(
1344
                'id'     => 'espresso-toolbar-registrations-today-pending',
1345
                'parent' => 'espresso-toolbar-registrations-today',
1346
                'title'  => __('Pending', 'event_espresso'),
1347
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1348
                    'action'     => 'default',
1349
                    'status'     => 'today',
1350
                    'reg_status' => EEM_Registration::status_id_pending_payment,
1351
                ), $reg_admin_url),
1352
                'meta'   => array(
1353
                    'title'  => __('Pending Payment', 'event_espresso'),
1354
                    'target' => '',
1355
                    'class'  => $menu_class,
1356
                ),
1357
            ));
1358
        }
1359
        //Registration Overview Today Incomplete
1360 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1361
            'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')
1362
        ) {
1363
            $admin_bar->add_menu(array(
1364
                'id'     => 'espresso-toolbar-registrations-today-not-approved',
1365
                'parent' => 'espresso-toolbar-registrations-today',
1366
                'title'  => __('Not Approved', 'event_espresso'),
1367
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1368
                    'action'      => 'default',
1369
                    'status'      => 'today',
1370
                    '_reg_status' => EEM_Registration::status_id_not_approved,
1371
                ), $reg_admin_url),
1372
                'meta'   => array(
1373
                    'title'  => __('Not Approved', 'event_espresso'),
1374
                    'target' => '',
1375
                    'class'  => $menu_class,
1376
                ),
1377
            ));
1378
        }
1379
        //Registration Overview Today Incomplete
1380 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1381
            'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')
1382
        ) {
1383
            $admin_bar->add_menu(array(
1384
                'id'     => 'espresso-toolbar-registrations-today-cancelled',
1385
                'parent' => 'espresso-toolbar-registrations-today',
1386
                'title'  => __('Cancelled', 'event_espresso'),
1387
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1388
                    'action'      => 'default',
1389
                    'status'      => 'today',
1390
                    '_reg_status' => EEM_Registration::status_id_cancelled,
1391
                ), $reg_admin_url),
1392
                'meta'   => array(
1393
                    'title'  => __('Cancelled', 'event_espresso'),
1394
                    'target' => '',
1395
                    'class'  => $menu_class,
1396
                ),
1397
            ));
1398
        }
1399
        //Registration Overview This Month
1400 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1401
            'ee_admin_bar_menu_espresso-toolbar-registrations-month')
1402
        ) {
1403
            $admin_bar->add_menu(array(
1404
                'id'     => 'espresso-toolbar-registrations-month',
1405
                'parent' => 'espresso-toolbar-registrations',
1406
                'title'  => __('This Month', 'event_espresso'),
1407
                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1408
                    $reg_admin_url),
1409
                'meta'   => array(
1410
                    'title'  => __('This Month', 'event_espresso'),
1411
                    'target' => '',
1412
                    'class'  => $menu_class,
1413
                ),
1414
            ));
1415
        }
1416
        //Registration Overview This Month Approved
1417 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1418
            'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')
1419
        ) {
1420
            $admin_bar->add_menu(array(
1421
                'id'     => 'espresso-toolbar-registrations-month-approved',
1422
                'parent' => 'espresso-toolbar-registrations-month',
1423
                'title'  => __('Approved', 'event_espresso'),
1424
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1425
                    'action'      => 'default',
1426
                    'status'      => 'month',
1427
                    '_reg_status' => EEM_Registration::status_id_approved,
1428
                ), $reg_admin_url),
1429
                'meta'   => array(
1430
                    'title'  => __('Approved', 'event_espresso'),
1431
                    'target' => '',
1432
                    'class'  => $menu_class,
1433
                ),
1434
            ));
1435
        }
1436
        //Registration Overview This Month Pending
1437 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1438
            'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')
1439
        ) {
1440
            $admin_bar->add_menu(array(
1441
                'id'     => 'espresso-toolbar-registrations-month-pending',
1442
                'parent' => 'espresso-toolbar-registrations-month',
1443
                'title'  => __('Pending', 'event_espresso'),
1444
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1445
                    'action'      => 'default',
1446
                    'status'      => 'month',
1447
                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1448
                ), $reg_admin_url),
1449
                'meta'   => array(
1450
                    'title'  => __('Pending', 'event_espresso'),
1451
                    'target' => '',
1452
                    'class'  => $menu_class,
1453
                ),
1454
            ));
1455
        }
1456
        //Registration Overview This Month Not Approved
1457 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1458
            'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')
1459
        ) {
1460
            $admin_bar->add_menu(array(
1461
                'id'     => 'espresso-toolbar-registrations-month-not-approved',
1462
                'parent' => 'espresso-toolbar-registrations-month',
1463
                'title'  => __('Not Approved', 'event_espresso'),
1464
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1465
                    'action'      => 'default',
1466
                    'status'      => 'month',
1467
                    '_reg_status' => EEM_Registration::status_id_not_approved,
1468
                ), $reg_admin_url),
1469
                'meta'   => array(
1470
                    'title'  => __('Not Approved', 'event_espresso'),
1471
                    'target' => '',
1472
                    'class'  => $menu_class,
1473
                ),
1474
            ));
1475
        }
1476
        //Registration Overview This Month Cancelled
1477 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1478
            'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')
1479
        ) {
1480
            $admin_bar->add_menu(array(
1481
                'id'     => 'espresso-toolbar-registrations-month-cancelled',
1482
                'parent' => 'espresso-toolbar-registrations-month',
1483
                'title'  => __('Cancelled', 'event_espresso'),
1484
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1485
                    'action'      => 'default',
1486
                    'status'      => 'month',
1487
                    '_reg_status' => EEM_Registration::status_id_cancelled,
1488
                ), $reg_admin_url),
1489
                'meta'   => array(
1490
                    'title'  => __('Cancelled', 'event_espresso'),
1491
                    'target' => '',
1492
                    'class'  => $menu_class,
1493
                ),
1494
            ));
1495
        }
1496
        //Extensions & Services
1497 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_ee',
1498
            'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')
1499
        ) {
1500
            $admin_bar->add_menu(array(
1501
                'id'     => 'espresso-toolbar-extensions-and-services',
1502
                'parent' => 'espresso-toolbar',
1503
                'title'  => __('Extensions & Services', 'event_espresso'),
1504
                'href'   => $extensions_admin_url,
1505
                'meta'   => array(
1506
                    'title'  => __('Extensions & Services', 'event_espresso'),
1507
                    'target' => '',
1508
                    'class'  => $menu_class,
1509
                ),
1510
            ));
1511
        }
1512
    }
1513
1514
1515
1516
    /**
1517
     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1518
     * never returned with the function.
1519
     *
1520
     * @param  array $exclude_array any existing pages being excluded are in this array.
1521
     * @return array
1522
     */
1523
    public function remove_pages_from_wp_list_pages($exclude_array)
1524
    {
1525
        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1526
    }
1527
1528
1529
1530
1531
}
1532
// End of file EE_System.core.php
1533
// Location: /core/EE_System.core.php
1534