Completed
Branch FET-10304-welcome-to-vue (9b3e6e)
by
unknown
97:34 queued 86:04
created

EE_System::wp_enqueue_scripts()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 15
nc 3
nop 0
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
    exit('No direct script access allowed');
3
}
4
5
6
7
/**
8
 * EE_System
9
 *
10
 * @package        Event Espresso
11
 * @subpackage     core/
12
 * @author         Brent Christensen, Michael Nelson
13
 *                 ------------------------------------------------------------------------
14
 */
15
final class EE_System
16
{
17
18
19
    /**
20
     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
21
     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
22
     */
23
    const req_type_normal = 0;
24
25
    /**
26
     * Indicates this is a brand new installation of EE so we should install
27
     * tables and default data etc
28
     */
29
    const req_type_new_activation = 1;
30
31
    /**
32
     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
33
     * and we just exited maintenance mode). We MUST check the database is setup properly
34
     * and that default data is setup too
35
     */
36
    const req_type_reactivation = 2;
37
38
    /**
39
     * indicates that EE has been upgraded since its previous request.
40
     * We may have data migration scripts to call and will want to trigger maintenance mode
41
     */
42
    const req_type_upgrade = 3;
43
44
    /**
45
     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
46
     */
47
    const req_type_downgrade = 4;
48
49
    /**
50
     * @deprecated since version 4.6.0.dev.006
51
     * Now whenever a new_activation is detected the request type is still just
52
     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
53
     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
54
     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
55
     * (Specifically, when the migration manager indicates migrations are finished
56
     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
57
     */
58
    const req_type_activation_but_not_installed = 5;
59
60
    /**
61
     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
62
     */
63
    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
64
65
66
    /**
67
     *    instance of the EE_System object
68
     *
69
     * @var    $_instance
70
     * @access    private
71
     */
72
    private static $_instance = null;
73
74
    /**
75
     * @type  EE_Registry $Registry
76
     * @access    protected
77
     */
78
    protected $registry;
79
80
    /**
81
     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
82
     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
83
     *
84
     * @var int
85
     */
86
    private $_req_type;
87
88
    /**
89
     * Whether or not there was a non-micro version change in EE core version during this request
90
     *
91
     * @var boolean
92
     */
93
    private $_major_version_change = false;
94
95
96
97
    /**
98
     * @singleton method used to instantiate class object
99
     * @access    public
100
     * @param  \EE_Registry $Registry
101
     * @return \EE_System
102
     */
103
    public static function instance(EE_Registry $Registry = null)
104
    {
105
        // check if class object is instantiated
106
        if ( ! self::$_instance instanceof EE_System) {
107
            self::$_instance = new self($Registry);
0 ignored issues
show
Bug introduced by
It seems like $Registry defined by parameter $Registry on line 103 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...
108
        }
109
        return self::$_instance;
110
    }
111
112
113
114
    /**
115
     * resets the instance and returns it
116
     *
117
     * @return EE_System
118
     */
119
    public static function reset()
120
    {
121
        self::$_instance->_req_type = null;
122
        //make sure none of the old hooks are left hanging around
123
        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
124
        //we need to reset the migration manager in order for it to detect DMSs properly
125
        EE_Data_Migration_Manager::reset();
126
        self::instance()->detect_activations_or_upgrades();
127
        self::instance()->perform_activations_upgrades_and_migrations();
128
        return self::instance();
129
    }
130
131
132
133
    /**
134
     *    sets hooks for running rest of system
135
     *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
136
     *    starting EE Addons from any other point may lead to problems
137
     *
138
     * @access private
139
     * @param  \EE_Registry $Registry
140
     */
141
    private function __construct(EE_Registry $Registry)
142
    {
143
        $this->registry = $Registry;
144
        do_action('AHEE__EE_System__construct__begin', $this);
145
        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
146
        add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
147
        // when an ee addon is activated, we want to call the core hook(s) again
148
        // because the newly-activated addon didn't get a chance to run at all
149
        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
150
        // detect whether install or upgrade
151
        add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
152
            3);
153
        // load EE_Config, EE_Textdomain, etc
154
        add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
155
        // load EE_Config, EE_Textdomain, etc
156
        add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
157
            array($this, 'register_shortcodes_modules_and_widgets'), 7);
158
        // you wanna get going? I wanna get going... let's get going!
159
        add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
160
        //other housekeeping
161
        //exclude EE critical pages from wp_list_pages
162
        add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
163
        // ALL EE Addons should use the following hook point to attach their initial setup too
164
        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
165
        do_action('AHEE__EE_System__construct__complete', $this);
166
    }
167
168
169
170
    /**
171
     * load_espresso_addons
172
     * allow addons to load first so that they can set hooks for running DMS's, etc
173
     * this is hooked into both:
174
     *    'AHEE__EE_Bootstrap__load_core_configuration'
175
     *        which runs during the WP 'plugins_loaded' action at priority 5
176
     *    and the WP 'activate_plugin' hookpoint
177
     *
178
     * @access public
179
     * @return void
180
     */
181
    public function load_espresso_addons()
182
    {
183
        // set autoloaders for all of the classes implementing EEI_Plugin_API
184
        // which provide helpers for EE plugin authors to more easily register certain components with EE.
185
        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
186
        //load and setup EE_Capabilities
187
        $this->registry->load_core('Capabilities');
188
        //caps need to be initialized on every request so that capability maps are set.
189
        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
190
        $this->registry->CAP->init_caps();
191
        do_action('AHEE__EE_System__load_espresso_addons');
192
        //if the WP API basic auth plugin isn't already loaded, load it now.
193
        //We want it for mobile apps. Just include the entire plugin
194
        //also, don't load the basic auth when a plugin is getting activated, because
195
        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
196
        //and causes a fatal error
197
        if ( ! function_exists('json_basic_auth_handler')
198
             && ! function_exists('json_basic_auth_error')
199
             && ! (
200
                isset($_GET['action'])
201
                && in_array($_GET['action'], array('activate', 'activate-selected'))
202
            )
203
             && ! (
204
                isset($_GET['activate'])
205
                && $_GET['activate'] === 'true'
206
            )
207
        ) {
208
            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
209
        }
210
        do_action('AHEE__EE_System__load_espresso_addons__complete');
211
    }
212
213
214
215
    /**
216
     * detect_activations_or_upgrades
217
     * Checks for activation or upgrade of core first;
218
     * then also checks if any registered addons have been activated or upgraded
219
     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
220
     * which runs during the WP 'plugins_loaded' action at priority 3
221
     *
222
     * @access public
223
     * @return void
224
     */
225
    public function detect_activations_or_upgrades()
226
    {
227
        //first off: let's make sure to handle core
228
        $this->detect_if_activation_or_upgrade();
229
        foreach ($this->registry->addons as $addon) {
230
            //detect teh request type for that addon
231
            $addon->detect_activation_or_upgrade();
232
        }
233
    }
234
235
236
237
    /**
238
     * detect_if_activation_or_upgrade
239
     * Takes care of detecting whether this is a brand new install or code upgrade,
240
     * and either setting up the DB or setting up maintenance mode etc.
241
     *
242
     * @access public
243
     * @return void
244
     */
245
    public function detect_if_activation_or_upgrade()
246
    {
247
        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
248
        // load M-Mode class
249
        $this->registry->load_core('Maintenance_Mode');
250
        // check if db has been updated, or if its a brand-new installation
251
        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
252
        $request_type = $this->detect_req_type($espresso_db_update);
253
        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
254
        switch ($request_type) {
255
            case EE_System::req_type_new_activation:
256
                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
257
                $this->_handle_core_version_change($espresso_db_update);
258
                break;
259
            case EE_System::req_type_reactivation:
260
                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
261
                $this->_handle_core_version_change($espresso_db_update);
262
                break;
263
            case EE_System::req_type_upgrade:
264
                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
265
                //migrations may be required now that we've upgraded
266
                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
267
                $this->_handle_core_version_change($espresso_db_update);
268
                //				echo "done upgrade";die;
269
                break;
270
            case EE_System::req_type_downgrade:
271
                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
272
                //its possible migrations are no longer required
273
                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
274
                $this->_handle_core_version_change($espresso_db_update);
275
                break;
276
            case EE_System::req_type_normal:
277
            default:
278
                //				$this->_maybe_redirect_to_ee_about();
279
                break;
280
        }
281
        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
282
    }
283
284
285
286
    /**
287
     * Updates the list of installed versions and sets hooks for
288
     * initializing the database later during the request
289
     *
290
     * @param array $espresso_db_update
291
     */
292
    protected function _handle_core_version_change($espresso_db_update)
293
    {
294
        $this->update_list_of_installed_versions($espresso_db_update);
295
        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
296
        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
297
            array($this, 'initialize_db_if_no_migrations_required'));
298
    }
299
300
301
302
    /**
303
     * standardizes the wp option 'espresso_db_upgrade' which actually stores
304
     * information about what versions of EE have been installed and activated,
305
     * NOT necessarily the state of the database
306
     *
307
     * @param null $espresso_db_update
308
     * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
309
     *           from the options table
310
     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
311
     */
312
    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
313
    {
314
        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
315
        if ( ! $espresso_db_update) {
316
            $espresso_db_update = get_option('espresso_db_update');
317
        }
318
        // check that option is an array
319
        if ( ! is_array($espresso_db_update)) {
320
            // if option is FALSE, then it never existed
321
            if ($espresso_db_update === false) {
322
                // make $espresso_db_update an array and save option with autoload OFF
323
                $espresso_db_update = array();
324
                add_option('espresso_db_update', $espresso_db_update, '', 'no');
325
            } else {
326
                // option is NOT FALSE but also is NOT an array, so make it an array and save it
327
                $espresso_db_update = array($espresso_db_update => array());
328
                update_option('espresso_db_update', $espresso_db_update);
329
            }
330
        } else {
331
            $corrected_db_update = array();
332
            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
333
            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
334
                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
335
                    //the key is an int, and the value IS NOT an array
336
                    //so it must be numerically-indexed, where values are versions installed...
337
                    //fix it!
338
                    $version_string = $should_be_array;
339
                    $corrected_db_update[$version_string] = array('unknown-date');
340
                } else {
341
                    //ok it checks out
342
                    $corrected_db_update[$should_be_version_string] = $should_be_array;
343
                }
344
            }
345
            $espresso_db_update = $corrected_db_update;
346
            update_option('espresso_db_update', $espresso_db_update);
347
        }
348
        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
349
        return $espresso_db_update;
350
    }
351
352
353
354
    /**
355
     * Does the traditional work of setting up the plugin's database and adding default data.
356
     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
357
     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
358
     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
359
     * so that it will be done when migrations are finished
360
     *
361
     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
362
     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
363
     *                                       This is a resource-intensive job
364
     *                                       so we prefer to only do it when necessary
365
     * @return void
366
     */
367
    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
368
    {
369
        $request_type = $this->detect_req_type();
370
        //only initialize system if we're not in maintenance mode.
371
        if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
372
            update_option('ee_flush_rewrite_rules', true);
373
            if ($verify_schema) {
374
                EEH_Activation::initialize_db_and_folders();
375
            }
376
            EEH_Activation::initialize_db_content();
377
            EEH_Activation::system_initialization();
378
            if ($initialize_addons_too) {
379
                $this->initialize_addons();
380
            }
381
        } else {
382
            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
383
        }
384
        if ($request_type === EE_System::req_type_new_activation
385
            || $request_type === EE_System::req_type_reactivation
386
            || (
387
                $request_type === EE_System::req_type_upgrade
388
                && $this->is_major_version_change()
389
            )
390
        ) {
391
            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
392
        }
393
    }
394
395
396
397
    /**
398
     * Initializes the db for all registered addons
399
     */
400
    public function initialize_addons()
401
    {
402
        //foreach registered addon, make sure its db is up-to-date too
403
        foreach ($this->registry->addons as $addon) {
404
            $addon->initialize_db_if_no_migrations_required();
405
        }
406
    }
407
408
409
410
    /**
411
     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
412
     *
413
     * @param    array  $version_history
414
     * @param    string $current_version_to_add version to be added to the version history
415
     * @return    boolean success as to whether or not this option was changed
416
     */
417
    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
418
    {
419
        if ( ! $version_history) {
420
            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
0 ignored issues
show
Bug introduced by
It seems like $version_history defined by $this->fix_espresso_db_u...ption($version_history) on line 420 can also be of type array; however, EE_System::fix_espresso_db_upgrade_option() does only seem to accept null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
421
        }
422
        if ($current_version_to_add == null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $current_version_to_add of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
423
            $current_version_to_add = espresso_version();
424
        }
425
        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
426
        // re-save
427
        return update_option('espresso_db_update', $version_history);
428
    }
429
430
431
432
    /**
433
     * Detects if the current version indicated in the has existed in the list of
434
     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
435
     *
436
     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
437
     *                                  If not supplied, fetches it from the options table.
438
     *                                  Also, caches its result so later parts of the code can also know whether
439
     *                                  there's been an update or not. This way we can add the current version to
440
     *                                  espresso_db_update, but still know if this is a new install or not
441
     * @return int one of the constants on EE_System::req_type_
442
     */
443
    public function detect_req_type($espresso_db_update = null)
444
    {
445
        if ($this->_req_type === null) {
446
            $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
447
                : $this->fix_espresso_db_upgrade_option();
448
            $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
449
                'ee_espresso_activation', espresso_version());
450
            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
451
        }
452
        return $this->_req_type;
453
    }
454
455
456
457
    /**
458
     * Returns whether or not there was a non-micro version change (ie, change in either
459
     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
460
     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
461
     *
462
     * @param $activation_history
463
     * @return bool
464
     */
465
    protected function _detect_major_version_change($activation_history)
466
    {
467
        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
468
        $previous_version_parts = explode('.', $previous_version);
469
        $current_version_parts = explode('.', espresso_version());
470
        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
471
               && ($previous_version_parts[0] !== $current_version_parts[0]
472
                   || $previous_version_parts[1] !== $current_version_parts[1]
473
               );
474
    }
475
476
477
478
    /**
479
     * Returns true if either the major or minor version of EE changed during this request.
480
     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
481
     *
482
     * @return bool
483
     */
484
    public function is_major_version_change()
485
    {
486
        return $this->_major_version_change;
487
    }
488
489
490
491
    /**
492
     * Determines the request type for any ee addon, given three piece of info: the current array of activation
493
     * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
494
     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
495
     * just activated to (for core that will always be espresso_version())
496
     *
497
     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
498
     *                                                 ee plugin. for core that's 'espresso_db_update'
499
     * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
500
     *                                                 indicate that this plugin was just activated
501
     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
502
     *                                                 espresso_version())
503
     * @return int one of the constants on EE_System::req_type_*
504
     */
505
    public static function detect_req_type_given_activation_history(
506
        $activation_history_for_addon,
507
        $activation_indicator_option_name,
508
        $version_to_upgrade_to
509
    ) {
510
        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
511
        if ($activation_history_for_addon) {
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...
512
            //it exists, so this isn't a completely new install
513
            //check if this version already in that list of previously installed versions
514
            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
515
                //it a version we haven't seen before
516
                if ($version_is_higher === 1) {
517
                    $req_type = EE_System::req_type_upgrade;
518
                } else {
519
                    $req_type = EE_System::req_type_downgrade;
520
                }
521
                delete_option($activation_indicator_option_name);
522
            } else {
523
                // its not an update. maybe a reactivation?
524
                if (get_option($activation_indicator_option_name, false)) {
525 View Code Duplication
                    if ($version_is_higher === -1) {
526
                        $req_type = EE_System::req_type_downgrade;
527
                    } elseif ($version_is_higher === 0) {
528
                        //we've seen this version before, but it's an activation. must be a reactivation
529
                        $req_type = EE_System::req_type_reactivation;
530
                    } else {//$version_is_higher === 1
531
                        $req_type = EE_System::req_type_upgrade;
532
                    }
533
                    delete_option($activation_indicator_option_name);
534 View Code Duplication
                } else {
535
                    //we've seen this version before and the activation indicate doesn't show it was just activated
536
                    if ($version_is_higher === -1) {
537
                        $req_type = EE_System::req_type_downgrade;
538
                    } elseif ($version_is_higher === 0) {
539
                        //we've seen this version before and it's not an activation. its normal request
540
                        $req_type = EE_System::req_type_normal;
541
                    } else {//$version_is_higher === 1
542
                        $req_type = EE_System::req_type_upgrade;
543
                    }
544
                }
545
            }
546
        } else {
547
            //brand new install
548
            $req_type = EE_System::req_type_new_activation;
549
            delete_option($activation_indicator_option_name);
550
        }
551
        return $req_type;
552
    }
553
554
555
556
    /**
557
     * Detects if the $version_to_upgrade_to is higher than the most recent version in
558
     * the $activation_history_for_addon
559
     *
560
     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
561
     *                                             sometimes containing 'unknown-date'
562
     * @param string $version_to_upgrade_to        (current version)
563
     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
564
     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
565
     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
566
     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
567
     */
568
    protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
569
    {
570
        //find the most recently-activated version
571
        $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
572
        return version_compare($version_to_upgrade_to, $most_recently_active_version);
573
    }
574
575
576
577
    /**
578
     * Gets the most recently active version listed in the activation history,
579
     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
580
     *
581
     * @param array $activation_history  (keys are versions, values are arrays of times activated,
582
     *                                   sometimes containing 'unknown-date'
583
     * @return string
584
     */
585
    protected static function _get_most_recently_active_version_from_activation_history($activation_history)
586
    {
587
        $most_recently_active_version_activation = '1970-01-01 00:00:00';
588
        $most_recently_active_version = '0.0.0.dev.000';
589
        if (is_array($activation_history)) {
590
            foreach ($activation_history as $version => $times_activated) {
591
                //check there is a record of when this version was activated. Otherwise,
592
                //mark it as unknown
593
                if ( ! $times_activated) {
594
                    $times_activated = array('unknown-date');
595
                }
596
                if (is_string($times_activated)) {
597
                    $times_activated = array($times_activated);
598
                }
599
                foreach ($times_activated as $an_activation) {
600
                    if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
601
                        $most_recently_active_version = $version;
602
                        $most_recently_active_version_activation = $an_activation == 'unknown-date'
603
                            ? '1970-01-01 00:00:00' : $an_activation;
604
                    }
605
                }
606
            }
607
        }
608
        return $most_recently_active_version;
609
    }
610
611
612
613
    /**
614
     * This redirects to the about EE page after activation
615
     *
616
     * @return void
617
     */
618
    public function redirect_to_about_ee()
619
    {
620
        $notices = EE_Error::get_notices(false);
621
        //if current user is an admin and it's not an ajax or rest request
622
        if (
623
            ! (defined('DOING_AJAX') && DOING_AJAX)
624
            && ! (defined('REST_REQUEST') && REST_REQUEST)
625
            && ! isset($notices['errors'])
626
            && apply_filters(
627
                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
628
                $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
629
            )
630
        ) {
631
            $query_params = array('page' => 'espresso_about');
632
            if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
633
                $query_params['new_activation'] = true;
634
            }
635
            if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
636
                $query_params['reactivation'] = true;
637
            }
638
            $url = add_query_arg($query_params, admin_url('admin.php'));
639
            wp_safe_redirect($url);
640
            exit();
641
        }
642
    }
643
644
645
646
    /**
647
     * load_core_configuration
648
     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
649
     * which runs during the WP 'plugins_loaded' action at priority 5
650
     *
651
     * @return void
652
     */
653
    public function load_core_configuration()
654
    {
655
        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
656
        $this->registry->load_core('EE_Load_Textdomain');
657
        //load textdomain
658
        EE_Load_Textdomain::load_textdomain();
659
        // load and setup EE_Config and EE_Network_Config
660
        $this->registry->load_core('Config');
661
        $this->registry->load_core('Network_Config');
662
        // setup autoloaders
663
        // enable logging?
664
        if ($this->registry->CFG->admin->use_full_logging) {
665
            $this->registry->load_core('Log');
666
        }
667
        // check for activation errors
668
        $activation_errors = get_option('ee_plugin_activation_errors', false);
669
        if ($activation_errors) {
670
            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
671
            update_option('ee_plugin_activation_errors', false);
672
        }
673
        // get model names
674
        $this->_parse_model_names();
675
        //load caf stuff a chance to play during the activation process too.
676
        $this->_maybe_brew_regular();
677
        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
678
    }
679
680
681
682
    /**
683
     * cycles through all of the models/*.model.php files, and assembles an array of model names
684
     *
685
     * @return void
686
     */
687
    private function _parse_model_names()
688
    {
689
        //get all the files in the EE_MODELS folder that end in .model.php
690
        $models = glob(EE_MODELS . '*.model.php');
691
        $model_names = array();
692
        $non_abstract_db_models = array();
693
        foreach ($models as $model) {
694
            // get model classname
695
            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
696
            $short_name = str_replace('EEM_', '', $classname);
697
            $reflectionClass = new ReflectionClass($classname);
698
            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
699
                $non_abstract_db_models[$short_name] = $classname;
700
            }
701
            $model_names[$short_name] = $classname;
702
        }
703
        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
704
        $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names',
705
            $non_abstract_db_models);
706
    }
707
708
709
710
    /**
711
     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
712
     * that need to be setup before our EE_System launches.
713
     *
714
     * @return void
715
     */
716
    private function _maybe_brew_regular()
717
    {
718
        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
719
            require_once EE_CAFF_PATH . 'brewing_regular.php';
720
        }
721
    }
722
723
724
725
    /**
726
     * register_shortcodes_modules_and_widgets
727
     * generate lists of shortcodes and modules, then verify paths and classes
728
     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
729
     * which runs during the WP 'plugins_loaded' action at priority 7
730
     *
731
     * @access public
732
     * @return void
733
     */
734
    public function register_shortcodes_modules_and_widgets()
735
    {
736
        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
737
        // check for addons using old hookpoint
738
        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
739
            $this->_incompatible_addon_error();
740
        }
741
    }
742
743
744
745
    /**
746
     * _incompatible_addon_error
747
     *
748
     * @access public
749
     * @return void
750
     */
751
    private function _incompatible_addon_error()
752
    {
753
        // get array of classes hooking into here
754
        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons');
755
        if ( ! empty($class_names)) {
756
            $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
757
                'event_espresso');
758
            $msg .= '<ul>';
759
            foreach ($class_names as $class_name) {
760
                $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
761
                        $class_name) . '</b></li>';
762
            }
763
            $msg .= '</ul>';
764
            $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
765
                'event_espresso');
766
            // save list of incompatible addons to wp-options for later use
767
            add_option('ee_incompatible_addons', $class_names, '', 'no');
768
            if (is_admin()) {
769
                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
770
            }
771
        }
772
    }
773
774
775
776
    /**
777
     * brew_espresso
778
     * begins the process of setting hooks for initializing EE in the correct order
779
     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
780
     * which runs during the WP 'plugins_loaded' action at priority 9
781
     *
782
     * @return void
783
     */
784
    public function brew_espresso()
785
    {
786
        do_action('AHEE__EE_System__brew_espresso__begin', $this);
787
        // load some final core systems
788
        add_action('init', array($this, 'set_hooks_for_core'), 1);
789
        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
790
        add_action('init', array($this, 'load_CPTs_and_session'), 5);
791
        add_action('init', array($this, 'load_controllers'), 7);
792
        add_action('init', array($this, 'core_loaded_and_ready'), 9);
793
        add_action('init', array($this, 'initialize'), 10);
794
        add_action('init', array($this, 'initialize_last'), 100);
795
        add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100);
796
        add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100);
797
        add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
798
        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
799
            // pew pew pew
800
            $this->registry->load_core('PUE');
801
            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
802
        }
803
        do_action('AHEE__EE_System__brew_espresso__complete', $this);
804
    }
805
806
807
808
    /**
809
     *    set_hooks_for_core
810
     *
811
     * @access public
812
     * @return    void
813
     */
814
    public function set_hooks_for_core()
815
    {
816
        $this->_deactivate_incompatible_addons();
817
        do_action('AHEE__EE_System__set_hooks_for_core');
818
    }
819
820
821
822
    /**
823
     * Using the information gathered in EE_System::_incompatible_addon_error,
824
     * deactivates any addons considered incompatible with the current version of EE
825
     */
826
    private function _deactivate_incompatible_addons()
827
    {
828
        $incompatible_addons = get_option('ee_incompatible_addons', array());
829
        if ( ! empty($incompatible_addons)) {
830
            $active_plugins = get_option('active_plugins', array());
831
            foreach ($active_plugins as $active_plugin) {
832
                foreach ($incompatible_addons as $incompatible_addon) {
833
                    if (strpos($active_plugin, $incompatible_addon) !== false) {
834
                        unset($_GET['activate']);
835
                        espresso_deactivate_plugin($active_plugin);
836
                    }
837
                }
838
            }
839
        }
840
    }
841
842
843
844
    /**
845
     *    perform_activations_upgrades_and_migrations
846
     *
847
     * @access public
848
     * @return    void
849
     */
850
    public function perform_activations_upgrades_and_migrations()
851
    {
852
        //first check if we had previously attempted to setup EE's directories but failed
853
        if (EEH_Activation::upload_directories_incomplete()) {
854
            EEH_Activation::create_upload_directories();
855
        }
856
        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
857
    }
858
859
860
861
    /**
862
     *    load_CPTs_and_session
863
     *
864
     * @access public
865
     * @return    void
866
     */
867
    public function load_CPTs_and_session()
868
    {
869
        do_action('AHEE__EE_System__load_CPTs_and_session__start');
870
        // register Custom Post Types
871
        $this->registry->load_core('Register_CPTs');
872
        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
873
    }
874
875
876
877
    /**
878
     * load_controllers
879
     * this is the best place to load any additional controllers that needs access to EE core.
880
     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
881
     * time
882
     *
883
     * @access public
884
     * @return void
885
     */
886
    public function load_controllers()
887
    {
888
        do_action('AHEE__EE_System__load_controllers__start');
889
        // let's get it started
890
        if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
891
            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
892
            $this->registry->load_core('Front_Controller', array(), false, true);
0 ignored issues
show
Unused Code introduced by
The call to EE_Registry::load_core() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
893
        } else if ( ! EE_FRONT_AJAX) {
894
            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
895
            EE_Registry::instance()->load_core('Admin');
896
        }
897
        do_action('AHEE__EE_System__load_controllers__complete');
898
    }
899
900
901
902
    /**
903
     * core_loaded_and_ready
904
     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
905
     *
906
     * @access public
907
     * @return void
908
     */
909
    public function core_loaded_and_ready()
910
    {
911
        do_action('AHEE__EE_System__core_loaded_and_ready');
912
        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
913
        $this->registry->load_core('Session');
914
        //		add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 );
915
    }
916
917
918
919
    /**
920
     * initialize
921
     * this is the best place to begin initializing client code
922
     *
923
     * @access public
924
     * @return void
925
     */
926
    public function initialize()
927
    {
928
        do_action('AHEE__EE_System__initialize');
929
    }
930
931
932
933
    /**
934
     * initialize_last
935
     * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
936
     * initialize has done so
937
     *
938
     * @access public
939
     * @return void
940
     */
941
    public function initialize_last()
942
    {
943
        do_action('AHEE__EE_System__initialize_last');
944
    }
945
946
947
948
    /**
949
     * set_hooks_for_shortcodes_modules_and_addons
950
     * this is the best place for other systems to set callbacks for hooking into other parts of EE
951
     * this happens at the very beginning of the wp_loaded hookpoint
952
     *
953
     * @access public
954
     * @return void
955
     */
956
    public function set_hooks_for_shortcodes_modules_and_addons()
957
    {
958
        //		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
959
    }
960
961
962
963
    /**
964
     * do_not_cache
965
     * sets no cache headers and defines no cache constants for WP plugins
966
     *
967
     * @access public
968
     * @return void
969
     */
970
    public static function do_not_cache()
971
    {
972
        // set no cache constants
973
        if ( ! defined('DONOTCACHEPAGE')) {
974
            define('DONOTCACHEPAGE', true);
975
        }
976
        if ( ! defined('DONOTCACHCEOBJECT')) {
977
            define('DONOTCACHCEOBJECT', true);
978
        }
979
        if ( ! defined('DONOTCACHEDB')) {
980
            define('DONOTCACHEDB', true);
981
        }
982
        // add no cache headers
983
        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
984
        // plus a little extra for nginx and Google Chrome
985
        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
986
        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
987
        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
988
    }
989
990
991
992
    /**
993
     *    extra_nocache_headers
994
     *
995
     * @access    public
996
     * @param $headers
997
     * @return    array
998
     */
999
    public static function extra_nocache_headers($headers)
1000
    {
1001
        // for NGINX
1002
        $headers['X-Accel-Expires'] = 0;
1003
        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1004
        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1005
        return $headers;
1006
    }
1007
1008
1009
1010
    /**
1011
     *    nocache_headers
1012
     *
1013
     * @access    public
1014
     * @return    void
1015
     */
1016
    public static function nocache_headers()
1017
    {
1018
        nocache_headers();
1019
    }
1020
1021
1022
1023
    /**
1024
     *    espresso_toolbar_items
1025
     *
1026
     * @access public
1027
     * @param  WP_Admin_Bar $admin_bar
1028
     * @return void
1029
     */
1030
    public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1031
    {
1032
        // if in full M-Mode, or its an AJAX request, or user is NOT an admin
1033
        if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1034
            || defined('DOING_AJAX')
1035
            || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1036
        ) {
1037
            return;
1038
        }
1039
        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1040
        $menu_class = 'espresso_menu_item_class';
1041
        //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1042
        //because they're only defined in each of their respective constructors
1043
        //and this might be a frontend request, in which case they aren't available
1044
        $events_admin_url = admin_url("admin.php?page=espresso_events");
1045
        $reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1046
        $extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1047
        //Top Level
1048
        $admin_bar->add_menu(array(
1049
            'id'    => 'espresso-toolbar',
1050
            'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1051
                       . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1052
                       . '</span>',
1053
            'href'  => $events_admin_url,
1054
            'meta'  => array(
1055
                'title' => __('Event Espresso', 'event_espresso'),
1056
                'class' => $menu_class . 'first',
1057
            ),
1058
        ));
1059
        //Events
1060 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) {
1061
            $admin_bar->add_menu(array(
1062
                'id'     => 'espresso-toolbar-events',
1063
                'parent' => 'espresso-toolbar',
1064
                'title'  => __('Events', 'event_espresso'),
1065
                'href'   => $events_admin_url,
1066
                'meta'   => array(
1067
                    'title'  => __('Events', 'event_espresso'),
1068
                    'target' => '',
1069
                    'class'  => $menu_class,
1070
                ),
1071
            ));
1072
        }
1073
        if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) {
1074
            //Events Add New
1075
            $admin_bar->add_menu(array(
1076
                'id'     => 'espresso-toolbar-events-new',
1077
                'parent' => 'espresso-toolbar-events',
1078
                'title'  => __('Add New', 'event_espresso'),
1079
                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1080
                'meta'   => array(
1081
                    'title'  => __('Add New', 'event_espresso'),
1082
                    'target' => '',
1083
                    'class'  => $menu_class,
1084
                ),
1085
            ));
1086
        }
1087
        if (is_single() && (get_post_type() == 'espresso_events')) {
1088
            //Current post
1089
            global $post;
1090
            if ($this->registry->CAP->current_user_can('ee_edit_event',
1091
                'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)
1092
            ) {
1093
                //Events Edit Current Event
1094
                $admin_bar->add_menu(array(
1095
                    'id'     => 'espresso-toolbar-events-edit',
1096
                    'parent' => 'espresso-toolbar-events',
1097
                    'title'  => __('Edit Event', 'event_espresso'),
1098
                    'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID),
1099
                        $events_admin_url),
1100
                    'meta'   => array(
1101
                        'title'  => __('Edit Event', 'event_espresso'),
1102
                        'target' => '',
1103
                        'class'  => $menu_class,
1104
                    ),
1105
                ));
1106
            }
1107
        }
1108
        //Events View
1109 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_events',
1110
            'ee_admin_bar_menu_espresso-toolbar-events-view')
1111
        ) {
1112
            $admin_bar->add_menu(array(
1113
                'id'     => 'espresso-toolbar-events-view',
1114
                'parent' => 'espresso-toolbar-events',
1115
                'title'  => __('View', 'event_espresso'),
1116
                'href'   => $events_admin_url,
1117
                'meta'   => array(
1118
                    'title'  => __('View', 'event_espresso'),
1119
                    'target' => '',
1120
                    'class'  => $menu_class,
1121
                ),
1122
            ));
1123
        }
1124 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) {
1125
            //Events View All
1126
            $admin_bar->add_menu(array(
1127
                'id'     => 'espresso-toolbar-events-all',
1128
                'parent' => 'espresso-toolbar-events-view',
1129
                'title'  => __('All', 'event_espresso'),
1130
                'href'   => $events_admin_url,
1131
                'meta'   => array(
1132
                    'title'  => __('All', 'event_espresso'),
1133
                    'target' => '',
1134
                    'class'  => $menu_class,
1135
                ),
1136
            ));
1137
        }
1138 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_events',
1139
            'ee_admin_bar_menu_espresso-toolbar-events-today')
1140
        ) {
1141
            //Events View Today
1142
            $admin_bar->add_menu(array(
1143
                'id'     => 'espresso-toolbar-events-today',
1144
                'parent' => 'espresso-toolbar-events-view',
1145
                'title'  => __('Today', 'event_espresso'),
1146
                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1147
                    $events_admin_url),
1148
                'meta'   => array(
1149
                    'title'  => __('Today', 'event_espresso'),
1150
                    'target' => '',
1151
                    'class'  => $menu_class,
1152
                ),
1153
            ));
1154
        }
1155 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_events',
1156
            'ee_admin_bar_menu_espresso-toolbar-events-month')
1157
        ) {
1158
            //Events View This Month
1159
            $admin_bar->add_menu(array(
1160
                'id'     => 'espresso-toolbar-events-month',
1161
                'parent' => 'espresso-toolbar-events-view',
1162
                'title'  => __('This Month', 'event_espresso'),
1163
                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1164
                    $events_admin_url),
1165
                'meta'   => array(
1166
                    'title'  => __('This Month', 'event_espresso'),
1167
                    'target' => '',
1168
                    'class'  => $menu_class,
1169
                ),
1170
            ));
1171
        }
1172
        //Registration Overview
1173 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1174
            'ee_admin_bar_menu_espresso-toolbar-registrations')
1175
        ) {
1176
            $admin_bar->add_menu(array(
1177
                'id'     => 'espresso-toolbar-registrations',
1178
                'parent' => 'espresso-toolbar',
1179
                'title'  => __('Registrations', 'event_espresso'),
1180
                'href'   => $reg_admin_url,
1181
                'meta'   => array(
1182
                    'title'  => __('Registrations', 'event_espresso'),
1183
                    'target' => '',
1184
                    'class'  => $menu_class,
1185
                ),
1186
            ));
1187
        }
1188
        //Registration Overview Today
1189 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1190
            'ee_admin_bar_menu_espresso-toolbar-registrations-today')
1191
        ) {
1192
            $admin_bar->add_menu(array(
1193
                'id'     => 'espresso-toolbar-registrations-today',
1194
                'parent' => 'espresso-toolbar-registrations',
1195
                'title'  => __('Today', 'event_espresso'),
1196
                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1197
                    $reg_admin_url),
1198
                'meta'   => array(
1199
                    'title'  => __('Today', 'event_espresso'),
1200
                    'target' => '',
1201
                    'class'  => $menu_class,
1202
                ),
1203
            ));
1204
        }
1205
        //Registration Overview Today Completed
1206 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1207
            'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')
1208
        ) {
1209
            $admin_bar->add_menu(array(
1210
                'id'     => 'espresso-toolbar-registrations-today-approved',
1211
                'parent' => 'espresso-toolbar-registrations-today',
1212
                'title'  => __('Approved', 'event_espresso'),
1213
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1214
                    'action'      => 'default',
1215
                    'status'      => 'today',
1216
                    '_reg_status' => EEM_Registration::status_id_approved,
1217
                ), $reg_admin_url),
1218
                'meta'   => array(
1219
                    'title'  => __('Approved', 'event_espresso'),
1220
                    'target' => '',
1221
                    'class'  => $menu_class,
1222
                ),
1223
            ));
1224
        }
1225
        //Registration Overview Today Pending\
1226 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1227
            'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')
1228
        ) {
1229
            $admin_bar->add_menu(array(
1230
                'id'     => 'espresso-toolbar-registrations-today-pending',
1231
                'parent' => 'espresso-toolbar-registrations-today',
1232
                'title'  => __('Pending', 'event_espresso'),
1233
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1234
                    'action'     => 'default',
1235
                    'status'     => 'today',
1236
                    'reg_status' => EEM_Registration::status_id_pending_payment,
1237
                ), $reg_admin_url),
1238
                'meta'   => array(
1239
                    'title'  => __('Pending Payment', 'event_espresso'),
1240
                    'target' => '',
1241
                    'class'  => $menu_class,
1242
                ),
1243
            ));
1244
        }
1245
        //Registration Overview Today Incomplete
1246 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1247
            'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')
1248
        ) {
1249
            $admin_bar->add_menu(array(
1250
                'id'     => 'espresso-toolbar-registrations-today-not-approved',
1251
                'parent' => 'espresso-toolbar-registrations-today',
1252
                'title'  => __('Not Approved', 'event_espresso'),
1253
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1254
                    'action'      => 'default',
1255
                    'status'      => 'today',
1256
                    '_reg_status' => EEM_Registration::status_id_not_approved,
1257
                ), $reg_admin_url),
1258
                'meta'   => array(
1259
                    'title'  => __('Not Approved', 'event_espresso'),
1260
                    'target' => '',
1261
                    'class'  => $menu_class,
1262
                ),
1263
            ));
1264
        }
1265
        //Registration Overview Today Incomplete
1266 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1267
            'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')
1268
        ) {
1269
            $admin_bar->add_menu(array(
1270
                'id'     => 'espresso-toolbar-registrations-today-cancelled',
1271
                'parent' => 'espresso-toolbar-registrations-today',
1272
                'title'  => __('Cancelled', 'event_espresso'),
1273
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1274
                    'action'      => 'default',
1275
                    'status'      => 'today',
1276
                    '_reg_status' => EEM_Registration::status_id_cancelled,
1277
                ), $reg_admin_url),
1278
                'meta'   => array(
1279
                    'title'  => __('Cancelled', 'event_espresso'),
1280
                    'target' => '',
1281
                    'class'  => $menu_class,
1282
                ),
1283
            ));
1284
        }
1285
        //Registration Overview This Month
1286 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1287
            'ee_admin_bar_menu_espresso-toolbar-registrations-month')
1288
        ) {
1289
            $admin_bar->add_menu(array(
1290
                'id'     => 'espresso-toolbar-registrations-month',
1291
                'parent' => 'espresso-toolbar-registrations',
1292
                'title'  => __('This Month', 'event_espresso'),
1293
                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1294
                    $reg_admin_url),
1295
                'meta'   => array(
1296
                    'title'  => __('This Month', 'event_espresso'),
1297
                    'target' => '',
1298
                    'class'  => $menu_class,
1299
                ),
1300
            ));
1301
        }
1302
        //Registration Overview This Month Approved
1303 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1304
            'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')
1305
        ) {
1306
            $admin_bar->add_menu(array(
1307
                'id'     => 'espresso-toolbar-registrations-month-approved',
1308
                'parent' => 'espresso-toolbar-registrations-month',
1309
                'title'  => __('Approved', 'event_espresso'),
1310
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1311
                    'action'      => 'default',
1312
                    'status'      => 'month',
1313
                    '_reg_status' => EEM_Registration::status_id_approved,
1314
                ), $reg_admin_url),
1315
                'meta'   => array(
1316
                    'title'  => __('Approved', 'event_espresso'),
1317
                    'target' => '',
1318
                    'class'  => $menu_class,
1319
                ),
1320
            ));
1321
        }
1322
        //Registration Overview This Month Pending
1323 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1324
            'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')
1325
        ) {
1326
            $admin_bar->add_menu(array(
1327
                'id'     => 'espresso-toolbar-registrations-month-pending',
1328
                'parent' => 'espresso-toolbar-registrations-month',
1329
                'title'  => __('Pending', 'event_espresso'),
1330
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1331
                    'action'      => 'default',
1332
                    'status'      => 'month',
1333
                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1334
                ), $reg_admin_url),
1335
                'meta'   => array(
1336
                    'title'  => __('Pending', 'event_espresso'),
1337
                    'target' => '',
1338
                    'class'  => $menu_class,
1339
                ),
1340
            ));
1341
        }
1342
        //Registration Overview This Month Not Approved
1343 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1344
            'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')
1345
        ) {
1346
            $admin_bar->add_menu(array(
1347
                'id'     => 'espresso-toolbar-registrations-month-not-approved',
1348
                'parent' => 'espresso-toolbar-registrations-month',
1349
                'title'  => __('Not Approved', 'event_espresso'),
1350
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1351
                    'action'      => 'default',
1352
                    'status'      => 'month',
1353
                    '_reg_status' => EEM_Registration::status_id_not_approved,
1354
                ), $reg_admin_url),
1355
                'meta'   => array(
1356
                    'title'  => __('Not Approved', 'event_espresso'),
1357
                    'target' => '',
1358
                    'class'  => $menu_class,
1359
                ),
1360
            ));
1361
        }
1362
        //Registration Overview This Month Cancelled
1363 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1364
            'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')
1365
        ) {
1366
            $admin_bar->add_menu(array(
1367
                'id'     => 'espresso-toolbar-registrations-month-cancelled',
1368
                'parent' => 'espresso-toolbar-registrations-month',
1369
                'title'  => __('Cancelled', 'event_espresso'),
1370
                'href'   => EEH_URL::add_query_args_and_nonce(array(
1371
                    'action'      => 'default',
1372
                    'status'      => 'month',
1373
                    '_reg_status' => EEM_Registration::status_id_cancelled,
1374
                ), $reg_admin_url),
1375
                'meta'   => array(
1376
                    'title'  => __('Cancelled', 'event_espresso'),
1377
                    'target' => '',
1378
                    'class'  => $menu_class,
1379
                ),
1380
            ));
1381
        }
1382
        //Extensions & Services
1383 View Code Duplication
        if ($this->registry->CAP->current_user_can('ee_read_ee',
1384
            'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')
1385
        ) {
1386
            $admin_bar->add_menu(array(
1387
                'id'     => 'espresso-toolbar-extensions-and-services',
1388
                'parent' => 'espresso-toolbar',
1389
                'title'  => __('Extensions & Services', 'event_espresso'),
1390
                'href'   => $extensions_admin_url,
1391
                'meta'   => array(
1392
                    'title'  => __('Extensions & Services', 'event_espresso'),
1393
                    'target' => '',
1394
                    'class'  => $menu_class,
1395
                ),
1396
            ));
1397
        }
1398
    }
1399
1400
1401
1402
    /**
1403
     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1404
     * never returned with the function.
1405
     *
1406
     * @param  array $exclude_array any existing pages being excluded are in this array.
1407
     * @return array
1408
     */
1409
    public function remove_pages_from_wp_list_pages($exclude_array)
1410
    {
1411
        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1412
    }
1413
1414
1415
1416
1417
1418
1419
    /***********************************************        WP_ENQUEUE_SCRIPTS HOOK         ***********************************************/
1420
    /**
1421
     *    wp_enqueue_scripts
1422
     *
1423
     * @access    public
1424
     * @return    void
1425
     */
1426
    public function wp_enqueue_scripts()
1427
    {
1428
        // unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' );
1429
        if (apply_filters('FHEE_load_EE_System_scripts', true)) {
1430
            // jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via:  add_filter( 'FHEE_load_jquery_validate', '__return_true' );
1431
            if (apply_filters('FHEE_load_jquery_validate', false)) {
1432
                // register jQuery Validate and additional methods
1433
                wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
1434
                    array('jquery'), '1.15.0', true);
1435
                wp_register_script('jquery-validate-extra-methods',
1436
                    EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
1437
                    array('jquery', 'jquery-validate'), '1.15.0', true);
1438
            }
1439
1440
            //registers the eejs-api script so it can be used as a dependency on other scripts.
1441
            wp_register_script('eejs-api', EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', array('underscore'), espresso_version(), true);
1442
            EE_Registry::$eejs['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
1443
            wp_localize_script(
1444
                'eejs-api',
1445
                'eejs',
1446
                array(
1447
                    'data' => EE_Registry::$eejs
1448
                )
1449
            );
1450
        }
1451
    }
1452
1453
1454
1455
}
1456
// End of file EE_System.core.php
1457
// Location: /core/EE_System.core.php
1458